fix: the balance lists and Home cut amounts to four decimals (closes #757)
The balance lists and Home's ETH line rounded with toFixed(4), so 0.99996 ETH read 1.0000 there and 0.9999 on Send. They now cut the stored decimal string with truncateAmount(), as the history rows do. balanceLine() takes the stored balance string instead of a parsed number, and escapes the quantity cell. The screens that state what is authorized keep the floor of truncateAmountNeverZero(). Model: opus-5-5
This commit is contained in:
1 parent
6d158bf1b1
commit
fb7c75101f
12 files changed
+146
-54
No files matched your search
+14
-11
@@ -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) {
|
||||
`<div class="flex text-xs${clickClass}"${tokenAttr}>` +
|
||||
`<span class="flex justify-between w-[42ch] max-w-full">` +
|
||||
`<span>${escapeHtml(displaySymbol(symbol))}</span>` +
|
||||
`<span>${qty}</span>` +
|
||||
`<span>${escapeHtml(qty)}</span>` +
|
||||
`</span>` +
|
||||
`<span class="text-right text-muted flex-1">${usd}</span>` +
|
||||
`</div>`
|
||||
@@ -420,7 +423,7 @@ function markTrackedTokensNotFetched() {
|
||||
function balanceLinesForAddress(addr, trackedTokens, showZero) {
|
||||
let html = balanceLine(
|
||||
nativeCurrency(),
|
||||
unknownableAmount(addr.balance),
|
||||
addr.balance,
|
||||
getPrice("ETH"),
|
||||
"ETH",
|
||||
);
|
||||
@@ -438,7 +441,7 @@ function balanceLinesForAddress(addr, trackedTokens, showZero) {
|
||||
if (bal === 0 && !showZero) continue;
|
||||
html += balanceLine(
|
||||
t.symbol,
|
||||
bal,
|
||||
t.balance,
|
||||
getPrice(t.address),
|
||||
t.address.toLowerCase(),
|
||||
);
|
||||
@@ -456,7 +459,7 @@ function balanceLinesForAddress(addr, trackedTokens, showZero) {
|
||||
}
|
||||
html += balanceLine(
|
||||
t.symbol,
|
||||
t.balanceNotFetched ? null : 0,
|
||||
t.balanceNotFetched ? null : "0",
|
||||
getPrice(t.address),
|
||||
t.address.toLowerCase(),
|
||||
);
|
||||
@@ -467,10 +470,10 @@ function balanceLinesForAddress(addr, trackedTokens, showZero) {
|
||||
|
||||
// Whether an address holds anything at all: ETH or any ERC-20 the wallet
|
||||
// knows about, except a token holding below 0.000001, which the balance list
|
||||
// under the remove-address warning leaves out too. Deliberately unrounded —
|
||||
// the rendered lines round to four decimals, so a dust balance displays as
|
||||
// 0.0000 while still being real money at a real address. Callers that warn
|
||||
// about holdings must ask this, not the rendered figure.
|
||||
// under the remove-address warning leaves out too. Deliberately exact — the
|
||||
// rendered lines cut to four decimals, so a dust balance displays as 0.0000
|
||||
// while still being real money at a real address. Callers that warn about
|
||||
// holdings must ask this, not the rendered figure.
|
||||
function addressHoldsFunds(addr) {
|
||||
if (!addr) return false;
|
||||
// A null or absent ETH balance reads as unknown, so the address may hold
|
||||
|
||||
Reference in new issue
Block a user