From e907492e484ee37a1f92be9f591bc2b0ad0479be Mon Sep 17 00:00:00 2001 From: Christophe de Carvalho Date: Fri, 15 Mar 2024 08:45:54 +0000 Subject: [PATCH] fix: update method to get a signer from walletconnect provider --- package.json | 2 +- src/lib/wallet.ts | 25 +++++++++++-------------- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/package.json b/package.json index f6bf326..39e5bdc 100644 --- a/package.json +++ b/package.json @@ -60,4 +60,4 @@ "@socket.tech/ll-core-v2": "^0.0.68" } } -} \ No newline at end of file +} diff --git a/src/lib/wallet.ts b/src/lib/wallet.ts index 8e482f4..7f484d6 100644 --- a/src/lib/wallet.ts +++ b/src/lib/wallet.ts @@ -1,12 +1,11 @@ -// import { chains } from '$lib/consts/chains'; import { CHAIN_DETAILS } from '@squirrel-labs/peanut-sdk'; import { createWeb3Modal, defaultConfig } from '@web3modal/ethers5'; -import type { Web3Modal } from '@web3modal/ethers5/dist/types/src/client'; -import type { ethers } from 'ethers'; +import { ethers } from 'ethers'; import { writable } from 'svelte/store'; import type { PeanutChain } from './types'; +type Web3Modal = ReturnType; export interface OpenOptions { view: 'Account' | 'Connect' | 'Networks'; } @@ -16,10 +15,6 @@ let modal: Web3Modal | null = null; export const getAccountStores = () => accountStores; export const accountStores = { - provider: writable(undefined), - providerType: writable<'walletConnect' | 'injected' | 'coinbaseWallet' | 'eip6963' | undefined>( - undefined - ), address: writable(undefined), chainId: writable(undefined), isConnected: writable(false), @@ -55,16 +50,14 @@ export function initWeb3Modal() { projectId }); - //TODO: unsubribe + //TODO: unsubscribe modal?.subscribeProvider((newState) => { - accountStores.provider.set(newState.provider); - accountStores.providerType.set(newState.providerType); accountStores.address.set(newState.address); accountStores.chainId.set(newState.chainId); accountStores.isConnected.set(newState.isConnected); }); - //TODO: unsubribe + //TODO: unsubscribe modal?.subscribeState((newState) => { modalSateStores.selectedNetworkId.set(newState.selectedNetworkId); modalSateStores.isOpen.set(newState.open); @@ -72,9 +65,13 @@ export function initWeb3Modal() { } function getSigner(): ethers.providers.JsonRpcSigner | undefined { - if (modal) { - return modal.getSigner(); - } + if (!modal) return undefined; + const provider = modal.getWalletProvider(); + + if (!provider) return undefined; + + const p = new ethers.providers.Web3Provider(provider); + return p.getSigner(); } export async function open(options?: OpenOptions) {