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 React, { useState } from 'react';
|
||||||
import { TouchableOpacity, View } from 'react-native';
|
import { TouchableOpacity, View } from 'react-native';
|
||||||
import { Button, List, Text, useTheme } from 'react-native-paper';
|
import { Button, List, Text, useTheme } from 'react-native-paper';
|
||||||
|
|
||||||
import { useNavigation } from '@react-navigation/native';
|
import { useNavigation } from '@react-navigation/native';
|
||||||
import { NativeStackNavigationProp } from '@react-navigation/native-stack';
|
import { NativeStackNavigationProp } from '@react-navigation/native-stack';
|
||||||
|
|
||||||
import { AccountsProps, StackParamsList, Account } from '../types';
|
import { AccountsProps, StackParamsList, Account } from '../types';
|
||||||
import { addAccount } from '../utils/Accounts';
|
import { addAccount } from '../utils/Accounts';
|
||||||
import styles from '../styles/stylesheet';
|
import styles from '../styles/stylesheet';
|
||||||
@ -19,11 +17,11 @@ const Accounts: React.FC<AccountsProps> = ({
|
|||||||
}) => {
|
}) => {
|
||||||
const navigation =
|
const navigation =
|
||||||
useNavigation<NativeStackNavigationProp<StackParamsList>>();
|
useNavigation<NativeStackNavigationProp<StackParamsList>>();
|
||||||
|
|
||||||
const [expanded, setExpanded] = useState(false);
|
const [expanded, setExpanded] = useState(false);
|
||||||
const [isAccountCreating, setIsAccountCreating] = useState(false);
|
const [isAccountCreating, setIsAccountCreating] = useState(false);
|
||||||
const [hdDialog, setHdDialog] = useState(false);
|
const [hdDialog, setHdDialog] = useState(false);
|
||||||
const [pathCode, setPathCode] = useState('');
|
const [pathCode, setPathCode] = useState('');
|
||||||
|
const theme = useTheme();
|
||||||
|
|
||||||
const handlePress = () => setExpanded(!expanded);
|
const handlePress = () => setExpanded(!expanded);
|
||||||
|
|
||||||
@ -59,7 +57,6 @@ const Accounts: React.FC<AccountsProps> = ({
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
));
|
));
|
||||||
const theme = useTheme();
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View>
|
<View>
|
||||||
@ -68,7 +65,7 @@ const Accounts: React.FC<AccountsProps> = ({
|
|||||||
hideDialog={() => setHdDialog(false)}
|
hideDialog={() => setHdDialog(false)}
|
||||||
updateAccounts={updateAccounts}
|
updateAccounts={updateAccounts}
|
||||||
updateIndex={updateId}
|
updateIndex={updateId}
|
||||||
pathCode={pathCode} // Pass pathCode here
|
pathCode={pathCode}
|
||||||
/>
|
/>
|
||||||
<List.Accordion
|
<List.Accordion
|
||||||
title={`Account ${currentIndex + 1}`}
|
title={`Account ${currentIndex + 1}`}
|
||||||
@ -91,16 +88,7 @@ const Accounts: React.FC<AccountsProps> = ({
|
|||||||
mode="contained"
|
mode="contained"
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
setHdDialog(true);
|
setHdDialog(true);
|
||||||
switch (network) {
|
setPathCode(network === 'eth' ? "m/44'/60'/" : "m/44'/118'/");
|
||||||
case 'eth':
|
|
||||||
setPathCode("m/44'/60'/");
|
|
||||||
break;
|
|
||||||
case 'cosmos':
|
|
||||||
setPathCode("m/44'/118'/");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
setPathCode('');
|
|
||||||
}
|
|
||||||
}}>
|
}}>
|
||||||
Add Account from HD path
|
Add Account from HD path
|
||||||
</Button>
|
</Button>
|
||||||
@ -117,9 +105,7 @@ const Accounts: React.FC<AccountsProps> = ({
|
|||||||
</Text>
|
</Text>
|
||||||
<Text variant="bodyLarge">
|
<Text variant="bodyLarge">
|
||||||
<Text style={{ fontWeight: '700' }}>HD Path: </Text>
|
<Text style={{ fontWeight: '700' }}>HD Path: </Text>
|
||||||
{selectedAccounts &&
|
{selectedAccounts[currentIndex]?.hdPath}
|
||||||
selectedAccounts[currentIndex] &&
|
|
||||||
selectedAccounts[currentIndex].hdPath}
|
|
||||||
</Text>
|
</Text>
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
import { ScrollView, View, Text } from 'react-native';
|
import { ScrollView, View, Text } from 'react-native';
|
||||||
import { Button, TextInput } from 'react-native-paper';
|
import { Button, TextInput } from 'react-native-paper';
|
||||||
|
|
||||||
import { addAccountFromHDPath } from '../utils/Accounts';
|
import { addAccountFromHDPath } from '../utils/Accounts';
|
||||||
import { Account } from '../types';
|
import { Account } from '../types';
|
||||||
|
|
||||||
@ -21,13 +22,17 @@ const HDPath = ({
|
|||||||
const createFromHDPathHandler = async () => {
|
const createFromHDPathHandler = async () => {
|
||||||
setIsAccountCreating(true);
|
setIsAccountCreating(true);
|
||||||
const hdPath = pathCode + path;
|
const hdPath = pathCode + path;
|
||||||
const newAccount = await addAccountFromHDPath(hdPath);
|
try {
|
||||||
setIsAccountCreating(false);
|
const newAccount = await addAccountFromHDPath(hdPath);
|
||||||
|
if (newAccount) {
|
||||||
if (newAccount) {
|
updateAccounts(newAccount);
|
||||||
updateAccounts(newAccount);
|
updateIndex(newAccount.counterId);
|
||||||
updateIndex(newAccount.counterId);
|
hideDialog();
|
||||||
hideDialog();
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error creating account:', error);
|
||||||
|
} finally {
|
||||||
|
setIsAccountCreating(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -39,7 +44,7 @@ const HDPath = ({
|
|||||||
</Text>
|
</Text>
|
||||||
<TextInput
|
<TextInput
|
||||||
mode="outlined"
|
mode="outlined"
|
||||||
onChangeText={text => setPath(text)}
|
onChangeText={setPath}
|
||||||
value={path}
|
value={path}
|
||||||
style={{ flex: 1 }}
|
style={{ flex: 1 }}
|
||||||
/>
|
/>
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
import { Alert, View } from 'react-native';
|
import { View } from 'react-native';
|
||||||
import { Button } from 'react-native-paper';
|
import { Button } from 'react-native-paper';
|
||||||
|
|
||||||
import { createWallet, resetWallet } from '../utils/Accounts';
|
import { createWallet, resetWallet } from '../utils/Accounts';
|
||||||
@ -19,7 +19,6 @@ const HomeScreen = () => {
|
|||||||
const [network, setNetwork] = useState<string>('eth');
|
const [network, setNetwork] = useState<string>('eth');
|
||||||
const [currentIndex, setCurrentIndex] = useState<number>(0);
|
const [currentIndex, setCurrentIndex] = useState<number>(0);
|
||||||
const [phrase, setPhrase] = useState('');
|
const [phrase, setPhrase] = useState('');
|
||||||
|
|
||||||
const [accounts, setAccounts] = useState<AccountsState>({
|
const [accounts, setAccounts] = useState<AccountsState>({
|
||||||
ethAccounts: [],
|
ethAccounts: [],
|
||||||
cosmosAccounts: [],
|
cosmosAccounts: [],
|
||||||
@ -31,15 +30,15 @@ const HomeScreen = () => {
|
|||||||
const createWalletHandler = async () => {
|
const createWalletHandler = async () => {
|
||||||
setIsWalletCreating(true);
|
setIsWalletCreating(true);
|
||||||
const { mnemonic, ethAccounts, cosmosAccounts } = await createWallet();
|
const { mnemonic, ethAccounts, cosmosAccounts } = await createWallet();
|
||||||
ethAccounts &&
|
if (ethAccounts && cosmosAccounts) {
|
||||||
cosmosAccounts &&
|
|
||||||
setAccounts({
|
setAccounts({
|
||||||
ethAccounts: [...accounts.ethAccounts, ethAccounts],
|
ethAccounts: [...accounts.ethAccounts, ethAccounts],
|
||||||
cosmosAccounts: [...accounts.cosmosAccounts, cosmosAccounts],
|
cosmosAccounts: [...accounts.cosmosAccounts, cosmosAccounts],
|
||||||
});
|
});
|
||||||
setWalletDialog(true);
|
setWalletDialog(true);
|
||||||
setIsWalletCreated(true);
|
setIsWalletCreated(true);
|
||||||
setPhrase(mnemonic);
|
setPhrase(mnemonic);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const confirmResetWallet = async () => {
|
const confirmResetWallet = async () => {
|
||||||
@ -79,9 +78,10 @@ const HomeScreen = () => {
|
|||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
Alert.alert('Select a valid network!');
|
console.error('Select a valid network!');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={styles.appContainer}>
|
<View style={styles.appContainer}>
|
||||||
<DialogComponent
|
<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 'react-native-get-random-values';
|
||||||
import '@ethersproject/shims';
|
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 'react-native-get-random-values';
|
||||||
import '@ethersproject/shims';
|
import '@ethersproject/shims';
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user