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