Add cosmos to account list

This commit is contained in:
Ilja 2022-02-25 15:48:54 +02:00
parent 7fe4415af0
commit 580cb40b32
6 changed files with 45 additions and 22 deletions

View File

@ -1,18 +1,22 @@
import SettingsStore from '@/store/SettingsStore' import SettingsStore from '@/store/SettingsStore'
import { cosmosAddresses } from '@/utils/CosmosWalletUtil'
import { eip155Addresses } from '@/utils/EIP155WalletUtil' import { eip155Addresses } from '@/utils/EIP155WalletUtil'
import { useSnapshot } from 'valtio' import { useSnapshot } from 'valtio'
export default function AccountPicker() { export default function AccountPicker() {
const { address } = useSnapshot(SettingsStore.state) const { account } = useSnapshot(SettingsStore.state)
function onSelect(value: string) {
const account = Number(value)
SettingsStore.setAccount(account)
SettingsStore.setEIP155Address(eip155Addresses[account])
SettingsStore.setCosmosAddress(cosmosAddresses[account])
}
return ( return (
<select <select value={account} onChange={e => onSelect(e.currentTarget.value)} aria-label="addresses">
value={address} <option value={0}>Account 1</option>
onChange={e => SettingsStore.setAddress(e.currentTarget.value)} <option value={1}>Account 2</option>
aria-label="addresses"
>
<option value={eip155Addresses[0]}>Account 1</option>
<option value={eip155Addresses[1]}>Account 2</option>
</select> </select>
) )
} }

View File

@ -5,8 +5,8 @@ export const COSMOS_MAINNET_CHAINS = {
'cosmos:cosmoshub-4': { 'cosmos:cosmoshub-4': {
chainId: 'cosmoshub-4', chainId: 'cosmoshub-4',
name: 'Cosmos Hub', name: 'Cosmos Hub',
logo: '/chain-logos/cosmos-cosmoshub4.png', logo: '/chain-logos/cosmos-cosmoshub-4.png',
rgb: '27, 31, 53', rgb: '107, 111, 147',
rpc: 'https://cloudflare-eth.com/' rpc: ''
} }
} }

View File

