From f226afdf36b2cf7bd8babc29e0fb8514d3d047c3 Mon Sep 17 00:00:00 2001 From: Justin Do Date: Fri, 27 Oct 2023 22:15:00 +0700 Subject: [PATCH] Fix crash after importing a watch-only wallet and clicking the send button (#200) * fix crash when import watch-only wallet and click send * add listen mixer notification and check nil when delete watch-only wallet * update logic nitices for user when they have only watch-only wallet * clean code * update new logic for check when click button send * change warning text when the app have only watch-only wallet --- libwallet/assets/dcr/wallet.go | 3 ++- ui/cryptomaterial/slider.go | 10 +++++----- ui/page/root/home_page.go | 22 +++++++++++++++++++++- ui/values/localizable/en.go | 1 + ui/values/strings.go | 1 + ui/window.go | 3 +++ 6 files changed, 33 insertions(+), 7 deletions(-) diff --git a/libwallet/assets/dcr/wallet.go b/libwallet/assets/dcr/wallet.go index 7f3df3a2b..8b4af2fec 100644 --- a/libwallet/assets/dcr/wallet.go +++ b/libwallet/assets/dcr/wallet.go @@ -155,7 +155,8 @@ func CreateWatchOnlyWallet(walletName, extendedPublicKey string, params *sharedW syncData: &SyncData{ syncProgressListeners: make(map[string]sharedW.SyncProgressListener), }, - txAndBlockNotificationListeners: make(map[string]sharedW.TxAndBlockNotificationListener), + txAndBlockNotificationListeners: make(map[string]sharedW.TxAndBlockNotificationListener), + accountMixerNotificationListener: make(map[string]AccountMixerNotificationListener), } dcrWallet.SetNetworkCancelCallback(dcrWallet.SafelyCancelSync) diff --git a/ui/cryptomaterial/slider.go b/ui/cryptomaterial/slider.go index 04118c378..660f45f05 100644 --- a/ui/cryptomaterial/slider.go +++ b/ui/cryptomaterial/slider.go @@ -57,8 +57,12 @@ func (s *Slider) Layout(gtx C, items []layout.Widget) D { s.items = items s.isSliderItemsSet = true } - s.handleClickEvent() + if len(s.items) == 0 { + return D{} + } + + s.handleClickEvent() gtx.Constraints.Max = s.items[s.selected](gtx).Size return layout.Stack{Alignment: layout.S}.Layout(gtx, layout.Expanded(s.items[s.selected]), @@ -138,10 +142,6 @@ func (s *Slider) containerLayout(gtx C, content layout.Widget) D { return s.card.Layout(gtx, content) } -func (s *Slider) centerLayout(gtx C, content layout.Widget) D { - return layout.Center.Layout(gtx, content) -} - func (s *Slider) RefreshItems() { s.isSliderItemsSet = false } diff --git a/ui/page/root/home_page.go b/ui/page/root/home_page.go index 41779b44b..34988cc11 100644 --- a/ui/page/root/home_page.go +++ b/ui/page/root/home_page.go @@ -40,7 +40,6 @@ type HomePage struct { appLevelSettingsButton *cryptomaterial.Clickable appNotificationButton *cryptomaterial.Clickable hideBalanceButton *cryptomaterial.Clickable - checkBox cryptomaterial.CheckBoxStyle infoButton cryptomaterial.IconButton // TOD0: use *cryptomaterial.Clickable bottomNavigationBar components.BottomNavigationBar @@ -215,6 +214,17 @@ func (hp *HomePage) HandleUserInteractions() { case values.StrReceive: hp.ParentWindow().ShowModal(components.NewReceiveModal(hp.Load)) case values.StrSend: + allWallets := hp.WL.AssetsManager.AllWallets() + isSendAvailable := false + for _, wallet := range allWallets { + if !wallet.IsWatchingOnlyWallet() { + isSendAvailable = true + } + } + if !isSendAvailable { + hp.showWarningNoWallet() + return + } hp.ParentWindow().ShowModal(send.NewSendPage(hp.Load, true)) } } @@ -277,6 +287,16 @@ func (hp *HomePage) HandleUserInteractions() { } } +func (hp *HomePage) showWarningNoWallet() { + go func() { + info := modal.NewCustomModal(hp.Load). + PositiveButtonStyle(hp.Theme.Color.Primary, hp.Theme.Color.Surface). + SetContentAlignment(layout.W, layout.W, layout.Center). + Body(values.String(values.StrNoWalletsAvailable)) + hp.ParentWindow().ShowModal(info) + }() +} + // KeysToHandle returns an expression that describes a set of key combinations // that this page wishes to capture. The HandleKeyPress() method will only be // called when any of these key combinations is pressed. diff --git a/ui/values/localizable/en.go b/ui/values/localizable/en.go index 142fc635d..3be8bbcdf 100644 --- a/ui/values/localizable/en.go +++ b/ui/values/localizable/en.go @@ -787,4 +787,5 @@ const EN = ` "bondStrengthErrMsg" = "Bond Strength must be a valid number" "minimumBondStrength" = "Minimum Bond Strength is %d" "assets" = "Assets" +"noWalletsAvailable" = "You cannot spend from a watch only wallet, try creating another wallet." ` diff --git a/ui/values/strings.go b/ui/values/strings.go index 97e38057a..9f4d65bab 100644 --- a/ui/values/strings.go +++ b/ui/values/strings.go @@ -897,4 +897,5 @@ const ( StrBondStrengthErrMsg = "bondStrengthErrMsg" StrMinimumBondStrength = "minimumBondStrength" StrAssets = "assets" + StrNoWalletsAvailable = "noWalletsAvailable" ) diff --git a/ui/window.go b/ui/window.go index 69d859498..0aa8bcebb 100644 --- a/ui/window.go +++ b/ui/window.go @@ -282,6 +282,9 @@ func (win *Window) prepareToDisplayUI(evt system.FrameEvent) *op.Ops { if modal := win.navigator.TopModal(); modal != nil { gtx = gtx.Disabled() } + if win.navigator.CurrentPage() == nil { + win.navigator.Display(page.NewStartPage(win.load)) + } return win.navigator.CurrentPage().Layout(gtx) })