@wagmi/connectors 2.2.0 → 2.3.0-cjs

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