diff --git a/README.md b/README.md index 6bb4aa9..3947868 100644 --- a/README.md +++ b/README.md @@ -1187,20 +1187,17 @@ These helpers write one kind of value on every screen that shows it: times; - `renderAddressHtml()` in the same file: most addresses. -Most screens show token and ETH amounts with four decimal places. History rows -cut amounts to four decimals and never round up (`truncateAmount()` in -`src/shared/amountDisplay.js`). The balance lists and Home's ETH balance round -to four places. The screens that state what is being authorized cut as the -history does, and extend an amount below 0.0001 to its first nonzero digit -(`truncateAmountNeverZero()`). So a nonzero amount never reads as zero there. -Those screens are: +Every screen shows token and ETH amounts the same way, through +`truncateAmountNeverZero()` in `src/shared/amountDisplay.js`: -- TxApproval; -- SignApproval's Permit warning; -- ConfirmTx, and Send's current balance; -- WaitTx, SuccessTx and ErrorTx. +- an amount is cut to four decimal places, never rounded, so 0.99996 reads + `0.9999`; +- an amount below 0.0001 is shown to its first nonzero digit, so 0.00004 reads + `0.00004`. -TransactionDetail shows the exact amount and its base units. +So an amount never reads as more than it is, and a nonzero amount never reads as +zero. TransactionDetail is the one exception: it shows the exact amount and its +base units. An amount to send is valid when it is a number above zero, written as digits with at most one decimal point. Nothing but zeros may follow the token's last diff --git a/src/popup/views/addressToken.js b/src/popup/views/addressToken.js index ec8e3d5..9bfec5e 100644 --- a/src/popup/views/addressToken.js +++ b/src/popup/views/addressToken.js @@ -159,10 +159,10 @@ function renderBalance() { const addr = state.wallets[state.selectedWallet].addresses[state.selectedAddress]; const tokenId = state.selectedToken; - let amount, price; + let balance, price; if (tokenId === "ETH") { // null when no refresh has read the balance. - amount = unknownableAmount(addr.balance); + balance = addr.balance; price = getPrice("ETH"); } else { const id = tokenId.toLowerCase(); @@ -175,12 +175,13 @@ function renderBalance() { // null when the scale is unknown, or when no refresh has read the // token's balance: no quantity to show, and none to price. // balanceLine() states that rather than printing 0.0000. - if (tb) amount = unknownableAmount(tb.balance); - else amount = tracked && tracked.balanceNotFetched ? null : 0; + if (tb) balance = tb.balance; + else balance = tracked && tracked.balanceNotFetched ? null : "0"; price = getPrice(tokenId); } // USD total for this token only + const amount = unknownableAmount(balance); const usdVal = price && amount !== null ? amount * price : null; const usdStr = formatUsd(usdVal); $("address-token-usd-total").innerHTML = escapeHtml(usdStr) || " "; @@ -188,7 +189,7 @@ function renderBalance() { // Single token balance line (no tokenId — not clickable here) $("address-token-balance").innerHTML = balanceLine( currentSymbol, - amount, + balance, price, ); } diff --git a/src/popup/views/helpers.js b/src/popup/views/helpers.js index ceb40db..b12dd16 100644 --- a/src/popup/views/helpers.js +++ b/src/popup/views/helpers.js @@ -394,13 +394,16 @@ function formatFee(wei, symbol, chainId) { // the row that issue #307 was reported against: every screen that lists a // holding renders through here. // -// `amount` is null for a holding whose scale nothing knows +// `balance` is the stored balance, a decimal string. It is null for a holding +// whose scale nothing knows // (https://git.eeqj.de/sneak/AutistMask/issues/349), and for a balance no // refresh has read. There is no quantity to print for it and no fiat value to // derive from one, and printing 0.0000 for a real holding is the failure this // whole rule exists to prevent, so the row says so instead. -function balanceLine(symbol, amount, price, tokenId) { - const qty = amount === null ? "quantity unknown" : amount.toFixed(4); +function balanceLine(symbol, balance, price, tokenId) { + const amount = unknownableAmount(balance); + const qty = + amount === null ? "quantity unknown" : truncateAmountNeverZero(balance); const usd = price && amount !== null ? escapeHtml(formatUsd(amount * price)) || " " @@ -415,7 +418,7 @@ function balanceLine(symbol, amount, price, tokenId) { `