Wallet Integration
The application integrates with Cardano wallets to enable blockchain interactions. This section provides a comprehensive overview of how the OADA UI handles wallet connections, transactions, and blockchain interactions.
Overview
The wallet integration system serves as the bridge between the OADA UI and the Cardano blockchain. It handles:
Wallet connection and disconnection
Transaction building and signing
UTXO management
Network switching
Address validation and verification
Balance tracking
Transaction history
Supported Wallets
The application supports multiple Cardano wallets, each implementing the standard Cardano wallet interface:
Eternl
Nami
Flint
Yoroi
Gero
Each wallet must implement the standard WalletProvider interface to ensure consistent behavior across the application.
Key Components:
The wallet integration is organized in the src/services/wallet/ directory with the following structure:
Key functionalities include:
Wallet connection management
UTXO (Unspent Transaction Output) handling
Transaction signing and submission
Network switching
Address validation
Balance tracking
Transaction history
Error handling
Wallet Provider Interface (src/store/wallet.ts)
src/store/wallet.ts)The Wallet Provider Interface defines the contract for interacting with different Cardano wallet providers. It provides a unified way to access wallet functionality regardless of the specific provider implementation.
The supported wallet providers are defined in a registry that maps provider names to their availability:
The Lucid wallet API provider implementation handles wallet connection and API access through browser extensions:
Wallet State Management (src/store/slices/walletSlice.ts)
src/store/slices/walletSlice.ts)The Wallet State Management system handles all wallet-related state in the Redux store. Let's break down the key types and interfaces:
The initial state for the wallet slice:
Utility functions for value conversion:
UTxO management functions:
The Redux slice for wallet state management:
WebSocket Integration (src/websocket.tsx)
src/websocket.tsx)The WebSocket Integration provides real-time communication with the backend. Let's break down the key components:
Wallet Connection
The wallet connection functions handle the process of connecting and disconnecting wallets:
UTxO Management
The UTxO management functions handle the retrieval and updating of unspent transaction outputs:
Usage Examples
Connecting a Wallet
This example demonstrates how to implement wallet connection in a React component:
Monitoring Wallet Events
This example shows how to implement wallet event monitoring using WebSocket:
Error Handling
The error handling system provides custom error types and utility functions:
Best Practices
Error Handling
Always wrap wallet operations in try-catch blocks
Provide clear error messages to users
Implement proper error recovery mechanisms
Log errors for debugging
State Management
Use Redux for global wallet state
Implement proper loading states
Handle disconnection gracefully
Cache wallet data appropriately
Security
Validate all user inputs
Verify transaction parameters
Implement proper timeout handling
Use secure storage for sensitive data
Performance
Optimize UTXO selection
Cache wallet data
Implement proper cleanup
Handle network changes efficiently
User Experience
Provide clear feedback
Show loading states
Handle edge cases gracefully
Implement proper validation
Last updated