feat: implement standardized react query cache architecture and optim…#88
Conversation
EmeditWeb
left a comment
There was a problem hiding this comment.
Review verdict: ✅ APPROVE
Well-structured cache architecture. Verified locally: build passes, lint clean, tests pass (30). Standards are clean — no hardcoded hex, no API calls in page components, no any. The centralized queryKeys factory (with its own test) plus the useOptimisticProduct / useOptimisticVouch hooks are a solid, maintainable pattern, and the page refactors to consume them are consistent.
One thing to confirm before merge (non-blocking): the two optimistic-update hooks should roll back to the previous cache snapshot on mutation error (onError restoring the pre-mutation data) and reconcile via onSettled/invalidate. If that's already covered by the tests, great; if not, please add a rollback path so a failed mutation doesn't leave stale optimistic state in the UI.
Approve.
…egacy peer dependencies
…ache-architecture
|
@EmeditWeb can you please check now? |
|
@EmeditWeb any update as regards reviewing? |
|
I'm currently auditing them. Thanks for your work |
EmeditWeb
left a comment
There was a problem hiding this comment.
Re-audited on current head: build passes, eslint . clean, 36 tests pass, CI green. Optimistic updates correctly implement rollback (onMutate snapshots previous cache, onError restores via setQueryData) — my earlier note is addressed. This branch merged in #87; soroban.service.ts is byte-identical to what's now on main (#87 merged first), so it auto-resolves with no duplication. Approving and merging.
Closes #84
Features & Enhancements
1. Canonical Query Key Factory
src/services/queryKeys.tswith a central, hierarchical Query Key Factory covering:queryKeys.pool(all,info,stats)queryKeys.loans(all,lists,myLoans,borrower,detail)queryKeys.vouches(all,requests,myVouches,forLearner)queryKeys.vendors(all,lists,list,detail,dashboard,vendorLoans,payments,products,apiKeys)queryKeys.reputation(all,score,profile,history)invalidateSubtreehelper mapping mutations to exact query subtree invalidations.2. Global QueryClient Defaults
src/main.tsx:staleTime: 5 * 60 * 1000(5 minutes)gcTime: 30 * 60 * 1000(30 minutes)retry: 1refetchOnWindowFocus: false3. High-Frequency Optimistic Mutations & Automatic Rollback
useOptimisticVouch: Optimistically removes pending requests / adds active vouches on submit, restores previous snapshot on error, and invalidates affected query subtrees.useOptimisticProduct: Optimistically creates, updates, and deletes vendor products in cache with instant UI updates and rollback on failure.useOptimisticDeposit: Optimistically updates pool liquidity & deposit totals during transaction processing with rollback on error.4. Page Integration
Sponsors,SponsorOnboarding,Vendors,VendorDetail,VendorDashboard,Vouch, andLearnerProfileto consume standardized query keys and optimistic hooks.Verification & Testing
src/services/__tests__/queryKeys.test.tsandsrc/hooks/__tests__/optimisticMutations.test.ts.npm testpasses with 30 tests.npm run lintpasses with 0 errors and 0 warnings.npm run buildcompiles with 0 errors.