forked from cerc-io/laconic-wallet
Combines states
This commit is contained in:
parent
956821e4e9
commit
16b2ed3bc2
@ -3,8 +3,7 @@ import { ScrollView, View, Text, StyleSheet } 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, PathState } from '../types';
|
||||||
import { HDNode } from 'ethers/lib/utils';
|
|
||||||
|
|
||||||
const HDPath = ({
|
const HDPath = ({
|
||||||
pathCode,
|
pathCode,
|
||||||
@ -18,13 +17,26 @@ const HDPath = ({
|
|||||||
hideDialog: () => void;
|
hideDialog: () => void;
|
||||||
}) => {
|
}) => {
|
||||||
const [isAccountCreating, setIsAccountCreating] = useState(false);
|
const [isAccountCreating, setIsAccountCreating] = useState(false);
|
||||||
const [firstNumber, setFirstNumber] = useState('');
|
const [path, setPath] = useState<PathState>({
|
||||||
const [secondNumber, setSecondNumber] = useState('');
|
firstNumber: '',
|
||||||
const [thirdNumber, setThirdNumber] = useState('');
|
secondNumber: '',
|
||||||
|
thirdNumber: '',
|
||||||
|
});
|
||||||
|
|
||||||
|
const handleChange = (key: keyof PathState, value: string) => {
|
||||||
|
setPath({
|
||||||
|
...path,
|
||||||
|
[key]: value.replace(/[^0-9]/g, ''), // Allow only numeric characters
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
const createFromHDPathHandler = async () => {
|
const createFromHDPathHandler = async () => {
|
||||||
setIsAccountCreating(true);
|
setIsAccountCreating(true);
|
||||||
const hdPath = pathCode + `${firstNumber}'/${secondNumber}/${thirdNumber}`;
|
|
||||||
|
const hdPath =
|
||||||
|
pathCode +
|
||||||
|
`${path.firstNumber}'/${path.secondNumber}/${path.thirdNumber}`;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const newAccount = await addAccountFromHDPath(hdPath);
|
const newAccount = await addAccountFromHDPath(hdPath);
|
||||||
if (newAccount) {
|
if (newAccount) {
|
||||||
@ -46,8 +58,8 @@ const HDPath = ({
|
|||||||
<TextInput
|
<TextInput
|
||||||
keyboardType="numeric"
|
keyboardType="numeric"
|
||||||
mode="outlined"
|
mode="outlined"
|
||||||
onChangeText={setFirstNumber}
|
onChangeText={text => handleChange('firstNumber', text)}
|
||||||
value={firstNumber}
|
value={path.firstNumber}
|
||||||
style={styles.textInput}
|
style={styles.textInput}
|
||||||
maxLength={1}
|
maxLength={1}
|
||||||
/>
|
/>
|
||||||
@ -55,17 +67,17 @@ const HDPath = ({
|
|||||||
<TextInput
|
<TextInput
|
||||||
keyboardType="numeric"
|
keyboardType="numeric"
|
||||||
mode="outlined"
|
mode="outlined"
|
||||||
onChangeText={setSecondNumber}
|
onChangeText={text => handleChange('secondNumber', text)}
|
||||||
value={secondNumber}
|
value={path.secondNumber}
|
||||||
style={styles.textInput}
|
style={styles.textInput}
|
||||||
maxLength={1}
|
maxLength={1}
|
||||||
/>
|
/>
|
||||||
<Text style={styles.text}>'/</Text>
|
<Text style={styles.text}>/</Text>
|
||||||
<TextInput
|
<TextInput
|
||||||
keyboardType="numeric"
|
keyboardType="numeric"
|
||||||
mode="outlined"
|
mode="outlined"
|
||||||
onChangeText={setThirdNumber}
|
onChangeText={text => handleChange('thirdNumber', text)}
|
||||||
value={thirdNumber}
|
value={path.thirdNumber}
|
||||||
style={styles.textInput}
|
style={styles.textInput}
|
||||||
maxLength={1}
|
maxLength={1}
|
||||||
/>
|
/>
|
||||||
|
Loading…
Reference in New Issue
Block a user