@wagmi/connectors 3.1.1 → 4.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -39
- package/dist/esm/coinbaseWallet.js +141 -0
- package/dist/esm/coinbaseWallet.js.map +1 -0
- package/dist/esm/exports/index.js +7 -0
- package/dist/esm/exports/index.js.map +1 -0
- package/dist/esm/exports/index.test-d.js +4 -0
- package/dist/esm/exports/index.test-d.js.map +1 -0
- package/dist/esm/injected.js +372 -0
- package/dist/esm/injected.js.map +1 -0
- package/dist/esm/ledger.js +162 -0
- package/dist/esm/ledger.js.map +1 -0
- package/dist/esm/safe.js +88 -0
- package/dist/esm/safe.js.map +1 -0
- package/dist/esm/tsconfig.build.tsbuildinfo +1 -0
- package/dist/esm/version.js +2 -0
- package/dist/esm/version.js.map +1 -0
- package/dist/esm/walletConnect.js +280 -0
- package/dist/esm/walletConnect.js.map +1 -0
- package/dist/types/coinbaseWallet.d.ts +21 -0
- package/dist/types/coinbaseWallet.d.ts.map +1 -0
- package/dist/types/exports/index.d.ts +7 -0
- package/dist/types/exports/index.d.ts.map +1 -0
- package/dist/types/exports/index.test-d.d.ts +2 -0
- package/dist/types/exports/index.test-d.d.ts.map +1 -0
- package/dist/types/injected.d.ts +382 -0
- package/dist/types/injected.d.ts.map +1 -0
- package/dist/types/ledger.d.ts +18 -0
- package/dist/types/ledger.d.ts.map +1 -0
- package/dist/types/safe.d.ts +18 -0
- package/dist/types/safe.d.ts.map +1 -0
- package/dist/types/version.d.ts +2 -0
- package/dist/types/version.d.ts.map +1 -0
- package/dist/types/walletConnect.d.ts +63 -0
- package/dist/types/walletConnect.d.ts.map +1 -0
- package/package.json +43 -82
- package/src/coinbaseWallet.ts +207 -0
- package/src/exports/index.ts +17 -0
- package/src/injected.ts +535 -0
- package/src/ledger.ts +210 -0
- package/src/safe.ts +114 -0
- package/src/version.ts +1 -0
- package/src/walletConnect.ts +394 -0
- package/coinbaseWallet/package.json +0 -4
- package/dist/base-70e3a8a9.d.ts +0 -142
- package/dist/chunk-2UFLHRLT.js +0 -391
- package/dist/chunk-OQILYQDO.js +0 -15
- package/dist/chunk-UGBGYVBH.js +0 -22
- package/dist/chunk-W65LBPLT.js +0 -58
- package/dist/coinbaseWallet.d.ts +0 -62
- package/dist/coinbaseWallet.js +0 -216
- package/dist/index.d.ts +0 -20
- package/dist/index.js +0 -16
- package/dist/injected.d.ts +0 -64
- package/dist/injected.js +0 -9
- package/dist/ledger.d.ts +0 -69
- package/dist/ledger.js +0 -261
- package/dist/metaMask.d.ts +0 -33
- package/dist/metaMask.js +0 -144
- package/dist/mock/index.d.ts +0 -80
- package/dist/mock/index.js +0 -200
- package/dist/safe.d.ts +0 -53
- package/dist/safe.js +0 -129
- package/dist/walletConnect.d.ts +0 -109
- package/dist/walletConnect.js +0 -325
- package/dist/walletConnectLegacy.d.ts +0 -38
- package/dist/walletConnectLegacy.js +0 -179
- package/injected/package.json +0 -4
- package/ledger/package.json +0 -4
- package/metaMask/package.json +0 -4
- package/mock/package.json +0 -4
- package/safe/package.json +0 -4
- package/walletConnect/package.json +0 -4
- package/walletConnectLegacy/package.json +0 -4
|
@@ -0,0 +1,394 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ChainNotConfiguredError,
|
|
3
|
+
ProviderNotFoundError,
|
|
4
|
+
createConnector,
|
|
5
|
+
normalizeChainId,
|
|
6
|
+
} from '@wagmi/core'
|
|
7
|
+
import type { Evaluate, ExactPartial, Omit } from '@wagmi/core/internal'
|
|
8
|
+
import {
|
|
9
|
+
EthereumProvider,
|
|
10
|
+
OPTIONAL_EVENTS,
|
|
11
|
+
OPTIONAL_METHODS,
|
|
12
|
+
} from '@walletconnect/ethereum-provider'
|
|
13
|
+
import {
|
|
14
|
+
type Address,
|
|
15
|
+
type ProviderConnectInfo,
|
|
16
|
+
type ProviderRpcError,
|
|
17
|
+
SwitchChainError,
|
|
18
|
+
UserRejectedRequestError,
|
|
19
|
+
getAddress,
|
|
20
|
+
numberToHex,
|
|
21
|
+
} from 'viem'
|
|
22
|
+
|
|
23
|
+
type EthereumProviderOptions = Parameters<typeof EthereumProvider['init']>[0]
|
|
24
|
+
|
|
25
|
+
export type WalletConnectParameters = Evaluate<
|
|
26
|
+
{
|
|
27
|
+
/**
|
|
28
|
+
* If a new chain is added to a previously existing configured connector `chains`, this flag
|
|
29
|
+
* will determine if that chain should be considered as stale. A stale chain is a chain that
|
|
30
|
+
* WalletConnect has yet to establish a relationship with (ie. the user has not approved or
|
|
31
|
+
* rejected the chain).
|
|
32
|
+
*
|
|
33
|
+
* Preface: Whereas WalletConnect v1 supported dynamic chain switching, WalletConnect v2 requires
|
|
34
|
+
* the user to pre-approve a set of chains up-front. This comes with consequent UX nuances (see below) when
|
|
35
|
+
* a user tries to switch to a chain that they have not approved.
|
|
36
|
+
*
|
|
37
|
+
* This flag mainly affects the behavior when a wallet does not support dynamic chain authorization
|
|
38
|
+
* with WalletConnect v2.
|
|
39
|
+
*
|
|
40
|
+
* If `true` (default), the new chain will be treated as a stale chain. If the user
|
|
41
|
+
* has yet to establish a relationship (approved/rejected) with this chain in their WalletConnect
|
|
42
|
+
* session, the connector will disconnect upon the dapp auto-connecting, and the user will have to
|
|
43
|
+
* reconnect to the dapp (revalidate the chain) in order to approve the newly added chain.
|
|
44
|
+
* This is the default behavior to avoid an unexpected error upon switching chains which may
|
|
45
|
+
* be a confusing user experience (ie. the user will not know they have to reconnect
|
|
46
|
+
* unless the dapp handles these types of errors).
|
|
47
|
+
*
|
|
48
|
+
* If `false`, the new chain will be treated as a validated chain. This means that if the user
|
|
49
|
+
* has yet to establish a relationship with the chain in their WalletConnect session, wagmi will successfully
|
|
50
|
+
* auto-connect the user. This comes with the trade-off that the connector will throw an error
|
|
51
|
+
* when attempting to switch to the unapproved chain. This may be useful in cases where a dapp constantly
|
|
52
|
+
* modifies their configured chains, and they do not want to disconnect the user upon
|
|
53
|
+
* auto-connecting. If the user decides to switch to the unapproved chain, it is important that the
|
|
54
|
+
* dapp handles this error and prompts the user to reconnect to the dapp in order to approve
|
|
55
|
+
* the newly added chain.
|
|
56
|
+
*
|
|
57
|
+
* @default true
|
|
58
|
+
*/
|
|
59
|
+
isNewChainsStale?: boolean
|
|
60
|
+
} & Omit<
|
|
61
|
+
EthereumProviderOptions,
|
|
62
|
+
| 'chains'
|
|
63
|
+
| 'events'
|
|
64
|
+
| 'optionalChains'
|
|
65
|
+
| 'optionalEvents'
|
|
66
|
+
| 'optionalMethods'
|
|
67
|
+
| 'methods'
|
|
68
|
+
| 'rpcMap'
|
|
69
|
+
| 'showQrModal'
|
|
70
|
+
> &
|
|
71
|
+
ExactPartial<Pick<EthereumProviderOptions, 'showQrModal'>>
|
|
72
|
+
>
|
|
73
|
+
|
|
74
|
+
export function walletConnect(parameters: WalletConnectParameters) {
|
|
75
|
+
const isNewChainsStale = parameters.isNewChainsStale ?? true
|
|
76
|
+
|
|
77
|
+
type Provider = Awaited<ReturnType<typeof EthereumProvider['init']>>
|
|
78
|
+
type NamespaceMethods =
|
|
79
|
+
| 'wallet_addEthereumChain'
|
|
80
|
+
| 'wallet_switchEthereumChain'
|
|
81
|
+
type Properties = {
|
|
82
|
+
connect(parameters?: { chainId?: number; pairingTopic?: string }): Promise<{
|
|
83
|
+
accounts: readonly Address[]
|
|
84
|
+
chainId: number
|
|
85
|
+
}>
|
|
86
|
+
getNamespaceChainsIds(): number[]
|
|
87
|
+
getNamespaceMethods(): NamespaceMethods[]
|
|
88
|
+
getRequestedChainsIds(): Promise<number[]>
|
|
89
|
+
isChainsStale(): Promise<boolean>
|
|
90
|
+
onConnect(connectInfo: ProviderConnectInfo): void
|
|
91
|
+
onDisplayUri(uri: string): void
|
|
92
|
+
onSessionDelete(data: { topic: string }): void
|
|
93
|
+
setRequestedChainsIds(chains: number[]): void
|
|
94
|
+
requestedChainsStorageKey: `${string}.requestedChains`
|
|
95
|
+
}
|
|
96
|
+
type StorageItem = {
|
|
97
|
+
[_ in Properties['requestedChainsStorageKey']]: number[]
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
let provider_: Provider | undefined
|
|
101
|
+
let providerPromise: Promise<typeof provider_>
|
|
102
|
+
const NAMESPACE = 'eip155'
|
|
103
|
+
|
|
104
|
+
return createConnector<Provider, Properties, StorageItem>((config) => ({
|
|
105
|
+
id: 'walletConnect',
|
|
106
|
+
name: 'WalletConnect',
|
|
107
|
+
async setup() {
|
|
108
|
+
const provider = await this.getProvider()
|
|
109
|
+
if (!provider) return
|
|
110
|
+
provider.on('connect', this.onConnect.bind(this))
|
|
111
|
+
provider.on('session_delete', this.onSessionDelete.bind(this))
|
|
112
|
+
},
|
|
113
|
+
async connect({ chainId, ...rest } = {}) {
|
|
114
|
+
try {
|
|
115
|
+
const provider = await this.getProvider()
|
|
116
|
+
if (!provider) throw new ProviderNotFoundError()
|
|
117
|
+
provider.on('display_uri', this.onDisplayUri)
|
|
118
|
+
|
|
119
|
+
let targetChainId = chainId
|
|
120
|
+
if (!targetChainId) {
|
|
121
|
+
const state = (await config.storage?.getItem('state')) ?? {}
|
|
122
|
+
const isChainSupported = config.chains.some(
|
|
123
|
+
(x) => x.id === state.chainId,
|
|
124
|
+
)
|
|
125
|
+
if (isChainSupported) targetChainId = state.chainId
|
|
126
|
+
else targetChainId = config.chains[0]?.id
|
|
127
|
+
}
|
|
128
|
+
if (!targetChainId) throw new Error('No chains found on connector.')
|
|
129
|
+
|
|
130
|
+
const isChainsStale = await this.isChainsStale()
|
|
131
|
+
// If there is an active session with stale chains, disconnect current session.
|
|
132
|
+
if (provider.session && isChainsStale) await provider.disconnect()
|
|
133
|
+
|
|
134
|
+
// If there isn't an active session or chains are stale, connect.
|
|
135
|
+
if (!provider.session || isChainsStale) {
|
|
136
|
+
const optionalChains = config.chains
|
|
137
|
+
.filter((chain) => chain.id !== targetChainId)
|
|
138
|
+
.map((optionalChain) => optionalChain.id)
|
|
139
|
+
await provider.connect({
|
|
140
|
+
chains: [targetChainId],
|
|
141
|
+
optionalChains,
|
|
142
|
+
...('pairingTopic' in rest
|
|
143
|
+
? { pairingTopic: rest.pairingTopic }
|
|
144
|
+
: {}),
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
this.setRequestedChainsIds(config.chains.map((x) => x.id))
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// If session exists and chains are authorized, enable provider for required chain
|
|
151
|
+
const accounts = (await provider.enable()).map(getAddress)
|
|
152
|
+
const currentChainId = await this.getChainId()
|
|
153
|
+
|
|
154
|
+
provider.removeListener('display_uri', this.onDisplayUri)
|
|
155
|
+
provider.removeListener('connect', this.onConnect.bind(this))
|
|
156
|
+
provider.on('accountsChanged', this.onAccountsChanged.bind(this))
|
|
157
|
+
provider.on('chainChanged', this.onChainChanged)
|
|
158
|
+
provider.on('disconnect', this.onDisconnect.bind(this))
|
|
159
|
+
provider.on('session_delete', this.onSessionDelete.bind(this))
|
|
160
|
+
|
|
161
|
+
return { accounts, chainId: currentChainId }
|
|
162
|
+
} catch (error) {
|
|
163
|
+
if (
|
|
164
|
+
/(user rejected|connection request reset)/i.test(
|
|
165
|
+
(error as ProviderRpcError)?.message,
|
|
166
|
+
)
|
|
167
|
+
) {
|
|
168
|
+
throw new UserRejectedRequestError(error as Error)
|
|
169
|
+
}
|
|
170
|
+
throw error
|
|
171
|
+
}
|
|
172
|
+
},
|
|
173
|
+
async disconnect() {
|
|
174
|
+
const provider = await this.getProvider()
|
|
175
|
+
try {
|
|
176
|
+
await provider.disconnect()
|
|
177
|
+
} catch (error) {
|
|
178
|
+
if (!/No matching key/i.test((error as Error).message)) throw error
|
|
179
|
+
} finally {
|
|
180
|
+
provider.removeListener(
|
|
181
|
+
'accountsChanged',
|
|
182
|
+
this.onAccountsChanged.bind(this),
|
|
183
|
+
)
|
|
184
|
+
provider.removeListener('chainChanged', this.onChainChanged)
|
|
185
|
+
provider.removeListener('disconnect', this.onDisconnect.bind(this))
|
|
186
|
+
provider.removeListener(
|
|
187
|
+
'session_delete',
|
|
188
|
+
this.onSessionDelete.bind(this),
|
|
189
|
+
)
|
|
190
|
+
provider.on('connect', this.onConnect.bind(this))
|
|
191
|
+
|
|
192
|
+
this.setRequestedChainsIds([])
|
|
193
|
+
}
|
|
194
|
+
},
|
|
195
|
+
async getAccounts() {
|
|
196
|
+
const provider = await this.getProvider()
|
|
197
|
+
return provider.accounts.map(getAddress)
|
|
198
|
+
},
|
|
199
|
+
async getProvider({ chainId } = {}) {
|
|
200
|
+
async function initProvider() {
|
|
201
|
+
const [defaultChain, ...optionalChains] = config.chains.map((x) => x.id)
|
|
202
|
+
if (!defaultChain) return
|
|
203
|
+
return await EthereumProvider.init({
|
|
204
|
+
...parameters,
|
|
205
|
+
chains: [defaultChain],
|
|
206
|
+
disableProviderPing: true,
|
|
207
|
+
optionalMethods: OPTIONAL_METHODS,
|
|
208
|
+
optionalEvents: OPTIONAL_EVENTS,
|
|
209
|
+
optionalChains,
|
|
210
|
+
projectId: parameters.projectId,
|
|
211
|
+
rpcMap: Object.fromEntries(
|
|
212
|
+
config.chains.map((chain) => [
|
|
213
|
+
chain.id,
|
|
214
|
+
chain.rpcUrls.default.http[0]!,
|
|
215
|
+
]),
|
|
216
|
+
),
|
|
217
|
+
showQrModal: parameters.showQrModal ?? true,
|
|
218
|
+
})
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
if (!provider_) {
|
|
222
|
+
if (!providerPromise) providerPromise = initProvider()
|
|
223
|
+
provider_ = await providerPromise
|
|
224
|
+
}
|
|
225
|
+
if (chainId) await this.switchChain?.({ chainId })
|
|
226
|
+
return provider_!
|
|
227
|
+
},
|
|
228
|
+
async getChainId() {
|
|
229
|
+
const provider = await this.getProvider()
|
|
230
|
+
return provider.chainId
|
|
231
|
+
},
|
|
232
|
+
async isAuthorized() {
|
|
233
|
+
try {
|
|
234
|
+
const [accounts, provider] = await Promise.all([
|
|
235
|
+
this.getAccounts(),
|
|
236
|
+
this.getProvider(),
|
|
237
|
+
])
|
|
238
|
+
|
|
239
|
+
// If an account does not exist on the session, then the connector is unauthorized.
|
|
240
|
+
if (!accounts.length) return false
|
|
241
|
+
|
|
242
|
+
// If the chains are stale on the session, then the connector is unauthorized.
|
|
243
|
+
const isChainsStale = await this.isChainsStale()
|
|
244
|
+
if (isChainsStale && provider.session) {
|
|
245
|
+
await provider.disconnect().catch(() => {})
|
|
246
|
+
return false
|
|
247
|
+
}
|
|
248
|
+
return true
|
|
249
|
+
} catch {
|
|
250
|
+
return false
|
|
251
|
+
}
|
|
252
|
+
},
|
|
253
|
+
async switchChain({ chainId }) {
|
|
254
|
+
const chain = config.chains.find((chain) => chain.id === chainId)
|
|
255
|
+
if (!chain) throw new SwitchChainError(new ChainNotConfiguredError())
|
|
256
|
+
|
|
257
|
+
try {
|
|
258
|
+
const provider = await this.getProvider()
|
|
259
|
+
const namespaceChains = this.getNamespaceChainsIds()
|
|
260
|
+
const namespaceMethods = this.getNamespaceMethods()
|
|
261
|
+
const isChainApproved = namespaceChains.includes(chainId)
|
|
262
|
+
|
|
263
|
+
if (
|
|
264
|
+
!isChainApproved &&
|
|
265
|
+
namespaceMethods.includes('wallet_addEthereumChain')
|
|
266
|
+
) {
|
|
267
|
+
await provider.request({
|
|
268
|
+
method: 'wallet_addEthereumChain',
|
|
269
|
+
params: [
|
|
270
|
+
{
|
|
271
|
+
chainId: numberToHex(chain.id),
|
|
272
|
+
blockExplorerUrls: [chain.blockExplorers?.default],
|
|
273
|
+
chainName: chain.name,
|
|
274
|
+
nativeCurrency: chain.nativeCurrency,
|
|
275
|
+
rpcUrls: [...chain.rpcUrls.default.http],
|
|
276
|
+
},
|
|
277
|
+
],
|
|
278
|
+
})
|
|
279
|
+
const requestedChains = await this.getRequestedChainsIds()
|
|
280
|
+
this.setRequestedChainsIds([...requestedChains, chainId])
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
await provider.request({
|
|
284
|
+
method: 'wallet_switchEthereumChain',
|
|
285
|
+
params: [{ chainId: numberToHex(chainId) }],
|
|
286
|
+
})
|
|
287
|
+
return chain
|
|
288
|
+
} catch (error) {
|
|
289
|
+
const message =
|
|
290
|
+
typeof error === 'string'
|
|
291
|
+
? error
|
|
292
|
+
: (error as ProviderRpcError)?.message
|
|
293
|
+
if (/user rejected request/i.test(message))
|
|
294
|
+
throw new UserRejectedRequestError(error as Error)
|
|
295
|
+
throw new SwitchChainError(error as Error)
|
|
296
|
+
}
|
|
297
|
+
},
|
|
298
|
+
onAccountsChanged(accounts) {
|
|
299
|
+
if (accounts.length === 0) this.onDisconnect()
|
|
300
|
+
else config.emitter.emit('change', { accounts: accounts.map(getAddress) })
|
|
301
|
+
},
|
|
302
|
+
onChainChanged(chain) {
|
|
303
|
+
const chainId = normalizeChainId(chain)
|
|
304
|
+
config.emitter.emit('change', { chainId })
|
|
305
|
+
},
|
|
306
|
+
async onConnect(connectInfo) {
|
|
307
|
+
const chainId = normalizeChainId(connectInfo.chainId)
|
|
308
|
+
const accounts = await this.getAccounts()
|
|
309
|
+
config.emitter.emit('connect', { accounts, chainId })
|
|
310
|
+
},
|
|
311
|
+
async onDisconnect(_error) {
|
|
312
|
+
this.setRequestedChainsIds([])
|
|
313
|
+
config.emitter.emit('disconnect')
|
|
314
|
+
|
|
315
|
+
const provider = await this.getProvider()
|
|
316
|
+
provider.removeListener(
|
|
317
|
+
'accountsChanged',
|
|
318
|
+
this.onAccountsChanged.bind(this),
|
|
319
|
+
)
|
|
320
|
+
provider.removeListener('chainChanged', this.onChainChanged)
|
|
321
|
+
provider.removeListener('disconnect', this.onDisconnect.bind(this))
|
|
322
|
+
provider.removeListener('session_delete', this.onSessionDelete.bind(this))
|
|
323
|
+
provider.on('connect', this.onConnect.bind(this))
|
|
324
|
+
},
|
|
325
|
+
onDisplayUri(uri) {
|
|
326
|
+
config.emitter.emit('message', { type: 'display_uri', data: uri })
|
|
327
|
+
},
|
|
328
|
+
onSessionDelete() {
|
|
329
|
+
this.onDisconnect()
|
|
330
|
+
},
|
|
331
|
+
getNamespaceChainsIds() {
|
|
332
|
+
if (!provider_) return []
|
|
333
|
+
const chainIds = provider_.session?.namespaces[NAMESPACE]?.chains?.map(
|
|
334
|
+
(chain) => parseInt(chain.split(':')[1] || ''),
|
|
335
|
+
)
|
|
336
|
+
return chainIds ?? []
|
|
337
|
+
},
|
|
338
|
+
getNamespaceMethods() {
|
|
339
|
+
if (!provider_) return []
|
|
340
|
+
const methods = provider_.session?.namespaces[NAMESPACE]
|
|
341
|
+
?.methods as NamespaceMethods[]
|
|
342
|
+
return methods ?? []
|
|
343
|
+
},
|
|
344
|
+
async getRequestedChainsIds() {
|
|
345
|
+
return (
|
|
346
|
+
(await config.storage?.getItem(this.requestedChainsStorageKey)) ?? []
|
|
347
|
+
)
|
|
348
|
+
},
|
|
349
|
+
/**
|
|
350
|
+
* Checks if the target chains match the chains that were
|
|
351
|
+
* initially requested by the connector for the WalletConnect session.
|
|
352
|
+
* If there is a mismatch, this means that the chains on the connector
|
|
353
|
+
* are considered stale, and need to be revalidated at a later point (via
|
|
354
|
+
* connection).
|
|
355
|
+
*
|
|
356
|
+
* There may be a scenario where a dapp adds a chain to the
|
|
357
|
+
* connector later on, however, this chain will not have been approved or rejected
|
|
358
|
+
* by the wallet. In this case, the chain is considered stale.
|
|
359
|
+
*
|
|
360
|
+
* There are exceptions however:
|
|
361
|
+
* - If the wallet supports dynamic chain addition via `eth_addEthereumChain`,
|
|
362
|
+
* then the chain is not considered stale.
|
|
363
|
+
* - If the `isNewChainsStale` flag is falsy on the connector, then the chain is
|
|
364
|
+
* not considered stale.
|
|
365
|
+
*
|
|
366
|
+
* For the above cases, chain validation occurs dynamically when the user
|
|
367
|
+
* attempts to switch chain.
|
|
368
|
+
*
|
|
369
|
+
* Also check that dapp supports at least 1 chain from previously approved session.
|
|
370
|
+
*/
|
|
371
|
+
async isChainsStale() {
|
|
372
|
+
const namespaceMethods = this.getNamespaceMethods()
|
|
373
|
+
if (namespaceMethods.includes('wallet_addEthereumChain')) return false
|
|
374
|
+
if (!isNewChainsStale) return false
|
|
375
|
+
|
|
376
|
+
const connectorChains = config.chains.map((x) => x.id)
|
|
377
|
+
const namespaceChains = this.getNamespaceChainsIds()
|
|
378
|
+
if (
|
|
379
|
+
namespaceChains.length &&
|
|
380
|
+
!namespaceChains.some((id) => connectorChains.includes(id))
|
|
381
|
+
)
|
|
382
|
+
return false
|
|
383
|
+
|
|
384
|
+
const requestedChains = await this.getRequestedChainsIds()
|
|
385
|
+
return !connectorChains.every((id) => requestedChains.includes(id))
|
|
386
|
+
},
|
|
387
|
+
async setRequestedChainsIds(chains) {
|
|
388
|
+
await config.storage?.setItem(this.requestedChainsStorageKey, chains)
|
|
389
|
+
},
|
|
390
|
+
get requestedChainsStorageKey() {
|
|
391
|
+
return `${this.id}.requestedChains` as Properties['requestedChainsStorageKey']
|
|
392
|
+
},
|
|
393
|
+
}))
|
|
394
|
+
}
|
package/dist/base-70e3a8a9.d.ts
DELETED
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import EventEmitter from 'eventemitter3';
|
|
2
|
-
import { EIP1193Provider, Transport, Chain, Account, WalletClient as WalletClient$1, Address } from 'viem';
|
|
3
|
-
import { Chain as Chain$1 } from 'viem/chains';
|
|
4
|
-
|
|
5
|
-
type InjectedProviderFlags = {
|
|
6
|
-
isApexWallet?: true;
|
|
7
|
-
isAvalanche?: true;
|
|
8
|
-
isBackpack?: true;
|
|
9
|
-
isBifrost?: true;
|
|
10
|
-
isBitKeep?: true;
|
|
11
|
-
isBitski?: true;
|
|
12
|
-
isBlockWallet?: true;
|
|
13
|
-
isBraveWallet?: true;
|
|
14
|
-
isCoin98?: true;
|
|
15
|
-
isCoinbaseWallet?: true;
|
|
16
|
-
isDawn?: true;
|
|
17
|
-
isDefiant?: true;
|
|
18
|
-
isDesig?: true;
|
|
19
|
-
isEnkrypt?: true;
|
|
20
|
-
isExodus?: true;
|
|
21
|
-
isFordefi?: true;
|
|
22
|
-
isFrame?: true;
|
|
23
|
-
isFrontier?: true;
|
|
24
|
-
isGamestop?: true;
|
|
25
|
-
isHaloWallet?: true;
|
|
26
|
-
isHaqqWallet?: true;
|
|
27
|
-
isHyperPay?: true;
|
|
28
|
-
isImToken?: true;
|
|
29
|
-
isKuCoinWallet?: true;
|
|
30
|
-
isMathWallet?: true;
|
|
31
|
-
isMetaMask?: true;
|
|
32
|
-
isNovaWallet?: true;
|
|
33
|
-
isOkxWallet?: true;
|
|
34
|
-
isOKExWallet?: true;
|
|
35
|
-
isOneInchAndroidWallet?: true;
|
|
36
|
-
isOneInchIOSWallet?: true;
|
|
37
|
-
isOpera?: true;
|
|
38
|
-
isPhantom?: true;
|
|
39
|
-
isPortal?: true;
|
|
40
|
-
isRabby?: true;
|
|
41
|
-
isRainbow?: true;
|
|
42
|
-
isStatus?: true;
|
|
43
|
-
isSubWallet?: true;
|
|
44
|
-
isTalisman?: true;
|
|
45
|
-
isTally?: true;
|
|
46
|
-
isTokenPocket?: true;
|
|
47
|
-
isTokenary?: true;
|
|
48
|
-
isTrust?: true;
|
|
49
|
-
isTrustWallet?: true;
|
|
50
|
-
isTTWallet?: true;
|
|
51
|
-
isXDEFI?: true;
|
|
52
|
-
isZeal?: true;
|
|
53
|
-
isZerion?: true;
|
|
54
|
-
};
|
|
55
|
-
type InjectedProviders = InjectedProviderFlags & {
|
|
56
|
-
isMetaMask: true;
|
|
57
|
-
/** Only exists in MetaMask as of 2022/04/03 */
|
|
58
|
-
_events: {
|
|
59
|
-
connect?: () => void;
|
|
60
|
-
};
|
|
61
|
-
/** Only exists in MetaMask as of 2022/04/03 */
|
|
62
|
-
_state?: {
|
|
63
|
-
accounts?: string[];
|
|
64
|
-
initialized?: boolean;
|
|
65
|
-
isConnected?: boolean;
|
|
66
|
-
isPermanentlyDisconnected?: boolean;
|
|
67
|
-
isUnlocked?: boolean;
|
|
68
|
-
};
|
|
69
|
-
};
|
|
70
|
-
interface WindowProvider extends InjectedProviders, EIP1193Provider {
|
|
71
|
-
providers?: WindowProvider[];
|
|
72
|
-
}
|
|
73
|
-
type WalletClient<TTransport extends Transport = Transport, TChain extends Chain = Chain, TAccount extends Account = Account> = WalletClient$1<TTransport, TChain, TAccount>;
|
|
74
|
-
type Storage = {
|
|
75
|
-
getItem<T>(key: string, defaultState?: T | null): T | null;
|
|
76
|
-
setItem<T>(key: string, value: T | null): void;
|
|
77
|
-
removeItem(key: string): void;
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
type ConnectorData = {
|
|
81
|
-
account?: Address;
|
|
82
|
-
chain?: {
|
|
83
|
-
id: number;
|
|
84
|
-
unsupported: boolean;
|
|
85
|
-
};
|
|
86
|
-
};
|
|
87
|
-
interface ConnectorEvents {
|
|
88
|
-
change(data: ConnectorData): void;
|
|
89
|
-
connect(data: ConnectorData): void;
|
|
90
|
-
message({ type, data }: {
|
|
91
|
-
type: string;
|
|
92
|
-
data?: unknown;
|
|
93
|
-
}): void;
|
|
94
|
-
disconnect(): void;
|
|
95
|
-
error(error: Error): void;
|
|
96
|
-
}
|
|
97
|
-
declare abstract class Connector<Provider = any, Options = any> extends EventEmitter<ConnectorEvents> {
|
|
98
|
-
/** Unique connector id */
|
|
99
|
-
abstract readonly id: string;
|
|
100
|
-
/** Connector name */
|
|
101
|
-
abstract readonly name: string;
|
|
102
|
-
/** Chains connector supports */
|
|
103
|
-
readonly chains: Chain$1[];
|
|
104
|
-
/** Options to use with connector */
|
|
105
|
-
readonly options: Options;
|
|
106
|
-
/** Connector storage. */
|
|
107
|
-
protected storage?: Storage;
|
|
108
|
-
/** Whether connector is usable */
|
|
109
|
-
abstract readonly ready: boolean;
|
|
110
|
-
constructor({ chains, options, }: {
|
|
111
|
-
chains?: Chain$1[];
|
|
112
|
-
options: Options;
|
|
113
|
-
});
|
|
114
|
-
abstract connect(config?: {
|
|
115
|
-
chainId?: number;
|
|
116
|
-
}): Promise<Required<ConnectorData>>;
|
|
117
|
-
abstract disconnect(): Promise<void>;
|
|
118
|
-
abstract getAccount(): Promise<Address>;
|
|
119
|
-
abstract getChainId(): Promise<number>;
|
|
120
|
-
abstract getProvider(config?: {
|
|
121
|
-
chainId?: number;
|
|
122
|
-
}): Promise<Provider>;
|
|
123
|
-
abstract getWalletClient(config?: {
|
|
124
|
-
chainId?: number;
|
|
125
|
-
}): Promise<WalletClient>;
|
|
126
|
-
abstract isAuthorized(): Promise<boolean>;
|
|
127
|
-
switchChain?(chainId: number): Promise<Chain$1>;
|
|
128
|
-
watchAsset?(asset: {
|
|
129
|
-
address: string;
|
|
130
|
-
decimals?: number;
|
|
131
|
-
image?: string;
|
|
132
|
-
symbol: string;
|
|
133
|
-
}): Promise<boolean>;
|
|
134
|
-
protected abstract onAccountsChanged(accounts: Address[]): void;
|
|
135
|
-
protected abstract onChainChanged(chain: number | string): void;
|
|
136
|
-
protected abstract onDisconnect(error: Error): void;
|
|
137
|
-
protected getBlockExplorerUrls(chain: Chain$1): string[] | undefined;
|
|
138
|
-
protected isChainUnsupported(chainId: number): boolean;
|
|
139
|
-
setStorage(storage: Storage): void;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
export { Connector as C, WindowProvider as W, ConnectorData as a, ConnectorEvents as b, WalletClient as c };
|