import { Button } from '@/components/ui/button' import { Checkbox } from '@/components/ui/checkbox' import { Input } from '@/components/ui/input' import { Label } from '@/components/ui/label' import { useNostr } from '@/providers/NostrProvider' import { Check, Copy, Download, RefreshCcw } from 'lucide-react' import { generateSecretKey } from 'nostr-tools' import { nsecEncode } from 'nostr-tools/nip19' import { useState } from 'react' import { useTranslation } from 'react-i18next' import InfoCard from '../InfoCard' type Step = 'generate' | 'password' export default function Signup({ back, onSignupSuccess }: { back: () => void onSignupSuccess: () => void }) { const { t } = useTranslation() const { nsecLogin } = useNostr() const [step, setStep] = useState('generate') const [nsec, setNsec] = useState(generateNsec()) const [checkedSaveKey, setCheckedSaveKey] = useState(false) const [password, setPassword] = useState('') const [confirmPassword, setConfirmPassword] = useState('') const [copied, setCopied] = useState(false) const handleDownload = () => { const blob = new Blob([nsec], { type: 'text/plain' }) const url = URL.createObjectURL(blob) const a = document.createElement('a') a.href = url a.download = 'nostr-private-key.txt' document.body.appendChild(a) a.click() document.body.removeChild(a) URL.revokeObjectURL(url) } const handleSignup = async () => { await nsecLogin(nsec, password || undefined, true) onSignupSuccess() } const passwordsMatch = password === confirmPassword const canSubmit = !password || passwordsMatch const renderStepIndicator = () => (
{(['generate', 'password'] as Step[]).map((s, index) => (
{index + 1}
{index < 1 &&
}
))}
) if (step === 'generate') { return (
{renderStepIndicator()}

{t('Create Your Nostr Account')}

{t('Generate your unique private key. This is your digital identity.')}

e.currentTarget.select()} />
setCheckedSaveKey(!!c)} />
) } // step === 'password' return (
{renderStepIndicator()}

{t('Secure Your Account')}

{t('Add an extra layer of protection with a password')}

setPassword(e.target.value)} />
{password && (
setConfirmPassword(e.target.value)} /> {confirmPassword && !passwordsMatch && (

{t('Passwords do not match')}

)}
)}
) } function generateNsec() { const sk = generateSecretKey() return nsecEncode(sk) }