diff --git a/components/HDPath.tsx b/components/HDPath.tsx index 6e9c6fa..582d890 100644 --- a/components/HDPath.tsx +++ b/components/HDPath.tsx @@ -3,7 +3,8 @@ import { ScrollView, View, Text } from 'react-native'; import { Button, TextInput } from 'react-native-paper'; import { addAccountFromHDPath } from '../utils/Accounts'; -import { Account } from '../types'; +import { Account, PathState } from '../types'; +import styles from '../styles/stylesheet'; const HDPath = ({ pathCode, @@ -16,12 +17,25 @@ const HDPath = ({ updateAccounts: (account: Account) => void; hideDialog: () => void; }) => { - const [path, setPath] = useState(''); const [isAccountCreating, setIsAccountCreating] = useState(false); + const [path, setPath] = useState({ + firstNumber: '', + secondNumber: '', + thirdNumber: '', + }); + + const handleChange = (key: keyof PathState, value: string) => { + setPath({ + ...path, + [key]: value.replace(/[^0-9]/g, ''), + }); + }; const createFromHDPathHandler = async () => { setIsAccountCreating(true); - const hdPath = pathCode + path; + const hdPath = + pathCode + + `${path.firstNumber}'/${path.secondNumber}/${path.thirdNumber}`; try { const newAccount = await addAccountFromHDPath(hdPath); if (newAccount) { @@ -37,19 +51,34 @@ const HDPath = ({ }; return ( - - - - {pathCode} - + + + {pathCode} handleChange('firstNumber', text)} + value={path.firstNumber} + style={styles.HDtextInput} + /> + '/ + handleChange('secondNumber', text)} + value={path.secondNumber} + style={styles.HDtextInput} + /> + / + handleChange('thirdNumber', text)} + value={path.thirdNumber} + style={styles.HDtextInput} /> - +