import React, { useState } from 'react'; import { Download, Key } from 'lucide-react'; import { Button } from '@/components/ui/button.tsx'; import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, } from '@/components/ui/dialog.tsx'; import { toast } from '@/hooks/useToast.ts'; import { generateSecretKey, nip19 } from 'nostr-tools'; interface SignupFormProps { isOpen: boolean; onClose: () => void; } const SignupForm: React.FC = ({ isOpen, onClose }) => { const [step, setStep] = useState<'generate' | 'download' | 'done'>('generate'); const [isLoading, setIsLoading] = useState(false); const [nsecKey, setNsecKey] = useState(''); // Generate a proper nsec key using nostr-tools const generateKey = () => { setIsLoading(true); try { // Generate a new private key const privateKey = generateSecretKey(); // Convert to nsec format const nsec = nip19.nsecEncode(privateKey); setNsecKey(nsec); setStep('download'); } catch (error) { console.error('Failed to generate key:', error); toast({ title: 'Error', description: 'Failed to generate key. Please try again.', variant: 'destructive', }); } finally { setIsLoading(false); } }; const downloadKey = () => { // Create a blob with the key text const blob = new Blob([nsecKey], { type: 'text/plain' }); const url = globalThis.URL.createObjectURL(blob); // Create a temporary link element and trigger download const a = document.createElement('a'); a.href = url; a.download = 'nsec.txt'; document.body.appendChild(a); a.click(); // Clean up globalThis.URL.revokeObjectURL(url); document.body.removeChild(a); toast({ title: 'Key downloaded', description: 'Your key has been downloaded. Keep it safe!', }); }; const finishSignup = () => { setStep('done'); onClose(); toast({ title: 'Account created', description: 'You are now logged in.', }); }; return ( {step === 'generate' && 'Create Your Account'} {step === 'download' && 'Download Your Key'} {step === 'done' && 'Setting Up Your Account'} {step === 'generate' && 'Generate a secure key for your account'} {step === 'download' && "Keep your key safe - you'll need it to log in"} {step === 'done' && 'Finalizing your account setup'}
{step === 'generate' && (

We'll generate a secure key for your account. You'll need this key to log in later.

)} {step === 'download' && (
{nsecKey}

Important:

  • This is your only way to access your account
  • Store it somewhere safe
  • Never share this key with anyone
)} {step === 'done' && (
)}
); }; export default SignupForm;