Skip to content

feat: add cache-purge pipeline on account switch - #29

Merged
elizabetheonoja-art merged 1 commit into
Utility-Protocol:mainfrom
Timrossid:feat/switch-account-cache-purge
Jun 17, 2026
Merged

feat: add cache-purge pipeline on account switch#29
elizabetheonoja-art merged 1 commit into
Utility-Protocol:mainfrom
Timrossid:feat/switch-account-cache-purge

Conversation

@Timrossid

@Timrossid Timrossid commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Scope

Fixes stale contract state and cached RPC responses persisting when users switch between multiple Stellar accounts.

Changes

WalletProvider (\src/components/providers/WalletProvider.tsx)

  • cacheVersion ref exposed via \WalletContext\ — descendant hooks can observe it before resolving stale promises
  • purgeCache() pipeline atomically clears React context state (\�ccount, \�ccounts), localStorage entries (\utility-wallet-session, \utility-wallet-accounts, \utility-auth-session), IndexedDB stores scoped to the old account key prefix, and aborts in-flight RPC requests
  • switchAccount guard serializes execution via a module-level promise chain (\switchGuard) to prevent concurrent switch race conditions
  • disconnect updated to reuse the same \purgeCache\ pipeline

api.ts (\src/services/api.ts)

  • Added \�ctiveControllers\ Set tracking all in-flight \AbortController\ instances
  • Added \�bortAllRequests()\ exported function to abort all active requests

  • equest()\ registers/unregisters its controller via \ inally\ block for reliable cleanup

cache.ts (\src/services/cache.ts)

  • Added \cacheClearByPrefix(prefix)\ to delete IndexedDB entries matching a given key prefix

Resolution Strategy

  1. \cacheVersion\ (useRef) incremented on every purge and exposed via context
  2. \switchAccount\ wraps inner logic with \switchGuard\ promise chain (mutex pattern)
  3. \purgeCache\ is called inside the mutex, passing the old account address for scoped IndexedDB cleanup
  4. \�bortAllRequests()\ aborts all tracked AbortControllers from \�pi.ts\ on each switch

Closes #1

Implement purgeCache() pipeline that atomically clears React context state,
localStorage entries, IndexedDB stores scoped to the old account key prefix,
and aborts in-flight RPC requests.

- Lift cacheVersion ref and expose it via WalletContext
- Add cacheClearByPrefix() to cache.ts for scoped IndexedDB cleanup
- Add abortAllRequests() to api.ts with tracked active AbortControllers
- Enhance switchAccount with monitored mutex serialization
- Enhance disconnect to use the same purge pipeline
- Register/unregister AbortControllers in api.ts request() via finally block
@elizabetheonoja-art
elizabetheonoja-art merged commit 1de8659 into Utility-Protocol:main Jun 17, 2026
3 checks passed
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.

Issue 1: Asynchronous Web3 Account-Switching Cache Purging Pipeline

2 participants