Skip to content

[frontend] Version localStorage keys with a shared envelope and migrate legacy values - #1708

Open
CathyZaks wants to merge 1 commit into
Junirezz:mainfrom
CathyZaks:fix/issue-1627-frontend-version-localstorage-keys-and-c
Open

CathyZaks wants to merge 1 commit into
Junirezz:mainfrom
CathyZaks:fix/issue-1627-frontend-version-localstorage-keys-and-c

Conversation

@CathyZaks

Copy link
Copy Markdown
Contributor

Header

Frontend localStorage hardening for issue #1627: versioned envelopes, legacy migration, session-cleanup coverage.

Problem

Most localStorage keys held raw unversioned values, so a future shape change could not be migrated safely.

Key Before
yieldvault-preferences:<wallet> (usePreferences) bare JSON merge
wallet_session_start raw epoch-ms string
yv_slippage_percent raw number string
yieldvault:first-deposit:<wallet> raw "true"
hasSeenWalkthrough raw "true"

Solution

Added lib/versionedStorage.ts, a {version, data} envelope (same shape as lib/userPreferenceStore.ts). Every listed key now reads and writes through it. A pre-envelope value is detected, passed to a per-key migrateLegacy, and rewritten as an envelope. Unknown-version or corrupt data falls back to defaults.

Preference store decision: usePreferences (theme, locale, currency, notifications, precision) and userPreferenceStore (chart modes, table density, transaction columns) hold disjoint fields and are both composed by PreferencesContext. Both are now versioned envelopes under distinct keys. I did not merge them; see Notes.

Changes

  • lib/versionedStorage.ts (new): readVersionedItem, writeVersionedItem, isVersionedEnvelope.
  • hooks/usePreferences.ts: reads and writes the v1 envelope and migrates the legacy bare object.
  • hooks/useSlippage.ts: v1 envelope, plus migration of the raw value and of the yv_slippage_bps key.
  • lib/walletSession.ts: wallet_session_start is a v1 envelope; legacy raw string is migrated.
  • components/VaultDashboard.tsx: first-deposit flag is a v1 envelope.
  • components/OnboardingWalkthrough.tsx: hasSeenWalkthrough is a v1 envelope.
  • lib/sessionCleanup.ts: documents which keys are cleared and which persist deliberately. wallet_session_start is still cleared in either format.
  • Existing tests were updated for the envelope format.

Regression Tests

Acceptance criterion Test
Migration test from the old key usePreferences.test.ts (legacy object to v1), useSlippage.test.ts (raw and yv_slippage_bps), OnboardingWalkthrough.test.tsx (raw "true"), versionedStorage.test.ts
Each key versioned the same tests, plus walletSession.test.ts, VaultDashboard.test.tsx, AuthContext.test.tsx
sessionCleanup covers keys sessionCleanup.test.ts: clears envelope and legacy wallet_session_start; asserts preference and UX keys persist

Testing

  • npm run lint: 0 errors (37 pre-existing warnings)
  • npm run build: succeeded
  • npx vitest run: 1438 tests. The first full run had 2 failures (wallet session raw-format assertions), which I fixed. The two affected files then passed (26/26).
  • A later vitest run --coverage had 3 timeouts in VaultDashboard.test.tsx under load. The file passes alone (23/23) with and without my change.

Notes for Reviewers

  • Merging usePreferences and userPreferenceStore into one store would touch the context and its consumers. I left it out as beyond the minimal change; the two stores are now consistently versioned.
  • The first-deposit flag is not cleared on disconnect, because clearing it would re-trigger confetti. Preference keys also persist by design.

Closes #1627

@drips-wave

drips-wave Bot commented Oct 21, 2026

Copy link
Copy Markdown

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

This branch has not been deployed

No deployments
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.

[frontend] Version localStorage keys and consolidate duplicate preference stores

1 participant