import React from 'react'; import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, DialogFooter, } from '../ui/dialog'; import { Button } from '../ui/Button'; import Typography from '../ui/Typography'; import { CheckCircle2, XCircle, Loader2, Copy, ExternalLink, } from 'lucide-react'; import type { HCS10ProfileResponse } from '../../../shared/schemas/hcs10'; import { cn } from '../../lib/utils'; import { useWalletStore } from '../../stores/walletStore'; import { Progress } from '../ui/Progress'; interface RegistrationStatusDialogProps { isOpen: boolean; onClose: () => void; isRegistering: boolean; result: HCS10ProfileResponse | null; error: string | null; progress?: { message: string; percent: number; stage?: string; }; } /** * Dialog showing registration progress and results */ export function RegistrationStatusDialog({ isOpen, onClose, isRegistering, result, error, progress, }: RegistrationStatusDialogProps) { const [copied, setCopied] = React.useState(false); const walletNetwork = useWalletStore((s) => s.network) as 'mainnet' | 'testnet' | null; const stageKey = (progress?.stage || '').toLowerCase(); const stageText = stageKey === 'preparing' ? 'Preparing' : stageKey === 'submitting' ? 'Submitting' : stageKey === 'confirming' ? 'Confirming' : stageKey === 'verifying' ? 'Verifying' : stageKey === 'completed' ? 'Completed' : undefined; React.useEffect(() => { const handleEscape = (e: KeyboardEvent) => { if (e.key === 'Escape' && isOpen) { onClose(); } }; if (isOpen) { document.addEventListener('keydown', handleEscape); return () => document.removeEventListener('keydown', handleEscape); } }, [isOpen, onClose]); const handleCopyAccountId = () => { if (result?.accountId) { navigator.clipboard.writeText(result.accountId); setCopied(true); setTimeout(() => setCopied(false), 2000); } }; const handleViewOnExplorer = () => { if (result?.transactionId) { const selectedNetwork = walletNetwork || 'testnet'; const explorerUrl = `https://hashscan.io/${selectedNetwork === 'testnet' ? 'testnet/' : ''}transaction/${result.transactionId}`; window.electron.openExternal(explorerUrl); } }; return ( onClose()}> {isRegistering && 'Registering Agent Profile'} {result && 'Registration Successful'} {error && 'Registration Failed'}
{isRegistering && (
{progress?.message || 'Creating your agent profile on Hedera'} {stageText && ( {stageText} )}
Progress {Math.max(0, Math.min(progress?.percent ?? 0, 100))}%
This may take a few moments
)} {result && !isRegistering && (
Your agent has been successfully registered! Your agent is now discoverable on the Hedera Hashgraph
Agent Account ID {result.accountId}
{result.transactionId && ( )}
)} {error && !isRegistering && (
Registration Failed
{error} {error?.includes('does not have a valid HCS-11 memo') && ( This account already has an HCS-10 agent registered. Try closing this dialog and using the Reset button to clear the registration state and try again. )}
)}
{isRegistering ? ( ) : ( )}
); }