@wagmi/core 0.7.6 → 0.7.8

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.
@@ -1,8 +1,8 @@
1
1
  import { Address } from 'abitype';
2
2
  import EventEmitter from 'eventemitter3';
3
- import { C as Chain } from './index-bacc1c49.js';
3
+ import { C as Chain } from './index-58cffc47.js';
4
4
 
5
- declare type ConnectorData<Provider = any> = {
5
+ type ConnectorData<Provider = any> = {
6
6
  account?: Address;
7
7
  chain?: {
8
8
  id: number;
package/dist/chains.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export { k as arbitrum, l as arbitrumGoerli, m as foundry, n as goerli, o as hardhat, q as localhost, r as mainnet, t as optimism, v as optimismGoerli, w as polygon, x as polygonMumbai, s as sepolia } from './index-bacc1c49.js';
1
+ export { k as arbitrum, l as arbitrumGoerli, m as foundry, n as goerli, o as hardhat, q as localhost, r as mainnet, t as optimism, v as optimismGoerli, w as polygon, x as polygonMumbai, s as sepolia } from './index-58cffc47.js';
2
2
  import 'abitype';
3
3
  import 'ethers';
@@ -59,7 +59,7 @@ function configureChains(defaultChains2, providers3, {
59
59
  `Could not find valid provider configuration for chain "${chain2.name}".
60
60
  `,
61
61
  "You may need to add `jsonRpcProvider` to `configureChains` with the chain's RPC URLs.",
62
- "Read more: https://wagmi.sh/docs/providers/jsonRpc"
62
+ "Read more: https://wagmi.sh/react/providers/jsonRpc"
63
63
  ].join("\n")
64
64
  );
65
65
  }
@@ -217,8 +217,43 @@ function deepEqual(a, b) {
217
217
  return a !== a && b !== b;
218
218
  }
219
219
 
220
- // src/utils/normalizeFunctionName.ts
220
+ // src/utils/deserialize.ts
221
221
  import { BigNumber } from "ethers";
222
+ var findAndReplace = (cacheRef, {
223
+ find,
224
+ replace
225
+ }) => {
226
+ if (cacheRef && find(cacheRef)) {
227
+ return replace(cacheRef);
228
+ }
229
+ if (typeof cacheRef !== "object") {
230
+ return cacheRef;
231
+ }
232
+ if (Array.isArray(cacheRef)) {
233
+ return cacheRef.map((item) => findAndReplace(item, { find, replace }));
234
+ }
235
+ if (cacheRef instanceof Object) {
236
+ return Object.entries(cacheRef).reduce(
237
+ (curr, [key, value]) => ({
238
+ ...curr,
239
+ [key]: findAndReplace(value, { find, replace })
240
+ }),
241
+ {}
242
+ );
243
+ }
244
+ return cacheRef;
245
+ };
246
+ function deserialize(cachedString) {
247
+ const cache = JSON.parse(cachedString);
248
+ const deserializedCacheWithBigNumbers = findAndReplace(cache, {
249
+ find: (data) => data.type === "BigNumber",
250
+ replace: (data) => BigNumber.from(data.hex)
251
+ });
252
+ return deserializedCacheWithBigNumbers;
253
+ }
254
+
255
+ // src/utils/normalizeFunctionName.ts
256
+ import { BigNumber as BigNumber2 } from "ethers";
222
257
  import { FunctionFragment, isAddress } from "ethers/lib/utils.js";
223
258
  function normalizeFunctionName({
224
259
  contract,
@@ -264,7 +299,7 @@ function isArgOfType(arg, abiParameter) {
264
299
  if (/^u?int(8|16|24|32|40|48|56|64|72|80|88|96|104|112|120|128|136|144|152|160|168|176|184|192|200|208|216|224|232|240|248|256)?$/.test(
265
300
  abiParameterType
266
301
  ))
267
- return argType === "number" || argType === "bigint" || BigNumber.isBigNumber(arg);
302
+ return argType === "number" || argType === "bigint" || BigNumber2.isBigNumber(arg);
268
303
  if (/^bytes([1-9]|1[0-9]|2[0-9]|3[0-2])?$/.test(abiParameterType))
269
304
  return argType === "string" || arg instanceof Uint8Array;
270
305
  if (/[a-z]+[1-9]{0,3}(\[[0-9]{0,}\])+$/.test(abiParameterType)) {
@@ -399,6 +434,60 @@ function parseContractResult({
399
434
  return data;
400
435
  }
401
436
 
437
+ // src/utils/serialize.ts
438
+ function getReferenceKey(keys, cutoff) {
439
+ return keys.slice(0, cutoff).join(".") || ".";
440
+ }
441
+ function getCutoff(array, value) {
442
+ const { length } = array;
443
+ for (let index = 0; index < length; ++index) {
444
+ if (array[index] === value) {
445
+ return index + 1;
446
+ }
447
+ }
448
+ return 0;
449
+ }
450
+ function createReplacer(replacer, circularReplacer) {
451
+ const hasReplacer = typeof replacer === "function";
452
+ const hasCircularReplacer = typeof circularReplacer === "function";
453
+ const cache = [];
454
+ const keys = [];
455
+ return function replace(key, value) {
456
+ if (typeof value === "object") {
457
+ if (cache.length) {
458
+ const thisCutoff = getCutoff(cache, this);
459
+ if (thisCutoff === 0) {
460
+ cache[cache.length] = this;
461
+ } else {
462
+ cache.splice(thisCutoff);
463
+ keys.splice(thisCutoff);
464
+ }
465
+ keys[keys.length] = key;
466
+ const valueCutoff = getCutoff(cache, value);
467
+ if (valueCutoff !== 0) {
468
+ return hasCircularReplacer ? circularReplacer.call(
469
+ this,
470
+ key,
471
+ value,
472
+ getReferenceKey(keys, valueCutoff)
473
+ ) : `[ref=${getReferenceKey(keys, valueCutoff)}]`;
474
+ }
475
+ } else {
476
+ cache[0] = value;
477
+ keys[0] = key;
478
+ }
479
+ }
480
+ return hasReplacer ? replacer.call(this, key, value) : value;
481
+ };
482
+ }
483
+ function serialize(value, replacer, indent, circularReplacer) {
484
+ return JSON.stringify(
485
+ value,
486
+ createReplacer(replacer, circularReplacer),
487
+ indent ?? void 0
488
+ );
489
+ }
490
+
402
491
  // src/connectors/base.ts
403
492
  import { default as EventEmitter } from "eventemitter3";
404
493
 
@@ -1717,10 +1806,10 @@ var InjectedConnector = class extends Connector {
1717
1806
  const options = {
1718
1807
  shimDisconnect: true,
1719
1808
  shimChainChangedDisconnect: true,
1809
+ getProvider: () => typeof window !== "undefined" ? window.ethereum : void 0,
1720
1810
  ...options_
1721
1811
  };
1722
1812
  super({ chains, options });
1723
- this.ready = typeof window != "undefined" && !!window.ethereum;
1724
1813
  __privateAdd(this, _provider, void 0);
1725
1814
  __privateAdd(this, _switchingChains, void 0);
1726
1815
  this.shimDisconnectKey = "injected.shimDisconnect";
@@ -1738,27 +1827,31 @@ var InjectedConnector = class extends Connector {
1738
1827
  this.emit("change", { chain: { id, unsupported } });
1739
1828
  };
1740
1829
  this.onDisconnect = () => {
1741
- if (this.options?.shimChainChangedDisconnect && __privateGet(this, _switchingChains)) {
1830
+ if (this.options.shimChainChangedDisconnect && __privateGet(this, _switchingChains)) {
1742
1831
  __privateSet(this, _switchingChains, false);
1743
1832
  return;
1744
1833
  }
1745
1834
  this.emit("disconnect");
1746
- if (this.options?.shimDisconnect)
1835
+ if (this.options.shimDisconnect)
1747
1836
  getClient().storage?.removeItem(this.shimDisconnectKey);
1748
1837
  };
1749
- let name = "Injected";
1750
- const overrideName = options.name;
1751
- if (typeof overrideName === "string")
1752
- name = overrideName;
1753
- else if (typeof window !== "undefined") {
1754
- const detectedName = getInjectedName(window.ethereum);
1755
- if (overrideName)
1756
- name = overrideName(detectedName);
1757
- else
1758
- name = typeof detectedName === "string" ? detectedName : detectedName[0];
1759
- }
1838
+ const provider = options.getProvider();
1839
+ if (typeof options.name === "string")
1840
+ this.name = options.name;
1841
+ else if (provider) {
1842
+ const detectedName = getInjectedName(provider);
1843
+ if (options.name)
1844
+ this.name = options.name(detectedName);
1845
+ else {
1846
+ if (typeof detectedName === "string")
1847
+ this.name = detectedName;
1848
+ else
1849
+ this.name = detectedName[0];
1850
+ }
1851
+ } else
1852
+ this.name = "Injected";
1760
1853
  this.id = "injected";
1761
- this.name = name;
1854
+ this.ready = !!provider;
1762
1855
  }
1763
1856
  async connect({ chainId: chainId2 } = {}) {
1764
1857
  try {
@@ -1782,7 +1875,7 @@ var InjectedConnector = class extends Connector {
1782
1875
  id = chain2.id;
1783
1876
  unsupported = this.isChainUnsupported(id);
1784
1877
  }
1785
- if (this.options?.shimDisconnect)
1878
+ if (this.options.shimDisconnect)
1786
1879
  getClient().storage?.setItem(this.shimDisconnectKey, true);
1787
1880
  return { account, chain: { id, unsupported }, provider };
1788
1881
  } catch (error) {
@@ -1800,7 +1893,7 @@ var InjectedConnector = class extends Connector {
1800
1893
  provider.removeListener("accountsChanged", this.onAccountsChanged);
1801
1894
  provider.removeListener("chainChanged", this.onChainChanged);
1802
1895
  provider.removeListener("disconnect", this.onDisconnect);
1803
- if (this.options?.shimDisconnect)
1896
+ if (this.options.shimDisconnect)
1804
1897
  getClient().storage?.removeItem(this.shimDisconnectKey);
1805
1898
  }
1806
1899
  async getAccount() {
@@ -1819,8 +1912,9 @@ var InjectedConnector = class extends Connector {
1819
1912
  return provider.request({ method: "eth_chainId" }).then(normalizeChainId);
1820
1913
  }
1821
1914
  async getProvider() {
1822
- if (typeof window !== "undefined" && !!window.ethereum)
1823
- __privateSet(this, _provider, window.ethereum);
1915
+ const provider = this.options.getProvider();
1916
+ if (provider)
1917
+ __privateSet(this, _provider, provider);
1824
1918
  return __privateGet(this, _provider);
1825
1919
  }
1826
1920
  async getSigner({ chainId: chainId2 } = {}) {
@@ -1835,7 +1929,7 @@ var InjectedConnector = class extends Connector {
1835
1929
  }
1836
1930
  async isAuthorized() {
1837
1931
  try {
1838
- if (this.options?.shimDisconnect && !getClient().storage?.getItem(this.shimDisconnectKey))
1932
+ if (this.options.shimDisconnect && !getClient().storage?.getItem(this.shimDisconnectKey))
1839
1933
  return false;
1840
1934
  const provider = await this.getProvider();
1841
1935
  if (!provider)
@@ -1847,7 +1941,7 @@ var InjectedConnector = class extends Connector {
1847
1941
  }
1848
1942
  }
1849
1943
  async switchChain(chainId2) {
1850
- if (this.options?.shimChainChangedDisconnect)
1944
+ if (this.options.shimChainChangedDisconnect)
1851
1945
  __privateSet(this, _switchingChains, true);
1852
1946
  const provider = await this.getProvider();
1853
1947
  if (!provider)
@@ -1930,15 +2024,17 @@ var noopStorage = {
1930
2024
  removeItem: (_key) => null
1931
2025
  };
1932
2026
  function createStorage({
1933
- storage,
1934
- key: prefix = "wagmi"
2027
+ deserialize: deserialize2 = deserialize,
2028
+ key: prefix = "wagmi",
2029
+ serialize: serialize2 = serialize,
2030
+ storage
1935
2031
  }) {
1936
2032
  return {
1937
2033
  ...storage,
1938
2034
  getItem: (key, defaultState = null) => {
1939
2035
  const value = storage.getItem(`${prefix}.${key}`);
1940
2036
  try {
1941
- return value ? JSON.parse(value) : defaultState;
2037
+ return value ? deserialize2(value) : defaultState;
1942
2038
  } catch (error) {
1943
2039
  console.warn(error);
1944
2040
  return defaultState;
@@ -1949,7 +2045,7 @@ function createStorage({
1949
2045
  storage.removeItem(`${prefix}.${key}`);
1950
2046
  } else {
1951
2047
  try {
1952
- storage.setItem(`${prefix}.${key}`, JSON.stringify(value));
2048
+ storage.setItem(`${prefix}.${key}`, serialize2(value));
1953
2049
  } catch (err) {
1954
2050
  console.error(err);
1955
2051
  }
@@ -2009,6 +2105,7 @@ var Client = class {
2009
2105
  webSocketProvider: this.getWebSocketProvider({ chainId: chainId2 })
2010
2106
  }),
2011
2107
  {
2108
+ deserialize: (state) => state,
2012
2109
  name: storeKey,
2013
2110
  getStorage: () => storage,
2014
2111
  partialize: (state) => ({
@@ -2020,7 +2117,8 @@ var Client = class {
2020
2117
  },
2021
2118
  chains: state?.chains
2022
2119
  }),
2023
- version: 1
2120
+ serialize: (state) => state,
2121
+ version: 2
2024
2122
  }
2025
2123
  )
2026
2124
  )
@@ -2202,7 +2300,7 @@ function createClient(config) {
2202
2300
  function getClient() {
2203
2301
  if (!client) {
2204
2302
  throw new Error(
2205
- "No wagmi client found. Ensure you have set up a client: https://wagmi.sh/docs/client"
2303
+ "No wagmi client found. Ensure you have set up a client: https://wagmi.sh/react/client"
2206
2304
  );
2207
2305
  }
2208
2306
  return client;
@@ -2215,7 +2313,7 @@ async function connect({
2215
2313
  }) {
2216
2314
  const client2 = getClient();
2217
2315
  const activeConnector = client2.connector;
2218
- if (connector.id === activeConnector?.id)
2316
+ if (activeConnector && connector.id === activeConnector.id)
2219
2317
  throw new ConnectorAlreadyConnectedError();
2220
2318
  try {
2221
2319
  client2.setState((x) => ({ ...x, status: "connecting" }));
@@ -3440,9 +3538,11 @@ export {
3440
3538
  configureChains,
3441
3539
  debounce,
3442
3540
  deepEqual,
3541
+ deserialize,
3443
3542
  minimizeContractInterface,
3444
3543
  normalizeChainId,
3445
3544
  parseContractResult,
3545
+ serialize,
3446
3546
  erc20ABI,
3447
3547
  erc721ABI,
3448
3548
  erc4626ABI,
@@ -1,12 +1,12 @@
1
1
  import { CoinbaseWalletProvider } from '@coinbase/wallet-sdk';
2
2
  import { CoinbaseWalletSDKOptions } from '@coinbase/wallet-sdk/dist/CoinbaseWalletSDK';
3
3
  import { providers } from 'ethers';
4
- import { C as Chain } from '../index-bacc1c49.js';
5
- import { C as Connector } from '../base-5bd9b5ed.js';
4
+ import { C as Chain } from '../index-58cffc47.js';
5
+ import { C as Connector } from '../base-a32d0b91.js';
6
6
  import 'abitype';
7
7
  import 'eventemitter3';
8
8
 
9
- declare type Options = CoinbaseWalletSDKOptions & {
9
+ type Options = CoinbaseWalletSDKOptions & {
10
10
  /**
11
11
  * Fallback Ethereum JSON RPC URL
12
12
  * @default ""
@@ -5,7 +5,7 @@ import {
5
5
  SwitchChainError,
6
6
  UserRejectedRequestError,
7
7
  normalizeChainId
8
- } from "../chunk-MS4CUBFJ.js";
8
+ } from "../chunk-HEIMP7HQ.js";
9
9
  import "../chunk-4DNFSL2K.js";
10
10
  import {
11
11
  __privateAdd,
@@ -1,11 +1,11 @@
1
- import { C as Chain, E as Ethereum } from '../index-bacc1c49.js';
2
- import { a as InjectedConnectorOptions, I as InjectedConnector } from '../injected-6980e5c3.js';
1
+ import { C as Chain, E as Ethereum } from '../index-58cffc47.js';
2
+ import { a as InjectedConnectorOptions, I as InjectedConnector } from '../injected-82510902.js';
3
3
  import 'abitype';
4
4
  import 'ethers';
5
- import '../base-5bd9b5ed.js';
5
+ import '../base-a32d0b91.js';
6
6
  import 'eventemitter3';
7
7
 
8
- declare type MetaMaskConnectorOptions = Pick<InjectedConnectorOptions, 'shimChainChangedDisconnect' | 'shimDisconnect'> & {
8
+ type MetaMaskConnectorOptions = Pick<InjectedConnectorOptions, 'shimChainChangedDisconnect' | 'shimDisconnect'> & {
9
9
  /**
10
10
  * While "disconnected" with `shimDisconnect`, allows user to select a different MetaMask account (than the currently connected account) when trying to connect.
11
11
  */
@@ -14,7 +14,6 @@ declare type MetaMaskConnectorOptions = Pick<InjectedConnectorOptions, 'shimChai
14
14
  declare class MetaMaskConnector extends InjectedConnector {
15
15
  #private;
16
16
  readonly id = "metaMask";
17
- readonly ready: boolean;
18
17
  constructor({ chains, options: options_, }?: {
19
18
  chains?: Chain[];
20
19
  options?: MetaMaskConnectorOptions;
@@ -29,7 +28,6 @@ declare class MetaMaskConnector extends InjectedConnector {
29
28
  };
30
29
  provider: Ethereum;
31
30
  }>;
32
- getProvider(): Promise<Ethereum | undefined>;
33
31
  }
34
32
 
35
33
  export { MetaMaskConnector, MetaMaskConnectorOptions };
@@ -4,18 +4,17 @@ import {
4
4
  ResourceUnavailableError,
5
5
  UserRejectedRequestError,
6
6
  getClient
7
- } from "../chunk-MS4CUBFJ.js";
7
+ } from "../chunk-HEIMP7HQ.js";
8
8
  import "../chunk-4DNFSL2K.js";
9
9
  import {
10
10
  __privateAdd,
11
11
  __privateGet,
12
- __privateMethod,
13
12
  __privateSet
14
13
  } from "../chunk-MQXBDTVK.js";
15
14
 
16
15
  // src/connectors/metaMask.ts
17
16
  import { getAddress } from "ethers/lib/utils.js";
18
- var _provider, _UNSTABLE_shimOnConnectSelectAccount, _getReady, getReady_fn, _findProvider, findProvider_fn;
17
+ var _UNSTABLE_shimOnConnectSelectAccount;
19
18
  var MetaMaskConnector = class extends InjectedConnector {
20
19
  constructor({
21
20
  chains,
@@ -25,14 +24,35 @@ var MetaMaskConnector = class extends InjectedConnector {
25
24
  name: "MetaMask",
26
25
  shimDisconnect: true,
27
26
  shimChainChangedDisconnect: true,
27
+ getProvider() {
28
+ function getReady(ethereum) {
29
+ const isMetaMask = !!ethereum?.isMetaMask;
30
+ if (!isMetaMask)
31
+ return;
32
+ if (ethereum.isBraveWallet && !ethereum._events && !ethereum._state)
33
+ return;
34
+ if (ethereum.isAvalanche)
35
+ return;
36
+ if (ethereum.isKuCoinWallet)
37
+ return;
38
+ if (ethereum.isPortal)
39
+ return;
40
+ if (ethereum.isTokenPocket)
41
+ return;
42
+ if (ethereum.isTokenary)
43
+ return;
44
+ return ethereum;
45
+ }
46
+ if (typeof window === "undefined")
47
+ return;
48
+ if (window.ethereum?.providers)
49
+ return window.ethereum.providers.find(getReady);
50
+ return getReady(window.ethereum);
51
+ },
28
52
  ...options_
29
53
  };
30
54
  super({ chains, options });
31
- __privateAdd(this, _getReady);
32
- __privateAdd(this, _findProvider);
33
55
  this.id = "metaMask";
34
- this.ready = typeof window != "undefined" && !!__privateMethod(this, _findProvider, findProvider_fn).call(this, window.ethereum);
35
- __privateAdd(this, _provider, void 0);
36
56
  __privateAdd(this, _UNSTABLE_shimOnConnectSelectAccount, void 0);
37
57
  __privateSet(this, _UNSTABLE_shimOnConnectSelectAccount, options.UNSTABLE_shimOnConnectSelectAccount);
38
58
  }
@@ -52,10 +72,15 @@ var MetaMaskConnector = class extends InjectedConnector {
52
72
  account = await this.getAccount().catch(() => null);
53
73
  const isConnected = !!account;
54
74
  if (isConnected)
55
- await provider.request({
56
- method: "wallet_requestPermissions",
57
- params: [{ eth_accounts: {} }]
58
- }).catch(() => null);
75
+ try {
76
+ await provider.request({
77
+ method: "wallet_requestPermissions",
78
+ params: [{ eth_accounts: {} }]
79
+ });
80
+ } catch (error) {
81
+ if (this.isUserRejectedRequestError(error))
82
+ throw new UserRejectedRequestError(error);
83
+ }
59
84
  }
60
85
  if (!account) {
61
86
  const accounts = await provider.request({
@@ -81,40 +106,8 @@ var MetaMaskConnector = class extends InjectedConnector {
81
106
  throw error;
82
107
  }
83
108
  }
84
- async getProvider() {
85
- if (typeof window !== "undefined") {
86
- __privateSet(this, _provider, __privateMethod(this, _findProvider, findProvider_fn).call(this, window.ethereum));
87
- }
88
- return __privateGet(this, _provider);
89
- }
90
109
  };
91
- _provider = new WeakMap();
92
110
  _UNSTABLE_shimOnConnectSelectAccount = new WeakMap();
93
- _getReady = new WeakSet();
94
- getReady_fn = function(ethereum) {
95
- const isMetaMask = !!ethereum?.isMetaMask;
96
- if (!isMetaMask)
97
- return;
98
- if (ethereum.isBraveWallet && !ethereum._events && !ethereum._state)
99
- return;
100
- if (ethereum.isAvalanche)
101
- return;
102
- if (ethereum.isKuCoinWallet)
103
- return;
104
- if (ethereum.isPortal)
105
- return;
106
- if (ethereum.isTokenPocket)
107
- return;
108
- if (ethereum.isTokenary)
109
- return;
110
- return ethereum;
111
- };
112
- _findProvider = new WeakSet();
113
- findProvider_fn = function(ethereum) {
114
- if (ethereum?.providers)
115
- return ethereum.providers.find(__privateMethod(this, _getReady, getReady_fn));
116
- return __privateMethod(this, _getReady, getReady_fn).call(this, ethereum);
117
- };
118
111
  export {
119
112
  MetaMaskConnector
120
113
  };
@@ -1,11 +1,11 @@
1
1
  import * as ethers from 'ethers';
2
2
  import { providers } from 'ethers';
3
- import { S as Signer, C as Chain } from '../../index-bacc1c49.js';
4
- import { C as Connector, a as ConnectorData } from '../../base-5bd9b5ed.js';
3
+ import { S as Signer, C as Chain } from '../../index-58cffc47.js';
4
+ import { C as Connector, a as ConnectorData } from '../../base-a32d0b91.js';
5
5
  import EventEmitter from 'eventemitter3';
6
6
  import 'abitype';
7
7
 
8
- declare type MockProviderOptions = {
8
+ type MockProviderOptions = {
9
9
  chainId?: number;
10
10
  flags?: {
11
11
  isAuthorized?: boolean;
@@ -15,12 +15,12 @@ declare type MockProviderOptions = {
15
15
  };
16
16
  signer: Signer;
17
17
  };
18
- declare type Events = {
18
+ type Events = {
19
19
  accountsChanged(accounts: string[]): void;
20
20
  chainChanged(chainId: number | string): void;
21
21
  disconnect(): void;
22
22
  };
23
- declare type Event = keyof Events;
23
+ type Event = keyof Events;
24
24
  declare class MockProvider extends providers.BaseProvider {
25
25
  #private;
26
26
  events: EventEmitter<Events, any>;
@@ -2,7 +2,7 @@ import {
2
2
  Connector,
3
3
  UserRejectedRequestError,
4
4
  normalizeChainId
5
- } from "../../chunk-MS4CUBFJ.js";
5
+ } from "../../chunk-HEIMP7HQ.js";
6
6
  import "../../chunk-4DNFSL2K.js";
7
7
  import {
8
8
  __privateAdd,
@@ -1,12 +1,12 @@
1
1
  import WalletConnectProvider from '@walletconnect/ethereum-provider';
2
2
  import { providers } from 'ethers';
3
- import { C as Chain } from '../index-bacc1c49.js';
4
- import { C as Connector } from '../base-5bd9b5ed.js';
3
+ import { C as Chain } from '../index-58cffc47.js';
4
+ import { C as Connector } from '../base-a32d0b91.js';
5
5
  import 'abitype';
6
6
  import 'eventemitter3';
7
7
 
8
- declare type WalletConnectOptions = ConstructorParameters<typeof WalletConnectProvider>[0];
9
- declare type WalletConnectSigner = providers.JsonRpcSigner;
8
+ type WalletConnectOptions = ConstructorParameters<typeof WalletConnectProvider>[0];
9
+ type WalletConnectSigner = providers.JsonRpcSigner;
10
10
  declare class WalletConnectConnector extends Connector<WalletConnectProvider, WalletConnectOptions, WalletConnectSigner> {
11
11
  #private;
12
12
  readonly id = "walletConnect";
@@ -4,7 +4,7 @@ import {
4
4
  UserRejectedRequestError,
5
5
  getClient,
6
6
  normalizeChainId
7
- } from "../chunk-MS4CUBFJ.js";
7
+ } from "../chunk-HEIMP7HQ.js";
8
8
  import "../chunk-4DNFSL2K.js";
9
9
  import {
10
10
  __privateAdd,
@@ -138,10 +138,18 @@ switchChain_fn = async function(chainId) {
138
138
  const provider = await this.getProvider();
139
139
  const id = hexValue(chainId);
140
140
  try {
141
- await provider.request({
142
- method: "wallet_switchEthereumChain",
143
- params: [{ chainId: id }]
144
- });
141
+ await Promise.race([
142
+ provider.request({
143
+ method: "wallet_switchEthereumChain",
144
+ params: [{ chainId: id }]
145
+ }),
146
+ new Promise(
147
+ (res) => this.on("change", ({ chain }) => {
148
+ if (chain?.id === chainId)
149
+ res(chainId);
150
+ })
151
+ )
152
+ ]);
145
153
  return this.chains.find((x) => x.id === chainId) ?? {
146
154
  id: chainId,
147
155
  name: `Chain ${id}`,