@wagmi/connectors 3.1.4-cjs → 3.1.4

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,27 +1,27 @@
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 _chunkUGBGYVBHjs = require('./chunk-UGBGYVBH.js');
5
-
6
-
7
- var _chunkOQILYQDOjs = require('./chunk-OQILYQDO.js');
8
-
9
-
10
-
11
-
12
-
13
- var _chunkW65LBPLTjs = require('./chunk-W65LBPLT.js');
1
+ import {
2
+ ChainNotConfiguredForConnectorError,
3
+ ConnectorNotFoundError
4
+ } from "./chunk-UGBGYVBH.js";
5
+ import {
6
+ normalizeChainId
7
+ } from "./chunk-OQILYQDO.js";
8
+ import {
9
+ Connector,
10
+ __privateAdd,
11
+ __privateGet,
12
+ __privateSet
13
+ } from "./chunk-W65LBPLT.js";
14
14
 
15
15
  // src/injected.ts
16
-
17
-
18
-
19
-
20
-
21
-
22
-
23
-
24
- var _viem = require('viem');
16
+ import {
17
+ ResourceUnavailableRpcError,
18
+ SwitchChainError,
19
+ UserRejectedRequestError,
20
+ createWalletClient,
21
+ custom,
22
+ getAddress,
23
+ numberToHex
24
+ } from "viem";
25
25
 
26
26
  // src/utils/getInjectedName.ts
