#413 refactor: Redux store shape is overly nested simplify FIXED - #572
Conversation
|
@veloura-dev is attempting to deploy a commit to the David Dada's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
@veloura-dev 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! 🚀 |
sshdopey
left a comment
There was a problem hiding this comment.
This is a thorough refactor that directly addresses the nested state issue with a clean flat selector layer and updates all consumers. The added tests and documentation show great care. Thanks for also fixing the pre-existing build blockers to validate your work — that's above and beyond! The changes are behavior-preserving and well-tested. Great job! ❤️
|
Approved! 🎉 I couldn't auto-merge this just yet (it may need a rebase or have a check still running). A maintainer can merge it whenever it's ready. |
Summary
CLOSE #413
Accessing app state required drilling through up to 5 levels of nested structure (
HB_DATA.pool.*,d.you.deltaAbs.toLocaleString(...),detail.scoreHistory.credit.map(...), …) because the app state lives in one nested singleton (src/data.ts,src/data/projectDetails.ts) and had no selector layer at all.This PR introduces a flat selector layer (
src/state/selectors.ts) and refactors every consumer to read state through it:selectPoolSummary,selectYou,selectProjects,selectProjectById,selectScoreHistory,selectScoreValueHistory,selectCreator,selectActivity,selectPriceHistory,searchProjects, …). Every selector returns flat scalars/arrays — one level, by contract — with derived values (e.g.deployed = totalAssets − liquid) precomputed so no consumer re-derives them from nested branches.wallet/useVault.ts,wallet/vault.ts,lib/api.ts,data/admin.ts,alerts/YieldAlertProvider.tsx,app/sitemap.ts.src/state/selectors.test.ts) enforce the contract: values match the store roots exactly and every summary result is flat (helper fails if any returned value is an object).Note for reviewers:
maincurrently ships with pre-existing breakage that blocked build/tests for everyone (duplicatedgetRiskIndicator/formatSharePrice/validateAddressfrom merges, 3 files with syntax errors, a corrupted XSS/SQL-detection regex that matched every address, a TDZ crash on the Deposit screen,next/headersimported into the client bundle viai18n/request.ts, two stylesheets imported but missing, aPriceHistoryChartcomponent imported but missing, and 5 i18n keys missing from all locales). These were masked onmainbecause type-checking bailed at the syntax errors. Repairing them was required to validate this fix and is included here, all behavior-preserving, and verified against a pristine-mainbaseline. Full file-by-file breakdown:FIX_MANIFEST.md.Type of change
Screenshots / screencast
N/A — behavior-preserving refactor; no visible UI change (light/dark render identically to before). The restored
PriceHistoryChartrenders the pricing section on/project/[id]exactly as the already-merged page code (project/[id]/page.tsx) intended — it was previously a missing import (runtime/build error), so "before" was an error state, not a visual baseline.Checklist
Closes #…)bun run buildpasses locally (builds + type-checks)messages/en.jsonandmessages/fr.json(if any copy changed)Validation
tsc --noEmitvitest runnext build/,/explore,/project/1,/portfolio