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

Fix display the account name in the Inputs and the Outputs of the transaction #467

Merged
merged 1 commit into from
Jun 17, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 28 additions & 14 deletions ui/transaction_details_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (pg *transactionDetailsPage) Layout(gtx layout.Context) layout.Dimensions {
return pg.separator(gtx)
},
func(gtx C) D {
return pg.txnInputs(gtx)
return pg.txnInputs(gtx, common)
},
func(gtx C) D {
return pg.separator(gtx)
Expand Down Expand Up @@ -284,7 +284,7 @@ func (pg *transactionDetailsPage) txnInfoSection(gtx layout.Context, t1, t2, t3
)
}

func (pg *transactionDetailsPage) txnInputs(gtx layout.Context) layout.Dimensions {
func (pg *transactionDetailsPage) txnInputs(gtx layout.Context, common *pageCommon) layout.Dimensions {
transaction := *pg.txnInfo
x := len(transaction.Txn.Inputs) + len(transaction.Txn.Outputs)
for i := 0; i < x; i++ {
Expand All @@ -299,11 +299,7 @@ func (pg *transactionDetailsPage) txnInputs(gtx layout.Context) layout.Dimension

collapsibleBody := func(gtx C) D {
return pg.transactionInputsContainer.Layout(gtx, len(transaction.Txn.Inputs), func(gtx C, i int) D {
amount := dcrutil.Amount(transaction.Txn.Inputs[i].Amount).String()
acctName := fmt.Sprintf("(%s)", transaction.AccountName)
walName := transaction.WalletName
hashAcct := transaction.Txn.Inputs[i].PreviousOutpoint
return pg.txnIORow(gtx, amount, acctName, walName, hashAcct, i)
return pg.txnIORow(gtx, common, transaction, "INPUT", i)
})
}
return pg.pageSections(gtx, func(gtx C) D {
Expand All @@ -322,20 +318,38 @@ func (pg *transactionDetailsPage) txnOutputs(gtx layout.Context, common *pageCom

collapsibleBody := func(gtx C) D {
return pg.transactionOutputsContainer.Layout(gtx, len(transaction.Txn.Outputs), func(gtx C, i int) D {
amount := dcrutil.Amount(transaction.Txn.Outputs[i].Amount).String()
acctName := fmt.Sprintf("(%s)", transaction.AccountName)
walName := transaction.WalletName
hashAcct := transaction.Txn.Outputs[i].Address
x := len(transaction.Txn.Inputs)
return pg.txnIORow(gtx, amount, acctName, walName, hashAcct, i+x)
return pg.txnIORow(gtx, common, transaction, "OUTPUT", i)
})
}
return pg.pageSections(gtx, func(gtx C) D {
return pg.outputsCollapsible.Layout(gtx, collapsibleHeader, collapsibleBody)
})
}

func (pg *transactionDetailsPage) txnIORow(gtx layout.Context, amount, acctName, walName, hashAcct string, i int) layout.Dimensions {
func (pg *transactionDetailsPage) txnIORow(gtx layout.Context, common *pageCommon, transaction *wallet.Transaction, txType string, i int) layout.Dimensions {

var (
amount string
accountNumber int32
hashAcct string
)

if txType == "INPUT" {
amount = dcrutil.Amount(transaction.Txn.Inputs[i].Amount).String()
accountNumber = transaction.Txn.Inputs[i].AccountNumber
hashAcct = transaction.Txn.Inputs[i].PreviousOutpoint
} else {
amount = dcrutil.Amount(transaction.Txn.Outputs[i].Amount).String()
accountNumber = transaction.Txn.Outputs[i].AccountNumber
hashAcct = transaction.Txn.Outputs[i].Address
i += len(transaction.Txn.Inputs)
}

walletID := transaction.Txn.WalletID
accountName := common.wallet.GetAccountName(walletID, accountNumber)
acctName := fmt.Sprintf("(%s)", accountName)
walName := transaction.WalletName

return layout.Inset{Bottom: values.MarginPadding5}.Layout(gtx, func(gtx C) D {
card := pg.theme.Card()
card.Color = pg.theme.Color.LightGray
Expand Down
13 changes: 13 additions & 0 deletions wallet/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -1448,3 +1448,16 @@ func (wal *Wallet) DataSize() string {
}
return fmt.Sprintf("%f GB", float64(v)*1e-9)
}

// GetAccountName returns the account name or 'external' if it does not belong to the wallet
func (wal *Wallet) GetAccountName(walletID int, accountNumber int32) string {
wallet := wal.multi.WalletWithID(walletID)
if wallet == nil {
return "external"
}
account, err := wallet.GetAccount(accountNumber)
if err != nil {
return "external"
}
return account.Name
}