fix: WaitTx and TransactionDetail use the network the transaction was sent on (closes #584)
WaitTx asked the active network's node for the receipt, so after a network switch a transaction sent on the other network was never found and was reported as timed out. It now asks the node of the network its chain id names, through reviewedNetworkProvider(), moved from ConfirmTx into the shared view helpers so both screens use one function. WaitTx and TransactionDetail build their explorer links for that network too. A stored wait or transaction whose chain id names no network is refused on restore, as a stored ConfirmTx transaction already is. Model: opus-5-5
This commit was merged in pull request #621.
This commit is contained in:
+25
-17
@@ -14,10 +14,13 @@ const {
|
||||
displaySymbol,
|
||||
clearViewStack,
|
||||
tokenLabel,
|
||||
reviewedNetworkProvider,
|
||||
} = require("./helpers");
|
||||
const { state } = require("../../shared/state");
|
||||
const { nativeCurrencyByChainId } = require("../../shared/networks");
|
||||
const { getProvider } = require("../../shared/balances");
|
||||
const {
|
||||
SUPPORTED_CHAIN_IDS,
|
||||
nativeCurrencyByChainId,
|
||||
} = require("../../shared/networks");
|
||||
const { log } = require("../../shared/log");
|
||||
|
||||
// Receipt poll cadence and the deadline after which the wait is reported as
|
||||
@@ -61,15 +64,16 @@ function endWait() {
|
||||
}
|
||||
|
||||
// A contract creation reaches these screens with `to` as "" (approval.js
|
||||
// writes `to: toAddr || ""`).
|
||||
function toAddressHtml(address) {
|
||||
// writes `to: toAddr || ""`). The link opens the explorer of the network with
|
||||
// `chainId`, or of the active network when none is given.
|
||||
function toAddressHtml(address, chainId) {
|
||||
if (!address) return escapeHtml(CONTRACT_CREATION_TEXT);
|
||||
const title = addressTitle(address, state.wallets);
|
||||
return renderAddressHtml(address, { title });
|
||||
return renderAddressHtml(address, { title, chainId });
|
||||
}
|
||||
|
||||
function txHashHtml(hash) {
|
||||
const link = explorerUrl("tx", hash);
|
||||
function txHashHtml(hash, chainId) {
|
||||
const link = explorerUrl("tx", hash, chainId);
|
||||
return copyableHtml(hash, "break-all") + etherscanLinkHtml(link);
|
||||
}
|
||||
|
||||
@@ -91,9 +95,11 @@ function startWait(txInfo, txHash, broadcastTime, pollNow) {
|
||||
// native currency of txInfo.chainId, the network the transaction was sent
|
||||
// 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
|
||||
// is open or before a later popup resumes it. A null token is a swap whose
|
||||
// amount was not decoded (see showTxApproval() in approval.js): the amount
|
||||
// says so, and no symbol follows it.
|
||||
// is open or before a later popup resumes it. This screen's links open
|
||||
// that network's explorer, and its receipt is asked of that network's
|
||||
// node, for the same reason. A null token is a swap whose amount was not
|
||||
// decoded (see showTxApproval() in approval.js): the amount says so, and
|
||||
// no symbol follows it.
|
||||
let symbol = "";
|
||||
if (txInfo.token === "ETH") {
|
||||
symbol = nativeCurrencyByChainId(txInfo.chainId);
|
||||
@@ -102,8 +108,8 @@ function startWait(txInfo, txHash, broadcastTime, pollNow) {
|
||||
}
|
||||
$("wait-tx-summary").textContent =
|
||||
txInfo.amount + (symbol ? " " + symbol : "");
|
||||
$("wait-tx-to").innerHTML = toAddressHtml(txInfo.to);
|
||||
$("wait-tx-hash").innerHTML = txHashHtml(txHash);
|
||||
$("wait-tx-to").innerHTML = toAddressHtml(txInfo.to, txInfo.chainId);
|
||||
$("wait-tx-hash").innerHTML = txHashHtml(txHash, txInfo.chainId);
|
||||
attachCopyHandlers("view-wait-tx");
|
||||
|
||||
// Persisted so closing and reopening the popup resumes this wait
|
||||
@@ -128,7 +134,7 @@ function startWait(txInfo, txHash, broadcastTime, pollNow) {
|
||||
renderElapsed();
|
||||
}, 1000);
|
||||
|
||||
const provider = getProvider(state.rpcUrl, state.networkId);
|
||||
const provider = reviewedNetworkProvider(txInfo);
|
||||
let consecutiveFailures = 0;
|
||||
|
||||
async function poll() {
|
||||
@@ -207,10 +213,11 @@ function showWait(txInfo, txHash) {
|
||||
// an object merely missing one of them throws a TypeError out of
|
||||
// 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
|
||||
// broadcastTime leaves an unexitable wait counting "NaNs". txInfo.token,
|
||||
// txInfo.tokenSymbol and txInfo.chainId are deliberately unchecked: they are
|
||||
// compared and coalesced rather than dereferenced, and tokenSymbol is null for
|
||||
// ETH.
|
||||
// broadcastTime leaves an unexitable wait counting "NaNs". txInfo.chainId picks
|
||||
// the node the receipt is asked of and the explorer the links open, so it has
|
||||
// to name a network. txInfo.token and txInfo.tokenSymbol are deliberately
|
||||
// unchecked: they are compared and coalesced rather than dereferenced, and
|
||||
// tokenSymbol is null for ETH.
|
||||
function restoreWait() {
|
||||
const d = state.viewData;
|
||||
if (!d || !d.pendingWait) return false;
|
||||
@@ -226,6 +233,7 @@ function restoreWait() {
|
||||
// path itself created.
|
||||
if (typeof info.to !== "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)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user