Compare commits

..

1 Commits

Author SHA1 Message Date
user
7d1d584b52 feat: make block number click-to-copy with Etherscan external link on success-tx view
All checks were successful
check / check (push) Successful in 7s
Closes #99

The block number on the success-tx view is now styled consistently with
other blockchain entities (addresses, tx hashes): it has a dashed underline
for click-to-copy and an external link icon pointing to etherscan.io/block/.
2026-02-28 14:52:06 -08:00
3 changed files with 12 additions and 61 deletions

View File

@@ -25,7 +25,6 @@ const { decryptWithPassword } = require("../../shared/vault");
const { formatUsd, getPrice } = require("../../shared/prices");
const { getProvider } = require("../../shared/balances");
const { isScamAddress } = require("../../shared/scamlist");
const { hasTransactionHistory } = require("../../shared/transactions");
const { ERC20_ABI } = require("../../shared/constants");
const { log } = require("../../shared/log");
const makeBlockie = require("ethereum-blockies-base64");
@@ -245,7 +244,6 @@ function show(txInfo) {
showView("confirm-tx");
estimateGas(txInfo);
checkRecipientHistory(txInfo);
}
async function estimateGas(txInfo) {
@@ -288,31 +286,6 @@ async function estimateGas(txInfo) {
}
}
async function checkRecipientHistory(txInfo) {
try {
const hasHistory = await hasTransactionHistory(
txInfo.to,
state.blockscoutUrl,
);
if (hasHistory === false) {
const warningsEl = $("confirm-warnings");
const warningDiv = document.createElement("div");
warningDiv.className =
"border border-dashed p-2 mb-1 text-xs font-bold";
warningDiv.style.color = "#dc2626";
warningDiv.style.borderColor = "#dc2626";
warningDiv.textContent =
"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");
}
} 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;

View File

@@ -59,6 +59,16 @@ function txHashHtml(hash) {
);
}
function blockNumberHtml(blockNumber) {
const num = String(blockNumber);
const link = `https://etherscan.io/block/${num}`;
const extLink = `<a href="${link}" target="_blank" rel="noopener" class="inline-flex items-center">${EXT_ICON}</a>`;
return (
`<span class="underline decoration-dashed cursor-pointer" data-copy="${escapeHtml(num)}">${escapeHtml(num)}</span>` +
extLink
);
}
function attachCopyHandlers(viewId) {
document
.getElementById(viewId)
@@ -189,7 +199,7 @@ function renderSuccess() {
$("success-tx-to").innerHTML = toAddressHtml(d.to);
}
$("success-tx-block").textContent = String(d.blockNumber);
$("success-tx-block").innerHTML = blockNumberHtml(d.blockNumber);
$("success-tx-hash").innerHTML = txHashHtml(d.hash);
// Show decoded calldata details if present

View File

@@ -251,36 +251,4 @@ function filterTransactions(txs, filters = {}) {
return { transactions: filtered, newFraudContracts: newFraud };
}
async function hasTransactionHistory(address, blockscoutUrl) {
try {
const resp = await debugFetch(blockscoutUrl + "/addresses/" + address);
if (!resp.ok) {
// 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
}
const data = await resp.json();
// Blockscout v2 address endpoint returns tx counts.
// An address with no history may still exist (e.g. received ETH once
// but shows 0 outgoing). We check both transactions_count and
// token_transfers_count to be thorough.
const txCount =
(parseInt(data.transactions_count, 10) || 0) +
(parseInt(data.token_transfers_count, 10) || 0);
return txCount > 0;
} catch (e) {
log.errorf("hasTransactionHistory error:", e.message);
return null; // unknown, don't block the user
}
}
module.exports = {
fetchRecentTransactions,
filterTransactions,
hasTransactionHistory,
};
module.exports = { fetchRecentTransactions, filterTransactions };