From 671a251632d71a6a163d5cc4ee36a4c94790a906 Mon Sep 17 00:00:00 2001 From: Christopher Cali Date: Tue, 1 Aug 2023 09:01:16 -0400 Subject: [PATCH] Commit progress before switching branches --- apps/web/package.json | 1 + apps/web/src/composables/contracts.ts | 8 +- apps/web/src/composables/walletConnectV2.ts | 25 +- apps/web/src/layouts/default-layout.vue | 14 + common/wallets/package.json | 1 + common/wallets/src/index.ts | 8 +- common/wallets/src/providers/walletConnect.ts | 64 +++++ package-lock.json | 242 ++++++++++++++++++ 8 files changed, 357 insertions(+), 6 deletions(-) create mode 100644 common/wallets/src/providers/walletConnect.ts diff --git a/apps/web/package.json b/apps/web/package.json index c9d1c0bd5..9a717e54a 100644 --- a/apps/web/package.json +++ b/apps/web/package.json @@ -14,6 +14,7 @@ "@walletconnect/web3-provider": "^1.8.0", "@web3modal/ethereum": "^2.7.1", "@web3modal/html": "^2.7.1", + "@web3modal/standalone": "^2.4.3", "borsh": "^0.7.0", "buffer": "^6.0.3", "d3": "^7.8.1", diff --git a/apps/web/src/composables/contracts.ts b/apps/web/src/composables/contracts.ts index 468beb9c7..303ed329b 100644 --- a/apps/web/src/composables/contracts.ts +++ b/apps/web/src/composables/contracts.ts @@ -10,6 +10,7 @@ import usePrice from '@/composables/price' import useTrezor from '@/composables/trezor' import useUsers from '@/composables/users' import useWalletConnect from './walletConnect' +import useWalletConnectV2 from './walletConnectV2' import { Account, BreakdownAmount, BreakdownString, ContractEventsByAddress, Pool, ProviderString, UserWithAccounts } from '@casimir/types' const currentStaked = ref({ @@ -39,6 +40,7 @@ export default function useContracts() { const { getEthersTrezorSigner } = useTrezor() const { user } = useUsers() const { isWalletConnectSigner, getEthersWalletConnectSigner } = useWalletConnect() + const { getEthersWalletConnectSignerV2 } = useWalletConnectV2() const stakeDepositedListener = async () => await refreshBreakdown() const stakeRebalancedListener = async () => await refreshBreakdown() @@ -51,12 +53,14 @@ export default function useContracts() { 'Browser': getEthersBrowserSigner, 'Ledger': getEthersLedgerSigner, 'Trezor': getEthersTrezorSigner, - 'WalletConnect': getEthersWalletConnectSigner + 'WalletConnect': getEthersWalletConnectSignerV2 } const signerType = ethersProviderList.includes(walletProvider) ? 'Browser' : walletProvider const signerCreator = signerCreators[signerType as keyof typeof signerCreators] let signer = signerCreator(walletProvider) - if (isWalletConnectSigner(signer)) signer = await signer + // if (isWalletConnectSigner(signer)) signer = await signer + signer = await signer + console.log('signer in deposit :>> ', signer) const managerSigner = manager.connect(signer as ethers.Signer) const fees = await getDepositFees() const depositAmount = parseFloat(amount) * ((100 + fees) / 100) diff --git a/apps/web/src/composables/walletConnectV2.ts b/apps/web/src/composables/walletConnectV2.ts index c7f527f70..f4269a6c8 100644 --- a/apps/web/src/composables/walletConnectV2.ts +++ b/apps/web/src/composables/walletConnectV2.ts @@ -1,22 +1,28 @@ +import { ethers } from 'ethers' +import { EthersWalletConnectSigner } from '@casimir/wallets' import { EthereumClient, w3mConnectors, w3mProvider } from '@web3modal/ethereum' import { Web3Modal } from '@web3modal/html' import { configureChains, createConfig, mainnet, signMessage } from '@wagmi/core' import { publicProvider } from '@wagmi/core/providers/public' -import useEthers from '@/composables/ethers' -import useAuth from '@/composables/auth' import { CryptoAddress, LoginCredentials } from '@casimir/types' import { infuraProvider } from '@wagmi/core/providers/infura' +import useAuth from '@/composables/auth' +import useEthers from '@/composables/ethers' +import useEnvironment from '@/composables/environment' const { getEthersBalance } = useEthers() const { createSiweMessage, signInWithEthereum } = useAuth() +const { ethereumUrl } = useEnvironment() // const chains = [mainnet] const projectId = '8e6877b49198d7a9f9561b8712805726' + + const { chains, publicClient } = configureChains( [mainnet], - [infuraProvider({ apiKey: import.meta.env.INFURA_API_KEY as string }), w3mProvider({ projectId }), publicProvider()] + [w3mProvider({ projectId }), publicProvider()] ) const wagmiConfig = createConfig({ autoConnect: true, @@ -28,6 +34,18 @@ export default function useWalletConnectV2() { const ethereumClient = new EthereumClient(wagmiConfig, chains) const web3modal = new Web3Modal({ projectId }, ethereumClient) + async function getEthersWalletConnectSignerV2() { + // const options = { + // provider: new ethers.providers.JsonRpcProvider(ethereumUrl), + // // baseURL: speculosUrl + // } + // return new EthersWalletConnectSigner(options) + const signer = EthersWalletConnectSigner.create({}) + // const signer = await EthersWalletConnectSigner.create({ provider: new ethers.providers.JsonRpcProvider(ethereumUrl) }) + console.log('signer :>> ', signer) + return signer + } + async function getWalletConnectAddressAndBalance() : Promise { const { address } = (ethereumClient.getAccount()) const balance = (await getEthersBalance(address as string)).toString() @@ -57,6 +75,7 @@ export default function useWalletConnectV2() { return { web3modal, getWalletConnectAddressAndBalance, + getEthersWalletConnectSignerV2, loginWithWalletConnectV2 } } \ No newline at end of file diff --git a/apps/web/src/layouts/default-layout.vue b/apps/web/src/layouts/default-layout.vue index d7be71cd8..fa1e3ad93 100644 --- a/apps/web/src/layouts/default-layout.vue +++ b/apps/web/src/layouts/default-layout.vue @@ -6,6 +6,12 @@ import router from '@/composables/router' import VueFeather from 'vue-feather' import useWallet from '@/composables/wallet' import useUser from '@/composables/users' +import useWalletConnectV2 from '@/composables/walletConnectV2' +const { getEthersWalletConnectSignerV2 } = useWalletConnectV2() + +async function func() { + await getEthersWalletConnectSignerV2() +} const authFlowCardNumber = ref(1) const selectedProivder = ref(null as null | string) @@ -74,6 +80,14 @@ onUnmounted(() =>{