Skip to content

Cache and restore wallets#703

Open
paullinator wants to merge 4 commits intomasterfrom
paul/cacheWallets
Open

Cache and restore wallets#703
paullinator wants to merge 4 commits intomasterfrom
paul/cacheWallets

Conversation

@paullinator
Copy link
Member

@paullinator paullinator commented Feb 4, 2026

Improve login performance by caching wallet state on a per account level in unencrypted JSON file and rehydrate before wallets load.

CHANGELOG

Does this branch warrant an entry to the CHANGELOG?

  • Yes
  • No

Dependencies

none

Description

none

Note

Medium Risk
Touches the login/account startup path and changes what EdgeAccount.currencyWallets returns before keys/engines load, which could cause subtle UI or lifecycle regressions if cache data is stale or delegation/update behavior is wrong.

Overview
Implements cache-first login by loading accountCache/<storageWalletId>/walletCache.json during accountPixie startup and immediately exposing cached EdgeCurrencyWallet objects (with background loading of the normal files/engines when cache is present).

Adds a new cache subsystem (cache-wallet-loader/cached-currency-wallet/cached-currency-config/cleaners/utils) that validates cached JSON, constructs delegating wallet/config objects that fall back to real engines when available, supports delegating otherMethods and wallet disklets, and ensures yaob propagation by calling update(wallet) in key setters.

Introduces an auto-saving, throttled cache writer (makeWalletCacheSaver) wired into accountPixie to persist active wallet state (balances, enabled tokens, public info, selected token definitions, and otherMethods names) with failure backoff; makeAccountApi now optionally merges cached wallets/IDs until keys are loaded. Includes extensive end-to-end tests plus fake-plugin hooks to deterministically gate engine startup and simulate missing otherMethods, and adds documentation for the architecture.

Written by Cursor Bugbot for commit 28424f6. This will update automatically on new commits. Configure here.

@cursor

This comment has been minimized.

result[walletId] = wallet
}
}
return result
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Getter always allocates new object reducing bridge efficiency

Low Severity

When cacheSetup is non-null (for the lifetime of the account after a cache-first login), the currencyWallets getter always allocates a new result object on every access. The watcher pixie calls update(accountApi) on every Redux state change, causing yaob to re-read this getter, see a new object reference, and push the full wallet map over the bridge—even when the underlying wallet set hasn't changed. Previously the getter returned a stable reference from the pixie output.

Fix in Cursor Fix in Web

@cursor

This comment has been minimized.

paullinator and others added 4 commits February 18, 2026 14:41
Add missing return in fake plugin getBalance for token balance.
Improve @ts-expect-error comment and log swap quote close errors.

Co-authored-by: Cursor <cursoragent@cursor.com>
Improve login performance by caching wallet state on a per account level in unencrypted JSON file and rehydrate before wallets load.
fixup! Cache and restore wallets

Co-authored-by: Cursor <cursoragent@cursor.com>
fixup! Cache and restore wallets

Review feedback:
- W2: Add account existence check in background .catch handler
- W3: Add comment about coupling to disklet error format
- W4: Pass error directly to log instead of String(error)
- S1: Use asJSON instead of JSON.parse for better error context
- S4: Fix misleading retry comment in cache saver
- S5: Add comments explaining .catch(() => {}) in scheduleSave
- S6: Increase poll interval from 300ms to 500ms
- S7: Remove outdated JSDoc clause about GUI waiting

Co-authored-by: Cursor <cursoragent@cursor.com>
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is ON. A Cloud Agent has been kicked off to fix the reported issue.

@cursor
Copy link

cursor bot commented Feb 18, 2026

Bugbot Autofix prepared fixes for 1 of the 1 bugs found in the latest run.

  • ✅ Fixed: Initial cache save overwrites token definitions with empty data
    • Added a check for accountState.keysLoaded before triggering the initial cache save, ensuring builtinTokens are populated in Redux before the cache is written.

Create PR

Or push these changes by commenting:

@cursor push cfdb37f5a6
Preview (cfdb37f5a6)
diff --git a/src/core/account/account-pixie.ts b/src/core/account/account-pixie.ts
--- a/src/core/account/account-pixie.ts
+++ b/src/core/account/account-pixie.ts
@@ -362,8 +362,10 @@
 
           if (cacheSaver == null) return
 
-          // Trigger initial save to persist cached wallet data from login
-          if (!initialSaveDone) {
+          // Trigger initial save to persist cached wallet data from login.
+          // Wait until keysLoaded is true to ensure builtinTokens are populated,
+          // avoiding overwriting cached tokens with empty data during cache-first login.
+          if (!initialSaveDone && accountState.keysLoaded) {
             initialSaveDone = true
             cacheSaver.markDirty()
             return

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments