Skip to content

fix: guard wallet storage against QuotaExceededError and SecurityError#328

Merged
Jagadeeshftw merged 5 commits into
AnchorNet-Org:mainfrom
Kaycee276:feature/issue-241-wallet-storage
Jul 23, 2026
Merged

fix: guard wallet storage against QuotaExceededError and SecurityError#328
Jagadeeshftw merged 5 commits into
AnchorNet-Org:mainfrom
Kaycee276:feature/issue-241-wallet-storage

Conversation

@Kaycee276

Copy link
Copy Markdown
Contributor

Guard wallet.ts's localStorage calls against SecurityError/QuotaExceededError

Context

Browsers can throw synchronously from localStorage.getItem/setItem in restricted contexts (e.g., Safari private browsing throwing a QuotaExceededError, or embedded contexts throwing a SecurityError). Because WalletProvider called these synchronous methods directly without a try/catch, it caused uncaught exceptions, entirely breaking the "Connect wallet" button and mount restore effect in those environments rather than failing gracefully.

Implementation Details

  • Wrapped all window.localStorage.getItem, setItem, and removeItem calls in src/lib/wallet.ts within try/catch blocks.
  • On caught errors, loadAccount returns null safely.
  • saveAccount and clearAccount fail silently without propagating the exception.
  • Addressed SEED_STORAGE_KEY generation gracefully handling storage failures.
  • Added test suites simulating SecurityError and QuotaExceededError around Storage.prototype overrides inside src/lib/wallet.test.ts.
  • Implemented mocked error assertions in src/components/WalletProvider.test.tsx to verify that WalletProvider updates in-memory UI connection state cleanly despite the underlying local persistence failing.
  • Added SSR tests validating code fallback execution where window is undefined.

Verification

  • Validated all tests passing locally for the wallet flow context (npm test -- src/lib/wallet.test.ts src/components/WalletProvider.test.tsx).
  • Ensured 100% test branch and line coverage thresholds for src/lib/wallet.ts and src/components/WalletProvider.tsx are met.

closes #241

@Jagadeeshftw
Jagadeeshftw merged commit adc1f79 into AnchorNet-Org:main Jul 23, 2026
1 check failed
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.

Guard wallet.ts's localStorage calls against SecurityError/QuotaExceededError

2 participants