Skip to content

Commit

Permalink
allow users cancel dex active orders/expired bonds password modal
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 1, 2024
1 parent 6109a43 commit 7c64a85
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 71 deletions.
151 changes: 80 additions & 71 deletions ui/page/root/home_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,80 @@ func (hp *HomePage) initDEX() {
dexPassEditor := hp.Theme.EditorPassword(new(widget.Editor), values.String(values.StrDexPassword))
dexPassEditor.Editor.SingleLine, dexPassEditor.IsRequired = true, true

showWalletToSyncModal := func() bool {

Check failure on line 223 in ui/page/root/home_page.go

View workflow job for this annotation

GitHub Actions / Build

(*HomePage).initDEX$1$1 - result 0 (bool) is always true (unparam)
// DEX client has active orders or expired bonds, retrieve the
// wallets involved and ensure they are synced or syncing.
walletsToSyncMap := make(map[uint32]*struct{})
for _, orders := range activeOrders {
for _, ord := range orders {
walletsToSyncMap[ord.BaseID] = &struct{}{}
walletsToSyncMap[ord.QuoteID] = &struct{}{}
}
}

for _, bond := range expiredBonds {
walletsToSyncMap[bond.AssetID] = &struct{}{}
}

var walletsToSyncStr string
var walletsToSync []sharedW.Asset
for assetID := range walletsToSyncMap {
walletID, err := dexClient.WalletIDForAsset(assetID)
if err != nil {
log.Errorf("dexClient.WalletIDForAsset(%d) error: %w", assetID, err)
continue
}

if walletID == nil {
continue // impossible but better safe than sorry
}

wallet := hp.AssetsManager.WalletWithID(*walletID)
if wallet == nil { // impossible but better safe than sorry
log.Error("dex wallet with ID %d is missing", walletID)
continue
}

if wallet.IsSynced() || wallet.IsSyncing() {
continue // ok
}

walletsToSync = append(walletsToSync, wallet)
walletsToSyncStr += "," + fmt.Sprintf("%s (%s)", wallet.GetWalletName(), wallet.GetAssetType())
}

if len(walletsToSync) == 0 {
return true
}

walletSyncRequestModal := modal.NewCustomModal(hp.Load).
Title(values.String(values.StrWalletsNeedToSync)).
Body(values.StringF(values.StrWalletsNeedToSyncMsg, strings.Trim(walletsToSyncStr, ","))).
SetNegativeButtonText(values.String(values.StrIWillSyncLater)).
SetPositiveButtonText(values.String(values.StrOkaySync)).
SetPositiveButtonCallback(func(isChecked bool, im *modal.InfoModal) bool {
if !hp.isConnected.Load() {
// Notify user and return.
hp.Toast.NotifyError(values.String(values.StrNotConnected))
return false
}

for _, w := range walletsToSync {
err := w.SpvSync()
if err != nil {
log.Error(err)
} else {
w.SaveUserConfigValue(sharedW.AutoSyncConfigKey, true)
}
}

hp.ParentWindow().Reload()
return true
}).SetCancelable(false)
hp.ParentWindow().ShowModal(walletSyncRequestModal)
return true
}

loginModal := modal.NewCustomModal(hp.Load).
UseCustomWidget(func(gtx C) D {
return layout.Flex{Axis: layout.Vertical}.Layout(gtx,
Expand All @@ -231,6 +305,11 @@ func (hp *HomePage) initDEX() {
}),
)
}).
SetNegativeButtonText(values.String(values.StrLoginLater)).
NegativeButtonStyle(hp.Theme.Color.OrangeRipple, hp.Theme.Color.Surface).
SetNegativeButtonCallback(func() {
showWalletToSyncModal()
}).
SetPositiveButtonText(values.String(values.StrLogin)).
SetPositiveButtonCallback(func(isChecked bool, im *modal.InfoModal) bool {
dexPassEditor.SetError("")
Expand All @@ -240,77 +319,7 @@ func (hp *HomePage) initDEX() {
return false
}

// DEX client has active orders or expired bonds, retrieve the
// wallets involved and ensure they are synced or syncing.
walletsToSyncMap := make(map[uint32]*struct{})
for _, orders := range activeOrders {
for _, ord := range orders {
walletsToSyncMap[ord.BaseID] = &struct{}{}
walletsToSyncMap[ord.QuoteID] = &struct{}{}
}
}

for _, bond := range expiredBonds {
walletsToSyncMap[bond.AssetID] = &struct{}{}
}

var walletsToSyncStr string
var walletsToSync []sharedW.Asset
for assetID := range walletsToSyncMap {
walletID, err := dexClient.WalletIDForAsset(assetID)
if err != nil {
log.Errorf("dexClient.WalletIDForAsset(%d) error: %w", assetID, err)
continue
}

if walletID == nil {
continue // impossible but better safe than sorry
}

wallet := hp.AssetsManager.WalletWithID(*walletID)
if wallet == nil { // impossible but better safe than sorry
log.Error("dex wallet with ID %d is missing", walletID)
continue
}

if wallet.IsSynced() || wallet.IsSyncing() {
continue // ok
}

walletsToSync = append(walletsToSync, wallet)
walletsToSyncStr += "," + fmt.Sprintf("%s (%s)", wallet.GetWalletName(), wallet.GetAssetType())
}

if len(walletsToSync) == 0 {
return true
}

walletSyncRequestModal := modal.NewCustomModal(hp.Load).
Title(values.String(values.StrWalletsNeedToSync)).
Body(values.StringF(values.StrWalletsNeedToSyncMsg, strings.Trim(walletsToSyncStr, ","))).
SetNegativeButtonText(values.String(values.StrIWillSyncLater)).
SetPositiveButtonText(values.String(values.StrOkaySync)).
SetPositiveButtonCallback(func(isChecked bool, im *modal.InfoModal) bool {
if !hp.isConnected.Load() {
// Notify user and return.
hp.Toast.NotifyError(values.String(values.StrNotConnected))
return false
}

for _, w := range walletsToSync {
err := w.SpvSync()
if err != nil {
log.Error(err)
} else {
w.SaveUserConfigValue(sharedW.AutoSyncConfigKey, true)
}
}

hp.ParentWindow().Reload()
return true
})
hp.ParentWindow().ShowModal(walletSyncRequestModal)
return true
return showWalletToSyncModal()
}).
SetCancelable(false)
hp.ParentWindow().ShowModal(loginModal)
Expand Down
1 change: 1 addition & 0 deletions ui/values/localizable/en.go
Original file line number Diff line number Diff line change
Expand Up @@ -930,4 +930,5 @@ const EN = `
"backupDEXSeed" = "Backup DEX Seed"
"dexSeed" = "DEX Seed"
"optionalRestorationSeed" = "Restoration Seed (optional)"
"loginLater" = "I'll login later"
`
1 change: 1 addition & 0 deletions ui/values/strings.go
Original file line number Diff line number Diff line change
Expand Up @@ -1038,6 +1038,7 @@ const (
StrBackupDEXSeed = "backupDEXSeed"
StrDEXSeed = "dexSeed"
StrOptionalRestorationSeed = "optionalRestorationSeed"
StrLoginLater = "loginLater"

StrLoginDEXForActiveOrdersOrExpiredBonds = "loginDEXForActiveOrdersOrExpiredBonds"
)

0 comments on commit 7c64a85

Please sign in to comment.