Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
itswisdomagain committed Nov 14, 2023
1 parent 032480c commit d316d24
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 29 deletions.
28 changes: 13 additions & 15 deletions ui/page/components/consensus_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
)

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

Expand All @@ -37,7 +37,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 @@ -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
22 changes: 9 additions & 13 deletions ui/page/transaction/transactions_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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{}
Expand All @@ -188,18 +187,17 @@ 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
}

selectedVal, _, _ := strings.Cut(pg.txTypeDropDown.Selected(), " ")
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
}

Expand All @@ -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)
}
Expand All @@ -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 {
Expand Down Expand Up @@ -264,7 +261,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
Expand Down Expand Up @@ -306,7 +303,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 {
Expand All @@ -332,7 +328,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
Expand Down

0 comments on commit d316d24

Please sign in to comment.