Scope
File: src/components/providers/WalletProvider.tsx
Problem
When users switch between multiple Stellar accounts (multi-grid key management), stale contract state and cached RPC responses persist in React context, IndexedDB, and local storage. This creates race conditions where view components render stale balances, incorrect resource meter data, or orphaned transaction histories belonging to the previously selected account.
Requirements
- Implement a
purgeCache() pipeline that atomically clears:
- React context state (
account, accounts)
localStorage entries (utility-wallet-session, utility-wallet-accounts, utility-auth-session)
- IndexedDB stores in
src/services/cache.ts scoped to the old account key prefix
- In-flight RPC request abort controller
- Introduce a
cacheVersion ref counter incremented on every switch.
- Ensure all async effects in descendant hooks observe
cacheVersion via a shared context value before resolving stale promises.
- Add a
switchAccount guard that serializes execution via a module-level promise chain to prevent concurrent switch race conditions.
Resolution Strategy
- Lift
cacheVersion into a useRef inside WalletProvider and expose it via context.
- Wrap
switchAccount with a shared Promise.resolve() chain (monitored mutex pattern).
- Call
cacheClear() from src/services/cache.ts filtered by account key prefix after each switch.
- Abort any active
AbortController from src/services/api.ts on switch.
Tags
wallet, race-condition, cache, high-priority
Scope
File:
src/components/providers/WalletProvider.tsxProblem
When users switch between multiple Stellar accounts (multi-grid key management), stale contract state and cached RPC responses persist in React context, IndexedDB, and local storage. This creates race conditions where view components render stale balances, incorrect resource meter data, or orphaned transaction histories belonging to the previously selected account.
Requirements
purgeCache()pipeline that atomically clears:account,accounts)localStorageentries (utility-wallet-session,utility-wallet-accounts,utility-auth-session)src/services/cache.tsscoped to the old account key prefixcacheVersionref counter incremented on every switch.cacheVersionvia a shared context value before resolving stale promises.switchAccountguard that serializes execution via a module-level promise chain to prevent concurrent switch race conditions.Resolution Strategy
cacheVersioninto auseRefinsideWalletProviderand expose it via context.switchAccountwith a sharedPromise.resolve()chain (monitored mutex pattern).cacheClear()fromsrc/services/cache.tsfiltered by account key prefix after each switch.AbortControllerfromsrc/services/api.tson switch.Tags
wallet, race-condition, cache, high-priority