1
1
import { computed , readonly } from 'vue'
2
2
import { useStore } from '../store'
3
- import { ConnectOptions , ConnectorName , ProviderTarget , RDNS } from '../types'
3
+ import { ConnectOptions , ConnectorName , ProviderTarget } from '../types'
4
4
import { AutoConnectError , ConnectError , ConnectorNotFoundError } from '../errors'
5
5
import { normalizeChainId } from '../utils'
6
6
import {
@@ -24,7 +24,7 @@ export function useConnect(pinia?: any) {
24
24
walletStore . wallet . providerTarget = null
25
25
}
26
26
27
- async function connectTo ( connectorName : ConnectorName | string , options ? : ConnectOptions ) {
27
+ async function connectTo < T extends ConnectorName > ( connectorName : T , options : ConnectOptions < T > ) {
28
28
walletStore . wallet . error = ''
29
29
walletStore . wallet . status = 'connecting'
30
30
@@ -36,11 +36,8 @@ export function useConnect(pinia?: any) {
36
36
const { provider, account, chainId, info } = await connector . connect ( options )
37
37
38
38
if ( connector . name === 'BrowserWallet' ) {
39
- if ( ! info ) throw new Error ( 'BrowserWallet connector requires provider info' )
40
- if ( ! options ?. target ) throw new Error ( 'BrowserWallet connector requires target' )
41
-
42
- walletStore . wallet . providerInfo = info
43
- walletStore . wallet . providerTarget = options ?. target
39
+ walletStore . wallet . providerInfo = info || null
40
+ walletStore . wallet . providerTarget = options ?. target || null
44
41
}
45
42
46
43
walletStore . wallet . connector = connector
@@ -114,12 +111,14 @@ export function useConnect(pinia?: any) {
114
111
const browserWallet = walletStore . connectors . find ( conn => conn . name === 'BrowserWallet' )
115
112
if ( ! browserWallet ) return
116
113
117
- let options : ConnectOptions
114
+ let options : ConnectOptions < 'BrowserWallet' >
118
115
119
116
switch ( target ) {
120
117
case 'window.ethereum' :
121
118
if ( ! isWindowEthereumAvailable ) return
122
- options = { target : 'window.ethereum' }
119
+ options = {
120
+ target : 'window.ethereum' ,
121
+ }
123
122
break
124
123
case 'rdns' :
125
124
const lastRdns = getLastConnectedBrowserWallet ( )
@@ -132,7 +131,7 @@ export function useConnect(pinia?: any) {
132
131
}
133
132
134
133
try {
135
- await connectTo ( browserWallet . name , options )
134
+ await connectTo ( 'BrowserWallet' , options )
136
135
} catch ( err : any ) {
137
136
throw new AutoConnectError ( err )
138
137
}
0 commit comments