This document outlines the contract for implementing actual Stellar wallet integration in the Liquifact frontend. The current UI implementation uses mock data and states for development and testing.
- ✅ UI state machine with 6 connection states
- ✅ Accessibility features (ARIA labels, screen reader support)
- ✅ Responsive design
- ✅ Helper text and error messaging
- ✅ Visual status indicators
- ✅ Persistent inline error banner for ERROR/WRONG_NETWORK states
- ❌ Actual wallet connection logic (mocked)
const WALLET_STATES = {
DISCONNECTED: 'disconnected', // Initial state, wallet not connected
CONNECTING: 'connecting', // Connection in progress
CONNECTED: 'connected', // Successfully connected
ERROR: 'error', // Connection failed
WRONG_NETWORK: 'wrong_network', // Connected to wrong network
NO_WALLET: 'no_wallet' // No wallet detected
};- Check for installed Stellar wallets (Freighter, Albedo, etc.)
- Update
NO_WALLETstate based on detection
Replace the mock connectWallet() function with actual wallet integration:
const connectWallet = async () => {
// TODO: Implement actual wallet connection
// 1. Detect available wallets
// 2. Request connection
// 3. Get account info
// 4. Verify network (public vs testnet)
// 5. Handle errors appropriately
};Expected wallet data shape:
const walletData = {
address: 'G...', // Stellar public key
network: 'public', // 'public' or 'testnet'
balance: '1,234.56 XLM', // Formatted balance string
walletType: 'freighter' // Wallet provider name
};- Check if connected wallet is on correct network (public mainnet)
- Update
WRONG_NETWORKstate if on testnet - Provide network switching guidance
- Handle wallet rejection (user cancels)
- Handle network errors
- Handle insufficient permissions
- Update
ERRORstate with appropriate messages
Target wallets for integration:
- Freighter (primary)
- Albedo (secondary)
- Rabet (tertiary)
WalletStatus is a presentational consumer of useWallet() from WalletProvider. The shared hook exposes:
state- Current connection statewalletData- Connected wallet information (balance is runtime-only, not persisted)connect()- Initiate connection (returns{ outcome, message? })disconnect()- Terminate connection and clear persisted snapshot
When the wallet enters ERROR or WRONG_NETWORK states:
- Display: An inline error banner (
role="alert",aria-live="assertive") is rendered above the main wallet status UI - Content: The banner displays the specific error message (e.g., "Failed to connect to wallet. Please try again." or "Wallet is connected to testnet. Please switch to public network.")
- Persistence: Unlike the auto-dismissing toast notification, the banner remains visible as long as the wallet is in an error state
- Clearing: The banner is removed when:
- User retries and the connection succeeds (→ CONNECTED state)
- User retries and reaches a different error state (error message updates)
- User performs another action that transitions the wallet state
- Toast: Provides immediate, prominent feedback when an error occurs (auto-dismisses after a few seconds)
- Inline Banner: Provides persistent visibility for users who may have missed the toast or need to reference the error
- SR-only Status: Announces the error to screen reader users without duplicating the visible banner
This multi-layered approach ensures:
- Immediate notice via toast
- Persistent reference via inline banner
- Accessible announcements for screen readers
WalletProvider (see components/WalletProvider.jsx) is the single source of truth for wallet state. It is mounted once in app/layout.js and persists a minimal, non-sensitive snapshot to localStorage so the UI can rehydrate after reload.
// Persisted snapshot shape (liquifact-wallet-snapshot)
{
version: 1,
state: 'connected',
address: 'GABC...XYZ123', // truncated only
network: 'public'
}Never persist balances, private keys, or full signing material. WalletStatus consumes useWallet() from WalletProvider.
Note:
components/WalletContext.jsxis a deprecated compatibility shim that re-exports everything fromWalletProvider.jsx. All new code should import directly from@/components/WalletProvider.
Use global state for:
- Wallet connection status across app
- Transaction signing
- Network operations
- Validate Stellar addresses
- Verify network before transactions
- Secure storage of connection state
- Handle wallet disconnection gracefully
- Test all wallet states
- Test connection flow end-to-end
- Test error scenarios
- Test network switching
- Test multiple wallet types
Add required wallet SDKs:
npm install @stellar/freighter-api
# Other wallet SDKs as needed- Install wallet SDKs
- Implement actual connection logic
- Add transaction signing capabilities
- Test with real wallets
- Update documentation with real wallet flows