diff --git a/README.md b/README.md index e4a7310..5be6135 100644 --- a/README.md +++ b/README.md @@ -1191,8 +1191,8 @@ These helpers write one kind of value on every screen that shows it: 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 +`src/shared/amountDisplay.js`). The balance lists and Home's ETH balance cut +them the same way. 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: 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/deleteAddress.js b/src/popup/views/deleteAddress.js index 5614957..e3507d1 100644 --- a/src/popup/views/deleteAddress.js +++ b/src/popup/views/deleteAddress.js @@ -79,8 +79,8 @@ function recoveryPathText(wallet) { // "Holds" means ETH or any ERC-20 the wallet knows about — an address with no // ETH and a five-figure stablecoin position must not get the blank line on // the one screen whose job is to warn. The sentence names no figure of its -// own: the rendered lines round to four decimals, so a sentence built from a -// rounded number would report "0.0000 ETH" for an address holding real money. +// own: the rendered lines cut to four decimals, so a sentence built from their +// figure would report "0.0000 ETH" for an address holding real money. // The lines below it carry the amounts, in the same format as Home and // AddressDetail, followed by the USD total when there is one to give — no // total line at all on testnet, before the first price fetch or while no diff --git a/src/popup/views/helpers.js b/src/popup/views/helpers.js index af027c0..6481da4 100644 --- a/src/popup/views/helpers.js +++ b/src/popup/views/helpers.js @@ -18,6 +18,7 @@ const { formatEther } = require("ethers"); const makeBlockie = require("ethereum-blockies-base64"); const { + truncateAmount, truncateAmountNeverZero, isBelowOneMillionth, } = require("../../shared/amountDisplay"); @@ -373,13 +374,15 @@ 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" : truncateAmount(balance); const usd = price && amount !== null ? escapeHtml(formatUsd(amount * price)) || " " @@ -394,7 +397,7 @@ function balanceLine(symbol, amount, price, tokenId) { `