Skip to content

Commit

Permalink
rework init flow
Browse files Browse the repository at this point in the history
This reworks app initialization to achieve a number of ux goals.

1) Adds chance for user to quickly configure native wallets and add
   known dexes (view-only)
2) Adds seed backup dialog
3) Makes the Wallets view the landing page
  • Loading branch information
buck54321 authored and chappjc committed Jul 12, 2023
1 parent ce29d0c commit b24e20c
Show file tree
Hide file tree
Showing 19 changed files with 561 additions and 124 deletions.
1 change: 0 additions & 1 deletion client/core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -4510,7 +4510,6 @@ func (c *Core) InitializeClient(pw, restorationSeed []byte) error {
subject, details := c.formatDetails(TopicSeedNeedsSaving)
c.notify(newSecurityNote(TopicSeedNeedsSaving, subject, details, db.Success))
}

return nil
}

Expand Down
8 changes: 7 additions & 1 deletion client/webserver/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,13 @@ func (s *WebServer) apiInit(w http.ResponseWriter, r *http.Request) {
return
}

writeJSON(w, simpleAck(), s.indent)
writeJSON(w, struct {
OK bool `json:"ok"`
Hosts []string `json:"hosts"`
}{
OK: true,
Hosts: s.knownUnregisteredExchanges(map[string]*core.Exchange{}),
}, s.indent)
}

// apiIsInitialized is the handler for the '/isinitialized' request.
Expand Down
6 changes: 6 additions & 0 deletions client/webserver/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
const (
homeRoute = "/"
registerRoute = "/register"
initRoute = "/init"
loginRoute = "/login"
marketsRoute = "/markets"
walletsRoute = "/wallets"
Expand Down Expand Up @@ -225,6 +226,11 @@ func (s *WebServer) handleGenerateQRCode(w http.ResponseWriter, r *http.Request)
}
}

// handleInit is the handler for the '/init' page request
func (s *WebServer) handleInit(w http.ResponseWriter, r *http.Request) {
s.sendTemplate(w, "init", s.commonArgs(r, "Welcome | Decred DEX"))
}

// handleSettings is the handler for the '/settings' page request.
func (s *WebServer) handleSettings(w http.ResponseWriter, r *http.Request) {
common := s.commonArgs(r, "Settings | Decred DEX")
Expand Down
74 changes: 59 additions & 15 deletions client/webserver/live_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ var (
delayBalance = false
doubleCreateAsyncErr = false
randomizeOrdersCount = false
initErrors = false
)

func dummySettings() map[string]string {
Expand Down Expand Up @@ -224,7 +225,7 @@ func mkDexAsset(symbol string) *dex.Asset {
a := &dex.Asset{
ID: assetID,
Symbol: symbol,
Version: uint32(rand.Intn(12)),
Version: 0,
MaxFeeRate: uint64(rand.Intn(10) + 1),
SwapSize: uint64(rand.Intn(150) + 150),
SwapSizeBase: uint64(rand.Intn(150) + 15),
Expand Down Expand Up @@ -370,7 +371,21 @@ var tExchanges = map[string]*core.Exchange{
Amt: 1e12,
},
},
CandleDurs: []string{"1h", "24h"},
CandleDurs: []string{"1h", "24h"},
PendingBonds: map[string]*core.PendingBondState{},
BondAssets: map[string]*core.BondAsset{
"dcr": {
ID: 42,
Confs: 2,
Amt: 1,
},
},
BondOptions: &core.BondOptions{
BondAsset: 42,
TargetTier: 0,
MaxBondedAmt: 100e8,
},
ViewOnly: true,
},
secondDEX: {
Host: "thisdexwithalongname.com",
Expand Down Expand Up @@ -414,7 +429,21 @@ var tExchanges = map[string]*core.Exchange{
Amt: 1e10,
},
},
CandleDurs: []string{"5m", "1h", "24h"},
CandleDurs: []string{"5m", "1h", "24h"},
PendingBonds: map[string]*core.PendingBondState{},
BondAssets: map[string]*core.BondAsset{
"dcr": {
ID: 42,
Confs: 2,
Amt: 1,
},
},
BondOptions: &core.BondOptions{
BondAsset: 42,
TargetTier: 0,
MaxBondedAmt: 100e8,
},
ViewOnly: true,
},
}

