@wagmi/connectors 2.2.0-cjs → 2.2.0

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({ chainId } = {}) {
138
138
  const [provider, account] = await Promise.all([
@@ -142,10 +142,10 @@ var WalletConnectConnector = class extends _chunkQYMCVNHTjs.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 _viem.createWalletClient.call(void 0, {
145
+ return createWalletClient({
146
146
  account,
147
147
  chain,
148
- transport: _viem.custom.call(void 0, provider)
148
+ transport: custom(provider)
149
149
  });
150
150
  }
151
151
  async isAuthorized() {
@@ -154,58 +154,58 @@ var WalletConnectConnector = class extends _chunkQYMCVNHTjs.Connector {
154
154
  this.getAccount(),
155
155
  this.getProvider()
156
156
  ]);
157
- const isChainsStale = _chunkQYMCVNHTjs.__privateMethod.call(void 0, this, _isChainsStale, isChainsStale_fn).call(this);
157
+ const isChainsStale = __privateMethod(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 (e) {
163
+ } catch {
164
164
  }
165
165
  return false;
166
166
  }
167
167
  return true;
168
- } catch (e2) {
168
+ } catch {
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 (0, _viem.SwitchChainError)(new Error("chain not found on connector."));
175
+ throw new SwitchChainError(new Error("chain not found on connector."));
176
176
  try {
177
177
  const provider = await this.getProvider();
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);
178
+ const namespaceChains = __privateMethod(this, _getNamespaceChainsIds, getNamespaceChainsIds_fn).call(this);
179
+ const namespaceMethods = __privateMethod(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: _viem.numberToHex.call(void 0, chain.id),
187
- blockExplorerUrls: [_optionalChain([chain, 'access', _12 => _12.blockExplorers, 'optionalAccess', _13 => _13.default, 'optionalAccess', _14 => _14.url])],
186
+ chainId: numberToHex(chain.id),
187
+ blockExplorerUrls: [chain.blockExplorers?.default?.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 = _chunkQYMCVNHTjs.__privateMethod.call(void 0, this, _getRequestedChainsIds, getRequestedChainsIds_fn).call(this);
194
+ const requestedChains = __privateMethod(this, _getRequestedChainsIds, getRequestedChainsIds_fn).call(this);
195
195
  requestedChains.push(chainId);
196
- _chunkQYMCVNHTjs.__privateMethod.call(void 0, this, _setRequestedChainsIds, setRequestedChainsIds_fn).call(this, requestedChains);
196
+ __privateMethod(this, _setRequestedChainsIds, setRequestedChainsIds_fn).call(this, requestedChains);
197
197
  }
198
198
  await provider.request({
199
199
  method: "wallet_switchEthereumChain",
200
- params: [{ chainId: _viem.numberToHex.call(void 0, chainId) }]
200
+ params: [{ chainId: numberToHex(chainId) }]
201
201
  });
202
202
  return chain;
203
203
  } catch (error) {
204
- const message = typeof error === "string" ? error : _optionalChain([error, 'optionalAccess', _15 => _15.message]);
204
+ const message = typeof error === "string" ? error : error?.message;
205
205
  if (/user rejected request/i.test(message)) {
206
- throw new (0, _viem.UserRejectedRequestError)(error);
206
+ throw new UserRejectedRequestError(error);
207
207
  }
208
- throw new (0, _viem.SwitchChainError)(error);
208
+ throw new 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 (!_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));
216
+ if (!__privateGet(this, _initProviderPromise) && typeof window !== "undefined") {
217
+ __privateSet(this, _initProviderPromise, __privateMethod(this, _initProvider, initProvider_fn).call(this));
218
218
  }
219
- return _chunkQYMCVNHTjs.__privateGet.call(void 0, this, _initProviderPromise);
219
+ return __privateGet(this, _initProviderPromise);
220
220
  };
221
221
  _initProvider = new WeakSet();
222
222
  initProvider_fn = async function() {
@@ -224,11 +224,11 @@ initProvider_fn = async function() {
224
224
  default: EthereumProvider,
225
225
  OPTIONAL_EVENTS,
226
226
  OPTIONAL_METHODS
227
- } = await Promise.resolve().then(() => require("@walletconnect/ethereum-provider"));
227
+ } = await import("@walletconnect/ethereum-provider");
228
228
  const [defaultChain, ...optionalChains] = this.chains.map(({ id }) => id);
229
229
  if (defaultChain) {
230
230
  const { projectId, showQrModal = true, qrModalOptions } = this.options;
231
- _chunkQYMCVNHTjs.__privateSet.call(void 0, this, _provider, await EthereumProvider.init({
231
+ __privateSet(this, _provider, await EthereumProvider.init({
232
232
  showQrModal,
233
233
  qrModalOptions,
234
234
  projectId,
@@ -247,65 +247,65 @@ initProvider_fn = async function() {
247
247
  };
248
248
  _isChainsStale = new WeakSet();
249
249
  isChainsStale_fn = function() {
250
- const namespaceMethods = _chunkQYMCVNHTjs.__privateMethod.call(void 0, this, _getNamespaceMethods, getNamespaceMethods_fn).call(this);
250
+ const namespaceMethods = __privateMethod(this, _getNamespaceMethods, getNamespaceMethods_fn).call(this);
251
251
  if (namespaceMethods.includes(ADD_ETH_CHAIN_METHOD))
252
252
  return false;
253
253
  if (!this.options.isNewChainsStale)
254
254
  return false;
255
- const requestedChains = _chunkQYMCVNHTjs.__privateMethod.call(void 0, this, _getRequestedChainsIds, getRequestedChainsIds_fn).call(this);
255
+ const requestedChains = __privateMethod(this, _getRequestedChainsIds, getRequestedChainsIds_fn).call(this);
256
256
  const connectorChains = this.chains.map(({ id }) => id);
257
- const namespaceChains = _chunkQYMCVNHTjs.__privateMethod.call(void 0, this, _getNamespaceChainsIds, getNamespaceChainsIds_fn).call(this);
257
+ const namespaceChains = __privateMethod(this, _getNamespaceChainsIds, getNamespaceChainsIds_fn).call(this);
258
258
  if (namespaceChains.length && !namespaceChains.some((id) => connectorChains.includes(id)))
259
259
  return false;
260
260
  return !connectorChains.every((id) => requestedChains.includes(id));
261
261
  };
262
262
  _setupListeners = new WeakSet();
263
263
  setupListeners_fn = function() {
264
- if (!_chunkQYMCVNHTjs.__privateGet.call(void 0, this, _provider))
264
+ if (!__privateGet(this, _provider))
265
265
  return;
266
- _chunkQYMCVNHTjs.__privateMethod.call(void 0, this, _removeListeners, removeListeners_fn).call(this);
267
- _chunkQYMCVNHTjs.__privateGet.call(void 0, this, _provider).on("accountsChanged", this.onAccountsChanged);
268
- _chunkQYMCVNHTjs.__privateGet.call(void 0, this, _provider).on("chainChanged", this.onChainChanged);
269
- _chunkQYMCVNHTjs.__privateGet.call(void 0, this, _provider).on("disconnect", this.onDisconnect);
270
- _chunkQYMCVNHTjs.__privateGet.call(void 0, this, _provider).on("session_delete", this.onDisconnect);
271
- _chunkQYMCVNHTjs.__privateGet.call(void 0, this, _provider).on("display_uri", this.onDisplayUri);
272
- _chunkQYMCVNHTjs.__privateGet.call(void 0, this, _provider).on("connect", this.onConnect);
266
+ __privateMethod(this, _removeListeners, removeListeners_fn).call(this);
267
+ __privateGet(this, _provider).on("accountsChanged", this.onAccountsChanged);
268
+ __privateGet(this, _provider).on("chainChanged", this.onChainChanged);
269
+ __privateGet(this, _provider).on("disconnect", this.onDisconnect);
270
+ __privateGet(this, _provider).on("session_delete", this.onDisconnect);
271
+ __privateGet(this, _provider).on("display_uri", this.onDisplayUri);
272
+ __privateGet(this, _provider).on("connect", this.onConnect);
273
273
  };
274
274
  _removeListeners = new WeakSet();
275
275
  removeListeners_fn = function() {
276
- if (!_chunkQYMCVNHTjs.__privateGet.call(void 0, this, _provider))
276
+ if (!__privateGet(this, _provider))
277
277
  return;
278
- _chunkQYMCVNHTjs.__privateGet.call(void 0, this, _provider).removeListener("accountsChanged", this.onAccountsChanged);
279
- _chunkQYMCVNHTjs.__privateGet.call(void 0, this, _provider).removeListener("chainChanged", this.onChainChanged);
280
- _chunkQYMCVNHTjs.__privateGet.call(void 0, this, _provider).removeListener("disconnect", this.onDisconnect);
281
- _chunkQYMCVNHTjs.__privateGet.call(void 0, this, _provider).removeListener("session_delete", this.onDisconnect);
282
- _chunkQYMCVNHTjs.__privateGet.call(void 0, this, _provider).removeListener("display_uri", this.onDisplayUri);
283
- _chunkQYMCVNHTjs.__privateGet.call(void 0, this, _provider).removeListener("connect", this.onConnect);
278
+ __privateGet(this, _provider).removeListener("accountsChanged", this.onAccountsChanged);
279
+ __privateGet(this, _provider).removeListener("chainChanged", this.onChainChanged);
280
+ __privateGet(this, _provider).removeListener("disconnect", this.onDisconnect);
281
+ __privateGet(this, _provider).removeListener("session_delete", this.onDisconnect);
282
+ __privateGet(this, _provider).removeListener("display_uri", this.onDisplayUri);
283
+ __privateGet(this, _provider).removeListener("connect", this.onConnect);
284
284
  };
285
285
  _setRequestedChainsIds = new WeakSet();
286
286
  setRequestedChainsIds_fn = function(chains) {
287
- _optionalChain([this, 'access', _16 => _16.storage, 'optionalAccess', _17 => _17.setItem, 'call', _18 => _18(REQUESTED_CHAINS_KEY, chains)]);
287
+ this.storage?.setItem(REQUESTED_CHAINS_KEY, chains);
288
288
  };
289
289
  _getRequestedChainsIds = new WeakSet();
290
290
  getRequestedChainsIds_fn = function() {
291
- return _nullishCoalesce(_optionalChain([this, 'access', _19 => _19.storage, 'optionalAccess', _20 => _20.getItem, 'call', _21 => _21(REQUESTED_CHAINS_KEY)]), () => ( []));
291
+ return this.storage?.getItem(REQUESTED_CHAINS_KEY) ?? [];
292
292
  };
293
293
  _getNamespaceChainsIds = new WeakSet();
294
294
  getNamespaceChainsIds_fn = function() {
295
- if (!_chunkQYMCVNHTjs.__privateGet.call(void 0, this, _provider))
295
+ if (!__privateGet(this, _provider))
296
296
  return [];
297
- 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(
297
+ const chainIds = __privateGet(this, _provider).session?.namespaces[NAMESPACE]?.chains?.map(
298
298
  (chain) => parseInt(chain.split(":")[1] || "")
299
- )]);
300
- return _nullishCoalesce(chainIds, () => ( []));
299
+ );
300
+ return chainIds ?? [];
301
301
  };
302
302
  _getNamespaceMethods = new WeakSet();
303
303
  getNamespaceMethods_fn = function() {
304
- if (!_chunkQYMCVNHTjs.__privateGet.call(void 0, this, _provider))
304
+ if (!__privateGet(this, _provider))
305
305
  return [];
306
- 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]);
307
- return _nullishCoalesce(methods, () => ( []));
306
+ const methods = __privateGet(this, _provider).session?.namespaces[NAMESPACE]?.methods;
307
+ return methods ?? [];
308
+ };
309
+ export {
310
+ WalletConnectConnector
308
311
  };
309
-
310
-
311
- 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({ chainId } = {}) {
122
122
  const [provider, account] = await Promise.all([
@@ -126,17 +126,17 @@ var WalletConnectLegacyConnector = class extends _chunkQYMCVNHTjs.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 _viem.createWalletClient.call(void 0, {
129
+ return createWalletClient({
130
130
  account,
131
131
  chain,
132
- transport: _viem.custom.call(void 0, provider)
132
+ transport: custom(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 (e) {
139
+ } catch {
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 = _viem.numberToHex.call(void 0, chainId);
148
+ const id = numberToHex(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 (_optionalChain([chain, 'optionalAccess', _15 => _15.id]) === chainId)
157
+ if (chain?.id === chainId)
158
158
  res(chainId);
159
159
  })
160
160
  )
161
161
  ]);
162
- return _nullishCoalesce(this.chains.find((x) => x.id === chainId), () => ( {
162
+ return 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 : _optionalChain([error, 'optionalAccess', _16 => _16.message]);
170
+ const message = typeof error === "string" ? error : error?.message;
171
171
  if (/user rejected request/i.test(message))
172
- throw new (0, _viem.UserRejectedRequestError)(error);
173
- throw new (0, _viem.SwitchChainError)(error);
172
+ throw new UserRejectedRequestError(error);
173
+ throw new SwitchChainError(error);
174
174
  }
175
175
  };
176
-
177
-
178
- exports.WalletConnectLegacyConnector = WalletConnectLegacyConnector;
176
+ export {
177
+ WalletConnectLegacyConnector
178
+ };
@@ -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
  }
@@ -1,4 +1,4 @@
1
1
  {
2
- "module": "../dist/metaMask.mjs",
2
+ "type": "module",
3
3
  "main": "../dist/metaMask.js"
4
4
  }
package/mock/package.json CHANGED
@@ -1,4 +1,4 @@
1
1
  {
2
- "module": "../dist/mock/index.mjs",
2
+ "type": "module",
3
3
  "main": "../dist/mock/index.js"
4
4
  }