Overview
TheConnectButton component is the primary wallet interface for the OneBalance application. It manages user authentication via Privy, displays the connected wallet address, and provides a detailed account modal with portfolio information, balances across chains, and asset management capabilities.
Import
Props
TheConnectButton component does not accept any props. It manages its own state and relies on global context providers.
The component requires the following providers to be available in the React tree:
PrivyProviderfor authenticationPredictedAddressContextfor account address management
Features
Authentication States
The component handles three distinct states:- Loading State: Displays while Privy is initializing
- Unauthenticated State: Shows a “Login” button
- Authenticated State: Shows wallet address and opens account modal
Account Modal
When authenticated, clicking the button opens a comprehensive account modal that includes:- Wallet Header: Account identifier with formatted address
- Account Address: Full address display with copy functionality
- Portfolio Summary: Total portfolio value, asset count, and chain count
- Asset List: Detailed breakdown of all assets across chains
- Logout Button: Disconnects the wallet
Usage
Basic Usage
With Onboarding Annotation
Component Behavior
Address Formatting
The component automatically formats wallet addresses for display:- Full address:
0x1234567890abcdef1234567890abcdef12345678 - Displayed as:
0x1234...5678
formatAddress function:
Predicted Address Management
The component automatically fetches the predicted account address when a wallet connects:Balance Refresh
Balances are automatically refreshed when the account modal is opened:State Variations
- Loading
- Login
- Connected
Dependencies
Hooks
Provides authentication methods (
login, logout) and state (authenticated, ready)Returns the embedded wallet instance for address derivation
Manages the predicted account address state and fetching
Fetches and manages balance data for the connected account
Provides asset metadata for display in the asset list
Child Components
The account modal renders several specialized components:AssetList: Detailed asset breakdown by chain
Modal Structure
Styling
The component uses Tailwind CSS classes for styling with support for dark mode:- Connected indicator:
bg-emerald-500 animate-pulse(pulsing green dot) - Button hover effects:
hover:shadow-md transition-all duration-200 - Login button:
shadow-lg hover:shadow-xl transform hover:scale-105
Accessibility
- Includes a hidden
DialogTitlefor screen readers - Proper button semantics with
aria-labelattributes - Keyboard navigation support through Dialog component
- Focus management when modal opens/closes
Related Components
- BalanceDisplay - Shows balance information
- AssetList - Lists assets with chain breakdown