Compare commits
1 Commits
feature/is
...
issue-99-b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7d1d584b52 |
@@ -25,7 +25,6 @@ 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 { 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");
|
||||||
@@ -245,7 +244,6 @@ function show(txInfo) {
|
|||||||
showView("confirm-tx");
|
showView("confirm-tx");
|
||||||
|
|
||||||
estimateGas(txInfo);
|
estimateGas(txInfo);
|
||||||
checkRecipientHistory(txInfo);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function estimateGas(txInfo) {
|
async function estimateGas(txInfo) {
|
||||||
@@ -288,23 +286,6 @@ async function estimateGas(txInfo) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function checkRecipientHistory(txInfo) {
|
|
||||||
const isNew = await hasZeroTransactionHistory(
|
|
||||||
txInfo.to,
|
|
||||||
state.blockscoutUrl,
|
|
||||||
);
|
|
||||||
if (!isNew) return;
|
|
||||||
|
|
||||||
const warningsEl = $("confirm-warnings");
|
|
||||||
const warningHtml =
|
|
||||||
`<div class="border border-red-500 border-dashed p-2 mb-1 text-xs font-bold text-red-500">` +
|
|
||||||
`WARNING: This address has ZERO transaction history. ` +
|
|
||||||
`It has never sent or received any funds. ` +
|
|
||||||
`Double-check the address before sending.</div>`;
|
|
||||||
warningsEl.innerHTML = warningHtml + warningsEl.innerHTML;
|
|
||||||
warningsEl.classList.remove("hidden");
|
|
||||||
}
|
|
||||||
|
|
||||||
function init(ctx) {
|
function init(ctx) {
|
||||||
$("btn-confirm-send").addEventListener("click", async () => {
|
$("btn-confirm-send").addEventListener("click", async () => {
|
||||||
const password = $("confirm-tx-password").value;
|
const password = $("confirm-tx-password").value;
|
||||||
|
|||||||
@@ -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) {
|
function attachCopyHandlers(viewId) {
|
||||||
document
|
document
|
||||||
.getElementById(viewId)
|
.getElementById(viewId)
|
||||||
@@ -189,7 +199,7 @@ function renderSuccess() {
|
|||||||
$("success-tx-to").innerHTML = toAddressHtml(d.to);
|
$("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);
|
$("success-tx-hash").innerHTML = txHashHtml(d.hash);
|
||||||
|
|
||||||
// Show decoded calldata details if present
|
// Show decoded calldata details if present
|
||||||
|
|||||||
@@ -251,40 +251,4 @@ function filterTransactions(txs, filters = {}) {
|
|||||||
return { transactions: filtered, newFraudContracts: newFraud };
|
return { transactions: filtered, newFraudContracts: newFraud };
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
module.exports = { fetchRecentTransactions, filterTransactions };
|
||||||
* 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 {
|
|
||||||
const resp = await debugFetch(
|
|
||||||
blockscoutUrl + "/addresses/" + address + "/transactions?limit=1",
|
|
||||||
);
|
|
||||||
if (!resp.ok) return false;
|
|
||||||
const json = await resp.json();
|
|
||||||
if ((json.items || []).length > 0) return false;
|
|
||||||
|
|
||||||
// Also check token transfers — an address may have only received
|
|
||||||
// ERC-20 tokens without any native ETH transactions.
|
|
||||||
const ttResp = await debugFetch(
|
|
||||||
blockscoutUrl +
|
|
||||||
"/addresses/" +
|
|
||||||
address +
|
|
||||||
"/token-transfers?type=ERC-20&limit=1",
|
|
||||||
);
|
|
||||||
if (!ttResp.ok) return false;
|
|
||||||
const ttJson = await ttResp.json();
|
|
||||||
return (ttJson.items || []).length === 0;
|
|
||||||
} catch (e) {
|
|
||||||
log.errorf("hasZeroTransactionHistory check failed:", e.message);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
fetchRecentTransactions,
|
|
||||||
filterTransactions,
|
|
||||||
hasZeroTransactionHistory,
|
|
||||||
};
|
|
||||||
|
|||||||
Reference in New Issue
Block a user