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. Send's current balance and ConfirmTx's balance line kept the nonzero floor, so 0.00004 USDC read 0.0000 in the lists and 0.00004 on Send. All four 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 amounts, fees and allowances a screen asks the user to approve keep the floor of truncateAmountNeverZero(). Model: opus-5-5
92 lines
2.9 KiB
JavaScript
92 lines
2.9 KiB
JavaScript
// 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");
|
|
});
|
|
});
|