@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,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) {
@@ -106,7 +106,7 @@ function getInjectedName(ethereum) {
106
106
  if (provider.isMetaMask)
107
107
  return "MetaMask";
108
108
  };
109
- if (_optionalChain([ethereum, 'access', _ => _.providers, 'optionalAccess', _2 => _2.length])) {
109
+ if (ethereum.providers?.length) {
110
110
  const nameSet = /* @__PURE__ */ new Set();
111
111
  let unknownCount = 1;
112
112
  for (const provider of ethereum.providers) {
@@ -120,14 +120,14 @@ function getInjectedName(ethereum) {
120
120
  const names = [...nameSet];
121
121
  if (names.length)
122
122
  return names;
123
- return _nullishCoalesce(names[0], () => ( "Injected"));
123
+ return names[0] ?? "Injected";
124
124
  }
125
- return _nullishCoalesce(getName(ethereum), () => ( "Injected"));
125
+ return getName(ethereum) ?? "Injected";
126
126
  }
127
127
 
128
128
  // src/injected.ts
129
129
  var _provider;
130
- var InjectedConnector = class extends _chunkQYMCVNHTjs.Connector {
130
+ var InjectedConnector = class extends Connector {
131
131
  constructor({
132
132
  chains,
133
133
  options: options_
@@ -138,32 +138,32 @@ var InjectedConnector = class extends _chunkQYMCVNHTjs.Connector {
138
138
  if (typeof window === "undefined")
139
139
  return;
140
140
  const ethereum = window.ethereum;
141
- if (_optionalChain([ethereum, 'optionalAccess', _3 => _3.providers]))
141
+ if (ethereum?.providers)
142
142
  return ethereum.providers[0];
143
143
  return ethereum;
144
144
  },
145
145
  ...options_
146
146
  };
147
147
  super({ chains, options });
148
- _chunkQYMCVNHTjs.__publicField.call(void 0, this, "id", "injected");
149
- _chunkQYMCVNHTjs.__publicField.call(void 0, this, "name");
150
- _chunkQYMCVNHTjs.__publicField.call(void 0, this, "ready");
151
- _chunkQYMCVNHTjs.__privateAdd.call(void 0, this, _provider, void 0);
152
- _chunkQYMCVNHTjs.__publicField.call(void 0, this, "shimDisconnectKey", `${this.id}.shimDisconnect`);
153
- _chunkQYMCVNHTjs.__publicField.call(void 0, this, "onAccountsChanged", (accounts) => {
148
+ __publicField(this, "id", "injected");
149
+ __publicField(this, "name");
150
+ __publicField(this, "ready");
151
+ __privateAdd(this, _provider, void 0);
152
+ __publicField(this, "shimDisconnectKey", `${this.id}.shimDisconnect`);
153
+ __publicField(this, "onAccountsChanged", (accounts) => {
154
154
  if (accounts.length === 0)
155
155
  this.emit("disconnect");
156
156
  else
157
157
  this.emit("change", {
158
- account: _viem.getAddress.call(void 0, accounts[0])
158
+ account: getAddress(accounts[0])
159
159
  });
160
160
  });
161
- _chunkQYMCVNHTjs.__publicField.call(void 0, this, "onChainChanged", (chainId) => {
162
- const id = _chunkOQILYQDOjs.normalizeChainId.call(void 0, chainId);
161
+ __publicField(this, "onChainChanged", (chainId) => {
162
+ const id = normalizeChainId(chainId);
163
163
  const unsupported = this.isChainUnsupported(id);
164
164
  this.emit("change", { chain: { id, unsupported } });
165
165
  });
166
- _chunkQYMCVNHTjs.__publicField.call(void 0, this, "onDisconnect", async (error) => {
166
+ __publicField(this, "onDisconnect", async (error) => {
167
167
  if (error.code === 1013) {
168
168
  const provider = await this.getProvider();
169
169
  if (provider) {
@@ -174,7 +174,7 @@ var InjectedConnector = class extends _chunkQYMCVNHTjs.Connector {
174
174
  }
175
175
  this.emit("disconnect");
176
176
  if (this.options.shimDisconnect)
177
- _optionalChain([this, 'access', _4 => _4.storage, 'optionalAccess', _5 => _5.removeItem, 'call', _6 => _6(this.shimDisconnectKey)]);
177
+ this.storage?.removeItem(this.shimDisconnectKey);
178
178
  });
179
179
  const provider = options.getProvider();
180
180
  if (typeof options.name === "string")
@@ -197,7 +197,7 @@ var InjectedConnector = class extends _chunkQYMCVNHTjs.Connector {
197
197
  try {
198
198
  const provider = await this.getProvider();
199
199
  if (!provider)
200
- throw new (0, _chunkZCAPXGBXjs.ConnectorNotFoundError)();
200
+ throw new ConnectorNotFoundError();
201
201
  if (provider.on) {
202
202
  provider.on("accountsChanged", this.onAccountsChanged);
203
203
  provider.on("chainChanged", this.onChainChanged);
@@ -207,7 +207,7 @@ var InjectedConnector = class extends _chunkQYMCVNHTjs.Connector {
207
207
  const accounts = await provider.request({
208
208
  method: "eth_requestAccounts"
209
209
  });
210
- const account = _viem.getAddress.call(void 0, accounts[0]);
210
+ const account = getAddress(accounts[0]);
211
211
  let id = await this.getChainId();
212
212
  let unsupported = this.isChainUnsupported(id);
213
213
  if (chainId && id !== chainId) {
@@ -216,46 +216,46 @@ var InjectedConnector = class extends _chunkQYMCVNHTjs.Connector {
216
216
  unsupported = this.isChainUnsupported(id);
217
217
  }
218
218
  if (this.options.shimDisconnect)
219
- _optionalChain([this, 'access', _7 => _7.storage, 'optionalAccess', _8 => _8.setItem, 'call', _9 => _9(this.shimDisconnectKey, true)]);
219
+ this.storage?.setItem(this.shimDisconnectKey, true);
220
220
  return { account, chain: { id, unsupported } };
221
221
  } catch (error) {
222
222
  if (this.isUserRejectedRequestError(error))
223
- throw new (0, _viem.UserRejectedRequestError)(error);
223
+ throw new UserRejectedRequestError(error);
224
224
  if (error.code === -32002)
225
- throw new (0, _viem.ResourceUnavailableRpcError)(error);
225
+ throw new ResourceUnavailableRpcError(error);
226
226
  throw error;
227
227
  }
228
228
  }
229
229
  async disconnect() {
230
230
  const provider = await this.getProvider();
231
- if (!_optionalChain([provider, 'optionalAccess', _10 => _10.removeListener]))
231
+ if (!provider?.removeListener)
232
232
  return;
233
233
  provider.removeListener("accountsChanged", this.onAccountsChanged);
234
234
  provider.removeListener("chainChanged", this.onChainChanged);
235
235
  provider.removeListener("disconnect", this.onDisconnect);
236
236
  if (this.options.shimDisconnect)
237
- _optionalChain([this, 'access', _11 => _11.storage, 'optionalAccess', _12 => _12.removeItem, 'call', _13 => _13(this.shimDisconnectKey)]);
237
+ this.storage?.removeItem(this.shimDisconnectKey);
238
238
  }
239
239
  async getAccount() {
240
240
  const provider = await this.getProvider();
241
241
  if (!provider)
242
- throw new (0, _chunkZCAPXGBXjs.ConnectorNotFoundError)();
242
+ throw new ConnectorNotFoundError();
243
243
  const accounts = await provider.request({
244
244
  method: "eth_accounts"
245
245
  });
246
- return _viem.getAddress.call(void 0, accounts[0]);
246
+ return getAddress(accounts[0]);
247
247
  }
248
248
  async getChainId() {
249
249
  const provider = await this.getProvider();
250
250
  if (!provider)
251
- throw new (0, _chunkZCAPXGBXjs.ConnectorNotFoundError)();
252
- return provider.request({ method: "eth_chainId" }).then(_chunkOQILYQDOjs.normalizeChainId);
251
+ throw new ConnectorNotFoundError();
252
+ return provider.request({ method: "eth_chainId" }).then(normalizeChainId);
253
253
  }
254
254
  async getProvider() {
255
255
  const provider = this.options.getProvider();
256
256
  if (provider)
257
- _chunkQYMCVNHTjs.__privateSet.call(void 0, this, _provider, provider);
258
- return _chunkQYMCVNHTjs.__privateGet.call(void 0, this, _provider);
257
+ __privateSet(this, _provider, provider);
258
+ return __privateGet(this, _provider);
259
259
  }
260
260
  async getWalletClient({ chainId } = {}) {
261
261
  const [provider, account] = await Promise.all([
@@ -265,30 +265,30 @@ var InjectedConnector = class extends _chunkQYMCVNHTjs.Connector {
265
265
  const chain = this.chains.find((x) => x.id === chainId);
266
266
  if (!provider)
267
267
  throw new Error("provider is required.");
268
- return _viem.createWalletClient.call(void 0, {
268
+ return createWalletClient({
269
269
  account,
270
270
  chain,
271
- transport: _viem.custom.call(void 0, provider)
271
+ transport: custom(provider)
272
272
  });
273
273
  }
274
274
  async isAuthorized() {
275
275
  try {
276
- if (this.options.shimDisconnect && !_optionalChain([this, 'access', _14 => _14.storage, 'optionalAccess', _15 => _15.getItem, 'call', _16 => _16(this.shimDisconnectKey)]))
276
+ if (this.options.shimDisconnect && !this.storage?.getItem(this.shimDisconnectKey))
277
277
  return false;
278
278
  const provider = await this.getProvider();
279
279
  if (!provider)
280
- throw new (0, _chunkZCAPXGBXjs.ConnectorNotFoundError)();
280
+ throw new ConnectorNotFoundError();
281
281
  const account = await this.getAccount();
282
282
  return !!account;
283
- } catch (e) {
283
+ } catch {
284
284
  return false;
285
285
  }
286
286
  }
287
287
  async switchChain(chainId) {
288
288
  const provider = await this.getProvider();
289
289
  if (!provider)
290
- throw new (0, _chunkZCAPXGBXjs.ConnectorNotFoundError)();
291
- const id = _viem.numberToHex.call(void 0, chainId);
290
+ throw new ConnectorNotFoundError();
291
+ const id = numberToHex(chainId);
292
292
  try {
293
293
  await Promise.all([
294
294
  provider.request({
@@ -297,26 +297,26 @@ var InjectedConnector = class extends _chunkQYMCVNHTjs.Connector {
297
297
  }),
298
298
  new Promise(
299
299
  (res) => this.on("change", ({ chain }) => {
300
- if (_optionalChain([chain, 'optionalAccess', _17 => _17.id]) === chainId)
300
+ if (chain?.id === chainId)
301
301
  res();
302
302
  })
303
303
  )
304
304
  ]);
305
- return _nullishCoalesce(this.chains.find((x) => x.id === chainId), () => ( {
305
+ return this.chains.find((x) => x.id === chainId) ?? {
306
306
  id: chainId,
307
307
  name: `Chain ${id}`,
308
308
  network: `${id}`,
309
309
  nativeCurrency: { name: "Ether", decimals: 18, symbol: "ETH" },
310
310
  rpcUrls: { default: { http: [""] }, public: { http: [""] } }
311
- }));
311
+ };
312
312
  } catch (error) {
313
313
  const chain = this.chains.find((x) => x.id === chainId);
314
314
  if (!chain)
315
- throw new (0, _chunkZCAPXGBXjs.ChainNotConfiguredForConnectorError)({
315
+ throw new ChainNotConfiguredForConnectorError({
316
316
  chainId,
317
317
  connectorId: this.id
318
318
  });
319
- if (error.code === 4902 || _optionalChain([error, 'optionalAccess', _18 => _18.data, 'optionalAccess', _19 => _19.originalError, 'optionalAccess', _20 => _20.code]) === 4902) {
319
+ if (error.code === 4902 || error?.data?.originalError?.code === 4902) {
320
320
  try {
321
321
  await provider.request({
322
322
  method: "wallet_addEthereumChain",
@@ -325,24 +325,24 @@ var InjectedConnector = class extends _chunkQYMCVNHTjs.Connector {
325
325
  chainId: id,
326
326
  chainName: chain.name,
327
327
  nativeCurrency: chain.nativeCurrency,
328
- rpcUrls: [_nullishCoalesce(_optionalChain([chain, 'access', _21 => _21.rpcUrls, 'access', _22 => _22.public, 'optionalAccess', _23 => _23.http, 'access', _24 => _24[0]]), () => ( ""))],
328
+ rpcUrls: [chain.rpcUrls.public?.http[0] ?? ""],
329
329
  blockExplorerUrls: this.getBlockExplorerUrls(chain)
330
330
  }
331
331
  ]
332
332
  });
333
333
  const currentChainId = await this.getChainId();
334
334
  if (currentChainId !== chainId)
335
- throw new (0, _viem.UserRejectedRequestError)(
335
+ throw new UserRejectedRequestError(
336
336
  new Error("User rejected switch after adding network.")
337
337
  );
338
338
  return chain;
339
339
  } catch (error2) {
340
- throw new (0, _viem.UserRejectedRequestError)(error2);
340
+ throw new UserRejectedRequestError(error2);
341
341
  }
342
342
  }
343
343
  if (this.isUserRejectedRequestError(error))
344
- throw new (0, _viem.UserRejectedRequestError)(error);
345
- throw new (0, _viem.SwitchChainError)(error);
344
+ throw new UserRejectedRequestError(error);
345
+ throw new SwitchChainError(error);
346
346
  }
347
347
  }
348
348
  async watchAsset({
@@ -353,7 +353,7 @@ var InjectedConnector = class extends _chunkQYMCVNHTjs.Connector {
353
353
  }) {
354
354
  const provider = await this.getProvider();
355
355
  if (!provider)
356
- throw new (0, _chunkZCAPXGBXjs.ConnectorNotFoundError)();
356
+ throw new ConnectorNotFoundError();
357
357
  return provider.request({
358
358
  method: "wallet_watchAsset",
359
359
  params: {
@@ -373,6 +373,6 @@ var InjectedConnector = class extends _chunkQYMCVNHTjs.Connector {
373
373
  };
374
374
  _provider = new WeakMap();
375
375
 
376
-
377
-
378
- exports.InjectedConnector = InjectedConnector;
376
+ export {
377
+ InjectedConnector
378
+ };
@@ -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
+ };