Skip to content

Commit

Permalink
unexport modal.SetLoading and allow modals show loading btn
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 21f77d9 commit f6fc430
Show file tree
Hide file tree
Showing 30 changed files with 49 additions and 91 deletions.
6 changes: 4 additions & 2 deletions ui/modal/create_password_modal.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func (cm *CreatePasswordModal) SetNegativeButtonCallback(callback func()) *Creat
return cm
}

func (cm *CreatePasswordModal) SetLoading(loading bool) {
func (cm *CreatePasswordModal) setLoading(loading bool) {
cm.isLoading = loading
cm.Modal.SetDisabled(loading)
}
Expand Down Expand Up @@ -235,11 +235,13 @@ func (cm *CreatePasswordModal) Handle() {
return
}
}
cm.SetLoading(true)
cm.setLoading(true)
go func() {
if cm.positiveButtonClicked(cm.walletName.Editor.Text(), cm.passwordEditor.Editor.Text(), cm) {
cm.Dismiss()
return
}
cm.setLoading(false)
}()
}

Expand Down
14 changes: 9 additions & 5 deletions ui/modal/create_watch_only_modal.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (cm *CreateWatchOnlyModal) EnableName(enable bool) *CreateWatchOnlyModal {
return cm
}

func (cm *CreateWatchOnlyModal) SetLoading(loading bool) {
func (cm *CreateWatchOnlyModal) setLoading(loading bool) {
cm.isLoading = loading
cm.Modal.SetDisabled(loading)
}
Expand Down Expand Up @@ -140,10 +140,14 @@ func (cm *CreateWatchOnlyModal) Handle() {
return
}

cm.SetLoading(true)
if cm.callback(cm.walletName.Editor.Text(), cm.extendedPubKey.Editor.Text(), cm) {
cm.Dismiss()
}
cm.setLoading(true)
go func() {
if cm.callback(cm.walletName.Editor.Text(), cm.extendedPubKey.Editor.Text(), cm) {
cm.Dismiss()
return
}
cm.setLoading(false)
}()
}

cm.btnNegative.SetEnabled(!cm.isLoading)
Expand Down
7 changes: 4 additions & 3 deletions ui/modal/info_modal.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func (in *InfoModal) CheckBox(checkbox cryptomaterial.CheckBoxStyle, mustBeCheck
return in
}

func (in *InfoModal) SetLoading(loading bool) {
func (in *InfoModal) setLoading(loading bool) {
in.isLoading = loading
in.Modal.SetDisabled(loading)
}
Expand Down Expand Up @@ -298,12 +298,13 @@ func (in *InfoModal) Handle() {
isChecked = in.checkbox.CheckBox.Value
}

in.SetLoading(true)
in.setLoading(true)
go func() {
if in.positiveButtonClicked(isChecked, in) {
in.Dismiss()
return
}
in.SetLoading(false)
in.setLoading(false)
}()
}

Expand Down
14 changes: 9 additions & 5 deletions ui/modal/text_input_modal.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (tm *TextInputModal) Hint(hint string) *TextInputModal {
return tm
}

func (tm *TextInputModal) SetLoading(loading bool) {
func (tm *TextInputModal) setLoading(loading bool) {
tm.isLoading = loading
tm.Modal.SetDisabled(loading)
}
Expand Down Expand Up @@ -115,11 +115,15 @@ func (tm *TextInputModal) Handle() {
return
}

tm.SetLoading(true)
tm.setLoading(true)
tm.SetError("")
if tm.callback(tm.textInput.Editor.Text(), tm) {
tm.Dismiss()
}
go func() {
if tm.callback(tm.textInput.Editor.Text(), tm) {
tm.Dismiss()
return
}
tm.setLoading(false)
}()
}

