Persist navigation state across popup close/reopen
All checks were successful
check / check (push) Successful in 17s
All checks were successful
check / check (push) Successful in 17s
The current view, selected wallet, selected address, and selected token are now saved to extension storage. When the popup reopens, it restores to the last visited view instead of always returning to the home screen. Restorable views: main, address detail, address-token, receive, settings. Non-restorable views (send, confirm, tx status, forms) fall back to the nearest parent. Stored indices are validated against current wallet data to handle stale references. Also refactors receive view setup into a centralized receive.show() function, eliminating duplicate QR/address/warning code from addressDetail.js, addressToken.js, and home.js. Adds settings.show() to centralize settings field population.
This commit is contained in:
@@ -52,8 +52,67 @@ const ctx = {
|
||||
showAddressToken: () => addressToken.show(),
|
||||
showAddTokenView: () => addToken.show(),
|
||||
showConfirmTx: (txInfo) => confirmTx.show(txInfo),
|
||||
showReceive: () => receive.show(),
|
||||
};
|
||||
|
||||
// Views that can be fully re-rendered from persisted state.
|
||||
// All others fall back to the nearest restorable parent.
|
||||
const RESTORABLE_VIEWS = new Set([
|
||||
"main",
|
||||
"address",
|
||||
"address-token",
|
||||
"receive",
|
||||
"settings",
|
||||
]);
|
||||
|
||||
function restoreView() {
|
||||
const view = state.currentView;
|
||||
if (!view || !RESTORABLE_VIEWS.has(view)) {
|
||||
return fallbackView();
|
||||
}
|
||||
|
||||
// Validate that selectedWallet/selectedAddress still point to valid data
|
||||
if (view === "address" || view === "address-token" || view === "receive") {
|
||||
if (
|
||||
state.selectedWallet === null ||
|
||||
state.selectedAddress === null ||
|
||||
!state.wallets[state.selectedWallet] ||
|
||||
!state.wallets[state.selectedWallet].addresses[
|
||||
state.selectedAddress
|
||||
]
|
||||
) {
|
||||
return fallbackView();
|
||||
}
|
||||
}
|
||||
|
||||
if (view === "address-token" && !state.selectedToken) {
|
||||
return fallbackView();
|
||||
}
|
||||
|
||||
switch (view) {
|
||||
case "address":
|
||||
addressDetail.show();
|
||||
break;
|
||||
case "address-token":
|
||||
addressToken.show();
|
||||
break;
|
||||
case "receive":
|
||||
receive.show();
|
||||
break;
|
||||
case "settings":
|
||||
settings.show();
|
||||
break;
|
||||
default:
|
||||
fallbackView();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
function fallbackView() {
|
||||
renderWalletList();
|
||||
showView("main");
|
||||
}
|
||||
|
||||
async function init() {
|
||||
if (DEBUG) {
|
||||
const banner = document.createElement("div");
|
||||
@@ -98,10 +157,7 @@ async function init() {
|
||||
showView("main");
|
||||
return;
|
||||
}
|
||||
$("settings-rpc").value = state.rpcUrl;
|
||||
$("settings-blockscout").value = state.blockscoutUrl;
|
||||
settings.renderSiteLists();
|
||||
showView("settings");
|
||||
settings.show();
|
||||
});
|
||||
|
||||
welcome.init(ctx);
|
||||
@@ -121,7 +177,7 @@ async function init() {
|
||||
showView("welcome");
|
||||
} else {
|
||||
renderWalletList();
|
||||
showView("main");
|
||||
restoreView();
|
||||
doRefreshAndRender();
|
||||
setInterval(doRefreshAndRender, 10000);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user