@wagmi/connectors 3.1.2-cjs → 3.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/ledger.js CHANGED
@@ -1,52 +1,52 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); 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
- var _chunkW65LBPLTjs = require('./chunk-W65LBPLT.js');
1
+ import {
2
+ normalizeChainId
3
+ } from "./chunk-OQILYQDO.js";
4
+ import {
5
+ Connector,
6
+ __privateAdd,
7
+ __privateGet,
8
+ __privateMethod,
9
+ __privateSet
10
+ } from "./chunk-W65LBPLT.js";
11
11
 
12
12
  // src/ledger.ts
13
-
14
-
15
-
16
- var _connectkitloader = require('@ledgerhq/connect-kit-loader');
17
-
18
-
19
-
20
-
21
-
22
-
23
-
24
- var _viem = require('viem');
13
+ import {
14
+ SupportedProviders,
15
+ loadConnectKit
16
+ } from "@ledgerhq/connect-kit-loader";
17
+ import {
18
+ SwitchChainError,
19
+ UserRejectedRequestError,
20
+ createWalletClient,
21
+ custom,
22
+ getAddress,
23
+ numberToHex
24
+ } from "viem";
25
25
  var _provider, _initProviderPromise, _isV1, _createProvider, createProvider_fn, _initProvider, initProvider_fn, _setupListeners, setupListeners_fn, _removeListeners, removeListeners_fn;
