Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b2e2de5cd5 |
No files matched your search
@@ -1191,15 +1191,23 @@ 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
|
Most screens show token and ETH amounts with four decimal places. History rows
|
||||||
cut amounts to four decimals and never round up (`truncateAmount()` in
|
cut amounts to four decimals and never round up (`truncateAmount()` in
|
||||||
`src/shared/amountDisplay.js`). The balance lists and Home's ETH balance round
|
`src/shared/amountDisplay.js`). These balances are cut the same way:
|
||||||
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
|
- the balance lists;
|
||||||
|
- Home's ETH balance;
|
||||||
|
- Send's current balance;
|
||||||
|
- ConfirmTx's balance line.
|
||||||
|
|
||||||
|
So a balance below 0.0001 reads `0.0000` there.
|
||||||
|
|
||||||
|
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.
|
(`truncateAmountNeverZero()`). So a nonzero amount never reads as zero there.
|
||||||
Those screens are:
|
Those screens are:
|
||||||
|
|
||||||
- TxApproval;
|
- TxApproval;
|
||||||
- SignApproval's Permit warning;
|
- SignApproval's Permit warning;
|
||||||
- ConfirmTx, and Send's current balance;
|
- ConfirmTx's amount and network fee;
|
||||||
- WaitTx, SuccessTx and ErrorTx.
|
- WaitTx, SuccessTx and ErrorTx.
|
||||||
|
|
||||||
TransactionDetail shows the exact amount and its base units.
|
TransactionDetail shows the exact amount and its base units.
|
||||||
@@ -1647,10 +1655,11 @@ The development dependencies ship nowhere:
|
|||||||
|
|
||||||
### Crypto policy
|
### Crypto policy
|
||||||
|
|
||||||
In the extension, hashing, key derivation, signing and encryption go through
|
Hashing, key derivation, signing and encryption go through `ethers` or
|
||||||
`ethers` or `libsodium-wrappers-sumo`. A new recovery phrase takes its random
|
`libsodium-wrappers-sumo`. No primitive is implemented in this repository. A new
|
||||||
bytes from `ethers`. `build.js` and `script/lib/package.js` also hash files with
|
recovery phrase draws its random bytes from the browser's
|
||||||
`ethers`. No primitive is implemented in this repository.
|
`crypto.getRandomValues()`. The build tooling, `build.js` and `script/lib/`,
|
||||||
|
hashes files with Node's `crypto`; none of it ships in the extension.
|
||||||
|
|
||||||
### Content Security Policy
|
### Content Security Policy
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
|
const crypto = require("crypto");
|
||||||
const { execSync } = require("child_process");
|
const { execSync } = require("child_process");
|
||||||
const esbuild = require("esbuild");
|
const esbuild = require("esbuild");
|
||||||
const { sha256 } = require("ethers");
|
|
||||||
const { resolveVersion } = require("./script/lib/version");
|
const { resolveVersion } = require("./script/lib/version");
|
||||||
const {
|
const {
|
||||||
BACKGROUND_ENTRY_PREFIX,
|
BACKGROUND_ENTRY_PREFIX,
|
||||||
@@ -314,8 +314,10 @@ function copyIcons(distDir) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function sha256File(absPath) {
|
function sha256File(absPath) {
|
||||||
// ethers prefixes the hex with 0x; the receipt holds bare hex.
|
return crypto
|
||||||
return sha256(fs.readFileSync(absPath)).slice(2);
|
.createHash("sha256")
|
||||||
|
.update(fs.readFileSync(absPath))
|
||||||
|
.digest("hex");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write the receipt for the files this build emitted. Deliberately records no
|
// Write the receipt for the files this build emitted. Deliberately records no
|
||||||
|
|||||||
@@ -25,9 +25,9 @@
|
|||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
const crypto = require("crypto");
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
const ethers = require("ethers");
|
|
||||||
|
|
||||||
const { readZip, writeZip } = require("./zip");
|
const { readZip, writeZip } = require("./zip");
|
||||||
const { resolveVersion } = require("./version");
|
const { resolveVersion } = require("./version");
|
||||||
@@ -60,9 +60,8 @@ function fail(message) {
|
|||||||
throw new Error(message);
|
throw new Error(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lowercase hex without the 0x prefix ethers adds, as sha256sum prints it.
|
|
||||||
function sha256(buf) {
|
function sha256(buf) {
|
||||||
return ethers.sha256(buf).slice(2);
|
return crypto.createHash("sha256").update(buf).digest("hex");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Every regular file under dir, as archive-root-relative forward-slashed
|
// Every regular file under dir, as archive-root-relative forward-slashed
|
||||||
@@ -292,9 +291,4 @@ if (require.main === module) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = { checkSelfContained, htmlReferences, manifestReferences };
|
||||||
checkSelfContained,
|
|
||||||
htmlReferences,
|
|
||||||
manifestReferences,
|
|
||||||
sha256,
|
|
||||||
};
|
|
||||||
@@ -159,10 +159,10 @@ function renderBalance() {
|
|||||||
const addr =
|
const addr =
|
||||||
state.wallets[state.selectedWallet].addresses[state.selectedAddress];
|
state.wallets[state.selectedWallet].addresses[state.selectedAddress];
|
||||||
const tokenId = state.selectedToken;
|
const tokenId = state.selectedToken;
|
||||||
let amount, price;
|
let balance, price;
|
||||||
if (tokenId === "ETH") {
|
if (tokenId === "ETH") {
|
||||||
// null when no refresh has read the balance.
|
// null when no refresh has read the balance.
|
||||||
amount = unknownableAmount(addr.balance);
|
balance = addr.balance;
|
||||||
price = getPrice("ETH");
|
price = getPrice("ETH");
|
||||||
} else {
|
} else {
|
||||||
const id = tokenId.toLowerCase();
|
const id = tokenId.toLowerCase();
|
||||||
@@ -175,12 +175,13 @@ function renderBalance() {
|
|||||||
// null when the scale is unknown, or when no refresh has read the
|
// null when the scale is unknown, or when no refresh has read the
|
||||||
// token's balance: no quantity to show, and none to price.
|
// token's balance: no quantity to show, and none to price.
|
||||||
// balanceLine() states that rather than printing 0.0000.
|
// balanceLine() states that rather than printing 0.0000.
|
||||||
if (tb) amount = unknownableAmount(tb.balance);
|
if (tb) balance = tb.balance;
|
||||||
else amount = tracked && tracked.balanceNotFetched ? null : 0;
|
else balance = tracked && tracked.balanceNotFetched ? null : "0";
|
||||||
price = getPrice(tokenId);
|
price = getPrice(tokenId);
|
||||||
}
|
}
|
||||||
|
|
||||||
// USD total for this token only
|
// USD total for this token only
|
||||||
|
const amount = unknownableAmount(balance);
|
||||||
const usdVal = price && amount !== null ? amount * price : null;
|
const usdVal = price && amount !== null ? amount * price : null;
|
||||||
const usdStr = formatUsd(usdVal);
|
const usdStr = formatUsd(usdVal);
|
||||||
$("address-token-usd-total").innerHTML = escapeHtml(usdStr) || " ";
|
$("address-token-usd-total").innerHTML = escapeHtml(usdStr) || " ";
|
||||||
@@ -188,7 +189,7 @@ function renderBalance() {
|
|||||||
// Single token balance line (no tokenId — not clickable here)
|
// Single token balance line (no tokenId — not clickable here)
|
||||||
$("address-token-balance").innerHTML = balanceLine(
|
$("address-token-balance").innerHTML = balanceLine(
|
||||||
currentSymbol,
|
currentSymbol,
|
||||||
amount,
|
balance,
|
||||||
price,
|
price,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,9 +43,12 @@ const {
|
|||||||
transferAmountUnits,
|
transferAmountUnits,
|
||||||
} = require("../../shared/transferAmount");
|
} = require("../../shared/transferAmount");
|
||||||
const { assertWithinCeilings } = require("../../shared/approvalVerify");
|
const { assertWithinCeilings } = require("../../shared/approvalVerify");
|
||||||
// The amount, the balance line and the fee reserve go through it, as the
|
// The amount and the fee reserve keep the nonzero floor, as the approval
|
||||||
// approval screen's amounts do.
|
// screen's amounts do. The balance line is cut as the balance lists cut it.
|
||||||
const { truncateAmountNeverZero } = require("../../shared/amountDisplay");
|
const {
|
||||||
|
truncateAmount,
|
||||||
|
truncateAmountNeverZero,
|
||||||
|
} = require("../../shared/amountDisplay");
|
||||||
const {
|
const {
|
||||||
CODES,
|
CODES,
|
||||||
FEE_PENDING,
|
FEE_PENDING,
|
||||||
@@ -160,7 +163,7 @@ function renderBalance(txInfo) {
|
|||||||
const price = getPrice(txInfo.token, txInfo.chainId);
|
const price = getPrice(txInfo.token, txInfo.chainId);
|
||||||
const balUsd = price ? parseFloat(bal) * price : null;
|
const balUsd = price ? parseFloat(bal) * price : null;
|
||||||
$("confirm-balance").textContent = valueWithUsd(
|
$("confirm-balance").textContent = valueWithUsd(
|
||||||
truncateAmountNeverZero(bal) + " " + symbol,
|
truncateAmount(bal) + " " + symbol,
|
||||||
balUsd,
|
balUsd,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,8 +79,8 @@ function recoveryPathText(wallet) {
|
|||||||
// "Holds" means ETH or any ERC-20 the wallet knows about — an address with no
|
// "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
|
// 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
|
// 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
|
// own: the rendered lines cut to four decimals, so a sentence built from their
|
||||||
// rounded number would report "0.0000 ETH" for an address holding real money.
|
// 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
|
// 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
|
// 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
|
// total line at all on testnet, before the first price fetch or while no
|
||||||
|
|||||||
+14
-11
@@ -18,6 +18,7 @@
|
|||||||
const { formatEther } = require("ethers");
|
const { formatEther } = require("ethers");
|
||||||
const makeBlockie = require("ethereum-blockies-base64");
|
const makeBlockie = require("ethereum-blockies-base64");
|
||||||
const {
|
const {
|
||||||
|
truncateAmount,
|
||||||
truncateAmountNeverZero,
|
truncateAmountNeverZero,
|
||||||
isBelowOneMillionth,
|
isBelowOneMillionth,
|
||||||
} = require("../../shared/amountDisplay");
|
} = 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
|
// the row that issue #307 was reported against: every screen that lists a
|
||||||
// holding renders through here.
|
// 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
|
// (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
|
// 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
|
// 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.
|
// whole rule exists to prevent, so the row says so instead.
|
||||||
function balanceLine(symbol, amount, price, tokenId) {
|
function balanceLine(symbol, balance, price, tokenId) {
|
||||||
const qty = amount === null ? "quantity unknown" : amount.toFixed(4);
|
const amount = unknownableAmount(balance);
|
||||||
|
const qty = amount === null ? "quantity unknown" : truncateAmount(balance);
|
||||||
const usd =
|
const usd =
|
||||||
price && amount !== null
|
price && amount !== null
|
||||||
? escapeHtml(formatUsd(amount * price)) || " "
|
? escapeHtml(formatUsd(amount * price)) || " "
|
||||||
@@ -394,7 +397,7 @@ function balanceLine(symbol, amount, price, tokenId) {
|
|||||||
`<div class="flex text-xs${clickClass}"${tokenAttr}>` +
|
`<div class="flex text-xs${clickClass}"${tokenAttr}>` +
|
||||||
`<span class="flex justify-between w-[42ch] max-w-full">` +
|
`<span class="flex justify-between w-[42ch] max-w-full">` +
|
||||||
`<span>${escapeHtml(displaySymbol(symbol))}</span>` +
|
`<span>${escapeHtml(displaySymbol(symbol))}</span>` +
|
||||||
`<span>${qty}</span>` +
|
`<span>${escapeHtml(qty)}</span>` +
|
||||||
`</span>` +
|
`</span>` +
|
||||||
`<span class="text-right text-muted flex-1">${usd}</span>` +
|
`<span class="text-right text-muted flex-1">${usd}</span>` +
|
||||||
`</div>`
|
`</div>`
|
||||||
@@ -420,7 +423,7 @@ function markTrackedTokensNotFetched() {
|
|||||||
function balanceLinesForAddress(addr, trackedTokens, showZero) {
|
function balanceLinesForAddress(addr, trackedTokens, showZero) {
|
||||||
let html = balanceLine(
|
let html = balanceLine(
|
||||||
nativeCurrency(),
|
nativeCurrency(),
|
||||||
unknownableAmount(addr.balance),
|
addr.balance,
|
||||||
getPrice("ETH"),
|
getPrice("ETH"),
|
||||||
"ETH",
|
"ETH",
|
||||||
);
|
);
|
||||||
@@ -438,7 +441,7 @@ function balanceLinesForAddress(addr, trackedTokens, showZero) {
|
|||||||
if (bal === 0 && !showZero) continue;
|
if (bal === 0 && !showZero) continue;
|
||||||
html += balanceLine(
|
html += balanceLine(
|
||||||
t.symbol,
|
t.symbol,
|
||||||
bal,
|
t.balance,
|
||||||
getPrice(t.address),
|
getPrice(t.address),
|
||||||
t.address.toLowerCase(),
|
t.address.toLowerCase(),
|
||||||
);
|
);
|
||||||
@@ -456,7 +459,7 @@ function balanceLinesForAddress(addr, trackedTokens, showZero) {
|
|||||||
}
|
}
|
||||||
html += balanceLine(
|
html += balanceLine(
|
||||||
t.symbol,
|
t.symbol,
|
||||||
t.balanceNotFetched ? null : 0,
|
t.balanceNotFetched ? null : "0",
|
||||||
getPrice(t.address),
|
getPrice(t.address),
|
||||||
t.address.toLowerCase(),
|
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
|
// 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
|
// knows about, except a token holding below 0.000001, which the balance list
|
||||||
// under the remove-address warning leaves out too. Deliberately unrounded —
|
// under the remove-address warning leaves out too. Deliberately exact — the
|
||||||
// the rendered lines round to four decimals, so a dust balance displays as
|
// rendered lines cut to four decimals, so a dust balance displays as 0.0000
|
||||||
// 0.0000 while still being real money at a real address. Callers that warn
|
// while still being real money at a real address. Callers that warn about
|
||||||
// about holdings must ask this, not the rendered figure.
|
// holdings must ask this, not the rendered figure.
|
||||||
function addressHoldsFunds(addr) {
|
function addressHoldsFunds(addr) {
|
||||||
if (!addr) return false;
|
if (!addr) return false;
|
||||||
// A null or absent ETH balance reads as unknown, so the address may hold
|
// A null or absent ETH balance reads as unknown, so the address may hold
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ const {
|
|||||||
resetSendValidation,
|
resetSendValidation,
|
||||||
} = require("./send");
|
} = require("./send");
|
||||||
const { deriveAddressFromXpub } = require("../../shared/wallet");
|
const { deriveAddressFromXpub } = require("../../shared/wallet");
|
||||||
|
const { truncateAmount } = require("../../shared/amountDisplay");
|
||||||
const { canRemoveAddress } = require("../../shared/walletDelete");
|
const { canRemoveAddress } = require("../../shared/walletDelete");
|
||||||
const {
|
const {
|
||||||
walletDefect,
|
walletDefect,
|
||||||
@@ -81,7 +82,7 @@ function renderTotalValue() {
|
|||||||
if (ethBal === null) {
|
if (ethBal === null) {
|
||||||
el.textContent = "unknown (" + nativeCurrency() + ")";
|
el.textContent = "unknown (" + nativeCurrency() + ")";
|
||||||
} else {
|
} else {
|
||||||
const ethStr = ethBal.toFixed(4) + " " + nativeCurrency();
|
const ethStr = truncateAmount(addr.balance) + " " + nativeCurrency();
|
||||||
const ethUsd = ethPrice
|
const ethUsd = ethPrice
|
||||||
? " (" + formatUsd(ethBal * ethPrice) + ")"
|
? " (" + formatUsd(ethBal * ethPrice) + ")"
|
||||||
: "";
|
: "";
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ const { resolveSymbol } = require("../../shared/tokenList");
|
|||||||
const { isLowHolderCount } = require("../../shared/holders");
|
const { isLowHolderCount } = require("../../shared/holders");
|
||||||
const { isSpoofedSymbol } = require("../../shared/symbolSpoof");
|
const { isSpoofedSymbol } = require("../../shared/symbolSpoof");
|
||||||
const {
|
const {
|
||||||
truncateAmountNeverZero,
|
truncateAmount,
|
||||||
isBelowOneMillionth,
|
isBelowOneMillionth,
|
||||||
} = require("../../shared/amountDisplay");
|
} = require("../../shared/amountDisplay");
|
||||||
const {
|
const {
|
||||||
@@ -239,7 +239,7 @@ function updateSendBalance() {
|
|||||||
addr.balance == null
|
addr.balance == null
|
||||||
? "Current balance: unknown (" + nativeCurrency() + ")"
|
? "Current balance: unknown (" + nativeCurrency() + ")"
|
||||||
: "Current balance: " +
|
: "Current balance: " +
|
||||||
truncateAmountNeverZero(addr.balance) +
|
truncateAmount(addr.balance) +
|
||||||
" " +
|
" " +
|
||||||
nativeCurrency();
|
nativeCurrency();
|
||||||
} else {
|
} else {
|
||||||
@@ -258,18 +258,15 @@ function updateSendBalance() {
|
|||||||
$("send-balance").textContent =
|
$("send-balance").textContent =
|
||||||
bal == null
|
bal == null
|
||||||
? "Current balance: unknown (" + symbol + ")"
|
? "Current balance: unknown (" + symbol + ")"
|
||||||
: "Current balance: " +
|
: "Current balance: " + truncateAmount(bal) + " " + symbol;
|
||||||
truncateAmountNeverZero(bal) +
|
|
||||||
" " +
|
|
||||||
symbol;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fill the amount field with the most the selected holding can send: a
|
// Fill the amount field with the most the selected holding can send: a
|
||||||
// token's whole balance (cut to 18 decimal places), or for ETH the exact
|
// token's whole balance (cut to 18 decimal places), or for ETH the exact
|
||||||
// balance minus the fee reserve the confirmation screen checks against, never
|
// balance minus the fee reserve the confirmation screen checks against, never
|
||||||
// the rounded balance the screen shows. Where there is nothing to fill in, a
|
// the balance the screen shows, which is cut to four decimals. Where there is
|
||||||
// flash message says why.
|
// nothing to fill in, a flash message says why.
|
||||||
async function fillMaxAmount() {
|
async function fillMaxAmount() {
|
||||||
const addr = currentAddress();
|
const addr = currentAddress();
|
||||||
if (!addr) return;
|
if (!addr) return;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// Wallet operations: mnemonic generation, HD derivation, signing.
|
// Wallet operations: mnemonic generation, HD derivation, signing.
|
||||||
// All crypto delegated to ethers.js.
|
// All crypto delegated to ethers.js.
|
||||||
|
|
||||||
const { Mnemonic, HDNodeWallet, Wallet, randomBytes } = require("ethers");
|
const { Mnemonic, HDNodeWallet, Wallet } = require("ethers");
|
||||||
const { DEBUG, DEBUG_MNEMONIC, BIP44_ETH_PATH } = require("./constants");
|
const { DEBUG, DEBUG_MNEMONIC, BIP44_ETH_PATH } = require("./constants");
|
||||||
|
|
||||||
function generateMnemonic() {
|
function generateMnemonic() {
|
||||||
@@ -10,7 +10,10 @@ function generateMnemonic() {
|
|||||||
// settings toggle drives, which would let a user of a release build turn
|
// settings toggle drives, which would let a user of a release build turn
|
||||||
// the hardcoded, publicly known test phrase back on for real wallets.
|
// the hardcoded, publicly known test phrase back on for real wallets.
|
||||||
if (DEBUG) return DEBUG_MNEMONIC;
|
if (DEBUG) return DEBUG_MNEMONIC;
|
||||||
return Mnemonic.fromEntropy(randomBytes(16)).phrase;
|
const m = Mnemonic.fromEntropy(
|
||||||
|
globalThis.crypto.getRandomValues(new Uint8Array(16)),
|
||||||
|
);
|
||||||
|
return m.phrase;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Every extended key (xprv or xpub) entering the app goes through this.
|
// Every extended key (xprv or xpub) entering the app goes through this.
|
||||||
|
|||||||
@@ -25,10 +25,6 @@ const { ERC20_ABI } = require("../src/shared/constants");
|
|||||||
const { state } = require("../src/shared/state");
|
const { state } = require("../src/shared/state");
|
||||||
const { decodeCalldata } = require("../src/shared/calldataDecoder");
|
const { decodeCalldata } = require("../src/shared/calldataDecoder");
|
||||||
const uniswap = require("../src/shared/uniswap");
|
const uniswap = require("../src/shared/uniswap");
|
||||||
const {
|
|
||||||
truncateAmount,
|
|
||||||
truncateAmountNeverZero,
|
|
||||||
} = require("../src/shared/amountDisplay");
|
|
||||||
|
|
||||||
const iface = new Interface(ERC20_ABI);
|
const iface = new Interface(ERC20_ABI);
|
||||||
|
|
||||||
@@ -183,15 +179,4 @@ describe("the four-decimal rule is otherwise unchanged", () => {
|
|||||||
test("a genuine zero still renders as zero", () => {
|
test("a genuine zero still renders as zero", () => {
|
||||||
expect(amount(transferData(0n), DAI).rawValue).toBe("0.0000");
|
expect(amount(transferData(0n), DAI).rawValue).toBe("0.0000");
|
||||||
});
|
});
|
||||||
|
|
||||||
// The three truncators now share one module. The floor is a policy of the
|
|
||||||
// approval and confirmation screens only: the history and balance lists
|
|
||||||
// keep plain truncation, because the transaction detail view is the
|
|
||||||
// authoritative record and already shows exact precision.
|
|
||||||
test("the list rule stays unfloored", () => {
|
|
||||||
expect(truncateAmount("0.000000000000000001")).toBe("0.0000");
|
|
||||||
expect(truncateAmountNeverZero("0.000000000000000001")).toBe(
|
|
||||||
"0.000000000000000001",
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
@@ -41,13 +41,13 @@ describe("balanceLine", () => {
|
|||||||
// this payload before its id attribute, so an assertion about the
|
// this payload before its id attribute, so an assertion about the
|
||||||
// rest of the payload would pass on the cap and say nothing about
|
// rest of the payload would pass on the cap and say nothing about
|
||||||
// the escape.
|
// the escape.
|
||||||
const html = balanceLine(HOSTILE_SYMBOL, 1, null, null);
|
const html = balanceLine(HOSTILE_SYMBOL, "1", null, null);
|
||||||
expect(html).not.toContain("<iframe");
|
expect(html).not.toContain("<iframe");
|
||||||
expect(html).toContain("<iframe");
|
expect(html).toContain("<iframe");
|
||||||
});
|
});
|
||||||
|
|
||||||
test("caps the symbol before rendering it", () => {
|
test("caps the symbol before rendering it", () => {
|
||||||
const html = balanceLine("A".repeat(4096), 1, null, null);
|
const html = balanceLine("A".repeat(4096), "1", null, null);
|
||||||
expect(html).toContain("A".repeat(MAX_SYMBOL_LENGTH - 1) + "…");
|
expect(html).toContain("A".repeat(MAX_SYMBOL_LENGTH - 1) + "…");
|
||||||
expect(html).not.toContain("A".repeat(MAX_SYMBOL_LENGTH + 1));
|
expect(html).not.toContain("A".repeat(MAX_SYMBOL_LENGTH + 1));
|
||||||
});
|
});
|
||||||
@@ -55,13 +55,13 @@ describe("balanceLine", () => {
|
|||||||
// The token id lands inside data-token="...", so a quote in it is a
|
// The token id lands inside data-token="...", so a quote in it is a
|
||||||
// way out of the attribute and into a new one.
|
// way out of the attribute and into a new one.
|
||||||
test("keeps a quote-bearing token id inside its attribute", () => {
|
test("keeps a quote-bearing token id inside its attribute", () => {
|
||||||
const html = balanceLine("TKN", 1, null, '" onclick="alert(1)');
|
const html = balanceLine("TKN", "1", null, '" onclick="alert(1)');
|
||||||
expect(html).not.toContain('onclick="');
|
expect(html).not.toContain('onclick="');
|
||||||
expect(html).toContain('data-token="" onclick="alert(1)"');
|
expect(html).toContain('data-token="" onclick="alert(1)"');
|
||||||
});
|
});
|
||||||
|
|
||||||
test("renders an ordinary holding unchanged", () => {
|
test("renders an ordinary holding unchanged", () => {
|
||||||
const html = balanceLine("USDC", 1.5, null, "0xabc");
|
const html = balanceLine("USDC", "1.5", null, "0xabc");
|
||||||
expect(html).toContain("<span>USDC</span>");
|
expect(html).toContain("<span>USDC</span>");
|
||||||
expect(html).toContain("<span>1.5000</span>");
|
expect(html).toContain("<span>1.5000</span>");
|
||||||
expect(html).toContain('data-token="0xabc"');
|
expect(html).toContain('data-token="0xabc"');
|
||||||
@@ -69,7 +69,7 @@ describe("balanceLine", () => {
|
|||||||
|
|
||||||
// formatUsd() writes a value under a cent as "< $0.01".
|
// formatUsd() writes a value under a cent as "< $0.01".
|
||||||
test("escapes the USD value along with the symbol", () => {
|
test("escapes the USD value along with the symbol", () => {
|
||||||
const html = balanceLine("USDC", 0.001, 1, null);
|
const html = balanceLine("USDC", "0.001", 1, null);
|
||||||
expect(html).toContain("< $0.01");
|
expect(html).toContain("< $0.01");
|
||||||
expect(html).not.toContain("< $0.01");
|
expect(html).not.toContain("< $0.01");
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,91 @@
|
|||||||
|
// The balance lists, Home's ETH line and Send's current balance show a balance
|
||||||
|
// as the history rows do (README.md, Amounts): cut to four decimal places,
|
||||||
|
// never rounded up (https://git.eeqj.de/sneak/AutistMask/issues/757).
|
||||||
|
//
|
||||||
|
// Driven through the real popup over a stored profile on Ethereum Mainnet.
|
||||||
|
|
||||||
|
const {
|
||||||
|
ADDRESS,
|
||||||
|
bootPopup,
|
||||||
|
cleanupPopup,
|
||||||
|
unversionedValidProfile,
|
||||||
|
} = require("./support/popupBoot");
|
||||||
|
const { balanceLine } = require("../src/popup/views/helpers");
|
||||||
|
|
||||||
|
const USDC = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48";
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
cleanupPopup();
|
||||||
|
});
|
||||||
|
|
||||||
|
// The quantity cell of a balance row.
|
||||||
|
function quantity(row) {
|
||||||
|
return row.match(/<span>([^<]*)<\/span><\/span>/)[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
// The popup on Home over one address holding `eth` ETH and `usdc` USDC.
|
||||||
|
function bootHolding(eth, usdc) {
|
||||||
|
const profile = unversionedValidProfile({
|
||||||
|
trackedTokens: [{ address: USDC, symbol: "USDC", decimals: 6 }],
|
||||||
|
});
|
||||||
|
profile.wallets[0].addresses[0] = {
|
||||||
|
address: ADDRESS,
|
||||||
|
balance: eth,
|
||||||
|
tokenBalances: [
|
||||||
|
{ address: USDC, symbol: "USDC", decimals: 6, balance: usdc },
|
||||||
|
],
|
||||||
|
};
|
||||||
|
return bootPopup(profile);
|
||||||
|
}
|
||||||
|
|
||||||
|
// The balance row for `token` in Home's wallet list.
|
||||||
|
function homeRow(page, token) {
|
||||||
|
return page
|
||||||
|
.node("wallet-list")
|
||||||
|
.innerHTML.split("<div ")
|
||||||
|
.find((row) => row.includes('data-token="' + token + '"'));
|
||||||
|
}
|
||||||
|
|
||||||
|
describe("balanceLine", () => {
|
||||||
|
test("cuts 0.99996 to 0.9999, never rounding it up to 1.0000", () => {
|
||||||
|
expect(quantity(balanceLine("ETH", "0.99996", null, "ETH"))).toBe(
|
||||||
|
"0.9999",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("cuts 0.00004 to 0.0000", () => {
|
||||||
|
expect(quantity(balanceLine("USDC", "0.00004", null, USDC))).toBe(
|
||||||
|
"0.0000",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("Home", () => {
|
||||||
|
test("the ETH line and the balance list read 0.99996 ETH as 0.9999", async () => {
|
||||||
|
const page = await bootHolding("0.99996", "0.00004");
|
||||||
|
|
||||||
|
expect(page.visibleViews()).toEqual(["main"]);
|
||||||
|
expect(page.text("total-value")).toBe("0.9999 ETH");
|
||||||
|
expect(quantity(homeRow(page, "ETH"))).toBe("0.9999");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("the balance list reads 0.00004 USDC as 0.0000", async () => {
|
||||||
|
const page = await bootHolding("0.99996", "0.00004");
|
||||||
|
|
||||||
|
expect(quantity(homeRow(page, USDC.toLowerCase()))).toBe("0.0000");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("Send", () => {
|
||||||
|
test("the current balance reads 0.00004 USDC as 0.0000", async () => {
|
||||||
|
const page = await bootHolding("0.99996", "0.00004");
|
||||||
|
await page.click("btn-main-send");
|
||||||
|
// USDC chosen in the dropdown, as the user does.
|
||||||
|
const dropdown = page.node("send-token");
|
||||||
|
dropdown.value = USDC;
|
||||||
|
for (const fn of dropdown.listeners.change) await fn();
|
||||||
|
|
||||||
|
expect(page.visibleViews()).toEqual(["send"]);
|
||||||
|
expect(page.text("send-balance")).toBe("Current balance: 0.0000 USDC");
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -4,8 +4,8 @@
|
|||||||
// the copy is the substance and is tested as such. Two things it must not
|
// the copy is the substance and is tested as such. Two things it must not
|
||||||
// get wrong: what it takes to get the address back — the app refuses both
|
// get wrong: what it takes to get the address back — the app refuses both
|
||||||
// obvious routes — and what counts as holding something, which is any
|
// obvious routes — and what counts as holding something, which is any
|
||||||
// ERC-20 as well as ETH, at any size, including a balance that rounds to
|
// ERC-20 as well as ETH, at any size, including a balance below the four
|
||||||
// zero at the four decimals the balance lines render. The DOM behaviour
|
// decimals the balance lines render. The DOM behaviour
|
||||||
// around them is driven against the real popup by tests/e2e/run.js.
|
// around them is driven against the real popup by tests/e2e/run.js.
|
||||||
|
|
||||||
// helpers.js pulls in state.js, which reads chrome.storage.local at load.
|
// helpers.js pulls in state.js, which reads chrome.storage.local at load.
|
||||||
@@ -165,9 +165,9 @@ describe("the balance warning on the removal confirmation", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// The sentence must not assert an amount, because any amount it could
|
// The sentence must not assert an amount, because any amount it could
|
||||||
// assert has been rounded: "This address holds 0.0000 ETH." is what the
|
// assert has been cut to four decimals: "This address holds 0.0000 ETH." is
|
||||||
// rounded form produces for an address that holds real money.
|
// what the cut form produces for an address that holds real money.
|
||||||
test("the warning sentence asserts no rounded amount", () => {
|
test("the warning sentence asserts no cut amount", () => {
|
||||||
for (const addr of [DUST, ETH_ONLY, TOKEN_ONLY]) {
|
for (const addr of [DUST, ETH_ONLY, TOKEN_ONLY]) {
|
||||||
expect(balanceWarningHtml(addr)).not.toMatch(
|
expect(balanceWarningHtml(addr)).not.toMatch(
|
||||||
/holds [\d.]+ (ETH|USDC)/,
|
/holds [\d.]+ (ETH|USDC)/,
|
||||||
|
|||||||
+9
-9
@@ -829,12 +829,11 @@ test("a common-token quick-pick fills in the contract address (#150)", async (en
|
|||||||
await visible(env.page, "#view-address");
|
await visible(env.page, "#view-address");
|
||||||
});
|
});
|
||||||
|
|
||||||
// The native amount as the transaction list writes it (four decimals) and
|
// The native amount as the transaction list writes it (cut to four decimals,
|
||||||
// as the detail screen writes it (full precision). Both are rendered here
|
// quantity() below) and as the detail screen writes it (full precision). Both
|
||||||
// from the fixture rather than read off the screen, so the assertions
|
// are rendered here from the fixture rather than read off the screen, so the
|
||||||
// compare against the wei the stub served.
|
// assertions compare against the wei the stub served.
|
||||||
const NATIVE_ROW_TEXT =
|
const NATIVE_ROW_TEXT = quantity(STUB_NATIVE_VALUE_WEI) + " ETH";
|
||||||
parseFloat(formatEther(STUB_NATIVE_VALUE_WEI)).toFixed(4) + " ETH";
|
|
||||||
const NATIVE_DETAIL_TEXT = formatEther(STUB_NATIVE_VALUE_WEI) + " ETH";
|
const NATIVE_DETAIL_TEXT = formatEther(STUB_NATIVE_VALUE_WEI) + " ETH";
|
||||||
|
|
||||||
test("the native ETH transaction detail still renders (#151)", async (env) => {
|
test("the native ETH transaction detail still renders (#151)", async (env) => {
|
||||||
@@ -2724,10 +2723,11 @@ async function goToConfirm(page, send) {
|
|||||||
await assertAddressesFit(page, "the confirmation screen");
|
await assertAddressesFit(page, "the confirmation screen");
|
||||||
}
|
}
|
||||||
|
|
||||||
// A balance as the main view renders it: balanceLinesForAddress() writes
|
// An amount in wei as the main view's balance lines and the transaction list
|
||||||
// every quantity with four decimal places.
|
// write it: cut to four decimal places, never rounded, as feeEth() does.
|
||||||
function quantity(wei) {
|
function quantity(wei) {
|
||||||
return parseFloat(formatEther(wei)).toFixed(4);
|
const [whole, frac = ""] = formatEther(wei).split(".");
|
||||||
|
return whole + "." + (frac + "0000").slice(0, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wait on the main view until a changed balance fixture has been picked up.
|
// Wait on the main view until a changed balance fixture has been picked up.
|
||||||
|
|||||||
+2
-13
@@ -1,5 +1,4 @@
|
|||||||
// The release archives: the zip container, the self-containment rule, and the
|
// The release archives: the zip container, and the self-containment rule.
|
||||||
// digest format in release/SHA256SUMS.
|
|
||||||
//
|
//
|
||||||
// script/package produces one archive per browser and script/lib/package.js
|
// script/package produces one archive per browser and script/lib/package.js
|
||||||
// decides what goes in it. The trap that rule exists for is real and specific:
|
// decides what goes in it. The trap that rule exists for is real and specific:
|
||||||
@@ -12,14 +11,12 @@
|
|||||||
// So the packager resolves every reference in the manifest and in every HTML
|
// So the packager resolves every reference in the manifest and in every HTML
|
||||||
// document, and fails on any that leaves the extension root. These are the
|
// document, and fails on any that leaves the extension root. These are the
|
||||||
// cases for that, plus the archive format itself — new code, and the thing the
|
// cases for that, plus the archive format itself — new code, and the thing the
|
||||||
// artifact is made of. One more case checks the digest format in
|
// artifact is made of.
|
||||||
// release/SHA256SUMS.
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
checkSelfContained,
|
checkSelfContained,
|
||||||
htmlReferences,
|
htmlReferences,
|
||||||
manifestReferences,
|
manifestReferences,
|
||||||
sha256,
|
|
||||||
} = require("../script/lib/package");
|
} = require("../script/lib/package");
|
||||||
const { readZip, writeZip } = require("../script/lib/zip");
|
const { readZip, writeZip } = require("../script/lib/zip");
|
||||||
|
|
||||||
@@ -145,14 +142,6 @@ describe("archive self-containment", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// release/SHA256SUMS is checked with `sha256sum -c`, which needs the digest
|
|
||||||
// as bare lowercase hex. The expected value is the FIPS 180-2 digest of "abc".
|
|
||||||
test("sha256 prints the digest as sha256sum does", () => {
|
|
||||||
expect(sha256(Buffer.from("abc"))).toBe(
|
|
||||||
"ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad",
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("the zip container", () => {
|
describe("the zip container", () => {
|
||||||
const files = [
|
const files = [
|
||||||
{ name: "manifest.json", data: Buffer.from('{"a":1}') },
|
{ name: "manifest.json", data: Buffer.from('{"a":1}') },
|
||||||
|
|||||||
@@ -6,8 +6,10 @@
|
|||||||
// balances and the fee were each cut to six decimal places, a rule of their
|
// balances and the fee were each cut to six decimal places, a rule of their
|
||||||
// own, and a token holding cut to zero was dropped, while the approval screen
|
// own, and a token holding cut to zero was dropped, while the approval screen
|
||||||
// showed the same fee through src/shared/amountDisplay.js with the nonzero
|
// showed the same fee through src/shared/amountDisplay.js with the nonzero
|
||||||
// floor. The balances are now stored exactly, every nonzero token holding
|
// floor. The balances are now stored exactly, and every nonzero token holding
|
||||||
// kept, and the screens show them and the fee through that helper.
|
// is kept. The fee lines show the fee through that helper with the floor. The
|
||||||
|
// balance lines cut a balance to four decimals, as the balance lists do, so a
|
||||||
|
// balance below 0.0001 reads 0.0000.
|
||||||
//
|
//
|
||||||
// Driven through the real refreshBalances(), Send screen, confirmation screen
|
// Driven through the real refreshBalances(), Send screen, confirmation screen
|
||||||
// and approval screen, with only the node, the explorer and the DOM stubbed: a
|
// and approval screen, with only the node, the explorer and the DOM stubbed: a
|
||||||
@@ -278,21 +280,21 @@ beforeEach(() => {
|
|||||||
mockNode.feeData = { maxFeePerGas: 1n, gasPrice: 1n };
|
mockNode.feeData = { maxFeePerGas: 1n, gasPrice: 1n };
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("an ETH balance below 0.000001 never renders as zero", () => {
|
describe("an ETH balance below 0.0001 reads 0.0000", () => {
|
||||||
test("on the Send screen", async () => {
|
test("on the Send screen", async () => {
|
||||||
await refreshWith(HALF_MICRO_ETH);
|
await refreshWith(HALF_MICRO_ETH);
|
||||||
state.selectedToken = "ETH";
|
state.selectedToken = "ETH";
|
||||||
send.updateSendBalance();
|
send.updateSendBalance();
|
||||||
expect(text("send-balance")).toBe("Current balance: 0.0000005 ETH");
|
expect(text("send-balance")).toBe("Current balance: 0.0000 ETH");
|
||||||
});
|
});
|
||||||
|
|
||||||
test("on the confirmation screen", async () => {
|
test("on the confirmation screen", async () => {
|
||||||
await refreshWith(HALF_MICRO_ETH);
|
await refreshWith(HALF_MICRO_ETH);
|
||||||
await confirmSend("0.0000001");
|
await confirmSend("0.0000001");
|
||||||
expect(text("confirm-balance")).toBe("0.0000005 ETH");
|
expect(text("confirm-balance")).toBe("0.0000 ETH");
|
||||||
});
|
});
|
||||||
|
|
||||||
test("while a balance above the floor keeps four decimals", async () => {
|
test("while a larger balance is cut to four decimals", async () => {
|
||||||
await refreshWith(1234567890000000000n);
|
await refreshWith(1234567890000000000n);
|
||||||
await confirmSend("0.1");
|
await confirmSend("0.1");
|
||||||
expect(text("confirm-balance")).toBe("1.2345 ETH");
|
expect(text("confirm-balance")).toBe("1.2345 ETH");
|
||||||
@@ -302,7 +304,7 @@ describe("an ETH balance below 0.000001 never renders as zero", () => {
|
|||||||
// A token the user tracks stays on the balance list when the explorer's row is
|
// A token the user tracks stays on the balance list when the explorer's row is
|
||||||
// dropped, so a holding of it below 0.000001 reached these screens as zero, and
|
// dropped, so a holding of it below 0.000001 reached these screens as zero, and
|
||||||
// the send was checked against zero.
|
// the send was checked against zero.
|
||||||
describe("a tracked token holding below 0.000001 never renders as zero", () => {
|
describe("a tracked token holding below 0.000001 reads 0.0000", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
state.trackedTokens = [
|
state.trackedTokens = [
|
||||||
{ address: TOKEN, symbol: "TOK", name: "Token", decimals: 18 },
|
{ address: TOKEN, symbol: "TOK", name: "Token", decimals: 18 },
|
||||||
@@ -313,13 +315,13 @@ describe("a tracked token holding below 0.000001 never renders as zero", () => {
|
|||||||
await refreshWith(10n ** 18n, [tokenRow(HALF_MICRO_ETH)]);
|
await refreshWith(10n ** 18n, [tokenRow(HALF_MICRO_ETH)]);
|
||||||
state.selectedToken = TOKEN;
|
state.selectedToken = TOKEN;
|
||||||
send.updateSendBalance();
|
send.updateSendBalance();
|
||||||
expect(text("send-balance")).toBe("Current balance: 0.0000005 TOK");
|
expect(text("send-balance")).toBe("Current balance: 0.0000 TOK");
|
||||||
});
|
});
|
||||||
|
|
||||||
test("on the confirmation screen, which checks the send against it", async () => {
|
test("on the confirmation screen, which checks the send against it", async () => {
|
||||||
await refreshWith(10n ** 18n, [tokenRow(HALF_MICRO_ETH)]);
|
await refreshWith(10n ** 18n, [tokenRow(HALF_MICRO_ETH)]);
|
||||||
await confirmSend("0.0000005", TOKEN);
|
await confirmSend("0.0000005", TOKEN);
|
||||||
expect(text("confirm-balance")).toBe("0.0000005 TOK");
|
expect(text("confirm-balance")).toBe("0.0000 TOK");
|
||||||
expect(errors()).toBe("");
|
expect(errors()).toBe("");
|
||||||
expect(balanceError()).toBe("");
|
expect(balanceError()).toBe("");
|
||||||
await confirmSend("0.0000006", TOKEN);
|
await confirmSend("0.0000006", TOKEN);
|
||||||
@@ -347,11 +349,9 @@ describe("a tracked token holding below 0.000001 never renders as zero", () => {
|
|||||||
await refreshWith(10n ** 18n, [tokenRow(1n, { decimals: "24" })]);
|
await refreshWith(10n ** 18n, [tokenRow(1n, { decimals: "24" })]);
|
||||||
state.selectedToken = TOKEN;
|
state.selectedToken = TOKEN;
|
||||||
send.updateSendBalance();
|
send.updateSendBalance();
|
||||||
expect(text("send-balance")).toBe(
|
expect(text("send-balance")).toBe("Current balance: 0.0000 TOK");
|
||||||
"Current balance: 0.000000000000000000000001 TOK",
|
|
||||||
);
|
|
||||||
await confirmSend("0.000000000000000001", TOKEN);
|
await confirmSend("0.000000000000000001", TOKEN);
|
||||||
expect(text("confirm-balance")).toBe("0.000000000000000000000001 TOK");
|
expect(text("confirm-balance")).toBe("0.0000 TOK");
|
||||||
expect(balanceError()).toContain(
|
expect(balanceError()).toContain(
|
||||||
"Your TOK balance does not cover this amount.",
|
"Your TOK balance does not cover this amount.",
|
||||||
);
|
);
|
||||||
@@ -363,20 +363,20 @@ describe("a tracked token holding below 0.000001 never renders as zero", () => {
|
|||||||
// selected while its own screen is open: after sending 2 of a 2.0000003
|
// selected while its own screen is open: after sending 2 of a 2.0000003
|
||||||
// holding, the user is back on that screen, and Send read the missing row as
|
// holding, the user is back on that screen, and Send read the missing row as
|
||||||
// zero.
|
// zero.
|
||||||
describe("an untracked token holding below 0.000001 never renders as zero", () => {
|
describe("an untracked token holding below 0.000001 reads 0.0000", () => {
|
||||||
const row = () => tokenRow(HALF_MICRO_ETH, { holders_count: "50000" });
|
const row = () => tokenRow(HALF_MICRO_ETH, { holders_count: "50000" });
|
||||||
|
|
||||||
test("on the Send screen", async () => {
|
test("on the Send screen", async () => {
|
||||||
await refreshWith(10n ** 18n, [row()]);
|
await refreshWith(10n ** 18n, [row()]);
|
||||||
state.selectedToken = TOKEN;
|
state.selectedToken = TOKEN;
|
||||||
send.updateSendBalance();
|
send.updateSendBalance();
|
||||||
expect(text("send-balance")).toBe("Current balance: 0.0000005 TOK");
|
expect(text("send-balance")).toBe("Current balance: 0.0000 TOK");
|
||||||
});
|
});
|
||||||
|
|
||||||
test("on the confirmation screen, which checks the send against it", async () => {
|
test("on the confirmation screen, which checks the send against it", async () => {
|
||||||
await refreshWith(10n ** 18n, [row()]);
|
await refreshWith(10n ** 18n, [row()]);
|
||||||
await confirmSend("0.0000005", TOKEN);
|
await confirmSend("0.0000005", TOKEN);
|
||||||
expect(text("confirm-balance")).toBe("0.0000005 TOK");
|
expect(text("confirm-balance")).toBe("0.0000 TOK");
|
||||||
expect(errors()).toBe("");
|
expect(errors()).toBe("");
|
||||||
expect(balanceError()).toBe("");
|
expect(balanceError()).toBe("");
|
||||||
await confirmSend("0.0000006", TOKEN);
|
await confirmSend("0.0000006", TOKEN);
|
||||||
|
|||||||
@@ -1361,6 +1361,31 @@ describe("fetchRecentTransactions merge and dedup", () => {
|
|||||||
expect(txs[0].holders).toBe(3500000);
|
expect(txs[0].holders).toBe(3500000);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// README.md, Amounts: a history row cuts to four decimals, with no floor.
|
||||||
|
test("a token transfer below 0.0001 reads 0.0000", async () => {
|
||||||
|
respondWith(
|
||||||
|
[],
|
||||||
|
[
|
||||||
|
{
|
||||||
|
transaction_hash: "0x" + "4".repeat(64),
|
||||||
|
block_number: 21000040,
|
||||||
|
timestamp: TS,
|
||||||
|
from: { hash: ORDINARY_PEER },
|
||||||
|
to: { hash: VICTIM },
|
||||||
|
total: { value: "40", decimals: "6" },
|
||||||
|
token: {
|
||||||
|
symbol: "USDC",
|
||||||
|
address_hash: USDC_CONTRACT,
|
||||||
|
holders_count: "3500000",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
|
const txs = await fetchRecentTransactions(VICTIM, BLOCKSCOUT, "0x1");
|
||||||
|
expect(txs[0].value).toBe("0.0000");
|
||||||
|
});
|
||||||
|
|
||||||
test("two transfers of the same token in one transaction collapse to one entry", async () => {
|
test("two transfers of the same token in one transaction collapse to one entry", async () => {
|
||||||
const hash = "0x" + "3".repeat(64);
|
const hash = "0x" + "3".repeat(64);
|
||||||
const leg = (value) => ({
|
const leg = (value) => ({
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ afterEach(() => {
|
|||||||
describe("balanceLine", () => {
|
describe("balanceLine", () => {
|
||||||
test("an unknown quantity and a zero one render differently", () => {
|
test("an unknown quantity and a zero one render differently", () => {
|
||||||
const unknown = balanceLine("NOVEL", null, null, NOVEL);
|
const unknown = balanceLine("NOVEL", null, null, NOVEL);
|
||||||
const zero = balanceLine("NOVEL", 0, null, NOVEL);
|
const zero = balanceLine("NOVEL", "0", null, NOVEL);
|
||||||
expect(unknown).not.toBe(zero);
|
expect(unknown).not.toBe(zero);
|
||||||
expect(quantities(unknown)).toEqual(["NOVEL", "quantity unknown"]);
|
expect(quantities(unknown)).toEqual(["NOVEL", "quantity unknown"]);
|
||||||
expect(quantities(zero)).toEqual(["NOVEL", "0.0000"]);
|
expect(quantities(zero)).toEqual(["NOVEL", "0.0000"]);
|
||||||
@@ -105,7 +105,7 @@ describe("balanceLine", () => {
|
|||||||
test("an unknown quantity produces no fiat figure, a zero one does", () => {
|
test("an unknown quantity produces no fiat figure, a zero one does", () => {
|
||||||
prices[NOVEL] = 3;
|
prices[NOVEL] = 3;
|
||||||
const unknown = balanceLine("NOVEL", null, 3, NOVEL);
|
const unknown = balanceLine("NOVEL", null, 3, NOVEL);
|
||||||
const zero = balanceLine("NOVEL", 0, 3, NOVEL);
|
const zero = balanceLine("NOVEL", "0", 3, NOVEL);
|
||||||
// A price times an unknown quantity is not $0.00: that is the same
|
// A price times an unknown quantity is not $0.00: that is the same
|
||||||
// claim of "nothing here" the quantity cell just refused to make.
|
// claim of "nothing here" the quantity cell just refused to make.
|
||||||
expect(unknown).toContain(
|
expect(unknown).toContain(
|
||||||
|
|||||||
Reference in new issue
Block a user