fix: a network switch in Settings leaves no balance from the previous network stored (closes #653)
The switch is now made on the stored record that its save has just read. The switched fields are then copied into the page's state. A save writes only the fields that the page changed since its last save. A switch made on the page's state alone mishandled what another page stored since then: - A balance from the previous network stayed under the new network. - A token tracked on the previous network moved to the new network. - An endpoint URL saved for the previous network was replaced by the page's older one. Tests store each of these before the switch and check the stored record after it. Model: opus-5-5
This commit is contained in:
@@ -47,6 +47,7 @@ function loadModuleWith(persisted) {
|
||||
return {
|
||||
mod: require("../src/shared/state"),
|
||||
chainSwitch: require("../src/shared/chainSwitch"),
|
||||
storage,
|
||||
written: () => storage.read("autistmask"),
|
||||
};
|
||||
}
|
||||
@@ -105,6 +106,27 @@ describe("a custom endpoint survives a chain switch", () => {
|
||||
expect(mod.state.rpcUrl).toBe(CUSTOM_RPC);
|
||||
});
|
||||
|
||||
// Another page saves the user's own node for Ethereum Mainnet after this
|
||||
// page's last save. This page's switch keeps that node for Ethereum
|
||||
// Mainnet.
|
||||
test("an endpoint another page saved for the network being left is remembered", async () => {
|
||||
const { mod, chainSwitch, storage, written } = loadModuleWith({
|
||||
wallets: walletFixture(),
|
||||
networkId: "mainnet",
|
||||
rpcUrl: MAINNET.defaultRpcUrl,
|
||||
blockscoutUrl: MAINNET.defaultBlockscoutUrl,
|
||||
networkEndpoints: {},
|
||||
});
|
||||
await mod.loadState();
|
||||
storage.write("autistmask", { ...written(), rpcUrl: CUSTOM_RPC });
|
||||
|
||||
await chainSwitch.onChainSwitch("sepolia");
|
||||
expect(written().networkEndpoints.mainnet.rpcUrl).toBe(CUSTOM_RPC);
|
||||
|
||||
await chainSwitch.onChainSwitch("mainnet");
|
||||
expect(mod.state.rpcUrl).toBe(CUSTOM_RPC);
|
||||
});
|
||||
|
||||
test("the remembered endpoints survive an extension restart", async () => {
|
||||
const first = loadModuleWith({
|
||||
wallets: walletFixture(),
|
||||
|
||||
Reference in New Issue
Block a user