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

Convert all Toast alerts to Modals #1039

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 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
3 changes: 2 additions & 1 deletion ui/decredmaterial/icon_gallery.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type Icons struct {
ContentAdd, NavigationCheck, NavigationMore, ActionCheckCircle, ActionInfo, NavigationArrowBack,
NavigationArrowForward, ActionCheck, ChevronRight, NavigationCancel, NavMoreIcon,
ImageBrightness1, ContentClear, DropDownIcon, Cached, ContentRemove, ConcealIcon, RevealIcon,
SearchIcon, PlayIcon *widget.Icon
SearchIcon, PlayIcon, ErrorIcon *widget.Icon
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not needed as the icon used for the modal on the mockup already exist.

image


OverviewIcon, OverviewIconInactive, WalletIcon, WalletIconInactive, MixerInactive, RedAlert,
ReceiveIcon, Transferred, TransactionsIcon, TransactionsIconInactive, SendIcon, MoreIcon, MoreIconInactive,
Expand Down Expand Up @@ -59,6 +59,7 @@ func (i *Icons) StandardMaterialIcons() *Icons {
i.RevealIcon = MustIcon(widget.NewIcon(icons.ActionVisibilityOff))
i.SearchIcon = MustIcon(widget.NewIcon(icons.ActionSearch))
i.PlayIcon = MustIcon(widget.NewIcon(icons.AVPlayArrow))
i.ErrorIcon = MustIcon(widget.NewIcon(icons.AlertError))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not needed.


return i
}
Expand Down
11 changes: 9 additions & 2 deletions ui/modal/create_watch_only_modal.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,19 @@ func (cm *CreateWatchOnlyModal) Handle() {
matchedWalletID, err := cm.WL.MultiWallet.WalletWithXPub(cm.extendedPubKey.Editor.Text())
if err != nil {
log.Errorf("Error checking xpub: %v", err)
cm.Toast.NotifyError(values.StringF(values.StrXpubKeyErr, err)) // Error maybe useful to user.
errorModal := NewErrorModal(cm.Load, values.StringF(values.StrXpubKeyErr, err), func(isChecked bool) bool {
return true
})
cm.ParentWindow().ShowModal(errorModal)

return
}

if matchedWalletID != -1 {
cm.Toast.NotifyError(values.String(values.StrXpubWalletExist))
errorModal := NewErrorModal(cm.Load, values.String(values.StrXpubWalletExist), func(isChecked bool) bool {
return true
})
cm.ParentWindow().ShowModal(errorModal)
return
}

Expand Down
88 changes: 70 additions & 18 deletions ui/modal/info_modal.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"gioui.org/io/key"
"gioui.org/layout"
"gioui.org/text"
"gioui.org/unit"
"gioui.org/widget/material"

"github.com/planetdecred/godcr/ui/decredmaterial"
Expand All @@ -17,8 +18,6 @@ type InfoModal struct {
*load.Load
*decredmaterial.Modal

enterKeyPressed bool

dialogIcon *decredmaterial.Icon

dialogTitle string
Expand All @@ -28,7 +27,8 @@ type InfoModal struct {

positiveButtonText string
positiveButtonClicked func(isChecked bool) bool
btnPositve decredmaterial.Button
btnPositive decredmaterial.Button
btnPositiveWidth unit.Dp

negativeButtonText string
negativeButtonClicked func()
Expand All @@ -44,30 +44,74 @@ type InfoModal struct {
isLoading bool
}

// ButtonType is the type of button in modal.
type ButtonType uint8

const (
Normal ButtonType = iota
Outline
Danger
)

func NewInfoModal(l *load.Load) *InfoModal {
return NewInfoModalWithKey(l, "info_modal")
return NewInfoModalWithKey(l, "info_modal", Outline)
}

func NewInfoModalWithKey(l *load.Load, key string) *InfoModal {
func NewSuccessModal(l *load.Load, title string, clicked func(isChecked bool) bool) *InfoModal {
icon := decredmaterial.NewIcon(l.Theme.Icons.ActionCheckCircle)
icon.Color = l.Theme.Color.Green500
return NewNotice(l, title, icon, clicked)
}

func NewErrorModal(l *load.Load, title string, clicked func(isChecked bool) bool) *InfoModal {
icon := decredmaterial.NewIcon(l.Theme.Icons.ErrorIcon)
icon.Color = l.Theme.Color.Danger
return NewNotice(l, title, icon, clicked)
}

func NewNotice(l *load.Load, title string, icon *decredmaterial.Icon, clicked func(isChecked bool) bool) *InfoModal {
info := NewInfoModalWithKey(l, "info_modal", Normal)
info.positiveButtonText = values.String(values.StrOk)
info.positiveButtonClicked = clicked
info.btnPositiveWidth = values.MarginPadding100
info.dialogIcon = icon
info.dialogTitle = title
info.titleAlignment = layout.Center
info.btnAlignment = layout.Center
return info
}

func NewInfoModalWithKey(l *load.Load, key string, btnPositiveType ButtonType) *InfoModal {

in := &InfoModal{
Load: l,
Modal: l.Theme.ModalFloatTitle(key),
btnPositve: l.Theme.OutlineButton(values.String(values.StrYes)),
btnNegative: l.Theme.OutlineButton(values.String(values.StrNo)),
isCancelable: true,
isLoading: false,
btnAlignment: layout.E,
Load: l,
Modal: l.Theme.ModalFloatTitle(key),
btnNegative: l.Theme.OutlineButton(values.String(values.StrNo)),
isCancelable: true,
isLoading: false,
btnAlignment: layout.E,
btnPositiveWidth: 0,
}

in.btnPositve.Font.Weight = text.Medium
in.btnPositive = getPositiveButtonType(l, btnPositiveType)
in.btnPositive.Font.Weight = text.Medium
in.btnNegative.Font.Weight = text.Medium

in.materialLoader = material.Loader(l.Theme.Base)

return in
}

func getPositiveButtonType(l *load.Load, btnType ButtonType) decredmaterial.Button {
if btnType == Normal {
return l.Theme.Button(values.String(values.StrYes))
} else if btnType == Outline {
return l.Theme.OutlineButton(values.String(values.StrYes))
} else {
return l.Theme.DangerButton(values.String(values.StrYes))
}
}

func (in *InfoModal) OnResume() {}

func (in *InfoModal) OnDismiss() {}
Expand Down Expand Up @@ -116,7 +160,12 @@ func (in *InfoModal) PositiveButton(text string, clicked func(isChecked bool) bo
}

func (in *InfoModal) PositiveButtonStyle(background, text color.NRGBA) *InfoModal {
in.btnPositve.Background, in.btnPositve.Color = background, text
in.btnPositive.Background, in.btnPositive.Color = background, text
return in
}

func (in *InfoModal) PositiveButtonWidth(width unit.Dp) *InfoModal {
in.btnPositiveWidth = width
return in
}

Expand Down Expand Up @@ -173,12 +222,12 @@ func (in *InfoModal) KeysToHandle() key.Set {
// window that match any of the key combinations returned by KeysToHandle().
// Satisfies the load.KeyEventHandler interface for receiving key events.
func (in *InfoModal) HandleKeyPress(evt *key.Event) {
in.btnPositve.Click()
in.btnPositive.Click()
in.ParentWindow().Reload()
}

func (in *InfoModal) Handle() {
for in.btnPositve.Clicked() {
for in.btnPositive.Clicked() {
if in.isLoading {
return
}
Expand Down Expand Up @@ -311,9 +360,12 @@ func (in *InfoModal) actionButtonsLayout() layout.Widget {
return layout.Dimensions{}
}

in.btnPositve.Text = in.positiveButtonText
in.btnPositive.Text = in.positiveButtonText
gtx.Constraints.Max.X = gtx.Dp(values.MarginPadding250)
return in.btnPositve.Layout(gtx)
if in.btnPositiveWidth > 0 {
gtx.Constraints.Min.X = gtx.Dp(in.btnPositiveWidth)
}
return in.btnPositive.Layout(gtx)
}),
)
})
Expand Down
10 changes: 5 additions & 5 deletions ui/modal/text_input_modal.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type TextInputModal struct {

func NewTextInputModal(l *load.Load) *TextInputModal {
tm := &TextInputModal{
InfoModal: NewInfoModalWithKey(l, "text_input_modal"),
InfoModal: NewInfoModalWithKey(l, "text_input_modal", Outline),
isCancelable: true,
}

Expand Down Expand Up @@ -65,7 +65,7 @@ func (tm *TextInputModal) PositiveButton(text string, callback func(string, *Tex
}

func (tm *TextInputModal) PositiveButtonStyle(background, text color.NRGBA) *TextInputModal {
tm.positiveButtonColor, tm.btnPositve.Color = background, text
tm.positiveButtonColor, tm.btnPositive.Color = background, text
return tm
}

Expand Down Expand Up @@ -93,10 +93,10 @@ func (tm *TextInputModal) SetTextWithTemplate(template string) *TextInputModal {
func (tm *TextInputModal) Handle() {

if editorsNotEmpty(tm.textInput.Editor) {
tm.btnPositve.Background = tm.positiveButtonColor
tm.btnPositive.Background = tm.positiveButtonColor
tm.isEnabled = true
} else {
tm.btnPositve.Background = tm.Theme.Color.Gray3
tm.btnPositive.Background = tm.Theme.Color.Gray3
tm.isEnabled = false
}

Expand All @@ -105,7 +105,7 @@ func (tm *TextInputModal) Handle() {
tm.textInput.SetError("")
}

if (tm.btnPositve.Clicked() || isSubmit) && tm.isEnabled {
if (tm.btnPositive.Clicked() || isSubmit) && tm.isEnabled {
if tm.isLoading {
return
}
Expand Down
16 changes: 13 additions & 3 deletions ui/page/components/dexserver_selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/planetdecred/godcr/app"
"github.com/planetdecred/godcr/ui/decredmaterial"
"github.com/planetdecred/godcr/ui/load"
"github.com/planetdecred/godcr/ui/modal"
"github.com/planetdecred/godcr/ui/values"
)

Expand Down Expand Up @@ -60,23 +61,32 @@ func (ds *DexServerSelector) isLoadingDexClient() bool {
func (ds *DexServerSelector) startDexClient() {
_, err := ds.WL.MultiWallet.StartDexClient()
if err != nil {
ds.Toast.NotifyError(err.Error())
errModal := modal.NewErrorModal(ds.Load, err.Error(), func(isChecked bool) bool {
return true
})
ds.ParentWindow().ShowModal(errModal)
return
}

// TODO: move to dcrlibwallet sine bypass Dex password by DEXClientPass
if !ds.Dexc().Initialized() {
err = ds.Dexc().InitializeWithPassword([]byte(values.DEXClientPass))
if err != nil {
ds.Toast.NotifyError(err.Error())
errModal := modal.NewErrorModal(ds.Load, err.Error(), func(isChecked bool) bool {
return true
})
ds.ParentWindow().ShowModal(errModal)
return
}
}

if !ds.Dexc().IsLoggedIn() {
err := ds.Dexc().Login([]byte(values.DEXClientPass))
if err != nil {
ds.Toast.NotifyError(err.Error())
errModal := modal.NewErrorModal(ds.Load, err.Error(), func(isChecked bool) bool {
return true
})
ds.ParentWindow().ShowModal(errModal)
return
}
}
Expand Down
6 changes: 5 additions & 1 deletion ui/page/components/vsp_selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/planetdecred/godcr/app"
"github.com/planetdecred/godcr/ui/decredmaterial"
"github.com/planetdecred/godcr/ui/load"
"github.com/planetdecred/godcr/ui/modal"
"github.com/planetdecred/godcr/ui/values"
)

Expand Down Expand Up @@ -166,7 +167,10 @@ func (v *vspSelectorModal) Handle() {
go func() {
err := v.WL.MultiWallet.SaveVSP(v.inputVSP.Editor.Text())
if err != nil {
v.Toast.NotifyError(err.Error())
errModal := modal.NewErrorModal(v.Load, err.Error(), func(isChecked bool) bool {
return true
})
v.ParentWindow().ShowModal(errModal)
} else {
v.inputVSP.Editor.SetText("")
}
Expand Down
10 changes: 8 additions & 2 deletions ui/page/components/wallet_selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,16 @@ func (ws *WalletSelector) deleteBadWallet(badWalletID int) {
go func() {
err := ws.WL.MultiWallet.DeleteBadWallet(badWalletID)
if err != nil {
ws.Toast.NotifyError(err.Error())
errorModal := modal.NewErrorModal(ws.Load, err.Error(), func(isChecked bool) bool {
return true
})
ws.ParentWindow().ShowModal(errorModal)
return
}
ws.Toast.Notify(values.String(values.StrWalletRemoved))
infoModal := modal.NewSuccessModal(ws.Load, values.String(values.StrWalletRemoved), func(isChecked bool) bool {
return true
})
ws.ParentWindow().ShowModal(infoModal)
ws.loadBadWallets() // refresh bad wallets list
ws.ParentWindow().Reload()
}()
Expand Down
10 changes: 7 additions & 3 deletions ui/page/debug_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,15 @@ func (pg *DebugPage) resetDexData() {
Body(values.String(values.StrDexResetInfo)).
NegativeButton(values.String(values.StrCancel), func() {}).
PositiveButton(values.String(values.StrResetDexClient), func(isChecked bool) bool {
suc := modal.NewErrorModal(pg.Load, values.StrDexDataResetFalse, func(isChecked bool) bool {
return true
})
if pg.Dexc().Reset() {
pg.Toast.Notify("DEX client data reset complete.")
} else {
pg.Toast.NotifyError("DEX client data reset failed. Check the logs.")
suc = modal.NewSuccessModal(pg.Load, values.StrDexDataReset, func(isChecked bool) bool {
return true
})
}
pg.ParentWindow().ShowModal(suc)
return true
})
pg.ParentWindow().ShowModal(confirmModal)
Expand Down
5 changes: 4 additions & 1 deletion ui/page/dexclient/add_dex_modal.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,10 @@ func (md *AddDexModal) doAddDexServer(serverAddr string) {

dexServer, paid, err := md.Dexc().Core().DiscoverAccount(serverAddr, []byte(DEXClientPass), cert)
if err != nil {
md.Toast.NotifyError(err.Error())
errorModal := modal.NewErrorModal(md.Load, err.Error(), func(isChecked bool) bool {
return true
})
md.ParentWindow().ShowModal(errorModal)
return
}

Expand Down
17 changes: 13 additions & 4 deletions ui/page/governance/agenda_vote_modal.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/planetdecred/dcrlibwallet"
"github.com/planetdecred/godcr/ui/decredmaterial"
"github.com/planetdecred/godcr/ui/load"
"github.com/planetdecred/godcr/ui/modal"
"github.com/planetdecred/godcr/ui/page/components"
"github.com/planetdecred/godcr/ui/values"
)
Expand Down Expand Up @@ -92,7 +93,10 @@ func (avm *agendaVoteModal) FetchUnspentUnexpiredTickets(walletID int) {
wallet := avm.WL.MultiWallet.WalletWithID(walletID)
tickets, err := wallet.UnspentUnexpiredTickets()
if err != nil {
avm.Toast.NotifyError(err.Error())
errorModal := modal.NewErrorModal(avm.Load, err.Error(), func(isChecked bool) bool {
return true
})
avm.ParentWindow().ShowModal(errorModal)
return
}

Expand Down Expand Up @@ -234,12 +238,17 @@ func (avm *agendaVoteModal) sendVotes() {
if err.Error() == dcrlibwallet.ErrInvalidPassphrase {
avm.spendingPassword.SetError(values.String(values.StrInvalidPassphrase))
} else {
avm.Toast.NotifyError(err.Error())
errorModal := modal.NewErrorModal(avm.Load, err.Error(), func(isChecked bool) bool {
return true
})
avm.ParentWindow().ShowModal(errorModal)
}
return
}
avm.Toast.Notify(values.String(values.StrVoteUpdated))

successModal := modal.NewSuccessModal(avm.Load, values.String(values.StrVoteUpdated), func(isChecked bool) bool {
return true
})
avm.ParentWindow().ShowModal(successModal)
avm.Dismiss()
avm.onPreferenceUpdated()
}()
Expand Down
Loading