fix: a chain switch gives trackedTokens its own copy of the network's list (closes #719)
check / check (push) Waiting to run
e2e / e2e-chrome (push) Waiting to run
e2e / e2e-firefox (push) Waiting to run

After a switch, `trackedTokens` and that network's list in
`networkTrackedTokens` were one array. So a page's next add or removal also
changed `networkTrackedTokens`, and the save wrote that page's older copy over
the stored one. Another page's add on the previous network was lost, and its
removal was undone.

`applyChainSwitchFields()` now copies the incoming network's list. An add or
removal on the active network changes only `trackedTokens`.

Model: opus-5-5
This commit was merged in pull request #730.
This commit is contained in:
2026-11-03 07:10:33 +01:00
parent 42a5d94b49
commit ba61bedaaf
2 changed files with 57 additions and 3 deletions
+7 -3
View File
@@ -42,11 +42,15 @@ function applyChainSwitchFields(s, newNetworkId) {
// Tracked tokens are kept per network the same way, because a contract
// address names a token on one network only. s.trackedTokens stays the
// active network's list, so nothing that reads it changes: the outgoing
// list is put away under its network, and the incoming network's list, or
// an empty one, takes its place.
// list is put away under its network, and a copy of the incoming network's
// list, or an empty list, takes its place.
//
// It is a copy because a save writes a changed s.networkTrackedTokens whole,
// over any list another page stored. An add or removal on the active network
// must change only s.trackedTokens.
if (!s.networkTrackedTokens) s.networkTrackedTokens = {};
s.networkTrackedTokens[s.networkId] = s.trackedTokens;
s.trackedTokens = s.networkTrackedTokens[net.id] || [];
s.trackedTokens = structuredClone(s.networkTrackedTokens[net.id] || []);
s.networkId = net.id;
s.rpcUrl = remembered.rpcUrl || net.defaultRpcUrl;