import * as React from "react"; import { Button } from "@/components/ui/button"; import { Badge } from "@/components/ui/badge"; import { Bitcoin, Coins, Loader2 } from "lucide-react"; import { useAppKit, useAppKitAccount, useAppKitState } from "@reown/appkit/react"; import { useAuth } from "@/contexts/useAuth"; interface WalletConnectionStepProps { onComplete: () => void; isLoading: boolean; setIsLoading: (loading: boolean) => void; } export function WalletConnectionStep({ onComplete, isLoading, setIsLoading, }: WalletConnectionStepProps) { const { initialized } = useAppKitState(); const appKit = useAppKit(); const { isAuthenticated } = useAuth(); // Get account info for different chains const bitcoinAccount = useAppKitAccount({ namespace: "bip122" }); const ethereumAccount = useAppKitAccount({ namespace: "eip155" }); // Determine which account is connected const isBitcoinConnected = bitcoinAccount.isConnected; const isEthereumConnected = ethereumAccount.isConnected; const isConnected = isBitcoinConnected || isEthereumConnected; // Get the active account info const activeAccount = isBitcoinConnected ? bitcoinAccount : ethereumAccount; const activeAddress = activeAccount.address; const activeChain = isBitcoinConnected ? "Bitcoin" : "Ethereum"; const handleBitcoinConnect = async () => { if (!initialized || !appKit) { console.error('AppKit not initialized'); return; } setIsLoading(true); try { await appKit.open({ view: "Connect", namespace: "bip122" }); // The wizard will automatically advance when connection is detected } catch (error) { console.error('Error connecting Bitcoin wallet:', error); } finally { setIsLoading(false); } }; const handleEthereumConnect = async () => { if (!initialized || !appKit) { console.error('AppKit not initialized'); return; } setIsLoading(true); try { await appKit.open({ view: "Connect", namespace: "eip155" }); // The wizard will automatically advance when connection is detected } catch (error) { console.error('Error connecting Ethereum wallet:', error); } finally { setIsLoading(false); } }; const handleNext = () => { onComplete(); }; // Show loading state if AppKit is not initialized if (!initialized) { return (
Initializing wallet connection...
Connected to {activeChain} with {activeAddress?.slice(0, 6)}...{activeAddress?.slice(-4)}
Proceeding to verification step...
Choose a network and wallet to connect to OpChan
{/* Bitcoin Section */}