Centralize view state into app ctx with viewData persistence
All checks were successful
check / check (push) Successful in 17s
All checks were successful
check / check (push) Successful in 17s
Creates a centralized transactionDetail.js view module, replacing the duplicated showTxDetail/copyableHtml/blockieHtml/txDetailAddressHtml code that was in both addressDetail.js and addressToken.js (~120 lines removed). Transaction data is stored in state.viewData and persisted, so the transaction detail view survives popup close/reopen. Adds viewData to persisted state. Each view that needs data for restore stores it in state.viewData before rendering. The ctx object now has showTransactionDetail() alongside all other show methods. Restorable views expanded to include: transaction (via viewData.tx), success-tx (via viewData.hash/blockNumber), error-tx (via viewData.message). txStatus.js split into show (sets data) + render (reads data) for each screen, enabling restore. Non-restorable views (send, confirm-tx, wait-tx, add-wallet, import-key, add-token) fall back to the nearest parent since they involve active form state or network polling.
This commit is contained in:
@@ -7,7 +7,7 @@ const {
|
||||
addressDotHtml,
|
||||
escapeHtml,
|
||||
} = require("./helpers");
|
||||
const { state } = require("../../shared/state");
|
||||
const { state, saveState } = require("../../shared/state");
|
||||
const { getProvider } = require("../../shared/balances");
|
||||
const { log } = require("../../shared/log");
|
||||
|
||||
@@ -107,26 +107,51 @@ function showSuccess(txInfo, txHash, blockNumber) {
|
||||
clearTimers();
|
||||
|
||||
const symbol = txInfo.token === "ETH" ? "ETH" : txInfo.tokenSymbol || "?";
|
||||
$("success-tx-summary").textContent = txInfo.amount + " " + symbol;
|
||||
$("success-tx-to").innerHTML = toAddressHtml(txInfo.to);
|
||||
$("success-tx-block").textContent = String(blockNumber);
|
||||
$("success-tx-hash").innerHTML = txHashHtml(txHash);
|
||||
attachCopyHandlers("view-success-tx");
|
||||
|
||||
showView("success-tx");
|
||||
state.viewData = {
|
||||
amount: txInfo.amount,
|
||||
symbol: symbol,
|
||||
to: txInfo.to,
|
||||
hash: txHash,
|
||||
blockNumber: blockNumber,
|
||||
};
|
||||
renderSuccess();
|
||||
ctx.doRefreshAndRender();
|
||||
}
|
||||
|
||||
function renderSuccess() {
|
||||
const d = state.viewData;
|
||||
if (!d || !d.hash) return;
|
||||
$("success-tx-summary").textContent = d.amount + " " + d.symbol;
|
||||
$("success-tx-to").innerHTML = toAddressHtml(d.to);
|
||||
$("success-tx-block").textContent = String(d.blockNumber);
|
||||
$("success-tx-hash").innerHTML = txHashHtml(d.hash);
|
||||
attachCopyHandlers("view-success-tx");
|
||||
showView("success-tx");
|
||||
}
|
||||
|
||||
function showError(txInfo, txHash, message) {
|
||||
clearTimers();
|
||||
|
||||
const symbol = txInfo.token === "ETH" ? "ETH" : txInfo.tokenSymbol || "?";
|
||||
$("error-tx-summary").textContent = txInfo.amount + " " + symbol;
|
||||
$("error-tx-to").innerHTML = toAddressHtml(txInfo.to);
|
||||
$("error-tx-message").textContent = message;
|
||||
state.viewData = {
|
||||
amount: txInfo.amount,
|
||||
symbol: symbol,
|
||||
to: txInfo.to,
|
||||
hash: txHash || null,
|
||||
message: message,
|
||||
};
|
||||
renderError();
|
||||
}
|
||||
|
||||
if (txHash) {
|
||||
$("error-tx-hash").innerHTML = txHashHtml(txHash);
|
||||
function renderError() {
|
||||
const d = state.viewData;
|
||||
if (!d || !d.message) return;
|
||||
$("error-tx-summary").textContent = d.amount + " " + d.symbol;
|
||||
$("error-tx-to").innerHTML = toAddressHtml(d.to);
|
||||
$("error-tx-message").textContent = d.message;
|
||||
|
||||
if (d.hash) {
|
||||
$("error-tx-hash").innerHTML = txHashHtml(d.hash);
|
||||
$("error-tx-hash-section").classList.remove("hidden");
|
||||
attachCopyHandlers("view-error-tx");
|
||||
} else {
|
||||
@@ -151,4 +176,4 @@ function init(_ctx) {
|
||||
$("btn-error-tx-done").addEventListener("click", navigateBack);
|
||||
}
|
||||
|
||||
module.exports = { init, showWait, showError };
|
||||
module.exports = { init, showWait, showError, renderSuccess, renderError };
|
||||
|
||||
Reference in New Issue
Block a user