Repository navigation
Conversation
|
@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! 🚀 |
This branch has not been deployed
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.
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.
yieldvault-preferences:<wallet>(usePreferences)wallet_session_startyv_slippage_percentyieldvault:first-deposit:<wallet>"true"hasSeenWalkthrough"true"Solution
Added
lib/versionedStorage.ts, a{version, data}envelope (same shape aslib/userPreferenceStore.ts). Every listed key now reads and writes through it. A pre-envelope value is detected, passed to a per-keymigrateLegacy, and rewritten as an envelope. Unknown-version or corrupt data falls back to defaults.Preference store decision:
usePreferences(theme, locale, currency, notifications, precision) anduserPreferenceStore(chart modes, table density, transaction columns) hold disjoint fields and are both composed byPreferencesContext. 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 theyv_slippage_bpskey.lib/walletSession.ts:wallet_session_startis a v1 envelope; legacy raw string is migrated.components/VaultDashboard.tsx: first-deposit flag is a v1 envelope.components/OnboardingWalkthrough.tsx:hasSeenWalkthroughis a v1 envelope.lib/sessionCleanup.ts: documents which keys are cleared and which persist deliberately.wallet_session_startis still cleared in either format.Regression Tests
usePreferences.test.ts(legacy object to v1),useSlippage.test.ts(raw andyv_slippage_bps),OnboardingWalkthrough.test.tsx(raw"true"),versionedStorage.test.tswalletSession.test.ts,VaultDashboard.test.tsx,AuthContext.test.tsxsessionCleanupcovers keyssessionCleanup.test.ts: clears envelope and legacywallet_session_start; asserts preference and UX keys persistTesting
npm run lint: 0 errors (37 pre-existing warnings)npm run build: succeedednpx 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).vitest run --coveragehad 3 timeouts inVaultDashboard.test.tsxunder load. The file passes alone (23/23) with and without my change.Notes for Reviewers
usePreferencesanduserPreferenceStoreinto 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.Closes #1627