Skip to content

feat: add response caching to wallet integration #624

Open
0xjerah wants to merge 1 commit into
rinafcode:mainfrom
0xjerah:feat/wallet-response-caching
Open

feat: add response caching to wallet integration #624
0xjerah wants to merge 1 commit into
rinafcode:mainfrom
0xjerah:feat/wallet-response-caching

Conversation

@0xjerah
Copy link
Copy Markdown

@0xjerah 0xjerah commented May 30, 2026

Summary

  • Adds a WalletCache class (src/utils/web3/walletCache.ts) with generic TTL-based in-memory caching and prefix-based invalidation
  • Caches NFT gallery responses for 5 minutes, DeFi staking positions for 60 seconds, and native balance for 30 seconds
  • Cache is automatically invalidated on wallet disconnect, and kept in sync after stake/unstake mutations
  • Adds fetchBalance to useWeb3Wallet — fetches native ETH/MATIC balance via eth_getBalance and caches the result
  • Extends queryKeys.ts with wallet-specific key factories (balance, nfts, positions, transactions)
  • Exports all cache primitives (WalletCache, walletCache, walletCacheKeys, CACHE_TTL) from @/utils/web3

Test plan

  • 23 unit tests for WalletCache covering get/set/has/delete/clear/invalidateByPrefix/size, TTL expiry, key builders, and TTL constants — all passing
  • Verify NFT gallery does not re-fetch on tab switch within 5-minute window
  • Verify balance updates within 30 seconds after a transaction
  • Verify positions re-fetch after stake/unstake (cache is invalidated)
  • Verify cache clears on wallet disconnect

Closes #374

Implements TTL-based in-memory response caching across the wallet
integration — NFT gallery (5 min), DeFi positions (60 s), and native
balance (30 s). Cache is invalidated on disconnect, stake, and unstake.
Adds walletCacheKeys, CACHE_TTL constants, wallet query keys, and 23
passing unit tests for the new WalletCache utility.
@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented May 30, 2026

@0xjerah Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

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.

refactor Wallet Integration : Response Caching

1 participant