Implement account switching logic

This commit is contained in:
Ilja 2022-02-21 14:22:54 +02:00
parent 26c57c1da6
commit 99ab6286f2
2 changed files with 22 additions and 8 deletions

View File

@ -1,8 +1,15 @@
export default function AccountPicker() {
import { ReactEventHandler } from 'react'
interface IProps {
value: number
onChange: ReactEventHandler<HTMLSelectElement>
}
export default function AccountPicker({ value, onChange }: IProps) {
return (
<select value="Account 1">
<option value="Account 1">Account 1</option>
<option value="Account 2">Account 2</option>
<select value={Number(value)} onChange={onChange}>
<option value={0}>Account 1</option>
<option value={1}>Account 2</option>
</select>
)
}

View File

@ -5,23 +5,24 @@ import { EIP155_MAINNET_CHAINS, EIP155_TEST_CHAINS } from '@/data/EIP155Data'
import SettingsStore from '@/store/SettingsStore'
import { wallets } from '@/utils/WalletUtil'
import { Text } from '@nextui-org/react'
import { Fragment } from 'react'
import { Fragment, useState } from 'react'
import { useSnapshot } from 'valtio'
export default function HomePage() {
const [account, setAccount] = useState(0)
const { testNets } = useSnapshot(SettingsStore.state)
const addresses = Object.keys(wallets)
return (
<Fragment>
<PageHeader title="Accounts">
<AccountPicker />
<AccountPicker value={account} onChange={e => setAccount(Number(e.currentTarget.value))} />
</PageHeader>
<Text h4 css={{ marginBottom: '$5' }}>
Mainnets
</Text>
{Object.values(EIP155_MAINNET_CHAINS).map(({ name, logo, rgb }) => (
<AccountCard key={name} name={name} logo={logo} rgb={rgb} address={addresses[0]} />
<AccountCard key={name} name={name} logo={logo} rgb={rgb} address={addresses[account]} />
))}
{testNets ? (
@ -30,7 +31,13 @@ export default function HomePage() {
Testnets
</Text>
{Object.values(EIP155_TEST_CHAINS).map(({ name, logo, rgb }) => (
<AccountCard key={name} name={name} logo={logo} rgb={rgb} address={addresses[0]} />
<AccountCard
key={name}
name={name}
logo={logo}
rgb={rgb}
address={addresses[account]}
/>
))}
</Fragment>
) : null}