Skip to content

feat: implement standardized react query cache architecture and optim…#88

Merged
EmeditWeb merged 4 commits into
StepFi-app:mainfrom
sublime247:feat/react-query-cache-architecture
Jul 22, 2026
Merged

feat: implement standardized react query cache architecture and optim…#88
EmeditWeb merged 4 commits into
StepFi-app:mainfrom
sublime247:feat/react-query-cache-architecture

Conversation

@sublime247

Copy link
Copy Markdown
Contributor

Closes #84

Features & Enhancements

1. Canonical Query Key Factory

  • Introduced src/services/queryKeys.ts with 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)
  • Added invalidateSubtree helper mapping mutations to exact query subtree invalidations.

2. Global QueryClient Defaults

  • Configured global QueryClient options in src/main.tsx:
    • staleTime: 5 * 60 * 1000 (5 minutes)
    • gcTime: 30 * 60 * 1000 (30 minutes)
    • retry: 1
    • refetchOnWindowFocus: false

3. 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

  • Refactored Sponsors, SponsorOnboarding, Vendors, VendorDetail, VendorDashboard, Vouch, and LearnerProfile to consume standardized query keys and optimistic hooks.

Verification & Testing

  • Unit Tests: Added src/services/__tests__/queryKeys.test.ts and src/hooks/__tests__/optimisticMutations.test.ts. npm test passes with 30 tests.
  • Linting: npm run lint passes with 0 errors and 0 warnings.
  • Production Build: npm run build compiles with 0 errors.
  • Mobile Viewport: Tested on 375px viewport layout.

@sublime247
sublime247 requested a review from EmeditWeb as a code owner July 20, 2026 11:31

@EmeditWeb EmeditWeb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@sublime247

Copy link
Copy Markdown
Contributor Author

@EmeditWeb can you please check now?

@sublime247

Copy link
Copy Markdown
Contributor Author

@EmeditWeb any update as regards reviewing?

@EmeditWeb

Copy link
Copy Markdown
Member

I'm currently auditing them. Thanks for your work

@EmeditWeb EmeditWeb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@EmeditWeb
EmeditWeb merged commit 482262e into StepFi-app:main Jul 22, 2026
1 check 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.

core: implement React Query cache architecture with optimistic updates

2 participants