Compare commits
1 Commits
fix/116-ti
...
c8d1f96770
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c8d1f96770 |
@@ -56,37 +56,9 @@
|
|||||||
< Back
|
< Back
|
||||||
</button>
|
</button>
|
||||||
<h2 class="font-bold mb-2">Add Wallet</h2>
|
<h2 class="font-bold mb-2">Add Wallet</h2>
|
||||||
|
|
||||||
<!-- Mode selector tabs -->
|
|
||||||
<div
|
|
||||||
class="flex border-b border-border mb-3"
|
|
||||||
id="add-wallet-tabs"
|
|
||||||
>
|
|
||||||
<button
|
|
||||||
id="tab-mnemonic"
|
|
||||||
class="px-3 py-1.5 cursor-pointer text-xs font-bold border border-border border-b-bg bg-bg -mb-px"
|
|
||||||
>
|
|
||||||
From Phrase
|
|
||||||
</button>
|
|
||||||
<button
|
|
||||||
id="tab-privkey"
|
|
||||||
class="px-3 py-1.5 cursor-pointer text-xs text-muted border border-dashed border-border-light border-b-transparent -mb-px hover:bg-fg hover:text-bg"
|
|
||||||
>
|
|
||||||
From Key
|
|
||||||
</button>
|
|
||||||
<button
|
|
||||||
id="tab-xprv"
|
|
||||||
class="px-3 py-1.5 cursor-pointer text-xs text-muted border border-dashed border-border-light border-b-transparent -mb-px hover:bg-fg hover:text-bg"
|
|
||||||
>
|
|
||||||
From xprv
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Mnemonic form section -->
|
|
||||||
<div id="add-wallet-section-mnemonic">
|
|
||||||
<p class="mb-2">
|
<p class="mb-2">
|
||||||
Enter your 12 or 24 word recovery phrase below, or click
|
Enter your 12 or 24 word recovery phrase below, or click the
|
||||||
the button to roll the die for a new one.
|
button to roll the die for a new one.
|
||||||
</p>
|
</p>
|
||||||
<div class="mb-1 flex justify-end">
|
<div class="mb-1 flex justify-end">
|
||||||
<button
|
<button
|
||||||
@@ -109,51 +81,12 @@
|
|||||||
id="add-wallet-phrase-warning"
|
id="add-wallet-phrase-warning"
|
||||||
class="text-xs mb-2 border border-border border-dashed p-2 hidden"
|
class="text-xs mb-2 border border-border border-dashed p-2 hidden"
|
||||||
>
|
>
|
||||||
Write these words down and keep them safe. Anyone with
|
Write these words down and keep them safe. Anyone with them
|
||||||
them can take your funds; if you lose them, your wallet
|
can take your funds; if you lose them, your wallet is gone.
|
||||||
is gone.
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Private key form section -->
|
|
||||||
<div id="add-wallet-section-privkey" class="hidden">
|
|
||||||
<p class="mb-2">
|
|
||||||
Paste your private key below. This wallet will have a
|
|
||||||
single address.
|
|
||||||
</p>
|
|
||||||
<div class="mb-2">
|
|
||||||
<input
|
|
||||||
type="password"
|
|
||||||
id="import-private-key"
|
|
||||||
class="border border-border p-1 w-full font-mono text-sm bg-bg text-fg"
|
|
||||||
placeholder="0x..."
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Extended key (xprv) form section -->
|
|
||||||
<div id="add-wallet-section-xprv" class="hidden">
|
|
||||||
<p class="mb-2">
|
|
||||||
Paste your extended private key (xprv) below. This will
|
|
||||||
import the HD wallet and scan for used addresses.
|
|
||||||
</p>
|
|
||||||
<div class="mb-2">
|
|
||||||
<input
|
|
||||||
type="password"
|
|
||||||
id="import-xprv-key"
|
|
||||||
class="border border-border p-1 w-full font-mono text-sm bg-bg text-fg"
|
|
||||||
placeholder="xprv..."
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Shared password fields -->
|
|
||||||
<div class="mb-2" id="add-wallet-password-section">
|
<div class="mb-2" id="add-wallet-password-section">
|
||||||
<label class="block mb-1">Choose a password</label>
|
<label class="block mb-1">Choose a password</label>
|
||||||
<p
|
<p class="text-xs text-muted mb-1">
|
||||||
class="text-xs text-muted mb-1"
|
|
||||||
id="add-wallet-password-hint"
|
|
||||||
>
|
|
||||||
This password encrypts your recovery phrase on this
|
This password encrypts your recovery phrase on this
|
||||||
device. You will need it to send funds.
|
device. You will need it to send funds.
|
||||||
</p>
|
</p>
|
||||||
@@ -174,6 +107,64 @@
|
|||||||
<button
|
<button
|
||||||
id="btn-add-wallet-confirm"
|
id="btn-add-wallet-confirm"
|
||||||
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"
|
||||||
|
>
|
||||||
|
Add
|
||||||
|
</button>
|
||||||
|
<div class="mt-3 text-xs text-muted">
|
||||||
|
Have a private key instead?
|
||||||
|
<button
|
||||||
|
id="btn-add-wallet-import-key"
|
||||||
|
class="underline cursor-pointer bg-transparent border-none text-fg text-xs font-mono p-0"
|
||||||
|
>
|
||||||
|
Import private key
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- ============ IMPORT PRIVATE KEY ============ -->
|
||||||
|
<div id="view-import-key" class="view hidden">
|
||||||
|
<button
|
||||||
|
id="btn-import-key-back"
|
||||||
|
class="border border-border px-2 py-1 hover:bg-fg hover:text-bg cursor-pointer mb-2"
|
||||||
|
>
|
||||||
|
< Back
|
||||||
|
</button>
|
||||||
|
<h2 class="font-bold mb-2">Import Private Key</h2>
|
||||||
|
<p class="mb-2">
|
||||||
|
Paste your private key below. This wallet will have a single
|
||||||
|
address.
|
||||||
|
</p>
|
||||||
|
<div class="mb-2">
|
||||||
|
<input
|
||||||
|
type="password"
|
||||||
|
id="import-private-key"
|
||||||
|
class="border border-border p-1 w-full font-mono text-sm bg-bg text-fg"
|
||||||
|
placeholder="0x..."
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div class="mb-2" id="import-key-password-section">
|
||||||
|
<label class="block mb-1">Choose a password</label>
|
||||||
|
<p class="text-xs text-muted mb-1">
|
||||||
|
This password encrypts your private key on this device.
|
||||||
|
You will need it to send funds.
|
||||||
|
</p>
|
||||||
|
<input
|
||||||
|
type="password"
|
||||||
|
id="import-key-password"
|
||||||
|
class="border border-border p-1 w-full font-mono text-sm bg-bg text-fg"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div class="mb-2" id="import-key-password-confirm-section">
|
||||||
|
<label class="block mb-1">Confirm password</label>
|
||||||
|
<input
|
||||||
|
type="password"
|
||||||
|
id="import-key-password-confirm"
|
||||||
|
class="border border-border p-1 w-full font-mono text-sm bg-bg text-fg"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<button
|
||||||
|
id="btn-import-key-confirm"
|
||||||
|
class="border border-border px-2 py-1 hover:bg-fg hover:text-bg cursor-pointer"
|
||||||
>
|
>
|
||||||
Import
|
Import
|
||||||
</button>
|
</button>
|
||||||
@@ -586,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"
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ const { $, showView } = require("./views/helpers");
|
|||||||
const home = require("./views/home");
|
const home = require("./views/home");
|
||||||
const welcome = require("./views/welcome");
|
const welcome = require("./views/welcome");
|
||||||
const addWallet = require("./views/addWallet");
|
const addWallet = require("./views/addWallet");
|
||||||
|
const importKey = require("./views/importKey");
|
||||||
const addressDetail = require("./views/addressDetail");
|
const addressDetail = require("./views/addressDetail");
|
||||||
const addressToken = require("./views/addressToken");
|
const addressToken = require("./views/addressToken");
|
||||||
const send = require("./views/send");
|
const send = require("./views/send");
|
||||||
@@ -53,6 +54,7 @@ const ctx = {
|
|||||||
renderWalletList,
|
renderWalletList,
|
||||||
doRefreshAndRender,
|
doRefreshAndRender,
|
||||||
showAddWalletView: () => addWallet.show(),
|
showAddWalletView: () => addWallet.show(),
|
||||||
|
showImportKeyView: () => importKey.show(),
|
||||||
showAddressDetail: () => addressDetail.show(),
|
showAddressDetail: () => addressDetail.show(),
|
||||||
showAddressToken: () => addressToken.show(),
|
showAddressToken: () => addressToken.show(),
|
||||||
showAddTokenView: () => addToken.show(),
|
showAddTokenView: () => addToken.show(),
|
||||||
@@ -215,6 +217,7 @@ async function init() {
|
|||||||
|
|
||||||
welcome.init(ctx);
|
welcome.init(ctx);
|
||||||
addWallet.init(ctx);
|
addWallet.init(ctx);
|
||||||
|
importKey.init(ctx);
|
||||||
home.init(ctx);
|
home.init(ctx);
|
||||||
addressDetail.init(ctx);
|
addressDetail.init(ctx);
|
||||||
addressToken.init(ctx);
|
addressToken.init(ctx);
|
||||||
|
|||||||
@@ -19,16 +19,3 @@ body {
|
|||||||
width: 396px;
|
width: 396px;
|
||||||
overflow-x: hidden;
|
overflow-x: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Copy-flash feedback: inverts colors then fades back */
|
|
||||||
.copy-flash-active {
|
|
||||||
background-color: var(--color-fg) !important;
|
|
||||||
color: var(--color-bg) !important;
|
|
||||||
transition: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.copy-flash-fade {
|
|
||||||
transition:
|
|
||||||
background-color 300ms ease-out,
|
|
||||||
color 300ms ease-out;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -3,101 +3,31 @@ const {
|
|||||||
generateMnemonic,
|
generateMnemonic,
|
||||||
hdWalletFromMnemonic,
|
hdWalletFromMnemonic,
|
||||||
isValidMnemonic,
|
isValidMnemonic,
|
||||||
addressFromPrivateKey,
|
|
||||||
hdWalletFromXprv,
|
|
||||||
isValidXprv,
|
|
||||||
} = require("../../shared/wallet");
|
} = require("../../shared/wallet");
|
||||||
const { encryptWithPassword } = require("../../shared/vault");
|
const { encryptWithPassword } = require("../../shared/vault");
|
||||||
const { state, saveState } = require("../../shared/state");
|
const { state, saveState } = require("../../shared/state");
|
||||||
const { scanForAddresses } = require("../../shared/balances");
|
const { scanForAddresses } = require("../../shared/balances");
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if an address already exists in ANY wallet (hd, xprv, or key).
|
|
||||||
* Returns the wallet object if found, or undefined.
|
|
||||||
*/
|
|
||||||
function findWalletByAddress(addr) {
|
|
||||||
const lower = addr.toLowerCase();
|
|
||||||
return state.wallets.find((w) =>
|
|
||||||
w.addresses.some((a) => a.address.toLowerCase() === lower),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if an xpub already exists in any HD-type wallet (hd or xprv).
|
|
||||||
* Returns the wallet object if found, or undefined.
|
|
||||||
*/
|
|
||||||
function findWalletByXpub(xpub) {
|
|
||||||
return state.wallets.find((w) => w.xpub && w.xpub === xpub);
|
|
||||||
}
|
|
||||||
|
|
||||||
let currentMode = "mnemonic";
|
|
||||||
|
|
||||||
const MODES = ["mnemonic", "privkey", "xprv"];
|
|
||||||
|
|
||||||
const PASSWORD_HINTS = {
|
|
||||||
mnemonic:
|
|
||||||
"This password encrypts your recovery phrase on this device. You will need it to send funds.",
|
|
||||||
privkey:
|
|
||||||
"This password encrypts your private key on this device. You will need it to send funds.",
|
|
||||||
xprv: "This password encrypts your key on this device. You will need it to send funds.",
|
|
||||||
};
|
|
||||||
|
|
||||||
function switchMode(mode) {
|
|
||||||
currentMode = mode;
|
|
||||||
for (const m of MODES) {
|
|
||||||
$("add-wallet-section-" + m).classList.toggle("hidden", m !== mode);
|
|
||||||
const tab = $("tab-" + m);
|
|
||||||
const isActive = m === mode;
|
|
||||||
// Active: bold, solid border on top/sides, no bottom border (connects to content)
|
|
||||||
tab.classList.toggle("font-bold", isActive);
|
|
||||||
tab.classList.toggle("border-solid", isActive);
|
|
||||||
tab.classList.toggle("border-border", isActive);
|
|
||||||
tab.classList.toggle("border-b-bg", isActive);
|
|
||||||
tab.classList.toggle("bg-bg", isActive);
|
|
||||||
// Inactive: muted text, dashed border on top/sides, transparent bottom, hover invert
|
|
||||||
tab.classList.toggle("text-muted", !isActive);
|
|
||||||
tab.classList.toggle("border-dashed", !isActive);
|
|
||||||
tab.classList.toggle("border-border-light", !isActive);
|
|
||||||
tab.classList.toggle("border-b-transparent", !isActive);
|
|
||||||
tab.classList.toggle("hover:bg-fg", !isActive);
|
|
||||||
tab.classList.toggle("hover:text-bg", !isActive);
|
|
||||||
}
|
|
||||||
$("add-wallet-password-hint").textContent = PASSWORD_HINTS[mode];
|
|
||||||
}
|
|
||||||
|
|
||||||
function show() {
|
function show() {
|
||||||
$("wallet-mnemonic").value = "";
|
$("wallet-mnemonic").value = "";
|
||||||
$("import-private-key").value = "";
|
|
||||||
$("import-xprv-key").value = "";
|
|
||||||
$("add-wallet-password").value = "";
|
$("add-wallet-password").value = "";
|
||||||
$("add-wallet-password-confirm").value = "";
|
$("add-wallet-password-confirm").value = "";
|
||||||
$("add-wallet-phrase-warning").classList.add("hidden");
|
$("add-wallet-phrase-warning").classList.add("hidden");
|
||||||
switchMode("mnemonic");
|
|
||||||
showView("add-wallet");
|
showView("add-wallet");
|
||||||
}
|
}
|
||||||
|
|
||||||
function validatePassword() {
|
function init(ctx) {
|
||||||
const pw = $("add-wallet-password").value;
|
$("btn-generate-phrase").addEventListener("click", () => {
|
||||||
const pw2 = $("add-wallet-password-confirm").value;
|
$("wallet-mnemonic").value = generateMnemonic();
|
||||||
if (!pw) {
|
$("add-wallet-phrase-warning").classList.remove("hidden");
|
||||||
showFlash("Please choose a password.");
|
});
|
||||||
return null;
|
|
||||||
}
|
|
||||||
if (pw.length < 12) {
|
|
||||||
showFlash("Password must be at least 12 characters.");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
if (pw !== pw2) {
|
|
||||||
showFlash("Passwords do not match.");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return pw;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function importMnemonic(ctx) {
|
$("btn-add-wallet-confirm").addEventListener("click", async () => {
|
||||||
const mnemonic = $("wallet-mnemonic").value.trim();
|
const mnemonic = $("wallet-mnemonic").value.trim();
|
||||||
if (!mnemonic) {
|
if (!mnemonic) {
|
||||||
showFlash("Enter a recovery phrase or press the die to generate one.");
|
showFlash(
|
||||||
|
"Enter a recovery phrase or press the die to generate one.",
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const words = mnemonic.split(/\s+/);
|
const words = mnemonic.split(/\s+/);
|
||||||
@@ -113,19 +43,34 @@ async function importMnemonic(ctx) {
|
|||||||
showFlash("Invalid recovery phrase. Check for typos.");
|
showFlash("Invalid recovery phrase. Check for typos.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const pw = validatePassword();
|
const pw = $("add-wallet-password").value;
|
||||||
if (!pw) return;
|
const pw2 = $("add-wallet-password-confirm").value;
|
||||||
const { xpub, firstAddress } = hdWalletFromMnemonic(mnemonic);
|
if (!pw) {
|
||||||
const xpubDup = findWalletByXpub(xpub);
|
showFlash("Please choose a password.");
|
||||||
if (xpubDup) {
|
|
||||||
showFlash(
|
|
||||||
"This recovery phrase is already added (" + xpubDup.name + ").",
|
|
||||||
);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const addrDup = findWalletByAddress(firstAddress);
|
if (pw.length < 12) {
|
||||||
if (addrDup) {
|
showFlash("Password must be at least 12 characters.");
|
||||||
showFlash("Address already exists in wallet (" + addrDup.name + ").");
|
return;
|
||||||
|
}
|
||||||
|
if (pw !== pw2) {
|
||||||
|
showFlash("Passwords do not match.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const { xpub, firstAddress } = hdWalletFromMnemonic(mnemonic);
|
||||||
|
const duplicate = state.wallets.find(
|
||||||
|
(w) =>
|
||||||
|
w.type === "hd" &&
|
||||||
|
w.addresses[0] &&
|
||||||
|
w.addresses[0].address.toLowerCase() ===
|
||||||
|
firstAddress.toLowerCase(),
|
||||||
|
);
|
||||||
|
if (duplicate) {
|
||||||
|
showFlash(
|
||||||
|
"This recovery phrase is already added (" +
|
||||||
|
duplicate.name +
|
||||||
|
").",
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const encrypted = await encryptWithPassword(mnemonic, pw);
|
const encrypted = await encryptWithPassword(mnemonic, pw);
|
||||||
@@ -164,138 +109,8 @@ async function importMnemonic(ctx) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ctx.doRefreshAndRender();
|
ctx.doRefreshAndRender();
|
||||||
}
|
|
||||||
|
|
||||||
async function importPrivateKey(ctx) {
|
|
||||||
const key = $("import-private-key").value.trim();
|
|
||||||
if (!key) {
|
|
||||||
showFlash("Please enter your private key.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let addr;
|
|
||||||
try {
|
|
||||||
addr = addressFromPrivateKey(key);
|
|
||||||
} catch (e) {
|
|
||||||
showFlash("Invalid private key.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const pw = validatePassword();
|
|
||||||
if (!pw) return;
|
|
||||||
const duplicate = findWalletByAddress(addr);
|
|
||||||
if (duplicate) {
|
|
||||||
showFlash(
|
|
||||||
"This address already exists in wallet (" + duplicate.name + ").",
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const encrypted = await encryptWithPassword(key, pw);
|
|
||||||
const walletNum = state.wallets.length + 1;
|
|
||||||
state.wallets.push({
|
|
||||||
type: "key",
|
|
||||||
name: "Wallet " + walletNum,
|
|
||||||
encryptedSecret: encrypted,
|
|
||||||
addresses: [{ address: addr, balance: "0.0000", tokenBalances: [] }],
|
|
||||||
});
|
|
||||||
state.hasWallet = true;
|
|
||||||
await saveState();
|
|
||||||
ctx.renderWalletList();
|
|
||||||
showView("main");
|
|
||||||
|
|
||||||
ctx.doRefreshAndRender();
|
|
||||||
}
|
|
||||||
|
|
||||||
async function importXprvKey(ctx) {
|
|
||||||
const xprv = $("import-xprv-key").value.trim();
|
|
||||||
if (!xprv) {
|
|
||||||
showFlash("Please enter your extended private key.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!isValidXprv(xprv)) {
|
|
||||||
showFlash("Invalid extended private key.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let result;
|
|
||||||
try {
|
|
||||||
result = hdWalletFromXprv(xprv);
|
|
||||||
} catch (e) {
|
|
||||||
showFlash("Invalid extended private key.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const { xpub, firstAddress } = result;
|
|
||||||
const xpubDup = findWalletByXpub(xpub);
|
|
||||||
if (xpubDup) {
|
|
||||||
showFlash("This key is already added (" + xpubDup.name + ").");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const addrDup = findWalletByAddress(firstAddress);
|
|
||||||
if (addrDup) {
|
|
||||||
showFlash("Address already exists in wallet (" + addrDup.name + ").");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const pw = validatePassword();
|
|
||||||
if (!pw) return;
|
|
||||||
const encrypted = await encryptWithPassword(xprv, pw);
|
|
||||||
const walletNum = state.wallets.length + 1;
|
|
||||||
const wallet = {
|
|
||||||
type: "xprv",
|
|
||||||
name: "Wallet " + walletNum,
|
|
||||||
xpub: xpub,
|
|
||||||
encryptedSecret: encrypted,
|
|
||||||
nextIndex: 1,
|
|
||||||
addresses: [
|
|
||||||
{ address: firstAddress, balance: "0.0000", tokenBalances: [] },
|
|
||||||
],
|
|
||||||
};
|
|
||||||
state.wallets.push(wallet);
|
|
||||||
state.hasWallet = true;
|
|
||||||
await saveState();
|
|
||||||
ctx.renderWalletList();
|
|
||||||
showView("main");
|
|
||||||
|
|
||||||
// Scan for used HD addresses beyond index 0.
|
|
||||||
showFlash("Scanning for addresses...", 30000);
|
|
||||||
const scan = await scanForAddresses(xpub, state.rpcUrl);
|
|
||||||
if (scan.addresses.length > 1) {
|
|
||||||
wallet.addresses = scan.addresses.map((a) => ({
|
|
||||||
address: a.address,
|
|
||||||
balance: "0.0000",
|
|
||||||
tokenBalances: [],
|
|
||||||
}));
|
|
||||||
wallet.nextIndex = scan.nextIndex;
|
|
||||||
await saveState();
|
|
||||||
ctx.renderWalletList();
|
|
||||||
showFlash("Found " + scan.addresses.length + " addresses.");
|
|
||||||
} else {
|
|
||||||
showFlash("Ready.", 1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx.doRefreshAndRender();
|
|
||||||
}
|
|
||||||
|
|
||||||
function init(ctx) {
|
|
||||||
// Tab click handlers
|
|
||||||
$("tab-mnemonic").addEventListener("click", () => switchMode("mnemonic"));
|
|
||||||
$("tab-privkey").addEventListener("click", () => switchMode("privkey"));
|
|
||||||
$("tab-xprv").addEventListener("click", () => switchMode("xprv"));
|
|
||||||
|
|
||||||
// Generate mnemonic
|
|
||||||
$("btn-generate-phrase").addEventListener("click", () => {
|
|
||||||
$("wallet-mnemonic").value = generateMnemonic();
|
|
||||||
$("add-wallet-phrase-warning").classList.remove("hidden");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Import / confirm
|
|
||||||
$("btn-add-wallet-confirm").addEventListener("click", async () => {
|
|
||||||
if (currentMode === "mnemonic") {
|
|
||||||
await importMnemonic(ctx);
|
|
||||||
} else if (currentMode === "privkey") {
|
|
||||||
await importPrivateKey(ctx);
|
|
||||||
} else if (currentMode === "xprv") {
|
|
||||||
await importXprvKey(ctx);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Back button
|
|
||||||
$("btn-add-wallet-back").addEventListener("click", () => {
|
$("btn-add-wallet-back").addEventListener("click", () => {
|
||||||
if (!state.hasWallet) {
|
if (!state.hasWallet) {
|
||||||
showView("welcome");
|
showView("welcome");
|
||||||
@@ -304,6 +119,11 @@ function init(ctx) {
|
|||||||
showView("main");
|
showView("main");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$("btn-add-wallet-import-key").addEventListener(
|
||||||
|
"click",
|
||||||
|
ctx.showImportKeyView,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { init, show };
|
module.exports = { init, show };
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ const {
|
|||||||
$,
|
$,
|
||||||
showView,
|
showView,
|
||||||
showFlash,
|
showFlash,
|
||||||
flashCopyFeedback,
|
|
||||||
balanceLinesForAddress,
|
balanceLinesForAddress,
|
||||||
addressDotHtml,
|
addressDotHtml,
|
||||||
addressTitle,
|
addressTitle,
|
||||||
@@ -95,10 +94,6 @@ function show() {
|
|||||||
function isoDate(timestamp) {
|
function isoDate(timestamp) {
|
||||||
const d = new Date(timestamp * 1000);
|
const d = new Date(timestamp * 1000);
|
||||||
const pad = (n) => String(n).padStart(2, "0");
|
const pad = (n) => String(n).padStart(2, "0");
|
||||||
const off = -d.getTimezoneOffset();
|
|
||||||
const sign = off >= 0 ? "+" : "-";
|
|
||||||
const absOff = Math.abs(off);
|
|
||||||
const tz = sign + pad(Math.floor(absOff / 60)) + ":" + pad(absOff % 60);
|
|
||||||
return (
|
return (
|
||||||
d.getFullYear() +
|
d.getFullYear() +
|
||||||
"-" +
|
"-" +
|
||||||
@@ -110,8 +105,7 @@ function isoDate(timestamp) {
|
|||||||
":" +
|
":" +
|
||||||
pad(d.getMinutes()) +
|
pad(d.getMinutes()) +
|
||||||
":" +
|
":" +
|
||||||
pad(d.getSeconds()) +
|
pad(d.getSeconds())
|
||||||
tz
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -247,7 +241,6 @@ function init(_ctx) {
|
|||||||
if (addr) {
|
if (addr) {
|
||||||
navigator.clipboard.writeText(addr);
|
navigator.clipboard.writeText(addr);
|
||||||
showFlash("Copied!");
|
showFlash("Copied!");
|
||||||
flashCopyFeedback($("address-full"));
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -365,7 +358,6 @@ function init(_ctx) {
|
|||||||
if (key) {
|
if (key) {
|
||||||
navigator.clipboard.writeText(key);
|
navigator.clipboard.writeText(key);
|
||||||
showFlash("Copied!");
|
showFlash("Copied!");
|
||||||
flashCopyFeedback($("export-privkey-value"));
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -374,7 +366,6 @@ function init(_ctx) {
|
|||||||
if (full) {
|
if (full) {
|
||||||
navigator.clipboard.writeText(full);
|
navigator.clipboard.writeText(full);
|
||||||
showFlash("Copied!");
|
showFlash("Copied!");
|
||||||
flashCopyFeedback($("export-privkey-address"));
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ const {
|
|||||||
$,
|
$,
|
||||||
showView,
|
showView,
|
||||||
showFlash,
|
showFlash,
|
||||||
flashCopyFeedback,
|
|
||||||
addressDotHtml,
|
addressDotHtml,
|
||||||
addressTitle,
|
addressTitle,
|
||||||
escapeHtml,
|
escapeHtml,
|
||||||
@@ -48,10 +47,6 @@ function etherscanAddressLink(address) {
|
|||||||
function isoDate(timestamp) {
|
function isoDate(timestamp) {
|
||||||
const d = new Date(timestamp * 1000);
|
const d = new Date(timestamp * 1000);
|
||||||
const pad = (n) => String(n).padStart(2, "0");
|
const pad = (n) => String(n).padStart(2, "0");
|
||||||
const off = -d.getTimezoneOffset();
|
|
||||||
const sign = off >= 0 ? "+" : "-";
|
|
||||||
const absOff = Math.abs(off);
|
|
||||||
const tz = sign + pad(Math.floor(absOff / 60)) + ":" + pad(absOff % 60);
|
|
||||||
return (
|
return (
|
||||||
d.getFullYear() +
|
d.getFullYear() +
|
||||||
"-" +
|
"-" +
|
||||||
@@ -63,8 +58,7 @@ function isoDate(timestamp) {
|
|||||||
":" +
|
":" +
|
||||||
pad(d.getMinutes()) +
|
pad(d.getMinutes()) +
|
||||||
":" +
|
":" +
|
||||||
pad(d.getSeconds()) +
|
pad(d.getSeconds())
|
||||||
tz
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -323,7 +317,6 @@ function init(_ctx) {
|
|||||||
if (addr) {
|
if (addr) {
|
||||||
navigator.clipboard.writeText(addr);
|
navigator.clipboard.writeText(addr);
|
||||||
showFlash("Copied!");
|
showFlash("Copied!");
|
||||||
flashCopyFeedback($("address-token-full"));
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -332,7 +325,6 @@ function init(_ctx) {
|
|||||||
if (copyEl) {
|
if (copyEl) {
|
||||||
navigator.clipboard.writeText(copyEl.dataset.copy);
|
navigator.clipboard.writeText(copyEl.dataset.copy);
|
||||||
showFlash("Copied!");
|
showFlash("Copied!");
|
||||||
flashCopyFeedback(copyEl);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -381,7 +373,6 @@ function init(_ctx) {
|
|||||||
copyEl.addEventListener("click", () => {
|
copyEl.addEventListener("click", () => {
|
||||||
navigator.clipboard.writeText(copyEl.dataset.copy);
|
navigator.clipboard.writeText(copyEl.dataset.copy);
|
||||||
showFlash("Copied!");
|
showFlash("Copied!");
|
||||||
flashCopyFeedback(copyEl);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
updateSendBalance();
|
updateSendBalance();
|
||||||
|
|||||||
@@ -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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ const {
|
|||||||
hideError,
|
hideError,
|
||||||
showView,
|
showView,
|
||||||
showFlash,
|
showFlash,
|
||||||
flashCopyFeedback,
|
|
||||||
addressTitle,
|
addressTitle,
|
||||||
addressDotHtml,
|
addressDotHtml,
|
||||||
escapeHtml,
|
escapeHtml,
|
||||||
@@ -118,7 +117,6 @@ function show(txInfo) {
|
|||||||
copyEl.onclick = () => {
|
copyEl.onclick = () => {
|
||||||
navigator.clipboard.writeText(copyEl.dataset.copy);
|
navigator.clipboard.writeText(copyEl.dataset.copy);
|
||||||
showFlash("Copied!");
|
showFlash("Copied!");
|
||||||
flashCopyFeedback(copyEl);
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -245,9 +243,6 @@ function show(txInfo) {
|
|||||||
state.viewData = { pendingTx: txInfo };
|
state.viewData = { pendingTx: txInfo };
|
||||||
showView("confirm-tx");
|
showView("confirm-tx");
|
||||||
|
|
||||||
// Reset recipient warning to hidden (space always reserved, no layout shift)
|
|
||||||
$("confirm-recipient-warning").style.visibility = "hidden";
|
|
||||||
|
|
||||||
estimateGas(txInfo);
|
estimateGas(txInfo);
|
||||||
checkRecipientHistory(txInfo);
|
checkRecipientHistory(txInfo);
|
||||||
}
|
}
|
||||||
@@ -293,19 +288,21 @@ async function estimateGas(txInfo) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function checkRecipientHistory(txInfo) {
|
async function checkRecipientHistory(txInfo) {
|
||||||
const el = $("confirm-recipient-warning");
|
|
||||||
try {
|
try {
|
||||||
const provider = getProvider(state.rpcUrl);
|
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") {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const txCount = await provider.getTransactionCount(txInfo.to);
|
const txCount = await provider.getTransactionCount(txInfo.to);
|
||||||
if (txCount === 0) {
|
if (txCount === 0) {
|
||||||
el.style.visibility = "visible";
|
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) {
|
} catch (e) {
|
||||||
log.errorf("recipient history check failed:", e.message);
|
log.errorf("recipient history check failed:", e.message);
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ const { state, saveState } = require("../../shared/state");
|
|||||||
const VIEWS = [
|
const VIEWS = [
|
||||||
"welcome",
|
"welcome",
|
||||||
"add-wallet",
|
"add-wallet",
|
||||||
|
"import-key",
|
||||||
"main",
|
"main",
|
||||||
"address",
|
"address",
|
||||||
"address-token",
|
"address-token",
|
||||||
@@ -226,10 +227,6 @@ function formatAddressHtml(address, ensName, maxLen, title) {
|
|||||||
function isoDate(timestamp) {
|
function isoDate(timestamp) {
|
||||||
const d = new Date(timestamp * 1000);
|
const d = new Date(timestamp * 1000);
|
||||||
const pad = (n) => String(n).padStart(2, "0");
|
const pad = (n) => String(n).padStart(2, "0");
|
||||||
const off = -d.getTimezoneOffset();
|
|
||||||
const sign = off >= 0 ? "+" : "-";
|
|
||||||
const absOff = Math.abs(off);
|
|
||||||
const tz = sign + pad(Math.floor(absOff / 60)) + ":" + pad(absOff % 60);
|
|
||||||
return (
|
return (
|
||||||
d.getFullYear() +
|
d.getFullYear() +
|
||||||
"-" +
|
"-" +
|
||||||
@@ -241,8 +238,7 @@ function isoDate(timestamp) {
|
|||||||
":" +
|
":" +
|
||||||
pad(d.getMinutes()) +
|
pad(d.getMinutes()) +
|
||||||
":" +
|
":" +
|
||||||
pad(d.getSeconds()) +
|
pad(d.getSeconds())
|
||||||
tz
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -263,26 +259,12 @@ function timeAgo(timestamp) {
|
|||||||
return years + " year" + (years !== 1 ? "s" : "") + " ago";
|
return years + " year" + (years !== 1 ? "s" : "") + " ago";
|
||||||
}
|
}
|
||||||
|
|
||||||
function flashCopyFeedback(el) {
|
|
||||||
if (!el) return;
|
|
||||||
el.classList.remove("copy-flash-fade");
|
|
||||||
el.classList.add("copy-flash-active");
|
|
||||||
setTimeout(() => {
|
|
||||||
el.classList.remove("copy-flash-active");
|
|
||||||
el.classList.add("copy-flash-fade");
|
|
||||||
setTimeout(() => {
|
|
||||||
el.classList.remove("copy-flash-fade");
|
|
||||||
}, 350);
|
|
||||||
}, 100);
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
$,
|
$,
|
||||||
showError,
|
showError,
|
||||||
hideError,
|
hideError,
|
||||||
showView,
|
showView,
|
||||||
showFlash,
|
showFlash,
|
||||||
flashCopyFeedback,
|
|
||||||
balanceLine,
|
balanceLine,
|
||||||
balanceLinesForAddress,
|
balanceLinesForAddress,
|
||||||
addressColor,
|
addressColor,
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ const {
|
|||||||
$,
|
$,
|
||||||
showView,
|
showView,
|
||||||
showFlash,
|
showFlash,
|
||||||
flashCopyFeedback,
|
|
||||||
balanceLinesForAddress,
|
balanceLinesForAddress,
|
||||||
isoDate,
|
isoDate,
|
||||||
timeAgo,
|
timeAgo,
|
||||||
@@ -86,10 +85,9 @@ function renderActiveAddress() {
|
|||||||
el.innerHTML =
|
el.innerHTML =
|
||||||
`<span class="underline decoration-dashed cursor-pointer" id="active-addr-copy">${dot}${escapeHtml(addr)}</span>` +
|
`<span class="underline decoration-dashed cursor-pointer" id="active-addr-copy">${dot}${escapeHtml(addr)}</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>`;
|
||||||
$("active-addr-copy").addEventListener("click", (e) => {
|
$("active-addr-copy").addEventListener("click", () => {
|
||||||
navigator.clipboard.writeText(addr);
|
navigator.clipboard.writeText(addr);
|
||||||
showFlash("Copied!");
|
showFlash("Copied!");
|
||||||
flashCopyFeedback(e.currentTarget);
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
el.textContent = "";
|
el.textContent = "";
|
||||||
@@ -241,7 +239,7 @@ function render(ctx) {
|
|||||||
html += `<div>`;
|
html += `<div>`;
|
||||||
html += `<div class="flex justify-between items-center bg-section py-1 px-2" style="margin:0 -0.5rem">`;
|
html += `<div class="flex justify-between items-center bg-section py-1 px-2" style="margin:0 -0.5rem">`;
|
||||||
html += `<span class="font-bold cursor-pointer wallet-name underline decoration-dashed" data-wallet="${wi}">${wallet.name}</span>`;
|
html += `<span class="font-bold cursor-pointer wallet-name underline decoration-dashed" data-wallet="${wi}">${wallet.name}</span>`;
|
||||||
if (wallet.type === "hd" || wallet.type === "xprv") {
|
if (wallet.type === "hd") {
|
||||||
html += `<button class="btn-add-address border border-border px-1 hover:bg-fg hover:text-bg cursor-pointer text-xs" data-wallet="${wi}" title="Add another address to this wallet">+</button>`;
|
html += `<button class="btn-add-address border border-border px-1 hover:bg-fg hover:text-bg cursor-pointer text-xs" data-wallet="${wi}" title="Add another address to this wallet">+</button>`;
|
||||||
}
|
}
|
||||||
html += `</div>`;
|
html += `</div>`;
|
||||||
|
|||||||
69
src/popup/views/importKey.js
Normal file
69
src/popup/views/importKey.js
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
const { $, showView, showFlash } = require("./helpers");
|
||||||
|
const { addressFromPrivateKey } = require("../../shared/wallet");
|
||||||
|
const { encryptWithPassword } = require("../../shared/vault");
|
||||||
|
const { state, saveState } = require("../../shared/state");
|
||||||
|
|
||||||
|
function show() {
|
||||||
|
$("import-private-key").value = "";
|
||||||
|
$("import-key-password").value = "";
|
||||||
|
$("import-key-password-confirm").value = "";
|
||||||
|
showView("import-key");
|
||||||
|
}
|
||||||
|
|
||||||
|
function init(ctx) {
|
||||||
|
$("btn-import-key-confirm").addEventListener("click", async () => {
|
||||||
|
const key = $("import-private-key").value.trim();
|
||||||
|
if (!key) {
|
||||||
|
showFlash("Please enter your private key.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let addr;
|
||||||
|
try {
|
||||||
|
addr = addressFromPrivateKey(key);
|
||||||
|
} catch (e) {
|
||||||
|
showFlash("Invalid private key.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const pw = $("import-key-password").value;
|
||||||
|
const pw2 = $("import-key-password-confirm").value;
|
||||||
|
if (!pw) {
|
||||||
|
showFlash("Please choose a password.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (pw.length < 12) {
|
||||||
|
showFlash("Password must be at least 12 characters.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (pw !== pw2) {
|
||||||
|
showFlash("Passwords do not match.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const encrypted = await encryptWithPassword(key, pw);
|
||||||
|
const walletNum = state.wallets.length + 1;
|
||||||
|
state.wallets.push({
|
||||||
|
type: "key",
|
||||||
|
name: "Wallet " + walletNum,
|
||||||
|
encryptedSecret: encrypted,
|
||||||
|
addresses: [
|
||||||
|
{ address: addr, balance: "0.0000", tokenBalances: [] },
|
||||||
|
],
|
||||||
|
});
|
||||||
|
state.hasWallet = true;
|
||||||
|
await saveState();
|
||||||
|
ctx.renderWalletList();
|
||||||
|
showView("main");
|
||||||
|
|
||||||
|
ctx.doRefreshAndRender();
|
||||||
|
});
|
||||||
|
|
||||||
|
$("btn-import-key-back").addEventListener("click", () => {
|
||||||
|
if (!state.hasWallet) {
|
||||||
|
showView("welcome");
|
||||||
|
} else {
|
||||||
|
ctx.renderWalletList();
|
||||||
|
showView("main");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = { init, show };
|
||||||
@@ -2,7 +2,6 @@ const {
|
|||||||
$,
|
$,
|
||||||
showView,
|
showView,
|
||||||
showFlash,
|
showFlash,
|
||||||
flashCopyFeedback,
|
|
||||||
formatAddressHtml,
|
formatAddressHtml,
|
||||||
addressTitle,
|
addressTitle,
|
||||||
} = require("./helpers");
|
} = require("./helpers");
|
||||||
@@ -61,12 +60,11 @@ function show() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function init(ctx) {
|
function init(ctx) {
|
||||||
$("receive-address-block").addEventListener("click", (e) => {
|
$("receive-address-block").addEventListener("click", () => {
|
||||||
const addr = $("receive-address-block").dataset.full;
|
const addr = $("receive-address-block").dataset.full;
|
||||||
if (addr) {
|
if (addr) {
|
||||||
navigator.clipboard.writeText(addr);
|
navigator.clipboard.writeText(addr);
|
||||||
showFlash("Copied!");
|
showFlash("Copied!");
|
||||||
flashCopyFeedback(e.currentTarget);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -75,7 +73,6 @@ function init(ctx) {
|
|||||||
if (addr) {
|
if (addr) {
|
||||||
navigator.clipboard.writeText(addr);
|
navigator.clipboard.writeText(addr);
|
||||||
showFlash("Copied!");
|
showFlash("Copied!");
|
||||||
flashCopyFeedback($("receive-address-block"));
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ const {
|
|||||||
$,
|
$,
|
||||||
showView,
|
showView,
|
||||||
showFlash,
|
showFlash,
|
||||||
flashCopyFeedback,
|
|
||||||
addressDotHtml,
|
addressDotHtml,
|
||||||
addressTitle,
|
addressTitle,
|
||||||
escapeHtml,
|
escapeHtml,
|
||||||
@@ -159,9 +158,8 @@ function render() {
|
|||||||
loadCalldata(tx.hash, tx.to);
|
loadCalldata(tx.hash, tx.to);
|
||||||
}
|
}
|
||||||
|
|
||||||
const isoStr = isoDate(tx.timestamp);
|
$("tx-detail-time").textContent =
|
||||||
$("tx-detail-time").innerHTML =
|
isoDate(tx.timestamp) + " (" + timeAgo(tx.timestamp) + ")";
|
||||||
copyableHtml(isoStr) + " (" + escapeHtml(timeAgo(tx.timestamp)) + ")";
|
|
||||||
$("tx-detail-status").textContent = tx.isError ? "Failed" : "Success";
|
$("tx-detail-status").textContent = tx.isError ? "Failed" : "Success";
|
||||||
showView("transaction");
|
showView("transaction");
|
||||||
|
|
||||||
@@ -172,7 +170,6 @@ function render() {
|
|||||||
el.onclick = () => {
|
el.onclick = () => {
|
||||||
navigator.clipboard.writeText(el.dataset.copy);
|
navigator.clipboard.writeText(el.dataset.copy);
|
||||||
showFlash("Copied!");
|
showFlash("Copied!");
|
||||||
flashCopyFeedback(el);
|
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -250,7 +247,6 @@ async function loadCalldata(txHash, toAddress) {
|
|||||||
el.onclick = () => {
|
el.onclick = () => {
|
||||||
navigator.clipboard.writeText(el.dataset.copy);
|
navigator.clipboard.writeText(el.dataset.copy);
|
||||||
showFlash("Copied!");
|
showFlash("Copied!");
|
||||||
flashCopyFeedback(el);
|
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ const {
|
|||||||
$,
|
$,
|
||||||
showView,
|
showView,
|
||||||
showFlash,
|
showFlash,
|
||||||
flashCopyFeedback,
|
|
||||||
addressDotHtml,
|
addressDotHtml,
|
||||||
addressTitle,
|
addressTitle,
|
||||||
escapeHtml,
|
escapeHtml,
|
||||||
@@ -44,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) {
|
||||||
@@ -60,16 +58,6 @@ function txHashHtml(hash) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function blockNumberHtml(blockNumber) {
|
|
||||||
const num = String(blockNumber);
|
|
||||||
const link = `https://etherscan.io/block/${num}`;
|
|
||||||
const extLink = `<a href="${link}" target="_blank" rel="noopener" class="inline-flex items-center">${EXT_ICON}</a>`;
|
|
||||||
return (
|
|
||||||
`<span class="underline decoration-dashed cursor-pointer" data-copy="${escapeHtml(num)}">${escapeHtml(num)}</span>` +
|
|
||||||
extLink
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function attachCopyHandlers(viewId) {
|
function attachCopyHandlers(viewId) {
|
||||||
document
|
document
|
||||||
.getElementById(viewId)
|
.getElementById(viewId)
|
||||||
@@ -78,7 +66,6 @@ function attachCopyHandlers(viewId) {
|
|||||||
el.onclick = () => {
|
el.onclick = () => {
|
||||||
navigator.clipboard.writeText(el.dataset.copy);
|
navigator.clipboard.writeText(el.dataset.copy);
|
||||||
showFlash("Copied!");
|
showFlash("Copied!");
|
||||||
flashCopyFeedback(el);
|
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -152,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>`;
|
||||||
@@ -177,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;
|
||||||
|
|
||||||
const hasDecoded = d.decoded && d.decoded.details;
|
|
||||||
|
|
||||||
// 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-summary").textContent = d.amount + " " + d.symbol;
|
||||||
$("success-tx-to").innerHTML = toAddressHtml(d.to);
|
$("success-tx-to").innerHTML = toAddressHtml(d.to);
|
||||||
}
|
$("success-tx-block").textContent = String(d.blockNumber);
|
||||||
|
|
||||||
$("success-tx-block").innerHTML = blockNumberHtml(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) {
|
||||||
@@ -487,10 +481,7 @@ function decode(data, toAddress) {
|
|||||||
const deadlineDate = new Date(Number(deadline) * 1000);
|
const deadlineDate = new Date(Number(deadline) * 1000);
|
||||||
details.push({
|
details.push({
|
||||||
label: "Deadline",
|
label: "Deadline",
|
||||||
value: deadlineDate
|
value: deadlineDate.toISOString().replace("T", " ").slice(0, 19),
|
||||||
.toISOString()
|
|
||||||
.replace("T", " ")
|
|
||||||
.replace(".000Z", "Z"),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -24,26 +24,6 @@ function hdWalletFromMnemonic(mnemonic) {
|
|||||||
return { xpub, firstAddress };
|
return { xpub, firstAddress };
|
||||||
}
|
}
|
||||||
|
|
||||||
function hdWalletFromXprv(xprv) {
|
|
||||||
const root = HDNodeWallet.fromExtendedKey(xprv);
|
|
||||||
if (!root.privateKey) {
|
|
||||||
throw new Error("Not an extended private key (xprv).");
|
|
||||||
}
|
|
||||||
const node = root.derivePath("44'/60'/0'/0");
|
|
||||||
const xpub = node.neuter().extendedKey;
|
|
||||||
const firstAddress = node.deriveChild(0).address;
|
|
||||||
return { xpub, firstAddress };
|
|
||||||
}
|
|
||||||
|
|
||||||
function isValidXprv(key) {
|
|
||||||
try {
|
|
||||||
const node = HDNodeWallet.fromExtendedKey(key);
|
|
||||||
return !!node.privateKey;
|
|
||||||
} catch {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function addressFromPrivateKey(key) {
|
function addressFromPrivateKey(key) {
|
||||||
const w = new Wallet(key);
|
const w = new Wallet(key);
|
||||||
return w.address;
|
return w.address;
|
||||||
@@ -58,11 +38,6 @@ function getSignerForAddress(walletData, addrIndex, decryptedSecret) {
|
|||||||
);
|
);
|
||||||
return node.deriveChild(addrIndex);
|
return node.deriveChild(addrIndex);
|
||||||
}
|
}
|
||||||
if (walletData.type === "xprv") {
|
|
||||||
const root = HDNodeWallet.fromExtendedKey(decryptedSecret);
|
|
||||||
const node = root.derivePath("44'/60'/0'/0");
|
|
||||||
return node.deriveChild(addrIndex);
|
|
||||||
}
|
|
||||||
return new Wallet(decryptedSecret);
|
return new Wallet(decryptedSecret);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,8 +49,6 @@ module.exports = {
|
|||||||
generateMnemonic,
|
generateMnemonic,
|
||||||
deriveAddressFromXpub,
|
deriveAddressFromXpub,
|
||||||
hdWalletFromMnemonic,
|
hdWalletFromMnemonic,
|
||||||
hdWalletFromXprv,
|
|
||||||
isValidXprv,
|
|
||||||
addressFromPrivateKey,
|
addressFromPrivateKey,
|
||||||
getSignerForAddress,
|
getSignerForAddress,
|
||||||
isValidMnemonic,
|
isValidMnemonic,
|
||||||
|
|||||||
Reference in New Issue
Block a user