Compare commits
1 Commits
b799686cd4
...
fix/77-con
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d2f7284975 |
@@ -496,11 +496,6 @@
|
|||||||
class="border border-border p-1 w-full font-mono text-sm bg-bg text-fg"
|
class="border border-border p-1 w-full font-mono text-sm bg-bg text-fg"
|
||||||
placeholder="Address (0x...) or ENS name"
|
placeholder="Address (0x...) or ENS name"
|
||||||
/>
|
/>
|
||||||
<div
|
|
||||||
id="send-to-error"
|
|
||||||
class="text-xs"
|
|
||||||
style="min-height: 1.25rem; color: #cc0000"
|
|
||||||
></div>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="mb-2">
|
<div class="mb-2">
|
||||||
<div class="flex justify-between mb-1">
|
<div class="flex justify-between mb-1">
|
||||||
@@ -577,40 +572,15 @@
|
|||||||
<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"
|
||||||
></div>
|
></div>
|
||||||
<div class="mb-2">
|
|
||||||
<label class="block mb-1 text-xs">Password</label>
|
|
||||||
<input
|
|
||||||
type="password"
|
|
||||||
id="confirm-tx-password"
|
|
||||||
class="border border-border p-1 w-full font-mono text-sm bg-bg text-fg"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
id="confirm-tx-password-error"
|
|
||||||
class="text-xs mb-2 min-h-[1.25rem]"
|
|
||||||
></div>
|
|
||||||
<button
|
<button
|
||||||
id="btn-confirm-send"
|
id="btn-confirm-send"
|
||||||
class="border border-border px-2 py-1 hover:bg-fg hover:text-bg cursor-pointer"
|
class="border border-border px-2 py-1 hover:bg-fg hover:text-bg cursor-pointer"
|
||||||
>
|
>
|
||||||
Sign & Send
|
Send
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -689,6 +659,42 @@
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- ============ PASSWORD MODAL ============ -->
|
||||||
|
<div
|
||||||
|
id="password-modal"
|
||||||
|
class="hidden fixed inset-0 bg-bg flex items-center justify-center z-50"
|
||||||
|
>
|
||||||
|
<div class="border border-border p-4 bg-bg w-80">
|
||||||
|
<h2 class="font-bold mb-2">Enter Password</h2>
|
||||||
|
<p class="text-xs text-muted mb-2">
|
||||||
|
Your password is needed to authorize this transaction.
|
||||||
|
</p>
|
||||||
|
<input
|
||||||
|
type="password"
|
||||||
|
id="modal-password"
|
||||||
|
class="border border-border p-1 w-full font-mono text-sm bg-bg text-fg mb-2"
|
||||||
|
/>
|
||||||
|
<div
|
||||||
|
id="modal-password-error"
|
||||||
|
class="text-xs mb-2 border border-border border-dashed p-1 hidden"
|
||||||
|
></div>
|
||||||
|
<div class="flex gap-2">
|
||||||
|
<button
|
||||||
|
id="btn-modal-confirm"
|
||||||
|
class="border border-border px-2 py-1 hover:bg-fg hover:text-bg cursor-pointer"
|
||||||
|
>
|
||||||
|
Confirm
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
id="btn-modal-cancel"
|
||||||
|
class="border border-border px-2 py-1 hover:bg-fg hover:text-bg cursor-pointer"
|
||||||
|
>
|
||||||
|
Cancel
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<!-- ============ RECEIVE ============ -->
|
<!-- ============ RECEIVE ============ -->
|
||||||
<div id="view-receive" class="view hidden">
|
<div id="view-receive" class="view hidden">
|
||||||
<button
|
<button
|
||||||
@@ -1128,10 +1134,7 @@
|
|||||||
class="border border-border p-1 w-full font-mono text-sm bg-bg text-fg"
|
class="border border-border p-1 w-full font-mono text-sm bg-bg text-fg"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div id="approve-tx-error" class="text-xs hidden mb-2"></div>
|
||||||
id="approve-tx-error"
|
|
||||||
class="text-xs mb-2 border border-border border-dashed p-1 min-h-[1.25rem] hidden"
|
|
||||||
></div>
|
|
||||||
<div class="flex justify-between">
|
<div class="flex justify-between">
|
||||||
<button
|
<button
|
||||||
id="btn-approve-tx"
|
id="btn-approve-tx"
|
||||||
@@ -1194,10 +1197,7 @@
|
|||||||
class="border border-border p-1 w-full font-mono text-sm bg-bg text-fg"
|
class="border border-border p-1 w-full font-mono text-sm bg-bg text-fg"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div id="approve-sign-error" class="text-xs hidden mb-2"></div>
|
||||||
id="approve-sign-error"
|
|
||||||
class="text-xs mb-2 border border-border border-dashed p-1 min-h-[1.25rem] hidden"
|
|
||||||
></div>
|
|
||||||
<div class="flex justify-between">
|
<div class="flex justify-between">
|
||||||
<button
|
<button
|
||||||
id="btn-approve-sign"
|
id="btn-approve-sign"
|
||||||
|
|||||||
@@ -74,8 +74,8 @@ const RESTORABLE_VIEWS = new Set([
|
|||||||
"receive",
|
"receive",
|
||||||
"settings",
|
"settings",
|
||||||
"settings-addtoken",
|
"settings-addtoken",
|
||||||
"confirm-tx",
|
|
||||||
"transaction",
|
"transaction",
|
||||||
|
"confirm-tx",
|
||||||
"success-tx",
|
"success-tx",
|
||||||
"error-tx",
|
"error-tx",
|
||||||
]);
|
]);
|
||||||
@@ -128,16 +128,16 @@ function restoreView() {
|
|||||||
case "settings-addtoken":
|
case "settings-addtoken":
|
||||||
settingsAddToken.show();
|
settingsAddToken.show();
|
||||||
break;
|
break;
|
||||||
case "confirm-tx":
|
case "transaction":
|
||||||
if (state.viewData && state.viewData.pendingTx) {
|
if (state.viewData && state.viewData.tx) {
|
||||||
confirmTx.restore();
|
transactionDetail.render();
|
||||||
} else {
|
} else {
|
||||||
fallbackView();
|
fallbackView();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "transaction":
|
case "confirm-tx":
|
||||||
if (state.viewData && state.viewData.tx) {
|
if (state.viewData && state.viewData.pendingTx) {
|
||||||
transactionDetail.render();
|
confirmTx.show(state.viewData.pendingTx);
|
||||||
} else {
|
} else {
|
||||||
fallbackView();
|
fallbackView();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,11 +15,7 @@ const {
|
|||||||
filterTransactions,
|
filterTransactions,
|
||||||
} = require("../../shared/transactions");
|
} = require("../../shared/transactions");
|
||||||
const { resolveEnsNames } = require("../../shared/ens");
|
const { resolveEnsNames } = require("../../shared/ens");
|
||||||
const {
|
const { updateSendBalance, renderSendTokenSelect } = require("./send");
|
||||||
updateSendBalance,
|
|
||||||
renderSendTokenSelect,
|
|
||||||
resetSendValidation,
|
|
||||||
} = require("./send");
|
|
||||||
const { log } = require("../../shared/log");
|
const { log } = require("../../shared/log");
|
||||||
const makeBlockie = require("ethereum-blockies-base64");
|
const makeBlockie = require("ethereum-blockies-base64");
|
||||||
const { decryptWithPassword } = require("../../shared/vault");
|
const { decryptWithPassword } = require("../../shared/vault");
|
||||||
@@ -263,7 +259,6 @@ function init(_ctx) {
|
|||||||
$("send-token").classList.remove("hidden");
|
$("send-token").classList.remove("hidden");
|
||||||
$("send-token-static").classList.add("hidden");
|
$("send-token-static").classList.add("hidden");
|
||||||
updateSendBalance();
|
updateSendBalance();
|
||||||
resetSendValidation();
|
|
||||||
showView("send");
|
showView("send");
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -325,9 +320,6 @@ function init(_ctx) {
|
|||||||
$("export-privkey-flash").classList.remove("hidden");
|
$("export-privkey-flash").classList.remove("hidden");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const btn = $("btn-export-privkey-confirm");
|
|
||||||
btn.disabled = true;
|
|
||||||
btn.classList.add("text-muted");
|
|
||||||
const wallet = state.wallets[state.selectedWallet];
|
const wallet = state.wallets[state.selectedWallet];
|
||||||
try {
|
try {
|
||||||
const secret = await decryptWithPassword(
|
const secret = await decryptWithPassword(
|
||||||
@@ -347,9 +339,6 @@ function init(_ctx) {
|
|||||||
} catch {
|
} catch {
|
||||||
$("export-privkey-flash").textContent = "Wrong password.";
|
$("export-privkey-flash").textContent = "Wrong password.";
|
||||||
$("export-privkey-flash").classList.remove("hidden");
|
$("export-privkey-flash").classList.remove("hidden");
|
||||||
} finally {
|
|
||||||
btn.disabled = false;
|
|
||||||
btn.classList.remove("text-muted");
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -23,11 +23,7 @@ const {
|
|||||||
filterTransactions,
|
filterTransactions,
|
||||||
} = require("../../shared/transactions");
|
} = require("../../shared/transactions");
|
||||||
const { resolveEnsNames } = require("../../shared/ens");
|
const { resolveEnsNames } = require("../../shared/ens");
|
||||||
const {
|
const { updateSendBalance, renderSendTokenSelect } = require("./send");
|
||||||
updateSendBalance,
|
|
||||||
renderSendTokenSelect,
|
|
||||||
resetSendValidation,
|
|
||||||
} = require("./send");
|
|
||||||
const { log } = require("../../shared/log");
|
const { log } = require("../../shared/log");
|
||||||
const makeBlockie = require("ethereum-blockies-base64");
|
const makeBlockie = require("ethereum-blockies-base64");
|
||||||
|
|
||||||
@@ -376,7 +372,6 @@ function init(_ctx) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
updateSendBalance();
|
updateSendBalance();
|
||||||
resetSendValidation();
|
|
||||||
showView("send");
|
showView("send");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -4,8 +4,6 @@ const {
|
|||||||
addressTitle,
|
addressTitle,
|
||||||
escapeHtml,
|
escapeHtml,
|
||||||
showView,
|
showView,
|
||||||
showError,
|
|
||||||
hideError,
|
|
||||||
} = require("./helpers");
|
} = require("./helpers");
|
||||||
const { state, saveState } = require("../../shared/state");
|
const { state, saveState } = require("../../shared/state");
|
||||||
const { formatEther, formatUnits, Interface, toUtf8String } = require("ethers");
|
const { formatEther, formatUnits, Interface, toUtf8String } = require("ethers");
|
||||||
@@ -172,8 +170,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 +177,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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -268,9 +254,6 @@ function showTxApproval(details) {
|
|||||||
$("approve-tx-data-section").classList.add("hidden");
|
$("approve-tx-data-section").classList.add("hidden");
|
||||||
}
|
}
|
||||||
|
|
||||||
$("approve-tx-password").value = "";
|
|
||||||
$("approve-tx-error").classList.add("hidden");
|
|
||||||
|
|
||||||
showView("approve-tx");
|
showView("approve-tx");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -359,7 +342,7 @@ function showSignApproval(details) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$("approve-sign-password").value = "";
|
$("approve-sign-password").value = "";
|
||||||
hideError("approve-sign-error");
|
$("approve-sign-error").classList.add("hidden");
|
||||||
$("btn-approve-sign").disabled = false;
|
$("btn-approve-sign").disabled = false;
|
||||||
$("btn-approve-sign").classList.remove("text-muted");
|
$("btn-approve-sign").classList.remove("text-muted");
|
||||||
|
|
||||||
@@ -424,10 +407,11 @@ function init(ctx) {
|
|||||||
$("btn-approve-tx").addEventListener("click", () => {
|
$("btn-approve-tx").addEventListener("click", () => {
|
||||||
const password = $("approve-tx-password").value;
|
const password = $("approve-tx-password").value;
|
||||||
if (!password) {
|
if (!password) {
|
||||||
showError("approve-tx-error", "Please enter your password.");
|
$("approve-tx-error").textContent = "Please enter your password.";
|
||||||
|
$("approve-tx-error").classList.remove("hidden");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
hideError("approve-tx-error");
|
$("approve-tx-error").classList.add("hidden");
|
||||||
$("btn-approve-tx").disabled = true;
|
$("btn-approve-tx").disabled = true;
|
||||||
$("btn-approve-tx").classList.add("text-muted");
|
$("btn-approve-tx").classList.add("text-muted");
|
||||||
|
|
||||||
@@ -463,10 +447,11 @@ function init(ctx) {
|
|||||||
$("btn-approve-sign").addEventListener("click", () => {
|
$("btn-approve-sign").addEventListener("click", () => {
|
||||||
const password = $("approve-sign-password").value;
|
const password = $("approve-sign-password").value;
|
||||||
if (!password) {
|
if (!password) {
|
||||||
showError("approve-sign-error", "Please enter your password.");
|
$("approve-sign-error").textContent = "Please enter your password.";
|
||||||
|
$("approve-sign-error").classList.remove("hidden");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
hideError("approve-sign-error");
|
$("approve-sign-error").classList.add("hidden");
|
||||||
$("btn-approve-sign").disabled = true;
|
$("btn-approve-sign").disabled = true;
|
||||||
$("btn-approve-sign").classList.add("text-muted");
|
$("btn-approve-sign").classList.add("text-muted");
|
||||||
|
|
||||||
@@ -484,7 +469,8 @@ function init(ctx) {
|
|||||||
} else {
|
} else {
|
||||||
const msg =
|
const msg =
|
||||||
(response && response.error) || "Signing failed.";
|
(response && response.error) || "Signing failed.";
|
||||||
showError("approve-sign-error", msg);
|
$("approve-sign-error").textContent = msg;
|
||||||
|
$("approve-sign-error").classList.remove("hidden");
|
||||||
$("btn-approve-sign").disabled = false;
|
$("btn-approve-sign").disabled = false;
|
||||||
$("btn-approve-sign").classList.remove("text-muted");
|
$("btn-approve-sign").classList.remove("text-muted");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// Transaction confirmation view with inline password.
|
// Transaction confirmation view + password modal.
|
||||||
// Shows transaction details, warnings, errors. On Sign & Send,
|
// Shows transaction details, warnings, errors. On proceed, opens
|
||||||
// reads inline password, decrypts secret, signs and broadcasts.
|
// password modal, decrypts secret, signs and broadcasts.
|
||||||
|
|
||||||
const {
|
const {
|
||||||
parseEther,
|
parseEther,
|
||||||
@@ -14,12 +14,11 @@ const {
|
|||||||
showError,
|
showError,
|
||||||
hideError,
|
hideError,
|
||||||
showView,
|
showView,
|
||||||
showFlash,
|
|
||||||
addressTitle,
|
addressTitle,
|
||||||
addressDotHtml,
|
addressDotHtml,
|
||||||
escapeHtml,
|
escapeHtml,
|
||||||
} = require("./helpers");
|
} = require("./helpers");
|
||||||
const { state } = require("../../shared/state");
|
const { state, saveState } = require("../../shared/state");
|
||||||
const { getSignerForAddress } = require("../../shared/wallet");
|
const { getSignerForAddress } = require("../../shared/wallet");
|
||||||
const { decryptWithPassword } = require("../../shared/vault");
|
const { decryptWithPassword } = require("../../shared/vault");
|
||||||
const { formatUsd, getPrice } = require("../../shared/prices");
|
const { formatUsd, getPrice } = require("../../shared/prices");
|
||||||
@@ -39,13 +38,6 @@ const EXT_ICON =
|
|||||||
|
|
||||||
let pendingTx = null;
|
let pendingTx = null;
|
||||||
|
|
||||||
function restore() {
|
|
||||||
const d = state.viewData;
|
|
||||||
if (d && d.pendingTx) {
|
|
||||||
show(d.pendingTx);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function etherscanTokenLink(address) {
|
function etherscanTokenLink(address) {
|
||||||
return `https://etherscan.io/token/${address}`;
|
return `https://etherscan.io/token/${address}`;
|
||||||
}
|
}
|
||||||
@@ -103,22 +95,11 @@ function show(txInfo) {
|
|||||||
// Token contract section (ERC-20 only)
|
// Token contract section (ERC-20 only)
|
||||||
const tokenSection = $("confirm-token-section");
|
const tokenSection = $("confirm-token-section");
|
||||||
if (isErc20) {
|
if (isErc20) {
|
||||||
const dot = addressDotHtml(txInfo.token);
|
|
||||||
const link = etherscanTokenLink(txInfo.token);
|
const link = etherscanTokenLink(txInfo.token);
|
||||||
$("confirm-token-contract").innerHTML =
|
$("confirm-token-contract").innerHTML =
|
||||||
`<div class="flex items-center">${dot}` +
|
escapeHtml(txInfo.token) +
|
||||||
`<span class="break-all underline decoration-dashed cursor-pointer" data-copy="${escapeHtml(txInfo.token)}">${escapeHtml(txInfo.token)}</span>` +
|
` <a href="${link}" target="_blank" rel="noopener" class="inline-flex items-center">${EXT_ICON}</a>`;
|
||||||
`<a href="${link}" target="_blank" rel="noopener" class="inline-flex items-center">${EXT_ICON}</a>` +
|
|
||||||
`</div>`;
|
|
||||||
tokenSection.classList.remove("hidden");
|
tokenSection.classList.remove("hidden");
|
||||||
// Attach click-to-copy on the contract address
|
|
||||||
const copyEl = tokenSection.querySelector("[data-copy]");
|
|
||||||
if (copyEl) {
|
|
||||||
copyEl.onclick = () => {
|
|
||||||
navigator.clipboard.writeText(copyEl.dataset.copy);
|
|
||||||
showFlash("Copied!");
|
|
||||||
};
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
tokenSection.classList.add("hidden");
|
tokenSection.classList.add("hidden");
|
||||||
}
|
}
|
||||||
@@ -233,24 +214,16 @@ function show(txInfo) {
|
|||||||
sendBtn.classList.remove("text-muted");
|
sendBtn.classList.remove("text-muted");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset password field and error
|
|
||||||
$("confirm-tx-password").value = "";
|
|
||||||
hideError("confirm-tx-password-error");
|
|
||||||
|
|
||||||
// Gas estimate — show placeholder then fetch async
|
// Gas estimate — show placeholder then fetch async
|
||||||
$("confirm-fee").classList.remove("hidden");
|
$("confirm-fee").classList.remove("hidden");
|
||||||
$("confirm-fee-amount").textContent = "Estimating...";
|
$("confirm-fee-amount").textContent = "Estimating...";
|
||||||
state.viewData = { pendingTx: txInfo };
|
|
||||||
showView("confirm-tx");
|
showView("confirm-tx");
|
||||||
|
|
||||||
// Reset recipient warning: reserve space (visibility:hidden) while
|
// Persist txInfo so the view survives popup close/reopen
|
||||||
// the async check runs, preventing layout shift per README policy.
|
state.viewData = { pendingTx: txInfo };
|
||||||
const recipientWarning = $("confirm-recipient-warning");
|
saveState();
|
||||||
recipientWarning.style.display = "";
|
|
||||||
recipientWarning.style.visibility = "hidden";
|
|
||||||
|
|
||||||
estimateGas(txInfo);
|
estimateGas(txInfo);
|
||||||
checkRecipientHistory(txInfo);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function estimateGas(txInfo) {
|
async function estimateGas(txInfo) {
|
||||||
@@ -293,48 +266,39 @@ async function estimateGas(txInfo) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function checkRecipientHistory(txInfo) {
|
function showPasswordModal() {
|
||||||
const el = $("confirm-recipient-warning");
|
$("modal-password").value = "";
|
||||||
try {
|
hideError("modal-password-error");
|
||||||
const provider = getProvider(state.rpcUrl);
|
$("password-modal").classList.remove("hidden");
|
||||||
// Skip warning for contract addresses — they may legitimately
|
}
|
||||||
// have zero outgoing transactions (getTransactionCount returns
|
|
||||||
// the nonce, i.e. sent-tx count only).
|
function hidePasswordModal() {
|
||||||
const code = await provider.getCode(txInfo.to);
|
$("password-modal").classList.add("hidden");
|
||||||
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", () => {
|
||||||
const password = $("confirm-tx-password").value;
|
showPasswordModal();
|
||||||
|
});
|
||||||
|
|
||||||
|
$("btn-confirm-back").addEventListener("click", () => {
|
||||||
|
showView("send");
|
||||||
|
});
|
||||||
|
|
||||||
|
$("btn-modal-cancel").addEventListener("click", () => {
|
||||||
|
hidePasswordModal();
|
||||||
|
});
|
||||||
|
|
||||||
|
$("btn-modal-confirm").addEventListener("click", async () => {
|
||||||
|
const password = $("modal-password").value;
|
||||||
if (!password) {
|
if (!password) {
|
||||||
showError(
|
showError("modal-password-error", "Please enter your password.");
|
||||||
"confirm-tx-password-error",
|
|
||||||
"Please enter your password.",
|
|
||||||
);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const wallet = state.wallets[state.selectedWallet];
|
const wallet = state.wallets[state.selectedWallet];
|
||||||
let decryptedSecret;
|
let decryptedSecret;
|
||||||
hideError("confirm-tx-password-error");
|
hideError("modal-password-error");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
decryptedSecret = await decryptWithPassword(
|
decryptedSecret = await decryptWithPassword(
|
||||||
@@ -342,12 +306,11 @@ function init(ctx) {
|
|||||||
password,
|
password,
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
showError("confirm-tx-password-error", "Wrong password.");
|
showError("modal-password-error", "Wrong password.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$("btn-confirm-send").disabled = true;
|
hidePasswordModal();
|
||||||
$("btn-confirm-send").classList.add("text-muted");
|
|
||||||
|
|
||||||
let tx;
|
let tx;
|
||||||
try {
|
try {
|
||||||
@@ -384,15 +347,8 @@ function init(ctx) {
|
|||||||
decryptedSecret = null;
|
decryptedSecret = null;
|
||||||
const hash = tx ? tx.hash : null;
|
const hash = tx ? tx.hash : null;
|
||||||
txStatus.showError(pendingTx, hash, e.shortMessage || e.message);
|
txStatus.showError(pendingTx, hash, e.shortMessage || e.message);
|
||||||
} finally {
|
|
||||||
$("btn-confirm-send").disabled = false;
|
|
||||||
$("btn-confirm-send").classList.remove("text-muted");
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$("btn-confirm-back").addEventListener("click", () => {
|
|
||||||
showView("send");
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { init, show, restore };
|
module.exports = { init, show };
|
||||||
|
|||||||
@@ -40,10 +40,6 @@ function init(_ctx) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const btn = $("btn-delete-wallet-confirm");
|
|
||||||
btn.disabled = true;
|
|
||||||
btn.classList.add("text-muted");
|
|
||||||
|
|
||||||
const walletIdx = deleteWalletIndex;
|
const walletIdx = deleteWalletIndex;
|
||||||
const wallet = state.wallets[walletIdx];
|
const wallet = state.wallets[walletIdx];
|
||||||
|
|
||||||
@@ -53,8 +49,6 @@ function init(_ctx) {
|
|||||||
} catch (_e) {
|
} catch (_e) {
|
||||||
$("delete-wallet-flash").textContent = "Wrong password.";
|
$("delete-wallet-flash").textContent = "Wrong password.";
|
||||||
$("delete-wallet-flash").classList.remove("hidden");
|
$("delete-wallet-flash").classList.remove("hidden");
|
||||||
btn.disabled = false;
|
|
||||||
btn.classList.remove("text-muted");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,11 +11,7 @@ const {
|
|||||||
truncateMiddle,
|
truncateMiddle,
|
||||||
} = require("./helpers");
|
} = require("./helpers");
|
||||||
const { state, saveState, currentAddress } = require("../../shared/state");
|
const { state, saveState, currentAddress } = require("../../shared/state");
|
||||||
const {
|
const { updateSendBalance, renderSendTokenSelect } = require("./send");
|
||||||
updateSendBalance,
|
|
||||||
renderSendTokenSelect,
|
|
||||||
resetSendValidation,
|
|
||||||
} = require("./send");
|
|
||||||
const { deriveAddressFromXpub } = require("../../shared/wallet");
|
const { deriveAddressFromXpub } = require("../../shared/wallet");
|
||||||
const {
|
const {
|
||||||
formatUsd,
|
formatUsd,
|
||||||
@@ -392,7 +388,6 @@ function init(ctx) {
|
|||||||
$("send-token-static").classList.add("hidden");
|
$("send-token-static").classList.add("hidden");
|
||||||
renderSendTokenSelect(addr);
|
renderSendTokenSelect(addr);
|
||||||
updateSendBalance();
|
updateSendBalance();
|
||||||
resetSendValidation();
|
|
||||||
showView("send");
|
showView("send");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -11,107 +11,6 @@ const { state, currentAddress } = require("../../shared/state");
|
|||||||
let ctx;
|
let ctx;
|
||||||
const { getProvider } = require("../../shared/balances");
|
const { getProvider } = require("../../shared/balances");
|
||||||
const { KNOWN_SYMBOLS, resolveSymbol } = require("../../shared/tokenList");
|
const { KNOWN_SYMBOLS, resolveSymbol } = require("../../shared/tokenList");
|
||||||
const { getAddress } = require("ethers");
|
|
||||||
|
|
||||||
const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Validate a destination address string.
|
|
||||||
* Returns { valid: true } or { valid: false, error: "..." }.
|
|
||||||
*/
|
|
||||||
function validateToAddress(value) {
|
|
||||||
const v = value.trim();
|
|
||||||
if (!v) return { valid: false, error: "" };
|
|
||||||
|
|
||||||
// ENS names: contains a dot and doesn't start with 0x
|
|
||||||
if (v.includes(".") && !v.startsWith("0x")) {
|
|
||||||
// Basic ENS format check: at least one label before and after dot
|
|
||||||
if (/^[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)+$/.test(v)) {
|
|
||||||
return { valid: true };
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
valid: false,
|
|
||||||
error: "Please enter a valid ENS name.",
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// Must look like an Ethereum address
|
|
||||||
if (!/^0x[0-9a-fA-F]{40}$/.test(v)) {
|
|
||||||
return {
|
|
||||||
valid: false,
|
|
||||||
error: "Please enter a valid Ethereum address.",
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reject zero address
|
|
||||||
if (v.toLowerCase() === ZERO_ADDRESS) {
|
|
||||||
return {
|
|
||||||
valid: false,
|
|
||||||
error: "Sending to the zero address is not allowed.",
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// EIP-55 checksum validation: all-lowercase is ok, otherwise must match checksum
|
|
||||||
if (v !== v.toLowerCase()) {
|
|
||||||
try {
|
|
||||||
const checksummed = getAddress(v);
|
|
||||||
if (checksummed !== v) {
|
|
||||||
return {
|
|
||||||
valid: false,
|
|
||||||
error: "Address checksum is invalid. Please double-check the address.",
|
|
||||||
};
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
return {
|
|
||||||
valid: false,
|
|
||||||
error: "Address checksum is invalid. Please double-check the address.",
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Warn if sending to own address
|
|
||||||
const addr = currentAddress();
|
|
||||||
if (addr && v.toLowerCase() === addr.address.toLowerCase()) {
|
|
||||||
// Allow but will warn — we return valid with a warning
|
|
||||||
return {
|
|
||||||
valid: true,
|
|
||||||
warning: "This is your own address. Are you sure?",
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return { valid: true };
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateToValidation() {
|
|
||||||
const input = $("send-to");
|
|
||||||
const errorEl = $("send-to-error");
|
|
||||||
const btn = $("btn-send-review");
|
|
||||||
const value = input.value.trim();
|
|
||||||
|
|
||||||
if (!value) {
|
|
||||||
errorEl.textContent = "";
|
|
||||||
btn.disabled = true;
|
|
||||||
btn.classList.add("opacity-50");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = validateToAddress(value);
|
|
||||||
if (!result.valid) {
|
|
||||||
errorEl.textContent = result.error;
|
|
||||||
errorEl.style.color = "#cc0000";
|
|
||||||
btn.disabled = true;
|
|
||||||
btn.classList.add("opacity-50");
|
|
||||||
} else if (result.warning) {
|
|
||||||
errorEl.textContent = result.warning;
|
|
||||||
errorEl.style.color = "#b8860b";
|
|
||||||
btn.disabled = false;
|
|
||||||
btn.classList.remove("opacity-50");
|
|
||||||
} else {
|
|
||||||
errorEl.textContent = "";
|
|
||||||
btn.disabled = false;
|
|
||||||
btn.classList.remove("opacity-50");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const EXT_ICON =
|
const EXT_ICON =
|
||||||
`<span style="display:inline-block;width:10px;height:10px;margin-left:4px;vertical-align:middle">` +
|
`<span style="display:inline-block;width:10px;height:10px;margin-left:4px;vertical-align:middle">` +
|
||||||
@@ -189,13 +88,6 @@ function init(_ctx) {
|
|||||||
ctx = _ctx;
|
ctx = _ctx;
|
||||||
$("send-token").addEventListener("change", updateSendBalance);
|
$("send-token").addEventListener("change", updateSendBalance);
|
||||||
|
|
||||||
// Initial state: disable review button until address is entered
|
|
||||||
$("btn-send-review").disabled = true;
|
|
||||||
$("btn-send-review").classList.add("opacity-50");
|
|
||||||
|
|
||||||
// Validate address on input
|
|
||||||
$("send-to").addEventListener("input", updateToValidation);
|
|
||||||
|
|
||||||
$("btn-send-review").addEventListener("click", async () => {
|
$("btn-send-review").addEventListener("click", async () => {
|
||||||
const to = $("send-to").value.trim();
|
const to = $("send-to").value.trim();
|
||||||
const amount = $("send-amount").value.trim();
|
const amount = $("send-amount").value.trim();
|
||||||
@@ -203,15 +95,6 @@ function init(_ctx) {
|
|||||||
showFlash("Please enter a recipient address.");
|
showFlash("Please enter a recipient address.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Re-validate before proceeding
|
|
||||||
const validation = validateToAddress(to);
|
|
||||||
if (!validation.valid) {
|
|
||||||
showFlash(
|
|
||||||
validation.error || "Please enter a valid Ethereum address.",
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!amount || isNaN(parseFloat(amount)) || parseFloat(amount) <= 0) {
|
if (!amount || isNaN(parseFloat(amount)) || parseFloat(amount) <= 0) {
|
||||||
showFlash("Please enter a valid amount.");
|
showFlash("Please enter a valid amount.");
|
||||||
return;
|
return;
|
||||||
@@ -276,19 +159,4 @@ function init(_ctx) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function resetSendValidation() {
|
module.exports = { init, updateSendBalance, renderSendTokenSelect };
|
||||||
const errorEl = $("send-to-error");
|
|
||||||
const btn = $("btn-send-review");
|
|
||||||
if (errorEl) errorEl.textContent = "";
|
|
||||||
if (btn) {
|
|
||||||
btn.disabled = true;
|
|
||||||
btn.classList.add("opacity-50");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
init,
|
|
||||||
updateSendBalance,
|
|
||||||
renderSendTokenSelect,
|
|
||||||
resetSendValidation,
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -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) {
|
||||||
|
|||||||
@@ -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