-
Notifications
You must be signed in to change notification settings - Fork 1
Description
Objective
Extend wallet state management to support users having both BYO wallets and embedded wallets simultaneously, tracking which wallet type is active and managing balance aggregation.
Background
With embedded wallet support, users may have:
- One or more BYO wallets (MetaMask, WalletConnect, Phantom)
- One embedded wallet (Dynamic MPC)
- Need to switch between them based on operation type
The app needs to track which wallet is currently active, aggregate balances across both, and provide context about wallet capabilities (standard EOA vs. smart wallet eligible).
Acceptance Criteria
- Extend
useWalletConnectionhook to return wallet type information - Add state for tracking active wallet preference (BYO vs. embedded)
- Create utility functions to determine wallet capabilities:
- Can execute standard transactions (both types)
- Can use session keys (embedded only)
- Can use automation features (embedded only)
- Implement wallet type detection and caching
- Update transaction execution logic to use appropriate wallet based on operation
- Ensure wallet state correctly persists and restores across sessions
- Add tests for wallet type detection and switching logic
Technical Context
Current Wallet Hooks:
/apps/agentic-chat/src/hooks/useWalletConnection.ts- Returns wallet connection state/apps/agentic-chat/src/lib/walletUtils.ts- Wallet utility functions
Current State Structure:
interface WalletConnectionResult {
isConnected: boolean
evmAddress?: string
solanaAddress?: string
primaryAddress?: string
approvedChainIds: string[]
evmWallet?: EthereumWallet
solanaWallet?: SolanaWallet
}Needed Additions:
interface WalletConnectionResult {
// ... existing fields
walletType: 'external' | 'embedded' | undefined
isSmartWalletEligible: boolean
canUseAutomation: boolean
activeWallet: 'byo' | 'embedded'
}State Storage:
- Consider using Zustand store (
/apps/agentic-chat/src/stores/chatStore.ts) for wallet preferences - Or extend existing wallet state in React context
Implementation Considerations
Wallet Type Detection:
Check wallet?.connector?.name or similar Dynamic SDK property to distinguish embedded from external wallets.
Smart Wallet Eligibility:
- Embedded wallets can become smart wallets (ERC-4337)
- BYO wallets cannot (they're externally controlled EOAs)
Automation Capabilities:
- Only embedded smart wallets can use session keys
- BYO wallets require user signature for every transaction
Balance Aggregation:
If user has both BYO and embedded wallets, may want to show combined balance in UI (separate ticket for UI implementation).
Testing Requirements
- Test switching between BYO and embedded wallet
- Test wallet type detection for different wallet connectors
- Test state persistence across page refresh
- Test that automation-requiring operations correctly detect wallet capability
- Test edge case: user connects BYO wallet, then creates embedded wallet
- Test edge case: user has embedded wallet, then connects BYO wallet
Files to Modify
/apps/agentic-chat/src/hooks/useWalletConnection.ts/apps/agentic-chat/src/lib/walletUtils.ts/apps/agentic-chat/src/stores/chatStore.ts(if using Zustand for preferences)- Type definitions as needed
Dependencies
- Requires "Add Embedded Wallet Support to Dynamic SDK Configuration" ticket to be completed first
Metadata
Metadata
Assignees
Labels
Type
Projects
Status