@wagmi/connectors 5.5.0 → 5.5.2
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/dist/esm/metaMask.js +71 -45
- package/dist/esm/metaMask.js.map +1 -1
- package/dist/esm/tsconfig.build.tsbuildinfo +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/types/metaMask.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/package.json +3 -3
- package/src/metaMask.ts +88 -58
- package/src/version.ts +1 -1
package/dist/esm/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const version = '5.5.
|
|
1
|
+
export const version = '5.5.2';
|
|
2
2
|
//# sourceMappingURL=version.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metaMask.d.ts","sourceRoot":"","sources":["../../src/metaMask.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,kBAAkB,EAElB,WAAW,EACZ,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"metaMask.d.ts","sourceRoot":"","sources":["../../src/metaMask.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,kBAAkB,EAElB,WAAW,EACZ,MAAM,eAAe,CAAA;AAStB,OAAO,KAAK,EACV,OAAO,EACP,YAAY,EACZ,KAAK,EAEL,YAAY,EACb,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EAIL,KAAK,mBAAmB,EAUzB,MAAM,MAAM,CAAA;AAEb,MAAM,MAAM,kBAAkB,GAAG,YAAY,CAC3C,uBAAuB,GACrB,KAAK,CACD;IAEE,cAAc,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CACpC,GACD;IAGE,WAAW,CAAC,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,OAAO,EAAE,CAAA;KAAE,GAAG,SAAS,CAAA;CAChE,CACJ,CACJ,CAAA;AAED,KAAK,uBAAuB,GAAG,OAAO,CACpC,YAAY,CACV,IAAI,CACF,kBAAkB,EAChB,SAAS,GACT,qBAAqB,GACrB,qBAAqB,GACrB,gBAAgB,GAChB,aAAa,GACb,gBAAgB,CACnB,CACF,GAAG;IACF,kBAAkB;IAClB,mBAAmB,CAAC,EAAE,kBAAkB,CAAC,qBAAqB,CAAC,CAAA;IAC/D,kBAAkB;IAClB,mBAAmB,CAAC,EAAE,kBAAkB,CAAC,qBAAqB,CAAC,CAAA;IAC/D,kBAAkB;IAClB,cAAc,CAAC,EAAE,kBAAkB,CAAC,gBAAgB,CAAC,CAAA;IACrD,kBAAkB;IAClB,WAAW,CAAC,EAAE,kBAAkB,CAAC,aAAa,CAAC,CAAA;CAChD,CACF,CAAA;AAGD,wBAAgB,QAAQ,CAAC,UAAU,GAAE,kBAAuB;2BAGjC,mBAAmB,GAAG,IAAI;sBAC/B,MAAM,GAAG,IAAI;4BA6alC;yBAjbe,QAAQ"}
|
package/dist/types/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const version = "5.5.
|
|
1
|
+
export declare const version = "5.5.2";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wagmi/connectors",
|
|
3
3
|
"description": "Collection of connectors for Wagmi",
|
|
4
|
-
"version": "5.5.
|
|
4
|
+
"version": "5.5.2",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"peerDependencies": {
|
|
31
31
|
"typescript": ">=5.0.4",
|
|
32
32
|
"viem": "2.x",
|
|
33
|
-
"@wagmi/core": "2.15.
|
|
33
|
+
"@wagmi/core": "2.15.1"
|
|
34
34
|
},
|
|
35
35
|
"peerDependenciesMeta": {
|
|
36
36
|
"typescript": {
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"@coinbase/wallet-sdk": "4.2.3",
|
|
42
|
-
"@metamask/sdk": "0.
|
|
42
|
+
"@metamask/sdk": "0.31.0",
|
|
43
43
|
"@safe-global/safe-apps-provider": "0.18.4",
|
|
44
44
|
"@safe-global/safe-apps-sdk": "9.1.0",
|
|
45
45
|
"@walletconnect/ethereum-provider": "2.17.0",
|
package/src/metaMask.ts
CHANGED
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
createConnector,
|
|
12
12
|
extractRpcUrls,
|
|
13
13
|
} from '@wagmi/core'
|
|
14
|
+
import type { linea, lineaSepolia, mainnet, sepolia } from '@wagmi/core/chains'
|
|
14
15
|
import type {
|
|
15
16
|
Compute,
|
|
16
17
|
ExactPartial,
|
|
@@ -23,7 +24,6 @@ import {
|
|
|
23
24
|
type Address,
|
|
24
25
|
type Hex,
|
|
25
26
|
type ProviderConnectInfo,
|
|
26
|
-
type ProviderRpcError,
|
|
27
27
|
ResourceUnavailableRpcError,
|
|
28
28
|
type RpcError,
|
|
29
29
|
SwitchChainError,
|
|
@@ -308,6 +308,93 @@ export function metaMask(parameters: MetaMaskParameters = {}) {
|
|
|
308
308
|
const chain = config.chains.find((x) => x.id === chainId)
|
|
309
309
|
if (!chain) throw new SwitchChainError(new ChainNotConfiguredError())
|
|
310
310
|
|
|
311
|
+
// Default chains cannot be added or removed
|
|
312
|
+
const isDefaultChain = (() => {
|
|
313
|
+
const metaMaskDefaultChains = [
|
|
314
|
+
1, 11_155_111, 59_144, 59_141,
|
|
315
|
+
] satisfies [
|
|
316
|
+
typeof mainnet.id,
|
|
317
|
+
typeof sepolia.id,
|
|
318
|
+
typeof linea.id,
|
|
319
|
+
typeof lineaSepolia.id,
|
|
320
|
+
]
|
|
321
|
+
return metaMaskDefaultChains.find((x) => x === chainId)
|
|
322
|
+
})()
|
|
323
|
+
|
|
324
|
+
// Avoid back and forth on mobile by using `'wallet_addEthereumChain'` for non-default chains
|
|
325
|
+
if (!isDefaultChain)
|
|
326
|
+
try {
|
|
327
|
+
const blockExplorerUrls = (() => {
|
|
328
|
+
const { default: blockExplorer, ...blockExplorers } =
|
|
329
|
+
chain.blockExplorers ?? {}
|
|
330
|
+
if (addEthereumChainParameter?.blockExplorerUrls)
|
|
331
|
+
return addEthereumChainParameter.blockExplorerUrls
|
|
332
|
+
if (blockExplorer)
|
|
333
|
+
return [
|
|
334
|
+
blockExplorer.url,
|
|
335
|
+
...Object.values(blockExplorers).map((x) => x.url),
|
|
336
|
+
]
|
|
337
|
+
return
|
|
338
|
+
})()
|
|
339
|
+
|
|
340
|
+
const rpcUrls = (() => {
|
|
341
|
+
if (addEthereumChainParameter?.rpcUrls?.length)
|
|
342
|
+
return addEthereumChainParameter.rpcUrls
|
|
343
|
+
return [chain.rpcUrls.default?.http[0] ?? '']
|
|
344
|
+
})()
|
|
345
|
+
|
|
346
|
+
await provider.request({
|
|
347
|
+
method: 'wallet_addEthereumChain',
|
|
348
|
+
params: [
|
|
349
|
+
{
|
|
350
|
+
blockExplorerUrls,
|
|
351
|
+
chainId: numberToHex(chainId),
|
|
352
|
+
chainName: addEthereumChainParameter?.chainName ?? chain.name,
|
|
353
|
+
iconUrls: addEthereumChainParameter?.iconUrls,
|
|
354
|
+
nativeCurrency:
|
|
355
|
+
addEthereumChainParameter?.nativeCurrency ??
|
|
356
|
+
chain.nativeCurrency,
|
|
357
|
+
rpcUrls,
|
|
358
|
+
} satisfies AddEthereumChainParameter,
|
|
359
|
+
],
|
|
360
|
+
})
|
|
361
|
+
|
|
362
|
+
// On mobile, there is a race condition between the result of `'wallet_addEthereumChain'` and `'eth_chainId'`.
|
|
363
|
+
// (`'eth_chainId'` from the MetaMask relay server).
|
|
364
|
+
// To avoid this, we wait for `'eth_chainId'` to return the expected chain ID with a retry loop.
|
|
365
|
+
let retryCount = 0
|
|
366
|
+
const currentChainId = await withRetry(
|
|
367
|
+
async () => {
|
|
368
|
+
retryCount += 1
|
|
369
|
+
const value = hexToNumber(
|
|
370
|
+
// `'eth_chainId'` is cached by the MetaMask SDK side to avoid unnecessary deeplinks
|
|
371
|
+
(await provider.request({ method: 'eth_chainId' })) as Hex,
|
|
372
|
+
)
|
|
373
|
+
if (value !== chainId) {
|
|
374
|
+
if (retryCount === 5) return -1
|
|
375
|
+
// `value` doesn't match expected `chainId`, throw to trigger retry
|
|
376
|
+
throw new Error('Chain ID mismatch')
|
|
377
|
+
}
|
|
378
|
+
return value
|
|
379
|
+
},
|
|
380
|
+
{
|
|
381
|
+
delay: 100,
|
|
382
|
+
retryCount: 5, // android device encryption is slower
|
|
383
|
+
},
|
|
384
|
+
)
|
|
385
|
+
|
|
386
|
+
if (currentChainId !== chainId)
|
|
387
|
+
throw new Error('User rejected switch after adding network.')
|
|
388
|
+
|
|
389
|
+
return chain
|
|
390
|
+
} catch (err) {
|
|
391
|
+
const error = err as RpcError
|
|
392
|
+
if (error.code === UserRejectedRequestError.code)
|
|
393
|
+
throw new UserRejectedRequestError(error)
|
|
394
|
+
throw new SwitchChainError(error)
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
// Use to `'wallet_switchEthereumChain'` for default chains
|
|
311
398
|
try {
|
|
312
399
|
await Promise.all([
|
|
313
400
|
provider
|
|
@@ -338,63 +425,6 @@ export function metaMask(parameters: MetaMaskParameters = {}) {
|
|
|
338
425
|
return chain
|
|
339
426
|
} catch (err) {
|
|
340
427
|
const error = err as RpcError
|
|
341
|
-
|
|
342
|
-
// Indicates chain is not added to provider
|
|
343
|
-
if (
|
|
344
|
-
error.code === 4902 ||
|
|
345
|
-
// Unwrapping for MetaMask Mobile
|
|
346
|
-
// https://github.com/MetaMask/metamask-mobile/issues/2944#issuecomment-976988719
|
|
347
|
-
(error as ProviderRpcError<{ originalError?: { code: number } }>)
|
|
348
|
-
?.data?.originalError?.code === 4902
|
|
349
|
-
) {
|
|
350
|
-
try {
|
|
351
|
-
const { default: blockExplorer, ...blockExplorers } =
|
|
352
|
-
chain.blockExplorers ?? {}
|
|
353
|
-
let blockExplorerUrls: string[] | undefined
|
|
354
|
-
if (addEthereumChainParameter?.blockExplorerUrls)
|
|
355
|
-
blockExplorerUrls = addEthereumChainParameter.blockExplorerUrls
|
|
356
|
-
else if (blockExplorer)
|
|
357
|
-
blockExplorerUrls = [
|
|
358
|
-
blockExplorer.url,
|
|
359
|
-
...Object.values(blockExplorers).map((x) => x.url),
|
|
360
|
-
]
|
|
361
|
-
|
|
362
|
-
let rpcUrls: readonly string[]
|
|
363
|
-
if (addEthereumChainParameter?.rpcUrls?.length)
|
|
364
|
-
rpcUrls = addEthereumChainParameter.rpcUrls
|
|
365
|
-
else rpcUrls = [chain.rpcUrls.default?.http[0] ?? '']
|
|
366
|
-
|
|
367
|
-
const addEthereumChain = {
|
|
368
|
-
blockExplorerUrls,
|
|
369
|
-
chainId: numberToHex(chainId),
|
|
370
|
-
chainName: addEthereumChainParameter?.chainName ?? chain.name,
|
|
371
|
-
iconUrls: addEthereumChainParameter?.iconUrls,
|
|
372
|
-
nativeCurrency:
|
|
373
|
-
addEthereumChainParameter?.nativeCurrency ??
|
|
374
|
-
chain.nativeCurrency,
|
|
375
|
-
rpcUrls,
|
|
376
|
-
} satisfies AddEthereumChainParameter
|
|
377
|
-
|
|
378
|
-
await provider.request({
|
|
379
|
-
method: 'wallet_addEthereumChain',
|
|
380
|
-
params: [addEthereumChain],
|
|
381
|
-
})
|
|
382
|
-
|
|
383
|
-
const currentChainId = hexToNumber(
|
|
384
|
-
// Call `'eth_chainId'` directly to guard against `this.state.chainId` (via `provider.getChainId`) being stale.
|
|
385
|
-
(await provider.request({ method: 'eth_chainId' })) as Hex,
|
|
386
|
-
)
|
|
387
|
-
if (currentChainId !== chainId)
|
|
388
|
-
throw new UserRejectedRequestError(
|
|
389
|
-
new Error('User rejected switch after adding network.'),
|
|
390
|
-
)
|
|
391
|
-
|
|
392
|
-
return chain
|
|
393
|
-
} catch (error) {
|
|
394
|
-
throw new UserRejectedRequestError(error as Error)
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
|
|
398
428
|
if (error.code === UserRejectedRequestError.code)
|
|
399
429
|
throw new UserRejectedRequestError(error)
|
|
400
430
|
throw new SwitchChainError(error)
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '5.5.
|
|
1
|
+
export const version = '5.5.2'
|