Skip to content

#413 refactor: Redux store shape is overly nested simplify FIXED - #572

Merged
dadadave80 merged 1 commit into
Heliobond:mainfrom
veloura-dev:#413-refactor--Redux-store-shape-is-overly-nested-simplify-FIX
Sep 6, 2026
Merged

#413 refactor: Redux store shape is overly nested simplify FIXED#572
dadadave80 merged 1 commit into
Heliobond:mainfrom
veloura-dev:#413-refactor--Redux-store-shape-is-overly-nested-simplify-FIX

Conversation

@veloura-dev

Copy link
Copy Markdown
Contributor

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:

  • 20 one-level selectors (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.
  • 11 consumer files refactored off the nested shape: Portfolio, Landing, Deposit, Explore, Watchlist, ProjectDetail, wallet/useVault.ts, wallet/vault.ts, lib/api.ts, data/admin.ts, alerts/YieldAlertProvider.tsx, app/sitemap.ts.
  • New tests (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).
  • Behavior-preserving: rendered output and values are unchanged.

Note for reviewers: main currently ships with pre-existing breakage that blocked build/tests for everyone (duplicated getRiskIndicator / formatSharePrice / validateAddress from merges, 3 files with syntax errors, a corrupted XSS/SQL-detection regex that matched every address, a TDZ crash on the Deposit screen, next/headers imported into the client bundle via i18n/request.ts, two stylesheets imported but missing, a PriceHistoryChart component imported but missing, and 5 i18n keys missing from all locales). These were masked on main because 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-main baseline. Full file-by-file breakdown: FIX_MANIFEST.md.

Type of change

  • Bug fix
  • Feature
  • Localization (i18n)
  • Accessibility
  • Smart contract / on-chain wiring
  • Docs / chore

Screenshots / screencast

N/A — behavior-preserving refactor; no visible UI change (light/dark render identically to before). The restored PriceHistoryChart renders 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

  • Tied to an accepted issue (Closes #…)
  • bun run build passes locally (builds + type-checks)
  • Follows the design system — token CSS vars, sentence case, mono numerals, deltas carry sign + arrow, no emoji, no hardcoded colours
  • User-facing strings added to both messages/en.json and messages/fr.json (if any copy changed)
  • Accessible — keyboard operable, visible focus, reduced-motion respected
  • No secrets committed
  • Docs updated where relevant

Validation

Gate Before After
tsc --noEmit ❌ 10 syntax errors (+~91 latent type errors hidden behind them) ✅ 0 errors
vitest run ❌ 24 files unloadable · 177 tests passing 47/47 files · 372/372 tests (incl. 33 new)
next build ❌ fails (syntax → CSS → client/server i18n errors) ✅ all 17 routes
Prod smoke ✅ 200 on /, /explore, /project/1, /portfolio
Deep-drill audit 5-level chains in 14 consumer files ✅ 0 nested-store chains outside the selector layer

@vercel

vercel Bot commented Sep 6, 2026

Copy link
Copy Markdown

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

@drips-wave

drips-wave Bot commented Sep 6, 2026

Copy link
Copy Markdown

@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! 🚀

Learn more about application limits

@sshdopey sshdopey left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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! ❤️

@sshdopey

sshdopey commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

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.

@dadadave80
dadadave80 merged commit 74fafed into Heliobond:main Sep 6, 2026
2 of 3 checks 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.

refactor: Redux store shape is overly nested — simplify

3 participants