Compare commits
1 Commits
feature/82
...
c8d1f96770
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c8d1f96770 |
@@ -172,8 +172,6 @@ function showTxApproval(details) {
|
|||||||
// If this is an ERC-20 call, try to extract the real recipient and amount
|
// If this is an ERC-20 call, try to extract the real recipient and amount
|
||||||
const decoded = decodeCalldata(details.txParams.data, toAddr || "");
|
const decoded = decodeCalldata(details.txParams.data, toAddr || "");
|
||||||
if (decoded && decoded.details) {
|
if (decoded && decoded.details) {
|
||||||
let decodedTokenAddr = null;
|
|
||||||
let decodedTokenSymbol = null;
|
|
||||||
for (const d of decoded.details) {
|
for (const d of decoded.details) {
|
||||||
if (d.label === "Recipient" && d.address) {
|
if (d.label === "Recipient" && d.address) {
|
||||||
pendingTxDetails.to = d.address;
|
pendingTxDetails.to = d.address;
|
||||||
@@ -181,20 +179,10 @@ function showTxApproval(details) {
|
|||||||
if (d.label === "Amount") {
|
if (d.label === "Amount") {
|
||||||
pendingTxDetails.amount = d.rawValue || d.value;
|
pendingTxDetails.amount = d.rawValue || d.value;
|
||||||
}
|
}
|
||||||
if (d.label === "Token In" && d.isToken && d.address) {
|
|
||||||
const t = TOKEN_BY_ADDRESS.get(d.address.toLowerCase());
|
|
||||||
if (t) {
|
|
||||||
decodedTokenAddr = d.address;
|
|
||||||
decodedTokenSymbol = t.symbol;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (token) {
|
if (token) {
|
||||||
pendingTxDetails.token = toAddr;
|
pendingTxDetails.token = toAddr;
|
||||||
pendingTxDetails.tokenSymbol = token.symbol;
|
pendingTxDetails.tokenSymbol = token.symbol;
|
||||||
} else if (decodedTokenAddr) {
|
|
||||||
pendingTxDetails.token = decodedTokenAddr;
|
|
||||||
pendingTxDetails.tokenSymbol = decodedTokenSymbol;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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 { hasTransactionHistory } = 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");
|
||||||
@@ -290,23 +289,20 @@ async function estimateGas(txInfo) {
|
|||||||
|
|
||||||
async function checkRecipientHistory(txInfo) {
|
async function checkRecipientHistory(txInfo) {
|
||||||
try {
|
try {
|
||||||
const hasHistory = await hasTransactionHistory(
|
const provider = getProvider(state.rpcUrl);
|
||||||
txInfo.to,
|
const txCount = await provider.getTransactionCount(txInfo.to);
|
||||||
state.blockscoutUrl,
|
if (txCount === 0) {
|
||||||
);
|
|
||||||
if (hasHistory === false) {
|
|
||||||
const warningsEl = $("confirm-warnings");
|
const warningsEl = $("confirm-warnings");
|
||||||
const warningDiv = document.createElement("div");
|
const warning =
|
||||||
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: The recipient address has ZERO transaction history. ` +
|
||||||
warningDiv.style.color = "#dc2626";
|
`This may indicate a fresh or unused address. Double-check the address before sending.</div>`;
|
||||||
warningDiv.style.borderColor = "#dc2626";
|
if (warningsEl.classList.contains("hidden")) {
|
||||||
warningDiv.textContent =
|
warningsEl.innerHTML = warning;
|
||||||
"WARNING: This address has ZERO transaction history on-chain. " +
|
warningsEl.classList.remove("hidden");
|
||||||
"It has never sent or received any transactions. " +
|
} else {
|
||||||
"Double-check the address before sending.";
|
warningsEl.innerHTML += warning;
|
||||||
warningsEl.appendChild(warningDiv);
|
}
|
||||||
warningsEl.classList.remove("hidden");
|
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log.errorf("recipient history check failed:", e.message);
|
log.errorf("recipient history check failed:", e.message);
|
||||||
|
|||||||
@@ -43,11 +43,10 @@ function toAddressHtml(address) {
|
|||||||
if (title) {
|
if (title) {
|
||||||
return (
|
return (
|
||||||
`<div class="flex items-center font-bold">${dot}${escapeHtml(title)}</div>` +
|
`<div class="flex items-center font-bold">${dot}${escapeHtml(title)}</div>` +
|
||||||
`<div class="break-all underline decoration-dashed cursor-pointer" data-copy="${escapeHtml(address)}">${escapeHtml(address)}</div>` +
|
`<div class="break-all">${escapeHtml(address)}${extLink}</div>`
|
||||||
extLink
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return `<div class="flex items-center">${dot}<span class="break-all underline decoration-dashed cursor-pointer" data-copy="${escapeHtml(address)}">${escapeHtml(address)}</span>${extLink}</div>`;
|
return `<div class="flex items-center">${dot}<span class="break-all">${escapeHtml(address)}</span>${extLink}</div>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
function txHashHtml(hash) {
|
function txHashHtml(hash) {
|
||||||
@@ -140,7 +139,7 @@ function etherscanTokenLink(address) {
|
|||||||
|
|
||||||
function decodedDetailsHtml(decoded) {
|
function decodedDetailsHtml(decoded) {
|
||||||
if (!decoded || !decoded.details) return "";
|
if (!decoded || !decoded.details) return "";
|
||||||
let html = `<div class="border border-border border-dashed p-2 mb-3">`;
|
let html = "";
|
||||||
if (decoded.name) {
|
if (decoded.name) {
|
||||||
html += `<div class="mb-2"><div class="text-xs text-muted mb-1">Action</div>`;
|
html += `<div class="mb-2"><div class="text-xs text-muted mb-1">Action</div>`;
|
||||||
html += `<div class="font-bold">${escapeHtml(decoded.name)}</div></div>`;
|
html += `<div class="font-bold">${escapeHtml(decoded.name)}</div></div>`;
|
||||||
@@ -165,36 +164,20 @@ function decodedDetailsHtml(decoded) {
|
|||||||
}
|
}
|
||||||
html += `</div>`;
|
html += `</div>`;
|
||||||
}
|
}
|
||||||
html += `</div>`;
|
|
||||||
return html;
|
return html;
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderSuccess() {
|
function renderSuccess() {
|
||||||
const d = state.viewData;
|
const d = state.viewData;
|
||||||
if (!d || !d.hash) return;
|
if (!d || !d.hash) return;
|
||||||
|
$("success-tx-summary").textContent = d.amount + " " + d.symbol;
|
||||||
const hasDecoded = d.decoded && d.decoded.details;
|
$("success-tx-to").innerHTML = toAddressHtml(d.to);
|
||||||
|
|
||||||
// When decoded details are present, the Amount and To are already
|
|
||||||
// shown inside the decoded well — hide the top-level duplicates.
|
|
||||||
const summarySection = $("success-tx-summary").parentElement;
|
|
||||||
const toSection = $("success-tx-to").parentElement;
|
|
||||||
if (hasDecoded) {
|
|
||||||
summarySection.classList.add("hidden");
|
|
||||||
toSection.classList.add("hidden");
|
|
||||||
} else {
|
|
||||||
summarySection.classList.remove("hidden");
|
|
||||||
toSection.classList.remove("hidden");
|
|
||||||
$("success-tx-summary").textContent = d.amount + " " + d.symbol;
|
|
||||||
$("success-tx-to").innerHTML = toAddressHtml(d.to);
|
|
||||||
}
|
|
||||||
|
|
||||||
$("success-tx-block").textContent = String(d.blockNumber);
|
$("success-tx-block").textContent = String(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
|
||||||
const decodedEl = $("success-tx-decoded");
|
const decodedEl = $("success-tx-decoded");
|
||||||
if (decodedEl && hasDecoded) {
|
if (decodedEl && d.decoded) {
|
||||||
decodedEl.innerHTML = decodedDetailsHtml(d.decoded);
|
decodedEl.innerHTML = decodedDetailsHtml(d.decoded);
|
||||||
decodedEl.classList.remove("hidden");
|
decodedEl.classList.remove("hidden");
|
||||||
} else if (decodedEl) {
|
} else if (decodedEl) {
|
||||||
|
|||||||
@@ -251,36 +251,4 @@ function filterTransactions(txs, filters = {}) {
|
|||||||
return { transactions: filtered, newFraudContracts: newFraud };
|
return { transactions: filtered, newFraudContracts: newFraud };
|
||||||
}
|
}
|
||||||
|
|
||||||
async function hasTransactionHistory(address, blockscoutUrl) {
|
module.exports = { fetchRecentTransactions, filterTransactions };
|
||||||
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,
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -445,18 +445,12 @@ function decode(data, toAddress) {
|
|||||||
const maxUint160 = BigInt(
|
const maxUint160 = BigInt(
|
||||||
"0xffffffffffffffffffffffffffffffffffffffff",
|
"0xffffffffffffffffffffffffffffffffffffffff",
|
||||||
);
|
);
|
||||||
const isUnlimited = inputAmount >= maxUint160;
|
const amountStr =
|
||||||
const amountRaw = isUnlimited
|
inputAmount >= maxUint160
|
||||||
? "Unlimited"
|
? "Unlimited"
|
||||||
: formatAmount(inputAmount, inInfo.decimals);
|
: formatAmount(inputAmount, inInfo.decimals) +
|
||||||
const amountStr = isUnlimited
|
(inSymbol ? " " + inSymbol : "");
|
||||||
? "Unlimited"
|
details.push({ label: "Amount", value: amountStr });
|
||||||
: amountRaw + (inSymbol ? " " + inSymbol : "");
|
|
||||||
details.push({
|
|
||||||
label: "Amount",
|
|
||||||
value: amountStr,
|
|
||||||
rawValue: amountRaw,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (outSymbol) {
|
if (outSymbol) {
|
||||||
|
|||||||
Reference in New Issue
Block a user