diff --git a/src/popup/views/confirmTx.js b/src/popup/views/confirmTx.js index 522e9e5..466a573 100644 --- a/src/popup/views/confirmTx.js +++ b/src/popup/views/confirmTx.js @@ -25,6 +25,7 @@ const { decryptWithPassword } = require("../../shared/vault"); const { formatUsd, getPrice } = require("../../shared/prices"); const { getProvider } = require("../../shared/balances"); const { isScamAddress } = require("../../shared/scamlist"); +const { DEFAULT_BLOCKSCOUT_URL } = require("../../shared/constants"); const { ERC20_ABI } = require("../../shared/constants"); const { log } = require("../../shared/log"); const makeBlockie = require("ethereum-blockies-base64"); @@ -181,7 +182,7 @@ function show(txInfo) { warningsEl.innerHTML = warnings .map( (w) => - `
WARNING: ${w}
`, + `
⚠ WARNING: ${w}
`, ) .join(""); warningsEl.classList.remove("hidden"); @@ -244,6 +245,7 @@ function show(txInfo) { showView("confirm-tx"); estimateGas(txInfo); + checkRecipientHistory(txInfo, warnings); } async function estimateGas(txInfo) { @@ -286,6 +288,33 @@ async function estimateGas(txInfo) { } } +async function checkRecipientHistory(txInfo, existingWarnings) { + try { + const blockscoutUrl = state.blockscoutUrl || DEFAULT_BLOCKSCOUT_URL; + const resp = await fetch(blockscoutUrl + "/addresses/" + txInfo.to); + if (!resp.ok) return; + const data = await resp.json(); + const txCount = + (parseInt(data.transactions_count || "0", 10) || 0) + + (parseInt(data.token_transfers_count || "0", 10) || 0); + if (txCount === 0) { + existingWarnings.push( + "This address has ZERO transaction history. It may be incorrect. Double-check before sending.", + ); + const warningsEl = $("confirm-warnings"); + warningsEl.innerHTML = existingWarnings + .map( + (w) => + `
⚠ WARNING: ${w}
`, + ) + .join(""); + warningsEl.classList.remove("hidden"); + } + } catch (e) { + log.errorf("recipient history check failed:", e.message); + } +} + function init(ctx) { $("btn-confirm-send").addEventListener("click", async () => { const password = $("confirm-tx-password").value;