diff --git a/src/components/auth/LoginArea.tsx b/src/components/auth/LoginArea.tsx index 4663d99..fbdd988 100644 --- a/src/components/auth/LoginArea.tsx +++ b/src/components/auth/LoginArea.tsx @@ -58,6 +58,10 @@ export function LoginArea({ className }: LoginAreaProps) { isOpen={signupDialogOpen} onClose={() => setSignupDialogOpen(false)} onLogin={handleLogin} + onOpenLogin={() => { + setSignupDialogOpen(false); + setLoginDialogOpen(true); + }} /> ); diff --git a/src/components/auth/NostrExtensionIndicator.tsx b/src/components/auth/NostrExtensionIndicator.tsx deleted file mode 100644 index b9680fd..0000000 --- a/src/components/auth/NostrExtensionIndicator.tsx +++ /dev/null @@ -1,50 +0,0 @@ -import React from 'react'; -import { useLoginActions } from '@/hooks/useLoginActions'; - -interface NostrExtensionIndicatorProps { - onLogin?: () => void; - onClose?: () => void; -} - -const NostrExtensionIndicator: React.FC = ({ onLogin, onClose }) => { - const login = useLoginActions(); - - const handleExtensionLogin = async () => { - try { - await login.extension(); - onLogin?.(); - onClose?.(); - } catch (error) { - console.error('Extension login failed:', error); - } - }; - - function renderBody(): React.ReactNode { - if ('nostr' in window) { - return ( - <> - - {' '}with browser extension. - - ); - } else { - return 'Browser extension not found.'; - } - } - - return ( -
-

- {renderBody()} -

-
- ); -}; - -export default NostrExtensionIndicator; \ No newline at end of file diff --git a/src/components/auth/SignupDialog.tsx b/src/components/auth/SignupDialog.tsx index daf5552..61154e8 100644 --- a/src/components/auth/SignupDialog.tsx +++ b/src/components/auth/SignupDialog.tsx @@ -2,13 +2,12 @@ // It is important that all functionality in this file is preserved, and should only be modified if explicitly requested. import React, { useState, useEffect } from 'react'; - import { Button } from '@/components/ui/button'; import { Dialog, DialogContent, DialogHeader, DialogTitle } from "@/components/ui/dialog"; - import { toast } from '@/hooks/useToast'; +import { useLoginActions } from '@/hooks/useLoginActions'; +import { generateSecretKey, nip19 } from 'nostr-tools'; -import NostrExtensionIndicator from './NostrExtensionIndicator'; import { cn } from '@/lib/utils'; interface SignupDialogProps { @@ -16,36 +15,76 @@ interface SignupDialogProps { onClose: () => void; onComplete?: () => void; onLogin?: () => void; + onOpenLogin?: () => void; } -const SignupDialog: React.FC = ({ isOpen, onClose, onLogin }) => { - const [step, setStep] = useState<'key' | 'keygen'>('key'); +const SignupDialog: React.FC = ({ isOpen, onClose, onLogin, onOpenLogin }) => { + const [step, setStep] = useState<'key' | 'keygen' | 'download'>('key'); + const [nsec, setNsec] = useState(''); + const login = useLoginActions(); const handleGenerateKey = () => { setStep('keygen'); + + // Add a dramatic pause for the key generation effect + setTimeout(() => { + try { + // Generate a new secret key + const sk = generateSecretKey(); + + // Convert to nsec format + setNsec(nip19.nsecEncode(sk)); + setStep('download'); + + toast({ + title: 'Your Secret Key is Ready!', + description: 'A new secret key has been generated for you.', + }); + } catch { + toast({ + title: 'Error', + description: 'Failed to generate key. Please try again.', + variant: 'destructive', + }); + setStep('key'); + } + }, 2000); }; const handleHasKey = () => { onClose(); - // This would trigger the login dialog to open with the key-add step - // For now, we'll just show a toast message - toast({ - title: 'Use Login Instead', - description: 'Please use the login dialog to enter your existing key.', - }); + if (onOpenLogin) { + onOpenLogin(); + } }; - const handleExtensionLogin = () => { - if (onLogin) { - onLogin(); + const handleUseKey = () => { + try { + login.nsec(nsec); + if (onLogin) { + onLogin(); + } + onClose(); + toast({ + title: 'Welcome!', + description: 'Your account is ready.', + }); + } catch { + toast({ + title: 'Login Failed', + description: 'Failed to login with the generated key. Please try again.', + variant: 'destructive', + }); } - onClose(); }; + + // Reset state when dialog opens useEffect(() => { if (isOpen) { setStep('key'); + setNsec(''); } }, [isOpen]); @@ -73,7 +112,7 @@ const SignupDialog: React.FC = ({ isOpen, onClose, onLogin })
+
)} -
-
-
-
-
-
- - or - -
-
- -