Skip to content

fix(wallet): clear React Query cache on Stellar wallet disconnect#214

Open
PrettyFox0 wants to merge 1 commit into
Neko-Protocol:devfrom
PrettyFox0:fix/clear-query-cache-on-disconnect
Open

fix(wallet): clear React Query cache on Stellar wallet disconnect#214
PrettyFox0 wants to merge 1 commit into
Neko-Protocol:devfrom
PrettyFox0:fix/clear-query-cache-on-disconnect

Conversation

@PrettyFox0

Copy link
Copy Markdown

Closes #208

Summary

`useStellarWallet.disconnect()` previously only cleared the Zustand wallet store; user-specific cached queries (balances, borrow positions, backstop state, etc.) stayed in memory and briefly flashed across features when a second wallet connected in the same session.

Fix

`disconnect()` now calls `queryClient.removeQueries(...)` with a predicate that removes:

  1. Any query whose first key is a known user-scoped prefix (explicit allowlist, documented in the source).
  2. Any query whose key array contains the disconnecting address — catches trailing-address keys like `['orchestrator', 'position', poolId, addr]` that don't fit the prefix list.

Protocol-level queries (pool configs, oracle prices, vault APY) are intentionally left cached — they hold no user data and re-fetching them on every reconnect would add unnecessary latency.

Documented user-scoped prefixes

`backstopDeposit`, `backstopWalletBalance`, `balances`, `borrowLimit`, `cetesBalance`, `etherfuse-assets`, `health-factor`, `kyc-status`, `portfolio-value`, `repayWalletBalance`, `stellar-balances`, `tokenBalance`, `userCollateral`, `userDebt`, `vaultBalance`.

Acceptance criteria

  • `useStellarWallet.ts` calls `queryClient.removeQueries()` for all address-scoped keys on disconnect
  • User-scoped prefixes documented in the source (and PR body)
  • Protocol queries unaffected
  • Connect wallet A → disconnect → connect wallet B → wallet B's data shows immediately, no flash of wallet A's data (manual verification — flagged for reviewer)

Closes Neko-Protocol#208

useStellarWallet.disconnect() previously only cleared the Zustand
wallet store; user-specific cached queries (balances, borrow positions,
backstop state, etc.) stayed in memory and briefly flashed across
features when a second wallet connected in the same session.

Now removes from the cache:
- queries under any known user-scoped key prefix
  (balances, backstopDeposit, borrowLimit, health-factor, kyc-status,
  portfolio-value, tokenBalance, userCollateral, userDebt, vaultBalance,
  ...etc)
- any query whose key array contains the disconnecting address (catches
  trailing-address keys like ['orchestrator', 'position', poolId, addr])

Protocol-level queries (pool configs, oracle prices, vault APY) are
intentionally left cached — they hold no user data.
@vercel

vercel Bot commented May 31, 2026

Copy link
Copy Markdown

Someone is attempting to deploy a commit to the Oppia Software Labs Team on Vercel.

A member of the Team first needs to authorize it.

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.

fix: Clear React Query cache on wallet disconnect

1 participant