@wagmi/connectors 2.6.2-cjs → 2.6.3

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,85 +1,85 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
-
3
-
4
-
5
-
6
-
7
-
8
- var _chunkQYMCVNHTjs = require('./chunk-QYMCVNHT.js');
1
+ import {
2
+ Connector,
3
+ __privateAdd,
4
+ __privateGet,
5
+ __privateMethod,
6
+ __privateSet,
7
+ __publicField
8
+ } from "./chunk-QYMCVNHT.js";
9
9
 
10
10
  // src/walletConnect.ts
11
-
12
-
13
-
14
-
15
-
16
-
17
-
18
- var _viem = require('viem');
11
+ import {
12
+ SwitchChainError,
13
+ UserRejectedRequestError,
14
+ createWalletClient,
15
+ custom,
16
+ getAddress,
17
+ numberToHex
18
+ } from "viem";
19
19
  var NAMESPACE = "eip155";
20
20
  var STORE_KEY = "store";
21
21
  var REQUESTED_CHAINS_KEY = "requestedChains";
22
22
  var ADD_ETH_CHAIN_METHOD = "wallet_addEthereumChain";
23
23
  var _provider, _initProviderPromise, _createProvider, createProvider_fn, _initProvider, initProvider_fn, _isChainsStale, isChainsStale_fn, _setupListeners, setupListeners_fn, _removeListeners, removeListeners_fn, _setRequestedChainsIds, setRequestedChainsIds_fn, _getRequestedChainsIds, getRequestedChainsIds_fn, _getNamespaceChainsIds, getNamespaceChainsIds_fn, _getNamespaceMethods, getNamespaceMethods_fn;
