Skip to content

Commit

Permalink
Fix crash after importing a watch-only wallet and clicking the send b…
Browse files Browse the repository at this point in the history
…utton (#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
  • Loading branch information
JustinBeBoy authored Oct 27, 2023
1 parent bd8906e commit f226afd
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 7 deletions.
3 changes: 2 additions & 1 deletion libwallet/assets/dcr/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions ui/cryptomaterial/slider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]),
Expand Down Expand Up @@ -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
}
Expand Down
22 changes: 21 additions & 1 deletion ui/page/root/home_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
}
}
Expand Down Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions ui/values/localizable/en.go
Original file line number Diff line number Diff line change
Expand Up @@ -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."
`
1 change: 1 addition & 0 deletions ui/values/strings.go
Original file line number Diff line number Diff line change
Expand Up @@ -897,4 +897,5 @@ const (
StrBondStrengthErrMsg = "bondStrengthErrMsg"
StrMinimumBondStrength = "minimumBondStrength"
StrAssets = "assets"
StrNoWalletsAvailable = "noWalletsAvailable"
)
3 changes: 3 additions & 0 deletions ui/window.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})

Expand Down

0 comments on commit f226afd

Please sign in to comment.