import { Button } from '@/components/ui/button' import { Input } from '@/components/ui/input' import { useNostr } from '@/providers/NostrProvider' import { Loader } from 'lucide-react' import { useState } from 'react' import { useTranslation } from 'react-i18next' export default function NpubLogin({ back, onLoginSuccess }: { back: () => void onLoginSuccess: () => void }) { const { t } = useTranslation() const { npubLogin } = useNostr() const [pending, setPending] = useState(false) const [npubInput, setNpubInput] = useState('') const [errMsg, setErrMsg] = useState(null) const handleInputChange = (e: React.ChangeEvent) => { setNpubInput(e.target.value) setErrMsg(null) } const handleLogin = () => { if (npubInput === '') return setPending(true) npubLogin(npubInput) .then(() => onLoginSuccess()) .catch((err) => setErrMsg(err.message)) .finally(() => setPending(false)) } return ( <>
{errMsg &&
{errMsg}
}
) }