24
- var WalletConnectConnector = class extends _chunkQYMCVNHTjs.Connector {
24
+ var WalletConnectConnector = class extends Connector {
25
25
  constructor(config) {
26
26
  super({
27
27
  ...config,
28
28
  options: { isNewChainsStale: true, ...config.options }
29
29
  });
30
- _chunkQYMCVNHTjs.__privateAdd.call(void 0, this, _createProvider);
31
- _chunkQYMCVNHTjs.__privateAdd.call(void 0, this, _initProvider);
32
- _chunkQYMCVNHTjs.__privateAdd.call(void 0, this, _isChainsStale);
33
- _chunkQYMCVNHTjs.__privateAdd.call(void 0, this, _setupListeners);
34
- _chunkQYMCVNHTjs.__privateAdd.call(void 0, this, _removeListeners);
35
- _chunkQYMCVNHTjs.__privateAdd.call(void 0, this, _setRequestedChainsIds);
36
- _chunkQYMCVNHTjs.__privateAdd.call(void 0, this, _getRequestedChainsIds);
37
- _chunkQYMCVNHTjs.__privateAdd.call(void 0, this, _getNamespaceChainsIds);
38
- _chunkQYMCVNHTjs.__privateAdd.call(void 0, this, _getNamespaceMethods);
39
- _chunkQYMCVNHTjs.__publicField.call(void 0, this, "id", "walletConnect");
40
- _chunkQYMCVNHTjs.__publicField.call(void 0, this, "name", "WalletConnect");
41
- _chunkQYMCVNHTjs.__publicField.call(void 0, this, "ready", true);
42
- _chunkQYMCVNHTjs.__privateAdd.call(void 0, this, _provider, void 0);
43
- _chunkQYMCVNHTjs.__privateAdd.call(void 0, this, _initProviderPromise, void 0);
44
- _chunkQYMCVNHTjs.__publicField.call(void 0, this, "onAccountsChanged", (accounts) => {
30
+ __privateAdd(this, _createProvider);
31
+ __privateAdd(this, _initProvider);
32
+ __privateAdd(this, _isChainsStale);
33
+ __privateAdd(this, _setupListeners);
34
+ __privateAdd(this, _removeListeners);
35
+ __privateAdd(this, _setRequestedChainsIds);
36
+ __privateAdd(this, _getRequestedChainsIds);
37
+ __privateAdd(this, _getNamespaceChainsIds);
38
+ __privateAdd(this, _getNamespaceMethods);
39
+ __publicField(this, "id", "walletConnect");
40
+ __publicField(this, "name", "WalletConnect");
41
+ __publicField(this, "ready", true);
42
+ __privateAdd(this, _provider, void 0);
43
+ __privateAdd(this, _initProviderPromise, void 0);
44
+ __publicField(this, "onAccountsChanged", (accounts) => {
45
45
  if (accounts.length === 0)
46
46
  this.emit("disconnect");
47
47
  else
48
- this.emit("change", { account: _viem.getAddress.call(void 0, accounts[0]) });
48
+ this.emit("change", { account: getAddress(accounts[0]) });
49
49
  });
50
- _chunkQYMCVNHTjs.__publicField.call(void 0, this, "onChainChanged", (chainId) => {
50
+ __publicField(this, "onChainChanged", (chainId) => {
51
51
  const id = Number(chainId);
52
52
  const unsupported = this.isChainUnsupported(id);
53
53
  this.emit("change", { chain: { id, unsupported } });
54
54
  });
55
- _chunkQYMCVNHTjs.__publicField.call(void 0, this, "onDisconnect", () => {
56
- _chunkQYMCVNHTjs.__privateMethod.call(void 0, this, _setRequestedChainsIds, setRequestedChainsIds_fn).call(this, []);
55
+ __publicField(this, "onDisconnect", () => {
56
+ __privateMethod(this, _setRequestedChainsIds, setRequestedChainsIds_fn).call(this, []);
57
57
  this.emit("disconnect");
58
58
  });
59
- _chunkQYMCVNHTjs.__publicField.call(void 0, this, "onDisplayUri", (uri) => {
59
+ __publicField(this, "onDisplayUri", (uri) => {
60
60
  this.emit("message", { type: "display_uri", data: uri });
61
61
  });
62
- _chunkQYMCVNHTjs.__publicField.call(void 0, this, "onConnect", () => {
62
+ __publicField(this, "onConnect", () => {
63
63
  this.emit("connect", {});
64
64
  });
65
- _chunkQYMCVNHTjs.__privateMethod.call(void 0, this, _createProvider, createProvider_fn).call(this);
65
+ __privateMethod(this, _createProvider, createProvider_fn).call(this);
66
66
  }
67
67
  async connect({ chainId, pairingTopic } = {}) {
68
68
  try {
69
69
  let targetChainId = chainId;
70
70
  if (!targetChainId) {
71
- const store = _optionalChain([this, 'access', _ => _.storage, 'optionalAccess', _2 => _2.getItem, 'call', _3 => _3(STORE_KEY)]);
72
- const lastUsedChainId = _optionalChain([store, 'optionalAccess', _4 => _4.state, 'optionalAccess', _5 => _5.data, 'optionalAccess', _6 => _6.chain, 'optionalAccess', _7 => _7.id]);
71
+ const store = this.storage?.getItem(STORE_KEY);
72
+ const lastUsedChainId = store?.state?.data?.chain?.id;
73
73
  if (lastUsedChainId && !this.isChainUnsupported(lastUsedChainId))
74
74
  targetChainId = lastUsedChainId;
75
75
  else
76
- targetChainId = _optionalChain([this, 'access', _8 => _8.chains, 'access', _9 => _9[0], 'optionalAccess', _10 => _10.id]);
76
+ targetChainId = this.chains[0]?.id;
77
77
  }
78
78
  if (!targetChainId)
79
79
  throw new Error("No chains found on connector.");
80
80
  const provider = await this.getProvider();
81
- _chunkQYMCVNHTjs.__privateMethod.call(void 0, this, _setupListeners, setupListeners_fn).call(this);
82
- const isChainsStale = _chunkQYMCVNHTjs.__privateMethod.call(void 0, this, _isChainsStale, isChainsStale_fn).call(this);
81
+ __privateMethod(this, _setupListeners, setupListeners_fn).call(this);
82
+ const isChainsStale = __privateMethod(this, _isChainsStale, isChainsStale_fn).call(this);
83
83
  if (provider.session && isChainsStale)
84
84
  await provider.disconnect();
85
85
  if (!provider.session || isChainsStale) {
@@ -90,10 +90,10 @@ var WalletConnectConnector = class extends _chunkQYMCVNHTjs.Connector {
90
90
  chains: [targetChainId],
91
91
  optionalChains
92
92
  });
93
- _chunkQYMCVNHTjs.__privateMethod.call(void 0, this, _setRequestedChainsIds, setRequestedChainsIds_fn).call(this, this.chains.map(({ id: id2 }) => id2));
93
+ __privateMethod(this, _setRequestedChainsIds, setRequestedChainsIds_fn).call(this, this.chains.map(({ id: id2 }) => id2));
94
94
  }
95
95
  const accounts = await provider.enable();
96
- const account = _viem.getAddress.call(void 0, accounts[0]);
96
+ const account = getAddress(accounts[0]);
97
97
  const id = await this.getChainId();
98
98
  const unsupported = this.isChainUnsupported(id);
99
99
  return {
@@ -101,8 +101,8 @@ var WalletConnectConnector = class extends _chunkQYMCVNHTjs.Connector {
101
101
  chain: { id, unsupported }
102
102
  };
103
103
  } catch (error) {
104
- if (/user rejected/i.test(_optionalChain([error, 'optionalAccess', _11 => _11.message]))) {
105
- throw new (0, _viem.UserRejectedRequestError)(error);
104
+ if (/user rejected/i.test(error?.message)) {
105
+ throw new UserRejectedRequestError(error);
106
106
  }
107
107
  throw error;
108
108
  }
@@ -115,24 +115,24 @@ var WalletConnectConnector = class extends _chunkQYMCVNHTjs.Connector {
115
115
  if (!/No matching key/i.test(error.message))
116
116
  throw error;
117
117
  } finally {
118
- _chunkQYMCVNHTjs.__privateMethod.call(void 0, this, _removeListeners, removeListeners_fn).call(this);
119
- _chunkQYMCVNHTjs.__privateMethod.call(void 0, this, _setRequestedChainsIds, setRequestedChainsIds_fn).call(this, []);
118
+ __privateMethod(this, _removeListeners, removeListeners_fn).call(this);
119
+ __privateMethod(this, _setRequestedChainsIds, setRequestedChainsIds_fn).call(this, []);
120
120
  }
121
121
  }
122
122
  async getAccount() {
123
123
  const { accounts } = await this.getProvider();
124
- return _viem.getAddress.call(void 0, accounts[0]);
124
+ return getAddress(accounts[0]);
125
125
  }
126
126
  async getChainId() {
127
127
  const { chainId } = await this.getProvider();
128
128
  return chainId;
129
129
  }
130
130
  async getProvider({ chainId } = {}) {
131
- if (!_chunkQYMCVNHTjs.__privateGet.call(void 0, this, _provider))
132
- await _chunkQYMCVNHTjs.__privateMethod.call(void 0, this, _createProvider, createProvider_fn).call(this);
131
+ if (!__privateGet(this, _provider))
132
+ await __privateMethod(this, _createProvider, createProvider_fn).call(this);
133
133
  if (chainId)
134
134
  await this.switchChain(chainId);
135
- return _chunkQYMCVNHTjs.__privateGet.call(void 0, this, _provider);
135
+ return __privateGet(this, _provider);
136
136
  }
137
137
  async getWalletClient({
138
138
  chainId
@@ -144,10 +144,10 @@ var WalletConnectConnector = class extends _chunkQYMCVNHTjs.Connector {
144
144
  const chain = this.chains.find((x) => x.id === chainId);
145
145
  if (!provider)
146
146
  throw new Error("provider is required.");
147
- return _viem.createWalletClient.call(void 0, {
147
+ return createWalletClient({
148
148
  account,
149
149
  chain,
150
- transport: _viem.custom.call(void 0, provider)
150
+ transport: custom(provider)
151
151
  });
152
152
  }
153
153
  async isAuthorized() {
@@ -156,58 +156,58 @@ var WalletConnectConnector = class extends _chunkQYMCVNHTjs.Connector {
156
156
  this.getAccount(),
157
157
  this.getProvider()
158
158
  ]);
159
- const isChainsStale = _chunkQYMCVNHTjs.__privateMethod.call(void 0, this, _isChainsStale, isChainsStale_fn).call(this);
159
+ const isChainsStale = __privateMethod(this, _isChainsStale, isChainsStale_fn).call(this);
160
160
  if (!account)
161
161
  return false;
162
162
  if (isChainsStale && provider.session) {
163
163
  try {
164
164
  await provider.disconnect();
165
- } catch (e) {
165
+ } catch {
166
166
  }
167
167
  return false;
168
168
  }
169
169
  return true;
170
- } catch (e2) {
170
+ } catch {
171
171
  return false;
172
172
  }
173
173
  }
174
174
  async switchChain(chainId) {
175
175
  const chain = this.chains.find((chain2) => chain2.id === chainId);
176
176
  if (!chain)
177
- throw new (0, _viem.SwitchChainError)(new Error("chain not found on connector."));
177
+ throw new SwitchChainError(new Error("chain not found on connector."));
178
178
  try {
179
179
  const provider = await this.getProvider();
180
- const namespaceChains = _chunkQYMCVNHTjs.__privateMethod.call(void 0, this, _getNamespaceChainsIds, getNamespaceChainsIds_fn).call(this);
181
- const namespaceMethods = _chunkQYMCVNHTjs.__privateMethod.call(void 0, this, _getNamespaceMethods, getNamespaceMethods_fn).call(this);
180
+ const namespaceChains = __privateMethod(this, _getNamespaceChainsIds, getNamespaceChainsIds_fn).call(this);
181
+ const namespaceMethods = __privateMethod(this, _getNamespaceMethods, getNamespaceMethods_fn).call(this);
182
182
  const isChainApproved = namespaceChains.includes(chainId);
183
183
  if (!isChainApproved && namespaceMethods.includes(ADD_ETH_CHAIN_METHOD)) {
184
184
  await provider.request({
185
185
  method: ADD_ETH_CHAIN_METHOD,
186
186
  params: [
187
187
  {
188
- chainId: _viem.numberToHex.call(void 0, chain.id),
189
- blockExplorerUrls: [_optionalChain([chain, 'access', _12 => _12.blockExplorers, 'optionalAccess', _13 => _13.default, 'optionalAccess', _14 => _14.url])],
188
+ chainId: numberToHex(chain.id),
189
+ blockExplorerUrls: [chain.blockExplorers?.default?.url],
190
190
  chainName: chain.name,
191
191
  nativeCurrency: chain.nativeCurrency,
192
192
  rpcUrls: [...chain.rpcUrls.default.http]
193
193
  }
194
194
  ]
195
195
  });
196
- const requestedChains = _chunkQYMCVNHTjs.__privateMethod.call(void 0, this, _getRequestedChainsIds, getRequestedChainsIds_fn).call(this);
196
+ const requestedChains = __privateMethod(this, _getRequestedChainsIds, getRequestedChainsIds_fn).call(this);
197
197
  requestedChains.push(chainId);
198
- _chunkQYMCVNHTjs.__privateMethod.call(void 0, this, _setRequestedChainsIds, setRequestedChainsIds_fn).call(this, requestedChains);
198
+ __privateMethod(this, _setRequestedChainsIds, setRequestedChainsIds_fn).call(this, requestedChains);
199
199
  }
200
200
  await provider.request({
201
201
  method: "wallet_switchEthereumChain",
202
- params: [{ chainId: _viem.numberToHex.call(void 0, chainId) }]
202
+ params: [{ chainId: numberToHex(chainId) }]
203
203
  });
204
204
  return chain;
205
205
  } catch (error) {
206
- const message = typeof error === "string" ? error : _optionalChain([error, 'optionalAccess', _15 => _15.message]);
206
+ const message = typeof error === "string" ? error : error?.message;
207
207
  if (/user rejected request/i.test(message)) {
208
- throw new (0, _viem.UserRejectedRequestError)(error);
208
+ throw new UserRejectedRequestError(error);
209
209
  }
210
- throw new (0, _viem.SwitchChainError)(error);
210
+ throw new SwitchChainError(error);
211
211
  }
212
212
  }
213
213
  };
@@ -215,27 +215,24 @@ _provider = new WeakMap();
215
215
  _initProviderPromise = new WeakMap();
216
216
  _createProvider = new WeakSet();
217
217
  createProvider_fn = async function() {
218
- if (!_chunkQYMCVNHTjs.__privateGet.call(void 0, this, _initProviderPromise) && typeof window !== "undefined") {
219
- _chunkQYMCVNHTjs.__privateSet.call(void 0, this, _initProviderPromise, _chunkQYMCVNHTjs.__privateMethod.call(void 0, this, _initProvider, initProvider_fn).call(this));
218
+ if (!__privateGet(this, _initProviderPromise) && typeof window !== "undefined") {
219
+ __privateSet(this, _initProviderPromise, __privateMethod(this, _initProvider, initProvider_fn).call(this));
220
220
  }
221
- return _chunkQYMCVNHTjs.__privateGet.call(void 0, this, _initProviderPromise);
221
+ return __privateGet(this, _initProviderPromise);
222
222
  };
223
223
  _initProvider = new WeakSet();
224
224
  initProvider_fn = async function() {
225
- const {
226
- default: EthereumProvider,
227
- OPTIONAL_EVENTS,
228
- OPTIONAL_METHODS
229
- } = await Promise.resolve().then(() => require("@walletconnect/ethereum-provider"));
225
+ const { EthereumProvider, OPTIONAL_EVENTS, OPTIONAL_METHODS } = await import("@walletconnect/ethereum-provider");
230
226
  const [defaultChain, ...optionalChains] = this.chains.map(({ id }) => id);
231
227
  if (defaultChain) {
232
228
  const {
233
229
  projectId,
234
230
  showQrModal = true,
235
231
  qrModalOptions,
236
- metadata
232
+ metadata,
233
+ relayUrl
237
234
  } = this.options;
238
- _chunkQYMCVNHTjs.__privateSet.call(void 0, this, _provider, await EthereumProvider.init({
235
+ __privateSet(this, _provider, await EthereumProvider.init({
239
236
  showQrModal,
240
237
  qrModalOptions,
241
238
  projectId,
@@ -249,71 +246,72 @@ initProvider_fn = async function() {
249
246
  chain.rpcUrls.default.http[0]
250
247
  ])
251
248
  ),
252
- metadata
249
+ metadata,
250
+ relayUrl
253
251
  }));
254
252
  }
255
253
  };
256
254
  _isChainsStale = new WeakSet();
257
255
  isChainsStale_fn = function() {
258
- const namespaceMethods = _chunkQYMCVNHTjs.__privateMethod.call(void 0, this, _getNamespaceMethods, getNamespaceMethods_fn).call(this);
256
+ const namespaceMethods = __privateMethod(this, _getNamespaceMethods, getNamespaceMethods_fn).call(this);
259
257
  if (namespaceMethods.includes(ADD_ETH_CHAIN_METHOD))
260
258
  return false;
261
259
  if (!this.options.isNewChainsStale)
262
260
  return false;
263
- const requestedChains = _chunkQYMCVNHTjs.__privateMethod.call(void 0, this, _getRequestedChainsIds, getRequestedChainsIds_fn).call(this);
261
+ const requestedChains = __privateMethod(this, _getRequestedChainsIds, getRequestedChainsIds_fn).call(this);
264
262
  const connectorChains = this.chains.map(({ id }) => id);
265
- const namespaceChains = _chunkQYMCVNHTjs.__privateMethod.call(void 0, this, _getNamespaceChainsIds, getNamespaceChainsIds_fn).call(this);
263
+ const namespaceChains = __privateMethod(this, _getNamespaceChainsIds, getNamespaceChainsIds_fn).call(this);
266
264
  if (namespaceChains.length && !namespaceChains.some((id) => connectorChains.includes(id)))
267
265
  return false;
268
266
  return !connectorChains.every((id) => requestedChains.includes(id));
269
267
  };
270
268
  _setupListeners = new WeakSet();
271
269
  setupListeners_fn = function() {
272
- if (!_chunkQYMCVNHTjs.__privateGet.call(void 0, this, _provider))
270
+ if (!__privateGet(this, _provider))
273
271
  return;
274
- _chunkQYMCVNHTjs.__privateMethod.call(void 0, this, _removeListeners, removeListeners_fn).call(this);
275
- _chunkQYMCVNHTjs.__privateGet.call(void 0, this, _provider).on("accountsChanged", this.onAccountsChanged);
276
- _chunkQYMCVNHTjs.__privateGet.call(void 0, this, _provider).on("chainChanged", this.onChainChanged);
277
- _chunkQYMCVNHTjs.__privateGet.call(void 0, this, _provider).on("disconnect", this.onDisconnect);
278
- _chunkQYMCVNHTjs.__privateGet.call(void 0, this, _provider).on("session_delete", this.onDisconnect);
279
- _chunkQYMCVNHTjs.__privateGet.call(void 0, this, _provider).on("display_uri", this.onDisplayUri);
280
- _chunkQYMCVNHTjs.__privateGet.call(void 0, this, _provider).on("connect", this.onConnect);
272
+ __privateMethod(this, _removeListeners, removeListeners_fn).call(this);
273
+ __privateGet(this, _provider).on("accountsChanged", this.onAccountsChanged);
274
+ __privateGet(this, _provider).on("chainChanged", this.onChainChanged);
275
+ __privateGet(this, _provider).on("disconnect", this.onDisconnect);
276
+ __privateGet(this, _provider).on("session_delete", this.onDisconnect);
277
+ __privateGet(this, _provider).on("display_uri", this.onDisplayUri);
278
+ __privateGet(this, _provider).on("connect", this.onConnect);
281
279
  };
282
280
  _removeListeners = new WeakSet();
283
281
  removeListeners_fn = function() {
284
- if (!_chunkQYMCVNHTjs.__privateGet.call(void 0, this, _provider))
282
+ if (!__privateGet(this, _provider))
285
283
  return;
286
- _chunkQYMCVNHTjs.__privateGet.call(void 0, this, _provider).removeListener("accountsChanged", this.onAccountsChanged);
287
- _chunkQYMCVNHTjs.__privateGet.call(void 0, this, _provider).removeListener("chainChanged", this.onChainChanged);
288
- _chunkQYMCVNHTjs.__privateGet.call(void 0, this, _provider).removeListener("disconnect", this.onDisconnect);
289
- _chunkQYMCVNHTjs.__privateGet.call(void 0, this, _provider).removeListener("session_delete", this.onDisconnect);
290
- _chunkQYMCVNHTjs.__privateGet.call(void 0, this, _provider).removeListener("display_uri", this.onDisplayUri);
291
- _chunkQYMCVNHTjs.__privateGet.call(void 0, this, _provider).removeListener("connect", this.onConnect);
284
+ __privateGet(this, _provider).removeListener("accountsChanged", this.onAccountsChanged);
285
+ __privateGet(this, _provider).removeListener("chainChanged", this.onChainChanged);
286
+ __privateGet(this, _provider).removeListener("disconnect", this.onDisconnect);
287
+ __privateGet(this, _provider).removeListener("session_delete", this.onDisconnect);
288
+ __privateGet(this, _provider).removeListener("display_uri", this.onDisplayUri);
289
+ __privateGet(this, _provider).removeListener("connect", this.onConnect);
292
290
  };
293
291
  _setRequestedChainsIds = new WeakSet();
294
292
  setRequestedChainsIds_fn = function(chains) {
295
- _optionalChain([this, 'access', _16 => _16.storage, 'optionalAccess', _17 => _17.setItem, 'call', _18 => _18(REQUESTED_CHAINS_KEY, chains)]);
293
+ this.storage?.setItem(REQUESTED_CHAINS_KEY, chains);
296
294
  };
297
295
  _getRequestedChainsIds = new WeakSet();
298
296
  getRequestedChainsIds_fn = function() {
299
- return _nullishCoalesce(_optionalChain([this, 'access', _19 => _19.storage, 'optionalAccess', _20 => _20.getItem, 'call', _21 => _21(REQUESTED_CHAINS_KEY)]), () => ( []));
297
+ return this.storage?.getItem(REQUESTED_CHAINS_KEY) ?? [];
300
298
  };
301
299
  _getNamespaceChainsIds = new WeakSet();
302
300
  getNamespaceChainsIds_fn = function() {
303
- if (!_chunkQYMCVNHTjs.__privateGet.call(void 0, this, _provider))
301
+ if (!__privateGet(this, _provider))
304
302
  return [];
305
- const chainIds = _optionalChain([_chunkQYMCVNHTjs.__privateGet.call(void 0, this, _provider), 'access', _22 => _22.session, 'optionalAccess', _23 => _23.namespaces, 'access', _24 => _24[NAMESPACE], 'optionalAccess', _25 => _25.chains, 'optionalAccess', _26 => _26.map, 'call', _27 => _27(
303
+ const chainIds = __privateGet(this, _provider).session?.namespaces[NAMESPACE]?.chains?.map(
306
304
  (chain) => parseInt(chain.split(":")[1] || "")
307
- )]);
308
- return _nullishCoalesce(chainIds, () => ( []));
305
+ );
306
+ return chainIds ?? [];
309
307
  };
310
308
  _getNamespaceMethods = new WeakSet();
311
309
  getNamespaceMethods_fn = function() {
312
- if (!_chunkQYMCVNHTjs.__privateGet.call(void 0, this, _provider))
310
+ if (!__privateGet(this, _provider))
313
311
  return [];
314
- const methods = _optionalChain([_chunkQYMCVNHTjs.__privateGet.call(void 0, this, _provider), 'access', _28 => _28.session, 'optionalAccess', _29 => _29.namespaces, 'access', _30 => _30[NAMESPACE], 'optionalAccess', _31 => _31.methods]);
315
- return _nullishCoalesce(methods, () => ( []));
312
+ const methods = __privateGet(this, _provider).session?.namespaces[NAMESPACE]?.methods;
313
+ return methods ?? [];
314
+ };
315
+ export {
316
+ WalletConnectConnector
316
317
  };
317
-
318
-
319
- exports.WalletConnectConnector = WalletConnectConnector;
@@ -1,46 +1,46 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
-
3
- var _chunkOQILYQDOjs = require('./chunk-OQILYQDO.js');
4
-
5
-
6
-
7
-
8
-
9
-
10
-
11
- var _chunkQYMCVNHTjs = require('./chunk-QYMCVNHT.js');
1
+ import {
2
+ normalizeChainId
3
+ } from "./chunk-OQILYQDO.js";
4
+ import {
5
+ Connector,
6
+ __privateAdd,
7
+ __privateGet,
8
+ __privateMethod,
9
+ __privateSet,
10
+ __publicField
11
+ } from "./chunk-QYMCVNHT.js";
12
12
 
13
13
  // src/walletConnectLegacy.ts
14
-
15
-
16
-
17
-
18
-
19
-
20
-
21
- var _viem = require('viem');
14
+ import {
15
+ SwitchChainError,
16
+ UserRejectedRequestError,
17
+ createWalletClient,
18
+ custom,
19
+ getAddress,
20
+ numberToHex
21
+ } from "viem";
22
22
  var switchChainAllowedRegex = /(imtoken|metamask|rainbow|trust wallet|uniswap wallet|ledger)/i;
23
23
  var _provider, _switchChain, switchChain_fn;
24
- var WalletConnectLegacyConnector = class extends _chunkQYMCVNHTjs.Connector {
24
+ var WalletConnectLegacyConnector = class extends Connector {
25
25
  constructor() {
26
26
  super(...arguments);
27
- _chunkQYMCVNHTjs.__privateAdd.call(void 0, this, _switchChain);
28
- _chunkQYMCVNHTjs.__publicField.call(void 0, this, "id", "walletConnectLegacy");
29
- _chunkQYMCVNHTjs.__publicField.call(void 0, this, "name", "WalletConnectLegacy");
30
- _chunkQYMCVNHTjs.__publicField.call(void 0, this, "ready", true);
31
- _chunkQYMCVNHTjs.__privateAdd.call(void 0, this, _provider, void 0);
32
- _chunkQYMCVNHTjs.__publicField.call(void 0, this, "onAccountsChanged", (accounts) => {
27
+ __privateAdd(this, _switchChain);
28
+ __publicField(this, "id", "walletConnectLegacy");
29
+ __publicField(this, "name", "WalletConnectLegacy");
30
+ __publicField(this, "ready", true);
31
+ __privateAdd(this, _provider, void 0);
32
+ __publicField(this, "onAccountsChanged", (accounts) => {
33
33
  if (accounts.length === 0)
34
34
  this.emit("disconnect");
35
35
  else
36
- this.emit("change", { account: _viem.getAddress.call(void 0, accounts[0]) });
36
+ this.emit("change", { account: getAddress(accounts[0]) });
37
37
  });
38
- _chunkQYMCVNHTjs.__publicField.call(void 0, this, "onChainChanged", (chainId) => {
39
- const id = _chunkOQILYQDOjs.normalizeChainId.call(void 0, chainId);
38
+ __publicField(this, "onChainChanged", (chainId) => {
39
+ const id = normalizeChainId(chainId);
40
40
  const unsupported = this.isChainUnsupported(id);
41
41
  this.emit("change", { chain: { id, unsupported } });
42
42
  });
43
- _chunkQYMCVNHTjs.__publicField.call(void 0, this, "onDisconnect", () => {
43
+ __publicField(this, "onDisconnect", () => {
44
44
  this.emit("disconnect");
45
45
  });
46
46
  }
@@ -48,8 +48,8 @@ var WalletConnectLegacyConnector = class extends _chunkQYMCVNHTjs.Connector {
48
48
  try {
49
49
  let targetChainId = chainId;
50
50
  if (!targetChainId) {
51
- const store = _optionalChain([this, 'access', _ => _.storage, 'optionalAccess', _2 => _2.getItem, 'call', _3 => _3("store")]);
52
- const lastUsedChainId = _optionalChain([store, 'optionalAccess', _4 => _4.state, 'optionalAccess', _5 => _5.data, 'optionalAccess', _6 => _6.chain, 'optionalAccess', _7 => _7.id]);
51
+ const store = this.storage?.getItem("store");
52
+ const lastUsedChainId = store?.state?.data?.chain?.id;
53
53
  if (lastUsedChainId && !this.isChainUnsupported(lastUsedChainId))
54
54
  targetChainId = lastUsedChainId;
55
55
  }
@@ -62,19 +62,19 @@ var WalletConnectLegacyConnector = class extends _chunkQYMCVNHTjs.Connector {
62
62
  provider.on("disconnect", this.onDisconnect);
63
63
  setTimeout(() => this.emit("message", { type: "connecting" }), 0);
64
64
  const accounts = await provider.enable();
65
- const account = _viem.getAddress.call(void 0, accounts[0]);
65
+ const account = getAddress(accounts[0]);
66
66
  const id = await this.getChainId();
67
67
  const unsupported = this.isChainUnsupported(id);
68
- const walletName = _nullishCoalesce(_optionalChain([provider, 'access', _8 => _8.connector, 'optionalAccess', _9 => _9.peerMeta, 'optionalAccess', _10 => _10.name]), () => ( ""));
68
+ const walletName = provider.connector?.peerMeta?.name ?? "";
69
69
  if (switchChainAllowedRegex.test(walletName))
70
- this.switchChain = _chunkQYMCVNHTjs.__privateMethod.call(void 0, this, _switchChain, switchChain_fn);
70
+ this.switchChain = __privateMethod(this, _switchChain, switchChain_fn);
71
71
  return {
72
72
  account,
73
73
  chain: { id, unsupported }
74
74
  };
75
75
  } catch (error) {
76
76
  if (/user closed modal/i.test(error.message))
77
- throw new (0, _viem.UserRejectedRequestError)(error);
77
+ throw new UserRejectedRequestError(error);
78
78
  throw error;
79
79
  }
80
80
  }
@@ -89,34 +89,34 @@ var WalletConnectLegacyConnector = class extends _chunkQYMCVNHTjs.Connector {
89
89
  async getAccount() {
90
90
  const provider = await this.getProvider();
91
91
  const accounts = provider.accounts;
92
- return _viem.getAddress.call(void 0, accounts[0]);
92
+ return getAddress(accounts[0]);
93
93
  }
94
94
  async getChainId() {
95
95
  const provider = await this.getProvider();
96
- const chainId = _chunkOQILYQDOjs.normalizeChainId.call(void 0, provider.chainId);
96
+ const chainId = normalizeChainId(provider.chainId);
97
97
  return chainId;
98
98
  }
99
99
  async getProvider({
100
100
  chainId,
101
101
  create
102
102
  } = {}) {
103
- if (!_chunkQYMCVNHTjs.__privateGet.call(void 0, this, _provider) || chainId || create) {
104
- const rpc = !_optionalChain([this, 'access', _11 => _11.options, 'optionalAccess', _12 => _12.infuraId]) ? this.chains.reduce(
103
+ if (!__privateGet(this, _provider) || chainId || create) {
104
+ const rpc = !this.options?.infuraId ? this.chains.reduce(
105
105
  (rpc2, chain) => ({
106
106
  ...rpc2,
107
107
  [chain.id]: chain.rpcUrls.default.http[0]
108
108
  }),
109
109
  {}
110
110
  ) : {};
111
- const WalletConnectProvider = (await Promise.resolve().then(() => require("@walletconnect/legacy-provider"))).default;
112
- _chunkQYMCVNHTjs.__privateSet.call(void 0, this, _provider, new WalletConnectProvider({
111
+ const WalletConnectProvider = (await import("@walletconnect/legacy-provider")).default;
112
+ __privateSet(this, _provider, new WalletConnectProvider({
113
113
  ...this.options,
114
114
  chainId,
115
- rpc: { ...rpc, ..._optionalChain([this, 'access', _13 => _13.options, 'optionalAccess', _14 => _14.rpc]) }
115
+ rpc: { ...rpc, ...this.options?.rpc }
116
116
  }));
117
- _chunkQYMCVNHTjs.__privateGet.call(void 0, this, _provider).http = await _chunkQYMCVNHTjs.__privateGet.call(void 0, this, _provider).setHttpProvider(chainId);
117
+ __privateGet(this, _provider).http = await __privateGet(this, _provider).setHttpProvider(chainId);
118
118
  }
119
- return _chunkQYMCVNHTjs.__privateGet.call(void 0, this, _provider);
119
+ return __privateGet(this, _provider);
120
120
  }
121
121
  async getWalletClient({
122
122
  chainId
@@ -128,17 +128,17 @@ var WalletConnectLegacyConnector = class extends _chunkQYMCVNHTjs.Connector {
128
128
  const chain = this.chains.find((x) => x.id === chainId);
129
129
  if (!provider)
130
130
  throw new Error("provider is required.");
131
- return _viem.createWalletClient.call(void 0, {
131
+ return createWalletClient({
132
132
  account,
133
133
  chain,
134
- transport: _viem.custom.call(void 0, provider)
134
+ transport: custom(provider)
135
135
  });
136
136
  }
137
137
  async isAuthorized() {
138
138
  try {
139
139
  const account = await this.getAccount();
140
140
  return !!account;
141
- } catch (e) {
141
+ } catch {
142
142
  return false;
143
143
  }
144
144
  }
@@ -147,7 +147,7 @@ _provider = new WeakMap();
147
147
  _switchChain = new WeakSet();
148
148
  switchChain_fn = async function(chainId) {
149
149
  const provider = await this.getProvider();
150
- const id = _viem.numberToHex.call(void 0, chainId);
150
+ const id = numberToHex(chainId);
151
151
  try {
152
152
  await Promise.race([
153
153
  provider.request({
@@ -156,25 +156,25 @@ switchChain_fn = async function(chainId) {
156
156
  }),
157
157
  new Promise(
158
158
  (res) => this.on("change", ({ chain }) => {
159
- if (_optionalChain([chain, 'optionalAccess', _15 => _15.id]) === chainId)
159
+ if (chain?.id === chainId)
160
160
  res(chainId);
161
161
  })
162
162
  )
163
163
  ]);
164
- return _nullishCoalesce(this.chains.find((x) => x.id === chainId), () => ( {
164
+ return this.chains.find((x) => x.id === chainId) ?? {
165
165
  id: chainId,
166
166
  name: `Chain ${id}`,
167
167
  network: `${id}`,
168
168
  nativeCurrency: { name: "Ether", decimals: 18, symbol: "ETH" },
169
169
  rpcUrls: { default: { http: [""] }, public: { http: [""] } }
170
- }));
170
+ };
171
171
  } catch (error) {
172
- const message = typeof error === "string" ? error : _optionalChain([error, 'optionalAccess', _16 => _16.message]);
172
+ const message = typeof error === "string" ? error : error?.message;
173
173
  if (/user rejected request/i.test(message))
174
- throw new (0, _viem.UserRejectedRequestError)(error);
175
- throw new (0, _viem.SwitchChainError)(error);
174
+ throw new UserRejectedRequestError(error);
175
+ throw new SwitchChainError(error);
176
176
  }
177
177
  };
178
-
179
-
180
- exports.WalletConnectLegacyConnector = WalletConnectLegacyConnector;
178
+ export {
179
+ WalletConnectLegacyConnector
180
+ };
@@ -1,4 +1,4 @@
1
1
  {
2
- "module": "../dist/injected.mjs",
2
+ "type": "module",
3
3
  "main": "../dist/injected.js"
4
4
  }
@@ -1,4 +1,4 @@
1
1
  {
2
- "module": "../dist/ledger.mjs",
2
+ "type": "module",
3
3
  "main": "../dist/ledger.js"
4
4
  }