feat(frontend): separate server state from mutable UI state - #1
Open
Fabluchy wants to merge 1 commit into
Open
Conversation
- Install @tanstack/react-query v5 as the server-state caching layer - Add QueryProvider wrapper (lib/QueryProvider.tsx) and mount in layout.tsx - Refactor lib/api.ts: replace class methods with plain async functions covering vaults, streak, discipline score, achievements, and fiat flows - Refactor types/index.ts: introduce UIPreferences type and queryKeys factory; keep server types (Vault, Streak, DisciplineScore, etc.) separate - Refactor stores/index.ts: Zustand now stores only wallet connection state and UIPreferences (persisted via zustand/middleware persist); all financial data removed from the store - Refactor hooks/useVault.ts: useVaults, useVaultById, useCreateVault, useDeposit, useWithdraw all use useQuery / useMutation; mutations invalidate the relevant query keys on success - Refactor hooks/useWallet.ts: connect/disconnect invalidate all financial query caches to prevent stale data bleeding across wallet sessions - Add hooks/useStreak.ts: useStreak, useDisciplineScore, useAchievements - Update features/vaults/VaultList.tsx: full implementation with loading skeletons, error state with retry, empty state, and vault cards - Update features/streaks/StreakTracker.tsx: full implementation with stat cards, loading skeletons, error state, and savings calendar - Fix lib/stellar.ts: remove invalid StellarWallet named import (pre-existing type error that blocked the build) Closes Vaulty-X#19
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Resolves the issue where Zustand stored mutable vault balances, streaks, and discipline scores without caching, loading states, invalidation, or refresh behaviour.
Changes
New dependency
@tanstack/react-query ^5.101.2— server-state cache layerNew files
src/lib/QueryProvider.tsx— TanStack Query client wrapped in'use client'so the root layout stays a server componentsrc/hooks/useStreak.ts—useStreak,useDisciplineScore,useAchievementshooksUpdated files
src/types/index.ts— addedUIPreferences,ColorTheme,queryKeysfactory;Date→stringfor safe JSON round-tripssrc/stores/index.ts— stripped all financial data; Zustand now holds only wallet connection state and UI preferences (persisted viazustand/middleware)src/lib/api.ts— refactored to plainasyncfunctions (no class required); addedfetchVaults,fetchVault,fetchStreak,fetchDisciplineScore,fetchAchievementssrc/hooks/useVault.ts— rewritten withuseQuery/useMutation; mutations invalidate vault, streak, and score caches on successsrc/hooks/useWallet.ts— clears all financial query caches on connect / disconnect / wallet switchsrc/features/vaults/VaultList.tsx— loading skeleton, error state with retry, empty statesrc/features/streaks/StreakTracker.tsx— stats grid, savings calendar, error handlingsrc/app/layout.tsx— wrapped withQueryProvidersrc/lib/stellar.ts— removed invalidStellarWalletnamed import (fixes pre-existing type error)Acceptance criteria
useWalletremoves all financial queries on connect/disconnectpartializepersistspreferences+walletonlyCloses Vaulty-X#19