Reorganise everything, to separate EIP155 from Cosmos logic
This commit is contained in:
parent
11a0966052
commit
948f66aef2
@ -12,6 +12,7 @@
|
||||
"@walletconnect/utils": "2.0.0-beta.22",
|
||||
"@json-rpc-tools/utils": "1.7.6",
|
||||
"@nextui-org/react": "1.0.2-beta.4",
|
||||
"@cosmostation/cosmosjs": "0.11.1",
|
||||
"next": "12.1.0",
|
||||
"react": "17.0.2",
|
||||
"react-dom": "17.0.2",
|
||||
|
@ -1,5 +1,5 @@
|
||||
import SettingsStore from '@/store/SettingsStore'
|
||||
import { addresses } from '@/utils/WalletUtil'
|
||||
import { eip155Addresses } from '@/utils/EIP155WalletUtil'
|
||||
import { useSnapshot } from 'valtio'
|
||||
|
||||
export default function AccountPicker() {
|
||||
@ -11,8 +11,8 @@ export default function AccountPicker() {
|
||||
onChange={e => SettingsStore.setAddress(e.currentTarget.value)}
|
||||
aria-label="addresses"
|
||||
>
|
||||
<option value={addresses[0]}>Account 1</option>
|
||||
<option value={addresses[1]}>Account 2</option>
|
||||
<option value={eip155Addresses[0]}>Account 1</option>
|
||||
<option value={eip155Addresses[1]}>Account 2</option>
|
||||
</select>
|
||||
)
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Chains
|
||||
*/
|
||||
export const EIP155_MAINNET_CHAINS = {
|
||||
export const COSMOS_MAINNET_CHAINS = {
|
||||
'cosmos:cosmoshub-4': {
|
||||
chainId: 'cosmoshub-4',
|
||||
name: 'Cosmos Hub',
|
||||
|
@ -1,6 +1,6 @@
|
||||
import SettingsStore from '@/store/SettingsStore'
|
||||
import { createOrRestoreEIP155Wallet } from '@/utils/EIP155WalletUtil'
|
||||
import { createWalletConnectClient } from '@/utils/WalletConnectUtil'
|
||||
import { createOrRestoreWallet } from '@/utils/WalletUtil'
|
||||
import { useCallback, useEffect, useState } from 'react'
|
||||
|
||||
export default function useInitialization() {
|
||||
@ -8,8 +8,8 @@ export default function useInitialization() {
|
||||
|
||||
const onInitialize = useCallback(async () => {
|
||||
try {
|
||||
const { addresses } = createOrRestoreWallet()
|
||||
SettingsStore.setAddress(addresses[0])
|
||||
const { eip155Addresses } = createOrRestoreEIP155Wallet()
|
||||
SettingsStore.setAddress(eip155Addresses[0])
|
||||
await createWalletConnectClient()
|
||||
setInitialized(true)
|
||||
} catch (err: unknown) {
|
||||
|
@ -1,6 +1,6 @@
|
||||
import PageHeader from '@/components/PageHeader'
|
||||
import SettingsStore from '@/store/SettingsStore'
|
||||
import { wallets } from '@/utils/WalletUtil'
|
||||
import { eip155Wallets } from '@/utils/EIP155WalletUtil'
|
||||
import { Card, Divider, Row, Switch, Text } from '@nextui-org/react'
|
||||
import { Fragment } from 'react'
|
||||
import { useSnapshot } from 'valtio'
|
||||
@ -15,7 +15,7 @@ export default function SettingsPage() {
|
||||
Mnemonic
|
||||
</Text>
|
||||
<Card bordered borderWeight="light" css={{ minHeight: '75px' }}>
|
||||
<Text css={{ fontFamily: '$mono' }}>{wallets[address].mnemonic.phrase}</Text>
|
||||
<Text css={{ fontFamily: '$mono' }}>{eip155Wallets[address].mnemonic.phrase}</Text>
|
||||
</Card>
|
||||
|
||||
<Text css={{ color: '$yellow500', marginTop: '$5', textAlign: 'center' }}>
|
||||
|
@ -1,10 +1,10 @@
|
||||
import { EIP155_CHAINS, EIP155_SIGNING_METHODS, TEIP155Chain } from '@/data/EIP155Data'
|
||||
import { eip155Addresses, eip155Wallets } from '@/utils/EIP155WalletUtil'
|
||||
import {
|
||||
getSignParamsMessage,
|
||||
getSignTypedDataParamsData,
|
||||
getWalletAddressFromParams
|
||||
} from '@/utils/HelperUtil'
|
||||
import { addresses, wallets } from '@/utils/WalletUtil'
|
||||
import { formatJsonRpcError, formatJsonRpcResult } from '@json-rpc-tools/utils'
|
||||
import { RequestEvent } from '@walletconnect/types'
|
||||
import { ERROR } from '@walletconnect/utils'
|
||||
@ -13,7 +13,7 @@ import { providers } from 'ethers'
|
||||
export async function approveEIP155Request(requestEvent: RequestEvent) {
|
||||
const { method, params, id } = requestEvent.request
|
||||
const { chainId } = requestEvent
|
||||
const wallet = wallets[getWalletAddressFromParams(addresses, params)]
|
||||
const wallet = eip155Wallets[getWalletAddressFromParams(eip155Addresses, params)]
|
||||
|
||||
switch (method) {
|
||||
case EIP155_SIGNING_METHODS.PERSONAL_SIGN:
|
||||
|
@ -1,11 +1,12 @@
|
||||
import { Wallet } from 'ethers'
|
||||
|
||||
export let wallets: Record<string, Wallet>
|
||||
export let addresses: string[]
|
||||
export let wallet1: Wallet
|
||||
export let wallet2: Wallet
|
||||
export let eip155Wallets: Record<string, Wallet>
|
||||
export let eip155Addresses: string[]
|
||||
|
||||
export function createOrRestoreWallet() {
|
||||
let wallet1: Wallet
|
||||
let wallet2: Wallet
|
||||
|
||||
export function createOrRestoreEIP155Wallet() {
|
||||
const mnemonic = localStorage.getItem('WALLET_MNEMONIC')
|
||||
|
||||
if (mnemonic) {
|
||||
@ -18,14 +19,14 @@ export function createOrRestoreWallet() {
|
||||
localStorage.setItem('WALLET_MNEMONIC', wallet1.mnemonic.phrase)
|
||||
}
|
||||
|
||||
wallets = {
|
||||
eip155Wallets = {
|
||||
[wallet1.address]: wallet1,
|
||||
[wallet2.address]: wallet2
|
||||
}
|
||||
addresses = Object.keys(wallets)
|
||||
eip155Addresses = Object.keys(eip155Wallets)
|
||||
|
||||
return {
|
||||
wallets,
|
||||
addresses
|
||||
eip155Wallets,
|
||||
eip155Addresses
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
import { EIP155_CHAINS, TEIP155Chain } from '@/data/EIP155Data'
|
||||
import ModalStore from '@/store/ModalStore'
|
||||
import { eip155Addresses } from '@/utils/EIP155WalletUtil'
|
||||
import { walletConnectClient } from '@/utils/WalletConnectUtil'
|
||||
import { addresses } from '@/utils/WalletUtil'
|
||||
import {
|
||||
Avatar,
|
||||
Button,
|
||||
@ -127,7 +127,7 @@ export default function SessionProposalModal() {
|
||||
<Row>
|
||||
<Col>
|
||||
<Text h5>Select Accounts to Connect</Text>
|
||||
{addresses.map((address, index) => (
|
||||
{eip155Addresses.map((address, index) => (
|
||||
<Card
|
||||
onClick={() => onSelectAddress(address)}
|
||||
clickable
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user