feat: show red warning when sending to address with zero tx history
All checks were successful
check / check (push) Successful in 21s
All checks were successful
check / check (push) Successful in 21s
On the confirm-tx view, asynchronously check the recipient address transaction count via getTransactionCount(). If zero, display a prominent red warning advising the user to double-check the address. Closes #82
This commit is contained in:
@@ -244,6 +244,7 @@ function show(txInfo) {
|
|||||||
showView("confirm-tx");
|
showView("confirm-tx");
|
||||||
|
|
||||||
estimateGas(txInfo);
|
estimateGas(txInfo);
|
||||||
|
checkRecipientHistory(txInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function estimateGas(txInfo) {
|
async function estimateGas(txInfo) {
|
||||||
@@ -286,6 +287,28 @@ async function estimateGas(txInfo) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function checkRecipientHistory(txInfo) {
|
||||||
|
try {
|
||||||
|
const provider = getProvider(state.rpcUrl);
|
||||||
|
const txCount = await provider.getTransactionCount(txInfo.to);
|
||||||
|
if (txCount === 0) {
|
||||||
|
const warningsEl = $("confirm-warnings");
|
||||||
|
const warning =
|
||||||
|
`<div class="border border-red-500 border-dashed p-2 mb-1 text-xs font-bold text-red-500">` +
|
||||||
|
`WARNING: The recipient address has ZERO transaction history. ` +
|
||||||
|
`This may indicate a fresh or unused address. Double-check the address before sending.</div>`;
|
||||||
|
if (warningsEl.classList.contains("hidden")) {
|
||||||
|
warningsEl.innerHTML = warning;
|
||||||
|
warningsEl.classList.remove("hidden");
|
||||||
|
} else {
|
||||||
|
warningsEl.innerHTML += warning;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} 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 () => {
|
||||||
const password = $("confirm-tx-password").value;
|
const password = $("confirm-tx-password").value;
|
||||||
|
|||||||
Reference in New Issue
Block a user