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

frontend: fix shown amount for unconfirmed ETH txs #3215

Merged
merged 1 commit into from
Mar 5, 2025
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
9 changes: 9 additions & 0 deletions backend/accounts/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,14 @@ func TestOrderedTransactionsDeductedAmount(t *testing.T) {
Amount: amount,
Fee: &fee,
},
{
// timestamp is nil, deductedAmount is still set
Timestamp: nil,
Height: 15,
Type: TxTypeSend,
Amount: amount,
Fee: &fee,
},
}

orderedTxs := NewOrderedTransactions(txs)
Expand All @@ -285,4 +293,5 @@ func TestOrderedTransactionsDeductedAmount(t *testing.T) {
requireAmountIsEqualTo(t, orderedTxs[1].DeductedAmount, 10)
requireAmountIsEqualTo(t, orderedTxs[2].DeductedAmount, 0)
requireAmountIsEqualTo(t, orderedTxs[3].DeductedAmount, 100)
requireAmountIsEqualTo(t, orderedTxs[4].DeductedAmount, 110)
}
24 changes: 14 additions & 10 deletions backend/coins/btc/handlers/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,18 @@ func (handlers *Handlers) formatAmountAsJSON(amount coin.Amount, isFee bool) For

func (handlers *Handlers) formatAmountAtTimeAsJSON(amount coin.Amount, timeStamp *time.Time) FormattedAmount {
accountCoin := handlers.account.Coin()
conversions, estimated := coin.ConversionsAtTime(
amount,
handlers.account.Coin(),
false,
handlers.account.Config().RateUpdater,
util.FormatBtcAsSat(handlers.account.Config().BtcCurrencyUnit),
timeStamp,
)
conversions := map[string]string{}
estimated := false
if timeStamp != nil {
conversions, estimated = coin.ConversionsAtTime(
amount,
handlers.account.Coin(),
false,
handlers.account.Config().RateUpdater,
util.FormatBtcAsSat(handlers.account.Config().BtcCurrencyUnit),
timeStamp,
)
}
return FormattedAmount{
Amount: accountCoin.FormatAmount(amount, false),
Unit: accountCoin.GetFormatUnit(false),
Expand Down Expand Up @@ -195,12 +199,12 @@ func (handlers *Handlers) getTxInfoJSON(txInfo *accounts.TransactionData, detail
timestamp = txInfo.CreatedTimestamp
}

var deductedAmountAtTime FormattedAmount
deductedAmountAtTime := handlers.formatAmountAtTimeAsJSON(txInfo.DeductedAmount, timestamp)

if timestamp != nil {
t := timestamp.Format(time.RFC3339)
formattedTime = &t
amountAtTime = handlers.formatAmountAtTimeAsJSON(txInfo.Amount, timestamp)
deductedAmountAtTime = handlers.formatAmountAtTimeAsJSON(txInfo.DeductedAmount, timestamp)
}

addresses := []string{}
Expand Down
2 changes: 1 addition & 1 deletion frontends/web/src/components/amount/conversion-amount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const ConversionAmount = ({

return (
<span className={styles.txConversionAmount}>
{conversion && amountToShow ? (
{(conversion || sendToSelf) && amountToShow ? (
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is a sendToSelf, we do not need conversion as we show the coin amount, and not its conversion into a fiat value.

<>
{sendToSelf && (
<span className={styles.txSmallInlineIcon}>
Expand Down
Loading