popup/index.js reduced to ~75 lines: loads state, builds a shared context object, initializes all views, shows first screen. Each view in popup/views/: helpers.js — $(), showError, hideError, showView welcome.js — welcome screen addWallet.js — unified create/import recovery phrase importKey.js — private key import home.js — wallet list, total value, address derivation addressDetail.js — address view, token list, QR, copy send.js — send form, ENS resolution, tx broadcast receive.js — QR + copy addToken.js — token lookup, common token picker settings.js — RPC endpoint approval.js — dApp approval (stub) Views communicate via a ctx object with shared callbacks (renderWalletList, showAddressDetail, doRefreshAndRender, etc).
This commit is contained in:
47
src/popup/views/helpers.js
Normal file
47
src/popup/views/helpers.js
Normal file
@@ -0,0 +1,47 @@
|
||||
// Shared DOM helpers used by all views.
|
||||
|
||||
const { DEBUG } = require("../../shared/wallet");
|
||||
|
||||
const VIEWS = [
|
||||
"welcome",
|
||||
"add-wallet",
|
||||
"import-key",
|
||||
"main",
|
||||
"address",
|
||||
"send",
|
||||
"receive",
|
||||
"add-token",
|
||||
"settings",
|
||||
"approve",
|
||||
];
|
||||
|
||||
function $(id) {
|
||||
return document.getElementById(id);
|
||||
}
|
||||
|
||||
function showError(id, msg) {
|
||||
const el = $(id);
|
||||
el.textContent = msg;
|
||||
el.classList.remove("hidden");
|
||||
}
|
||||
|
||||
function hideError(id) {
|
||||
$(id).classList.add("hidden");
|
||||
}
|
||||
|
||||
function showView(name) {
|
||||
for (const v of VIEWS) {
|
||||
const el = document.getElementById(`view-${v}`);
|
||||
if (el) {
|
||||
el.classList.toggle("hidden", v !== name);
|
||||
}
|
||||
}
|
||||
if (DEBUG) {
|
||||
const banner = document.getElementById("debug-banner");
|
||||
if (banner) {
|
||||
banner.textContent = "DEBUG / INSECURE (" + name + ")";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { $, showError, hideError, showView };
|
||||
Reference in New Issue
Block a user