import React, { useState } from 'react'; import { View } from 'react-native'; import { Text, Button, Dialog, Portal } from 'react-native-paper'; import { useNavigation } from '@react-navigation/native'; import { NativeStackNavigationProp } from '@react-navigation/native-stack'; import { createWallet, resetWallet } from '../utils'; import { DialogComponent } from './Dialog'; import { NetworkDropdown } from './NetworkDropdown'; import { StackParamsList, Account } from '../types'; const HomeScreen = () => { const navigation = useNavigation>(); const [isWalletCreated, setIsWalletCreated] = useState(false); const [isWalletCreating, setIsWalletCreating] = useState(false); const [walletDialog, setWalletDialog] = useState(false); const [resetWalletDialog, setResetWalletDialog] = useState(false); const [network, setNetwork] = useState('eth'); const [currentAccount, setCurrentAccount] = useState(); const [ethAccount, setEthAccount] = useState(); const [cosmosAccount, setCosmosAccount] = useState(); const hideWalletDialog = () => setWalletDialog(false); const hideResetDialog = () => setResetWalletDialog(false); const createWalletHandler = async () => { setIsWalletCreating(true); await new Promise(resolve => setTimeout(resolve, 2000)); const { ethWalletInfo, cosmosWalletInfo } = await createWallet(); setEthAccount(ethWalletInfo); setCosmosAccount(cosmosWalletInfo); setCurrentAccount(ethWalletInfo); setWalletDialog(true); setIsWalletCreated(true); }; const confirmResetWallet = async () => { await resetWallet(); setIsWalletCreated(false); setIsWalletCreating(false); hideResetDialog(); }; const updateNetwork = (newNetwork: string) => { setNetwork(newNetwork); switch (newNetwork) { case 'eth': setCurrentAccount(ethAccount); break; case 'cosmos': setCurrentAccount(cosmosAccount); break; default: console.error('Error updating network'); } }; return ( Reset Wallet Are you sure? {isWalletCreated ? ( Account 1 Address: {currentAccount && currentAccount.address} Public Key: {currentAccount && currentAccount.pubKey} ) : ( Create Wallet )} ); }; export { HomeScreen };