1
- // import { chains } from '$lib/consts/chains';
2
1
import { CHAIN_DETAILS } from '@squirrel-labs/peanut-sdk' ;
3
2
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' ;
6
4
import { writable } from 'svelte/store' ;
7
5
8
6
import type { PeanutChain } from './types' ;
9
7
8
+ type Web3Modal = ReturnType < typeof createWeb3Modal > ;
10
9
export interface OpenOptions {
11
10
view : 'Account' | 'Connect' | 'Networks' ;
12
11
}
@@ -16,10 +15,6 @@ let modal: Web3Modal | null = null;
16
15
export const getAccountStores = ( ) => accountStores ;
17
16
18
17
export const accountStores = {
19
- provider : writable < ethers . providers . Web3Provider | undefined > ( undefined ) ,
20
- providerType : writable < 'walletConnect' | 'injected' | 'coinbaseWallet' | 'eip6963' | undefined > (
21
- undefined
22
- ) ,
23
18
address : writable < string | undefined > ( undefined ) ,
24
19
chainId : writable < number | undefined > ( undefined ) ,
25
20
isConnected : writable < boolean > ( false ) ,
@@ -55,26 +50,28 @@ export function initWeb3Modal() {
55
50
projectId
56
51
} ) ;
57
52
58
- //TODO: unsubribe
53
+ //TODO: unsubscribe
59
54
modal ?. subscribeProvider ( ( newState ) => {
60
- accountStores . provider . set ( newState . provider ) ;
61
- accountStores . providerType . set ( newState . providerType ) ;
62
55
accountStores . address . set ( newState . address ) ;
63
56
accountStores . chainId . set ( newState . chainId ) ;
64
57
accountStores . isConnected . set ( newState . isConnected ) ;
65
58
} ) ;
66
59
67
- //TODO: unsubribe
60
+ //TODO: unsubscribe
68
61
modal ?. subscribeState ( ( newState ) => {
69
62
modalSateStores . selectedNetworkId . set ( newState . selectedNetworkId ) ;
70
63
modalSateStores . isOpen . set ( newState . open ) ;
71
64
} ) ;
72
65
}
73
66
74
67
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 ( ) ;
78
75
}
79
76
80
77
export async function open ( options ?: OpenOptions ) {
0 commit comments