@wagmi/connectors 2.3.0 → 2.4.0-cjs

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