26
- var LedgerConnector = class extends _chunkW65LBPLTjs.Connector {
26
+ var LedgerConnector = class extends Connector {
27
27
  constructor(config) {
28
28
  super({
29
29
  ...config,
30
30
  options: { ...config.options }
31
31
  });
32
- _chunkW65LBPLTjs.__privateAdd.call(void 0, this, _createProvider);
33
- _chunkW65LBPLTjs.__privateAdd.call(void 0, this, _initProvider);
34
- _chunkW65LBPLTjs.__privateAdd.call(void 0, this, _setupListeners);
35
- _chunkW65LBPLTjs.__privateAdd.call(void 0, this, _removeListeners);
32
+ __privateAdd(this, _createProvider);
33
+ __privateAdd(this, _initProvider);
34
+ __privateAdd(this, _setupListeners);
35
+ __privateAdd(this, _removeListeners);
36
36
  this.id = "ledger";
37
37
  this.name = "Ledger";
38
38
  this.ready = true;
39
- _chunkW65LBPLTjs.__privateAdd.call(void 0, this, _provider, void 0);
40
- _chunkW65LBPLTjs.__privateAdd.call(void 0, this, _initProviderPromise, void 0);
41
- _chunkW65LBPLTjs.__privateAdd.call(void 0, this, _isV1, void 0);
39
+ __privateAdd(this, _provider, void 0);
40
+ __privateAdd(this, _initProviderPromise, void 0);
41
+ __privateAdd(this, _isV1, void 0);
42
42
  this.onAccountsChanged = (accounts) => {
43
43
  if (accounts.length === 0)
44
44
  this.emit("disconnect");
45
45
  else
46
- this.emit("change", { account: _viem.getAddress.call(void 0, accounts[0]) });
46
+ this.emit("change", { account: getAddress(accounts[0]) });
47
47
  };
48
48
  this.onChainChanged = (chainId) => {
49
- const id = _chunkOQILYQDOjs.normalizeChainId.call(void 0, chainId);
49
+ const id = normalizeChainId(chainId);
50
50
  const unsupported = this.isChainUnsupported(id);
51
51
  this.emit("change", { chain: { id, unsupported } });
52
52
  };
@@ -56,7 +56,7 @@ var LedgerConnector = class extends _chunkW65LBPLTjs.Connector {
56
56
  this.onConnect = () => {
57
57
  this.emit("connect", {});
58
58
  };
59
- _chunkW65LBPLTjs.__privateSet.call(void 0, this, _isV1, this.walletConnectVersion === 1);
59
+ __privateSet(this, _isV1, this.walletConnectVersion === 1);
60
60
  }
61
61
  get walletConnectVersion() {
62
62
  if (this.options.walletConnectVersion)
@@ -68,7 +68,7 @@ var LedgerConnector = class extends _chunkW65LBPLTjs.Connector {
68
68
  async connect({ chainId } = {}) {
69
69
  try {
70
70
  const provider = await this.getProvider({ create: true });
71
- _chunkW65LBPLTjs.__privateMethod.call(void 0, this, _setupListeners, setupListeners_fn).call(this);
71
+ __privateMethod(this, _setupListeners, setupListeners_fn).call(this);
72
72
  if (!provider.session) {
73
73
  this.emit("message", { type: "connecting" });
74
74
  await provider.request({
@@ -89,8 +89,8 @@ var LedgerConnector = class extends _chunkW65LBPLTjs.Connector {
89
89
  provider
90
90
  };
91
91
  } catch (error) {
92
- if (/user rejected/i.test(_optionalChain([error, 'optionalAccess', _ => _.message]))) {
93
- throw new (0, _viem.UserRejectedRequestError)(error);
92
+ if (/user rejected/i.test(error?.message)) {
93
+ throw new UserRejectedRequestError(error);
94
94
  }
95
95
  throw error;
96
96
  }
@@ -98,14 +98,14 @@ var LedgerConnector = class extends _chunkW65LBPLTjs.Connector {
98
98
  async disconnect() {
99
99
  const provider = await this.getProvider();
100
100
  try {
101
- if (_optionalChain([provider, 'optionalAccess', _2 => _2.disconnect]))
101
+ if (provider?.disconnect)
102
102
  await provider.disconnect();
103
103
  } catch (error) {
104
104
  if (!/No matching key/i.test(error.message))
105
105
  throw error;
106
106
  } finally {
107
- _chunkW65LBPLTjs.__privateMethod.call(void 0, this, _removeListeners, removeListeners_fn).call(this);
108
- _chunkW65LBPLTjs.__privateGet.call(void 0, this, _isV1) && typeof localStorage !== "undefined" && localStorage.removeItem("walletconnect");
107
+ __privateMethod(this, _removeListeners, removeListeners_fn).call(this);
108
+ __privateGet(this, _isV1) && typeof localStorage !== "undefined" && localStorage.removeItem("walletconnect");
109
109
  }
110
110
  }
111
111
  async getAccount() {
@@ -113,7 +113,7 @@ var LedgerConnector = class extends _chunkW65LBPLTjs.Connector {
113
113
  const accounts = await provider.request({
114
114
  method: "eth_accounts"
115
115
  });
116
- const account = _viem.getAddress.call(void 0, accounts[0]);
116
+ const account = getAddress(accounts[0]);
117
117
  return account;
118
118
  }
119
119
  async getChainId() {
@@ -121,17 +121,17 @@ var LedgerConnector = class extends _chunkW65LBPLTjs.Connector {
121
121
  const chainId = await provider.request({
122
122
  method: "eth_chainId"
123
123
  });
124
- return _chunkOQILYQDOjs.normalizeChainId.call(void 0, chainId);
124
+ return normalizeChainId(chainId);
125
125
  }
126
126
  async getProvider({ chainId, create } = {
127
127
  create: false
128
128
  }) {
129
- if (!_chunkW65LBPLTjs.__privateGet.call(void 0, this, _provider) || _chunkW65LBPLTjs.__privateGet.call(void 0, this, _isV1) && create) {
130
- await _chunkW65LBPLTjs.__privateMethod.call(void 0, this, _createProvider, createProvider_fn).call(this);
129
+ if (!__privateGet(this, _provider) || __privateGet(this, _isV1) && create) {
130
+ await __privateMethod(this, _createProvider, createProvider_fn).call(this);
131
131
  }
132
132
  if (chainId)
133
133
  await this.switchChain(chainId);
134
- return _chunkW65LBPLTjs.__privateGet.call(void 0, this, _provider);
134
+ return __privateGet(this, _provider);
135
135
  }
136
136
  async getWalletClient({
137
137
  chainId
@@ -143,33 +143,33 @@ var LedgerConnector = class extends _chunkW65LBPLTjs.Connector {
143
143
  const chain = this.chains.find((x) => x.id === chainId);
144
144
  if (!provider)
145
145
  throw new Error("provider is required.");
146
- return _viem.createWalletClient.call(void 0, { account, chain, transport: _viem.custom.call(void 0, provider) });
146
+ return createWalletClient({ account, chain, transport: custom(provider) });
147
147
  }
148
148
  async isAuthorized() {
149
149
  try {
150
150
  const account = await this.getAccount();
151
151
  return !!account;
152
- } catch (e) {
152
+ } catch {
153
153
  return false;
154
154
  }
155
155
  }
156
156
  async switchChain(chainId) {
157
157
  const chain = this.chains.find((chain2) => chain2.id === chainId);
158
158
  if (!chain)
159
- throw new (0, _viem.SwitchChainError)(new Error("chain not found on connector."));
159
+ throw new SwitchChainError(new Error("chain not found on connector."));
160
160
  try {
161
161
  const provider = await this.getProvider();
162
162
  await provider.request({
163
163
  method: "wallet_switchEthereumChain",
164
- params: [{ chainId: _viem.numberToHex.call(void 0, chainId) }]
164
+ params: [{ chainId: numberToHex(chainId) }]
165
165
  });
166
166
  return chain;
167
167
  } catch (error) {
168
- const message = typeof error === "string" ? error : _optionalChain([error, 'optionalAccess', _3 => _3.message]);
168
+ const message = typeof error === "string" ? error : error?.message;
169
169
  if (/user rejected request/i.test(message)) {
170
- throw new (0, _viem.UserRejectedRequestError)(error);
170
+ throw new UserRejectedRequestError(error);
171
171
  }
172
- throw new (0, _viem.SwitchChainError)(error);
172
+ throw new SwitchChainError(error);
173
173
  }
174
174
  }
175
175
  };
@@ -178,22 +178,22 @@ _initProviderPromise = new WeakMap();
178
178
  _isV1 = new WeakMap();
179
179
  _createProvider = new WeakSet();
180
180
  createProvider_fn = async function() {
181
- if (!_chunkW65LBPLTjs.__privateGet.call(void 0, this, _initProviderPromise) && typeof window !== "undefined") {
182
- _chunkW65LBPLTjs.__privateSet.call(void 0, this, _initProviderPromise, _chunkW65LBPLTjs.__privateMethod.call(void 0, this, _initProvider, initProvider_fn).call(this));
181
+ if (!__privateGet(this, _initProviderPromise) && typeof window !== "undefined") {
182
+ __privateSet(this, _initProviderPromise, __privateMethod(this, _initProvider, initProvider_fn).call(this));
183
183
  }
184
- return _chunkW65LBPLTjs.__privateGet.call(void 0, this, _initProviderPromise);
184
+ return __privateGet(this, _initProviderPromise);
185
185
  };
186
186
  _initProvider = new WeakSet();
187
187
  initProvider_fn = async function() {
188
- const connectKit = await _connectkitloader.loadConnectKit.call(void 0, );
188
+ const connectKit = await loadConnectKit();
189
189
  if (this.options.enableDebugLogs) {
190
190
  connectKit.enableDebugLogs();
191
191
  }
192
192
  let checkSupportOptions;
193
- if (_chunkW65LBPLTjs.__privateGet.call(void 0, this, _isV1)) {
193
+ if (__privateGet(this, _isV1)) {
194
194
  const { chainId, bridge } = this.options;
195
195
  checkSupportOptions = {
196
- providerType: _connectkitloader.SupportedProviders.Ethereum,
196
+ providerType: SupportedProviders.Ethereum,
197
197
  walletConnectVersion: 1,
198
198
  chainId,
199
199
  bridge,
@@ -215,7 +215,7 @@ initProvider_fn = async function() {
215
215
  } = this.options;
216
216
  const optionalChains = this.chains.map(({ id }) => id);
217
217
  checkSupportOptions = {
218
- providerType: _connectkitloader.SupportedProviders.Ethereum,
218
+ providerType: SupportedProviders.Ethereum,
219
219
  walletConnectVersion: 2,
220
220
  projectId,
221
221
  chains: requiredChains,
@@ -233,29 +233,29 @@ initProvider_fn = async function() {
233
233
  };
234
234
  }
235
235
  connectKit.checkSupport(checkSupportOptions);
236
- _chunkW65LBPLTjs.__privateSet.call(void 0, this, _provider, await connectKit.getProvider());
236
+ __privateSet(this, _provider, await connectKit.getProvider());
237
237
  };
238
238
  _setupListeners = new WeakSet();
239
239
  setupListeners_fn = function() {
240
- if (!_chunkW65LBPLTjs.__privateGet.call(void 0, this, _provider))
240
+ if (!__privateGet(this, _provider))
241
241
  return;
242
- _chunkW65LBPLTjs.__privateMethod.call(void 0, this, _removeListeners, removeListeners_fn).call(this);
243
- _chunkW65LBPLTjs.__privateGet.call(void 0, this, _provider).on("accountsChanged", this.onAccountsChanged);
244
- _chunkW65LBPLTjs.__privateGet.call(void 0, this, _provider).on("chainChanged", this.onChainChanged);
245
- _chunkW65LBPLTjs.__privateGet.call(void 0, this, _provider).on("disconnect", this.onDisconnect);
246
- _chunkW65LBPLTjs.__privateGet.call(void 0, this, _provider).on("session_delete", this.onDisconnect);
247
- _chunkW65LBPLTjs.__privateGet.call(void 0, this, _provider).on("connect", this.onConnect);
242
+ __privateMethod(this, _removeListeners, removeListeners_fn).call(this);
243
+ __privateGet(this, _provider).on("accountsChanged", this.onAccountsChanged);
244
+ __privateGet(this, _provider).on("chainChanged", this.onChainChanged);
245
+ __privateGet(this, _provider).on("disconnect", this.onDisconnect);
246
+ __privateGet(this, _provider).on("session_delete", this.onDisconnect);
247
+ __privateGet(this, _provider).on("connect", this.onConnect);
248
248
  };
249
249
  _removeListeners = new WeakSet();
250
250
  removeListeners_fn = function() {
251
- if (!_chunkW65LBPLTjs.__privateGet.call(void 0, this, _provider))
251
+ if (!__privateGet(this, _provider))
252
252
  return;
253
- _chunkW65LBPLTjs.__privateGet.call(void 0, this, _provider).removeListener("accountsChanged", this.onAccountsChanged);
254
- _chunkW65LBPLTjs.__privateGet.call(void 0, this, _provider).removeListener("chainChanged", this.onChainChanged);
255
- _chunkW65LBPLTjs.__privateGet.call(void 0, this, _provider).removeListener("disconnect", this.onDisconnect);
256
- _chunkW65LBPLTjs.__privateGet.call(void 0, this, _provider).removeListener("session_delete", this.onDisconnect);
257
- _chunkW65LBPLTjs.__privateGet.call(void 0, this, _provider).removeListener("connect", this.onConnect);
253
+ __privateGet(this, _provider).removeListener("accountsChanged", this.onAccountsChanged);
254
+ __privateGet(this, _provider).removeListener("chainChanged", this.onChainChanged);
255
+ __privateGet(this, _provider).removeListener("disconnect", this.onDisconnect);
256
+ __privateGet(this, _provider).removeListener("session_delete", this.onDisconnect);
257
+ __privateGet(this, _provider).removeListener("connect", this.onConnect);
258
+ };
259
+ export {
260
+ LedgerConnector
258
261
  };
259
-
260
-
261
- exports.LedgerConnector = LedgerConnector;
package/dist/metaMask.js CHANGED
@@ -1,24 +1,24 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); 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 _chunk2UFLHRLTjs = require('./chunk-2UFLHRLT.js');
4
-
5
-
6
- var _chunkUGBGYVBHjs = require('./chunk-UGBGYVBH.js');
7
- require('./chunk-OQILYQDO.js');
8
-
9
-
10
-
11
-
12
- var _chunkW65LBPLTjs = require('./chunk-W65LBPLT.js');
1
+ import {
2
+ InjectedConnector
3
+ } from "./chunk-2UFLHRLT.js";
4
+ import {
5
+ ConnectorNotFoundError
6
+ } from "./chunk-UGBGYVBH.js";
7
+ import "./chunk-OQILYQDO.js";
8
+ import {
9
+ __privateAdd,
10
+ __privateGet,
11
+ __privateSet
12
+ } from "./chunk-W65LBPLT.js";
13
13
 
14
14
  // src/metaMask.ts
15
-
16
-
17
-
18
-
19
- var _viem = require('viem');
15
+ import {
16
+ ResourceUnavailableRpcError,
17
+ UserRejectedRequestError,
18
+ getAddress
19
+ } from "viem";
20
20
  var _UNSTABLE_shimOnConnectSelectAccount;
21
- var MetaMaskConnector = class extends _chunk2UFLHRLTjs.InjectedConnector {
21
+ var MetaMaskConnector = class extends InjectedConnector {
22
22
  constructor({
23
23
  chains,
24
24
  options: options_
@@ -28,7 +28,7 @@ var MetaMaskConnector = class extends _chunk2UFLHRLTjs.InjectedConnector {
28
28
  shimDisconnect: true,
29
29
  getProvider() {
30
30
  function getReady(ethereum2) {
31
- const isMetaMask = !!_optionalChain([ethereum2, 'optionalAccess', _ => _.isMetaMask]);
31
+ const isMetaMask = !!ethereum2?.isMetaMask;
32
32
  if (!isMetaMask)
33
33
  return;
34
34
  if (ethereum2.isBraveWallet && !ethereum2._events && !ethereum2._state)
@@ -72,7 +72,7 @@ var MetaMaskConnector = class extends _chunk2UFLHRLTjs.InjectedConnector {
72
72
  if (typeof window === "undefined")
73
73
  return;
74
74
  const ethereum = window.ethereum;
75
- if (_optionalChain([ethereum, 'optionalAccess', _2 => _2.providers]))
75
+ if (ethereum?.providers)
76
76
  return ethereum.providers.find(getReady);
77
77
  return getReady(ethereum);
78
78
  },
@@ -81,14 +81,14 @@ var MetaMaskConnector = class extends _chunk2UFLHRLTjs.InjectedConnector {
81
81
  super({ chains, options });
82
82
  this.id = "metaMask";
83
83
  this.shimDisconnectKey = `${this.id}.shimDisconnect`;
84
- _chunkW65LBPLTjs.__privateAdd.call(void 0, this, _UNSTABLE_shimOnConnectSelectAccount, void 0);
85
- _chunkW65LBPLTjs.__privateSet.call(void 0, this, _UNSTABLE_shimOnConnectSelectAccount, options.UNSTABLE_shimOnConnectSelectAccount);
84
+ __privateAdd(this, _UNSTABLE_shimOnConnectSelectAccount, void 0);
85
+ __privateSet(this, _UNSTABLE_shimOnConnectSelectAccount, options.UNSTABLE_shimOnConnectSelectAccount);
86
86
  }
87
87
  async connect({ chainId } = {}) {
88
88
  try {
89
89
  const provider = await this.getProvider();
90
90
  if (!provider)
91
- throw new (0, _chunkUGBGYVBHjs.ConnectorNotFoundError)();
91
+ throw new ConnectorNotFoundError();
92
92
  if (provider.on) {
93
93
  provider.on("accountsChanged", this.onAccountsChanged);
94
94
  provider.on("chainChanged", this.onChainChanged);
@@ -96,7 +96,7 @@ var MetaMaskConnector = class extends _chunk2UFLHRLTjs.InjectedConnector {
96
96
  }
97
97
  this.emit("message", { type: "connecting" });
98
98
  let account = null;
99
- if (_chunkW65LBPLTjs.__privateGet.call(void 0, this, _UNSTABLE_shimOnConnectSelectAccount) && _optionalChain([this, 'access', _3 => _3.options, 'optionalAccess', _4 => _4.shimDisconnect]) && !_optionalChain([this, 'access', _5 => _5.storage, 'optionalAccess', _6 => _6.getItem, 'call', _7 => _7(this.shimDisconnectKey)])) {
99
+ if (__privateGet(this, _UNSTABLE_shimOnConnectSelectAccount) && this.options?.shimDisconnect && !this.storage?.getItem(this.shimDisconnectKey)) {
100
100
  account = await this.getAccount().catch(() => null);
101
101
  const isConnected = !!account;
102
102
  if (isConnected)
@@ -108,8 +108,8 @@ var MetaMaskConnector = class extends _chunk2UFLHRLTjs.InjectedConnector {
108
108
  account = await this.getAccount();
109
109
  } catch (error) {
110
110
  if (this.isUserRejectedRequestError(error))
111
- throw new (0, _viem.UserRejectedRequestError)(error);
112
- if (error.code === new (0, _viem.ResourceUnavailableRpcError)(error).code)
111
+ throw new UserRejectedRequestError(error);
112
+ if (error.code === new ResourceUnavailableRpcError(error).code)
113
113
  throw error;
114
114
  }
115
115
  }
@@ -117,7 +117,7 @@ var MetaMaskConnector = class extends _chunk2UFLHRLTjs.InjectedConnector {
117
117
  const accounts = await provider.request({
118
118
  method: "eth_requestAccounts"
119
119
  });
120
- account = _viem.getAddress.call(void 0, accounts[0]);
120
+ account = getAddress(accounts[0]);
121
121
  }
122
122
  let id = await this.getChainId();
123
123
  let unsupported = this.isChainUnsupported(id);
@@ -126,19 +126,19 @@ var MetaMaskConnector = class extends _chunk2UFLHRLTjs.InjectedConnector {
126
126
  id = chain.id;
127
127
  unsupported = this.isChainUnsupported(id);
128
128
  }
129
- if (_optionalChain([this, 'access', _8 => _8.options, 'optionalAccess', _9 => _9.shimDisconnect]))
130
- _optionalChain([this, 'access', _10 => _10.storage, 'optionalAccess', _11 => _11.setItem, 'call', _12 => _12(this.shimDisconnectKey, true)]);
129
+ if (this.options?.shimDisconnect)
130
+ this.storage?.setItem(this.shimDisconnectKey, true);
131
131
  return { account, chain: { id, unsupported }, provider };
132
132
  } catch (error) {
133
133
  if (this.isUserRejectedRequestError(error))
134
- throw new (0, _viem.UserRejectedRequestError)(error);
134
+ throw new UserRejectedRequestError(error);
135
135
  if (error.code === -32002)
136
- throw new (0, _viem.ResourceUnavailableRpcError)(error);
136
+ throw new ResourceUnavailableRpcError(error);
137
137
  throw error;
138
138
  }
139
139
  }
140
140
  };
141
141
  _UNSTABLE_shimOnConnectSelectAccount = new WeakMap();
142
-
143
-
144
- exports.MetaMaskConnector = MetaMaskConnector;
142
+ export {
143
+ MetaMaskConnector
144
+ };
@@ -1,71 +1,71 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 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
- var _chunkW65LBPLTjs = require('../chunk-W65LBPLT.js');
1
+ import {
2
+ normalizeChainId
3
+ } from "../chunk-OQILYQDO.js";
4
+ import {
5
+ Connector,
6
+ __privateAdd,
7
+ __privateGet,
8
+ __privateMethod,
9
+ __privateSet
10
+ } from "../chunk-W65LBPLT.js";
11
11
 
12
12
  // src/mock/connector.ts
13
- var _viem = require('viem');
13
+ import { getAddress as getAddress2 } from "viem";
14
14
 
15
15
  // src/mock/provider.ts
16
- var _eventemitter3 = require('eventemitter3'); var _eventemitter32 = _interopRequireDefault(_eventemitter3);
17
-
16
+ import { default as EventEmitter } from "eventemitter3";
17
+ import { UserRejectedRequestError, getAddress } from "viem";
18
18
  var _options, _walletClient;
19
19
  var MockProvider = class {
20
20
  constructor(options) {
21
- this.events = new (0, _eventemitter32.default)();
22
- _chunkW65LBPLTjs.__privateAdd.call(void 0, this, _options, void 0);
23
- _chunkW65LBPLTjs.__privateAdd.call(void 0, this, _walletClient, void 0);
21
+ this.events = new EventEmitter();
22
+ __privateAdd(this, _options, void 0);
23
+ __privateAdd(this, _walletClient, void 0);
24
24
  this.chainId = options.chainId;
25
- _chunkW65LBPLTjs.__privateSet.call(void 0, this, _options, options);
25
+ __privateSet(this, _options, options);
26
26
  }
27
27
  async enable() {
28
- if (_optionalChain([_chunkW65LBPLTjs.__privateGet.call(void 0, this, _options), 'access', _ => _.flags, 'optionalAccess', _2 => _2.failConnect]))
29
- throw new (0, _viem.UserRejectedRequestError)(new Error("Failed to connect."));
30
- if (!_chunkW65LBPLTjs.__privateGet.call(void 0, this, _walletClient))
31
- _chunkW65LBPLTjs.__privateSet.call(void 0, this, _walletClient, _chunkW65LBPLTjs.__privateGet.call(void 0, this, _options).walletClient);
32
- const address = _chunkW65LBPLTjs.__privateGet.call(void 0, this, _walletClient).account.address;
28
+ if (__privateGet(this, _options).flags?.failConnect)
29
+ throw new UserRejectedRequestError(new Error("Failed to connect."));
30
+ if (!__privateGet(this, _walletClient))
31
+ __privateSet(this, _walletClient, __privateGet(this, _options).walletClient);
32
+ const address = __privateGet(this, _walletClient).account.address;
33
33
  this.events.emit("accountsChanged", [address]);
34
34
  return [address];
35
35
  }
36
36
  async disconnect() {
37
37
  this.events.emit("disconnect");
38
- _chunkW65LBPLTjs.__privateSet.call(void 0, this, _walletClient, void 0);
38
+ __privateSet(this, _walletClient, void 0);
39
39
  }
40
40
  async getAccounts() {
41
- const address = _optionalChain([_chunkW65LBPLTjs.__privateGet.call(void 0, this, _walletClient), 'optionalAccess', _3 => _3.account, 'access', _4 => _4.address]);
41
+ const address = __privateGet(this, _walletClient)?.account.address;
42
42
  if (!address)
43
43
  return [];
44
- return [_viem.getAddress.call(void 0, address)];
44
+ return [getAddress(address)];
45
45
  }
46
46
  getWalletClient() {
47
- const walletClient = _chunkW65LBPLTjs.__privateGet.call(void 0, this, _walletClient);
47
+ const walletClient = __privateGet(this, _walletClient);
48
48
  if (!walletClient)
49
49
  throw new Error("walletClient not found");
50
50
  return walletClient;
51
51
  }
52
52
  async switchChain(chainId) {
53
- if (_optionalChain([_chunkW65LBPLTjs.__privateGet.call(void 0, this, _options), 'access', _5 => _5.flags, 'optionalAccess', _6 => _6.failSwitchChain]))
54
- throw new (0, _viem.UserRejectedRequestError)(new Error("Failed to switch chain."));
55
- _chunkW65LBPLTjs.__privateGet.call(void 0, this, _options).chainId = chainId;
53
+ if (__privateGet(this, _options).flags?.failSwitchChain)
54
+ throw new UserRejectedRequestError(new Error("Failed to switch chain."));
55
+ __privateGet(this, _options).chainId = chainId;
56
56
  this.chainId = chainId;
57
57
  this.events.emit("chainChanged", chainId);
58
58
  }
59
59
  async switchWalletClient(walletClient) {
60
60
  const address = walletClient.account.address;
61
- _chunkW65LBPLTjs.__privateSet.call(void 0, this, _walletClient, walletClient);
61
+ __privateSet(this, _walletClient, walletClient);
62
62
  this.events.emit("accountsChanged", [address]);
63
63
  }
64
64
  async watchAsset(_asset) {
65
65
  return true;
66
66
  }
67
67
  async request({ method, params }) {
68
- return _optionalChain([_chunkW65LBPLTjs.__privateGet.call(void 0, this, _walletClient), 'optionalAccess', _7 => _7.transport, 'access', _8 => _8.request, 'call', _9 => _9({ method, params })]);
68
+ return __privateGet(this, _walletClient)?.transport.request({ method, params });
69
69
  }
70
70
  on(event, listener) {
71
71
  this.events.on(event, listener);
@@ -84,7 +84,7 @@ _walletClient = new WeakMap();
84
84
 
85
85
  // src/mock/connector.ts
86
86
  var _provider, _switchChain, switchChain_fn;
87
- var MockConnector = class extends _chunkW65LBPLTjs.Connector {
87
+ var MockConnector = class extends Connector {
88
88
  constructor({
89
89
  chains,
90
90
  options
@@ -93,22 +93,22 @@ var MockConnector = class extends _chunkW65LBPLTjs.Connector {
93
93
  chains,
94
94
  options: {
95
95
  ...options,
96
- chainId: _nullishCoalesce(options.chainId, () => ( _optionalChain([chains, 'optionalAccess', _10 => _10[0], 'optionalAccess', _11 => _11.id])))
96
+ chainId: options.chainId ?? chains?.[0]?.id
97
97
  }
98
98
  });
99
- _chunkW65LBPLTjs.__privateAdd.call(void 0, this, _switchChain);
99
+ __privateAdd(this, _switchChain);
100
100
  this.id = "mock";
101
101
  this.name = "Mock";
102
102
  this.ready = true;
103
- _chunkW65LBPLTjs.__privateAdd.call(void 0, this, _provider, void 0);
103
+ __privateAdd(this, _provider, void 0);
104
104
  this.onAccountsChanged = (accounts) => {
105
105
  if (accounts.length === 0)
106
106
  this.emit("disconnect");
107
107
  else
108
- this.emit("change", { account: _viem.getAddress.call(void 0, accounts[0]) });
108
+ this.emit("change", { account: getAddress2(accounts[0]) });
109
109
  };
110
110
  this.onChainChanged = (chainId) => {
111
- const id = _chunkOQILYQDOjs.normalizeChainId.call(void 0, chainId);
111
+ const id = normalizeChainId(chainId);
112
112
  const unsupported = this.isChainUnsupported(id);
113
113
  this.emit("change", { chain: { id, unsupported } });
114
114
  };
@@ -123,12 +123,12 @@ var MockConnector = class extends _chunkW65LBPLTjs.Connector {
123
123
  provider.on("disconnect", this.onDisconnect);
124
124
  this.emit("message", { type: "connecting" });
125
125
  const accounts = await provider.enable();
126
- const account = _viem.getAddress.call(void 0, accounts[0]);
127
- const id = _chunkOQILYQDOjs.normalizeChainId.call(void 0, provider.chainId);
126
+ const account = getAddress2(accounts[0]);
127
+ const id = normalizeChainId(provider.chainId);
128
128
  const unsupported = this.isChainUnsupported(id);
129
129
  const data = { account, chain: { id, unsupported }, provider };
130
- if (!_optionalChain([this, 'access', _12 => _12.options, 'access', _13 => _13.flags, 'optionalAccess', _14 => _14.noSwitchChain]))
131
- this.switchChain = _chunkW65LBPLTjs.__privateMethod.call(void 0, this, _switchChain, switchChain_fn);
130
+ if (!this.options.flags?.noSwitchChain)
131
+ this.switchChain = __privateMethod(this, _switchChain, switchChain_fn);
132
132
  return new Promise(
133
133
  (res) => setTimeout(() => res(data), 100)
134
134
  );
@@ -146,19 +146,19 @@ var MockConnector = class extends _chunkW65LBPLTjs.Connector {
146
146
  const account = accounts[0];
147
147
  if (!account)
148
148
  throw new Error("Failed to get account");
149
- return _viem.getAddress.call(void 0, account);
149
+ return getAddress2(account);
150
150
  }
151
151
  async getChainId() {
152
152
  const provider = await this.getProvider();
153
- return _chunkOQILYQDOjs.normalizeChainId.call(void 0, provider.chainId);
153
+ return normalizeChainId(provider.chainId);
154
154
  }
155
155
  async getProvider({ chainId } = {}) {
156
- if (!_chunkW65LBPLTjs.__privateGet.call(void 0, this, _provider) || chainId)
157
- _chunkW65LBPLTjs.__privateSet.call(void 0, this, _provider, new MockProvider({
156
+ if (!__privateGet(this, _provider) || chainId)
157
+ __privateSet(this, _provider, new MockProvider({
158
158
  ...this.options,
159
- chainId: _nullishCoalesce(_nullishCoalesce(chainId, () => ( this.options.chainId)), () => ( this.chains[0].id))
159
+ chainId: chainId ?? this.options.chainId ?? this.chains[0].id
160
160
  }));
161
- return _chunkW65LBPLTjs.__privateGet.call(void 0, this, _provider);
161
+ return __privateGet(this, _provider);
162
162
  }
163
163
  async getWalletClient() {
164
164
  const provider = await this.getProvider();
@@ -168,8 +168,8 @@ var MockConnector = class extends _chunkW65LBPLTjs.Connector {
168
168
  try {
169
169
  const provider = await this.getProvider();
170
170
  const account = await provider.getAccounts();
171
- return _nullishCoalesce(_optionalChain([this, 'access', _15 => _15.options, 'access', _16 => _16.flags, 'optionalAccess', _17 => _17.isAuthorized]), () => ( !!account));
172
- } catch (e) {
171
+ return this.options.flags?.isAuthorized ?? !!account;
172
+ } catch {
173
173
  return false;
174
174
  }
175
175
  }
@@ -186,15 +186,15 @@ _switchChain = new WeakSet();
186
186
  switchChain_fn = async function(chainId) {
187
187
  const provider = await this.getProvider();
188
188
  await provider.switchChain(chainId);
189
- return _nullishCoalesce(this.chains.find((x) => x.id === chainId), () => ( {
189
+ return this.chains.find((x) => x.id === chainId) ?? {
190
190
  id: chainId,
191
191
  name: `Chain ${chainId}`,
192
192
  network: `${chainId}`,
193
193
  nativeCurrency: { name: "Ether", decimals: 18, symbol: "ETH" },
194
194
  rpcUrls: { default: { http: [""] }, public: { http: [""] } }
195
- }));
195
+ };
196
+ };
197
+ export {
198
+ MockConnector,
199
+ MockProvider
196
200
  };
197
-
198
-
199
-
200
- exports.MockConnector = MockConnector; exports.MockProvider = MockProvider;