Compare commits
1 Commits
b799686cd4
...
feature/82
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fd69e1e215 |
@@ -577,19 +577,6 @@
|
|||||||
<div id="confirm-fee-amount" class="text-xs"></div>
|
<div id="confirm-fee-amount" class="text-xs"></div>
|
||||||
</div>
|
</div>
|
||||||
<div id="confirm-warnings" class="mb-2 hidden"></div>
|
<div id="confirm-warnings" class="mb-2 hidden"></div>
|
||||||
<div
|
|
||||||
id="confirm-recipient-warning"
|
|
||||||
class="mb-2"
|
|
||||||
style="visibility: hidden"
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
class="border border-red-500 border-dashed p-2 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>
|
|
||||||
</div>
|
|
||||||
<div
|
<div
|
||||||
id="confirm-errors"
|
id="confirm-errors"
|
||||||
class="mb-2 border border-border border-dashed p-2 hidden"
|
class="mb-2 border border-border border-dashed p-2 hidden"
|
||||||
|
|||||||
@@ -86,6 +86,42 @@ function valueWithUsd(text, usdAmount) {
|
|||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function renderWarnings(warnings) {
|
||||||
|
const warningsEl = $("confirm-warnings");
|
||||||
|
if (warnings.length > 0) {
|
||||||
|
warningsEl.innerHTML = warnings
|
||||||
|
.map(
|
||||||
|
(w) =>
|
||||||
|
`<div class="border border-border border-dashed p-2 mb-1 text-xs font-bold" style="color:#c00">WARNING: ${w}</div>`,
|
||||||
|
)
|
||||||
|
.join("");
|
||||||
|
warningsEl.classList.remove("hidden");
|
||||||
|
} else {
|
||||||
|
warningsEl.classList.add("hidden");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function checkAddressHistory(address, existingWarnings) {
|
||||||
|
try {
|
||||||
|
const provider = getProvider(state.rpcUrl);
|
||||||
|
const [balance, txCount] = await Promise.all([
|
||||||
|
provider.getBalance(address),
|
||||||
|
provider.getTransactionCount(address),
|
||||||
|
]);
|
||||||
|
if (balance === 0n && txCount === 0) {
|
||||||
|
const warnings = existingWarnings.slice();
|
||||||
|
warnings.push(
|
||||||
|
"This address has ZERO transaction history. " +
|
||||||
|
"It has never sent or received funds. " +
|
||||||
|
"Double-check that the address is correct before sending.",
|
||||||
|
);
|
||||||
|
renderWarnings(warnings);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
log.errorf("address history check failed:", e.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function show(txInfo) {
|
function show(txInfo) {
|
||||||
pendingTx = txInfo;
|
pendingTx = txInfo;
|
||||||
|
|
||||||
@@ -176,18 +212,10 @@ function show(txInfo) {
|
|||||||
warnings.push("You are sending to your own address.");
|
warnings.push("You are sending to your own address.");
|
||||||
}
|
}
|
||||||
|
|
||||||
const warningsEl = $("confirm-warnings");
|
renderWarnings(warnings);
|
||||||
if (warnings.length > 0) {
|
|
||||||
warningsEl.innerHTML = warnings
|
// Async check: warn if destination address has zero transaction history
|
||||||
.map(
|
checkAddressHistory(txInfo.to, warnings);
|
||||||
(w) =>
|
|
||||||
`<div class="border border-border border-dashed p-2 mb-1 text-xs font-bold">WARNING: ${w}</div>`,
|
|
||||||
)
|
|
||||||
.join("");
|
|
||||||
warningsEl.classList.remove("hidden");
|
|
||||||
} else {
|
|
||||||
warningsEl.classList.add("hidden");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check for errors
|
// Check for errors
|
||||||
const errors = [];
|
const errors = [];
|
||||||
@@ -243,14 +271,7 @@ function show(txInfo) {
|
|||||||
state.viewData = { pendingTx: txInfo };
|
state.viewData = { pendingTx: txInfo };
|
||||||
showView("confirm-tx");
|
showView("confirm-tx");
|
||||||
|
|
||||||
// Reset recipient warning: reserve space (visibility:hidden) while
|
|
||||||
// the async check runs, preventing layout shift per README policy.
|
|
||||||
const recipientWarning = $("confirm-recipient-warning");
|
|
||||||
recipientWarning.style.display = "";
|
|
||||||
recipientWarning.style.visibility = "hidden";
|
|
||||||
|
|
||||||
estimateGas(txInfo);
|
estimateGas(txInfo);
|
||||||
checkRecipientHistory(txInfo);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function estimateGas(txInfo) {
|
async function estimateGas(txInfo) {
|
||||||
@@ -293,34 +314,6 @@ async function estimateGas(txInfo) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function checkRecipientHistory(txInfo) {
|
|
||||||
const el = $("confirm-recipient-warning");
|
|
||||||
try {
|
|
||||||
const provider = getProvider(state.rpcUrl);
|
|
||||||
// Skip warning for contract addresses — they may legitimately
|
|
||||||
// have zero outgoing transactions (getTransactionCount returns
|
|
||||||
// the nonce, i.e. sent-tx count only).
|
|
||||||
const code = await provider.getCode(txInfo.to);
|
|
||||||
if (code && code !== "0x") {
|
|
||||||
// Contract address — hide the reserved space entirely
|
|
||||||
el.style.display = "none";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const txCount = await provider.getTransactionCount(txInfo.to);
|
|
||||||
if (txCount === 0) {
|
|
||||||
el.style.visibility = "visible";
|
|
||||||
} else {
|
|
||||||
// Address has history — collapse the reserved space
|
|
||||||
el.style.display = "none";
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
log.errorf("recipient history check failed:", e.message);
|
|
||||||
// On error, collapse the reserved space rather than showing a
|
|
||||||
// false warning or leaving an empty gap
|
|
||||||
el.style.display = "none";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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