Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update transaction row information #893

Merged
merged 7 commits into from Jul 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
159 changes: 84 additions & 75 deletions ui/page/components/components.go
Expand Up @@ -129,82 +129,93 @@ func UniformMobile(gtx layout.Context, isHorizontal, withList bool, body layout.
func TransactionTitleIcon(l *load.Load, wal *dcrlibwallet.Wallet, tx *dcrlibwallet.Transaction, ticketSpender *dcrlibwallet.Transaction) *TxStatus {
var txStatus TxStatus

if tx.Type == dcrlibwallet.TxTypeRegular {
if tx.Direction == dcrlibwallet.TxDirectionSent {
txStatus.Title = values.String(values.StrSent)
txStatus.Icon = l.Theme.Icons.SendIcon
} else if tx.Direction == dcrlibwallet.TxDirectionReceived {
txStatus.Title = values.String(values.StrReceived)
txStatus.Icon = l.Theme.Icons.ReceiveIcon
} else if tx.Direction == dcrlibwallet.TxDirectionTransferred {
txStatus.Title = values.String(values.StrYourself)
txStatus.Icon = l.Theme.Icons.Transferred
}
} else if tx.Type == dcrlibwallet.TxTypeMixed {
txStatus.Title = values.String(values.StrMixed)
txStatus.Icon = l.Theme.Icons.MixedTx
} else if wal.TxMatchesFilter(tx, dcrlibwallet.TxFilterStaking) {

if tx.Type == dcrlibwallet.TxTypeTicketPurchase {
if wal.TxMatchesFilter(tx, dcrlibwallet.TxFilterUnmined) {
txStatus.Title = values.String(values.StrUmined)
txStatus.Icon = l.Theme.Icons.TicketUnminedIcon
txStatus.TicketStatus = dcrlibwallet.TicketStatusUnmined
txStatus.Color = l.Theme.Color.LightBlue6
txStatus.Background = l.Theme.Color.LightBlue
} else if wal.TxMatchesFilter(tx, dcrlibwallet.TxFilterImmature) {
txStatus.Title = values.String(values.StrImmature)
txStatus.Icon = l.Theme.Icons.TicketImmatureIcon
txStatus.Color = l.Theme.Color.LightBlue6
txStatus.TicketStatus = dcrlibwallet.TicketStatusImmature
txStatus.ProgressBarColor = l.Theme.Color.LightBlue5
txStatus.ProgressTrackColor = l.Theme.Color.LightBlue3
txStatus.Background = l.Theme.Color.LightBlue
} else if ticketSpender != nil {
if ticketSpender.Type == dcrlibwallet.TxTypeVote {
txStatus.Title = values.String(values.StrVoted)
txStatus.Icon = l.Theme.Icons.TicketVotedIcon
txStatus.Color = l.Theme.Color.Turquoise700
txStatus.TicketStatus = dcrlibwallet.TicketStatusVotedOrRevoked
txStatus.ProgressBarColor = l.Theme.Color.Turquoise300
txStatus.ProgressTrackColor = l.Theme.Color.Turquoise100
txStatus.Background = l.Theme.Color.Success2
switch tx.Direction {
case dcrlibwallet.TxDirectionSent:
txStatus.Title = values.String(values.StrSent)
txStatus.Icon = l.Theme.Icons.SendIcon
case dcrlibwallet.TxDirectionReceived:
txStatus.Title = values.String(values.StrReceived)
txStatus.Icon = l.Theme.Icons.ReceiveIcon
default:
txStatus.Title = values.String(values.StrTransferred)
txStatus.Icon = l.Theme.Icons.Transferred
}

// replace icon for staking tx types
if wal.TxMatchesFilter(tx, dcrlibwallet.TxFilterStaking) {
switch tx.Type {
case dcrlibwallet.TxTypeTicketPurchase:
{
if wal.TxMatchesFilter(tx, dcrlibwallet.TxFilterUnmined) {
txStatus.Title = values.String(values.StrUmined)
txStatus.Icon = l.Theme.Icons.TicketUnminedIcon
txStatus.TicketStatus = dcrlibwallet.TicketStatusUnmined
txStatus.Color = l.Theme.Color.LightBlue6
txStatus.Background = l.Theme.Color.LightBlue
} else if wal.TxMatchesFilter(tx, dcrlibwallet.TxFilterImmature) {
txStatus.Title = values.String(values.StrImmature)
txStatus.Icon = l.Theme.Icons.TicketImmatureIcon
txStatus.Color = l.Theme.Color.LightBlue6
txStatus.TicketStatus = dcrlibwallet.TicketStatusImmature
txStatus.ProgressBarColor = l.Theme.Color.LightBlue5
txStatus.ProgressTrackColor = l.Theme.Color.LightBlue3
txStatus.Background = l.Theme.Color.LightBlue
} else if wal.TxMatchesFilter(tx, dcrlibwallet.TxFilterLive) {
txStatus.Title = values.String(values.StrLive)
txStatus.Icon = l.Theme.Icons.TicketLiveIcon
txStatus.Color = l.Theme.Color.Primary
txStatus.TicketStatus = dcrlibwallet.TicketStatusLive
txStatus.ProgressBarColor = l.Theme.Color.Primary
txStatus.ProgressTrackColor = l.Theme.Color.LightBlue4
txStatus.Background = l.Theme.Color.Primary50
} else if wal.TxMatchesFilter(tx, dcrlibwallet.TxFilterExpired) {
txStatus.Title = values.String(values.StrExpired)
txStatus.Icon = l.Theme.Icons.TicketExpiredIcon
txStatus.Color = l.Theme.Color.GrayText2
txStatus.TicketStatus = dcrlibwallet.TicketStatusExpired
txStatus.Background = l.Theme.Color.Gray4
} else {
txStatus.Title = values.String(values.StrRevoked)
txStatus.Icon = l.Theme.Icons.TicketRevokedIcon
txStatus.Color = l.Theme.Color.Orange
txStatus.TicketStatus = dcrlibwallet.TicketStatusVotedOrRevoked
txStatus.ProgressBarColor = l.Theme.Color.Danger
txStatus.ProgressTrackColor = l.Theme.Color.Orange3
txStatus.Background = l.Theme.Color.Orange2
if ticketSpender != nil {
if ticketSpender.Type == dcrlibwallet.TxTypeVote {
txStatus.Title = values.String(values.StrTicketVotedTitle)
txStatus.Icon = l.Theme.Icons.TicketLiveIcon
txStatus.Color = l.Theme.Color.Turquoise700
txStatus.TicketStatus = dcrlibwallet.TicketStatusVotedOrRevoked
txStatus.ProgressBarColor = l.Theme.Color.Turquoise300
txStatus.ProgressTrackColor = l.Theme.Color.Turquoise100
txStatus.Background = l.Theme.Color.Success2
} else {
txStatus.Title = values.String(values.StrTicketRevokedTitle)
txStatus.Icon = l.Theme.Icons.TicketLiveIcon
Sirmorrison marked this conversation as resolved.
Show resolved Hide resolved
txStatus.Color = l.Theme.Color.Orange
txStatus.TicketStatus = dcrlibwallet.TicketStatusVotedOrRevoked
txStatus.ProgressBarColor = l.Theme.Color.Danger
txStatus.ProgressTrackColor = l.Theme.Color.Orange3
txStatus.Background = l.Theme.Color.Orange2
}
}
}
} else if wal.TxMatchesFilter(tx, dcrlibwallet.TxFilterLive) {
txStatus.Title = values.String(values.StrLive)
txStatus.Icon = l.Theme.Icons.TicketLiveIcon
txStatus.Color = l.Theme.Color.Primary
txStatus.TicketStatus = dcrlibwallet.TicketStatusLive
txStatus.ProgressBarColor = l.Theme.Color.Primary
txStatus.ProgressTrackColor = l.Theme.Color.LightBlue4
txStatus.Background = l.Theme.Color.Primary50
} else if wal.TxMatchesFilter(tx, dcrlibwallet.TxFilterExpired) {
txStatus.Title = values.String(values.StrExpired)
txStatus.Icon = l.Theme.Icons.TicketExpiredIcon
txStatus.Color = l.Theme.Color.GrayText2
txStatus.TicketStatus = dcrlibwallet.TicketStatusExpired
txStatus.Background = l.Theme.Color.Gray4
} else {
txStatus.Title = values.String(values.StrPurchased)
txStatus.Icon = l.Theme.Icons.NewStakeIcon
txStatus.Color = l.Theme.Color.Text
txStatus.Background = l.Theme.Color.LightBlue
}
} else if tx.Type == dcrlibwallet.TxTypeVote {
case dcrlibwallet.TxTypeVote:
txStatus.Title = values.String(values.StrVote)
txStatus.Icon = l.Theme.Icons.TicketVotedIcon
} else if tx.Type == dcrlibwallet.TxTypeRevocation {
txStatus.Color = l.Theme.Color.Turquoise700
txStatus.TicketStatus = dcrlibwallet.TicketStatusVotedOrRevoked
txStatus.ProgressBarColor = l.Theme.Color.Turquoise300
txStatus.ProgressTrackColor = l.Theme.Color.Turquoise100
txStatus.Background = l.Theme.Color.Success2
default:
txStatus.Title = values.String(values.StrRevocation)
txStatus.Icon = l.Theme.Icons.TicketRevokedIcon
txStatus.Color = l.Theme.Color.Orange
txStatus.TicketStatus = dcrlibwallet.TicketStatusVotedOrRevoked
txStatus.ProgressBarColor = l.Theme.Color.Danger
txStatus.ProgressTrackColor = l.Theme.Color.Orange3
txStatus.Background = l.Theme.Color.Orange2
}
} else if tx.Type == dcrlibwallet.TxTypeMixed {
txStatus.Title = values.String(values.StrMixed)
txStatus.Icon = l.Theme.Icons.MixedTx
}

return &txStatus
Expand Down Expand Up @@ -463,7 +474,7 @@ func LayoutTransactionRow(gtx layout.Context, l *load.Load, row TransactionRow)
}),
layout.Rigid(func(gtx C) D {
// vote reward
if row.Transaction.Type != dcrlibwallet.TxTypeVote {
if row.Transaction.Type != dcrlibwallet.TxTypeVote && row.Transaction.Type != dcrlibwallet.TxTypeRevocation {
return D{}
}

Expand All @@ -474,11 +485,6 @@ func LayoutTransactionRow(gtx layout.Context, l *load.Load, row TransactionRow)
Margin: layout.Inset{Left: values.MarginPadding4},
Alignment: layout.Middle,
}.Layout(gtx,
layout.Rigid(func(gtx C) D {
label := l.Theme.Label(values.TextSize14, "+")
label.Color = l.Theme.Color.Turquoise800
return label.Layout(gtx)
}),
layout.Rigid(func(gtx C) D {
ic := l.Theme.Icons.DecredSymbol2

Expand All @@ -489,7 +495,10 @@ func LayoutTransactionRow(gtx layout.Context, l *load.Load, row TransactionRow)
}),
layout.Rigid(func(gtx C) D {
label := l.Theme.Label(values.TextSize12, dcrutil.Amount(row.Transaction.VoteReward).String())
label.Color = l.Theme.Color.Turquoise800
label.Color = l.Theme.Color.Orange
if row.Transaction.Type == dcrlibwallet.TxTypeVote {
label.Color = l.Theme.Color.Turquoise800
}
return label.Layout(gtx)
}),
)
Expand Down
52 changes: 32 additions & 20 deletions ui/page/transaction/transactions_page.go
Expand Up @@ -2,6 +2,7 @@ package transaction

import (
"context"
"fmt"
"image"

"gioui.org/layout"
Expand Down Expand Up @@ -71,26 +72,7 @@ func NewTransactionsPage(l *load.Load) *TransactionsPage {
pg.orderDropDown = components.CreateOrderDropDown(l, values.TxDropdownGroup, 1)
pg.wallets = pg.WL.SortedWalletList()
pg.walletDropDown = components.CreateOrUpdateWalletDropDown(pg.Load, &pg.walletDropDown, pg.wallets, values.TxDropdownGroup, 0)
pg.txTypeDropDown = l.Theme.DropDown([]decredmaterial.DropDownItem{
{
Text: values.String(values.StrAll),
},
{
Text: values.String(values.StrSent),
},
{
Text: values.String(values.StrReceived),
},
{
Text: values.String(values.StrYourself),
},
{
Text: values.String(values.StrMixed),
},
{
Text: values.String(values.StrStaking),
},
}, values.TxDropdownGroup, 2)
pg.refreshAvailableTxType(l)

walletTitles := make([]string, 0)
for _, wallet := range pg.wallets {
Expand All @@ -113,6 +95,36 @@ func (pg *TransactionsPage) OnNavigatedTo() {
pg.loadTransactions(pg.walletDropDown.SelectedIndex())
}

func (pg *TransactionsPage) refreshAvailableTxType(l *load.Load) {
txCount, _ := pg.WL.SelectedWallet.Wallet.CountTransactions(dcrlibwallet.TxFilterAll)
sentTxCount, _ := pg.WL.SelectedWallet.Wallet.CountTransactions(dcrlibwallet.TxFilterSent)
receivedTxCount, _ := pg.WL.SelectedWallet.Wallet.CountTransactions(dcrlibwallet.TxFilterReceived)
transferredTxCount, _ := pg.WL.SelectedWallet.Wallet.CountTransactions(dcrlibwallet.TxFilterTransferred)
mixedTxCount, _ := pg.WL.SelectedWallet.Wallet.CountTransactions(dcrlibwallet.TxFilterMixed)
stakingTxCount, _ := pg.WL.SelectedWallet.Wallet.CountTransactions(dcrlibwallet.TxFilterStaking)

pg.txTypeDropDown = l.Theme.DropDown([]decredmaterial.DropDownItem{
{
Text: fmt.Sprintf("%s (%d)", values.String(values.StrAll), txCount),
},
{
Text: fmt.Sprintf("%s (%d)", values.String(values.StrSent), sentTxCount),
},
{
Text: fmt.Sprintf("%s (%d)", values.String(values.StrReceived), receivedTxCount),
},
{
Text: fmt.Sprintf("%s (%d)", values.String(values.StrTransferred), transferredTxCount),
},
{
Text: fmt.Sprintf("%s (%d)", values.String(values.StrMixed), mixedTxCount),
},
{
Text: fmt.Sprintf("%s (%d)", values.String(values.StrStaking), stakingTxCount),
},
}, values.TxDropdownGroup, 2)
}

func (pg *TransactionsPage) loadTransactions(selectedWalletIndex int) {
selectedWallet := pg.wallets[selectedWalletIndex]
newestFirst := pg.orderDropDown.SelectedIndex() == 0
Expand Down
2 changes: 2 additions & 0 deletions ui/values/localizable/en.go
Expand Up @@ -470,4 +470,6 @@ unlockWithPassword = "Unlock with password"
"selectWalletType" = "Select the type of wallet you want to create"
"whatToCallWallet" = "What would you like to call your wallet?"
"existingWalletName" = "What is your wallet existing wallet name?"
"ticketVotedTitle" = "Ticket, Voted"
"ticketRevokedTitle" = "Ticket, Revoked"
`
2 changes: 2 additions & 0 deletions ui/values/strings.go
Expand Up @@ -578,4 +578,6 @@ const (
StrSelectWalletType = "selectWalletType"
StrWhatToCallWallet = "whatToCallWallet"
StrExistingWalletName = "existingWalletName"
StrTicketVotedTitle = "ticketVotedTitle"
StrTicketRevokedTitle = "ticketRevokedTitle"
)