Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add loader widget to confirmation box #400

Merged
merged 3 commits into from
May 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/dcrlibwallet"
"github.com/planetdecred/godcr/ui/decredmaterial"
Expand Down Expand Up @@ -55,6 +57,7 @@ type modalLoad struct {
template string
title string
confirm interface{}
loading bool
confirmText string
cancel interface{}
cancelText string
Expand Down Expand Up @@ -89,6 +92,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 @@ -381,6 +388,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 @@ -425,6 +433,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 @@ -445,6 +459,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 @@ -481,6 +496,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 @@ -513,6 +529,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 @@ -536,6 +553,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