refactor: delete-wallet-confirm as standalone full view
All checks were successful
check / check (push) Successful in 22s
All checks were successful
check / check (push) Successful in 22s
Replace the inline confirmation div at the bottom of Settings with a proper full-screen view (view-delete-wallet-confirm). This fixes the issue where the confirmation was offscreen on the 360x600 popup. - New view with back button, title, warning text, password input, and red-text Confirm Delete button - Dedicated flash area for password errors - New deleteWallet.js module with init/show pattern - Added delete-wallet-confirm to VIEWS array in helpers.js - Removed old inline confirmation HTML and logic from settings
This commit is contained in:
@@ -2,7 +2,7 @@ const { $, showView, showFlash, escapeHtml } = require("./helpers");
|
||||
const { state, saveState } = require("../../shared/state");
|
||||
const { ETHEREUM_MAINNET_CHAIN_ID } = require("../../shared/constants");
|
||||
const { log, debugFetch } = require("../../shared/log");
|
||||
const { decryptWithPassword } = require("../../shared/vault");
|
||||
const deleteWallet = require("./deleteWallet");
|
||||
|
||||
const runtime =
|
||||
typeof browser !== "undefined" ? browser.runtime : chrome.runtime;
|
||||
@@ -66,8 +66,6 @@ function renderTrackedTokens() {
|
||||
});
|
||||
}
|
||||
|
||||
let deleteWalletIndex = null;
|
||||
|
||||
function renderWalletListSettings() {
|
||||
const container = $("settings-wallet-list");
|
||||
if (state.wallets.length === 0) {
|
||||
@@ -86,12 +84,7 @@ function renderWalletListSettings() {
|
||||
container.querySelectorAll(".btn-delete-wallet").forEach((btn) => {
|
||||
btn.addEventListener("click", () => {
|
||||
const idx = parseInt(btn.dataset.idx, 10);
|
||||
const wallet = state.wallets[idx];
|
||||
deleteWalletIndex = idx;
|
||||
$("delete-wallet-name").textContent =
|
||||
wallet.name || "Wallet " + (idx + 1);
|
||||
$("delete-wallet-password").value = "";
|
||||
$("delete-wallet-confirm").classList.remove("hidden");
|
||||
deleteWallet.show(idx);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -134,8 +127,6 @@ function show() {
|
||||
renderTrackedTokens();
|
||||
renderSiteLists();
|
||||
renderWalletListSettings();
|
||||
deleteWalletIndex = null;
|
||||
$("delete-wallet-confirm").classList.add("hidden");
|
||||
|
||||
showView("settings");
|
||||
}
|
||||
@@ -150,6 +141,8 @@ function renderSiteLists() {
|
||||
}
|
||||
|
||||
function init(ctx) {
|
||||
deleteWallet.init(ctx);
|
||||
|
||||
$("btn-save-rpc").addEventListener("click", async () => {
|
||||
const url = $("settings-rpc").value.trim();
|
||||
if (!url) {
|
||||
@@ -259,72 +252,6 @@ function init(ctx) {
|
||||
ctx.renderWalletList();
|
||||
showView("main");
|
||||
});
|
||||
|
||||
$("btn-delete-wallet-cancel").addEventListener("click", () => {
|
||||
$("delete-wallet-confirm").classList.add("hidden");
|
||||
$("delete-wallet-password").value = "";
|
||||
deleteWalletIndex = null;
|
||||
});
|
||||
|
||||
$("btn-delete-wallet-confirm").addEventListener("click", async () => {
|
||||
const pw = $("delete-wallet-password").value;
|
||||
if (!pw) {
|
||||
showFlash("Password required.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (deleteWalletIndex === null) {
|
||||
showFlash("No wallet selected for deletion.");
|
||||
return;
|
||||
}
|
||||
|
||||
const walletIdx = deleteWalletIndex;
|
||||
const wallet = state.wallets[walletIdx];
|
||||
|
||||
// Verify password against the wallet's encrypted data
|
||||
try {
|
||||
await decryptWithPassword(wallet.encryptedSecret, pw);
|
||||
} catch (_e) {
|
||||
showFlash("Wrong password.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Collect addresses to clean up from allowedSites/deniedSites
|
||||
const addresses = (wallet.addresses || []).map((a) => a.address);
|
||||
|
||||
// Remove wallet
|
||||
state.wallets.splice(walletIdx, 1);
|
||||
|
||||
// Clean up site permissions for deleted addresses
|
||||
for (const addr of addresses) {
|
||||
delete state.allowedSites[addr];
|
||||
delete state.deniedSites[addr];
|
||||
}
|
||||
|
||||
deleteWalletIndex = null;
|
||||
|
||||
if (state.wallets.length === 0) {
|
||||
// No wallets left — reset selection and show welcome
|
||||
state.selectedWallet = null;
|
||||
state.selectedAddress = null;
|
||||
state.activeAddress = null;
|
||||
await saveState();
|
||||
$("delete-wallet-confirm").classList.add("hidden");
|
||||
showView("welcome");
|
||||
} else {
|
||||
// Switch to first wallet if deleted wallet was active
|
||||
state.selectedWallet = 0;
|
||||
state.selectedAddress = 0;
|
||||
state.activeAddress =
|
||||
state.wallets[0].addresses[0]?.address || null;
|
||||
await saveState();
|
||||
$("delete-wallet-confirm").classList.add("hidden");
|
||||
showFlash("Wallet deleted.");
|
||||
renderWalletListSettings();
|
||||
ctx.renderWalletList();
|
||||
showView("main");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = { init, show, renderSiteLists };
|
||||
|
||||
Reference in New Issue
Block a user