Skip to content

Issue 1: Asynchronous Web3 Account-Switching Cache Purging Pipeline #1

Description

@elizabetheonoja-art

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

  1. 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
  2. Introduce a cacheVersion ref counter incremented on every switch.
  3. Ensure all async effects in descendant hooks observe cacheVersion via a shared context value before resolving stale promises.
  4. 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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions