@wagmi/connectors 0.3.5 → 0.3.6-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
  }
@@ -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 { goerli, mainnet } from "@wagmi/core/chains";
32
- import { default as EventEmitter } from "eventemitter3";
33
- var Connector = class extends EventEmitter {
31
+ var _chains = require('@wagmi/core/chains');
32
+ var _eventemitter3 = require('eventemitter3'); var _eventemitter32 = _interopRequireDefault(_eventemitter3);
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();
@@ -42,7 +42,7 @@ var Connector = class extends EventEmitter {
42
42
  this.options = options;
43
43
  }
44
44
  getBlockExplorerUrls(chain) {
45
- const { default: blockExplorer, ...blockExplorers } = chain.blockExplorers ?? {};
45
+ const { default: blockExplorer, ...blockExplorers } = _nullishCoalesce(chain.blockExplorers, () => ( {}));
46
46
  if (blockExplorer)
47
47
  return [
48
48
  blockExplorer.url,
@@ -54,11 +54,11 @@ var Connector = class extends EventEmitter {
54
54
  }
55
55
  };
56
56
 
57
- export {
58
- __publicField,
59
- __privateGet,
60
- __privateAdd,
61
- __privateSet,
62
- __privateMethod,
63
- Connector
64
- };
57
+
58
+
59
+
60
+
61
+
62
+
63
+
64
+ exports.__publicField = __publicField; exports.__privateGet = __privateGet; exports.__privateAdd = __privateAdd; exports.__privateSet = __privateSet; exports.__privateMethod = __privateMethod; exports.Connector = Connector;
@@ -1,24 +1,24 @@
1
- import {
2
- Connector,
3
- __privateAdd,
4
- __privateGet,
5
- __privateSet,
6
- __publicField
7
- } from "./chunk-5NCTPR6C.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
+
5
+
6
+
7
+ var _chunk5NCTPR6Cjs = require('./chunk-5NCTPR6C.js');
8
8
 
9
9
  // src/injected.ts
10
- import {
11
- AddChainError,
12
- ChainNotConfiguredError,
13
- ConnectorNotFoundError,
14
- ResourceUnavailableError,
15
- SwitchChainError,
16
- UserRejectedRequestError,
17
- getClient,
18
- normalizeChainId
19
- } from "@wagmi/core";
20
- import { providers } from "ethers";
21
- import { getAddress, hexValue } from "ethers/lib/utils.js";
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+ var _core = require('@wagmi/core');
20
+ var _ethers = require('ethers');
21
+ var _utilsjs = require('ethers/lib/utils.js');
22
22
 
23
23
  // src/utils/getInjectedName.ts
24
24
  function getInjectedName(ethereum) {
@@ -82,7 +82,7 @@ function getInjectedName(ethereum) {
82
82
  if (provider.isOkxWallet || provider.isOKExWallet)
83
83
  return "OKX Wallet";
84
84
  };
85
- if (ethereum.providers?.length) {
85
+ if (_optionalChain([ethereum, 'access', _ => _.providers, 'optionalAccess', _2 => _2.length])) {
86
86
  const nameSet = /* @__PURE__ */ new Set();
87
87
  let unknownCount = 1;
88
88
  for (const provider of ethereum.providers) {
@@ -96,52 +96,54 @@ function getInjectedName(ethereum) {
96
96
  const names = [...nameSet];
97
97
  if (names.length)
98
98
  return names;
99
- return names[0] ?? "Injected";
99
+ return _nullishCoalesce(names[0], () => ( "Injected"));
100
100
  }
101
- return getName(ethereum) ?? "Injected";
101
+ return _nullishCoalesce(getName(ethereum), () => ( "Injected"));
102
102
  }
103
103
 
104
104
  // src/injected.ts
105
- var _provider, _switchingChains;
106
- var InjectedConnector = class extends Connector {
105
+ var _provider;
106
+ var InjectedConnector = class extends _chunk5NCTPR6Cjs.Connector {
107
107
  constructor({
108
108
  chains,
109
109
  options: options_
110
110
  } = {}) {
111
111
  const options = {
112
112
  shimDisconnect: true,
113
- shimChainChangedDisconnect: true,
114
113
  getProvider: () => typeof window !== "undefined" ? window.ethereum : void 0,
115
114
  ...options_
116
115
  };
117
116
  super({ chains, options });
118
- __publicField(this, "id", "injected");
119
- __publicField(this, "name");
120
- __publicField(this, "ready");
121
- __privateAdd(this, _provider, void 0);
122
- __privateAdd(this, _switchingChains, void 0);
123
- __publicField(this, "shimDisconnectKey", `${this.id}.shimDisconnect`);
124
- __publicField(this, "onAccountsChanged", (accounts) => {
117
+ _chunk5NCTPR6Cjs.__publicField.call(void 0, this, "id", "injected");
118
+ _chunk5NCTPR6Cjs.__publicField.call(void 0, this, "name");
119
+ _chunk5NCTPR6Cjs.__publicField.call(void 0, this, "ready");
120
+ _chunk5NCTPR6Cjs.__privateAdd.call(void 0, this, _provider, void 0);
121
+ _chunk5NCTPR6Cjs.__publicField.call(void 0, this, "shimDisconnectKey", `${this.id}.shimDisconnect`);
122
+ _chunk5NCTPR6Cjs.__publicField.call(void 0, this, "onAccountsChanged", (accounts) => {
125
123
  if (accounts.length === 0)
126
124
  this.emit("disconnect");
127
125
  else
128
126
  this.emit("change", {
129
- account: getAddress(accounts[0])
127
+ account: _utilsjs.getAddress.call(void 0, accounts[0])
130
128
  });
131
129
  });
132
- __publicField(this, "onChainChanged", (chainId) => {
133
- const id = normalizeChainId(chainId);
130
+ _chunk5NCTPR6Cjs.__publicField.call(void 0, this, "onChainChanged", (chainId) => {
131
+ const id = _core.normalizeChainId.call(void 0, chainId);
134
132
  const unsupported = this.isChainUnsupported(id);
135
133
  this.emit("change", { chain: { id, unsupported } });
136
134
  });
137
- __publicField(this, "onDisconnect", () => {
138
- if (this.options.shimChainChangedDisconnect && __privateGet(this, _switchingChains)) {
139
- __privateSet(this, _switchingChains, false);
140
- return;
135
+ _chunk5NCTPR6Cjs.__publicField.call(void 0, this, "onDisconnect", async (error) => {
136
+ if (error.code === 1013) {
137
+ const provider = await this.getProvider();
138
+ if (provider) {
139
+ const isAuthorized = await this.getAccount();
140
+ if (isAuthorized)
141
+ return;
142
+ }
141
143
  }
142
144
  this.emit("disconnect");
143
145
  if (this.options.shimDisconnect)
144
- getClient().storage?.removeItem(this.shimDisconnectKey);
146
+ _optionalChain([_core.getClient.call(void 0, ), 'access', _3 => _3.storage, 'optionalAccess', _4 => _4.removeItem, 'call', _5 => _5(this.shimDisconnectKey)]);
145
147
  });
146
148
  const provider = options.getProvider();
147
149
  if (typeof options.name === "string")
@@ -164,7 +166,7 @@ var InjectedConnector = class extends Connector {
164
166
  try {
165
167
  const provider = await this.getProvider();
166
168
  if (!provider)
167
- throw new ConnectorNotFoundError();
169
+ throw new (0, _core.ConnectorNotFoundError)();
168
170
  if (provider.on) {
169
171
  provider.on("accountsChanged", this.onAccountsChanged);
170
172
  provider.on("chainChanged", this.onChainChanged);
@@ -174,7 +176,7 @@ var InjectedConnector = class extends Connector {
174
176
  const accounts = await provider.request({
175
177
  method: "eth_requestAccounts"
176
178
  });
177
- const account = getAddress(accounts[0]);
179
+ const account = _utilsjs.getAddress.call(void 0, accounts[0]);
178
180
  let id = await this.getChainId();
179
181
  let unsupported = this.isChainUnsupported(id);
180
182
  if (chainId && id !== chainId) {
@@ -183,77 +185,75 @@ var InjectedConnector = class extends Connector {
183
185
  unsupported = this.isChainUnsupported(id);
184
186
  }
185
187
  if (this.options.shimDisconnect)
186
- getClient().storage?.setItem(this.shimDisconnectKey, true);
188
+ _optionalChain([_core.getClient.call(void 0, ), 'access', _6 => _6.storage, 'optionalAccess', _7 => _7.setItem, 'call', _8 => _8(this.shimDisconnectKey, true)]);
187
189
  return { account, chain: { id, unsupported }, provider };
188
190
  } catch (error) {
189
191
  if (this.isUserRejectedRequestError(error))
190
- throw new UserRejectedRequestError(error);
192
+ throw new (0, _core.UserRejectedRequestError)(error);
191
193
  if (error.code === -32002)
192
- throw new ResourceUnavailableError(error);
194
+ throw new (0, _core.ResourceUnavailableError)(error);
193
195
  throw error;
194
196
  }
195
197
  }
196
198
  async disconnect() {
197
199
  const provider = await this.getProvider();
198
- if (!provider?.removeListener)
200
+ if (!_optionalChain([provider, 'optionalAccess', _9 => _9.removeListener]))
199
201
  return;
200
202
  provider.removeListener("accountsChanged", this.onAccountsChanged);
201
203
  provider.removeListener("chainChanged", this.onChainChanged);
202
204
  provider.removeListener("disconnect", this.onDisconnect);
203
205
  if (this.options.shimDisconnect)
204
- getClient().storage?.removeItem(this.shimDisconnectKey);
206
+ _optionalChain([_core.getClient.call(void 0, ), 'access', _10 => _10.storage, 'optionalAccess', _11 => _11.removeItem, 'call', _12 => _12(this.shimDisconnectKey)]);
205
207
  }
206
208
  async getAccount() {
207
209
  const provider = await this.getProvider();
208
210
  if (!provider)
209
- throw new ConnectorNotFoundError();
211
+ throw new (0, _core.ConnectorNotFoundError)();
210
212
  const accounts = await provider.request({
211
213
  method: "eth_accounts"
212
214
  });
213
- return getAddress(accounts[0]);
215
+ return _utilsjs.getAddress.call(void 0, accounts[0]);
214
216
  }
215
217
  async getChainId() {
216
218
  const provider = await this.getProvider();
217
219
  if (!provider)
218
- throw new ConnectorNotFoundError();
219
- return provider.request({ method: "eth_chainId" }).then(normalizeChainId);
220
+ throw new (0, _core.ConnectorNotFoundError)();
221
+ return provider.request({ method: "eth_chainId" }).then(_core.normalizeChainId);
220
222
  }
221
223
  async getProvider() {
222
224
  const provider = this.options.getProvider();
223
225
  if (provider)
224
- __privateSet(this, _provider, provider);
225
- return __privateGet(this, _provider);
226
+ _chunk5NCTPR6Cjs.__privateSet.call(void 0, this, _provider, provider);
227
+ return _chunk5NCTPR6Cjs.__privateGet.call(void 0, this, _provider);
226
228
  }
227
229
  async getSigner({ chainId } = {}) {
228
230
  const [provider, account] = await Promise.all([
229
231
  this.getProvider(),
230
232
  this.getAccount()
231
233
  ]);
232
- return new providers.Web3Provider(
234
+ return new _ethers.providers.Web3Provider(
233
235
  provider,
234
236
  chainId
235
237
  ).getSigner(account);
236
238
  }
237
239
  async isAuthorized() {
238
240
  try {
239
- if (this.options.shimDisconnect && !getClient().storage?.getItem(this.shimDisconnectKey))
241
+ if (this.options.shimDisconnect && !_optionalChain([_core.getClient.call(void 0, ), 'access', _13 => _13.storage, 'optionalAccess', _14 => _14.getItem, 'call', _15 => _15(this.shimDisconnectKey)]))
240
242
  return false;
241
243
  const provider = await this.getProvider();
242
244
  if (!provider)
243
- throw new ConnectorNotFoundError();
245
+ throw new (0, _core.ConnectorNotFoundError)();
244
246
  const account = await this.getAccount();
245
247
  return !!account;
246
- } catch {
248
+ } catch (e) {
247
249
  return false;
248
250
  }
249
251
  }
250
252
  async switchChain(chainId) {
251
- if (this.options.shimChainChangedDisconnect)
252
- __privateSet(this, _switchingChains, true);
253
253
  const provider = await this.getProvider();
254
254
  if (!provider)
255
- throw new ConnectorNotFoundError();
256
- const id = hexValue(chainId);
255
+ throw new (0, _core.ConnectorNotFoundError)();
256
+ const id = _utilsjs.hexValue.call(void 0, chainId);
257
257
  try {
258
258
  await Promise.all([
259
259
  provider.request({
@@ -262,23 +262,23 @@ var InjectedConnector = class extends Connector {
262
262
  }),
263
263
  new Promise(
264
264
  (res) => this.on("change", ({ chain }) => {
265
- if (chain?.id === chainId)
265
+ if (_optionalChain([chain, 'optionalAccess', _16 => _16.id]) === chainId)
266
266
  res();
267
267
  })
268
268
  )
269
269
  ]);
270
- return this.chains.find((x) => x.id === chainId) ?? {
270
+ return _nullishCoalesce(this.chains.find((x) => x.id === chainId), () => ( {
271
271
  id: chainId,
272
272
  name: `Chain ${id}`,
273
273
  network: `${id}`,
274
274
  nativeCurrency: { name: "Ether", decimals: 18, symbol: "ETH" },
275
275
  rpcUrls: { default: { http: [""] }, public: { http: [""] } }
276
- };
276
+ }));
277
277
  } catch (error) {
278
278
  const chain = this.chains.find((x) => x.id === chainId);
279
279
  if (!chain)
280
- throw new ChainNotConfiguredError({ chainId, connectorId: this.id });
281
- if (error.code === 4902 || error?.data?.originalError?.code === 4902) {
280
+ throw new (0, _core.ChainNotConfiguredError)({ chainId, connectorId: this.id });
281
+ if (error.code === 4902 || _optionalChain([error, 'optionalAccess', _17 => _17.data, 'optionalAccess', _18 => _18.originalError, 'optionalAccess', _19 => _19.code]) === 4902) {
282
282
  try {
283
283
  await provider.request({
284
284
  method: "wallet_addEthereumChain",
@@ -287,7 +287,7 @@ var InjectedConnector = class extends Connector {
287
287
  chainId: id,
288
288
  chainName: chain.name,
289
289
  nativeCurrency: chain.nativeCurrency,
290
- rpcUrls: [chain.rpcUrls.public?.http[0] ?? ""],
290
+ rpcUrls: [_nullishCoalesce(_optionalChain([chain, 'access', _20 => _20.rpcUrls, 'access', _21 => _21.public, 'optionalAccess', _22 => _22.http, 'access', _23 => _23[0]]), () => ( ""))],
291
291
  blockExplorerUrls: this.getBlockExplorerUrls(chain)
292
292
  }
293
293
  ]
@@ -295,13 +295,13 @@ var InjectedConnector = class extends Connector {
295
295
  return chain;
296
296
  } catch (addError) {
297
297
  if (this.isUserRejectedRequestError(addError))
298
- throw new UserRejectedRequestError(error);
299
- throw new AddChainError();
298
+ throw new (0, _core.UserRejectedRequestError)(error);
299
+ throw new (0, _core.AddChainError)();
300
300
  }
301
301
  }
302
302
  if (this.isUserRejectedRequestError(error))
303
- throw new UserRejectedRequestError(error);
304
- throw new SwitchChainError(error);
303
+ throw new (0, _core.UserRejectedRequestError)(error);
304
+ throw new (0, _core.SwitchChainError)(error);
305
305
  }
306
306
  }
307
307
  async watchAsset({
@@ -312,7 +312,7 @@ var InjectedConnector = class extends Connector {
312
312
  }) {
313
313
  const provider = await this.getProvider();
314
314
  if (!provider)
315
- throw new ConnectorNotFoundError();
315
+ throw new (0, _core.ConnectorNotFoundError)();
316
316
  return provider.request({
317
317
  method: "wallet_watchAsset",
318
318
  params: {
@@ -331,8 +331,7 @@ var InjectedConnector = class extends Connector {
331
331
  }
332
332
  };
333
333
  _provider = new WeakMap();
334
- _switchingChains = new WeakMap();
335
334
 
336
- export {
337
- InjectedConnector
338
- };
335
+
336
+
337
+ exports.InjectedConnector = InjectedConnector;
@@ -1,24 +1,24 @@
1
- import {
2
- Connector,
3
- __privateAdd,
4
- __privateGet,
5
- __privateMethod,
6
- __privateSet,
7
- __publicField
8
- } from "./chunk-5NCTPR6C.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
+
5
+
6
+
7
+
8
+ var _chunk5NCTPR6Cjs = require('./chunk-5NCTPR6C.js');
9
9
 
10
10
  // src/coinbaseWallet.ts
11
- import {
12
- AddChainError,
13
- ChainNotConfiguredError,
14
- SwitchChainError,
15
- UserRejectedRequestError,
16
- normalizeChainId
17
- } from "@wagmi/core";
18
- import { providers } from "ethers";
19
- import { getAddress, hexValue } from "ethers/lib/utils.js";
11
+
12
+
13
+
14
+
15
+
16
+
17
+ var _core = require('@wagmi/core');
18
+ var _ethers = require('ethers');
19
+ var _utilsjs = require('ethers/lib/utils.js');
20
20
  var _client, _provider, _isUserRejectedRequestError, isUserRejectedRequestError_fn;
21
- var CoinbaseWalletConnector = class extends Connector {
21
+ var CoinbaseWalletConnector = class extends _chunk5NCTPR6Cjs.Connector {
22
22
  constructor({ chains, options }) {
23
23
  super({
24
24
  chains,
@@ -27,24 +27,24 @@ var CoinbaseWalletConnector = class extends Connector {
27
27
  ...options
28
28
  }
29
29
  });
30
- __privateAdd(this, _isUserRejectedRequestError);
31
- __publicField(this, "id", "coinbaseWallet");
32
- __publicField(this, "name", "Coinbase Wallet");
33
- __publicField(this, "ready", true);
34
- __privateAdd(this, _client, void 0);
35
- __privateAdd(this, _provider, void 0);
36
- __publicField(this, "onAccountsChanged", (accounts) => {
30
+ _chunk5NCTPR6Cjs.__privateAdd.call(void 0, this, _isUserRejectedRequestError);
31
+ _chunk5NCTPR6Cjs.__publicField.call(void 0, this, "id", "coinbaseWallet");
32
+ _chunk5NCTPR6Cjs.__publicField.call(void 0, this, "name", "Coinbase Wallet");
33
+ _chunk5NCTPR6Cjs.__publicField.call(void 0, this, "ready", true);
34
+ _chunk5NCTPR6Cjs.__privateAdd.call(void 0, this, _client, void 0);
35
+ _chunk5NCTPR6Cjs.__privateAdd.call(void 0, this, _provider, void 0);
36
+ _chunk5NCTPR6Cjs.__publicField.call(void 0, this, "onAccountsChanged", (accounts) => {
37
37
  if (accounts.length === 0)
38
38
  this.emit("disconnect");
39
39
  else
40
- this.emit("change", { account: getAddress(accounts[0]) });
40
+ this.emit("change", { account: _utilsjs.getAddress.call(void 0, accounts[0]) });
41
41
  });
42
- __publicField(this, "onChainChanged", (chainId) => {
43
- const id = normalizeChainId(chainId);
42
+ _chunk5NCTPR6Cjs.__publicField.call(void 0, this, "onChainChanged", (chainId) => {
43
+ const id = _core.normalizeChainId.call(void 0, chainId);
44
44
  const unsupported = this.isChainUnsupported(id);
45
45
  this.emit("change", { chain: { id, unsupported } });
46
46
  });
47
- __publicField(this, "onDisconnect", () => {
47
+ _chunk5NCTPR6Cjs.__publicField.call(void 0, this, "onDisconnect", () => {
48
48
  this.emit("disconnect");
49
49
  });
50
50
  }
@@ -56,7 +56,7 @@ var CoinbaseWalletConnector = class extends Connector {
56
56
  provider.on("disconnect", this.onDisconnect);
57
57
  this.emit("message", { type: "connecting" });
58
58
  const accounts = await provider.enable();
59
- const account = getAddress(accounts[0]);
59
+ const account = _utilsjs.getAddress.call(void 0, accounts[0]);
60
60
  let id = await this.getChainId();
61
61
  let unsupported = this.isChainUnsupported(id);
62
62
  if (chainId && id !== chainId) {
@@ -67,7 +67,7 @@ var CoinbaseWalletConnector = class extends Connector {
67
67
  return {
68
68
  account,
69
69
  chain: { id, unsupported },
70
- provider: new providers.Web3Provider(
70
+ provider: new _ethers.providers.Web3Provider(
71
71
  provider
72
72
  )
73
73
  };
@@ -75,12 +75,12 @@ var CoinbaseWalletConnector = class extends Connector {
75
75
  if (/(user closed modal|accounts received is empty)/i.test(
76
76
  error.message
77
77
  ))
78
- throw new UserRejectedRequestError(error);
78
+ throw new (0, _core.UserRejectedRequestError)(error);
79
79
  throw error;
80
80
  }
81
81
  }
82
82
  async disconnect() {
83
- if (!__privateGet(this, _provider))
83
+ if (!_chunk5NCTPR6Cjs.__privateGet.call(void 0, this, _provider))
84
84
  return;
85
85
  const provider = await this.getProvider();
86
86
  provider.removeListener("accountsChanged", this.onAccountsChanged);
@@ -94,39 +94,39 @@ var CoinbaseWalletConnector = class extends Connector {
94
94
  const accounts = await provider.request({
95
95
  method: "eth_accounts"
96
96
  });
97
- return getAddress(accounts[0]);
97
+ return _utilsjs.getAddress.call(void 0, accounts[0]);
98
98
  }
99
99
  async getChainId() {
100
100
  const provider = await this.getProvider();
101
- const chainId = normalizeChainId(provider.chainId);
101
+ const chainId = _core.normalizeChainId.call(void 0, provider.chainId);
102
102
  return chainId;
103
103
  }
104
104
  async getProvider() {
105
- if (!__privateGet(this, _provider)) {
106
- let CoinbaseWalletSDK = (await import("@coinbase/wallet-sdk")).default;
105
+ if (!_chunk5NCTPR6Cjs.__privateGet.call(void 0, this, _provider)) {
106
+ let CoinbaseWalletSDK = (await Promise.resolve().then(() => require("@coinbase/wallet-sdk"))).default;
107
107
  if (typeof CoinbaseWalletSDK !== "function" && typeof CoinbaseWalletSDK.default === "function")
108
108
  CoinbaseWalletSDK = CoinbaseWalletSDK.default;
109
- __privateSet(this, _client, new CoinbaseWalletSDK(this.options));
109
+ _chunk5NCTPR6Cjs.__privateSet.call(void 0, this, _client, new CoinbaseWalletSDK(this.options));
110
110
  class WalletProvider {
111
111
  }
112
112
  class Client {
113
113
  }
114
- const walletExtensionChainId = __privateGet(this, _client).walletExtension?.getChainId();
114
+ const walletExtensionChainId = _optionalChain([_chunk5NCTPR6Cjs.__privateGet.call(void 0, this, _client), 'access', _ => _.walletExtension, 'optionalAccess', _2 => _2.getChainId, 'call', _3 => _3()]);
115
115
  const chain = this.chains.find(
116
116
  (chain2) => this.options.chainId ? chain2.id === this.options.chainId : chain2.id === walletExtensionChainId
117
117
  ) || this.chains[0];
118
- const chainId = this.options.chainId || chain?.id;
119
- const jsonRpcUrl = this.options.jsonRpcUrl || chain?.rpcUrls.default.http[0];
120
- __privateSet(this, _provider, __privateGet(this, _client).makeWeb3Provider(jsonRpcUrl, chainId));
118
+ const chainId = this.options.chainId || _optionalChain([chain, 'optionalAccess', _4 => _4.id]);
119
+ const jsonRpcUrl = this.options.jsonRpcUrl || _optionalChain([chain, 'optionalAccess', _5 => _5.rpcUrls, 'access', _6 => _6.default, 'access', _7 => _7.http, 'access', _8 => _8[0]]);
120
+ _chunk5NCTPR6Cjs.__privateSet.call(void 0, this, _provider, _chunk5NCTPR6Cjs.__privateGet.call(void 0, this, _client).makeWeb3Provider(jsonRpcUrl, chainId));
121
121
  }
122
- return __privateGet(this, _provider);
122
+ return _chunk5NCTPR6Cjs.__privateGet.call(void 0, this, _provider);
123
123
  }
124
124
  async getSigner({ chainId } = {}) {
125
125
  const [provider, account] = await Promise.all([
126
126
  this.getProvider(),
127
127
  this.getAccount()
128
128
  ]);
129
- return new providers.Web3Provider(
129
+ return new _ethers.providers.Web3Provider(
130
130
  provider,
131
131
  chainId
132
132
  ).getSigner(account);
@@ -135,29 +135,29 @@ var CoinbaseWalletConnector = class extends Connector {
135
135
  try {
136
136
  const account = await this.getAccount();
137
137
  return !!account;
138
- } catch {
138
+ } catch (e) {
139
139
  return false;
140
140
  }
141
141
  }
142
142
  async switchChain(chainId) {
143
143
  const provider = await this.getProvider();
144
- const id = hexValue(chainId);
144
+ const id = _utilsjs.hexValue.call(void 0, chainId);
145
145
  try {
146
146
  await provider.request({
147
147
  method: "wallet_switchEthereumChain",
148
148
  params: [{ chainId: id }]
149
149
  });
150
- return this.chains.find((x) => x.id === chainId) ?? {
150
+ return _nullishCoalesce(this.chains.find((x) => x.id === chainId), () => ( {
151
151
  id: chainId,
152
152
  name: `Chain ${id}`,
153
153
  network: `${id}`,
154
154
  nativeCurrency: { name: "Ether", decimals: 18, symbol: "ETH" },
155
155
  rpcUrls: { default: { http: [""] }, public: { http: [""] } }
156
- };
156
+ }));
157
157
  } catch (error) {
158
158
  const chain = this.chains.find((x) => x.id === chainId);
159
159
  if (!chain)
160
- throw new ChainNotConfiguredError({ chainId, connectorId: this.id });
160
+ throw new (0, _core.ChainNotConfiguredError)({ chainId, connectorId: this.id });
161
161
  if (error.code === 4902) {
162
162
  try {
163
163
  await provider.request({
@@ -167,21 +167,21 @@ var CoinbaseWalletConnector = class extends Connector {
167
167
  chainId: id,
168
168
  chainName: chain.name,
169
169
  nativeCurrency: chain.nativeCurrency,
170
- rpcUrls: [chain.rpcUrls.public?.http[0] ?? ""],
170
+ rpcUrls: [_nullishCoalesce(_optionalChain([chain, 'access', _9 => _9.rpcUrls, 'access', _10 => _10.public, 'optionalAccess', _11 => _11.http, 'access', _12 => _12[0]]), () => ( ""))],
171
171
  blockExplorerUrls: this.getBlockExplorerUrls(chain)
172
172
  }
173
173
  ]
174
174
  });
175
175
  return chain;
176
176
  } catch (addError) {
177
- if (__privateMethod(this, _isUserRejectedRequestError, isUserRejectedRequestError_fn).call(this, addError))
178
- throw new UserRejectedRequestError(addError);
179
- throw new AddChainError();
177
+ if (_chunk5NCTPR6Cjs.__privateMethod.call(void 0, this, _isUserRejectedRequestError, isUserRejectedRequestError_fn).call(this, addError))
178
+ throw new (0, _core.UserRejectedRequestError)(addError);
179
+ throw new (0, _core.AddChainError)();
180
180
  }
181
181
  }
182
- if (__privateMethod(this, _isUserRejectedRequestError, isUserRejectedRequestError_fn).call(this, error))
183
- throw new UserRejectedRequestError(error);
184
- throw new SwitchChainError(error);
182
+ if (_chunk5NCTPR6Cjs.__privateMethod.call(void 0, this, _isUserRejectedRequestError, isUserRejectedRequestError_fn).call(this, error))
183
+ throw new (0, _core.UserRejectedRequestError)(error);
184
+ throw new (0, _core.SwitchChainError)(error);
185
185
  }
186
186
  }
187
187
  async watchAsset({
@@ -211,6 +211,6 @@ _isUserRejectedRequestError = new WeakSet();
211
211
  isUserRejectedRequestError_fn = function(error) {
212
212
  return /(user rejected)/i.test(error.message);
213
213
  };
214
- export {
215
- CoinbaseWalletConnector
216
- };
214
+
215
+
216
+ exports.CoinbaseWalletConnector = CoinbaseWalletConnector;
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
- import {
2
- Connector
3
- } from "./chunk-5NCTPR6C.js";
4
- export {
5
- Connector
6
- };
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _chunk5NCTPR6Cjs = require('./chunk-5NCTPR6C.js');
4
+
5
+
6
+ exports.Connector = _chunk5NCTPR6Cjs.Connector;
@@ -16,11 +16,6 @@ type InjectedConnectorOptions = {
16
16
  * () => typeof window !== 'undefined' ? window.ethereum : undefined
17
17
  */
18
18
  getProvider?: () => Ethereum | undefined;
19
- /**
20
- * MetaMask 10.9.3 emits disconnect event when chain is changed.
21
- * This flag prevents the `"disconnect"` event from being emitted upon switching chains. See [GitHub issue](https://github.com/MetaMask/metamask-extension/issues/13375#issuecomment-1027663334) for more info.
22
- */
23
- shimChainChangedDisconnect?: boolean;
24
19
  /**
25
20
  * MetaMask and other injected providers do not support programmatic disconnect.
26
21
  * This flag simulates the disconnect behavior by keeping track of connection status in storage. See [GitHub issue](https://github.com/MetaMask/metamask-extension/issues/10353) for more info.
@@ -66,7 +61,7 @@ declare class InjectedConnector extends Connector<Ethereum | undefined, Connecto
66
61
  }): Promise<boolean>;
67
62
  protected onAccountsChanged: (accounts: string[]) => void;
68
63
  protected onChainChanged: (chainId: number | string) => void;
69
- protected onDisconnect: () => void;
64
+ protected onDisconnect: (error: Error) => Promise<void>;
70
65
  protected isUserRejectedRequestError(error: unknown): boolean;
71
66
  }
72
67