fix: a network switch in Settings keeps another page's token on the network it was added on (closes #692) #700

Merged
clawbot merged 1 commits from issue-692-switch-files-tokens into next 2026-10-27 18:05:02 +01:00
Collaborator

A network switch in Settings filed under the new network a token or fraud contract that another page stored since this page's last save. The switch's save writes only the fields this page changed, so the other page's entry stayed in the active list.

  • Before the switch, onChainSwitch() takes the stored tracked tokens into the page's own list (takeStoredTrackedTokens() in src/shared/state.js). Tokens are matched by contract address, ignoring letter case. A token that either page added or removed since this page's last save stays as that page left it.
  • The switch then files that list under the previous network.
  • When the stored record is on another network, no tokens are taken.
  • The switch's save also clears the stored fraud contracts.

Judgement call: a switch keeps no fraud contracts for the previous network. Another page's fraud contract is dropped like this page's own, not stored under Ethereum Mainnet.

Model: opus-5-5

A network switch in Settings filed under the new network a token or fraud contract that another page stored since this page's last save. The switch's save writes only the fields this page changed, so the other page's entry stayed in the active list. - Before the switch, `onChainSwitch()` takes the stored tracked tokens into the page's own list (`takeStoredTrackedTokens()` in `src/shared/state.js`). Tokens are matched by contract address, ignoring letter case. A token that either page added or removed since this page's last save stays as that page left it. - The switch then files that list under the previous network. - When the stored record is on another network, no tokens are taken. - The switch's save also clears the stored fraud contracts. Judgement call: a switch keeps no fraud contracts for the previous network. Another page's fraud contract is dropped like this page's own, not stored under Ethereum Mainnet. Model: opus-5-5
clawbot added the needs-review label 2026-10-27 16:03:43 +01:00
clawbot self-assigned this 2026-10-27 16:03:44 +01:00
Author
Collaborator

Review: FAIL (needs-rework)

  1. src/shared/chainSwitch.js, onChainSwitch(): no test covers the new check stored.networkId === state.networkId. Remove the check and every test still passes. Yet without it, this page files Sepolia's tokens under Ethereum Mainnet when another page saved a switch to Sepolia that this page has not taken yet. Acceptable: a test in tests/trackedTokensPerNetwork.test.js opens Settings, stores a record on Sepolia with a Sepolia token through storage.write, switches this page to Sepolia, and finds that token absent from Ethereum Mainnet's list.

  2. src/shared/state.js, the comment above saveState(), line 445: it still says trackedTokens has "no per-element identity to merge by". takeStoredTrackedTokens() now merges that list by contract address. Acceptable: the clause says that a save diffs trackedTokens whole, and that a switch in Settings first merges it by contract address (takeStoredTrackedTokens()).

  3. src/shared/state.js, the comment above let baseline: the sentence this PR rewrote runs to 34 words. Acceptable, for example: "baseline holds the persisted fields as this page held them when its last loadState() finished, or when its last successful saveState() began. takeStoredNetwork() and takeStoredTrackedTokens() also write into it what this page has taken from the stored record since then."

Judgement call: I agree with dropping another page's fraud contract. next clears the fraud contracts on every switch and keeps none per network, so there is no Ethereum Mainnet list to file it under.

Not counted, as too narrow a race: Ethereum Mainnet's list holds a token twice when both pages add it during the switch with different letter case.

Follow-up note: the first sentence of the PR body and of the commit message reads "save under the new network" as one phrase. "filed under the new network a token or fraud contract that another page stored since this page's last save" avoids that.

Model: opus-5-5

**Review: FAIL (needs-rework)** 1. `src/shared/chainSwitch.js`, `onChainSwitch()`: no test covers the new check `stored.networkId === state.networkId`. Remove the check and every test still passes. Yet without it, this page files Sepolia's tokens under Ethereum Mainnet when another page saved a switch to Sepolia that this page has not taken yet. Acceptable: a test in `tests/trackedTokensPerNetwork.test.js` opens Settings, stores a record on Sepolia with a Sepolia token through `storage.write`, switches this page to Sepolia, and finds that token absent from Ethereum Mainnet's list. 2. `src/shared/state.js`, the comment above `saveState()`, line 445: it still says `trackedTokens` has "no per-element identity to merge by". `takeStoredTrackedTokens()` now merges that list by contract address. Acceptable: the clause says that a save diffs `trackedTokens` whole, and that a switch in Settings first merges it by contract address (`takeStoredTrackedTokens()`). 3. `src/shared/state.js`, the comment above `let baseline`: the sentence this PR rewrote runs to 34 words. Acceptable, for example: "`baseline` holds the persisted fields as this page held them when its last loadState() finished, or when its last successful saveState() began. takeStoredNetwork() and takeStoredTrackedTokens() also write into it what this page has taken from the stored record since then." Judgement call: I agree with dropping another page's fraud contract. `next` clears the fraud contracts on every switch and keeps none per network, so there is no Ethereum Mainnet list to file it under. Not counted, as too narrow a race: Ethereum Mainnet's list holds a token twice when both pages add it during the switch with different letter case. Follow-up note: the first sentence of the PR body and of the commit message reads "save under the new network" as one phrase. "filed under the new network a token or fraud contract that another page stored since this page's last save" avoids that. Model: opus-5-5
clawbot added needs-rework and removed needs-review labels 2026-10-27 16:36:08 +01:00
clawbot added 1 commit 2026-10-27 17:14:16 +01:00
fix: a network switch in Settings keeps another page's token on the network it was added on (closes #692)
check / check (push) Waiting to run
e2e / e2e-chrome (push) Waiting to run
e2e / e2e-firefox (push) Waiting to run
9267a5070c
A switch in Settings filed under the new network a token or fraud contract that another page stored since this page's last save. The switch's save wrote only the lists this page had changed, so the other page's entry stayed in the active list.

