// components/sheets/NostrLoginSheet.tsx import React, { useState } from 'react'; import { Modal, View, StyleSheet, Platform, KeyboardAvoidingView, ScrollView, ActivityIndicator, TouchableOpacity } from 'react-native'; import { Info, X } from 'lucide-react-native'; import { Text } from '@/components/ui/text'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { useNDKAuth } from '@/lib/hooks/useNDK'; interface NostrLoginSheetProps { open: boolean; onClose: () => void; } export default function NostrLoginSheet({ open, onClose }: NostrLoginSheetProps) { const [privateKey, setPrivateKey] = useState(''); const [error, setError] = useState(null); const { login, generateKeys, isLoading } = useNDKAuth(); // Handle key generation const handleGenerateKeys = async () => { try { const { nsec } = generateKeys(); setPrivateKey(nsec); setError(null); } catch (err) { setError('Failed to generate keys'); console.error('Key generation error:', err); } }; // Handle login const handleLogin = async () => { if (!privateKey.trim()) { setError('Please enter your private key or generate a new one'); return; } setError(null); try { const success = await login(privateKey); if (success) { setPrivateKey(''); onClose(); } else { setError('Failed to login with the provided key'); } } catch (err) { console.error('Login error:', err); setError(err instanceof Error ? err.message : 'An unexpected error occurred'); } }; if (!open) return null; return ( Login with Nostr Enter your Nostr private key (nsec) {error && ( {error} )} What is a Nostr Key? Nostr is a decentralized protocol where your private key (nsec) is your identity and password. Your private key is securely stored on your device and is never sent to any servers. ); } const styles = StyleSheet.create({ modalOverlay: { flex: 1, justifyContent: 'center', alignItems: 'center', backgroundColor: 'rgba(0, 0, 0, 0.5)', }, modalContent: { width: '90%', maxWidth: 500, backgroundColor: '#FFFFFF', borderRadius: 12, padding: 20, shadowColor: '#000', shadowOffset: { width: 0, height: 2 }, shadowOpacity: 0.25, shadowRadius: 3.84, elevation: 5, }, header: { flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', marginBottom: 15, }, title: { fontSize: 18, fontWeight: 'bold', }, container: { maxHeight: '80%', }, scrollView: { flex: 1, }, content: { padding: 10, }, loader: { marginRight: 8, } });