Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
itswisdomagain committed Nov 29, 2023
1 parent 3be3355 commit b56523e
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 36 deletions.
4 changes: 4 additions & 0 deletions libwallet/assets_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
34 changes: 16 additions & 18 deletions ui/page/components/consensus_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -14,7 +13,7 @@ import (
)

type ConsensusItem struct {
Agenda dcr.Agenda
Agenda *dcr.Agenda
VoteButton cryptomaterial.Button
}

Expand All @@ -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
Expand Down Expand Up @@ -127,15 +126,16 @@ func layoutAgendaVoteAction(gtx C, l *load.Load, item *ConsensusItem, hasVotingW
return D{}
}

canVote := hasVotingWallet && item.Agenda.Status == dcr.AgendaStatusUpcoming.String() || item.Agenda.Status == dcr.AgendaStatusInProgress.String()
hasVotingStatus := item.Agenda.Status == dcr.AgendaStatusUpcoming.String() || item.Agenda.Status == dcr.AgendaStatusInProgress.String()
canVote := hasVotingWallet && hasVotingStatus
item.VoteButton.SetEnabled(canVote)
if canVote {
item.VoteButton.Background = l.Theme.Color.Primary
} else {
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)
}

Expand All @@ -160,29 +160,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
}
2 changes: 1 addition & 1 deletion ui/page/governance/consensus_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
3 changes: 0 additions & 3 deletions ui/page/governance/treasury_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ type TreasuryPage struct {
ctx context.Context // page context
ctxCancel context.CancelFunc

assetsManager *libwallet.AssetsManager

dcrWalletSelector *components.WalletAndAccountSelector
selectedDCRWallet *dcr.Asset

Expand All @@ -60,7 +58,6 @@ func NewTreasuryPage(l *load.Load) *TreasuryPage {
pg := &TreasuryPage{
Load: l,
GenericPageModal: app.NewGenericPageModal(TreasuryPageID),
assetsManager: l.AssetsManager,
listContainer: &widget.List{
List: layout.List{Axis: layout.Vertical},
},
Expand Down
18 changes: 4 additions & 14 deletions ui/page/settings/settings_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b56523e

Please sign in to comment.