Expand Down Expand Up @@ -577,6 +606,10 @@ func (c *TCore) GetDEXConfig(host string, certI interface{}) (*core.Exchange, er
}

func (c *TCore) AddDEX(dexAddr string, certI interface{}) error {
randomDelay()
if initErrors {
return fmt.Errorf("forced init error")
}
return nil
}

Expand All @@ -597,8 +630,20 @@ func (c *TCore) Register(r *core.RegisterForm) (*core.RegisterResult, error) {
c.reg = r
return nil, nil
}
func (c *TCore) PostBond(r *core.PostBondForm) (*core.PostBondResult, error) {
return nil, nil
func (c *TCore) PostBond(form *core.PostBondForm) (*core.PostBondResult, error) {
xc, exists := tExchanges[form.Addr]
if !exists {
return nil, fmt.Errorf("server %q not known", form.Addr)
}
symbol := dex.BipIDSymbol(*form.Asset)
ba := xc.BondAssets[symbol]
tier := form.Bond / ba.Amt
xc.BondOptions.TargetTier = tier
xc.Tier = int64(tier)
return &core.PostBondResult{
BondID: "abc",
ReqConfirms: uint16(ba.Confs),
}, nil
}
func (c *TCore) UpdateBondOptions(form *core.BondOptionsForm) error {
return nil
Expand Down Expand Up @@ -628,7 +673,7 @@ func (c *TCore) EstimateSendTxFee(addr string, assetID uint32, value uint64, sub
return uint64(float64(value) * 0.01), len(addr) > 10, nil
}
func (c *TCore) Login([]byte) error { return nil }
func (c *TCore) IsInitialized() bool { return true }
func (c *TCore) IsInitialized() bool { return c.inited }
func (c *TCore) Logout() error { return nil }
func (c *TCore) Notifications(n int) ([]*db.Notification, error) {
return nil, nil
Expand Down Expand Up @@ -1393,6 +1438,9 @@ func (c *TCore) walletState(assetID uint32) *core.WalletState {

func (c *TCore) CreateWallet(appPW, walletPW []byte, form *core.WalletForm) error {
randomDelay()
if initErrors {
return fmt.Errorf("forced init error")
}
c.mtx.Lock()
defer c.mtx.Unlock()

Expand Down Expand Up @@ -1654,13 +1702,8 @@ func (c *TCore) NewDepositAddress(assetID uint32) (string, error) {
func (c *TCore) SetWalletPassword(appPW []byte, assetID uint32, newPW []byte) error { return nil }

func (c *TCore) User() *core.User {
exchanges := map[string]*core.Exchange{}
if c.reg != nil {
exchanges = tExchanges
}

user := &core.User{
Exchanges: exchanges,
Exchanges: tExchanges,
Initialized: c.inited,
Assets: c.SupportedAssets(),
FiatRates: map[uint32]float64{
Expand Down Expand Up @@ -1884,7 +1927,7 @@ func (c *TCore) runRandomNotes() {
}

func (c *TCore) ExportSeed(pw []byte) ([]byte, error) {
b, _ := hex.DecodeString("deadbeef1234567890")
b, _ := hex.DecodeString("ea9790d6b4ced3069b9fba7562904d7cfa68cb210600a76ede6f86dac1c3d18d5089e4c53543ef433f5ba4886465ab927b0231c30e8baa13f6d9c8dec1668821")
return b, nil
}
func (c *TCore) WalletLogFilePath(uint32) (string, error) {
Expand Down Expand Up @@ -1945,8 +1988,8 @@ func TestServer(t *testing.T) {
numBuys = 10
numSells = 10
feedPeriod = 5000 * time.Millisecond
initialize := true
register := true
initialize := false
register := false
forceDisconnectWallet = true
gapWidthFactor = 0.2
randomPokes = false
Expand All @@ -1955,6 +1998,7 @@ func TestServer(t *testing.T) {
delayBalance = true
doubleCreateAsyncErr = false
randomizeOrdersCount = true
initErrors = true

var shutdown context.CancelFunc
tCtx, shutdown = context.WithCancel(context.Background())
Expand Down
14 changes: 14 additions & 0 deletions client/webserver/locales/en-us.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,4 +354,18 @@ var EnUS = map[string]string{
"no_token_allowances": "You have not granted allowances for any swap contracts for this token.",
"token_unapproval_tx_msg": `Your token approval has been removed with transaction ID:`,
"approval_change_pending": "Approval change pending",
// Init page
"Quick Configuration": "Quick Configuration",
"quickconfig_server_header": "We can connect to these servers.",
"quickconfig_wallet_header": "We can activate these native wallets now. Configure additional wallets from the Wallets view.",
"quickconfig_server_error_header": "Errors encountered when connecting to the following servers. You can try again from the Settings view.",
"quickconfig_wallet_error_header": "Errors encountered when creating the following wallets. Wallets can be configured in the Wallets view.",
"Continue": "Continue",
"Backup App Seed": "Backup App Seed",
"seed_backup_implore": "It's highly recommended that you back up your application seed now. " +
"The application seed is critical to recovering your fidelity bonds and native wallets.",
"Backup Now": "Backup Now",
"Skip this step for now": "Skip this step for now",
"save_seed_instructions": "Save the following seed somewhere safe. Do not share this with anybody.",
"Done": "Done",
}
20 changes: 19 additions & 1 deletion client/webserver/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,25 @@ func extractBooleanCookie(r *http.Request, k string, defaultVal bool) bool {
func (s *WebServer) requireInit(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if !s.core.IsInitialized() {
http.Redirect(w, r, registerRoute, http.StatusSeeOther)
http.Redirect(w, r, initRoute, http.StatusSeeOther)
return
}
next.ServeHTTP(w, r)
})
}

// requireNotInit ensures that the core app is not initialized before allowing
// the incoming request to proceed. Redirects to the login page if the app is
// initialized and the user is not logged in. If logged in, directs to the
// wallets page.
func (s *WebServer) requireNotInit(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if s.core.IsInitialized() {
route := loginRoute
if extractUserInfo(r).Authed {
route = walletsRoute
}
http.Redirect(w, r, route, http.StatusSeeOther)
return
}
next.ServeHTTP(w, r)
Expand Down
13 changes: 11 additions & 2 deletions client/webserver/site/src/css/forms.scss
Original file line number Diff line number Diff line change
Expand Up @@ -331,12 +331,14 @@ button.form-button {
#sendForm,
#vSendForm,
#exportSeedAuth,
#cancelForm {
#cancelForm,
#quickConfigForm {
width: 375px;
}

#reconfigForm,
#authorizeSeedDisplay {
#authorizeSeedDisplay,
#seedBackupForm {
width: 425px;
}

Expand Down Expand Up @@ -411,3 +413,10 @@ a[data-tmpl=walletCfgGuide] {
}
}
}

div[data-handler=init] {
.quickconfig-asset-logo {
width: 25px;
height: 25px;
}
}
4 changes: 2 additions & 2 deletions client/webserver/site/src/html/bodybuilder.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<link rel="icon" href="/img/favicon.png?v=AK4XS4">
<meta name="description" content="Decred DEX Client Web Portal">
<title>{{.Title}}</title>
<link href="/css/style.css?v=b364da40|18bfd169" rel="stylesheet">
<link href="/css/style.css?v=a179bbb8|fadb2030" rel="stylesheet">
</head>
<body {{if .UserInfo.DarkMode}} class="dark"{{end}}>
<div class="popup-notes" id="popupNotes">
Expand Down Expand Up @@ -104,7 +104,7 @@
{{end}}

{{define "bottom"}}
<script src="/js/entry.js?v=316c3da9|8d59551e"></script>
<script src="/js/entry.js?v=39867746|72de6251"></script>
</body>
</html>
{{end}}
Loading

0 comments on commit b24e20c

Please sign in to comment.