From fd69e1e215dcc22d0ed28f1ff6addcd2fdd6dc77 Mon Sep 17 00:00:00 2001 From: user Date: Sat, 28 Feb 2026 14:33:40 -0800 Subject: [PATCH] feat: show red warning on confirm-tx for addresses with zero transaction history When sending to an address that has never sent or received funds (zero nonce and zero balance), display a prominent red warning on the transaction confirmation screen advising the user to double-check the address. Closes #82 --- src/popup/views/confirmTx.js | 52 +++++++++++++++++++++++++++--------- 1 file changed, 40 insertions(+), 12 deletions(-) diff --git a/src/popup/views/confirmTx.js b/src/popup/views/confirmTx.js index 522e9e5..9c36891 100644 --- a/src/popup/views/confirmTx.js +++ b/src/popup/views/confirmTx.js @@ -86,6 +86,42 @@ function valueWithUsd(text, usdAmount) { return text; } +function renderWarnings(warnings) { + const warningsEl = $("confirm-warnings"); + if (warnings.length > 0) { + warningsEl.innerHTML = warnings + .map( + (w) => + `
WARNING: ${w}
`, + ) + .join(""); + warningsEl.classList.remove("hidden"); + } else { + warningsEl.classList.add("hidden"); + } +} + +async function checkAddressHistory(address, existingWarnings) { + try { + const provider = getProvider(state.rpcUrl); + const [balance, txCount] = await Promise.all([ + provider.getBalance(address), + provider.getTransactionCount(address), + ]); + if (balance === 0n && txCount === 0) { + const warnings = existingWarnings.slice(); + warnings.push( + "This address has ZERO transaction history. " + + "It has never sent or received funds. " + + "Double-check that the address is correct before sending.", + ); + renderWarnings(warnings); + } + } catch (e) { + log.errorf("address history check failed:", e.message); + } +} + function show(txInfo) { pendingTx = txInfo; @@ -176,18 +212,10 @@ function show(txInfo) { warnings.push("You are sending to your own address."); } - const warningsEl = $("confirm-warnings"); - if (warnings.length > 0) { - warningsEl.innerHTML = warnings - .map( - (w) => - `
WARNING: ${w}
`, - ) - .join(""); - warningsEl.classList.remove("hidden"); - } else { - warningsEl.classList.add("hidden"); - } + renderWarnings(warnings); + + // Async check: warn if destination address has zero transaction history + checkAddressHistory(txInfo.to, warnings); // Check for errors const errors = []; -- 2.49.1