forked from cerc-io/laconic-wallet
Make review changes
This commit is contained in:
parent
9a6e52de90
commit
0bb2785383
@ -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<AccountsProps> = ({
|
||||
}) => {
|
||||
const navigation =
|
||||
useNavigation<NativeStackNavigationProp<StackParamsList>>();
|
||||
|
||||
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<AccountsProps> = ({
|
||||
}}
|
||||
/>
|
||||
));
|
||||
const theme = useTheme();
|
||||
|
||||
return (
|
||||
<View>
|
||||
@ -68,7 +65,7 @@ const Accounts: React.FC<AccountsProps> = ({
|
||||
hideDialog={() => setHdDialog(false)}
|
||||
updateAccounts={updateAccounts}
|
||||
updateIndex={updateId}
|
||||
pathCode={pathCode} // Pass pathCode here
|
||||
pathCode={pathCode}
|
||||
/>
|
||||
<List.Accordion
|
||||
title={`Account ${currentIndex + 1}`}
|
||||
@ -91,16 +88,7 @@ const Accounts: React.FC<AccountsProps> = ({
|
||||
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
|
||||
</Button>
|
||||
@ -117,9 +105,7 @@ const Accounts: React.FC<AccountsProps> = ({
|
||||
</Text>
|
||||
<Text variant="bodyLarge">
|
||||
<Text style={{ fontWeight: '700' }}>HD Path: </Text>
|
||||
{selectedAccounts &&
|
||||
selectedAccounts[currentIndex] &&
|
||||
selectedAccounts[currentIndex].hdPath}
|
||||
{selectedAccounts[currentIndex]?.hdPath}
|
||||
</Text>
|
||||
</View>
|
||||
|
||||
|
@ -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 = ({
|
||||
</Text>
|
||||
<TextInput
|
||||
mode="outlined"
|
||||
onChangeText={text => setPath(text)}
|
||||
onChangeText={setPath}
|
||||
value={path}
|
||||
style={{ flex: 1 }}
|
||||
/>
|
||||
|
@ -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<string>('eth');
|
||||
const [currentIndex, setCurrentIndex] = useState<number>(0);
|
||||
const [phrase, setPhrase] = useState('');
|
||||
|
||||
const [accounts, setAccounts] = useState<AccountsState>({
|
||||
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 (
|
||||
<View style={styles.appContainer}>
|
||||
<DialogComponent
|
||||
|
@ -1,3 +1,5 @@
|
||||
/* Importing this library provides react native with a secure random source.
|
||||
For more information, "visit https://docs.ethers.org/v5/cookbook/react-native/#cookbook-reactnative-security" */
|
||||
import 'react-native-get-random-values';
|
||||
import '@ethersproject/shims';
|
||||
|
||||
|
@ -1,3 +1,5 @@
|
||||
/* Importing this library provides react native with a secure random source.
|
||||
For more information, "visit https://docs.ethers.org/v5/cookbook/react-native/#cookbook-reactnative-security" */
|
||||
import 'react-native-get-random-values';
|
||||
import '@ethersproject/shims';
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user