import React, { useState } from 'react'; import { Alert, ScrollView, View } from 'react-native'; import { Text, Button, Dialog, Portal } from 'react-native-paper'; import { createWallet, resetWallet } from '../utils'; import { DialogComponent } from './Dialog'; import { NetworkDropdown } from './NetworkDropdown'; import { Account, AccountsState } from '../types'; import Accounts from './Accounts'; const HomeScreen = () => { 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 [currentIndex, setCurrentIndex] = useState(0); const [accounts, setAccounts] = useState({ ethAccounts: [], cosmosAccounts: [], }); 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(); ethWalletInfo && cosmosWalletInfo && setAccounts({ ethAccounts: [...accounts.ethAccounts, ethWalletInfo], cosmosAccounts: [...accounts.cosmosAccounts, cosmosWalletInfo], }); setWalletDialog(true); setIsWalletCreated(true); }; const confirmResetWallet = async () => { await resetWallet(); setIsWalletCreated(false); setIsWalletCreating(false); setAccounts({ ethAccounts: [], cosmosAccounts: [], }); setCurrentIndex(0); hideResetDialog(); setNetwork('eth'); }; const updateNetwork = (newNetwork: string) => { setNetwork(newNetwork); setCurrentIndex(0); }; const updateIndex = (index: number) => { setCurrentIndex(index); }; const updateAccounts = (account: Account) => { switch (network) { case 'eth': setAccounts({ ...accounts, ethAccounts: [...accounts.ethAccounts, account], }); break; case 'cosmos': setAccounts({ ...accounts, cosmosAccounts: [...accounts.cosmosAccounts, account], }); break; default: Alert.alert('Select a valid network!'); } }; return ( Reset Wallet Are you sure? {isWalletCreated ? ( ) : ( )} ); }; export { HomeScreen };