wip cosmos wallet util
This commit is contained in:
parent
948f66aef2
commit
b73855a561
BIN
wallets/.DS_Store
vendored
BIN
wallets/.DS_Store
vendored
Binary file not shown.
@ -1,4 +1,5 @@
|
|||||||
import SettingsStore from '@/store/SettingsStore'
|
import SettingsStore from '@/store/SettingsStore'
|
||||||
|
import { createOrRestoreCosmosWallet } from '@/utils/CosmosWalletUtil'
|
||||||
import { createOrRestoreEIP155Wallet } from '@/utils/EIP155WalletUtil'
|
import { createOrRestoreEIP155Wallet } from '@/utils/EIP155WalletUtil'
|
||||||
import { createWalletConnectClient } from '@/utils/WalletConnectUtil'
|
import { createWalletConnectClient } from '@/utils/WalletConnectUtil'
|
||||||
import { useCallback, useEffect, useState } from 'react'
|
import { useCallback, useEffect, useState } from 'react'
|
||||||
@ -9,6 +10,8 @@ export default function useInitialization() {
|
|||||||
const onInitialize = useCallback(async () => {
|
const onInitialize = useCallback(async () => {
|
||||||
try {
|
try {
|
||||||
const { eip155Addresses } = createOrRestoreEIP155Wallet()
|
const { eip155Addresses } = createOrRestoreEIP155Wallet()
|
||||||
|
const { cosmosAddresses } = createOrRestoreCosmosWallet()
|
||||||
|
console.log(cosmosAddresses)
|
||||||
SettingsStore.setAddress(eip155Addresses[0])
|
SettingsStore.setAddress(eip155Addresses[0])
|
||||||
await createWalletConnectClient()
|
await createWalletConnectClient()
|
||||||
setInitialized(true)
|
setInitialized(true)
|
||||||
|
51
wallets/react-wallet-v2/src/utils/CosmosWalletUtil.ts
Normal file
51
wallets/react-wallet-v2/src/utils/CosmosWalletUtil.ts
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
import { COSMOS_MAINNET_CHAINS } from '@/data/COSMOSData'
|
||||||
|
// @ts-expect-error
|
||||||
|
import { Cosmos } from '@cosmostation/cosmosjs/src/index'
|
||||||
|
|
||||||
|
export const wallet1 = new Cosmos(
|
||||||
|
'https://api.cosmos.network',
|
||||||
|
COSMOS_MAINNET_CHAINS['cosmos:cosmoshub-4'].chainId
|
||||||
|
)
|
||||||
|
wallet1.path("m/44'/118'/0'/0/0")
|
||||||
|
|
||||||
|
export const wallet2 = new Cosmos(
|
||||||
|
'https://api.cosmos.network',
|
||||||
|
COSMOS_MAINNET_CHAINS['cosmos:cosmoshub-4'].chainId
|
||||||
|
)
|
||||||
|
wallet1.path("m/44'/118'/0'/0/1")
|
||||||
|
|
||||||
|
export let cosmosWallets: Record<string, Cosmos>
|
||||||
|
export let cosmosAddresses: string[]
|
||||||
|
|
||||||
|
let address1: string
|
||||||
|
let address2: string
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utilities
|
||||||
|
*/
|
||||||
|
export function createOrRestoreCosmosWallet() {
|
||||||
|
const mnemonic = localStorage.getItem('WALLET_MNEMONIC')
|
||||||
|
|
||||||
|
if (mnemonic) {
|
||||||
|
address1 = wallet1.getAddress(mnemonic)
|
||||||
|
address2 = wallet2.getAddress(mnemonic)
|
||||||
|
} else {
|
||||||
|
// We can reuse same mnemonic for both wallets
|
||||||
|
const mnemonic = wallet1.getRandomMnemonic()
|
||||||
|
address1 = wallet1.getAddress(mnemonic)
|
||||||
|
address2 = wallet2.getAddress(mnemonic)
|
||||||
|
// Don't store mnemonic in local storage in a production project!
|
||||||
|
localStorage.setItem('WALLET_MNEMONIC', mnemonic)
|
||||||
|
}
|
||||||
|
|
||||||
|
cosmosWallets = {
|
||||||
|
[address1]: wallet1,
|
||||||
|
[address2]: wallet2
|
||||||
|
}
|
||||||
|
cosmosAddresses = Object.keys(cosmosWallets)
|
||||||
|
|
||||||
|
return {
|
||||||
|
cosmosWallets,
|
||||||
|
cosmosAddresses
|
||||||
|
}
|
||||||
|
}
|
@ -6,6 +6,9 @@ export let eip155Addresses: string[]
|
|||||||
let wallet1: Wallet
|
let wallet1: Wallet
|
||||||
let wallet2: Wallet
|
let wallet2: Wallet
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utilities
|
||||||
|
*/
|
||||||
export function createOrRestoreEIP155Wallet() {
|
export function createOrRestoreEIP155Wallet() {
|
||||||
const mnemonic = localStorage.getItem('WALLET_MNEMONIC')
|
const mnemonic = localStorage.getItem('WALLET_MNEMONIC')
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user