import * as React from "react"; import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, } from "@/components/ui/dialog"; import { Button } from "@/components/ui/button"; import { CheckCircle, Circle, Loader2 } from "lucide-react"; import { useAuth } from "@/contexts/useAuth"; import { WalletConnectionStep } from "./wallet-connection-step"; import { VerificationStep } from "./verification-step"; import { DelegationStep } from "./delegation-step"; interface WalletWizardProps { open: boolean; onOpenChange: (open: boolean) => void; onComplete: () => void; } type WizardStep = 1 | 2 | 3; export function WalletWizard({ open, onOpenChange, onComplete, }: WalletWizardProps) { const [currentStep, setCurrentStep] = React.useState(1); const [isLoading, setIsLoading] = React.useState(false); const { currentUser, isAuthenticated, verificationStatus } = useAuth(); // Reset wizard when opened and determine starting step React.useEffect(() => { if (open) { // Only auto-advance from step 1 to 2 when wallet connects during the session // Don't auto-advance to step 3 to allow manual navigation if (isAuthenticated && verificationStatus !== 'verified-owner') { setCurrentStep(2); // Start at verification step if authenticated but not verified } else if (!isAuthenticated) { setCurrentStep(1); // Start at connection step if not authenticated } else { setCurrentStep(1); // Default to step 1, let user navigate manually } setIsLoading(false); } }, [open, isAuthenticated, verificationStatus]); // Auto-advance from step 1 to 2 only when wallet connects during the session React.useEffect(() => { if (open && currentStep === 1 && isAuthenticated) { setCurrentStep(2); } }, [open, currentStep, isAuthenticated]); const handleStepComplete = (step: WizardStep) => { if (step < 3) { setCurrentStep((step + 1) as WizardStep); } else { onComplete(); onOpenChange(false); } }; const handleClose = () => { if (isLoading) return; // Prevent closing during operations onOpenChange(false); }; const getStepStatus = (step: WizardStep) => { if (currentStep > step) return "completed"; if (currentStep === step) return "current"; return "pending"; }; const renderStepIcon = (step: WizardStep) => { const status = getStepStatus(step); if (status === "completed") { return ; } else if (status === "current") { return ; } else { return ; } }; const getStepTitle = (step: WizardStep) => { switch (step) { case 1: return "Connect Wallet"; case 2: return "Verify Ownership"; case 3: return "Delegate Key"; default: return ""; } }; return ( Setup Your Account Complete these steps to access all OpChan features {/* Progress Indicator */}
{[1, 2, 3].map((step) => (
{renderStepIcon(step as WizardStep)} {getStepTitle(step as WizardStep)}
{step < 3 && (
)}
))}
{/* Step Content */}
{currentStep === 1 && ( handleStepComplete(1)} isLoading={isLoading} setIsLoading={setIsLoading} /> )} {currentStep === 2 && ( handleStepComplete(2)} onBack={() => setCurrentStep(1)} isLoading={isLoading} setIsLoading={setIsLoading} /> )} {currentStep === 3 && ( handleStepComplete(3)} onBack={() => setCurrentStep(2)} isLoading={isLoading} setIsLoading={setIsLoading} /> )}
{/* Footer */}

Step {currentStep} of 3

{currentStep > 1 && ( )}
); }