diff --git a/src/components/auth/AccountSwitcher.tsx b/src/components/auth/AccountSwitcher.tsx index afc655d..1693a11 100644 --- a/src/components/auth/AccountSwitcher.tsx +++ b/src/components/auth/AccountSwitcher.tsx @@ -1,7 +1,7 @@ // NOTE: This file is stable and usually should not be modified. // It is important that all functionality in this file is preserved, and should only be modified if explicitly requested. -import { ChevronDown, LogOut, UserIcon, UserPlus, Wallet } from 'lucide-react'; +import { ChevronDown, LogOut, UserIcon, UserPlus } from 'lucide-react'; import { DropdownMenu, DropdownMenuContent, @@ -10,7 +10,6 @@ import { DropdownMenuTrigger, } from '@/components/ui/dropdown-menu.tsx'; import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar.tsx'; -import { WalletModal } from '@/components/WalletModal'; import { useLoggedInAccounts, type Account } from '@/hooks/useLoggedInAccounts'; import { genUserName } from '@/lib/genUserName'; @@ -60,15 +59,6 @@ export function AccountSwitcher({ onAddAccountClick }: AccountSwitcherProps) { ))} - - e.preventDefault()} - > - - Wallet Settings - - setLoginDialogOpen(true)} className='flex items-center gap-2 px-4 py-2 rounded-full bg-primary text-primary-foreground w-full font-medium transition-all hover:bg-primary/90 animate-scale-in' > - Log in )} @@ -51,7 +48,6 @@ export function LoginArea({ className }: LoginAreaProps) { isOpen={loginDialogOpen} onClose={() => setLoginDialogOpen(false)} onLogin={handleLogin} - onSignup={() => setSignupDialogOpen(true)} /> void; onLogin: () => void; - onSignup?: () => void; } const validateNsec = (nsec: string) => { @@ -26,7 +26,7 @@ const validateBunkerUri = (uri: string) => { return uri.startsWith('bunker://'); }; -const LoginDialog: React.FC = ({ isOpen, onClose, onLogin, onSignup }) => { +const LoginDialog: React.FC = ({ isOpen, onClose, onLogin }) => { const [isLoading, setIsLoading] = useState(false); const [isFileLoading, setIsFileLoading] = useState(false); const [nsec, setNsec] = useState(''); @@ -170,203 +170,167 @@ const LoginDialog: React.FC = ({ isOpen, onClose, onLogin, onS reader.readAsText(file); }; - const handleSignupClick = () => { - onClose(); - if (onSignup) { - onSignup(); - } - }; + const hasExtension = 'nostr' in window; + const [isMoreOptionsOpen, setIsMoreOptionsOpen] = useState(false); - const defaultTab = 'nostr' in window ? 'extension' : 'key'; + const renderTabs = () => ( + + + + Secret Key + + + Remote Signer + + + + +
{ + e.preventDefault(); + handleKeyLogin(); + }} className='space-y-4'> +
+ { + setNsec(e.target.value); + if (errors.nsec) setErrors(prev => ({ ...prev, nsec: undefined })); + }} + className={`rounded-lg ${ + errors.nsec ? 'border-red-500 focus-visible:ring-red-500' : '' + }`} + placeholder='nsec1...' + autoComplete="off" + /> + {errors.nsec && ( +

{errors.nsec}

+ )} +
+ +
+ + + + +
+ + {errors.file && ( +

{errors.file}

+ )} +
+
+ + +
{ + e.preventDefault(); + handleBunkerLogin(); + }} className='space-y-4'> +
+ { + setBunkerUri(e.target.value); + if (errors.bunker) setErrors(prev => ({ ...prev, bunker: undefined })); + }} + className={`rounded-lg border-gray-300 dark:border-gray-700 focus-visible:ring-primary ${ + errors.bunker ? 'border-red-500' : '' + }`} + placeholder='bunker://' + autoComplete="off" + /> + {errors.bunker && ( +

{errors.bunker}

+ )} +
+ + +
+
+
+ ); return ( - - - - - Sign up or log in to continue - + + + + Log in + -
- {/* Prominent Sign Up Section */} -
-
-
- - - New to Nostr? - -
-

- Create a new account to get started. It's free and open. -

- -
-
- {/* Divider */} -
-
-
-
-
- - Or log in - -
-
+
+ 🔑 +
- {/* Login Methods */} - - - - - Extension - - - - Key - - - - Bunker - - - +
+ {/* Extension Login Button - shown if extension is available */} + {hasExtension && ( +
{errors.extension && ( {errors.extension} )} -
- -

- Login with one click using the browser extension -

-
- -
-
- + +
+ )} - -
-
- - { - setNsec(e.target.value); - if (errors.nsec) setErrors(prev => ({ ...prev, nsec: undefined })); - }} - className={`rounded-lg ${ - errors.nsec ? 'border-red-500 focus-visible:ring-red-500' : '' - }`} - placeholder='nsec1...' - autoComplete="off" - /> - {errors.nsec && ( -

{errors.nsec}

- )} -
+ {/* Tabs - wrapped in collapsible if extension is available, otherwise shown directly */} + {hasExtension ? ( + + + + - - -
-
-
-
-
- - or - -
-
- -
- - - {errors.file && ( -

{errors.file}

- )} -
-
-
- - -
- - { - setBunkerUri(e.target.value); - if (errors.bunker) setErrors(prev => ({ ...prev, bunker: undefined })); - }} - className={`rounded-lg border-gray-300 dark:border-gray-700 focus-visible:ring-primary ${ - errors.bunker ? 'border-red-500' : '' - }`} - placeholder='bunker://' - autoComplete="off" - /> - {errors.bunker && ( -

{errors.bunker}

- )} -
- -
- -
-
- + + {renderTabs()} + + + ) : ( + renderTabs() + )}
diff --git a/src/components/auth/SignupDialog.tsx b/src/components/auth/SignupDialog.tsx index b80f333..e722af6 100644 --- a/src/components/auth/SignupDialog.tsx +++ b/src/components/auth/SignupDialog.tsx @@ -2,35 +2,26 @@ // It is important that all functionality in this file is preserved, and should only be modified if explicitly requested. import React, { useState, useEffect, useRef } from 'react'; -import { Download, Key, UserPlus, FileText, Shield, User, Sparkles, LogIn, CheckCircle, Upload, Globe } from 'lucide-react'; +import { Download, Upload, Eye, EyeOff } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Textarea } from '@/components/ui/textarea'; import { Dialog, DialogContent, DialogHeader, DialogTitle } from "@/components/ui/dialog"; -import { Card, CardContent } from '@/components/ui/card'; import { toast } from '@/hooks/useToast'; import { useLoginActions } from '@/hooks/useLoginActions'; import { useNostrPublish } from '@/hooks/useNostrPublish'; import { useUploadFile } from '@/hooks/useUploadFile'; -import { generateSecretKey, nip19 } from 'nostr-tools'; -import { cn } from '@/lib/utils'; +import { generateSecretKey, getPublicKey, nip19 } from 'nostr-tools'; interface SignupDialogProps { isOpen: boolean; onClose: () => void; - onComplete?: () => void; } -const sanitizeFilename = (filename: string) => { - return filename.replace(/[^a-z0-9_.-]/gi, '_'); -} - -const SignupDialog: React.FC = ({ isOpen, onClose, onComplete }) => { - const [step, setStep] = useState<'welcome' | 'generate' | 'download' | 'profile' | 'done'>('welcome'); - const [isLoading, setIsLoading] = useState(false); +const SignupDialog: React.FC = ({ isOpen, onClose }) => { + const [step, setStep] = useState<'generate' | 'download' | 'profile'>('generate'); const [nsec, setNsec] = useState(''); - const [showSparkles, setShowSparkles] = useState(false); - const [keySecured, setKeySecured] = useState<'none' | 'downloaded'>('none'); + const [showKey, setShowKey] = useState(false); const [profileData, setProfileData] = useState({ name: '', about: '', @@ -43,34 +34,9 @@ const SignupDialog: React.FC = ({ isOpen, onClose, onComplete // Generate a proper nsec key using nostr-tools const generateKey = () => { - setIsLoading(true); - setShowSparkles(true); - - // 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', - }); - } finally { - setIsLoading(false); - setShowSparkles(false); - } - }, 2000); + const sk = generateSecretKey(); + setNsec(nip19.nsecEncode(sk)); + setStep('download'); }; const downloadKey = () => { @@ -79,8 +45,14 @@ const SignupDialog: React.FC = ({ isOpen, onClose, onComplete const blob = new Blob([nsec], { type: 'text/plain; charset=utf-8' }); const url = globalThis.URL.createObjectURL(blob); - // Sanitize filename - const filename = sanitizeFilename('nostr-nsec-key.txt'); + const decoded = nip19.decode(nsec); + if (decoded.type !== 'nsec') { + throw new Error('Invalid nsec key'); + } + + const pubkey = getPublicKey(decoded.data); + const npub = nip19.npubEncode(pubkey); + const filename = `nostr-${location.hostname.replaceAll(/\./g, '-')}-${npub.slice(5, 9)}.nsec.txt`; // Create a temporary link element and trigger download const a = document.createElement('a'); @@ -94,32 +66,13 @@ const SignupDialog: React.FC = ({ isOpen, onClose, onComplete globalThis.URL.revokeObjectURL(url); document.body.removeChild(a); - // Mark as secured - setKeySecured('downloaded'); - - toast({ - title: 'Secret Key Saved!', - description: 'Your key has been safely stored.', - }); - } catch { - toast({ - title: 'Download failed', - description: 'Could not download the key file. Please copy it manually.', - variant: 'destructive', - }); - } - }; - - - - const finishKeySetup = () => { - try { + // Continue to profile step login.nsec(nsec); setStep('profile'); } catch { toast({ - title: 'Login Failed', - description: 'Failed to login with the generated key. Please try again.', + title: 'Download failed', + description: 'Could not download the key file. Please copy it manually.', variant: 'destructive', }); } @@ -158,10 +111,6 @@ const SignupDialog: React.FC = ({ isOpen, onClose, onComplete const url = tags[0]?.[1]; if (url) { setProfileData(prev => ({ ...prev, picture: url })); - toast({ - title: 'Avatar uploaded!', - description: 'Your avatar has been uploaded successfully.', - }); } } catch { toast({ @@ -173,9 +122,6 @@ const SignupDialog: React.FC = ({ isOpen, onClose, onComplete }; const finishSignup = async (skipProfile = false) => { - // Mark signup completion time for fallback welcome modal - localStorage.setItem('signup_completed', Date.now().toString()); - try { // Publish profile if user provided information if (!skipProfile && (profileData.name || profileData.about || profileData.picture)) { @@ -188,30 +134,6 @@ const SignupDialog: React.FC = ({ isOpen, onClose, onComplete kind: 0, content: JSON.stringify(metadata), }); - - toast({ - title: 'Profile Created!', - description: 'Your profile has been set up.', - }); - } - - // Close signup and show welcome modal - onClose(); - if (onComplete) { - // Add a longer delay to ensure login state has fully propagated - setTimeout(() => { - onComplete(); - }, 600); - } else { - // Fallback for when used without onComplete - setStep('done'); - setTimeout(() => { - onClose(); - toast({ - title: 'Welcome!', - description: 'Your account is ready.', - }); - }, 3000); } } catch { toast({ @@ -219,372 +141,111 @@ const SignupDialog: React.FC = ({ isOpen, onClose, onComplete description: 'Your account was created but profile setup failed. You can update it later.', variant: 'destructive', }); - - // Still proceed to completion even if profile failed + } finally { onClose(); - if (onComplete) { - // Add a longer delay to ensure login state has fully propagated - setTimeout(() => { - onComplete(); - }, 600); - } else { - // Fallback for when used without onComplete - setStep('done'); - setTimeout(() => { - onClose(); - toast({ - title: 'Welcome!', - description: 'Your account is ready.', - }); - }, 3000); - } } }; const getTitle = () => { - if (step === 'welcome') return ( - - Create Your Account - - ); - if (step === 'generate') return ( - - Generating Your Key - - ); - if (step === 'download') return ( - - Secret Key - - ); - if (step === 'profile') return ( - - Create Your Profile - - ); - return ( - - Welcome! - - ); + if (step === 'generate') return 'Sign up'; + if (step === 'download') return 'Secret Key'; + if (step === 'profile') return 'Create Your Profile'; }; // Reset state when dialog opens useEffect(() => { if (isOpen) { - setStep('welcome'); - setIsLoading(false); + setStep('generate'); setNsec(''); - setShowSparkles(false); - setKeySecured('none'); + setShowKey(false); setProfileData({ name: '', about: '', picture: '' }); } }, [isOpen]); - // Add sparkle animation effect - useEffect(() => { - if (showSparkles) { - const interval = setInterval(() => { - // This will trigger re-renders for sparkle animation - }, 100); - return () => clearInterval(interval); - } - }, [showSparkles]); - return ( - - - + + + {getTitle()} -
- {/* Welcome Step - New engaging introduction */} - {step === 'welcome' && ( -
- {/* Hero illustration */} -
-
-
- - -
- -
- - -
-
- {/* Benefits */} -
-
- - Decentralized and censorship-resistant -
-
- - You are in control of your data -
-
- - Join a global network -
-
-
- -
- -
-
- )} - - {/* Generate Step - Enhanced with animations */} +
+ {/* Generate Step */} {step === 'generate' && ( -
-
- {/* Animated background elements */} - {showSparkles && ( -
- {[...Array(12)].map((_, i) => ( - - ))} -
- )} - -
- {isLoading ? ( -
-
- -
-
-
-
-
-

- - Generating your secret key... -

-

- Creating your secure key -

-
-
- ) : ( -
- -
-

- Ready to generate your secret key? -

-

- This key will be your password to access applications within the Nostr network. -

- -
-
- )} -
+
+
+ 🔑
- {!isLoading && ( - - )} +
)} - {/* Download Step - Whimsical and magical */} + {/* Download Step */} {step === 'download' && ( -
- {/* Key reveal */} -
- {/* Sparkles */} -
- - - - -
- -
-
-
- -
-
- -
-
-
- -
-

- Your secret key has been generated! -

- - {/* Warning */} -
-
-
- - - Important Warning - -
-

- This key is your primary and only means of accessing your account. Store it safely and securely. -

-
-
-
+
+
+ 🔑
- {/* Key vault */} - - - {/* Security options */} -
- - -
- {/* Download Option */} - - - - - - - -
- - {/* Continue button */} +
+
+ + + +
+
+
+ + Important Warning + +
+

+ This key is your primary and only means of accessing your account. Store it safely and securely. Please download your key to continue. +

+
+
)} - {/* Profile Step - Optional profile setup */} + {/* Profile Step */} {step === 'profile' && (
- {/* Profile setup illustration */} -
- {/* Sparkles */} -
- - - -
- -
-
-
- -
-
- -
-
-
- -
-

- Almost there! Let's set up your profile -

- -

- Your profile is your identity on Nostr. -

-
-
- {/* Publishing status indicator */} {isPublishing && ( -
+
-
- +
+ Publishing your profile...
@@ -602,7 +263,6 @@ const SignupDialog: React.FC = ({ isOpen, onClose, onComplete value={profileData.name} onChange={(e) => setProfileData(prev => ({ ...prev, name: e.target.value }))} placeholder='Your name' - className='rounded-lg' disabled={isPublishing} />
@@ -616,7 +276,7 @@ const SignupDialog: React.FC = ({ isOpen, onClose, onComplete value={profileData.about} onChange={(e) => setProfileData(prev => ({ ...prev, about: e.target.value }))} placeholder='Tell others about yourself...' - className='rounded-lg resize-none' + className='resize-none' rows={3} disabled={isPublishing} /> @@ -632,7 +292,7 @@ const SignupDialog: React.FC = ({ isOpen, onClose, onComplete value={profileData.picture} onChange={(e) => setProfileData(prev => ({ ...prev, picture: e.target.value }))} placeholder='https://example.com/your-avatar.jpg' - className='rounded-lg flex-1' + className='flex-1' disabled={isPublishing} /> = ({ isOpen, onClose, onComplete size='icon' onClick={() => avatarFileInputRef.current?.click()} disabled={isUploading || isPublishing} - className='rounded-lg shrink-0' title='Upload avatar image' > {isUploading ? ( @@ -664,7 +323,7 @@ const SignupDialog: React.FC = ({ isOpen, onClose, onComplete {/* Action buttons */}