@ -11,9 +11,12 @@ export default function useInitialization() {
try { try {
const { eip155Addresses } = createOrRestoreEIP155Wallet() const { eip155Addresses } = createOrRestoreEIP155Wallet()
const { cosmosAddresses } = await createOrRestoreCosmosWallet() const { cosmosAddresses } = await createOrRestoreCosmosWallet()
console.log(cosmosAddresses)
SettingsStore.setAddress(eip155Addresses[0]) SettingsStore.setEIP155Address(eip155Addresses[0])
SettingsStore.setCosmosAddress(cosmosAddresses[0])
await createWalletConnectClient() await createWalletConnectClient()
setInitialized(true) setInitialized(true)
} catch (err: unknown) { } catch (err: unknown) {
alert(err) alert(err)

View File

@ -1,6 +1,7 @@
import AccountCard from '@/components/AccountCard' import AccountCard from '@/components/AccountCard'
import AccountPicker from '@/components/AccountPicker' import AccountPicker from '@/components/AccountPicker'
import PageHeader from '@/components/PageHeader' import PageHeader from '@/components/PageHeader'
import { COSMOS_MAINNET_CHAINS } from '@/data/COSMOSData'
import { EIP155_MAINNET_CHAINS, EIP155_TEST_CHAINS } from '@/data/EIP155Data' import { EIP155_MAINNET_CHAINS, EIP155_TEST_CHAINS } from '@/data/EIP155Data'
import SettingsStore from '@/store/SettingsStore' import SettingsStore from '@/store/SettingsStore'
import { Text } from '@nextui-org/react' import { Text } from '@nextui-org/react'
@ -8,7 +9,7 @@ import { Fragment } from 'react'
import { useSnapshot } from 'valtio' import { useSnapshot } from 'valtio'
export default function HomePage() { export default function HomePage() {
const { testNets, address } = useSnapshot(SettingsStore.state) const { testNets, eip155Address, cosmosAddress } = useSnapshot(SettingsStore.state)
return ( return (
<Fragment> <Fragment>
@ -19,7 +20,10 @@ export default function HomePage() {
Mainnets Mainnets
</Text> </Text>
{Object.values(EIP155_MAINNET_CHAINS).map(({ name, logo, rgb }) => ( {Object.values(EIP155_MAINNET_CHAINS).map(({ name, logo, rgb }) => (
<AccountCard key={name} name={name} logo={logo} rgb={rgb} address={address} /> <AccountCard key={name} name={name} logo={logo} rgb={rgb} address={eip155Address} />
))}
{Object.values(COSMOS_MAINNET_CHAINS).map(({ name, logo, rgb }) => (
<AccountCard key={name} name={name} logo={logo} rgb={rgb} address={cosmosAddress} />
))} ))}
{testNets ? ( {testNets ? (
@ -28,7 +32,7 @@ export default function HomePage() {
Testnets Testnets
</Text> </Text>
{Object.values(EIP155_TEST_CHAINS).map(({ name, logo, rgb }) => ( {Object.values(EIP155_TEST_CHAINS).map(({ name, logo, rgb }) => (
<AccountCard key={name} name={name} logo={logo} rgb={rgb} address={address} /> <AccountCard key={name} name={name} logo={logo} rgb={rgb} address={eip155Address} />
))} ))}
</Fragment> </Fragment>
) : null} ) : null}

View File

@ -6,7 +6,7 @@ import { Fragment } from 'react'
import { useSnapshot } from 'valtio' import { useSnapshot } from 'valtio'
export default function SettingsPage() { export default function SettingsPage() {
const { testNets, address } = useSnapshot(SettingsStore.state) const { testNets, eip155Address } = useSnapshot(SettingsStore.state)
return ( return (
<Fragment> <Fragment>
@ -15,7 +15,7 @@ export default function SettingsPage() {
Mnemonic Mnemonic
</Text> </Text>
<Card bordered borderWeight="light" css={{ minHeight: '75px' }}> <Card bordered borderWeight="light" css={{ minHeight: '75px' }}>
<Text css={{ fontFamily: '$mono' }}>{eip155Wallets[address].mnemonic.phrase}</Text> <Text css={{ fontFamily: '$mono' }}>{eip155Wallets[eip155Address].mnemonic.phrase}</Text>
</Card> </Card>
<Text css={{ color: '$yellow500', marginTop: '$5', textAlign: 'center' }}> <Text css={{ color: '$yellow500', marginTop: '$5', textAlign: 'center' }}>

View File

@ -5,7 +5,9 @@ import { proxy } from 'valtio'
*/ */
interface State { interface State {
testNets: boolean testNets: boolean
address: string account: number
eip155Address: string
cosmosAddress: string
} }
/** /**
@ -13,7 +15,9 @@ interface State {
*/ */
const state = proxy<State>({ const state = proxy<State>({
testNets: typeof localStorage !== 'undefined' ? Boolean(localStorage.getItem('TEST_NETS')) : true, testNets: typeof localStorage !== 'undefined' ? Boolean(localStorage.getItem('TEST_NETS')) : true,
address: '' account: 0,
eip155Address: '',
cosmosAddress: ''
}) })
/** /**
@ -22,8 +26,16 @@ const state = proxy<State>({
const SettingsStore = { const SettingsStore = {
state, state,
setAddress(address: string) { setAccount(value: number) {
state.address = address state.account = value
},
setEIP155Address(eip155Address: string) {
state.eip155Address = eip155Address
},
setCosmosAddress(cosmosAddresses: string) {
state.cosmosAddress = cosmosAddresses
}, },
toggleTestNets() { toggleTestNets() {