@wagmi/connectors 1.0.3-cjs → 1.0.3

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