From 580cb40b3234fa912e38d8ff322a76ce9a77d2f1 Mon Sep 17 00:00:00 2001 From: Ilja Date: Fri, 25 Feb 2022 15:48:54 +0200 Subject: [PATCH] Add cosmos to account list --- .../src/components/AccountPicker.tsx | 20 +++++++++++-------- .../react-wallet-v2/src/data/COSMOSData.ts | 6 +++--- .../src/hooks/useInitialization.ts | 7 +++++-- wallets/react-wallet-v2/src/pages/index.tsx | 10 +++++++--- .../react-wallet-v2/src/pages/settings.tsx | 4 ++-- .../src/store/SettingsStore.ts | 20 +++++++++++++++---- 6 files changed, 45 insertions(+), 22 deletions(-) diff --git a/wallets/react-wallet-v2/src/components/AccountPicker.tsx b/wallets/react-wallet-v2/src/components/AccountPicker.tsx index 26a571e..8fc5098 100644 --- a/wallets/react-wallet-v2/src/components/AccountPicker.tsx +++ b/wallets/react-wallet-v2/src/components/AccountPicker.tsx @@ -1,18 +1,22 @@ import SettingsStore from '@/store/SettingsStore' +import { cosmosAddresses } from '@/utils/CosmosWalletUtil' import { eip155Addresses } from '@/utils/EIP155WalletUtil' import { useSnapshot } from 'valtio' 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 ( - onSelect(e.currentTarget.value)} aria-label="addresses"> + + ) } diff --git a/wallets/react-wallet-v2/src/data/COSMOSData.ts b/wallets/react-wallet-v2/src/data/COSMOSData.ts index 27162f5..d10d943 100644 --- a/wallets/react-wallet-v2/src/data/COSMOSData.ts +++ b/wallets/react-wallet-v2/src/data/COSMOSData.ts @@ -5,8 +5,8 @@ export const COSMOS_MAINNET_CHAINS = { 'cosmos:cosmoshub-4': { chainId: 'cosmoshub-4', name: 'Cosmos Hub', - logo: '/chain-logos/cosmos-cosmoshub4.png', - rgb: '27, 31, 53', - rpc: 'https://cloudflare-eth.com/' + logo: '/chain-logos/cosmos-cosmoshub-4.png', + rgb: '107, 111, 147', + rpc: '' } } diff --git a/wallets/react-wallet-v2/src/hooks/useInitialization.ts b/wallets/react-wallet-v2/src/hooks/useInitialization.ts index 597aac3..cd2bf4e 100644 --- a/wallets/react-wallet-v2/src/hooks/useInitialization.ts +++ b/wallets/react-wallet-v2/src/hooks/useInitialization.ts @@ -11,9 +11,12 @@ export default function useInitialization() { try { const { eip155Addresses } = createOrRestoreEIP155Wallet() const { cosmosAddresses } = await createOrRestoreCosmosWallet() - console.log(cosmosAddresses) - SettingsStore.setAddress(eip155Addresses[0]) + + SettingsStore.setEIP155Address(eip155Addresses[0]) + SettingsStore.setCosmosAddress(cosmosAddresses[0]) + await createWalletConnectClient() + setInitialized(true) } catch (err: unknown) { alert(err) diff --git a/wallets/react-wallet-v2/src/pages/index.tsx b/wallets/react-wallet-v2/src/pages/index.tsx index feae016..189b7e9 100644 --- a/wallets/react-wallet-v2/src/pages/index.tsx +++ b/wallets/react-wallet-v2/src/pages/index.tsx @@ -1,6 +1,7 @@ import AccountCard from '@/components/AccountCard' import AccountPicker from '@/components/AccountPicker' import PageHeader from '@/components/PageHeader' +import { COSMOS_MAINNET_CHAINS } from '@/data/COSMOSData' import { EIP155_MAINNET_CHAINS, EIP155_TEST_CHAINS } from '@/data/EIP155Data' import SettingsStore from '@/store/SettingsStore' import { Text } from '@nextui-org/react' @@ -8,7 +9,7 @@ import { Fragment } from 'react' import { useSnapshot } from 'valtio' export default function HomePage() { - const { testNets, address } = useSnapshot(SettingsStore.state) + const { testNets, eip155Address, cosmosAddress } = useSnapshot(SettingsStore.state) return ( @@ -19,7 +20,10 @@ export default function HomePage() { Mainnets {Object.values(EIP155_MAINNET_CHAINS).map(({ name, logo, rgb }) => ( - + + ))} + {Object.values(COSMOS_MAINNET_CHAINS).map(({ name, logo, rgb }) => ( + ))} {testNets ? ( @@ -28,7 +32,7 @@ export default function HomePage() { Testnets {Object.values(EIP155_TEST_CHAINS).map(({ name, logo, rgb }) => ( - + ))} ) : null} diff --git a/wallets/react-wallet-v2/src/pages/settings.tsx b/wallets/react-wallet-v2/src/pages/settings.tsx index c9c496d..b971a03 100644 --- a/wallets/react-wallet-v2/src/pages/settings.tsx +++ b/wallets/react-wallet-v2/src/pages/settings.tsx @@ -6,7 +6,7 @@ import { Fragment } from 'react' import { useSnapshot } from 'valtio' export default function SettingsPage() { - const { testNets, address } = useSnapshot(SettingsStore.state) + const { testNets, eip155Address } = useSnapshot(SettingsStore.state) return ( @@ -15,7 +15,7 @@ export default function SettingsPage() { Mnemonic - {eip155Wallets[address].mnemonic.phrase} + {eip155Wallets[eip155Address].mnemonic.phrase} diff --git a/wallets/react-wallet-v2/src/store/SettingsStore.ts b/wallets/react-wallet-v2/src/store/SettingsStore.ts index e50eafe..84fb881 100644 --- a/wallets/react-wallet-v2/src/store/SettingsStore.ts +++ b/wallets/react-wallet-v2/src/store/SettingsStore.ts @@ -5,7 +5,9 @@ import { proxy } from 'valtio' */ interface State { testNets: boolean - address: string + account: number + eip155Address: string + cosmosAddress: string } /** @@ -13,7 +15,9 @@ interface State { */ const state = proxy({ testNets: typeof localStorage !== 'undefined' ? Boolean(localStorage.getItem('TEST_NETS')) : true, - address: '' + account: 0, + eip155Address: '', + cosmosAddress: '' }) /** @@ -22,8 +26,16 @@ const state = proxy({ const SettingsStore = { state, - setAddress(address: string) { - state.address = address + setAccount(value: number) { + state.account = value + }, + + setEIP155Address(eip155Address: string) { + state.eip155Address = eip155Address + }, + + setCosmosAddress(cosmosAddresses: string) { + state.cosmosAddress = cosmosAddresses }, toggleTestNets() {