Skip to content

Commit

Permalink
Merge branch 'main' of github.com:WalletConnect/web-examples into fea…
Browse files Browse the repository at this point in the history
…t/sa-connection-improvments
  • Loading branch information
tomiir committed Feb 1, 2024
2 parents 8bc06be + 46bfda7 commit 9525e8c
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 322 deletions.
1 change: 0 additions & 1 deletion advanced/wallets/react-wallet-v2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
"cosmos-wallet": "1.2.0",
"ethers": "5.7.2",
"framer-motion": "6.5.1",
"mnemonic-keyring": "1.4.0",
"near-api-js": "^0.45.0",
"next": "12.1.5",
"permissionless": "0.0.20",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import ChainCard from '@/components/ChainCard'
import SettingsStore from '@/store/SettingsStore'
import { truncate } from '@/utils/HelperUtil'
import { styledToast, truncate } from '@/utils/HelperUtil'
import { updateSignClientChainId } from '@/utils/WalletConnectUtil'
import { Avatar, Button, Text, Tooltip, Loading } from '@nextui-org/react'
import { eip155Wallets } from '@/utils/EIP155WalletUtil'
Expand Down Expand Up @@ -134,7 +134,7 @@ export default function SmartAccountCard({
css={{ marginTop: 10, width: '100%' }}
onClick={onCreateSmartAccount}
>
{loading ? <Loading size="sm" /> : 'Create Smart Account'}
{loading ? <Loading size="sm" css={{ paddingTop: 10 }} /> : 'Create Smart Account'}
</Button>
</>
)}
Expand Down
8 changes: 8 additions & 0 deletions advanced/wallets/react-wallet-v2/src/hooks/useSmartAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { Chain, VITALIK_ADDRESS } from "@/utils/SmartAccountUtils";
import { useCallback, useEffect, useState } from "react";
import { useSnapshot } from "valtio";
import { Hex } from "viem";
import { styledToast } from "@/utils/HelperUtil";
import { TransactionExecutionError } from "viem";

export default function useSmartAccount(signerPrivateKey: Hex, chain: Chain) {
const [loading, setLoading] = useState(false)
Expand All @@ -20,6 +22,12 @@ export default function useSmartAccount(signerPrivateKey: Hex, chain: Chain) {
setLoading(false)
}
catch (e) {
if (e instanceof TransactionExecutionError) {
// shorten the error message
styledToast(e.cause.message, 'error')
} else if (e instanceof Error) {
styledToast(e.message, 'error')
}
console.error(e)
setLoading(false)
}
Expand Down
18 changes: 10 additions & 8 deletions advanced/wallets/react-wallet-v2/src/lib/CosmosLib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { fromHex } from '@cosmjs/encoding'
import { DirectSecp256k1Wallet } from '@cosmjs/proto-signing'
// @ts-expect-error
import { SignDoc } from '@cosmjs/proto-signing/build/codec/cosmos/tx/v1beta1/tx'
import Keyring from 'mnemonic-keyring'
import { Wallet } from 'ethers'

/**
* Constants
Expand All @@ -24,27 +24,29 @@ interface IInitArguments {
* Library
*/
export default class CosmosLib {
private keyring: Keyring
private mnemonic: string
private directSigner: DirectSecp256k1Wallet
private aminoSigner: Secp256k1Wallet

constructor(keyring: Keyring, directSigner: DirectSecp256k1Wallet, aminoSigner: Secp256k1Wallet) {
constructor(mnemonic: string, directSigner: DirectSecp256k1Wallet, aminoSigner: Secp256k1Wallet) {
this.directSigner = directSigner
this.keyring = keyring
this.mnemonic = mnemonic
this.aminoSigner = aminoSigner
}

static async init({ mnemonic, path, prefix }: IInitArguments) {
const keyring = await Keyring.init({ mnemonic: mnemonic ?? Keyring.generateMnemonic() })
const privateKey = fromHex(keyring.getPrivateKey(path ?? DEFAULT_PATH))
const wallet = mnemonic
? Wallet.fromMnemonic(mnemonic, path ?? DEFAULT_PATH)
: Wallet.createRandom({ path: path ?? DEFAULT_PATH })
const privateKey = fromHex(wallet.privateKey.replace('0x', ''))
const directSigner = await DirectSecp256k1Wallet.fromKey(privateKey, prefix ?? DEFAULT_PREFIX)
const aminoSigner = await Secp256k1Wallet.fromKey(privateKey, prefix ?? DEFAULT_PREFIX)

return new CosmosLib(keyring, directSigner, aminoSigner)
return new CosmosLib(wallet.mnemonic.phrase, directSigner, aminoSigner)
}

public getMnemonic() {
return this.keyring.mnemonic
return this.mnemonic
}

public async getAddress() {
Expand Down
4 changes: 2 additions & 2 deletions advanced/wallets/react-wallet-v2/src/lib/TezosLib.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { TezosToolkit } from '@taquito/taquito'
import { InMemorySigner } from '@taquito/signer'
import { localForger } from '@taquito/local-forging'
import Keyring from 'mnemonic-keyring'
import { Wallet } from 'ethers/'

/**
* Constants
Expand Down Expand Up @@ -50,7 +50,7 @@ export default class TezosLib {

static async init({ mnemonic, path, curve }: IInitArguments) {
const params = {
mnemonic: mnemonic ?? Keyring.generateMnemonic(),
mnemonic: mnemonic ?? Wallet.createRandom().mnemonic.phrase,
derivationPath: path ?? DEFAULT_PATH,
curve: curve ?? DEFAULT_CURVE
}
Expand Down
Loading

0 comments on commit 9525e8c

Please sign in to comment.