Skip to content

Fix: Prevent extension breakage when exiting wallet setup halfway - #10

Closed
stackedPenguin wants to merge 2 commits into
masterfrom
fix/incomplete-wallet-setup-bug
Closed

Fix: Prevent extension breakage when exiting wallet setup halfway#10
stackedPenguin wants to merge 2 commits into
masterfrom
fix/incomplete-wallet-setup-bug

Conversation

@stackedPenguin

Copy link
Copy Markdown
Collaborator

Problem

When users exited halfway through wallet setup and reopened the extension popup, the extension would break with:

  • ❌ Black screen flickering
  • ❌ Infinite loading spinner
  • ❌ Unusable popup
  • ❌ No way to complete setup or access the extension

Root Cause

The issue had multiple contributing factors:

  1. No cleanup of incomplete state - Partial wallet setup data remained in localStorage
  2. Poor loading state handling - RequireUserUnlocked returned null causing black screen
  3. Race conditions - Opening new popup while closing current one caused flickering
  4. Wrong redirect destination - Initially redirected to popup.html which has no onboarding routing
  5. Wrong window type - Opened as popup instead of full tab like first install

Solution

1. Automatic State Cleanup

File: packages/secure-background/src/store/SecureStore.ts

Added cleanupIncompleteOnboarding() method that:

  • Detects when user data exists but encrypted keyring (ciphertext) or public keys are missing
  • Automatically cleans up partial data via this.reset()
  • Returns true if cleanup occurred

2. Integrated Auto-Cleanup

File: packages/secure-background/src/store/KeyringStore/KeyringStore.ts

Modified state() method to call cleanupIncompleteOnboarding() before returning NeedsOnboarding state, ensuring cleanup happens automatically before UI renders.

3. Fixed Loading State & Tab Opening

File: packages/secure-ui/src/RequireUserUnlocked/RequireUserUnlocked.tsx

Changes:

  • Show <Loading /> component instead of null (which caused black screen)
  • Open options.html?onboarding=true in full browser tab (not popup)
  • Close popup window after tab opens
  • Matches first install behavior exactly

How It Works Now

Before (Broken):

  1. User exits halfway → partial data in storage
  2. User reopens → loads with incomplete state
  3. RequireUserUnlocked returns nullblack screen
  4. Race conditions → flickering
  5. Extension stuck/broken

After (Fixed):

  1. User exits halfway → partial data in storage
  2. User reopens → popup loads
  3. Auto-cleanup runs → clears incomplete state
  4. Shows loading spinner → smooth UX
  5. Opens onboarding in full tab → exactly like first install
  6. Works perfectly

Testing

  1. Load extension and start wallet setup
  2. Exit halfway through (after entering name, before password)
  3. Reopen the popup
  4. ✅ Brief loading spinner appears
  5. ✅ Full tab opens with onboarding screen
  6. ✅ Complete wallet setup successfully

Files Changed

  • packages/secure-background/src/store/SecureStore.ts - Added cleanup method
  • packages/secure-background/src/store/KeyringStore/KeyringStore.ts - Integrated cleanup
  • packages/secure-ui/src/RequireUserUnlocked/RequireUserUnlocked.tsx - Fixed loading & tab opening
  • yarn.lock - Updated dependencies

🤖 Generated with Claude Code

Fixes bug where exiting wallet setup partway through would cause:
- Black screen flickering
- Infinite loading spinner
- Unusable popup

Root cause: Incomplete wallet setup data remained in localStorage with no cleanup,
causing RequireUserUnlocked to return null (black screen) and race conditions when
opening/closing popups.

Changes:
- Add cleanupIncompleteOnboarding() to SecureStore for auto-cleanup of partial state
- Integrate cleanup in KeyringStore.state() before returning NeedsOnboarding
- Fix RequireUserUnlocked to show loading spinner instead of null/black screen
- Open onboarding in full tab (not popup) matching first install behavior

The extension now automatically detects and cleans up incomplete setup state,
then opens onboarding in a full browser tab exactly like first install.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
jacklevin74 pushed a commit that referenced this pull request Nov 16, 2025
Cherry-picked from PR #10 (fix/incomplete-wallet-setup-bug):
- Add cleanupIncompleteOnboarding method to detect and remove partial setup data
- Call cleanup before returning NeedsOnboarding state in KeyringStore
- Open onboarding in full tab instead of popup for better UX consistency
- Show loading spinner instead of blank screen while opening onboarding
- Prevent duplicate tab opening by checking if already on onboarding page

These changes complement our existing onboarding fixes by adding an
additional layer of cleanup for incomplete state, ensuring the extension
never gets stuck in a broken state during wallet setup.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Resolved conflicts in RequireUserUnlocked.tsx by adopting master's approach
of using QUERY_ONBOARDING constant instead of hardcoded string.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
jacklevin74 pushed a commit that referenced this pull request Nov 16, 2025
…ixes

This document summarizes all fixes applied to resolve:
- Duplicate user account creation
- Create vs import flow inconsistency
- Auto-selection of first wallet
- Active wallet validation bugs
- Wallet data initialization errors
- Automatic wallet recovery
- App crash on incomplete onboarding
- Localnet development support

Includes testing instructions and integration history for PRs #10 and #11.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@jacklevin74

Copy link
Copy Markdown
Owner

Integrated via cherry-pick in 895e8de. See ONBOARDING_FIXES.md

@stackedPenguin
stackedPenguin deleted the fix/incomplete-wallet-setup-bug branch November 17, 2025 03:53
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.

3 participants