fix: tracked tokens are kept per network, and bundled picks are offered on mainnet only (closes #523)
A network switch puts the outgoing network's tracked tokens away in a new persisted field, networkTrackedTokens, and brings back the incoming network's list, or an empty one, as endpoints are kept; the background's switch uses the same function. The two add-token screens offer their common-token picks on Ethereum Mainnet only. After a switch in Settings, Back renders the screen it lands on again, and the stack is cut at the first screen that cannot be rendered from saved state, or at AddressToken for any token but the native one; the cut stack is saved with the switch. ConfirmTx drawn again keeps the network it was reviewed on. A contract lookup that answers after a switch adds nothing. Model: opus-5-5
This commit was merged in pull request #572.
This commit is contained in:
@@ -16,6 +16,8 @@ const {
|
||||
} = require("../dustThreshold");
|
||||
const { state, saveState, currentNetwork } = require("../../shared/state");
|
||||
const { onChainSwitch } = require("../../shared/chainSwitch");
|
||||
const { restorableStack } = require("../../shared/persistedState");
|
||||
const { resetRenderedViews, markViewRendered } = require("../viewRouter");
|
||||
const {
|
||||
log,
|
||||
debugFetch,
|
||||
@@ -319,12 +321,33 @@ function init(ctx) {
|
||||
networkSelect.addEventListener("change", async () => {
|
||||
const newId = networkSelect.value;
|
||||
if (newId === state.networkId) return;
|
||||
// The screens beneath Settings show the previous network, so Back
|
||||
// finds them as it does in a reopened popup: each is rendered again
|
||||
// when Back lands on it, and the stack is cut at the first one that
|
||||
// cannot be rendered from saved state, such as Send or AddToken. It
|
||||
// is cut at AddressToken too, unless that shows the native token: any
|
||||
// other token there was picked on the previous network. Without a
|
||||
// wallet the stack starts at Welcome, which that cut would drop, and
|
||||
// Welcome shows nothing from a network. The cut comes before the
|
||||
// switch so that the switch's save keeps it for a popup closed
|
||||
// straight after.
|
||||
if (state.hasWallet) {
|
||||
const tokenView = state.viewStack.indexOf("address-token");
|
||||
if (tokenView !== -1 && state.selectedToken !== "ETH") {
|
||||
state.viewStack = state.viewStack.slice(0, tokenView);
|
||||
}
|
||||
state.viewStack = restorableStack(state.viewStack, "settings");
|
||||
}
|
||||
const net = await onChainSwitch(newId);
|
||||
// Open pages are told by the background, as after a site's approved
|
||||
// switch request.
|
||||
notify({ type: "AUTISTMASK_NETWORK_CHANGED", chainId: net.chainId });
|
||||
resetRenderedViews();
|
||||
// Settings itself is brought up to date for the new network here.
|
||||
markViewRendered("settings");
|
||||
$("settings-rpc").value = state.rpcUrl;
|
||||
$("settings-blockscout").value = state.blockscoutUrl;
|
||||
renderTrackedTokens();
|
||||
showFlash("Switched to " + net.name + ".");
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user