27
27
  function getInjectedName(ethereum) {
@@ -121,7 +121,7 @@ function getInjectedName(ethereum) {
121
121
  if (provider.isMetaMask)
122
122
  return "MetaMask";
123
123
  };
124
- if (_optionalChain([ethereum, 'access', _ => _.providers, 'optionalAccess', _2 => _2.length])) {
124
+ if (ethereum.providers?.length) {
125
125
  const nameSet = /* @__PURE__ */ new Set();
126
126
  let unknownCount = 1;
127
127
  for (const provider of ethereum.providers) {
@@ -135,14 +135,14 @@ function getInjectedName(ethereum) {
135
135
  const names = [...nameSet];
136
136
  if (names.length)
137
137
  return names;
138
- return _nullishCoalesce(names[0], () => ( "Injected"));
138
+ return names[0] ?? "Injected";
139
139
  }
140
- return _nullishCoalesce(getName(ethereum), () => ( "Injected"));
140
+ return getName(ethereum) ?? "Injected";
141
141
  }
142
142
 
143
143
  // src/injected.ts
144
144
  var _provider;
145
- var InjectedConnector = class extends _chunkW65LBPLTjs.Connector {
145
+ var InjectedConnector = class extends Connector {
146
146
  constructor({
147
147
  chains,
148
148
  options: options_
@@ -153,7 +153,7 @@ var InjectedConnector = class extends _chunkW65LBPLTjs.Connector {
153
153
  if (typeof window === "undefined")
154
154
  return;
155
155
  const ethereum = window.ethereum;
156
- if (_optionalChain([ethereum, 'optionalAccess', _3 => _3.providers]))
156
+ if (ethereum?.providers)
157
157
  return ethereum.providers[0];
158
158
  return ethereum;
159
159
  },
@@ -161,18 +161,18 @@ var InjectedConnector = class extends _chunkW65LBPLTjs.Connector {
161
161
  };
162
162
  super({ chains, options });
163
163
  this.id = "injected";
164
- _chunkW65LBPLTjs.__privateAdd.call(void 0, this, _provider, void 0);
164
+ __privateAdd(this, _provider, void 0);
165
165
  this.shimDisconnectKey = `${this.id}.shimDisconnect`;
166
166
  this.onAccountsChanged = (accounts) => {
167
167
  if (accounts.length === 0)
168
168
  this.emit("disconnect");
169
169
  else
170
170
  this.emit("change", {
171
- account: _viem.getAddress.call(void 0, accounts[0])
171
+ account: getAddress(accounts[0])
172
172
  });
173
173
  };
174
174
  this.onChainChanged = (chainId) => {
175
- const id = _chunkOQILYQDOjs.normalizeChainId.call(void 0, chainId);
175
+ const id = normalizeChainId(chainId);
176
176
  const unsupported = this.isChainUnsupported(id);
177
177
  this.emit("change", { chain: { id, unsupported } });
178
178
  };
@@ -187,7 +187,7 @@ var InjectedConnector = class extends _chunkW65LBPLTjs.Connector {
187
187
  }
188
188
  this.emit("disconnect");
189
189
  if (this.options.shimDisconnect)
190
- _optionalChain([this, 'access', _4 => _4.storage, 'optionalAccess', _5 => _5.removeItem, 'call', _6 => _6(this.shimDisconnectKey)]);
190
+ this.storage?.removeItem(this.shimDisconnectKey);
191
191
  };
192
192
  const provider = options.getProvider();
193
193
  if (typeof options.name === "string")
@@ -210,7 +210,7 @@ var InjectedConnector = class extends _chunkW65LBPLTjs.Connector {
210
210
  try {
211
211
  const provider = await this.getProvider();
212
212
  if (!provider)
213
- throw new (0, _chunkUGBGYVBHjs.ConnectorNotFoundError)();
213
+ throw new ConnectorNotFoundError();
214
214
  if (provider.on) {
215
215
  provider.on("accountsChanged", this.onAccountsChanged);
216
216
  provider.on("chainChanged", this.onChainChanged);
@@ -220,7 +220,7 @@ var InjectedConnector = class extends _chunkW65LBPLTjs.Connector {
220
220
  const accounts = await provider.request({
221
221
  method: "eth_requestAccounts"
222
222
  });
223
- const account = _viem.getAddress.call(void 0, accounts[0]);
223
+ const account = getAddress(accounts[0]);
224
224
  let id = await this.getChainId();
225
225
  let unsupported = this.isChainUnsupported(id);
226
226
  if (chainId && id !== chainId) {
@@ -229,46 +229,46 @@ var InjectedConnector = class extends _chunkW65LBPLTjs.Connector {
229
229
  unsupported = this.isChainUnsupported(id);
230
230
  }
231
231
  if (this.options.shimDisconnect)
232
- _optionalChain([this, 'access', _7 => _7.storage, 'optionalAccess', _8 => _8.setItem, 'call', _9 => _9(this.shimDisconnectKey, true)]);
232
+ this.storage?.setItem(this.shimDisconnectKey, true);
233
233
  return { account, chain: { id, unsupported } };
234
234
  } catch (error) {
235
235
  if (this.isUserRejectedRequestError(error))
236
- throw new (0, _viem.UserRejectedRequestError)(error);
236
+ throw new UserRejectedRequestError(error);
237
237
  if (error.code === -32002)
238
- throw new (0, _viem.ResourceUnavailableRpcError)(error);
238
+ throw new ResourceUnavailableRpcError(error);
239
239
  throw error;
240
240
  }
241
241
  }
242
242
  async disconnect() {
243
243
  const provider = await this.getProvider();
244
- if (!_optionalChain([provider, 'optionalAccess', _10 => _10.removeListener]))
244
+ if (!provider?.removeListener)
245
245
  return;
246
246
  provider.removeListener("accountsChanged", this.onAccountsChanged);
247
247
  provider.removeListener("chainChanged", this.onChainChanged);
248
248
  provider.removeListener("disconnect", this.onDisconnect);
249
249
  if (this.options.shimDisconnect)
250
- _optionalChain([this, 'access', _11 => _11.storage, 'optionalAccess', _12 => _12.removeItem, 'call', _13 => _13(this.shimDisconnectKey)]);
250
+ this.storage?.removeItem(this.shimDisconnectKey);
251
251
  }
252
252
  async getAccount() {
253
253
  const provider = await this.getProvider();
254
254
  if (!provider)
255
- throw new (0, _chunkUGBGYVBHjs.ConnectorNotFoundError)();
255
+ throw new ConnectorNotFoundError();
256
256
  const accounts = await provider.request({
257
257
  method: "eth_accounts"
258
258
  });
259
- return _viem.getAddress.call(void 0, accounts[0]);
259
+ return getAddress(accounts[0]);
260
260
  }
261
261
  async getChainId() {
262
262
  const provider = await this.getProvider();
263
263
  if (!provider)
264
- throw new (0, _chunkUGBGYVBHjs.ConnectorNotFoundError)();
265
- return provider.request({ method: "eth_chainId" }).then(_chunkOQILYQDOjs.normalizeChainId);
264
+ throw new ConnectorNotFoundError();
265
+ return provider.request({ method: "eth_chainId" }).then(normalizeChainId);
266
266
  }
267
267
  async getProvider() {
268
268
  const provider = this.options.getProvider();
269
269
  if (provider)
270
- _chunkW65LBPLTjs.__privateSet.call(void 0, this, _provider, provider);
271
- return _chunkW65LBPLTjs.__privateGet.call(void 0, this, _provider);
270
+ __privateSet(this, _provider, provider);
271
+ return __privateGet(this, _provider);
272
272
  }
273
273
  async getWalletClient({
274
274
  chainId
@@ -280,30 +280,30 @@ var InjectedConnector = class extends _chunkW65LBPLTjs.Connector {
280
280
  const chain = this.chains.find((x) => x.id === chainId);
281
281
  if (!provider)
282
282
  throw new Error("provider is required.");
283
- return _viem.createWalletClient.call(void 0, {
283
+ return createWalletClient({
284
284
  account,
285
285
  chain,
286
- transport: _viem.custom.call(void 0, provider)
286
+ transport: custom(provider)
287
287
  });
288
288
  }
289
289
  async isAuthorized() {
290
290
  try {
291
- if (this.options.shimDisconnect && !_optionalChain([this, 'access', _14 => _14.storage, 'optionalAccess', _15 => _15.getItem, 'call', _16 => _16(this.shimDisconnectKey)]))
291
+ if (this.options.shimDisconnect && !this.storage?.getItem(this.shimDisconnectKey))
292
292
  return false;
293
293
  const provider = await this.getProvider();
294
294
  if (!provider)
295
- throw new (0, _chunkUGBGYVBHjs.ConnectorNotFoundError)();
295
+ throw new ConnectorNotFoundError();
296
296
  const account = await this.getAccount();
297
297
  return !!account;
298
- } catch (e) {
298
+ } catch {
299
299
  return false;
300
300
  }
301
301
  }
302
302
  async switchChain(chainId) {
303
303
  const provider = await this.getProvider();
304
304
  if (!provider)
305
- throw new (0, _chunkUGBGYVBHjs.ConnectorNotFoundError)();
306
- const id = _viem.numberToHex.call(void 0, chainId);
305
+ throw new ConnectorNotFoundError();
306
+ const id = numberToHex(chainId);
307
307
  try {
308
308
  await Promise.all([
309
309
  provider.request({
@@ -312,26 +312,26 @@ var InjectedConnector = class extends _chunkW65LBPLTjs.Connector {
312
312
  }),
313
313
  new Promise(
314
314
  (res) => this.on("change", ({ chain }) => {
315
- if (_optionalChain([chain, 'optionalAccess', _17 => _17.id]) === chainId)
315
+ if (chain?.id === chainId)
316
316
  res();
317
317
  })
318
318
  )
319
319
  ]);
320
- return _nullishCoalesce(this.chains.find((x) => x.id === chainId), () => ( {
320
+ return this.chains.find((x) => x.id === chainId) ?? {
321
321
  id: chainId,
322
322
  name: `Chain ${id}`,
323
323
  network: `${id}`,
324
324
  nativeCurrency: { name: "Ether", decimals: 18, symbol: "ETH" },
325
325
  rpcUrls: { default: { http: [""] }, public: { http: [""] } }
326
- }));
326
+ };
327
327
  } catch (error) {
328
328
  const chain = this.chains.find((x) => x.id === chainId);
329
329
  if (!chain)
330
- throw new (0, _chunkUGBGYVBHjs.ChainNotConfiguredForConnectorError)({
330
+ throw new ChainNotConfiguredForConnectorError({
331
331
  chainId,
332
332
  connectorId: this.id
333
333
  });
334
- if (error.code === 4902 || _optionalChain([error, 'optionalAccess', _18 => _18.data, 'optionalAccess', _19 => _19.originalError, 'optionalAccess', _20 => _20.code]) === 4902) {
334
+ if (error.code === 4902 || error?.data?.originalError?.code === 4902) {
335
335
  try {
336
336
  await provider.request({
337
337
  method: "wallet_addEthereumChain",
@@ -340,24 +340,24 @@ var InjectedConnector = class extends _chunkW65LBPLTjs.Connector {
340
340
  chainId: id,
341
341
  chainName: chain.name,
342
342
  nativeCurrency: chain.nativeCurrency,
343
- rpcUrls: [_nullishCoalesce(_optionalChain([chain, 'access', _21 => _21.rpcUrls, 'access', _22 => _22.public, 'optionalAccess', _23 => _23.http, 'access', _24 => _24[0]]), () => ( ""))],
343
+ rpcUrls: [chain.rpcUrls.public?.http[0] ?? ""],
344
344
  blockExplorerUrls: this.getBlockExplorerUrls(chain)
345
345
  }
346
346
  ]
347
347
  });
348
348
  const currentChainId = await this.getChainId();
349
349
  if (currentChainId !== chainId)
350
- throw new (0, _viem.UserRejectedRequestError)(
350
+ throw new UserRejectedRequestError(
351
351
  new Error("User rejected switch after adding network.")
352
352
  );
353
353
  return chain;
354
354
  } catch (error2) {
355
- throw new (0, _viem.UserRejectedRequestError)(error2);
355
+ throw new UserRejectedRequestError(error2);
356
356
  }
357
357
  }
358
358
  if (this.isUserRejectedRequestError(error))
359
- throw new (0, _viem.UserRejectedRequestError)(error);
360
- throw new (0, _viem.SwitchChainError)(error);
359
+ throw new UserRejectedRequestError(error);
360
+ throw new SwitchChainError(error);
361
361
  }
362
362
  }
363
363
  async watchAsset({
@@ -368,7 +368,7 @@ var InjectedConnector = class extends _chunkW65LBPLTjs.Connector {
368
368
  }) {
369
369
  const provider = await this.getProvider();
370
370
  if (!provider)
371
- throw new (0, _chunkUGBGYVBHjs.ConnectorNotFoundError)();
371
+ throw new ConnectorNotFoundError();
372
372
  return provider.request({
373
373
  method: "wallet_watchAsset",
374
374
  params: {
@@ -388,6 +388,6 @@ var InjectedConnector = class extends _chunkW65LBPLTjs.Connector {
388
388
  };
389
389
  _provider = new WeakMap();
390
390
 
391
-
392
-
393
- exports.InjectedConnector = InjectedConnector;
391
+ export {
392
+ InjectedConnector
393
+ };
@@ -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});// src/errors.ts
1
+ // src/errors.ts
2
2
  var ChainNotConfiguredForConnectorError = class extends Error {
3
3
  constructor({
4
4
  chainId,
@@ -16,7 +16,7 @@ var ConnectorNotFoundError = class extends Error {
16
16
  }
17
17
  };
18
18
 
19
-
20
-
21
-
22
- exports.ChainNotConfiguredForConnectorError = ChainNotConfiguredForConnectorError; exports.ConnectorNotFoundError = ConnectorNotFoundError;
19
+ export {
20
+ ChainNotConfiguredForConnectorError,
21
+ ConnectorNotFoundError
22
+ };
@@ -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 __accessCheck = (obj, member, msg) => {
1
+ var __accessCheck = (obj, member, msg) => {
2
2
  if (!member.has(obj))
3
3
  throw TypeError("Cannot " + msg);
4
4
  };
@@ -22,11 +22,11 @@ var __privateMethod = (obj, member, method) => {
22
22
  };
23
23
 
24
24
  // src/base.ts
25
- var _eventemitter3 = require('eventemitter3'); var _eventemitter32 = _interopRequireDefault(_eventemitter3);
26
- var _chains = require('viem/chains');
27
- var Connector = class extends _eventemitter32.default {
25
+ import { default as EventEmitter } from "eventemitter3";
26
+ import { goerli, mainnet } from "viem/chains";
27
+ var Connector = class extends EventEmitter {
28
28
  constructor({
29
- chains = [_chains.mainnet, _chains.goerli],
29
+ chains = [mainnet, goerli],
30
30
  options
31
31
  }) {
32
32
  super();
@@ -34,7 +34,7 @@ var Connector = class extends _eventemitter32.default {
34
34
  this.options = options;
35
35
  }
36
36
  getBlockExplorerUrls(chain) {
37
- const { default: blockExplorer, ...blockExplorers } = _nullishCoalesce(chain.blockExplorers, () => ( {}));
37
+ const { default: blockExplorer, ...blockExplorers } = chain.blockExplorers ?? {};
38
38
  if (blockExplorer)
39
39
  return [
40
40
  blockExplorer.url,
@@ -49,10 +49,10 @@ var Connector = class extends _eventemitter32.default {
49
49
  }
50
50
  };
51
51
 
52
-
53
-
54
-
55
-
56
-
57
-
58
- exports.__privateGet = __privateGet; exports.__privateAdd = __privateAdd; exports.__privateSet = __privateSet; exports.__privateMethod = __privateMethod; exports.Connector = Connector;
52
+ export {
53
+ __privateGet,
54
+ __privateAdd,
55
+ __privateSet,
56
+ __privateMethod,
57
+ Connector
58
+ };
@@ -1,27 +1,27 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } 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 _chunkUGBGYVBHjs = require('./chunk-UGBGYVBH.js');
4
-
5
-
6
- var _chunkOQILYQDOjs = require('./chunk-OQILYQDO.js');
7
-
8
-
9
-
10
-
11
-
12
- var _chunkW65LBPLTjs = require('./chunk-W65LBPLT.js');
1
+ import {
2
+ ChainNotConfiguredForConnectorError
3
+ } from "./chunk-UGBGYVBH.js";
4
+ import {
5
+ normalizeChainId
6
+ } from "./chunk-OQILYQDO.js";
7
+ import {
8
+ Connector,
9
+ __privateAdd,
10
+ __privateGet,
11
+ __privateSet
12
+ } from "./chunk-W65LBPLT.js";
13
13
 
14
14
  // src/coinbaseWallet.ts
15
-
16
-
17
-
18
-
19
-
20
-
21
-
22
- var _viem = require('viem');
15
+ import {
16
+ SwitchChainError,
17
+ UserRejectedRequestError,
18
+ createWalletClient,
19
+ custom,
20
+ getAddress,
21
+ numberToHex
22
+ } from "viem";
23
23
  var _client, _provider;
24
- var CoinbaseWalletConnector = class extends _chunkW65LBPLTjs.Connector {
24
+ var CoinbaseWalletConnector = class extends Connector {
25
25
  constructor({ chains, options }) {
26
26
  super({
27
27
  chains,
@@ -33,16 +33,16 @@ var CoinbaseWalletConnector = class extends _chunkW65LBPLTjs.Connector {
33
33
  this.id = "coinbaseWallet";
34
34
  this.name = "Coinbase Wallet";
35
35
  this.ready = true;
36
- _chunkW65LBPLTjs.__privateAdd.call(void 0, this, _client, void 0);
37
- _chunkW65LBPLTjs.__privateAdd.call(void 0, this, _provider, void 0);
36
+ __privateAdd(this, _client, void 0);
37
+ __privateAdd(this, _provider, void 0);
38
38
  this.onAccountsChanged = (accounts) => {
39
39
  if (accounts.length === 0)
40
40
  this.emit("disconnect");
41
41
  else
42
- this.emit("change", { account: _viem.getAddress.call(void 0, accounts[0]) });
42
+ this.emit("change", { account: getAddress(accounts[0]) });
43
43
  };
44
44
  this.onChainChanged = (chainId) => {
45
- const id = _chunkOQILYQDOjs.normalizeChainId.call(void 0, chainId);
45
+ const id = normalizeChainId(chainId);
46
46
  const unsupported = this.isChainUnsupported(id);
47
47
  this.emit("change", { chain: { id, unsupported } });
48
48
  };
@@ -58,7 +58,7 @@ var CoinbaseWalletConnector = class extends _chunkW65LBPLTjs.Connector {
58
58
  provider.on("disconnect", this.onDisconnect);
59
59
  this.emit("message", { type: "connecting" });
60
60
  const accounts = await provider.enable();
61
- const account = _viem.getAddress.call(void 0, accounts[0]);
61
+ const account = getAddress(accounts[0]);
62
62
  let id = await this.getChainId();
63
63
  let unsupported = this.isChainUnsupported(id);
64
64
  if (chainId && id !== chainId) {
@@ -74,12 +74,12 @@ var CoinbaseWalletConnector = class extends _chunkW65LBPLTjs.Connector {
74
74
  if (/(user closed modal|accounts received is empty)/i.test(
75
75
  error.message
76
76
  ))
77
- throw new (0, _viem.UserRejectedRequestError)(error);
77
+ throw new UserRejectedRequestError(error);
78
78
  throw error;
79
79
  }
80
80
  }
81
81
  async disconnect() {
82
- if (!_chunkW65LBPLTjs.__privateGet.call(void 0, this, _provider))
82
+ if (!__privateGet(this, _provider))
83
83
  return;
84
84
  const provider = await this.getProvider();
85
85
  provider.removeListener("accountsChanged", this.onAccountsChanged);
@@ -93,32 +93,32 @@ var CoinbaseWalletConnector = class extends _chunkW65LBPLTjs.Connector {
93
93
  const accounts = await provider.request({
94
94
  method: "eth_accounts"
95
95
  });
96
- return _viem.getAddress.call(void 0, accounts[0]);
96
+ return getAddress(accounts[0]);
97
97
  }
98
98
  async getChainId() {
99
99
  const provider = await this.getProvider();
100
- const chainId = _chunkOQILYQDOjs.normalizeChainId.call(void 0, provider.chainId);
100
+ const chainId = normalizeChainId(provider.chainId);
101
101
  return chainId;
102
102
  }
103
103
  async getProvider() {
104
- if (!_chunkW65LBPLTjs.__privateGet.call(void 0, this, _provider)) {
105
- let CoinbaseWalletSDK = (await Promise.resolve().then(() => _interopRequireWildcard(require("@coinbase/wallet-sdk")))).default;
104
+ if (!__privateGet(this, _provider)) {
105
+ let CoinbaseWalletSDK = (await import("@coinbase/wallet-sdk")).default;
106
106
  if (typeof CoinbaseWalletSDK !== "function" && typeof CoinbaseWalletSDK.default === "function")
107
107
  CoinbaseWalletSDK = CoinbaseWalletSDK.default;
108
- _chunkW65LBPLTjs.__privateSet.call(void 0, this, _client, new CoinbaseWalletSDK(this.options));
108
+ __privateSet(this, _client, new CoinbaseWalletSDK(this.options));
109
109
  class WalletProvider {
110
110
  }
111
111
  class Client {
112
112
  }
113
- const walletExtensionChainId = _optionalChain([_chunkW65LBPLTjs.__privateGet.call(void 0, this, _client), 'access', _ => _.walletExtension, 'optionalAccess', _2 => _2.getChainId, 'call', _3 => _3()]);
113
+ const walletExtensionChainId = __privateGet(this, _client).walletExtension?.getChainId();
114
114
  const chain = this.chains.find(
115
115
  (chain2) => this.options.chainId ? chain2.id === this.options.chainId : chain2.id === walletExtensionChainId
116
116
  ) || this.chains[0];
117
- const chainId = this.options.chainId || _optionalChain([chain, 'optionalAccess', _4 => _4.id]);
118
- const jsonRpcUrl = this.options.jsonRpcUrl || _optionalChain([chain, 'optionalAccess', _5 => _5.rpcUrls, 'access', _6 => _6.default, 'access', _7 => _7.http, 'access', _8 => _8[0]]);
119
- _chunkW65LBPLTjs.__privateSet.call(void 0, this, _provider, _chunkW65LBPLTjs.__privateGet.call(void 0, this, _client).makeWeb3Provider(jsonRpcUrl, chainId));
117
+ const chainId = this.options.chainId || chain?.id;
118
+ const jsonRpcUrl = this.options.jsonRpcUrl || chain?.rpcUrls.default.http[0];
119
+ __privateSet(this, _provider, __privateGet(this, _client).makeWeb3Provider(jsonRpcUrl, chainId));
120
120
  }
121
- return _chunkW65LBPLTjs.__privateGet.call(void 0, this, _provider);
121
+ return __privateGet(this, _provider);
122
122
  }
123
123
  async getWalletClient({
124
124
  chainId
@@ -130,39 +130,39 @@ var CoinbaseWalletConnector = class extends _chunkW65LBPLTjs.Connector {
130
130
  const chain = this.chains.find((x) => x.id === chainId);
131
131
  if (!provider)
132
132
  throw new Error("provider is required.");
133
- return _viem.createWalletClient.call(void 0, {
133
+ return createWalletClient({
134
134
  account,
135
135
  chain,
136
- transport: _viem.custom.call(void 0, provider)
136
+ transport: custom(provider)
137
137
  });
138
138
  }
139
139
  async isAuthorized() {
140
140
  try {
141
141
  const account = await this.getAccount();
142
142
  return !!account;
143
- } catch (e) {
143
+ } catch {
144
144
  return false;
145
145
  }
146
146
  }
147
147
  async switchChain(chainId) {
148
148
  const provider = await this.getProvider();
149
- const id = _viem.numberToHex.call(void 0, chainId);
149
+ const id = numberToHex(chainId);
150
150
  try {
151
151
  await provider.request({
152
152
  method: "wallet_switchEthereumChain",
153
153
  params: [{ chainId: id }]
154
154
  });
155
- return _nullishCoalesce(this.chains.find((x) => x.id === chainId), () => ( {
155
+ return this.chains.find((x) => x.id === chainId) ?? {
156
156
  id: chainId,
157
157
  name: `Chain ${id}`,
158
158
  network: `${id}`,
159
159
  nativeCurrency: { name: "Ether", decimals: 18, symbol: "ETH" },
160
160
  rpcUrls: { default: { http: [""] }, public: { http: [""] } }
161
- }));
161
+ };
162
162
  } catch (error) {
163
163
  const chain = this.chains.find((x) => x.id === chainId);
164
164
  if (!chain)
165
- throw new (0, _chunkUGBGYVBHjs.ChainNotConfiguredForConnectorError)({
165
+ throw new ChainNotConfiguredForConnectorError({
166
166
  chainId,
167
167
  connectorId: this.id
168
168
  });
@@ -175,17 +175,17 @@ var CoinbaseWalletConnector = class extends _chunkW65LBPLTjs.Connector {
175
175
  chainId: id,
176
176
  chainName: chain.name,
177
177
  nativeCurrency: chain.nativeCurrency,
178
- rpcUrls: [_nullishCoalesce(_optionalChain([chain, 'access', _9 => _9.rpcUrls, 'access', _10 => _10.public, 'optionalAccess', _11 => _11.http, 'access', _12 => _12[0]]), () => ( ""))],
178
+ rpcUrls: [chain.rpcUrls.public?.http[0] ?? ""],
179
179
  blockExplorerUrls: this.getBlockExplorerUrls(chain)
180
180
  }
181
181
  ]
182
182
  });
183
183
  return chain;
184
184
  } catch (error2) {
185
- throw new (0, _viem.UserRejectedRequestError)(error2);
185
+ throw new UserRejectedRequestError(error2);
186
186
  }
187
187
  }
188
- throw new (0, _viem.SwitchChainError)(error);
188
+ throw new SwitchChainError(error);
189
189
  }
190
190
  }
191
191
  async watchAsset({
@@ -211,6 +211,6 @@ var CoinbaseWalletConnector = class extends _chunkW65LBPLTjs.Connector {
211
211
  };
212
212
  _client = new WeakMap();
213
213
  _provider = new WeakMap();
214
-
215
-
216
- exports.CoinbaseWalletConnector = CoinbaseWalletConnector;
214
+ export {
215
+ CoinbaseWalletConnector
216
+ };
package/dist/index.js CHANGED
@@ -1,16 +1,16 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
-
3
-
4
- var _chunkUGBGYVBHjs = require('./chunk-UGBGYVBH.js');
5
-
6
-
7
- var _chunkOQILYQDOjs = require('./chunk-OQILYQDO.js');
8
-
9
-
10
- var _chunkW65LBPLTjs = require('./chunk-W65LBPLT.js');
11
-
12
-
13
-
14
-
15
-
16
- exports.ChainNotConfiguredForConnectorError = _chunkUGBGYVBHjs.ChainNotConfiguredForConnectorError; exports.Connector = _chunkW65LBPLTjs.Connector; exports.ConnectorNotFoundError = _chunkUGBGYVBHjs.ConnectorNotFoundError; exports.normalizeChainId = _chunkOQILYQDOjs.normalizeChainId;
1
+ import {
2
+ ChainNotConfiguredForConnectorError,
3
+ ConnectorNotFoundError
4
+ } from "./chunk-UGBGYVBH.js";
5
+ import {
6
+ normalizeChainId
7
+ } from "./chunk-OQILYQDO.js";
8
+ import {
9
+ Connector
10
+ } from "./chunk-W65LBPLT.js";
11
+ export {
12
+ ChainNotConfiguredForConnectorError,
13
+ Connector,
14
+ ConnectorNotFoundError,
15
+ normalizeChainId
16
+ };
package/dist/injected.js CHANGED
@@ -1,9 +1,9 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
-
3
- var _chunkHX7NWRCDjs = require('./chunk-HX7NWRCD.js');
4
- require('./chunk-UGBGYVBH.js');
5
- require('./chunk-OQILYQDO.js');
6
- require('./chunk-W65LBPLT.js');
7
-
8
-
9
- exports.InjectedConnector = _chunkHX7NWRCDjs.InjectedConnector;
1
+ import {
2
+ InjectedConnector
3
+ } from "./chunk-HX7NWRCD.js";
4
+ import "./chunk-UGBGYVBH.js";
5
+ import "./chunk-OQILYQDO.js";
6
+ import "./chunk-W65LBPLT.js";
7
+ export {
8
+ InjectedConnector
9
+ };