Skip to content

Commit 0ba213c

Browse files
authored
Merge pull request #71 from zaibon/fix/wallet
fix: update method to get a signer from walletconnect provider
2 parents 6ae1d84 + e907492 commit 0ba213c

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,4 @@
6060
"@socket.tech/ll-core-v2": "^0.0.68"
6161
}
6262
}
63-
}
63+
}

src/lib/wallet.ts

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
// import { chains } from '$lib/consts/chains';
21
import { CHAIN_DETAILS } from '@squirrel-labs/peanut-sdk';
32
import { createWeb3Modal, defaultConfig } from '@web3modal/ethers5';
4-
import type { Web3Modal } from '@web3modal/ethers5/dist/types/src/client';
5-
import type { ethers } from 'ethers';
3+
import { ethers } from 'ethers';
64
import { writable } from 'svelte/store';
75

86
import type { PeanutChain } from './types';
97

8+
type Web3Modal = ReturnType<typeof createWeb3Modal>;
109
export interface OpenOptions {
1110
view: 'Account' | 'Connect' | 'Networks';
1211
}
@@ -16,10 +15,6 @@ let modal: Web3Modal | null = null;
1615
export const getAccountStores = () => accountStores;
1716

1817
export const accountStores = {
19-
provider: writable<ethers.providers.Web3Provider | undefined>(undefined),
20-
providerType: writable<'walletConnect' | 'injected' | 'coinbaseWallet' | 'eip6963' | undefined>(
21-
undefined
22-
),
2318
address: writable<string | undefined>(undefined),
2419
chainId: writable<number | undefined>(undefined),
2520
isConnected: writable<boolean>(false),
@@ -55,26 +50,28 @@ export function initWeb3Modal() {
5550
projectId
5651
});
5752

58-
//TODO: unsubribe
53+
//TODO: unsubscribe
5954
modal?.subscribeProvider((newState) => {
60-
accountStores.provider.set(newState.provider);
61-
accountStores.providerType.set(newState.providerType);
6255
accountStores.address.set(newState.address);
6356
accountStores.chainId.set(newState.chainId);
6457
accountStores.isConnected.set(newState.isConnected);
6558
});
6659

67-
//TODO: unsubribe
60+
//TODO: unsubscribe
6861
modal?.subscribeState((newState) => {
6962
modalSateStores.selectedNetworkId.set(newState.selectedNetworkId);
7063
modalSateStores.isOpen.set(newState.open);
7164
});
7265
}
7366

7467
function getSigner(): ethers.providers.JsonRpcSigner | undefined {
75-
if (modal) {
76-
return modal.getSigner();
77-
}
68+
if (!modal) return undefined;
69+
const provider = modal.getWalletProvider();
70+
71+
if (!provider) return undefined;
72+
73+
const p = new ethers.providers.Web3Provider(provider);
74+
return p.getSigner();
7875
}
7976

8077
export async function open(options?: OpenOptions) {

0 commit comments

Comments
 (0)