diff --git a/frontend/src/screens/Wallet/CreateWalletScreen.tsx b/frontend/src/screens/Wallet/CreateWalletScreen.tsx new file mode 100644 index 00000000..c6a4e060 --- /dev/null +++ b/frontend/src/screens/Wallet/CreateWalletScreen.tsx @@ -0,0 +1,398 @@ +import React, { useState } from 'react'; +import { + View, + Text, + StyleSheet, + TouchableOpacity, + SafeAreaView, + TextInput, + ScrollView, + Alert, + ActivityIndicator, + Clipboard, +} from 'react-native'; +import { Ionicons } from '@expo/vector-icons'; +import { LinearGradient } from 'expo-linear-gradient'; +import { usePolkadot } from '../../contexts/PolkadotContext'; + +export default function CreateWalletScreen({ navigation }: any) { + const { createWallet, isLoading } = usePolkadot(); + + const [walletName, setWalletName] = useState('My Wallet'); + const [password, setPassword] = useState(''); + const [confirmPassword, setConfirmPassword] = useState(''); + const [step, setStep] = useState<'form' | 'seed'>('form'); + const [seedPhrase, setSeedPhrase] = useState(''); + const [seedConfirmed, setSeedConfirmed] = useState(false); + + const handleCreateWallet = async () => { + // Validations + if (!walletName.trim()) { + Alert.alert('Error', 'Please enter a wallet name'); + return; + } + + if (password.length < 6) { + Alert.alert('Error', 'Password must be at least 6 characters'); + return; + } + + if (password !== confirmPassword) { + Alert.alert('Error', 'Passwords do not match'); + return; + } + + // Create wallet + const result = await createWallet(walletName, password); + + if (result.success && result.mnemonic) { + setSeedPhrase(result.mnemonic); + setStep('seed'); + } else { + Alert.alert('Error', result.error || 'Failed to create wallet'); + } + }; + + const handleCopySeed = () => { + Clipboard.setString(seedPhrase); + Alert.alert('Copied!', 'Seed phrase copied to clipboard'); + }; + + const handleComplete = () => { + if (!seedConfirmed) { + Alert.alert( + 'Important!', + 'Please confirm that you have backed up your seed phrase. You will need it to recover your wallet.', + [ + { text: 'Cancel', style: 'cancel' }, + { + text: 'I Have Backed It Up', + onPress: () => { + setSeedConfirmed(true); + navigation.navigate('MainTabs'); + }, + }, + ] + ); + } else { + navigation.navigate('MainTabs'); + } + }; + + if (step === 'seed') { + return ( + + + + + + Your Seed Phrase + + Write down these 12 words in order. Keep them safe and secret. + + + + + + + + Never share your seed phrase with anyone! + + + + + {seedPhrase.split(' ').map((word, index) => ( + + {index + 1}. + {word} + + ))} + + + + + Copy to Clipboard + + + + + setSeedConfirmed(!seedConfirmed)} + > + {seedConfirmed && ( + + )} + + + I have written down my seed phrase in a safe place + + + + + Continue + + + + + + ); + } + + return ( + + + + navigation.goBack()} + > + + + + + + Create New Wallet + + Set up your new PezkuwiChain wallet + + + + + + Wallet Name + + + + + Password + + + + + Confirm Password + + + + + {isLoading ? ( + + ) : ( + <> + Create Wallet + + + )} + + + + + + ); +} + +const styles = StyleSheet.create({ + container: { + flex: 1, + }, + gradient: { + flex: 1, + }, + scrollContent: { + padding: 20, + }, + backButton: { + width: 40, + height: 40, + borderRadius: 20, + backgroundColor: 'rgba(255,255,255,0.3)', + alignItems: 'center', + justifyContent: 'center', + marginBottom: 20, + }, + header: { + alignItems: 'center', + marginBottom: 30, + }, + title: { + fontSize: 28, + fontWeight: 'bold', + color: '#FFF', + marginTop: 16, + }, + subtitle: { + fontSize: 16, + color: '#FFF', + marginTop: 8, + textAlign: 'center', + opacity: 0.9, + }, + card: { + backgroundColor: '#FFF', + borderRadius: 20, + padding: 24, + }, + inputGroup: { + marginBottom: 20, + }, + label: { + fontSize: 16, + fontWeight: '600', + color: '#333', + marginBottom: 8, + }, + input: { + backgroundColor: '#F5F5F5', + borderRadius: 12, + padding: 16, + fontSize: 16, + color: '#333', + }, + createButton: { + backgroundColor: '#F08080', + borderRadius: 12, + padding: 16, + flexDirection: 'row', + alignItems: 'center', + justifyContent: 'center', + gap: 8, + marginTop: 10, + }, + createButtonText: { + color: '#FFF', + fontSize: 18, + fontWeight: '600', + }, + warningBanner: { + backgroundColor: '#FFF5F5', + borderRadius: 12, + padding: 16, + flexDirection: 'row', + alignItems: 'center', + gap: 12, + marginBottom: 20, + borderWidth: 1, + borderColor: '#FFE0E0', + }, + warningText: { + flex: 1, + fontSize: 14, + color: '#FF6B6B', + fontWeight: '600', + }, + seedContainer: { + flexDirection: 'row', + flexWrap: 'wrap', + gap: 12, + marginBottom: 20, + }, + seedWord: { + width: '30%', + backgroundColor: '#F5F5F5', + borderRadius: 8, + padding: 12, + flexDirection: 'row', + alignItems: 'center', + gap: 6, + }, + seedNumber: { + fontSize: 12, + color: '#999', + fontWeight: '600', + }, + seedText: { + fontSize: 14, + color: '#333', + fontWeight: '600', + }, + copyButton: { + backgroundColor: '#7DD3C0', + borderRadius: 12, + padding: 14, + flexDirection: 'row', + alignItems: 'center', + justifyContent: 'center', + gap: 8, + }, + copyButtonText: { + color: '#FFF', + fontSize: 16, + fontWeight: '600', + }, + checkboxContainer: { + flexDirection: 'row', + alignItems: 'center', + gap: 12, + marginTop: 20, + }, + checkbox: { + width: 24, + height: 24, + borderRadius: 6, + borderWidth: 2, + borderColor: '#FFF', + backgroundColor: 'rgba(255,255,255,0.2)', + alignItems: 'center', + justifyContent: 'center', + }, + checkboxLabel: { + flex: 1, + fontSize: 14, + color: '#FFF', + }, + continueButton: { + backgroundColor: '#FFF', + borderRadius: 12, + padding: 16, + flexDirection: 'row', + alignItems: 'center', + justifyContent: 'center', + gap: 8, + marginTop: 20, + }, + continueButtonDisabled: { + opacity: 0.5, + }, + continueButtonText: { + color: '#F08080', + fontSize: 18, + fontWeight: '700', + }, +});