Skip to content

Commit

Permalink
fix treasury page wrong wallet type bug
Browse files Browse the repository at this point in the history
  • Loading branch information
itswisdomagain committed Nov 23, 2023
1 parent 0024409 commit df24e21
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
5 changes: 2 additions & 3 deletions ui/page/components/treasury_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"gioui.org/widget"

"github.com/crypto-power/cryptopower/libwallet/assets/dcr"
sharedW "github.com/crypto-power/cryptopower/libwallet/assets/wallet"
"github.com/crypto-power/cryptopower/ui/cryptomaterial"
"github.com/crypto-power/cryptopower/ui/load"
"github.com/crypto-power/cryptopower/ui/values"
Expand Down Expand Up @@ -97,8 +96,8 @@ func LayoutNoPoliciesFound(gtx C, l *load.Load, syncing bool) D {
})
}

func LoadPolicies(l *load.Load, selectedWallet sharedW.Asset, pikey string) []*TreasuryItem {
policies, err := selectedWallet.(*dcr.Asset).TreasuryPolicies(pikey, "")
func LoadPolicies(l *load.Load, selectedDCRWallet *dcr.Asset, pikey string) []*TreasuryItem {
policies, err := selectedDCRWallet.TreasuryPolicies(pikey, "")
if err != nil {
return nil
}
Expand Down
25 changes: 13 additions & 12 deletions ui/page/governance/treasury_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ type TreasuryPage struct {

assetsManager *libwallet.AssetsManager

sourceWalletSelector *components.WalletAndAccountSelector
selectedWallet sharedW.Asset
dcrWalletSelector *components.WalletAndAccountSelector
selectedDCRWallet *dcr.Asset

treasuryItems []*components.TreasuryItem

Expand Down Expand Up @@ -90,7 +90,7 @@ func (pg *TreasuryPage) OnNavigatedTo() {
// a network call. Refresh the window once the call completes.
pg.PiKey = hex.EncodeToString(pg.AssetsManager.PiKeys()[0])

if pg.isTreasuryAPIAllowed() && pg.selectedWallet != nil {
if pg.isTreasuryAPIAllowed() && pg.selectedDCRWallet != nil {
pg.FetchPolicies()
}
}
Expand Down Expand Up @@ -157,7 +157,7 @@ func (pg *TreasuryPage) FetchPolicies() {
pg.isPolicyFetchInProgress = true

go func() {
pg.treasuryItems = components.LoadPolicies(pg.Load, pg.selectedWallet, pg.PiKey)
pg.treasuryItems = components.LoadPolicies(pg.Load, pg.selectedDCRWallet, pg.PiKey)
pg.isPolicyFetchInProgress = true
pg.ParentWindow().Reload()
}()
Expand All @@ -184,7 +184,7 @@ func (pg *TreasuryPage) Layout(gtx C) D {
}

func (pg *TreasuryPage) layout(gtx C) D {
if pg.selectedWallet == nil {
if pg.selectedDCRWallet == nil {
return pg.decredWalletRequired(gtx)
}
return layout.Flex{Axis: layout.Vertical}.Layout(gtx,
Expand Down Expand Up @@ -250,7 +250,7 @@ func (pg *TreasuryPage) layoutContent(gtx C) D {
layout.Rigid(func(gtx C) D {
return layout.Inset{Top: values.MarginPadding15}.Layout(gtx, func(gtx C) D {
gtx.Constraints.Max.X = gtx.Dp(values.MarginPadding350)
return pg.sourceWalletSelector.Layout(pg.ParentWindow(), gtx)
return pg.dcrWalletSelector.Layout(pg.ParentWindow(), gtx)
})
}),
layout.Rigid(func(gtx C) D {
Expand Down Expand Up @@ -304,7 +304,7 @@ func (pg *TreasuryPage) updatePolicyPreference(treasuryItem *components.Treasury
Title(values.String(values.StrConfirmVote)).
SetPositiveButtonCallback(func(_, password string, pm *modal.CreatePasswordModal) bool {
votingPreference := treasuryItem.OptionsRadioGroup.Value
err := pg.selectedWallet.(*dcr.Asset).SetTreasuryPolicy(treasuryItem.Policy.PiKey, votingPreference, "", password)
err := pg.selectedDCRWallet.SetTreasuryPolicy(treasuryItem.Policy.PiKey, votingPreference, "", password)
if err != nil {
pm.SetError(err.Error())
pm.SetLoading(false)
Expand All @@ -323,14 +323,15 @@ func (pg *TreasuryPage) updatePolicyPreference(treasuryItem *components.Treasury

func (pg *TreasuryPage) initWalletSelector() {
// Source wallet picker
pg.sourceWalletSelector = components.NewWalletAndAccountSelector(pg.Load, libutils.DCRWalletAsset).
pg.dcrWalletSelector = components.NewWalletAndAccountSelector(pg.Load, libutils.DCRWalletAsset).
Title(values.String(values.StrSelectWallet))
if pg.sourceWalletSelector.SelectedWallet() != nil {
pg.selectedWallet = pg.sourceWalletSelector.SelectedWallet()

if pg.dcrWalletSelector.SelectedWallet() != nil {
pg.selectedDCRWallet = pg.dcrWalletSelector.SelectedWallet().(*dcr.Asset)
}

pg.sourceWalletSelector.WalletSelected(func(selectedWallet sharedW.Asset) {
pg.selectedWallet = selectedWallet
pg.dcrWalletSelector.WalletSelected(func(selectedWallet sharedW.Asset) {
pg.selectedDCRWallet = selectedWallet.(*dcr.Asset)
pg.FetchPolicies()
})
}
Expand Down

0 comments on commit df24e21

Please sign in to comment.