Skip to content

Commit

Permalink
Add wallets parameter to wallet drop down selector
Browse files Browse the repository at this point in the history
  • Loading branch information
beansgum committed Jun 18, 2021
1 parent dd2777a commit 04a3b5d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 deletions.
4 changes: 2 additions & 2 deletions ui/components.go
Original file line number Diff line number Diff line change
Expand Up @@ -975,9 +975,9 @@ func (page *pageCommon) handleToast() {

// createOrUpdateWalletDropDown check for len of wallets to create dropDown,
// also update the list when create, update, delete a wallet.
func (page *pageCommon) createOrUpdateWalletDropDown(dwn **decredmaterial.DropDown) {
func (page *pageCommon) createOrUpdateWalletDropDown(dwn **decredmaterial.DropDown, wallets []*dcrlibwallet.Wallet) {
var walletDropDownItems []decredmaterial.DropDownItem
for _, wal := range page.multiWallet.AllWallets() {
for _, wal := range wallets {
item := decredmaterial.DropDownItem{
Text: wal.Name,
Icon: page.icons.walletIcon,
Expand Down
11 changes: 7 additions & 4 deletions ui/tickets_activity_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"strings"
"time"

"github.com/planetdecred/dcrlibwallet"
"github.com/planetdecred/godcr/wallet"

"gioui.org/layout"
Expand All @@ -25,6 +26,8 @@ type ticketsActivityPage struct {
ticketTypeDropDown *decredmaterial.DropDown
walletDropDown *decredmaterial.DropDown
common *pageCommon

wallets []*dcrlibwallet.Wallet
}

func TicketActivityPage(c *pageCommon) Page {
Expand All @@ -33,6 +36,7 @@ func TicketActivityPage(c *pageCommon) Page {
common: c,
tickets: c.walletTickets,
ticketsList: layout.List{Axis: layout.Vertical},
wallets: c.multiWallet.AllWallets(),
}
pg.orderDropDown = createOrderDropDown(c)
pg.ticketTypeDropDown = c.theme.DropDown([]decredmaterial.DropDownItem{
Expand All @@ -51,15 +55,15 @@ func TicketActivityPage(c *pageCommon) Page {

func (pg *ticketsActivityPage) Layout(gtx layout.Context) layout.Dimensions {
c := pg.common
c.createOrUpdateWalletDropDown(&pg.walletDropDown)
c.createOrUpdateWalletDropDown(&pg.walletDropDown, pg.wallets)
body := func(gtx C) D {
page := SubPage{
title: "Ticket activity",
back: func() {
c.changePage(PageTickets)
},
body: func(gtx C) D {
walletID := c.info.Wallets[pg.walletDropDown.SelectedIndex()].ID
walletID := pg.wallets[pg.walletDropDown.SelectedIndex()].ID
tickets := (*pg.tickets).Confirmed[walletID]
return layout.Stack{Alignment: layout.N}.Layout(gtx,
layout.Expanded(func(gtx C) D {
Expand Down Expand Up @@ -136,13 +140,12 @@ func filterTickets(tickets []wallet.Ticket, f func(string) bool) []wallet.Ticket
}

func (pg *ticketsActivityPage) handle() {
c := pg.common

sortSelection := pg.orderDropDown.SelectedIndex()
if pg.filterSorter != sortSelection {
pg.filterSorter = sortSelection
newestFirst := pg.filterSorter == 0
for _, wal := range c.info.Wallets {
for _, wal := range pg.wallets {
tickets := (*pg.tickets).Confirmed[wal.ID]
sort.SliceStable(tickets, func(i, j int) bool {
backTime := time.Unix(tickets[j].Info.Ticket.Timestamp, 0)
Expand Down
14 changes: 9 additions & 5 deletions ui/tickets_list_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"strings"
"time"

"github.com/planetdecred/dcrlibwallet"
"github.com/planetdecred/godcr/wallet"

"gioui.org/layout"
Expand All @@ -30,6 +31,8 @@ type ticketPageList struct {
isGridView bool
common *pageCommon
statusTooltips []*decredmaterial.Tooltip

wallets []*dcrlibwallet.Wallet
}

func TicketPageList(c *pageCommon) Page {
Expand All @@ -40,6 +43,8 @@ func TicketPageList(c *pageCommon) Page {
ticketsList: layout.List{Axis: layout.Vertical},
toggleViewType: new(widget.Clickable),
isGridView: true,

wallets: c.multiWallet.AllWallets(),
}
pg.orderDropDown = createOrderDropDown(c)
pg.ticketTypeDropDown = c.theme.DropDown([]decredmaterial.DropDownItem{
Expand All @@ -58,7 +63,7 @@ func TicketPageList(c *pageCommon) Page {

func (pg *ticketPageList) Layout(gtx layout.Context) layout.Dimensions {
c := pg.common
c.createOrUpdateWalletDropDown(&pg.walletDropDown)
c.createOrUpdateWalletDropDown(&pg.walletDropDown, pg.wallets)
pg.initTicketTooltips(*c)

body := func(gtx C) D {
Expand All @@ -68,7 +73,7 @@ func (pg *ticketPageList) Layout(gtx layout.Context) layout.Dimensions {
c.changePage(PageTickets)
},
body: func(gtx C) D {
walletID := c.info.Wallets[pg.walletDropDown.SelectedIndex()].ID
walletID := pg.wallets[pg.walletDropDown.SelectedIndex()].ID
tickets := (*pg.tickets).Confirmed[walletID]
return layout.Stack{Alignment: layout.N}.Layout(gtx,
layout.Expanded(func(gtx C) D {
Expand Down Expand Up @@ -295,7 +300,7 @@ func (pg *ticketPageList) ticketListGridLayout(gtx layout.Context, c *pageCommon
}

func (pg *ticketPageList) initTicketTooltips(common pageCommon) {
walletID := common.info.Wallets[pg.walletDropDown.SelectedIndex()].ID
walletID := pg.wallets[pg.walletDropDown.SelectedIndex()].ID
tickets := (*pg.tickets).Confirmed[walletID]

for range tickets {
Expand All @@ -304,7 +309,6 @@ func (pg *ticketPageList) initTicketTooltips(common pageCommon) {
}

func (pg *ticketPageList) handle() {
c := pg.common

if pg.toggleViewType.Clicked() {
pg.isGridView = !pg.isGridView
Expand All @@ -314,7 +318,7 @@ func (pg *ticketPageList) handle() {
if pg.filterSorter != sortSelection {
pg.filterSorter = sortSelection
newestFirst := pg.filterSorter == 0
for _, wal := range c.info.Wallets {
for _, wal := range pg.wallets {
tickets := (*pg.tickets).Confirmed[wal.ID]
sort.SliceStable(tickets, func(i, j int) bool {
backTime := time.Unix(tickets[j].Info.Ticket.Timestamp, 0)
Expand Down
2 changes: 1 addition & 1 deletion ui/transactions_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func TransactionsPage(common *pageCommon) Page {
wallets: common.multiWallet.AllWallets(),
}

common.createOrUpdateWalletDropDown(&pg.walletDropDown)
common.createOrUpdateWalletDropDown(&pg.walletDropDown, pg.wallets)
pg.orderDropDown = createOrderDropDown(common)
pg.txTypeDropDown = common.theme.DropDown([]decredmaterial.DropDownItem{
{
Expand Down

0 comments on commit 04a3b5d

Please sign in to comment.