1 Commits
Author SHA1 Message Date
sneak 172f2c8a87 fix: each PERMIT2_TRANSFER_FROM shows the amount it moves and where to (closes #611)
check / check (push) Canceled after 0s
e2e / e2e-chrome (push) Canceled after 0s
e2e / e2e-firefox (push) Canceled after 0s
The swap decoder now gives three lines for every PERMIT2_TRANSFER_FROM
it reads but a move into the router, after the swap's Amount line: the
amount moved from the sender, the token with its address, and where it
goes (the V2 pair the next swap spends, the sender, or the address
itself on a line of its own). A move into the router keeps its Paid to
and Token moved into the router lines, which already give its amount.
Before, a move to another address or to the next V2 pair showed no
amount at all. Who counts as paid, and so Min. received against Min.
paid out, is unchanged. tokenMovedLine() moves to module level and
takes its label as an argument.

Model: opus-5-5
2026-10-19 21:25:52 +00:00
11 changed files with 66 additions and 220 deletions
+9 -13
View File
@@ -1891,17 +1891,14 @@ view would leave a wallet one click from deletion.
no recipient." instead no recipient." instead
- Transaction hash: full hash (tap to copy) + etherscan link - Transaction hash: full hash (tap to copy) + etherscan link
- Count-up timer: "Waiting for confirmation... Ns" - Count-up timer: "Waiting for confirmation... Ns"
- **Behavior**: Polls `getTransactionReceipt` every 10 seconds. The screen - **Behavior**: Polls `getTransactionReceipt` every 10 seconds. The wait is
describes the transaction on the network it was sent on, whichever network is persisted: closing and reopening the popup resumes the poll, with the elapsed
active: the receipt is asked of that network's RPC endpoint, the one Settings counter and the timeout deadline still measured from the original broadcast. A
has for it, and the To and hash links open that network's explorer. The wait lookup that fails is retried on the next tick rather than counted as a missing
is persisted: closing and reopening the popup resumes the poll, with the receipt, because a failed lookup says nothing about the transaction; but six
elapsed counter and the timeout deadline still measured from the original failures in a row (60 seconds at the poll cadence) end the wait, so an RPC
broadcast. A lookup that fails is retried on the next tick rather than counted that never answers cannot leave it running indefinitely. Any lookup that
as a missing receipt, because a failed lookup says nothing about the answers resets that count.
transaction; but six failures in a row (60 seconds at the poll cadence) end
the wait, so an RPC that never answers cannot leave it running indefinitely.
Any lookup that answers resets that count.
- **Transitions**: - **Transitions**:
- Receipt found → **SuccessTx** - Receipt found → **SuccessTx**
- A lookup that answers "no receipt" 60 seconds or more after broadcast → - A lookup that answers "no receipt" 60 seconds or more after broadcast →
@@ -1966,8 +1963,7 @@ view would leave a wallet one click from deletion.
#### TransactionDetail (`transaction`) #### TransactionDetail (`transaction`)
- **When**: User tapped a transaction row on Home, AddressDetail, or - **When**: User tapped a transaction row on Home, AddressDetail, or
AddressToken. Its etherscan links open the explorer of the network the AddressToken.
transaction was sent on, whichever network is active.
- **Elements** (grouped into logical blocks using light well containers; field - **Elements** (grouped into logical blocks using light well containers; field
labels are self-explanatory so groups have no headings): labels are self-explanatory so groups have no headings):
- "Transaction" heading, "Back" button - "Transaction" heading, "Back" button
+1 -4
View File
@@ -145,15 +145,12 @@ function isRenderablePendingTx(value) {
// The stored transaction transactionDetail.render() shows. contractAddress is // The stored transaction transactionDetail.render() shows. contractAddress is
// optional on an ETH transfer, and reaches addressDotHtml() when it is there. // optional on an ETH transfer, and reaches addressDotHtml() when it is there.
// `chainId` picks the network whose explorer the links open, so when it is
// there it has to name one.
function isRenderableTx(value) { function isRenderableTx(value) {
return ( return (
isRecord(value) && isRecord(value) &&
isAddressText(value.from) && isAddressText(value.from) &&
isAddressText(value.to) && isAddressText(value.to) &&
(!value.contractAddress || isAddressText(value.contractAddress)) && (!value.contractAddress || isAddressText(value.contractAddress))
(!value.chainId || SUPPORTED_CHAIN_IDS.has(value.chainId))
); );
} }
+18 -2
View File
@@ -23,10 +23,12 @@ const {
goBack, goBack,
onViewLeave, onViewLeave,
formatFee, formatFee,
reviewedNetworkProvider,
} = require("./helpers"); } = require("./helpers");
const { state, currentNetwork } = require("../../shared/state"); const { state, currentNetwork } = require("../../shared/state");
const { nativeCurrencyByChainId } = require("../../shared/networks"); const {
networkByChainId,
nativeCurrencyByChainId,
} = require("../../shared/networks");
const { getSignerForAddress } = require("../../shared/wallet"); const { getSignerForAddress } = require("../../shared/wallet");
const { walletDefect } = require("../../shared/walletDefects"); const { walletDefect } = require("../../shared/walletDefects");
const { decryptWithPassword } = require("../../shared/vault"); const { decryptWithPassword } = require("../../shared/vault");
@@ -456,6 +458,20 @@ function setVisible(id, visible) {
$(id).style.visibility = visible ? "visible" : "hidden"; $(id).style.visibility = visible ? "visible" : "hidden";
} }
// The node of the network this transaction was reviewed for, which need not be
// the active one: the popup can reopen onto this screen after Settings switched
// the network. Its RPC URL is the one Settings has for that network: the
// active network's is state.rpcUrl, any other's the one remembered for it (see
// applyChainSwitchFields()).
function reviewedNetworkProvider(txInfo) {
const net = networkByChainId(txInfo.chainId);
if (net.id === state.networkId) {
return getProvider(state.rpcUrl, net.id);
}
const remembered = state.networkEndpoints[net.id] || {};
return getProvider(remembered.rpcUrl || net.defaultRpcUrl, net.id);
}
async function estimateGas(txInfo) { async function estimateGas(txInfo) {
try { try {
const provider = reviewedNetworkProvider(txInfo); const provider = reviewedNetworkProvider(txInfo);
-16
View File
@@ -19,7 +19,6 @@ const {
isBelowOneMillionth, isBelowOneMillionth,
} = require("../../shared/amountDisplay"); } = require("../../shared/amountDisplay");
const { resolveTokenSymbol } = require("../../shared/approvalAmount"); const { resolveTokenSymbol } = require("../../shared/approvalAmount");
const { getProvider } = require("../../shared/balances");
const { DEBUG } = require("../../shared/constants"); const { DEBUG } = require("../../shared/constants");
const { escapeHtml } = require("../../shared/html"); const { escapeHtml } = require("../../shared/html");
const { isDebug } = require("../../shared/log"); const { isDebug } = require("../../shared/log");
@@ -608,20 +607,6 @@ const EXT_ICON =
`<path d="M7 1.5h3.5V5M7 5.5L10.5 1.5"/>` + `<path d="M7 1.5h3.5V5M7 5.5L10.5 1.5"/>` +
`</svg></span>`; `</svg></span>`;
// The node of the network a transaction was reviewed for, the one its chain id
// names, which need not be the active one: the popup can reopen onto ConfirmTx
// or WaitTx after Settings switched the network. Its RPC URL is the one
// Settings has for that network: the active network's is state.rpcUrl, any
// other's the one remembered for it (see applyChainSwitchFields()).
function reviewedNetworkProvider(txInfo) {
const net = networkByChainId(txInfo.chainId);
if (net.id === state.networkId) {
return getProvider(state.rpcUrl, net.id);
}
const remembered = state.networkEndpoints[net.id] || {};
return getProvider(remembered.rpcUrl || net.defaultRpcUrl, net.id);
}
// Block-explorer URLs. The origin is a per-network constant from // Block-explorer URLs. The origin is a per-network constant from
// src/shared/networks.js, the explorer of the network with `chainId`, or of // src/shared/networks.js, the explorer of the network with `chainId`, or of
// the active network when no chain id is given; only the path segment is // the active network when no chain id is given; only the path segment is
@@ -777,7 +762,6 @@ module.exports = {
attachCopyHandlers, attachCopyHandlers,
etherscanLinkHtml, etherscanLinkHtml,
explorerUrl, explorerUrl,
reviewedNetworkProvider,
EXT_ICON, EXT_ICON,
truncateMiddle, truncateMiddle,
isoDate, isoDate,
+14 -24
View File
@@ -48,16 +48,16 @@ function getTransactionType(tx) {
return "Native " + nativeCurrencyByChainId(tx.chainId) + " Transfer"; return "Native " + nativeCurrencyByChainId(tx.chainId) + " Transfer";
} }
function txAddressHtml(address, ensName, title, chainId) { function txAddressHtml(address, ensName, title) {
const blockie = blockieHtml(address); const blockie = blockieHtml(address);
return ( return (
`<div class="mb-1">${blockie}</div>` + `<div class="mb-1">${blockie}</div>` +
renderAddressHtml(address, { title, ensName, chainId }) renderAddressHtml(address, { title, ensName })
); );
} }
function txHashHtml(hash, chainId) { function txHashHtml(hash) {
const link = explorerUrl("tx", hash, chainId); const link = explorerUrl("tx", hash);
const extLink = etherscanLinkHtml(link); const extLink = etherscanLinkHtml(link);
return copyableHtml(hash, "break-all") + extLink; return copyableHtml(hash, "break-all") + extLink;
} }
@@ -83,10 +83,10 @@ function show(tx) {
method: tx.method || null, method: tx.method || null,
contractAddress: tx.contractAddress || null, contractAddress: tx.contractAddress || null,
// The network the history entry was read from. The type line and // The network the history entry was read from. The type line and
// the fee are in its native currency, not the active network's, // the fee are in its native currency, not the active network's:
// and the links open its explorer: the active network can change, // the active network can change, in Settings or when the user
// in Settings or when the user approves a site's request, before // approves a site's request, before a later popup shows this
// a later popup shows this screen again. // screen again.
chainId: tx.chainId, chainId: tx.chainId,
}, },
}; };
@@ -96,24 +96,18 @@ function show(tx) {
function render() { function render() {
const tx = state.viewData.tx; const tx = state.viewData.tx;
if (!tx) return; if (!tx) return;
$("tx-detail-hash").innerHTML = txHashHtml(tx.hash, tx.chainId); $("tx-detail-hash").innerHTML = txHashHtml(tx.hash);
const fromTitle = addressTitle(tx.from, state.wallets); const fromTitle = addressTitle(tx.from, state.wallets);
$("tx-detail-from").innerHTML = txAddressHtml( $("tx-detail-from").innerHTML = txAddressHtml(
tx.from, tx.from,
tx.fromEns, tx.fromEns,
fromTitle, fromTitle,
tx.chainId,
); );
// A contract creation has no recipient: transactions.js gives it `to: ""`. // A contract creation has no recipient: transactions.js gives it `to: ""`.
if (tx.to) { if (tx.to) {
const toTitle = addressTitle(tx.to, state.wallets); const toTitle = addressTitle(tx.to, state.wallets);
$("tx-detail-to").innerHTML = txAddressHtml( $("tx-detail-to").innerHTML = txAddressHtml(tx.to, tx.toEns, toTitle);
tx.to,
tx.toEns,
toTitle,
tx.chainId,
);
} else { } else {
$("tx-detail-to").innerHTML = escapeHtml(CONTRACT_CREATION_TEXT); $("tx-detail-to").innerHTML = escapeHtml(CONTRACT_CREATION_TEXT);
} }
@@ -152,7 +146,7 @@ function render() {
if (tokenContractSection && tokenContractEl) { if (tokenContractSection && tokenContractEl) {
if (tx.contractAddress) { if (tx.contractAddress) {
const dot = addressDotHtml(tx.contractAddress); const dot = addressDotHtml(tx.contractAddress);
const link = explorerUrl("token", tx.contractAddress, tx.chainId); const link = explorerUrl("token", tx.contractAddress);
// Hand-rolled rather than renderAddressHtml() because the // Hand-rolled rather than renderAddressHtml() because the
// link goes to the explorer's /token/ page, not /address/. // link goes to the explorer's /token/ page, not /address/.
// Same two-row shape though: dot and link on the strip, the // Same two-row shape though: dot and link on the strip, the
@@ -210,11 +204,7 @@ function showDetailField(sectionId, contentId, value) {
function populateOnChainDetails(txData, chainId) { function populateOnChainDetails(txData, chainId) {
// Block number // Block number
if (txData.block_number != null) { if (txData.block_number != null) {
const blockLink = explorerUrl( const blockLink = explorerUrl("block", String(txData.block_number));
"block",
String(txData.block_number),
chainId,
);
const blockSection = $("tx-detail-block-section"); const blockSection = $("tx-detail-block-section");
const blockEl = $("tx-detail-block"); const blockEl = $("tx-detail-block");
if (blockSection && blockEl) { if (blockSection && blockEl) {
@@ -350,9 +340,9 @@ async function loadFullTxDetails(txHash, chainId) {
if (tokenSymbol) { if (tokenSymbol) {
detailsHtml += `<div class="font-bold">${escapeHtml(displaySymbol(tokenSymbol))}</div>`; detailsHtml += `<div class="font-bold">${escapeHtml(displaySymbol(tokenSymbol))}</div>`;
} }
detailsHtml += renderAddressHtml(d.address, { chainId }); detailsHtml += renderAddressHtml(d.address);
} else if (d.address) { } else if (d.address) {
detailsHtml += renderAddressHtml(d.address, { chainId }); detailsHtml += renderAddressHtml(d.address);
} else { } else {
detailsHtml += `<div class="font-bold">${escapeHtml(d.value)}</div>`; detailsHtml += `<div class="font-bold">${escapeHtml(d.value)}</div>`;
} }
+17 -25
View File
@@ -14,13 +14,10 @@ const {
displaySymbol, displaySymbol,
clearViewStack, clearViewStack,
tokenLabel, tokenLabel,
reviewedNetworkProvider,
} = require("./helpers"); } = require("./helpers");
const { state } = require("../../shared/state"); const { state } = require("../../shared/state");
const { const { nativeCurrencyByChainId } = require("../../shared/networks");
SUPPORTED_CHAIN_IDS, const { getProvider } = require("../../shared/balances");
nativeCurrencyByChainId,
} = require("../../shared/networks");
const { log } = require("../../shared/log"); const { log } = require("../../shared/log");
// Receipt poll cadence and the deadline after which the wait is reported as // Receipt poll cadence and the deadline after which the wait is reported as
@@ -64,16 +61,15 @@ function endWait() {
} }
// A contract creation reaches these screens with `to` as "" (approval.js // A contract creation reaches these screens with `to` as "" (approval.js
// writes `to: toAddr || ""`). The link opens the explorer of the network with // writes `to: toAddr || ""`).
// `chainId`, or of the active network when none is given. function toAddressHtml(address) {
function toAddressHtml(address, chainId) {
if (!address) return escapeHtml(CONTRACT_CREATION_TEXT); if (!address) return escapeHtml(CONTRACT_CREATION_TEXT);
const title = addressTitle(address, state.wallets); const title = addressTitle(address, state.wallets);
return renderAddressHtml(address, { title, chainId }); return renderAddressHtml(address, { title });
} }
function txHashHtml(hash, chainId) { function txHashHtml(hash) {
const link = explorerUrl("tx", hash, chainId); const link = explorerUrl("tx", hash);
return copyableHtml(hash, "break-all") + etherscanLinkHtml(link); return copyableHtml(hash, "break-all") + etherscanLinkHtml(link);
} }
@@ -95,11 +91,9 @@ function startWait(txInfo, txHash, broadcastTime, pollNow) {
// native currency of txInfo.chainId, the network the transaction was sent // native currency of txInfo.chainId, the network the transaction was sent
// on, not the active network's: the active network can change, in // on, not the active network's: the active network can change, in
// Settings or when the user approves a site's request, while this screen // Settings or when the user approves a site's request, while this screen
// is open or before a later popup resumes it. This screen's links open // is open or before a later popup resumes it. A null token is a swap whose
// that network's explorer, and its receipt is asked of that network's // amount was not decoded (see showTxApproval() in approval.js): the amount
// node, for the same reason. A null token is a swap whose amount was not // says so, and no symbol follows it.
// decoded (see showTxApproval() in approval.js): the amount says so, and
// no symbol follows it.
let symbol = ""; let symbol = "";
if (txInfo.token === "ETH") { if (txInfo.token === "ETH") {
symbol = nativeCurrencyByChainId(txInfo.chainId); symbol = nativeCurrencyByChainId(txInfo.chainId);
@@ -108,8 +102,8 @@ function startWait(txInfo, txHash, broadcastTime, pollNow) {
} }
$("wait-tx-summary").textContent = $("wait-tx-summary").textContent =
txInfo.amount + (symbol ? " " + symbol : ""); txInfo.amount + (symbol ? " " + symbol : "");
$("wait-tx-to").innerHTML = toAddressHtml(txInfo.to, txInfo.chainId); $("wait-tx-to").innerHTML = toAddressHtml(txInfo.to);
$("wait-tx-hash").innerHTML = txHashHtml(txHash, txInfo.chainId); $("wait-tx-hash").innerHTML = txHashHtml(txHash);
attachCopyHandlers("view-wait-tx"); attachCopyHandlers("view-wait-tx");
// Persisted so closing and reopening the popup resumes this wait // Persisted so closing and reopening the popup resumes this wait
@@ -134,7 +128,7 @@ function startWait(txInfo, txHash, broadcastTime, pollNow) {
renderElapsed(); renderElapsed();
}, 1000); }, 1000);
const provider = reviewedNetworkProvider(txInfo); const provider = getProvider(state.rpcUrl, state.networkId);
let consecutiveFailures = 0; let consecutiveFailures = 0;
async function poll() { async function poll() {
@@ -213,11 +207,10 @@ function showWait(txInfo, txHash) {
// an object merely missing one of them throws a TypeError out of // an object merely missing one of them throws a TypeError out of
// restoreView() — which init() does not guard, skipping the rest of popup // restoreView() — which init() does not guard, skipping the rest of popup
// init and leaving wait-tx on screen with no back control. A non-numeric // init and leaving wait-tx on screen with no back control. A non-numeric
// broadcastTime leaves an unexitable wait counting "NaNs". txInfo.chainId picks // broadcastTime leaves an unexitable wait counting "NaNs". txInfo.token,
// the node the receipt is asked of and the explorer the links open, so it has // txInfo.tokenSymbol and txInfo.chainId are deliberately unchecked: they are
// to name a network. txInfo.token and txInfo.tokenSymbol are deliberately // compared and coalesced rather than dereferenced, and tokenSymbol is null for
// unchecked: they are compared and coalesced rather than dereferenced, and // ETH.
// tokenSymbol is null for ETH.
function restoreWait() { function restoreWait() {
const d = state.viewData; const d = state.viewData;
if (!d || !d.pendingWait) return false; if (!d || !d.pendingWait) return false;
@@ -233,7 +226,6 @@ function restoreWait() {
// path itself created. // path itself created.
if (typeof info.to !== "string") return false; if (typeof info.to !== "string") return false;
if (typeof info.amount !== "string") return false; if (typeof info.amount !== "string") return false;
if (!SUPPORTED_CHAIN_IDS.has(info.chainId)) return false;
if (typeof w.broadcastTime !== "number" || !isFinite(w.broadcastTime)) { if (typeof w.broadcastTime !== "number" || !isFinite(w.broadcastTime)) {
return false; return false;
} }
-1
View File
@@ -192,7 +192,6 @@ describe("the wait, success and error screens", () => {
amount: "0.0000", amount: "0.0000",
token: "ETH", token: "ETH",
tokenSymbol: null, tokenSymbol: null,
chainId: "0x1",
}; };
const transfer = { ...creation, to: RECIPIENT }; const transfer = { ...creation, to: RECIPIENT };
+1 -14
View File
@@ -459,19 +459,6 @@ const CONTRACT = [
views: ["transaction"], views: ["transaction"],
restored: false, restored: false,
}, },
// A chain id naming no network has no explorer to link to.
{
value: {
tx: {
hash: "0x1",
from: ADDRESS,
to: ADDRESS,
chainId: "0x5",
},
},
views: ["transaction"],
restored: false,
},
// confirm-tx passes on `data.pendingTx`. // confirm-tx passes on `data.pendingTx`.
{ {
value: { pendingTx: { amount: "1" } }, value: { pendingTx: { amount: "1" } },
@@ -834,7 +821,7 @@ const WELL_FORMED_DATA = {
}, },
pendingWait: { pendingWait: {
hash: "0x1", hash: "0x1",
txInfo: { to: ADDRESS, amount: "1", chainId: "0x1" }, txInfo: { to: ADDRESS, amount: "1" },
broadcastTime: BROADCAST_TIME, broadcastTime: BROADCAST_TIME,
}, },
}; };
+1 -6
View File
@@ -225,12 +225,7 @@ describe("a popup already open when the stored profile becomes unreadable", () =
viewData: { viewData: {
pendingWait: { pendingWait: {
hash: "0x1", hash: "0x1",
txInfo: { txInfo: { to: ADDRESS, amount: "1", token: "ETH" },
to: ADDRESS,
amount: "1",
token: "ETH",
chainId: "0x1",
},
broadcastTime: Date.now(), broadcastTime: Date.now(),
}, },
}, },
+2 -45
View File
@@ -8,10 +8,6 @@
// tracks. It decodes against the address the explorer reports the transaction // tracks. It decodes against the address the explorer reports the transaction
// was sent to. // was sent to.
// //
// Its links open the explorer of the network the transaction was sent on,
// whichever network is active
// (https://git.eeqj.de/sneak/AutistMask/issues/584).
//
// The row is the one the real history parser makes from the explorer's answer, // The row is the one the real history parser makes from the explorer's answer,
// opened through transactionDetail.show(), which is what a click on the row // opened through transactionDetail.show(), which is what a click on the row
// calls. Driven against a minimal DOM stub in the shape // calls. Driven against a minimal DOM stub in the shape
@@ -39,7 +35,6 @@ globalThis.chrome = {
}; };
const { state } = require("../src/shared/state"); const { state } = require("../src/shared/state");
const { NETWORKS } = require("../src/shared/networks");
const { fetchRecentTransactions } = require("../src/shared/transactions"); const { fetchRecentTransactions } = require("../src/shared/transactions");
const transactionDetail = require("../src/popup/views/transactionDetail"); const transactionDetail = require("../src/popup/views/transactionDetail");
@@ -82,11 +77,7 @@ function mockExplorerAnswer(url) {
}; };
} }
if (url === EXPLORER + "/transactions/" + TX_HASH) { if (url === EXPLORER + "/transactions/" + TX_HASH) {
return { return { to: { hash: TOKEN }, raw_input: TRANSFER_DATA };
to: { hash: TOKEN },
raw_input: TRANSFER_DATA,
block_number: 100,
};
} }
return { items: [] }; return { items: [] };
} }
@@ -163,11 +154,7 @@ beforeEach(() => {
}); });
test("a token transfer's decoded details name the token contract and the amount at its scale", async () => { test("a token transfer's decoded details name the token contract and the amount at its scale", async () => {
const [row] = await fetchRecentTransactions( const [row] = await fetchRecentTransactions(HOLDER, EXPLORER, 1);
HOLDER,
EXPLORER,
NETWORKS.mainnet.chainId,
);
expect(row.to).toBe(RECIPIENT); expect(row.to).toBe(RECIPIENT);
expect(row.contractAddress).toBe(TOKEN.toLowerCase()); expect(row.contractAddress).toBe(TOKEN.toLowerCase());
@@ -187,33 +174,3 @@ test("a token transfer's decoded details name the token contract and the amount
'<div class="font-bold">1234.5000 TDOL</div>', '<div class="font-bold">1234.5000 TDOL</div>',
); );
}); });
// Mainnet is active and the row was read from Sepolia's explorer. The stub
// explorer answers whichever network asks, so every link on the screen is
// drawn.
test("with mainnet active, a Sepolia transaction's links open the Sepolia explorer", async () => {
state.networkId = "mainnet";
const [row] = await fetchRecentTransactions(
HOLDER,
EXPLORER,
NETWORKS.sepolia.chainId,
);
transactionDetail.show(row);
for (let i = 0; i < 10; i++) await new Promise((r) => setTimeout(r, 0));
const sepolia = "https://sepolia.etherscan.io";
const links = (id) =>
[...node(id).innerHTML.matchAll(/href="([^"]*)"/g)].map((m) => m[1]);
expect(links("tx-detail-hash")).toEqual([`${sepolia}/tx/${TX_HASH}`]);
expect(links("tx-detail-from")).toEqual([`${sepolia}/address/${HOLDER}`]);
expect(links("tx-detail-to")).toEqual([`${sepolia}/address/${RECIPIENT}`]);
expect(links("tx-detail-token-contract")).toEqual([
`${sepolia}/token/${TOKEN.toLowerCase()}`,
]);
expect(links("tx-detail-block")).toEqual([`${sepolia}/block/100`]);
expect(links("tx-detail-calldata-details")).toEqual([
`${sepolia}/address/${TOKEN}`,
`${sepolia}/address/${RECIPIENT}`,
]);
});
+3 -70
View File
@@ -29,13 +29,8 @@ jest.mock("../src/shared/log", () => ({
})); }));
const mockReceiptLookup = jest.fn(); const mockReceiptLookup = jest.fn();
// The RPC URL and network of every node a wait was given.
const mockNodes = [];
jest.mock("../src/shared/balances", () => ({ jest.mock("../src/shared/balances", () => ({
getProvider: (rpcUrl, networkId) => { getProvider: () => ({ getTransactionReceipt: mockReceiptLookup }),
mockNodes.push({ rpcUrl, networkId });
return { getTransactionReceipt: mockReceiptLookup };
},
refreshBalances: jest.fn(), refreshBalances: jest.fn(),
})); }));
@@ -112,7 +107,6 @@ global.chrome = { storage };
const txStatus = require("../src/popup/views/txStatus"); const txStatus = require("../src/popup/views/txStatus");
const { state } = require("../src/shared/state"); const { state } = require("../src/shared/state");
const { NETWORKS } = require("../src/shared/networks");
const { RESTORABLE_VIEWS } = require("../src/shared/restorableViews"); const { RESTORABLE_VIEWS } = require("../src/shared/restorableViews");
const { log } = require("../src/shared/log"); const { log } = require("../src/shared/log");
@@ -124,7 +118,6 @@ const TX_INFO = {
amount: "0.0050", amount: "0.0050",
token: "ETH", token: "ETH",
tokenSymbol: null, tokenSymbol: null,
chainId: NETWORKS.mainnet.chainId,
}; };
// True when a view element is not hidden. // True when a view element is not hidden.
@@ -144,11 +137,7 @@ beforeEach(() => {
jest.setSystemTime(new Date("2026-08-11T12:00:00Z")); jest.setSystemTime(new Date("2026-08-11T12:00:00Z"));
elements.clear(); elements.clear();
mockReceiptLookup.mockReset(); mockReceiptLookup.mockReset();
mockNodes.length = 0;
log.errorf.mockClear(); log.errorf.mockClear();
state.networkId = "mainnet";
state.rpcUrl = NETWORKS.mainnet.defaultRpcUrl;
state.networkEndpoints = {};
state.wallets = []; state.wallets = [];
state.viewData = {}; state.viewData = {};
state.viewStack = []; state.viewStack = [];
@@ -360,14 +349,14 @@ describe("WaitTx persistence across popup close", () => {
// out of restoreView(). // out of restoreView().
{ {
hash: TX_HASH, hash: TX_HASH,
txInfo: { ...TX_INFO, to: 42 }, txInfo: { to: 42, amount: "0.0050" },
broadcastTime: Date.now(), broadcastTime: Date.now(),
}, },
// Otherwise complete but an array: only Array.isArray() rejects // Otherwise complete but an array: only Array.isArray() rejects
// it, since typeof [] is "object" and the fields are present. // it, since typeof [] is "object" and the fields are present.
{ {
hash: TX_HASH, hash: TX_HASH,
txInfo: Object.assign([], TX_INFO), txInfo: Object.assign([], { to: RECIPIENT, amount: "0.0050" }),
broadcastTime: Date.now(), broadcastTime: Date.now(),
}, },
{ {
@@ -375,18 +364,6 @@ describe("WaitTx persistence across popup close", () => {
txInfo: { to: RECIPIENT }, txInfo: { to: RECIPIENT },
broadcastTime: Date.now(), broadcastTime: Date.now(),
}, },
// Otherwise complete but for a chain id naming no network: there
// is no node to ask for the receipt, and no explorer to link to.
{
hash: TX_HASH,
txInfo: { ...TX_INFO, chainId: undefined },
broadcastTime: Date.now(),
},
{
hash: TX_HASH,
txInfo: { ...TX_INFO, chainId: "0x5" },
broadcastTime: Date.now(),
},
]) { ]) {
state.viewData = { pendingWait: bad }; state.viewData = { pendingWait: bad };
expect(txStatus.restoreWait()).toBe(false); expect(txStatus.restoreWait()).toBe(false);
@@ -522,50 +499,6 @@ describe("WaitTx when the popup closes", () => {
}); });
}); });
// The popup can reopen onto WaitTx after Settings switched the network. The
// wait asked the active network's node for the receipt, never found it, and
// reported a timeout, and its links went to the active network's explorer
// (https://git.eeqj.de/sneak/AutistMask/issues/584).
describe("WaitTx for a Sepolia transaction with mainnet active", () => {
const SEPOLIA_NODE = "https://sepolia.node.example.invalid";
const sepoliaTx = { ...TX_INFO, chainId: NETWORKS.sepolia.chainId };
beforeEach(() => {
state.rpcUrl = "https://mainnet.node.example.invalid";
state.networkEndpoints = { sepolia: { rpcUrl: SEPOLIA_NODE } };
});
test("the receipt is asked of the Sepolia node Settings has", async () => {
mockReceiptLookup.mockResolvedValue({ blockNumber: 21000000 });
state.viewData = {
pendingWait: {
txInfo: sepoliaTx,
hash: TX_HASH,
broadcastTime: Date.now(),
},
};
expect(txStatus.restoreWait()).toBe(true);
await jest.advanceTimersByTimeAsync(0);
expect(mockNodes).toEqual([
{ rpcUrl: SEPOLIA_NODE, networkId: "sepolia" },
]);
expect(state.currentView).toBe("success-tx");
});
test("the recipient and hash link to the Sepolia explorer", () => {
mockReceiptLookup.mockResolvedValue(null);
txStatus.showWait(sepoliaTx, TX_HASH);
expect(getElement("wait-tx-to").innerHTML).toContain(
`href="https://sepolia.etherscan.io/address/${RECIPIENT}"`,
);
expect(getElement("wait-tx-hash").innerHTML).toContain(
`href="https://sepolia.etherscan.io/tx/${TX_HASH}"`,
);
});
});
describe("wait-tx is a view the popup may reopen onto", () => { describe("wait-tx is a view the popup may reopen onto", () => {
// The resume feature is wired through RESTORABLE_VIEWS: restoreView() // The resume feature is wired through RESTORABLE_VIEWS: restoreView()
// refuses any view not in the set, so dropping "wait-tx" from it kills // refuses any view not in the set, so dropping "wait-tx" from it kills