Skip to content

Commit

Permalink
update logic wallet/account selector in send page and receive page, c…
Browse files Browse the repository at this point in the history
…lean code
  • Loading branch information
JustinBeBoy committed Jul 31, 2024
1 parent 7e89a5f commit 8513dcb
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 37 deletions.
8 changes: 8 additions & 0 deletions ui/page/components/account_dropdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ func (d *AccountDropdown) selectedIsValid() bool {
if d.selectedAccount == nil {
return false
}

if d.selectedWallet.GetWalletID() != d.selectedAccount.WalletID {
return false
}

if d.accountIsValid != nil {
if !d.accountIsValid(d.selectedAccount) {
return false
Expand Down Expand Up @@ -150,6 +155,9 @@ func (d *AccountDropdown) getAccountByNumber(accountNumber int32) *sharedW.Accou
}

func (d *AccountDropdown) SelectedAccount() *sharedW.Account {
if d == nil {
return nil
}
return d.selectedAccount
}

Expand Down
24 changes: 13 additions & 11 deletions ui/page/send/page.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,18 @@ func (pg *Page) pageFields() pageFields {

// initWalletSelector is used for the send modal for wallet selection.
func (pg *Page) initModalWalletSelector(wallet sharedW.Asset) {
pg.walletDropdown = components.NewWalletDropdown(pg.Load).
SetChangedCallback(func(wallet sharedW.Asset) {
pg.selectedWallet = wallet
if pg.accountDropdown != nil {
pg.accountDropdown.Setup(wallet)
go pg.feeRateSelector.UpdatedFeeRate(pg.selectedWallet)
pg.setAssetTypeForRecipients()
}

}).
Setup()

pg.accountDropdown = components.NewAccountDropdown(pg.Load).
SetChangedCallback(func(account *sharedW.Account) {
pg.initAccountsSelectorForRecipients(account)
Expand Down Expand Up @@ -219,18 +231,8 @@ func (pg *Page) initModalWalletSelector(wallet sharedW.Asset) {
}

return accountIsValid
})
pg.walletDropdown = components.NewWalletDropdown(pg.Load).
SetChangedCallback(func(wallet sharedW.Asset) {
pg.selectedWallet = wallet
if pg.accountDropdown != nil {
pg.accountDropdown.Setup(wallet)
go pg.feeRateSelector.UpdatedFeeRate(pg.selectedWallet)
pg.setAssetTypeForRecipients()
}

}).
Setup()
Setup(wallet)

pg.selectedWallet = pg.walletDropdown.SelectedWallet()
if wallet != nil {
Expand Down
3 changes: 3 additions & 0 deletions ui/page/send/recipient.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ func (rp *recipient) initializeAccountSelectors(sourceAccount *sharedW.Account)

func (rp *recipient) isShowSendToWallet() bool {
sourceWalletSelected := rp.sendDestination.walletDropdown.SelectedWallet()
if sourceWalletSelected == nil {
return false
}
var wallets []sharedW.Asset
switch sourceWalletSelected.GetAssetType() {
case libUtil.BTCWalletAsset:
Expand Down
37 changes: 11 additions & 26 deletions ui/page/send/send_amount.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,39 +219,24 @@ func (sa *sendAmount) handle(gtx C) {
sa.usdAmountEditor.CustomButton.Background = sa.theme.Color.Gray1
}

for {
event, ok := sa.amountEditor.Editor.Update(gtx)
if !ok {
break
}

if gtx.Source.Focused(sa.amountEditor.Editor) {
switch event.(type) {
case widget.ChangeEvent:
if sa.sendMaxChangeEvent {
sa.sendMaxChangeEvent = false
continue
}
if gtx.Source.Focused(sa.amountEditor.Editor) {
if sa.amountEditor.Changed() {
if sa.sendMaxChangeEvent {
sa.sendMaxChangeEvent = false
} else {
sa.SendMax = false
sa.validateAmount()
sa.amountChanged()
}
}
}

for {
event, ok := sa.usdAmountEditor.Editor.Update(gtx)
if !ok {
break
}
}

if gtx.Source.Focused(sa.usdAmountEditor.Editor) {
switch event.(type) {
case widget.ChangeEvent:
if sa.usdSendMaxChangeEvent {
sa.usdSendMaxChangeEvent = false
continue
}
if gtx.Source.Focused(sa.usdAmountEditor.Editor) {
if sa.usdAmountEditor.Changed() {
if sa.usdSendMaxChangeEvent {
sa.usdSendMaxChangeEvent = false
} else {
sa.SendMax = false
sa.validateUSDAmount()
sa.amountChanged()
Expand Down
12 changes: 12 additions & 0 deletions ui/page/send/send_destination.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@ func (dst *destination) initDestinationWalletSelector(assetType libUtil.AssetTyp
_ = dst.accountDropdown.Setup(wallet)
}
}).
WalletValidator(func(wallet sharedW.Asset) bool {
if dst.sourceAccount == nil {
return true
}
if wallet.GetWalletID() == dst.sourceAccount.WalletID {
account, err := wallet.GetAccountsRaw()
if err != nil || len(account.Accounts) <= 2 {
return false
}
}
return true
}).
EnableWatchOnlyWallets(true).
Setup()
dst.accountDropdown = components.NewAccountDropdown(dst.Load).
Expand Down

0 comments on commit 8513dcb

Please sign in to comment.