@@ -938,10 +940,7 @@
is permanent. Any
funds will be unrecoverable without your recovery phrase.
-
+
{
const mnemonic = $("wallet-mnemonic").value.trim();
if (!mnemonic) {
- showFlash(
+ showError(
+ "add-wallet-error",
"Enter a recovery phrase or press the die to generate one.",
);
return;
}
const words = mnemonic.split(/\s+/);
if (words.length !== 12 && words.length !== 24) {
- showFlash(
+ showError(
+ "add-wallet-error",
"Recovery phrase must be 12 or 24 words. You entered " +
words.length +
".",
@@ -40,21 +43,27 @@ function init(ctx) {
return;
}
if (!isValidMnemonic(mnemonic)) {
- showFlash("Invalid recovery phrase. Check for typos.");
+ showError(
+ "add-wallet-error",
+ "Invalid recovery phrase. Check for typos.",
+ );
return;
}
const pw = $("add-wallet-password").value;
const pw2 = $("add-wallet-password-confirm").value;
if (!pw) {
- showFlash("Please choose a password.");
+ showError("add-wallet-error", "Please choose a password.");
return;
}
if (pw.length < 12) {
- showFlash("Password must be at least 12 characters.");
+ showError(
+ "add-wallet-error",
+ "Password must be at least 12 characters.",
+ );
return;
}
if (pw !== pw2) {
- showFlash("Passwords do not match.");
+ showError("add-wallet-error", "Passwords do not match.");
return;
}
const { xpub, firstAddress } = hdWalletFromMnemonic(mnemonic);
@@ -66,7 +75,8 @@ function init(ctx) {
firstAddress.toLowerCase(),
);
if (duplicate) {
- showFlash(
+ showError(
+ "add-wallet-error",
"This recovery phrase is already added (" +
duplicate.name +
").",
@@ -89,6 +99,7 @@ function init(ctx) {
state.hasWallet = true;
await saveState();
ctx.renderWalletList();
+ hideError("add-wallet-error");
showView("main");
// Scan for used HD addresses beyond index 0.
diff --git a/src/popup/views/addressDetail.js b/src/popup/views/addressDetail.js
index 49c627e..72d024c 100644
--- a/src/popup/views/addressDetail.js
+++ b/src/popup/views/addressDetail.js
@@ -2,6 +2,8 @@ const {
$,
showView,
showFlash,
+ showError,
+ hideError,
balanceLinesForAddress,
addressDotHtml,
addressTitle,
@@ -310,8 +312,7 @@ function init(_ctx) {
$("export-privkey-address").textContent = addr.address;
$("export-privkey-address").dataset.full = addr.address;
$("export-privkey-password").value = "";
- $("export-privkey-flash").classList.add("hidden");
- $("export-privkey-flash").textContent = "";
+ hideError("export-privkey-error");
$("export-privkey-password-section").classList.remove("hidden");
$("export-privkey-result").classList.add("hidden");
$("export-privkey-value").textContent = "";
@@ -321,8 +322,7 @@ function init(_ctx) {
$("btn-export-privkey-confirm").addEventListener("click", async () => {
const password = $("export-privkey-password").value;
if (!password) {
- $("export-privkey-flash").textContent = "Password is required.";
- $("export-privkey-flash").classList.remove("hidden");
+ showError("export-privkey-error", "Password is required.");
return;
}
const wallet = state.wallets[state.selectedWallet];
@@ -340,10 +340,9 @@ function init(_ctx) {
$("export-privkey-password-section").classList.add("hidden");
$("export-privkey-value").textContent = privateKey;
$("export-privkey-result").classList.remove("hidden");
- $("export-privkey-flash").classList.add("hidden");
+ hideError("export-privkey-error");
} catch {
- $("export-privkey-flash").textContent = "Wrong password.";
- $("export-privkey-flash").classList.remove("hidden");
+ showError("export-privkey-error", "Wrong password.");
}
});
diff --git a/src/popup/views/approval.js b/src/popup/views/approval.js
index 1b05110..276564d 100644
--- a/src/popup/views/approval.js
+++ b/src/popup/views/approval.js
@@ -4,6 +4,8 @@ const {
addressTitle,
escapeHtml,
showView,
+ showError,
+ hideError,
} = require("./helpers");
const { state, saveState } = require("../../shared/state");
const { formatEther, formatUnits, Interface, toUtf8String } = require("ethers");
@@ -342,7 +344,7 @@ function showSignApproval(details) {
}
$("approve-sign-password").value = "";
- $("approve-sign-error").classList.add("hidden");
+ hideError("approve-sign-error");
$("btn-approve-sign").disabled = false;
$("btn-approve-sign").classList.remove("text-muted");
@@ -407,11 +409,10 @@ function init(ctx) {
$("btn-approve-tx").addEventListener("click", () => {
const password = $("approve-tx-password").value;
if (!password) {
- $("approve-tx-error").textContent = "Please enter your password.";
- $("approve-tx-error").classList.remove("hidden");
+ showError("approve-tx-error", "Please enter your password.");
return;
}
- $("approve-tx-error").classList.add("hidden");
+ hideError("approve-tx-error");
$("btn-approve-tx").disabled = true;
$("btn-approve-tx").classList.add("text-muted");
@@ -447,11 +448,10 @@ function init(ctx) {
$("btn-approve-sign").addEventListener("click", () => {
const password = $("approve-sign-password").value;
if (!password) {
- $("approve-sign-error").textContent = "Please enter your password.";
- $("approve-sign-error").classList.remove("hidden");
+ showError("approve-sign-error", "Please enter your password.");
return;
}
- $("approve-sign-error").classList.add("hidden");
+ hideError("approve-sign-error");
$("btn-approve-sign").disabled = true;
$("btn-approve-sign").classList.add("text-muted");
@@ -469,8 +469,7 @@ function init(ctx) {
} else {
const msg =
(response && response.error) || "Signing failed.";
- $("approve-sign-error").textContent = msg;
- $("approve-sign-error").classList.remove("hidden");
+ showError("approve-sign-error", msg);
$("btn-approve-sign").disabled = false;
$("btn-approve-sign").classList.remove("text-muted");
}
diff --git a/src/popup/views/deleteWallet.js b/src/popup/views/deleteWallet.js
index 49e47bf..1aebf97 100644
--- a/src/popup/views/deleteWallet.js
+++ b/src/popup/views/deleteWallet.js
@@ -1,4 +1,4 @@
-const { $, showView, showFlash } = require("./helpers");
+const { $, showView, showFlash, showError, hideError } = require("./helpers");
const { state, saveState } = require("../../shared/state");
const { decryptWithPassword } = require("../../shared/vault");
@@ -11,8 +11,7 @@ function show(walletIdx) {
$("delete-wallet-name").textContent =
wallet.name || "Wallet " + (walletIdx + 1);
$("delete-wallet-password").value = "";
- $("delete-wallet-flash").textContent = "";
- $("delete-wallet-flash").classList.add("hidden");
+ hideError("delete-wallet-error");
showView("delete-wallet-confirm");
}
@@ -27,16 +26,15 @@ function init(_ctx) {
$("btn-delete-wallet-confirm").addEventListener("click", async () => {
const pw = $("delete-wallet-password").value;
if (!pw) {
- $("delete-wallet-flash").textContent =
- "Please enter your password.";
- $("delete-wallet-flash").classList.remove("hidden");
+ showError("delete-wallet-error", "Please enter your password.");
return;
}
if (deleteWalletIndex === null) {
- $("delete-wallet-flash").textContent =
- "No wallet selected for deletion.";
- $("delete-wallet-flash").classList.remove("hidden");
+ showError(
+ "delete-wallet-error",
+ "No wallet selected for deletion.",
+ );
return;
}
@@ -47,8 +45,7 @@ function init(_ctx) {
try {
await decryptWithPassword(wallet.encryptedSecret, pw);
} catch (_e) {
- $("delete-wallet-flash").textContent = "Wrong password.";
- $("delete-wallet-flash").classList.remove("hidden");
+ showError("delete-wallet-error", "Wrong password.");
return;
}
diff --git a/src/popup/views/importKey.js b/src/popup/views/importKey.js
index a3324a3..e09aa0f 100644
--- a/src/popup/views/importKey.js
+++ b/src/popup/views/importKey.js
@@ -1,4 +1,4 @@
-const { $, showView, showFlash } = require("./helpers");
+const { $, showView, showError, hideError } = require("./helpers");
const { addressFromPrivateKey } = require("../../shared/wallet");
const { encryptWithPassword } = require("../../shared/vault");
const { state, saveState } = require("../../shared/state");
@@ -7,6 +7,7 @@ function show() {
$("import-private-key").value = "";
$("import-key-password").value = "";
$("import-key-password-confirm").value = "";
+ hideError("import-key-error");
showView("import-key");
}
@@ -14,28 +15,31 @@ 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.");
+ showError("import-key-error", "Please enter your private key.");
return;
}
let addr;
try {
addr = addressFromPrivateKey(key);
} catch (e) {
- showFlash("Invalid private key.");
+ showError("import-key-error", "Invalid private key.");
return;
}
const pw = $("import-key-password").value;
const pw2 = $("import-key-password-confirm").value;
if (!pw) {
- showFlash("Please choose a password.");
+ showError("import-key-error", "Please choose a password.");
return;
}
if (pw.length < 12) {
- showFlash("Password must be at least 12 characters.");
+ showError(
+ "import-key-error",
+ "Password must be at least 12 characters.",
+ );
return;
}
if (pw !== pw2) {
- showFlash("Passwords do not match.");
+ showError("import-key-error", "Passwords do not match.");
return;
}
const encrypted = await encryptWithPassword(key, pw);