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:
@@ -23,6 +23,11 @@ const DEFAULT_STATE = {
|
||||
hasWallet: false,
|
||||
wallets: [],
|
||||
trackedTokens: [],
|
||||
// Tracked tokens remembered per network: { [networkId]: [token, ...] }.
|
||||
// trackedTokens above is the active network's list; this is what the
|
||||
// others are restored from when the active network changes. See
|
||||
// applyChainSwitchFields().
|
||||
networkTrackedTokens: {},
|
||||
networkId: "mainnet",
|
||||
rpcUrl: DEFAULT_RPC_URL,
|
||||
blockscoutUrl: DEFAULT_BLOCKSCOUT_URL,
|
||||
@@ -289,6 +294,20 @@ function normalizePersisted(saved) {
|
||||
// profile whose wallets are perfectly fine. An empty list is a legitimate
|
||||
// value and survives.
|
||||
out.trackedTokens = structuredClone(tokenRefs(saved.trackedTokens));
|
||||
// Each remembered list is floored like trackedTokens, because
|
||||
// applyChainSwitchFields() puts it straight back onto trackedTokens when
|
||||
// its network becomes the active one. A key that is not a network in
|
||||
// networks.js is dropped, which also keeps an own "__proto__" key from
|
||||
// reaching the plain assignment below.
|
||||
out.networkTrackedTokens = {};
|
||||
if (isRecord(saved.networkTrackedTokens)) {
|
||||
for (const netId of Object.keys(saved.networkTrackedTokens)) {
|
||||
if (!isKnownNetworkId(netId)) continue;
|
||||
out.networkTrackedTokens[netId] = structuredClone(
|
||||
tokenRefs(saved.networkTrackedTokens[netId]),
|
||||
);
|
||||
}
|
||||
}
|
||||
// The loud refusal for an unknown id is assertStateUsable(); this is the
|
||||
// floor under it. networkId is an object KEY into networkEndpoints below,
|
||||
// so a value that is not a network in networks.js must never get that far
|
||||
|
||||
Reference in New Issue
Block a user