diff --git a/components/Accounts.tsx b/components/Accounts.tsx index eaa96ab..b6b6b39 100644 --- a/components/Accounts.tsx +++ b/components/Accounts.tsx @@ -1,10 +1,8 @@ import React, { useState } from 'react'; import { TouchableOpacity, View } from 'react-native'; import { Button, List, Text, useTheme } from 'react-native-paper'; - import { useNavigation } from '@react-navigation/native'; import { NativeStackNavigationProp } from '@react-navigation/native-stack'; - import { AccountsProps, StackParamsList, Account } from '../types'; import { addAccount } from '../utils/Accounts'; import styles from '../styles/stylesheet'; @@ -19,11 +17,11 @@ const Accounts: React.FC = ({ }) => { const navigation = useNavigation>(); - const [expanded, setExpanded] = useState(false); const [isAccountCreating, setIsAccountCreating] = useState(false); const [hdDialog, setHdDialog] = useState(false); const [pathCode, setPathCode] = useState(''); + const theme = useTheme(); const handlePress = () => setExpanded(!expanded); @@ -59,7 +57,6 @@ const Accounts: React.FC = ({ }} /> )); - const theme = useTheme(); return ( @@ -68,7 +65,7 @@ const Accounts: React.FC = ({ hideDialog={() => setHdDialog(false)} updateAccounts={updateAccounts} updateIndex={updateId} - pathCode={pathCode} // Pass pathCode here + pathCode={pathCode} /> = ({ mode="contained" onPress={() => { setHdDialog(true); - switch (network) { - case 'eth': - setPathCode("m/44'/60'/"); - break; - case 'cosmos': - setPathCode("m/44'/118'/"); - break; - default: - setPathCode(''); - } + setPathCode(network === 'eth' ? "m/44'/60'/" : "m/44'/118'/"); }}> Add Account from HD path @@ -117,9 +105,7 @@ const Accounts: React.FC = ({ HD Path: - {selectedAccounts && - selectedAccounts[currentIndex] && - selectedAccounts[currentIndex].hdPath} + {selectedAccounts[currentIndex]?.hdPath} diff --git a/components/HDPath.tsx b/components/HDPath.tsx index 1e66efe..6e9c6fa 100644 --- a/components/HDPath.tsx +++ b/components/HDPath.tsx @@ -1,6 +1,7 @@ import React, { useState } from 'react'; import { ScrollView, View, Text } from 'react-native'; import { Button, TextInput } from 'react-native-paper'; + import { addAccountFromHDPath } from '../utils/Accounts'; import { Account } from '../types'; @@ -21,13 +22,17 @@ const HDPath = ({ const createFromHDPathHandler = async () => { setIsAccountCreating(true); const hdPath = pathCode + path; - const newAccount = await addAccountFromHDPath(hdPath); - setIsAccountCreating(false); - - if (newAccount) { - updateAccounts(newAccount); - updateIndex(newAccount.counterId); - hideDialog(); + try { + const newAccount = await addAccountFromHDPath(hdPath); + if (newAccount) { + updateAccounts(newAccount); + updateIndex(newAccount.counterId); + hideDialog(); + } + } catch (error) { + console.error('Error creating account:', error); + } finally { + setIsAccountCreating(false); } }; @@ -39,7 +44,7 @@ const HDPath = ({ setPath(text)} + onChangeText={setPath} value={path} style={{ flex: 1 }} /> diff --git a/components/HomeScreen.tsx b/components/HomeScreen.tsx index b2d5267..e6dc587 100644 --- a/components/HomeScreen.tsx +++ b/components/HomeScreen.tsx @@ -1,5 +1,5 @@ import React, { useState } from 'react'; -import { Alert, View } from 'react-native'; +import { View } from 'react-native'; import { Button } from 'react-native-paper'; import { createWallet, resetWallet } from '../utils/Accounts'; @@ -19,7 +19,6 @@ const HomeScreen = () => { const [network, setNetwork] = useState('eth'); const [currentIndex, setCurrentIndex] = useState(0); const [phrase, setPhrase] = useState(''); - const [accounts, setAccounts] = useState({ ethAccounts: [], cosmosAccounts: [], @@ -31,15 +30,15 @@ const HomeScreen = () => { const createWalletHandler = async () => { setIsWalletCreating(true); const { mnemonic, ethAccounts, cosmosAccounts } = await createWallet(); - ethAccounts && - cosmosAccounts && + if (ethAccounts && cosmosAccounts) { setAccounts({ ethAccounts: [...accounts.ethAccounts, ethAccounts], cosmosAccounts: [...accounts.cosmosAccounts, cosmosAccounts], }); - setWalletDialog(true); - setIsWalletCreated(true); - setPhrase(mnemonic); + setWalletDialog(true); + setIsWalletCreated(true); + setPhrase(mnemonic); + } }; const confirmResetWallet = async () => { @@ -79,9 +78,10 @@ const HomeScreen = () => { }); break; default: - Alert.alert('Select a valid network!'); + console.error('Select a valid network!'); } }; + return (