diff --git a/libwallet/assets_manager.go b/libwallet/assets_manager.go index 63c13b024..1cf201cc1 100644 --- a/libwallet/assets_manager.go +++ b/libwallet/assets_manager.go @@ -855,6 +855,10 @@ func (mgr *AssetsManager) CalculateTotalAssetsBalance() (map[utils.AssetType]sha } func (mgr *AssetsManager) CalculateAssetsUSDBalance(balances map[utils.AssetType]sharedW.AssetAmount) (map[utils.AssetType]float64, error) { + if !mgr.ExchangeRateFetchingEnabled() { + return nil, fmt.Errorf("USD exchange rate is disabled") + } + usdBalance := func(bal sharedW.AssetAmount, market string) (float64, error) { rate := mgr.RateSource.GetTicker(market) if rate == nil || rate.LastTradePrice <= 0 { diff --git a/ui/page/components/consensus_list.go b/ui/page/components/consensus_list.go index 7331bcb4a..e9c88b543 100644 --- a/ui/page/components/consensus_list.go +++ b/ui/page/components/consensus_list.go @@ -5,7 +5,6 @@ import ( "gioui.org/font" "gioui.org/layout" - "gioui.org/unit" "github.com/crypto-power/cryptopower/libwallet/assets/dcr" "github.com/crypto-power/cryptopower/ui/cryptomaterial" @@ -14,7 +13,7 @@ import ( ) type ConsensusItem struct { - Agenda dcr.Agenda + Agenda *dcr.Agenda VoteButton cryptomaterial.Button } @@ -37,7 +36,7 @@ func AgendaItemWidget(gtx C, l *load.Load, consensusItem *ConsensusItem, hasVoti ) } -func layoutAgendaStatus(gtx C, l *load.Load, agenda dcr.Agenda) D { +func layoutAgendaStatus(gtx C, l *load.Load, agenda *dcr.Agenda) D { var statusLabel cryptomaterial.Label var statusIcon *cryptomaterial.Icon var backgroundColor color.NRGBA @@ -135,7 +134,7 @@ func layoutAgendaVoteAction(gtx C, l *load.Load, item *ConsensusItem, hasVotingW item.VoteButton.Background = l.Theme.Color.Gray3 } - gtx.Constraints.Min.X, gtx.Constraints.Max.X = gtx.Dp(unit.Dp(150)), gtx.Dp(unit.Dp(200)) + gtx.Constraints.Min.X, gtx.Constraints.Max.X = gtx.Dp(values.MarginPadding150), gtx.Dp(values.MarginPadding200) return layout.Inset{Top: values.MarginPadding15}.Layout(gtx, item.VoteButton.Layout) } @@ -160,29 +159,27 @@ func LoadAgendas(l *load.Load, dcrWallet *dcr.Asset, newestFirst bool) []*Consen return nil } + var walletChoices map[string]string if dcrWallet != nil { - walletChoices, err := dcrWallet.AgendaChoices("") + walletChoices, err = dcrWallet.AgendaChoices("") if err != nil { return nil } - // Update the vote preference value in the agendas slice. Where the - // wallet doesn't have a set vote preference, default to "abstain". - for i := range agendas { - agenda := agendas[i] - if voteChoice, ok := walletChoices[agenda.AgendaID]; ok { - agenda.VotingPreference = voteChoice - } else { - agenda.VotingPreference = "abstain" - } - } } consensusItems := make([]*ConsensusItem, len(agendas)) - for i := 0; i < len(agendas); i++ { + for i := range agendas { + agenda := agendas[i] + if voteChoice, ok := walletChoices[agenda.AgendaID]; ok { + agenda.VotingPreference = voteChoice + } else { + agenda.VotingPreference = "-" + } consensusItems[i] = &ConsensusItem{ - Agenda: *agendas[i], + Agenda: agenda, VoteButton: l.Theme.Button(values.String(values.StrSetChoice)), } } + return consensusItems } diff --git a/ui/page/governance/consensus_page.go b/ui/page/governance/consensus_page.go index c0b50abc8..89f30df36 100644 --- a/ui/page/governance/consensus_page.go +++ b/ui/page/governance/consensus_page.go @@ -152,7 +152,7 @@ func (pg *ConsensusPage) HandleUserInteractions() { for _, item := range pg.consensusItems { if item.VoteButton.Clicked() { - pg.agendaVoteChoiceModal(&item.Agenda) + pg.agendaVoteChoiceModal(item.Agenda) } } diff --git a/ui/page/settings/settings_page.go b/ui/page/settings/settings_page.go index 574c7e6a4..7200658df 100644 --- a/ui/page/settings/settings_page.go +++ b/ui/page/settings/settings_page.go @@ -621,25 +621,15 @@ func (pg *SettingPage) updateSettingOptions() { } func (pg *SettingPage) updatePrivacySettings() { - pg.setInitialSwitchStatus(pg.privacyActive, pg.AssetsManager.IsPrivacyModeOn()) - if !pg.AssetsManager.IsPrivacyModeOn() { + privacyOn := pg.AssetsManager.IsPrivacyModeOn() + pg.setInitialSwitchStatus(pg.privacyActive, privacyOn) + if !privacyOn { pg.setInitialSwitchStatus(pg.transactionNotification, pg.AssetsManager.IsTransactionNotificationsOn()) pg.setInitialSwitchStatus(pg.governanceAPI, pg.AssetsManager.IsHTTPAPIPrivacyModeOff(libutils.GovernanceHTTPAPI)) pg.setInitialSwitchStatus(pg.exchangeAPI, pg.AssetsManager.IsHTTPAPIPrivacyModeOff(libutils.ExchangeHTTPAPI)) pg.setInitialSwitchStatus(pg.feeRateAPI, pg.AssetsManager.IsHTTPAPIPrivacyModeOff(libutils.FeeRateHTTPAPI)) pg.setInitialSwitchStatus(pg.vspAPI, pg.AssetsManager.IsHTTPAPIPrivacyModeOff(libutils.VspAPI)) - } /*else { - // TODO: Re "Clear all the peers saved if the privacy mode is on". Does - // this mean clear all peers for all wallets? The privacy mode isn't on - // for just the selected wallet afterall. - - if pg.WL.SelectedWallet != nil { - go func() { - // Clear all the peers saved if the privacy mode is on. - pg.WL.SelectedWallet.Wallet.SetStringConfigValueForKey(sharedW.SpvPersistentPeerAddressesConfigKey, "") - }() - } - }*/ + } } // OnNavigatedFrom is called when the page is about to be removed from diff --git a/ui/page/transaction/transactions_page.go b/ui/page/transaction/transactions_page.go index 4ed02b7dc..983f6c61d 100644 --- a/ui/page/transaction/transactions_page.go +++ b/ui/page/transaction/transactions_page.go @@ -153,9 +153,8 @@ func (pg *TransactionsPage) pageTitle(gtx C) D { } func (pg *TransactionsPage) refreshAvailableTxType() { - wal := pg.selectedWallet items := []cryptomaterial.DropDownItem{} - _, keysinfo := components.TxPageDropDownFields(wal.GetAssetType(), pg.selectedTabIndex) + _, keysinfo := components.TxPageDropDownFields(pg.selectedWallet.GetAssetType(), pg.selectedTabIndex) for _, name := range keysinfo { item := cryptomaterial.DropDownItem{} item.Text = name @@ -166,12 +165,12 @@ func (pg *TransactionsPage) refreshAvailableTxType() { go func() { countfn := func(fType int32) int { - count, _ := wal.CountTransactions(fType) + count, _ := pg.selectedWallet.CountTransactions(fType) return count } items := []cryptomaterial.DropDownItem{} - mapinfo, keysinfo := components.TxPageDropDownFields(wal.GetAssetType(), pg.selectedTabIndex) + mapinfo, keysinfo := components.TxPageDropDownFields(pg.selectedWallet.GetAssetType(), pg.selectedTabIndex) for _, name := range keysinfo { fieldtype := mapinfo[name] item := cryptomaterial.DropDownItem{} @@ -188,10 +187,9 @@ func (pg *TransactionsPage) refreshAvailableTxType() { } func (pg *TransactionsPage) loadTransactions(offset, pageSize int32) ([]*sharedW.Transaction, int, bool, error) { - wal := pg.selectedWallet - mapinfo, _ := components.TxPageDropDownFields(wal.GetAssetType(), pg.selectedTabIndex) + mapinfo, _ := components.TxPageDropDownFields(pg.selectedWallet.GetAssetType(), pg.selectedTabIndex) if len(mapinfo) < 1 { - err := fmt.Errorf("asset type(%v) and tab index(%d) found", wal.GetAssetType(), pg.selectedTabIndex) + err := fmt.Errorf("asset type(%v) and tab index(%d) found", pg.selectedWallet.GetAssetType(), pg.selectedTabIndex) return nil, -1, false, err } @@ -199,7 +197,7 @@ func (pg *TransactionsPage) loadTransactions(offset, pageSize int32) ([]*sharedW txFilter, ok := mapinfo[selectedVal] if !ok { err := fmt.Errorf("unsupported field(%v) for asset type(%v) and tab index(%d) found", - selectedVal, wal.GetAssetType(), pg.selectedTabIndex) + selectedVal, pg.selectedWallet.GetAssetType(), pg.selectedTabIndex) return nil, -1, false, err } @@ -210,7 +208,7 @@ func (pg *TransactionsPage) loadTransactions(offset, pageSize int32) ([]*sharedW pg.previousTxFilter = txFilter } - tempTxs, err := wal.GetTransactionsRaw(offset, pageSize, txFilter, true) + tempTxs, err := pg.selectedWallet.GetTransactionsRaw(offset, pageSize, txFilter, true) if err != nil { err = fmt.Errorf("Error loading transactions: %v", err) } @@ -229,7 +227,6 @@ func (pg *TransactionsPage) Layout(gtx layout.Context) layout.Dimensions { func (pg *TransactionsPage) layoutDesktop(gtx layout.Context) layout.Dimensions { pg.scroll.OnScrollChangeListener(pg.ParentWindow()) - wal := pg.selectedWallet txlisingView := layout.Flexed(1, func(gtx C) D { return layout.Inset{Top: values.MarginPadding0}.Layout(gtx, func(gtx C) D { @@ -265,7 +262,7 @@ func (pg *TransactionsPage) layoutDesktop(gtx layout.Context) layout.Dimensions tx := wallTxs[index] return layout.Flex{Axis: layout.Vertical}.Layout(gtx, layout.Rigid(func(gtx C) D { - return components.LayoutTransactionRow(gtx, pg.Load, wal, tx, true) + return components.LayoutTransactionRow(gtx, pg.Load, pg.selectedWallet, tx, true) }), layout.Rigid(func(gtx C) D { // No divider for last row @@ -308,7 +305,6 @@ func (pg *TransactionsPage) layoutDesktop(gtx layout.Context) layout.Dimensions } func (pg *TransactionsPage) layoutMobile(gtx layout.Context) layout.Dimensions { - wal := pg.selectedWallet container := func(gtx C) D { return layout.Flex{Axis: layout.Vertical}.Layout(gtx, layout.Rigid(func(gtx C) D { @@ -334,7 +330,7 @@ func (pg *TransactionsPage) layoutMobile(gtx layout.Context) layout.Dimensions { tx := wallTxs[index] return layout.Flex{Axis: layout.Vertical}.Layout(gtx, layout.Rigid(func(gtx C) D { - return components.LayoutTransactionRow(gtx, pg.Load, wal, tx, true) + return components.LayoutTransactionRow(gtx, pg.Load, pg.selectedWallet, tx, true) }), layout.Rigid(func(gtx C) D { // No divider for last row