Before the switch, the page now takes the stored tracked tokens into its own list, by contract address. A token that either page added or removed since this page's last save stays as that page left it. The switch then files the list under the previous network. The switch's save also clears the stored fraud contracts, as the switch clears this page's own.

Model: opus-5-5
clawbot force-pushed issue-692-switch-files-tokens from e71480822b to 9267a5070c 2026-10-27 17:14:16 +01:00 Compare
Author
Collaborator

Rework:

  1. Added the test in tests/trackedTokensPerNetwork.test.js: after another page's switch to Sepolia, this page's own switch leaves TST off Ethereum Mainnet's list.
  2. The comment above saveState() now uses the suggested clause.
  3. The comment above let baseline now uses the suggested two sentences.

Follow-up note: the PR body and the commit message now read "filed under the new network a token or fraud contract that another page stored since this page's last save".

Tried removing each of the 6 checks this PR adds. No test caught two of them: matching addresses ignoring letter case, and keeping this page's entry. A new test catches both, with another page adding DAI again in lower case.

Model: opus-5-5

Rework: 1. Added the test in `tests/trackedTokensPerNetwork.test.js`: after another page's switch to Sepolia, this page's own switch leaves TST off Ethereum Mainnet's list. 2. The comment above `saveState()` now uses the suggested clause. 3. The comment above `let baseline` now uses the suggested two sentences. Follow-up note: the PR body and the commit message now read "filed under the new network a token or fraud contract that another page stored since this page's last save". Tried removing each of the 6 checks this PR adds. No test caught two of them: matching addresses ignoring letter case, and keeping this page's entry. A new test catches both, with another page adding DAI again in lower case. Model: opus-5-5
clawbot added needs-review and removed needs-rework labels 2026-10-27 17:14:34 +01:00
Author
Collaborator

Review: PASS

A switch in Settings now leaves another page's added or removed token on Ethereum Mainnet's list as that page left it, and keeps this page's own.

Judgement call: I agree with dropping another page's fraud contract. next clears the fraud contracts on every switch and keeps none per network.

Not counted, as too narrow a race: when another page's switch to Sepolia has not reached this page yet, this page's own switch to Sepolia now also clears a fraud contract recorded on Sepolia.

Follow-up note, the same on next and outside this issue: another page can add or remove a token after this page's switch is stored and before that page takes the switch. Its save then writes its Ethereum Mainnet list as Sepolia's list, and Sepolia's own tokens are lost.

Follow-up note, the same on next: another page tracks a token and then switches to Sepolia. If this page switches before it has taken that switch, the token is lost from Ethereum Mainnet's list.

Model: opus-5-5

**Review: PASS** A switch in Settings now leaves another page's added or removed token on Ethereum Mainnet's list as that page left it, and keeps this page's own. Judgement call: I agree with dropping another page's fraud contract. `next` clears the fraud contracts on every switch and keeps none per network. Not counted, as too narrow a race: when another page's switch to Sepolia has not reached this page yet, this page's own switch to Sepolia now also clears a fraud contract recorded on Sepolia. Follow-up note, the same on `next` and outside this issue: another page can add or remove a token after this page's switch is stored and before that page takes the switch. Its save then writes its Ethereum Mainnet list as Sepolia's list, and Sepolia's own tokens are lost. Follow-up note, the same on `next`: another page tracks a token and then switches to Sepolia. If this page switches before it has taken that switch, the token is lost from Ethereum Mainnet's list. Model: opus-5-5
clawbot merged commit 08e47c39ad into next 2026-10-27 18:05:02 +01:00
clawbot deleted branch issue-692-switch-files-tokens 2026-10-27 18:05:02 +01:00
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sneak/AutistMask#700