import { useState } from 'react'; import { Loader2 } from 'lucide-react'; import { nip19 } from 'nostr-tools'; import { Button } from '@/components/ui/button'; import { Dialog, DialogContent, DialogHeader, DialogTitle, } from '@/components/ui/dialog'; import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar'; import { Skeleton } from '@/components/ui/skeleton'; import { useAuthor } from '@/hooks/useAuthor'; import { useLoginActions } from '@/hooks/useLoginActions'; interface QuickLoginDialogProps { /** Whether the dialog is open. */ isOpen: boolean; /** The pubkey (hex) detected from the NIP-07 extension. */ pubkey: string; /** Close the dialog. */ onClose: () => void; /** Continue to the full login dialog ("Other login"). */ onOtherLogin: () => void; } /** * Confirmation dialog shown when a NIP-07 extension is present and exposes a * public key. Displays the detected account's profile and a one-tap "Log in" * button, with a smaller "Other login" escape hatch to the full AuthDialog. */ export function QuickLoginDialog({ isOpen, pubkey, onClose, onOtherLogin, }: QuickLoginDialogProps) { const author = useAuthor(pubkey); const login = useLoginActions(); const [isLoggingIn, setIsLoggingIn] = useState(false); const [error, setError] = useState(''); const metadata = author.data?.metadata; const displayName = metadata?.display_name || metadata?.name || genericName(pubkey); const picture = metadata?.picture; const handleLogin = async () => { setIsLoggingIn(true); setError(''); try { await login.extension(); onClose(); } catch (e) { setError(e instanceof Error ? e.message : 'Login failed.'); setIsLoggingIn(false); } }; return ( !open && onClose()}> Welcome back
{author.isLoading ? ( <> ) : ( <> {displayName.slice(0, 2).toUpperCase()}

{displayName}

)}
{error && (

{error}

)}
); } /** Fallback display name derived from the npub when no metadata is available. */ function genericName(pubkey: string): string { try { const npub = nip19.npubEncode(pubkey); return `${npub.slice(0, 10)}…${npub.slice(-4)}`; } catch { return 'Nostr user'; } }