@wagmi/connectors 2.3.0-cjs → 2.3.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,4 +1,4 @@
1
1
  {
2
- "module": "../dist/coinbaseWallet.mjs",
2
+ "type": "module",
3
3
  "main": "../dist/coinbaseWallet.js"
4
4
  }
@@ -1,28 +1,28 @@
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
- var _chunkZCAPXGBXjs = require('./chunk-ZCAPXGBX.js');
5
-
6
-
7
- var _chunkOQILYQDOjs = require('./chunk-OQILYQDO.js');
8
-
9
-
10
-
11
-
12
-
13
-
14
- var _chunkQYMCVNHTjs = require('./chunk-QYMCVNHT.js');
1
+ import {
2
+ ChainNotConfiguredForConnectorError,
3
+ ConnectorNotFoundError
4
+ } from "./chunk-ZCAPXGBX.js";
5
+ import {
6
+ normalizeChainId
7
+ } from "./chunk-OQILYQDO.js";
8
+ import {
9
+ Connector,
10
+ __privateAdd,
11
+ __privateGet,
12
+ __privateSet,
13
+ __publicField
14
+ } from "./chunk-QYMCVNHT.js";
15
15
 
16
16
  // src/injected.ts
17
-
18
-
19
-
20
-
21
-
22
-
23
-
24
-
25
- var _viem = require('viem');
17
+ import {
18
+ ResourceUnavailableRpcError,
19
+ SwitchChainError,
20
+ UserRejectedRequestError,
21
+ createWalletClient,
22
+ custom,
23
+ getAddress,
24
+ numberToHex
25
+ } from "viem";
26
26
 
27
27
  // src/utils/getInjectedName.ts
