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, and 0.00004 USDC read 0.0000. They now show the stored decimal string through truncateAmountNeverZero(), as Send and the approval screens do. History rows take the same floor. truncateAmount() is no longer exported. balanceLine() now takes the stored balance string instead of a parsed number. Model: opus-5-5
79 lines
2.4 KiB
JavaScript
79 lines
2.4 KiB
JavaScript
// The balance lists and Home's ETH line show a balance as Send does (README.md,
|
|
// Amounts): cut to four decimal places, never rounded up, and a nonzero amount
|
|
// never shown as zero
|
|
// (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("shows 0.00004 as 0.00004, not 0.0000", () => {
|
|
expect(quantity(balanceLine("USDC", "0.00004", null, USDC))).toBe(
|
|
"0.00004",
|
|
);
|
|
});
|
|
});
|
|
|
|
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.00004", async () => {
|
|
const page = await bootHolding("0.99996", "0.00004");
|
|
|
|
expect(quantity(homeRow(page, USDC.toLowerCase()))).toBe("0.00004");
|
|
});
|
|
});
|