Skip to content

Commit

Permalink
add loader widget to confirmation box (planetdecred#400)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
dreacot committed May 12, 2021
1 parent 5543702 commit 9e99f38
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
18 changes: 18 additions & 0 deletions ui/modal_templates.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -54,6 +56,7 @@ type modalLoad struct {
template string
title string
confirm interface{}
loading bool
confirmText string
cancel interface{}
cancelText string
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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)
})
}),
Expand All @@ -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())
}
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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())
}
Expand All @@ -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() {
Expand Down
12 changes: 12 additions & 0 deletions ui/send_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}),
Expand Down Expand Up @@ -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("")
Expand Down Expand Up @@ -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
}
Expand All @@ -1098,6 +1109,7 @@ func (pg *sendPage) Handle(c pageCommon) {
}

for pg.closeConfirmationModalButton.Button.Clicked() {
c.modalLoad.setLoading(false)
pg.isConfirmationModalOpen = false
}

Expand Down

0 comments on commit 9e99f38

Please sign in to comment.