interface icon indicating copy to clipboard operation
interface copied to clipboard

fix: prevent app crash when wallet locks during Supply modal interaction

Open mmarfinetz opened this issue 4 months ago • 2 comments

Summary

Fixes #2382 - Prevents app crash when wallet is locked while Supply modal is open

Changes

  • ✅ Fixed UserAuthenticated component to handle disconnection gracefully
  • ✅ Added WalletGuard provider to monitor wallet disconnection events
  • ✅ Enhanced SupplyModal with connection state guards
  • ✅ Added TransactionErrorBoundary for additional safety
  • ✅ Integrated providers in _app.page.tsx with proper hierarchy

Problem

When users lock their wallet extension (MetaMask/Rabby/Ambire) while the Supply modal is open, the app crashes with:

Uncaught Error: Invariant failed: User data loaded but no user found

Solution

Implemented a two-part defensive strategy:

  1. Global Wallet Guard: Monitors disconnection and closes modals automatically
  2. Component-Level Guards: Graceful handling with "Connect Wallet" UI

Testing

  1. Connect wallet (MetaMask/Rabby/Ambire)
  2. Open Supply modal
  3. Lock wallet extension
  4. Before: App crashes with client exception
  5. After: Modal gracefully shows "Connect Wallet" prompt

Impact

  • Improves UX reliability
  • Prevents data loss during wallet disconnection events
  • Establishes pattern for other transaction modals

Screenshots

N/A - Fix is for preventing crashes, behavior change is the absence of errors

Checklist

  • [x] Code follows project conventions
  • [x] No breaking changes
  • [x] Tested with MetaMask, Rabby wallets
  • [x] Ready for review

mmarfinetz avatar Aug 08 '25 17:08 mmarfinetz