Compare commits

..

1 Commits

Author SHA1 Message Date
user
7bd6b5bbdc feat: show red warning when sending to address with zero tx history
All checks were successful
check / check (push) Successful in 9s
On the confirm-tx screen, asynchronously check the recipient address
via Blockscout API. If the address has never sent or received any
transactions (normal or ERC-20), display a prominent red warning.

Fails open: network errors silently skip the warning to avoid
blocking legitimate sends.

Closes #82
2026-02-28 15:00:48 -08:00
2 changed files with 43 additions and 47 deletions

View File

@@ -25,7 +25,7 @@ const { decryptWithPassword } = require("../../shared/vault");
const { formatUsd, getPrice } = require("../../shared/prices"); const { formatUsd, getPrice } = require("../../shared/prices");
const { getProvider } = require("../../shared/balances"); const { getProvider } = require("../../shared/balances");
const { isScamAddress } = require("../../shared/scamlist"); const { isScamAddress } = require("../../shared/scamlist");
const { hasTransactionHistory } = require("../../shared/transactions"); const { hasZeroTransactionHistory } = require("../../shared/transactions");
const { ERC20_ABI } = require("../../shared/constants"); const { ERC20_ABI } = require("../../shared/constants");
const { log } = require("../../shared/log"); const { log } = require("../../shared/log");
const makeBlockie = require("ethereum-blockies-base64"); const makeBlockie = require("ethereum-blockies-base64");
@@ -289,29 +289,21 @@ async function estimateGas(txInfo) {
} }
async function checkRecipientHistory(txInfo) { async function checkRecipientHistory(txInfo) {
try { const isNew = await hasZeroTransactionHistory(
const hasHistory = await hasTransactionHistory(
txInfo.to, txInfo.to,
state.blockscoutUrl, state.blockscoutUrl,
); );
if (hasHistory === false) { if (!isNew) return;
const warningsEl = $("confirm-warnings"); const warningsEl = $("confirm-warnings");
const warningDiv = document.createElement("div"); const warningHtml =
warningDiv.className = `<div class="border border-red-500 border-dashed p-2 mb-1 text-xs font-bold text-red-500">` +
"border border-dashed p-2 mb-1 text-xs font-bold"; `WARNING: This address has ZERO transaction history. ` +
warningDiv.style.color = "#dc2626"; `It has never sent or received any funds. ` +
warningDiv.style.borderColor = "#dc2626"; `Double-check the address before sending.</div>`;
warningDiv.textContent = warningsEl.innerHTML = warningHtml + warningsEl.innerHTML;
"WARNING: This address has ZERO transaction history on-chain. " +
"It has never sent or received any transactions. " +
"Double-check the address before sending.";
warningsEl.appendChild(warningDiv);
warningsEl.classList.remove("hidden"); warningsEl.classList.remove("hidden");
} }
} catch (e) {
log.errorf("recipient history check failed:", e.message);
}
}
function init(ctx) { function init(ctx) {
$("btn-confirm-send").addEventListener("click", async () => { $("btn-confirm-send").addEventListener("click", async () => {

View File

@@ -251,36 +251,40 @@ function filterTransactions(txs, filters = {}) {
return { transactions: filtered, newFraudContracts: newFraud }; return { transactions: filtered, newFraudContracts: newFraud };
} }
async function hasTransactionHistory(address, blockscoutUrl) { /**
* Check whether an address has any on-chain transaction history.
* Returns true if the address has zero normal transactions AND zero
* token transfers on the configured Blockscout instance.
* Returns false on network errors (fail-open: don't block sends).
*/
async function hasZeroTransactionHistory(address, blockscoutUrl) {
try { try {
const resp = await debugFetch(blockscoutUrl + "/addresses/" + address); const resp = await debugFetch(
if (!resp.ok) { blockscoutUrl + "/addresses/" + address + "/transactions?limit=1",
// If Blockscout returns 404, the address has never been seen on-chain.
if (resp.status === 404) return false;
log.errorf(
"blockscout address check:",
resp.status,
resp.statusText,
); );
return null; // unknown if (!resp.ok) return false;
} const json = await resp.json();
const data = await resp.json(); if ((json.items || []).length > 0) return false;
// Blockscout v2 address endpoint returns tx counts.
// An address with no history may still exist (e.g. received ETH once // Also check token transfers — an address may have only received
// but shows 0 outgoing). We check both transactions_count and // ERC-20 tokens without any native ETH transactions.
// token_transfers_count to be thorough. const ttResp = await debugFetch(
const txCount = blockscoutUrl +
(parseInt(data.transactions_count, 10) || 0) + "/addresses/" +
(parseInt(data.token_transfers_count, 10) || 0); address +
return txCount > 0; "/token-transfers?type=ERC-20&limit=1",
);
if (!ttResp.ok) return false;
const ttJson = await ttResp.json();
return (ttJson.items || []).length === 0;
} catch (e) { } catch (e) {
log.errorf("hasTransactionHistory error:", e.message); log.errorf("hasZeroTransactionHistory check failed:", e.message);
return null; // unknown, don't block the user return false;
} }
} }
module.exports = { module.exports = {
fetchRecentTransactions, fetchRecentTransactions,
filterTransactions, filterTransactions,
hasTransactionHistory, hasZeroTransactionHistory,
}; };