From 9e99f388cdaae575f37d5fe3357c15679acb98ee Mon Sep 17 00:00:00 2001 From: kennedy Izuegbu Date: Thu, 13 May 2021 00:36:59 +0100 Subject: [PATCH] add loader widget to confirmation box (#400) * add loader to create new wallet modal * properly align the loader widget - add the loader widget to (CreateAccountTemplate, ChangePasswordTemplate, ChangeStartupPasswordTemplate, ImportWatchOnlyWalletTemplate) * add loader widget to send page --- ui/modal_templates.go | 18 ++++++++++++++++++ ui/send_page.go | 12 ++++++++++++ 2 files changed, 30 insertions(+) diff --git a/ui/modal_templates.go b/ui/modal_templates.go index f284f5438..6541c7cfa 100644 --- a/ui/modal_templates.go +++ b/ui/modal_templates.go @@ -1,10 +1,12 @@ package ui import ( + "gioui.org/font/gofont" "gioui.org/layout" "gioui.org/text" "gioui.org/unit" "gioui.org/widget" + "gioui.org/widget/material" "github.com/planetdecred/godcr/ui/decredmaterial" "github.com/planetdecred/godcr/ui/values" @@ -54,6 +56,7 @@ type modalLoad struct { template string title string confirm interface{} + loading bool confirmText string cancel interface{} cancelText string @@ -88,6 +91,10 @@ func (m *ModalTemplate) importWatchOnlyWallet() []func(gtx C) D { } } +func (load *modalLoad) setLoading(isLoading bool) { + load.loading = isLoading +} + func (m *ModalTemplate) createNewWallet() []func(gtx C) D { return []func(gtx C) D{ func(gtx C) D { @@ -380,6 +387,7 @@ func (m *ModalTemplate) Layout(th *decredmaterial.Theme, load *modalLoad) []func if !load.isReset { m.resetFields() load.isReset = true + load.setLoading(false) } title := []func(gtx C) D{ @@ -424,6 +432,12 @@ func (m *ModalTemplate) actions(th *decredmaterial.Theme, load *modalLoad) []fun if load.template == RescanWalletTemplate { m.confirm.Background, m.confirm.Color = th.Color.Surface, th.Color.Primary } + if load.loading { + th := material.NewTheme(gofont.Collection()) + return layout.Inset{Top: unit.Dp(7)}.Layout(gtx, func(gtx C) D { + return material.Loader(th).Layout(gtx) + }) + } return m.confirm.Layout(gtx) }) }), @@ -444,6 +458,7 @@ func (m *ModalTemplate) handle(th *decredmaterial.Theme, load *modalLoad) (templ if m.editorsNotEmpty(th, m.walletName.Editor, m.spendingPassword.Editor, m.matchSpendingPassword.Editor) && m.confirm.Button.Clicked() { + load.setLoading(true) if m.passwordsMatch(m.spendingPassword.Editor, m.matchSpendingPassword.Editor) { load.confirm.(func(string, string))(m.walletName.Editor.Text(), m.spendingPassword.Editor.Text()) } @@ -480,6 +495,7 @@ func (m *ModalTemplate) handle(th *decredmaterial.Theme, load *modalLoad) (templ return case CreateAccountTemplate: if m.editorsNotEmpty(th, m.walletName.Editor, m.spendingPassword.Editor) && m.confirm.Button.Clicked() { + load.setLoading(true) load.confirm.(func(string, string))(m.walletName.Editor.Text(), m.spendingPassword.Editor.Text()) } if m.cancel.Button.Clicked() { @@ -512,6 +528,7 @@ func (m *ModalTemplate) handle(th *decredmaterial.Theme, load *modalLoad) (templ if m.editorsNotEmpty(th, m.oldSpendingPassword.Editor, m.spendingPassword.Editor, m.matchSpendingPassword.Editor) && m.confirm.Button.Clicked() { + load.setLoading(true) if m.passwordsMatch(m.spendingPassword.Editor, m.matchSpendingPassword.Editor) { load.confirm.(func(string, string))(m.oldSpendingPassword.Editor.Text(), m.spendingPassword.Editor.Text()) } @@ -535,6 +552,7 @@ func (m *ModalTemplate) handle(th *decredmaterial.Theme, load *modalLoad) (templ return case ImportWatchOnlyWalletTemplate: if m.confirm.Button.Clicked() { + load.setLoading(true) load.confirm.(func(string, string))(m.walletName.Editor.Text(), m.extendedPublicKey.Editor.Text()) } if m.cancel.Button.Clicked() { diff --git a/ui/send_page.go b/ui/send_page.go index 569ad3714..ef8d153dd 100644 --- a/ui/send_page.go +++ b/ui/send_page.go @@ -7,8 +7,11 @@ import ( "strconv" "strings" + "gioui.org/font/gofont" "gioui.org/layout" + "gioui.org/unit" "gioui.org/widget" + "gioui.org/widget/material" "github.com/decred/dcrd/dcrutil" "github.com/planetdecred/dcrlibwallet" @@ -583,6 +586,12 @@ func (pg *sendPage) confirmationModal(gtx layout.Context, common pageCommon) lay }) }), layout.Rigid(func(gtx C) D { + if common.modalLoad.loading { + th := material.NewTheme(gofont.Collection()) + return layout.Inset{Top: unit.Dp(7)}.Layout(gtx, func(gtx C) D { + return material.Loader(th).Layout(gtx) + }) + } pg.confirmButton.Text = fmt.Sprintf("Send %s", dcrutil.Amount(pg.totalCostDCR).String()) return pg.confirmButton.Layout(gtx) }), @@ -920,6 +929,7 @@ func (pg *sendPage) watchForBroadcastResult(c pageCommon) { pg.isConfirmationModalOpen = false pg.isBroadcastingTransaction = false pg.resetFields() + c.modalLoad.setLoading(false) pg.broadcastResult.TxHash = "" pg.calculateValues(c) pg.destinationAddressEditor.Editor.SetText("") @@ -1076,6 +1086,7 @@ func (pg *sendPage) Handle(c pageCommon) { pg.watchForBroadcastResult(c) for pg.confirmButton.Button.Clicked() { + c.modalLoad.setLoading(true) if !pg.inputsNotEmpty(pg.passwordEditor.Editor) { return } @@ -1098,6 +1109,7 @@ func (pg *sendPage) Handle(c pageCommon) { } for pg.closeConfirmationModalButton.Button.Clicked() { + c.modalLoad.setLoading(false) pg.isConfirmationModalOpen = false }