@@ -915,8 +923,8 @@
funds will be unrecoverable without your recovery phrase.
diff --git a/src/popup/views/addWallet.js b/src/popup/views/addWallet.js
index eed7ac9..e976438 100644
--- a/src/popup/views/addWallet.js
+++ b/src/popup/views/addWallet.js
@@ -1,4 +1,4 @@
-const { $, showView, showFlash } = require("./helpers");
+const { $, showView, showFlash, showError, hideError } = require("./helpers");
const {
generateMnemonic,
hdWalletFromMnemonic,
@@ -13,6 +13,7 @@ function show() {
$("add-wallet-password").value = "";
$("add-wallet-password-confirm").value = "";
$("add-wallet-phrase-warning").classList.add("hidden");
+ hideError("add-wallet-error");
showView("add-wallet");
}
@@ -25,14 +26,16 @@ function init(ctx) {
$("btn-add-wallet-confirm").addEventListener("click", async () => {
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,13 +75,15 @@ function init(ctx) {
firstAddress.toLowerCase(),
);
if (duplicate) {
- showFlash(
+ showError(
+ "add-wallet-error",
"This recovery phrase is already added (" +
duplicate.name +
").",
);
return;
}
+ hideError("add-wallet-error");
const encrypted = await encryptWithPassword(mnemonic, pw);
const walletNum = state.wallets.length + 1;
const wallet = {
diff --git a/src/popup/views/addressDetail.js b/src/popup/views/addressDetail.js
index 2deb222..db31d7d 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 btn = $("btn-export-privkey-confirm");
@@ -343,10 +343,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.");
} finally {
btn.disabled = false;
btn.classList.remove("text-muted");
diff --git a/src/popup/views/deleteWallet.js b/src/popup/views/deleteWallet.js
index 21cc2ea..887f0c0 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;
}
@@ -51,8 +49,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.");
btn.disabled = false;
btn.classList.remove("text-muted");
return;
diff --git a/src/popup/views/importKey.js b/src/popup/views/importKey.js
index a3324a3..d6d9ba6 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,30 +15,34 @@ 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;
}
+ hideError("import-key-error");
const encrypted = await encryptWithPassword(key, pw);
const walletNum = state.wallets.length + 1;
state.wallets.push({