import * as React from 'react'; import { Button } from '@/components/ui/button'; import { Bitcoin, Coins, Shield, ShieldCheck, Loader2, AlertCircle, } from 'lucide-react'; import { useAuth, useAuthActions } from '@/hooks'; import { EVerificationStatus } from '@opchan/core'; import { useAppKitAccount } from '@reown/appkit/react'; import { OrdinalDetails, EnsDetails } from '@opchan/core'; interface VerificationStepProps { onComplete: () => void; onBack: () => void; isLoading: boolean; setIsLoading: (loading: boolean) => void; } export function VerificationStep({ onComplete, onBack, isLoading, setIsLoading, }: VerificationStepProps) { const { currentUser, verificationStatus, isAuthenticating } = useAuth(); const { verifyWallet } = useAuthActions(); // Get account info to determine wallet type const bitcoinAccount = useAppKitAccount({ namespace: 'bip122' }); const ethereumAccount = useAppKitAccount({ namespace: 'eip155' }); const isBitcoinConnected = bitcoinAccount.isConnected; const isEthereumConnected = ethereumAccount.isConnected; const walletType = isBitcoinConnected ? 'bitcoin' : isEthereumConnected ? 'ethereum' : undefined; const [verificationResult, setVerificationResult] = React.useState<{ success: boolean; message: string; details?: OrdinalDetails | EnsDetails; } | null>(null); // Watch for changes in user state after verification React.useEffect(() => { if ( verificationResult?.success && verificationResult.message.includes('Checking ownership') ) { // Check if actual ownership was verified // Treat centralized verification status as source of truth const isOwnerVerified = verificationStatus === EVerificationStatus.ENS_ORDINAL_VERIFIED; const hasOwnership = walletType === 'bitcoin' ? isOwnerVerified && !!currentUser?.ordinalDetails : isOwnerVerified && !!currentUser?.ensDetails; if (hasOwnership) { setVerificationResult({ success: true, message: walletType === 'bitcoin' ? 'Ordinal ownership verified successfully!' : 'ENS ownership verified successfully!', details: walletType === 'bitcoin' ? currentUser?.ordinalDetails : currentUser?.ensDetails, }); } else { setVerificationResult({ success: false, message: walletType === 'bitcoin' ? 'No Ordinal ownership found. You can still participate in the forum with your connected wallet!' : 'No ENS ownership found. You can still participate in the forum with your connected wallet!', }); } } }, [currentUser, verificationResult, walletType, verificationStatus]); const handleVerify = async () => { if (!currentUser) return; setIsLoading(true); setVerificationResult(null); try { const success = await verifyWallet(); if (success) { // For now, just show success - the actual ownership check will be done // by the useEffect when the user state updates setVerificationResult({ success: true, message: walletType === 'bitcoin' ? 'Verification process completed. Checking ownership...' : 'Verification process completed. Checking ownership...', details: undefined, }); } else { setVerificationResult({ success: false, message: walletType === 'bitcoin' ? 'No Ordinal ownership found. You can still participate in the forum with your connected wallet!' : 'No ENS ownership found. You can still participate in the forum with your connected wallet!', }); } } catch (error) { setVerificationResult({ success: false, message: `Verification failed. Please try again: ${error}`, }); } finally { setIsLoading(false); } }; const handleNext = () => { onComplete(); }; const getVerificationType = () => { return walletType === 'bitcoin' ? 'Bitcoin Ordinal' : 'Ethereum ENS'; }; const getVerificationIcon = () => { return walletType === 'bitcoin' ? Bitcoin : Coins; }; const getVerificationColor = () => { return walletType === 'bitcoin' ? 'text-orange-500' : 'text-blue-500'; }; const getVerificationDescription = () => { if (walletType === 'bitcoin') { return "Verify your Bitcoin Ordinal ownership to unlock premium features. If you don't own any Ordinals, you can still participate in the forum with your connected wallet."; } else { return "Verify your Ethereum ENS ownership to unlock premium features. If you don't own any ENS, you can still participate in the forum with your connected wallet."; } }; // Show verification result if (verificationResult) { return (
{verificationResult.message}
{verificationResult.details && (Ordinal ID:{' '} {typeof verificationResult.details === 'object' && 'ordinalId' in verificationResult.details ? verificationResult.details.ordinalId : 'Verified'}
) : (ENS Name:{' '} {typeof verificationResult.details === 'object' && 'ensName' in verificationResult.details ? verificationResult.details.ensName : 'Verified'}
)}Your {getVerificationType()} ownership has been verified.
{currentUser && (Ordinal ID: Verified
} {walletType === 'ethereum' &&ENS Name: Verified
}{getVerificationDescription()}