1 Commits
Author SHA1 Message Date
sneak 3ff84c6b18 fix: a network switch in Settings leaves no balance from the previous network stored (closes #653)
check / check (push) Canceled after 0s
e2e / e2e-chrome (push) Canceled after 0s
e2e / e2e-firefox (push) Canceled after 0s
A save writes only the fields that differ from what the page last saved. When
the page had last saved a balance of "0", the switch's cleared "0" was no
change. So a balance that the background or another page stored since then
stayed under the new network.

The switch's save now also resets these fields in the stored record it reads:

- every address's balance and token balances;
- the time of the last balance refresh.

Every other field merges as before.

Model: opus-5-5
2026-10-27 08:39:44 +00:00
3 changed files with 5 additions and 5 deletions
+1 -1
View File
@@ -48,7 +48,7 @@ function clearPopupCaches() {
// waits for the lock (followStoredSettings() in src/popup/index.js): that
// follow runs first, and this switch is made after it.
//
// The save writes only the fields that this page changed since its last save.
// The save writes only the fields that differ from what this page last saved.
// When this page last saved a balance of "0", clearing that balance is no
// change. So the switch also resets these fields in the stored record:
//
+3 -3
View File
@@ -592,9 +592,9 @@ function reportSaveFailure(err) {
// `beforeWrite`, when given, is called inside the lock with the stored record
// as just read, before this page's state is compared against it. It may change
// `state`, and this save writes that change. It may also change the stored
// record: a field that this page did not change is written as `beforeWrite`
// left it. When it returns false, nothing is written; any other return lets the
// save go ahead.
// record. A field that this page did not change is then written as
// `beforeWrite` left it. When it returns false, nothing is written; any other
// return lets the save go ahead.
function saveState(beforeWrite) {
const turn = withLock("autistmask", () => saveStateOnce(beforeWrite));
// Every failed save is reported, whether or not the caller awaited this
+1 -1
View File
@@ -199,7 +199,7 @@ test("a token another page tracked before a switch in Settings stays in trackedT
// The contract lookup on SettingsAddToken answers on Ethereum Mainnet while the
// switch to Sepolia waits for the lock. The page adds the token to Ethereum
// Mainnet's list, and the switch then keeps that list for Ethereum Mainnet.
// Mainnet's list. The switch then keeps that list for Ethereum Mainnet.
test("a token added while a switch in Settings waits for the lock stays tracked on Ethereum Mainnet", async () => {
const boot = await bootOnAddToken("mainnet");
expect(boot.pageErrors).toEqual([]);