Skip to content

Conversation

@hadv
Copy link
Owner

@hadv hadv commented Dec 8, 2025

Summary

This PR implements wa-sqlite for client-side offline storage, replacing all localStorage usage with IndexedDB-backed SQLite database.

Changes

Core Database Implementation

  • clientDatabase.js: New SQLite database service using wa-sqlite with IDBBatchAtomicVFS for IndexedDB-backed persistence
  • walletsStore.js: Wallet data management layer on top of clientDatabase
  • Serialized operation queue pattern to prevent concurrent database access issues

localStorage → SQLite Migration

  • NetworkContext settings (selected network, custom RPCs)
  • PasskeyStorage credentials
  • WalletDataCache
  • DeviceManager
  • SlippageSelector/DeadlineSelector preferences

Bug Fixes

  • Fix token icon rendering to handle all string formats (not just paths starting with /)
  • Reduce swap gas reserve from 0.01 to 0.001 ETH for better UX with small balances

Build Configuration

  • Add vite-plugin-wasm and vite-plugin-top-level-await for WASM support

Testing

  1. Clear browser storage (DevTools → Application → Storage → Clear site data)
  2. Refresh the app
  3. Verify wallet data persists across page refreshes
  4. Test swap MAX button with small ETH balance
  5. Verify token icons display correctly on assets screen

Closes #171


Pull Request opened by Augment Code with guidance from the PR author

- Add wa-sqlite with IDBBatchAtomicVFS for IndexedDB-backed persistence
- Create clientDatabase.js with serialized operation queue pattern
- Create walletsStore.js for wallet data management
- Migrate all localStorage usage to SQLite:
  - NetworkContext settings
  - PasskeyStorage credentials
  - WalletDataCache
  - DeviceManager
  - SlippageSelector/DeadlineSelector preferences
- Fix token icon rendering (handle all string formats)
- Reduce swap gas reserve from 0.01 to 0.001 ETH
- Add vite-plugin-wasm and vite-plugin-top-level-await for WASM support

Closes #171
@hadv hadv force-pushed the feature/wa-sqlite-offline-storage branch from 5137500 to 17eddc6 Compare December 10, 2025 02:33
The test was making real network calls which timed out in CI environment.
Now uses vi.spyOn to mock the method and avoid actual RPC calls.
- Update PasskeySettings.jsx to use useModularAccountManager hook
- Update DeviceManagement.jsx to use modular account for passkey data
- Update AddCurrentDevice.jsx and AddMobileDevice.jsx for modular accounts
- Replace twoFactorEnabled with mfaEnabled terminology
- Adapt passkey data format from P256MFAValidatorModule structure
- Remove dependency on legacy useP256SDK in device management components

Note: On-chain passkey addition/removal and MFA toggle via UserOperation
are not yet implemented for modular accounts. Coming in a future update.
- Create new ModularAccountSDK class for modular account UserOp building
- Add executeOwnerOnly, addPasskey, removePasskey, enableMFA, disableMFA methods
- Add ERC-7579 mode encoding helpers (encodeSimpleSingleMode, encodeSingleExecution)
- Add useModularAccountSDK React hook

Update components to use ModularAccountSDK:
- AddCurrentDevice: on-chain passkey addition via modularSDK.addPasskey()
- AddMobileDevice: on-chain passkey addition for mobile devices
- DeviceManagement: on-chain passkey removal via modularSDK.removePasskey()
- PasskeySettings: MFA toggle via modularSDK.enableMFA/disableMFA()

The P256AccountSDK remains unchanged for legacy P256Account operations.
@hadv hadv force-pushed the feature/wa-sqlite-offline-storage branch from 9a373aa to ab81755 Compare December 10, 2025 04:40
- Fix ModularAccountManager returning factory address by using raw eth_call
- Remove isModular flags and conditional rendering from components
- Fix ReferenceError in SwapScreen (sdk vs modularSDK)
- Fix ReferenceError in RecoveryManager (missing component)
- Update WalletDetailScreen to use modularSDK
@hadv hadv merged commit d7781a8 into main Dec 10, 2025
4 checks passed
@hadv hadv deleted the feature/wa-sqlite-offline-storage branch December 10, 2025 06:40
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.

Replace localStorage with wa-sqlite for client-side offline storage

3 participants