Skip to content

Commit

Permalink
app: Fix amounts displayed for token transactions in tx history
Browse files Browse the repository at this point in the history
When displaying token transactions on the wallet page for the parent asset,
the unit info for the parent asset was being used, causing incorrect amounts.
  • Loading branch information
martonp committed Sep 29, 2024
1 parent df09f13 commit 891c4f2
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions client/webserver/site/src/js/wallets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1674,7 +1674,19 @@ export default class WalletsPage extends BasePage {

updateTxHistoryRow (row: PageElement, tx: WalletTransaction, assetID: number) {
const tmpl = Doc.parseTemplate(row)
const ui = app().unitInfo(assetID)
let amtAssetID = assetID
let feesAssetID = assetID
if (tx.tokenID) {
amtAssetID = tx.tokenID
if (assetID !== tx.tokenID) feesAssetID = assetID
else {
const asset = app().assets[assetID]
if (asset.token) feesAssetID = asset.token.parentID
else console.error(`unable to determine fee asset for tx ${tx.id}`)
}
}
const amtAssetUI = app().unitInfo(amtAssetID)
const feesAssetUI = app().unitInfo(feesAssetID)
tmpl.age.textContent = Doc.timeSince(tx.timestamp * 1000)
tmpl.age.dataset.timestamp = String(tx.timestamp * 1000)
Doc.setVis(tx.timestamp === 0, tmpl.pending)
Expand All @@ -1689,12 +1701,12 @@ export default class WalletsPage extends BasePage {
tmpl.type.textContent = txType
tmpl.id.textContent = trimStringWithEllipsis(tx.id, 12)
tmpl.id.setAttribute('title', tx.id)
tmpl.fees.textContent = Doc.formatCoinValue(tx.fees, ui)
tmpl.fees.textContent = Doc.formatCoinValue(tx.fees, feesAssetUI)
if (noAmtTxTypes.includes(tx.type)) {
tmpl.amount.textContent = '-'
} else {
const [u, c] = txTypeSignAndClass(tx.type)
const amt = Doc.formatCoinValue(tx.amount, ui)
const amt = Doc.formatCoinValue(tx.amount, amtAssetUI)
tmpl.amount.textContent = `${u}${amt}`
if (c !== '') tmpl.amount.classList.add(c)
}
Expand Down Expand Up @@ -1740,15 +1752,11 @@ export default class WalletsPage extends BasePage {
if (noAmtTxTypes.includes(tx.type)) {
Doc.hide(page.txDetailsAmtSection)
} else {
let assetID = this.selectedAssetID
if (tx.tokenID) assetID = tx.tokenID
Doc.show(page.txDetailsAmtSection)
const amt = Doc.formatCoinValue(tx.amount, app().unitInfo(this.selectedAssetID))
let amtUnit : string
if (tx.tokenID) {
amtUnit = app().assets[tx.tokenID].symbol.split('.')[0].toUpperCase()
} else {
amtUnit = app().assets[this.selectedAssetID].symbol.split('.')[0].toUpperCase()
}

const amt = Doc.formatCoinValue(tx.amount, app().unitInfo(assetID))
const amtUnit = app().assets[assetID].symbol.split('.')[0].toUpperCase()
const [s, c] = txTypeSignAndClass(tx.type)
page.txDetailsAmount.textContent = `${s}${amt} ${amtUnit}`
if (c !== '') page.txDetailsAmount.classList.add(c)
Expand Down

0 comments on commit 891c4f2

Please sign in to comment.