Skip to content

Commit

Permalink
review changes
Browse files Browse the repository at this point in the history
Signed-off-by: Philemon Ukane <[email protected]>
  • Loading branch information
ukane-philemon committed Feb 20, 2024
1 parent ead8999 commit 0eb2d2b
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 66 deletions.
37 changes: 19 additions & 18 deletions ui/page/dcrdex/dcrdex_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,19 @@ func (pg *DEXPage) ID() string {
// Part of the load.Page interface.
func (pg *DEXPage) OnNavigatedTo() {
if !pg.AssetsManager.DEXCInitialized() {
pg.showSplashPage = true
return
}

if pg.CurrentPage() != nil {
pg.CurrentPage().OnNavigatedTo()
} else {
pg.setPage()
pg.prepareInitialPage()
}
}

// setPage starts a goroutine that waits for dexc to get ready before displaying
// an appropriate page.
func (pg *DEXPage) setPage() {
// prepareInitialPage starts a goroutine that waits for dexc to get ready before
// displaying an appropriate page.
func (pg *DEXPage) prepareInitialPage() {
dexClient := pg.AssetsManager.DexClient()
if dexClient == nil {
return
Expand Down Expand Up @@ -119,34 +118,36 @@ func (pg *DEXPage) setPage() {
// eventually drawn on screen.
// Part of the load.Page interface.
func (pg *DEXPage) Layout(gtx C) D {
hasMultipleWallets := pg.isMultipleAssetTypeWalletAvailable()
isMainnet := pg.AssetsManager.NetType() == utils.Mainnet
if !isMainnet && (!pg.AssetsManager.DEXCInitialized() || pg.CurrentPage() == nil) { // dexc must have been reset.
pg.showSplashPage = true
if !pg.dexIsLoading {
pg.ParentNavigator().CloseAllPages()
pg.prepareInitialPage()
}
}

if pg.showSplashPage || pg.dexIsLoading {
return pg.Theme.List(pg.splashPageContainer).Layout(gtx, 1, func(gtx C, i int) D {
return pg.splashPage(gtx)
})
}

var msg string
var actionBtn *cryptomaterial.Button
if isMainnet {
if pg.CanChangeNetworkType() {
actionBtn = &pg.switchToTestnetBtn
}
msg = values.String(values.StrDexMainnetNotReady)
} else if !hasMultipleWallets {
} else if hasMultipleWallets := pg.isMultipleAssetTypeWalletAvailable(); !hasMultipleWallets {
msg = values.String(values.StrMultipleAssetRequiredMsg)
} else if !pg.AssetsManager.DEXCInitialized() || pg.CurrentPage() == nil { // dexc must have been reset.
pg.showSplashPage = true
if !pg.dexIsLoading {
pg.setPage()
}
}

if msg != "" {
return components.DisablePageWithOverlay(pg.Load, nil, gtx, msg, "", actionBtn)
}

if pg.showSplashPage || pg.dexIsLoading {
return pg.Theme.List(pg.splashPageContainer).Layout(gtx, 1, func(gtx C, i int) D {
return pg.splashPage(gtx)
})
}

return pg.CurrentPage().Layout(gtx)
}

Expand Down
83 changes: 37 additions & 46 deletions ui/page/dcrdex/dex_onboarding_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -986,18 +986,36 @@ func (pg *DEXOnboarding) HandleUserInteractions() {
}

pg.bondServer = serverInfo
if dexc.InitializedWithPassword() && len(pg.dexPass) == 0 {
// Prompt the user to login now so we can use
// dexClient.DiscoverAccount in
// pg.connectServerAndPrepareForBonding.
pg.showDEXPasswordModal(pg.connectServerAndPrepareForBonding)
pg.isLoading = true
if !dexc.InitializedWithPassword() || len(pg.dexPass) > 0 {
go func() {
pg.connectServerAndPrepareForBonding()
pg.isLoading = false
}()
break
}

pg.isLoading = true
go func() {
// If the user has already initialized using their dex seed and we
// don't have a cache because they navigated away from this page,
// prompt the user to provide their password now so we can use
// dexClient.DiscoverAccount in
// pg.connectServerAndPrepareForBonding.
// Note: User is already logged in from before, but we don't have a
// temporary cache to work with, so just ask for the password.
// Re-login is a no-op.
callbackFn := func(password string) {
pg.dexPass = []byte(password)
pg.connectServerAndPrepareForBonding()
pg.isLoading = false
}()
}

dexPasswordModal := dexLoginModal(pg.Load, pg.AssetsManager.DexClient(), callbackFn).
Title(values.String(values.StrDexPassword)).
SetDescription("").
SetNegativeButtonCallback(func() {
pg.isLoading = false
})
pg.ParentWindow().ShowModal(dexPasswordModal)

case onboardingPostBond:
// Validate all input fields.
Expand All @@ -1013,18 +1031,14 @@ func (pg *DEXOnboarding) HandleUserInteractions() {
}

pg.isLoading = true
if dexc.InitializedWithPassword() {
go func() {
go func() {
if dexc.InitializedWithPassword() {
pg.postBond()
pg.isLoading = false
}()

break
}
return
}

// DEX has not been initialized with a password, do it now.
go func() {
// Set password.
// DEX has not been initialized with a password, do it now.
pg.dexPass = []byte(pg.passwordEditor.Editor.Text())
if err := dexc.InitWithPassword(pg.dexPass, nil); err != nil {
pg.isLoading = false
Expand Down Expand Up @@ -1079,32 +1093,6 @@ func (pg *DEXOnboarding) HandleUserInteractions() {
}
}

func (pg *DEXOnboarding) showDEXPasswordModal(callbackFn func()) {
dexPasswordModal := modal.NewCreatePasswordModal(pg.Load).
EnableName(false).
EnableConfirmPassword(false).
Title(values.String(values.StrDexPassword)).
PasswordHint(values.String(values.StrDexPassword)).
SetNegativeButtonCallback(func() {
pg.isLoading = false
}).
SetPositiveButtonCallback(func(_, password string, pm *modal.CreatePasswordModal) bool {
pg.dexPass = []byte(password)
err := pg.AssetsManager.DexClient().Login(pg.dexPass)
if err != nil {
pm.SetError(err.Error())
pm.SetLoading(false)
return false
}

callbackFn()
pg.isLoading = false
return true
})
dexPasswordModal.SetPasswordTitleVisibility(false)
pg.ParentWindow().ShowModal(dexPasswordModal)
}

func (pg *DEXOnboarding) setAddServerStep() {
var dropdownServers []cryptomaterial.DropDownItem
if pg.existingDEXServer == "" {
Expand Down Expand Up @@ -1358,7 +1346,10 @@ func (pg *DEXOnboarding) checkForPendingBondPayment(host string) {
return
}

waitForBondTx := func() {
// waitForBondTx prepares the required information to display the
// onBoardingStepWaitForConfirmation page and sets up a listener for pending
// bond(s).
waitForBondTx := func(_ string) {
pg.newTier = 1
pg.currentStep = onBoardingStepWaitForConfirmation
pg.bondConfirmationInfo = &bondConfirmationInfo{
Expand Down Expand Up @@ -1386,13 +1377,13 @@ func (pg *DEXOnboarding) checkForPendingBondPayment(host string) {

dexClient := pg.AssetsManager.DexClient()
if dexClient.IsLoggedIn() {
waitForBondTx()
waitForBondTx("")
return
}

dexPasswordModal := dexLoginModal(pg.Load, dexClient, waitForBondTx)
dexPasswordModal.SetDescription(values.String(values.StrLoginDEXForPendingBonds))
dexPasswordModal.SetNegativeButtonCallback(waitForBondTx) // We'll display a form for them to login.
dexPasswordModal.SetNegativeButtonCallback(func() { waitForBondTx("") }) // We'll display a form for them to login.
pg.ParentWindow().ShowModal(dexPasswordModal)
}

Expand Down
4 changes: 2 additions & 2 deletions ui/page/dcrdex/market.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ func (pg *DEXMarketPage) OnNavigatedTo() {
pg.ParentWindow().ShowModal(dexLoginModal(pg.Load, dexc, nil))
}

func dexLoginModal(load *load.Load, dexClient libwallet.DEXClient, positiveBtnCallback func()) *modal.CreatePasswordModal {
func dexLoginModal(load *load.Load, dexClient libwallet.DEXClient, positiveBtnCallback func(password string)) *modal.CreatePasswordModal {
dexPasswordModal := modal.NewCreatePasswordModal(load).
EnableName(false).
EnableConfirmPassword(false).
Expand All @@ -306,7 +306,7 @@ func dexLoginModal(load *load.Load, dexClient libwallet.DEXClient, positiveBtnCa
}

if positiveBtnCallback != nil {
positiveBtnCallback()
positiveBtnCallback(password)
}
return true
}).SetCancelable(false)
Expand Down

0 comments on commit 0eb2d2b

Please sign in to comment.