feat: show red warning on confirm-tx when recipient has zero transaction history #93
@@ -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) =>
|
||||
`<div class="border border-border border-dashed p-2 mb-1 text-xs font-bold">WARNING: ${w}</div>`,
|
||||
`<div class="border border-red-500 border-dashed p-2 mb-1 text-xs font-bold text-red-500">⚠ WARNING: ${w}</div>`,
|
||||
)
|
||||
.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) =>
|
||||
`<div class="border border-red-500 border-dashed p-2 mb-1 text-xs font-bold text-red-500">⚠ WARNING: ${w}</div>`,
|
||||
)
|
||||
.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;
|
||||
|
||||
Reference in New Issue
Block a user