28
28
  function getInjectedName(ethereum) {
@@ -108,7 +108,7 @@ function getInjectedName(ethereum) {
108
108
  if (provider.isMetaMask)
109
109
  return "MetaMask";
110
110
  };
111
- if (_optionalChain([ethereum, 'access', _ => _.providers, 'optionalAccess', _2 => _2.length])) {
111
+ if (ethereum.providers?.length) {
112
112
  const nameSet = /* @__PURE__ */ new Set();
113
113
  let unknownCount = 1;
114
114
  for (const provider of ethereum.providers) {
@@ -122,14 +122,14 @@ function getInjectedName(ethereum) {
122
122
  const names = [...nameSet];
123
123
  if (names.length)
124
124
  return names;
125
- return _nullishCoalesce(names[0], () => ( "Injected"));
125
+ return names[0] ?? "Injected";
126
126
  }
127
- return _nullishCoalesce(getName(ethereum), () => ( "Injected"));
127
+ return getName(ethereum) ?? "Injected";
128
128
  }
129
129
 
130
130
  // src/injected.ts
131
131
  var _provider;
132
- var InjectedConnector = class extends _chunkQYMCVNHTjs.Connector {
132
+ var InjectedConnector = class extends Connector {
133
133
  constructor({
134
134
  chains,
135
135
  options: options_
@@ -140,32 +140,32 @@ var InjectedConnector = class extends _chunkQYMCVNHTjs.Connector {
140
140
  if (typeof window === "undefined")
141
141
  return;
142
142
  const ethereum = window.ethereum;
143
- if (_optionalChain([ethereum, 'optionalAccess', _3 => _3.providers]))
143
+ if (ethereum?.providers)
144
144
  return ethereum.providers[0];
145
145
  return ethereum;
146
146
  },
147
147
  ...options_
148
148
  };
149
149
  super({ chains, options });
150
- _chunkQYMCVNHTjs.__publicField.call(void 0, this, "id", "injected");
151
- _chunkQYMCVNHTjs.__publicField.call(void 0, this, "name");
152
- _chunkQYMCVNHTjs.__publicField.call(void 0, this, "ready");
153
- _chunkQYMCVNHTjs.__privateAdd.call(void 0, this, _provider, void 0);
154
- _chunkQYMCVNHTjs.__publicField.call(void 0, this, "shimDisconnectKey", `${this.id}.shimDisconnect`);
155
- _chunkQYMCVNHTjs.__publicField.call(void 0, this, "onAccountsChanged", (accounts) => {
150
+ __publicField(this, "id", "injected");
151
+ __publicField(this, "name");
152
+ __publicField(this, "ready");
153
+ __privateAdd(this, _provider, void 0);
154
+ __publicField(this, "shimDisconnectKey", `${this.id}.shimDisconnect`);
155
+ __publicField(this, "onAccountsChanged", (accounts) => {
156
156
  if (accounts.length === 0)
157
157
  this.emit("disconnect");
158
158
  else
159
159
  this.emit("change", {
160
- account: _viem.getAddress.call(void 0, accounts[0])
160
+ account: getAddress(accounts[0])
161
161
  });
162
162
  });
163
- _chunkQYMCVNHTjs.__publicField.call(void 0, this, "onChainChanged", (chainId) => {
164
- const id = _chunkOQILYQDOjs.normalizeChainId.call(void 0, chainId);
163
+ __publicField(this, "onChainChanged", (chainId) => {
164
+ const id = normalizeChainId(chainId);
165
165
  const unsupported = this.isChainUnsupported(id);
166
166
  this.emit("change", { chain: { id, unsupported } });
167
167
  });
168
- _chunkQYMCVNHTjs.__publicField.call(void 0, this, "onDisconnect", async (error) => {
168
+ __publicField(this, "onDisconnect", async (error) => {
169
169
  if (error.code === 1013) {
170
170
  const provider = await this.getProvider();
171
171
  if (provider) {
@@ -176,7 +176,7 @@ var InjectedConnector = class extends _chunkQYMCVNHTjs.Connector {
176
176
  }
177
177
  this.emit("disconnect");
178
178
  if (this.options.shimDisconnect)
179
- _optionalChain([this, 'access', _4 => _4.storage, 'optionalAccess', _5 => _5.removeItem, 'call', _6 => _6(this.shimDisconnectKey)]);
179
+ this.storage?.removeItem(this.shimDisconnectKey);
180
180
  });
181
181
  const provider = options.getProvider();
182
182
  if (typeof options.name === "string")
@@ -199,7 +199,7 @@ var InjectedConnector = class extends _chunkQYMCVNHTjs.Connector {
199
199
  try {
200
200
  const provider = await this.getProvider();
201
201
  if (!provider)
202
- throw new (0, _chunkZCAPXGBXjs.ConnectorNotFoundError)();
202
+ throw new ConnectorNotFoundError();
203
203
  if (provider.on) {
204
204
  provider.on("accountsChanged", this.onAccountsChanged);
205
205
  provider.on("chainChanged", this.onChainChanged);
@@ -209,7 +209,7 @@ var InjectedConnector = class extends _chunkQYMCVNHTjs.Connector {
209
209
  const accounts = await provider.request({
210
210
  method: "eth_requestAccounts"
211
211
  });
212
- const account = _viem.getAddress.call(void 0, accounts[0]);
212
+ const account = getAddress(accounts[0]);
213
213
  let id = await this.getChainId();
214
214
  let unsupported = this.isChainUnsupported(id);
215
215
  if (chainId && id !== chainId) {
@@ -218,46 +218,46 @@ var InjectedConnector = class extends _chunkQYMCVNHTjs.Connector {
218
218
  unsupported = this.isChainUnsupported(id);
219
219
  }
220
220
  if (this.options.shimDisconnect)
221
- _optionalChain([this, 'access', _7 => _7.storage, 'optionalAccess', _8 => _8.setItem, 'call', _9 => _9(this.shimDisconnectKey, true)]);
221
+ this.storage?.setItem(this.shimDisconnectKey, true);
222
222
  return { account, chain: { id, unsupported } };
223
223
  } catch (error) {
224
224
  if (this.isUserRejectedRequestError(error))
225
- throw new (0, _viem.UserRejectedRequestError)(error);
225
+ throw new UserRejectedRequestError(error);
226
226
  if (error.code === -32002)
227
- throw new (0, _viem.ResourceUnavailableRpcError)(error);
227
+ throw new ResourceUnavailableRpcError(error);
228
228
  throw error;
229
229
  }
230
230
  }
231
231
  async disconnect() {
232
232
  const provider = await this.getProvider();
233
- if (!_optionalChain([provider, 'optionalAccess', _10 => _10.removeListener]))
233
+ if (!provider?.removeListener)
234
234
  return;
235
235
  provider.removeListener("accountsChanged", this.onAccountsChanged);
236
236
  provider.removeListener("chainChanged", this.onChainChanged);
237
237
  provider.removeListener("disconnect", this.onDisconnect);
238
238
  if (this.options.shimDisconnect)
239
- _optionalChain([this, 'access', _11 => _11.storage, 'optionalAccess', _12 => _12.removeItem, 'call', _13 => _13(this.shimDisconnectKey)]);
239
+ this.storage?.removeItem(this.shimDisconnectKey);
240
240
  }
241
241
  async getAccount() {
242
242
  const provider = await this.getProvider();
243
243
  if (!provider)
244
- throw new (0, _chunkZCAPXGBXjs.ConnectorNotFoundError)();
244
+ throw new ConnectorNotFoundError();
245
245
  const accounts = await provider.request({
246
246
  method: "eth_accounts"
247
247
  });
248
- return _viem.getAddress.call(void 0, accounts[0]);
248
+ return getAddress(accounts[0]);
249
249
  }
250
250
  async getChainId() {
251
251
  const provider = await this.getProvider();
252
252
  if (!provider)
253
- throw new (0, _chunkZCAPXGBXjs.ConnectorNotFoundError)();
254
- return provider.request({ method: "eth_chainId" }).then(_chunkOQILYQDOjs.normalizeChainId);
253
+ throw new ConnectorNotFoundError();
254
+ return provider.request({ method: "eth_chainId" }).then(normalizeChainId);
255
255
  }
256
256
  async getProvider() {
257
257
  const provider = this.options.getProvider();
258
258
  if (provider)
259
- _chunkQYMCVNHTjs.__privateSet.call(void 0, this, _provider, provider);
260
- return _chunkQYMCVNHTjs.__privateGet.call(void 0, this, _provider);
259
+ __privateSet(this, _provider, provider);
260
+ return __privateGet(this, _provider);
261
261
  }
262
262
  async getWalletClient({ chainId } = {}) {
263
263
  const [provider, account] = await Promise.all([
@@ -267,30 +267,30 @@ var InjectedConnector = class extends _chunkQYMCVNHTjs.Connector {
267
267
  const chain = this.chains.find((x) => x.id === chainId);
268
268
  if (!provider)
269
269
  throw new Error("provider is required.");
270
- return _viem.createWalletClient.call(void 0, {
270
+ return createWalletClient({
271
271
  account,
272
272
  chain,
273
- transport: _viem.custom.call(void 0, provider)
273
+ transport: custom(provider)
274
274
  });
275
275
  }
276
276
  async isAuthorized() {
277
277
  try {
278
- if (this.options.shimDisconnect && !_optionalChain([this, 'access', _14 => _14.storage, 'optionalAccess', _15 => _15.getItem, 'call', _16 => _16(this.shimDisconnectKey)]))
278
+ if (this.options.shimDisconnect && !this.storage?.getItem(this.shimDisconnectKey))
279
279
  return false;
280
280
  const provider = await this.getProvider();
281
281
  if (!provider)
282
- throw new (0, _chunkZCAPXGBXjs.ConnectorNotFoundError)();
282
+ throw new ConnectorNotFoundError();
283
283
  const account = await this.getAccount();
284
284
  return !!account;
285
- } catch (e) {
285
+ } catch {
286
286
  return false;
287
287
  }
288
288
  }
289
289
  async switchChain(chainId) {
290
290
  const provider = await this.getProvider();
291
291
  if (!provider)
292
- throw new (0, _chunkZCAPXGBXjs.ConnectorNotFoundError)();
293
- const id = _viem.numberToHex.call(void 0, chainId);
292
+ throw new ConnectorNotFoundError();
293
+ const id = numberToHex(chainId);
294
294
  try {
295
295
  await Promise.all([
296
296
  provider.request({
@@ -299,26 +299,26 @@ var InjectedConnector = class extends _chunkQYMCVNHTjs.Connector {
299
299
  }),
300
300
  new Promise(
301
301
  (res) => this.on("change", ({ chain }) => {
302
- if (_optionalChain([chain, 'optionalAccess', _17 => _17.id]) === chainId)
302
+ if (chain?.id === chainId)
303
303
  res();
304
304
  })
305
305
  )
306
306
  ]);
307
- return _nullishCoalesce(this.chains.find((x) => x.id === chainId), () => ( {
307
+ return this.chains.find((x) => x.id === chainId) ?? {
308
308
  id: chainId,
309
309
  name: `Chain ${id}`,
310
310
  network: `${id}`,
311
311
  nativeCurrency: { name: "Ether", decimals: 18, symbol: "ETH" },
312
312
  rpcUrls: { default: { http: [""] }, public: { http: [""] } }
313
- }));
313
+ };
314
314
  } catch (error) {
315
315
  const chain = this.chains.find((x) => x.id === chainId);
316
316
  if (!chain)
317
- throw new (0, _chunkZCAPXGBXjs.ChainNotConfiguredForConnectorError)({
317
+ throw new ChainNotConfiguredForConnectorError({
318
318
  chainId,
319
319
  connectorId: this.id
320
320
  });
321
- if (error.code === 4902 || _optionalChain([error, 'optionalAccess', _18 => _18.data, 'optionalAccess', _19 => _19.originalError, 'optionalAccess', _20 => _20.code]) === 4902) {
321
+ if (error.code === 4902 || error?.data?.originalError?.code === 4902) {
322
322
  try {
323
323
  await provider.request({
324
324
  method: "wallet_addEthereumChain",
@@ -327,24 +327,24 @@ var InjectedConnector = class extends _chunkQYMCVNHTjs.Connector {
327
327
  chainId: id,
328
328
  chainName: chain.name,
329
329
  nativeCurrency: chain.nativeCurrency,
330
- rpcUrls: [_nullishCoalesce(_optionalChain([chain, 'access', _21 => _21.rpcUrls, 'access', _22 => _22.public, 'optionalAccess', _23 => _23.http, 'access', _24 => _24[0]]), () => ( ""))],
330
+ rpcUrls: [chain.rpcUrls.public?.http[0] ?? ""],
331
331
  blockExplorerUrls: this.getBlockExplorerUrls(chain)
332
332
  }
333
333
  ]
334
334
  });
335
335
  const currentChainId = await this.getChainId();
336
336
  if (currentChainId !== chainId)
337
- throw new (0, _viem.UserRejectedRequestError)(
337
+ throw new UserRejectedRequestError(
338
338
  new Error("User rejected switch after adding network.")
339
339
  );
340
340
  return chain;
341
341
  } catch (error2) {
342
- throw new (0, _viem.UserRejectedRequestError)(error2);
342
+ throw new UserRejectedRequestError(error2);
343
343
  }
344
344
  }
345
345
  if (this.isUserRejectedRequestError(error))
346
- throw new (0, _viem.UserRejectedRequestError)(error);
347
- throw new (0, _viem.SwitchChainError)(error);
346
+ throw new UserRejectedRequestError(error);
347
+ throw new SwitchChainError(error);
348
348
  }
349
349
  }
350
350
  async watchAsset({
@@ -355,7 +355,7 @@ var InjectedConnector = class extends _chunkQYMCVNHTjs.Connector {
355
355
  }) {
356
356
  const provider = await this.getProvider();
357
357
  if (!provider)
358
- throw new (0, _chunkZCAPXGBXjs.ConnectorNotFoundError)();
358
+ throw new ConnectorNotFoundError();
359
359
  return provider.request({
360
360
  method: "wallet_watchAsset",
361
361
  params: {
@@ -375,6 +375,6 @@ var InjectedConnector = class extends _chunkQYMCVNHTjs.Connector {
375
375
  };
376
376
  _provider = new WeakMap();
377
377
 
378
-
379
-
380
- exports.InjectedConnector = InjectedConnector;
378
+ export {
379
+ InjectedConnector
380
+ };
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/utils/normalizeChainId.ts
1
+ // src/utils/normalizeChainId.ts
2
2
  function normalizeChainId(chainId) {
3
3
  if (typeof chainId === "string")
4
4
  return Number.parseInt(
@@ -10,6 +10,6 @@ function normalizeChainId(chainId) {
10
10
  return chainId;
11
11
  }
12
12
 
13
-
14
-
15
- exports.normalizeChainId = normalizeChainId;
13
+ export {
14
+ normalizeChainId
15
+ };
@@ -1,4 +1,4 @@
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(); } }var __defProp = Object.defineProperty;
1
+ var __defProp = Object.defineProperty;
2
2
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
3
  var __publicField = (obj, key, value) => {
4
4
  __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
@@ -28,11 +28,11 @@ var __privateMethod = (obj, member, method) => {
28
28
  };
29
29
 
30
30
  // src/base.ts
31
- var _eventemitter3 = require('eventemitter3'); var _eventemitter32 = _interopRequireDefault(_eventemitter3);
32
- var _chains = require('viem/chains');
33
- var Connector = class extends _eventemitter32.default {
31
+ import { default as EventEmitter } from "eventemitter3";
32
+ import { goerli, mainnet } from "viem/chains";
33
+ var Connector = class extends EventEmitter {
34
34
  constructor({
35
- chains = [_chains.mainnet, _chains.goerli],
35
+ chains = [mainnet, goerli],
36
36
  options
37
37
  }) {
38
38
  super();
@@ -43,7 +43,7 @@ var Connector = class extends _eventemitter32.default {
43
43
  this.options = options;
44
44
  }
45
45
  getBlockExplorerUrls(chain) {
46
- const { default: blockExplorer, ...blockExplorers } = _nullishCoalesce(chain.blockExplorers, () => ( {}));
46
+ const { default: blockExplorer, ...blockExplorers } = chain.blockExplorers ?? {};
47
47
  if (blockExplorer)
48
48
  return [
49
49
  blockExplorer.url,
@@ -58,11 +58,11 @@ var Connector = class extends _eventemitter32.default {
58
58
  }
59
59
  };
60
60
 
61
-
62
-
63
-
64
-
65
-
66
-
67
-
68
- exports.__publicField = __publicField; exports.__privateGet = __privateGet; exports.__privateAdd = __privateAdd; exports.__privateSet = __privateSet; exports.__privateMethod = __privateMethod; exports.Connector = Connector;
61
+ export {
62
+ __publicField,
63
+ __privateGet,
64
+ __privateAdd,
65
+ __privateSet,
66
+ __privateMethod,
67
+ Connector
68
+ };
@@ -1,6 +1,6 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
-
3
- var _chunkQYMCVNHTjs = require('./chunk-QYMCVNHT.js');
1
+ import {
2
+ __publicField
3
+ } from "./chunk-QYMCVNHT.js";
4
4
 
5
5
  // src/errors.ts
6
6
  var ChainNotConfiguredForConnectorError = class extends Error {
@@ -9,18 +9,18 @@ var ChainNotConfiguredForConnectorError = class extends Error {
9
9
  connectorId
10
10
  }) {
11
11
  super(`Chain "${chainId}" not configured for connector "${connectorId}".`);
12
- _chunkQYMCVNHTjs.__publicField.call(void 0, this, "name", "ChainNotConfiguredForConnectorError");
12
+ __publicField(this, "name", "ChainNotConfiguredForConnectorError");
13
13
  }
14
14
  };
15
15
  var ConnectorNotFoundError = class extends Error {
16
16
  constructor() {
17
17
  super(...arguments);
18
- _chunkQYMCVNHTjs.__publicField.call(void 0, this, "name", "ConnectorNotFoundError");
19
- _chunkQYMCVNHTjs.__publicField.call(void 0, this, "message", "Connector not found");
18
+ __publicField(this, "name", "ConnectorNotFoundError");
19
+ __publicField(this, "message", "Connector not found");
20
20
  }
21
21
  };
22
22
 
23
-
24
-
25
-
26
- exports.ChainNotConfiguredForConnectorError = ChainNotConfiguredForConnectorError; exports.ConnectorNotFoundError = ConnectorNotFoundError;
23
+ export {
24
+ ChainNotConfiguredForConnectorError,
25
+ ConnectorNotFoundError
26
+ };