for tm.btnNegative.Clicked() {
Expand Down
1 change: 0 additions & 1 deletion ui/page/accounts/accounts_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,6 @@ func (pg *Page) HandleUserInteractions() {
_, err := pg.wallet.CreateNewAccount(accountName, password)
if err != nil {
m.SetError(err.Error())
m.SetLoading(false)
return false
}
pg.loadWalletAccount()
Expand Down
1 change: 0 additions & 1 deletion ui/page/accounts/btc_account_details_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,6 @@ func (pg *BTCAcctDetailsPage) HandleUserInteractions() {
err := pg.wallet.RenameAccount(int32(pg.account.AccountNumber), newName)
if err != nil {
tim.SetError(err.Error())
tim.SetLoading(false)
return false
}
pg.account.AccountName = newName
Expand Down
1 change: 0 additions & 1 deletion ui/page/accounts/dcr_account_details_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,6 @@ func (pg *AcctDetailsPage) HandleUserInteractions() {
err := pg.wallet.RenameAccount(pg.account.Number, newName)
if err != nil {
tim.SetError(err.Error())
tim.SetLoading(false)
return false
}
pg.account.Name = newName
Expand Down
1 change: 0 additions & 1 deletion ui/page/accounts/ltc_account_details_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,6 @@ func (pg *LTCAcctDetailsPage) HandleUserInteractions() {
err := pg.wallet.RenameAccount(int32(pg.account.AccountNumber), newName)
if err != nil {
tim.SetError(err.Error())
tim.SetLoading(false)
return false
}
pg.account.AccountName = newName
Expand Down
1 change: 0 additions & 1 deletion ui/page/components/restore_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,6 @@ func (pg *Restore) restoreFromSeedEditor() {
errString = values.StringF(values.StrWalletExist, pg.walletName)
}
m.SetError(errString)
m.SetLoading(false)
clearEditor()
return false
}
Expand Down
1 change: 0 additions & 1 deletion ui/page/components/seed_restore_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,6 @@ func (pg *SeedRestore) HandleUserInteractions() {
errString = values.StringF(values.StrWalletExist, pg.walletName)
}
m.SetError(errString)
m.SetLoading(false)
pg.isRestoring = false
return false
}
Expand Down
1 change: 0 additions & 1 deletion ui/page/dcrdex/dex_onboarding_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -1024,7 +1024,6 @@ func (pg *DEXOnboarding) HandleUserInteractions() {

pg.isLoading = false
pm.SetError(err.Error())
pm.SetLoading(false)
return false
})
dexPasswordModal.SetPasswordTitleVisibility(false)
Expand Down
4 changes: 0 additions & 4 deletions ui/page/dcrdex/market.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,6 @@ func (pg *DEXMarketPage) OnNavigatedTo() {
}

pm.SetError(err.Error())
pm.SetLoading(false)
return false
}).SetCancelable(false)
dexPasswordModal.SetPasswordTitleVisibility(false)
Expand Down Expand Up @@ -1591,7 +1590,6 @@ func (pg *DEXMarketPage) HandleUserInteractions() {
defer func() {
if err != nil {
pm.SetError(err.Error())
pm.SetLoading(false)
}
pg.showLoader = false
}()
Expand Down Expand Up @@ -1702,7 +1700,6 @@ func (pg *DEXMarketPage) showSelectDEXWalletModal(missingWallet libutils.AssetTy
err := pg.createMissingMarketWallet(missingWallet, dexPass, walletPass)
if err != nil {
pm.SetError(err.Error())
pm.SetLoading(false)
return false
}

Expand All @@ -1720,7 +1717,6 @@ func (pg *DEXMarketPage) showSelectDEXWalletModal(missingWallet libutils.AssetTy
err := pg.AssetsManager.DexClient().Login([]byte(password))
if err != nil {
pm.SetError(err.Error())
pm.SetLoading(false)
return false
}

Expand Down
25 changes: 14 additions & 11 deletions ui/page/exchange/confirm_order_modal.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (com *confirmOrderModal) SetError(err string) {
com.passwordEditor.SetError(values.TranslateErr(err))
}

func (com *confirmOrderModal) SetLoading(loading bool) {
func (com *confirmOrderModal) setLoading(loading bool) {
com.isCreating = loading
com.Modal.SetDisabled(loading)
}
Expand All @@ -102,40 +102,44 @@ func (com *confirmOrderModal) confirmOrder() {
return
}

com.SetLoading(true)
com.setLoading(true)
go func() {
var err error
defer func() {
if err != nil {
com.setLoading(false)
}
}()

if !com.sourceWalletSelector.SelectedWallet().IsSynced() {
com.SetError(values.String(values.StrSourceWalletNotSynced))
com.SetLoading(false)
err = errors.New(values.String(values.StrSourceWalletNotSynced))
com.SetError(err.Error())
return
}

if !com.destinationWalletSelector.SelectedWallet().IsSynced() {
com.SetError(values.String(values.StrDestinationWalletNotSynced))
com.SetLoading(false)
err = errors.New(values.String(values.StrDestinationWalletNotSynced))
com.SetError(err.Error())
return
}

err := com.sourceWalletSelector.SelectedWallet().UnlockWallet(password)
err = com.sourceWalletSelector.SelectedWallet().UnlockWallet(password)
if err != nil {
com.SetError(err.Error())
com.SetLoading(false)
return
}

order, err := com.createOrder()
if err != nil {
log.Error(errors.E(errors.Op("instantSwap.CreateOrder"), err))
com.SetError(err.Error())
com.SetLoading(false)
return
}

err = com.constructTx(order.DepositAddress, order.InvoicedAmount)
if err != nil {
com.AssetsManager.InstantSwap.DeleteOrder(order)
com.SetError(err.Error())
com.SetLoading(false)
return
}

Expand All @@ -144,7 +148,6 @@ func (com *confirmOrderModal) confirmOrder() {
if err != nil {
com.AssetsManager.InstantSwap.DeleteOrder(order)
com.SetError(err.Error())
com.SetLoading(false)
return
}

Expand Down
8 changes: 3 additions & 5 deletions ui/page/exchange/order_scheduler_modal.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func (osm *orderSchedulerModal) OnResume() {
osm.ctx, osm.ctxCancel = context.WithCancel(context.TODO())
}

func (osm *orderSchedulerModal) SetLoading(loading bool) {
func (osm *orderSchedulerModal) setLoading(loading bool) {
osm.isStarting = loading
osm.Modal.SetDisabled(loading)
}
Expand Down Expand Up @@ -460,14 +460,12 @@ func (osm *orderSchedulerModal) Layout(gtx layout.Context) D {
}

func (osm *orderSchedulerModal) startOrderScheduler() {
// osm.SetLoading(true)

go func() {
osm.SetLoading(true)
osm.setLoading(true)
err := osm.sourceWalletSelector.SelectedWallet().UnlockWallet(osm.passwordEditor.Editor.Text())
if err != nil {
osm.SetError(err.Error())
osm.SetLoading(false)
osm.setLoading(false)
return
}

Expand Down
2 changes: 1 addition & 1 deletion ui/page/exchange/order_settings_modal.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func (osm *orderSettingsModal) OnResume() {
go osm.feeRateSelector.UpdatedFeeRate(osm.sourceWalletSelector.SelectedWallet())
}

func (osm *orderSettingsModal) SetLoading(loading bool) {
func (osm *orderSettingsModal) setLoading(loading bool) {
osm.Modal.SetDisabled(loading)
}

Expand Down
2 changes: 0 additions & 2 deletions ui/page/governance/agenda_vote_modal.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,10 @@ func (avm *agendaVoteModal) sendVotes(_, password string, _ *modal.CreatePasswor
err := avm.dcrImpl.SetVoteChoice(avm.agenda.AgendaID, avm.voteChoice, "", password)
if err != nil {
avm.CreatePasswordModal.SetError(err.Error())
avm.CreatePasswordModal.SetLoading(false)
return false
}
successModal := modal.NewSuccessModal(avm.Load, values.String(values.StrVoteUpdated), modal.DefaultClickFunc())
avm.ParentWindow().ShowModal(successModal)
avm.Dismiss()
avm.onPreferenceUpdated()
return true
}
1 change: 0 additions & 1 deletion ui/page/governance/proposal_vote_modal.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ func (vm *voteModal) sendVotes() {
err := vm.AssetsManager.Politeia.CastVotes(ctx, w, libwallet.ConvertVotes(votes), vm.proposal.Token, password)
if err != nil {
pm.SetError(err.Error())
pm.SetLoading(false)
return false
}
vm.Dismiss()
Expand Down
1 change: 0 additions & 1 deletion ui/page/governance/treasury_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,6 @@ func (pg *TreasuryPage) updatePolicyPreference(treasuryItem *components.Treasury
err := pg.selectedDCRWallet.SetTreasuryPolicy(treasuryItem.Policy.PiKey, votingPreference, "", password)
if err != nil {
pm.SetError(err.Error())
pm.SetLoading(false)
return false
}

Expand Down
1 change: 0 additions & 1 deletion ui/page/privacy/account_mixer_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,6 @@ func (pg *AccountMixerPage) showModalPasswordStartAccountMixer() {
err := pg.dcrWallet.StartAccountMixer(password)
if err != nil {
pg.Toast.NotifyError(err.Error())
pm.SetLoading(false)
return
}
pm.Dismiss()
Expand Down
1 change: 0 additions & 1 deletion ui/page/privacy/manual_mixer_setup_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,6 @@ func (pg *ManualMixerSetupPage) showModalSetupMixerAcct() {
SetPositiveButtonCallback(func(_, password string, pm *modal.CreatePasswordModal) bool {
errfunc := func(err error) bool {
pm.SetError(err.Error())
pm.SetLoading(false)
return false
}
mixedAcctNumber := pg.mixedAccountSelector.SelectedAccount().Number
Expand Down
1 change: 0 additions & 1 deletion ui/page/privacy/shared_modals.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ func showModalSetupMixerAcct(conf *sharedModalConfig, dcrWallet *dcr.Asset, move
err := dcrWallet.CreateMixerAccounts(values.String(values.StrMixed), values.String(values.StrUnmixed), password)
if err != nil {
pm.SetError(err.Error())
pm.SetLoading(false)
return false
}

Expand Down
1 change: 0 additions & 1 deletion ui/page/root/home_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -944,7 +944,6 @@ func (hp *HomePage) unlockWalletForSyncing(wal sharedW.Asset, unlock load.NeedUn
err := wal.UnlockWallet(password)
if err != nil {
pm.SetError(err.Error())
pm.SetLoading(false)
return false
}
unlock(true)
Expand Down
1 change: 0 additions & 1 deletion ui/page/security/sign_message_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,6 @@ func (pg *SignMessagePage) HandleUserInteractions() {
sig, err := pg.wallet.SignMessage(password, address, message)
if err != nil {
pm.SetError(err.Error())
pm.SetLoading(false)
return false
}

Expand Down
1 change: 0 additions & 1 deletion ui/page/seedbackup/save_seed.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ func (pg *SaveSeedPage) OnNavigatedTo() {
SetPositiveButtonCallback(func(_, password string, m *modal.CreatePasswordModal) bool {
seed, err := pg.wallet.DecryptSeed(password)
if err != nil {
m.SetLoading(false)
m.SetError(err.Error())
return false
}
Expand Down
4 changes: 1 addition & 3 deletions ui/page/seedbackup/verify_seed.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,11 @@ func (pg *VerifySeedPage) verifySeed() {
return false
}

m.SetLoading(false)
m.SetError(err.Error())
return false
}
m.Dismiss()
pg.ParentNavigator().Display(NewBackupSuccessPage(pg.Load, pg.redirectCallback))

pg.ParentNavigator().Display(NewBackupSuccessPage(pg.Load, pg.redirectCallback))
return true
})
pg.ParentWindow().ShowModal(passwordModal)
Expand Down
Loading

0 comments on commit f6fc430

Please sign in to comment.