Skip to content

fix(onboarding): clear step-scoped storage from every reset path (#954) - #992

Open
xeexco wants to merge 1 commit into
Neurowealth:mainfrom
xeexco:fix/954-reset-onboarding-flow-storage
Open

xeexco wants to merge 1 commit into
Neurowealth:mainfrom
xeexco:fix/954-reset-onboarding-flow-storage

Conversation

@xeexco

@xeexco xeexco commented Sep 26, 2026 •

Copy link
Copy Markdown

Overview

This PR fixes the onboarding flow so every reset path clears the full set of localStorage records the flow owns.

resetFlow() in useOnboardingFlow previously reset only the onboarding-state record. The step-scoped blobs written by StrategyOverviewStep (user-strategy) and FirstDepositStep (first-deposit) survived the reset, so "Review Onboarding" dropped the user back to step 0 while localStorage still held their previous strategy and deposit choices — stale state that could resurface on the next pass through the flow.

OnboardingSettings kept its own copy of the clear logic, and the two reset paths had already drifted apart. That duplication is what let the partial reset go unnoticed, so this PR consolidates both entry points onto a single shared helper.

Related Issue

Closes #954

Changes

🔁 One shared onboarding reset

  • [ADD] src/lib/onboarding-state.ts — new resetOnboardingState()

  • [MODIFY] src/hooks/useOnboardingFlow.ts

    • resetFlow() now delegates to the shared helper before persisting the fresh in-progress record, so the flow state and the step-scoped keys are always cleared together.
  • [MODIFY] src/components/settings/OnboardingSettings.tsx

    • Drops the duplicated partial clear (which hardcoded the two step-scoped keys) and calls the shared helper instead.

🧪 Regression coverage

  • [ADD] src/hooks/useOnboardingFlow.test.ts

    • New suite: resetFlow() clears the step-scoped strategy/deposit records, still persists a fresh in-progress state record, and leaves unrelated keys untouched.
  • [MODIFY] src/lib/onboarding-state.test.ts

    • Covers resetOnboardingState(), including the already-empty storage no-op path.
  • [MODIFY] src/lib/storage-keys.test.ts

Verification Results

Full suite: TZ=UTC node --import tsx --test $(find src -name '*.test.ts' -print -o -name '*.test.tsx' -print)
ℹ tests 817
ℹ pass 748
ℹ fail 69   (identical set + files on clean main — pre-existing, see below)

Targeted:
✅ src/lib/onboarding-state.test.ts     8/8 passed
✅ src/hooks/useOnboardingFlow.test.ts  3/3 passed
✅ src/lib/storage-keys.test.ts         all passed

Red/green proof on the new regression test:
✖ pre-fix useOnboardingFlow.ts  ->  1 fail: "resetFlow clears the step-scoped strategy and deposit records"
✔ with this fix                 ->  3/3 pass

Gates:
✅ yarn validate:config
✅ yarn lint           (passes; warnings only)
⚠️ yarn typecheck      62 errors — byte-for-byte the same set as clean main (verified by stashing this branch)
⚠️ yarn build          stops at the same pre-existing transaction-preview type error as main
Acceptance Criteria Status
resetFlow() clears every record the onboarding flow writes ✅ State + user-strategy + first-deposit all removed in one helper
Both reset paths behave identically ✅ OnboardingFlow and OnboardingSettings call resetOnboardingState()
Reset still lands the flow on a usable fresh state ✅ Fresh { lastStep: 0, completed: false } record is persisted after the clear
Unrelated storage is not disturbed ✅ Covered by a dedicated test case
No new CI regressions ✅ Test/typecheck deltas vs. clean main: +6 passing tests, 0 new failures

Manual QA Steps

  1. Open /onboarding and prime the three keys by completing the flow, or directly:
    localStorage.setItem('onboarding-state', JSON.stringify({ completed: true, lastStep: 2 }));
    localStorage.setItem('user-strategy', 'aggressive');
    localStorage.setItem('first-deposit', JSON.stringify({ amount: 250, asset: 'xlm', isFirstDeposit: true }));
  2. Trigger Review Onboarding from the completion banner.
  3. Expected: the wizard returns to step 1, onboarding-state now holds { lastStep: 0, completed: false }, and both user-strategy and first-deposit are gone (DevTools → Application → Local Storage).
    • Before this fix, user-strategy and first-deposit both remained.
  4. Re-prime the keys, then repeat from /settings → Onboarding → Reset onboarding and confirm the same three keys clear.
  5. Sanity check: set an unrelated key (e.g. the cookie-consent key) first, and confirm the reset leaves it untouched.

Design Note

"No new duplicate abstractions without a one-line rationale" — this PR removes the duplicated clear rather than adding one: both callers now route through onboarding-state.ts, the adapter that already owns onboarding storage, which is the shared-reset option the issue suggested.

Pre-existing failures on main (not introduced here)

Clean main at this branch's base commit 0cbb5aa is already red — upstream Frontend CI run #646 on that exact SHA concluded failure. Reproduced locally on the pristine tree: 62 tsc errors and 69 unit-test failures across 12 files (src/lib/transactions.ts undefined i18n copy, the transaction /api routes, useTransactionAPI / useTransactionFlow / useTransactionForm, src/lib/i18n/messages.ts missing the domain namespace, WalletConnectStep.test.tsx React is not defined, and others). next build fails at that same type-check step. None of those files are touched by this PR, and repairing that i18n migration is out of scope for #954.

…rowealth#954)

resetFlow() only reset the onboarding-state record, so "Review Onboarding"
left the strategy/deposit blobs written by StrategyOverviewStep and
FirstDepositStep behind. OnboardingSettings kept its own copy of the clear
logic, and the two reset paths had already drifted apart.

Add a single resetOnboardingState() helper in the onboarding-state adapter
that clears the flow state plus both step-scoped keys via STORAGE_KEYS, and
route both reset entry points through it.

- onboarding-state.ts: add resetOnboardingState()
- useOnboardingFlow: resetFlow() delegates to the shared helper
- OnboardingSettings: drop the duplicated partial clear
- tests: reset coverage in onboarding-state.test.ts, a new
  useOnboardingFlow.test.ts regression suite, and the Neurowealth#581 source guard now
  points at onboarding-state.ts and asserts both paths share the helper
@drips-wave

drips-wave Bot commented Sep 26, 2026

Copy link
Copy Markdown

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

@robertocarlous

Copy link
Copy Markdown
Contributor

Fix conflicts

@robertocarlous

Copy link
Copy Markdown
Contributor

fix conflict

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.

Fix onboarding's resetFlow not clearing step-scoped localStorage records

2 participants