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'; import HDPathDialog from './HDPathDialog'; const Accounts = ({ network, accounts, updateAccounts, currentIndex, updateIndex: updateId, }: AccountsProps) => { 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); const addAccountHandler = async () => { setIsAccountCreating(true); const newAccount = await addAccount(network); setIsAccountCreating(false); if (newAccount) { updateAccounts(newAccount); updateId(newAccount.counterId); } }; const selectedAccounts: Account[] = (() => { switch (network) { case 'eth': return accounts.ethAccounts; case 'cosmos': return accounts.cosmosAccounts; default: return []; } })(); const renderAccountItems = () => selectedAccounts.map(account => ( { updateId(account.counterId); setExpanded(false); }} /> )); return ( setHdDialog(false)} updateAccounts={updateAccounts} updateIndex={updateId} pathCode={pathCode} /> {renderAccountItems()} Address: {selectedAccounts[currentIndex]?.address} Public Key: {selectedAccounts[currentIndex]?.pubKey} HD Path: {selectedAccounts[currentIndex]?.hdPath} { navigation.navigate('SignMessage', { selectedNetwork: network, accountInfo: selectedAccounts[currentIndex], }); }}> Sign Message ); }; export default Accounts;