@wagmi/connectors 2.3.0-cjs → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,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
- var _chunkZCAPXGBXjs = require('./chunk-ZCAPXGBX.js');
4
-
5
-
6
- var _chunkOQILYQDOjs = require('./chunk-OQILYQDO.js');
7
-
8
-
9
-
10
-
11
-
12
-
13
- var _chunkQYMCVNHTjs = require('./chunk-QYMCVNHT.js');
1
+ import {
2
+ ChainNotConfiguredForConnectorError
3
+ } from "./chunk-ZCAPXGBX.js";
4
+ import {
5
+ normalizeChainId
6
+ } from "./chunk-OQILYQDO.js";
7
+ import {
8
+ Connector,
9
+ __privateAdd,
10
+ __privateGet,
11
+ __privateSet,
12
+ __publicField
13
+ } from "./chunk-QYMCVNHT.js";
14
14
 
15
15
  // src/coinbaseWallet.ts
16
-
17
-
18
-
19
-
20
-
21
-
22
-
23
- var _viem = require('viem');
16
+ import {
17
+ SwitchChainError,
18
+ UserRejectedRequestError,
19
+ createWalletClient,
20
+ custom,
21
+ getAddress,
22
+ numberToHex
23
+ } from "viem";
24
24
  var _client, _provider;
25
- var CoinbaseWalletConnector = class extends _chunkQYMCVNHTjs.Connector {
25
+ var CoinbaseWalletConnector = class extends Connector {
26
26
  constructor({ chains, options }) {
27
27
  super({
28
28
  chains,
@@ -31,23 +31,23 @@ var CoinbaseWalletConnector = class extends _chunkQYMCVNHTjs.Connector {
31
31
  ...options
32
32
  }
33
33
  });
34
- _chunkQYMCVNHTjs.__publicField.call(void 0, this, "id", "coinbaseWallet");
35
- _chunkQYMCVNHTjs.__publicField.call(void 0, this, "name", "Coinbase Wallet");
36
- _chunkQYMCVNHTjs.__publicField.call(void 0, this, "ready", true);
37
- _chunkQYMCVNHTjs.__privateAdd.call(void 0, this, _client, void 0);
38
- _chunkQYMCVNHTjs.__privateAdd.call(void 0, this, _provider, void 0);
39
- _chunkQYMCVNHTjs.__publicField.call(void 0, this, "onAccountsChanged", (accounts) => {
34
+ __publicField(this, "id", "coinbaseWallet");
35
+ __publicField(this, "name", "Coinbase Wallet");
36
+ __publicField(this, "ready", true);
37
+ __privateAdd(this, _client, void 0);
38
+ __privateAdd(this, _provider, void 0);
39
+ __publicField(this, "onAccountsChanged", (accounts) => {
40
40
  if (accounts.length === 0)
41
41
  this.emit("disconnect");
42
42
  else
43
- this.emit("change", { account: _viem.getAddress.call(void 0, accounts[0]) });
43
+ this.emit("change", { account: getAddress(accounts[0]) });
44
44
  });
45
- _chunkQYMCVNHTjs.__publicField.call(void 0, this, "onChainChanged", (chainId) => {
46
- const id = _chunkOQILYQDOjs.normalizeChainId.call(void 0, chainId);
45
+ __publicField(this, "onChainChanged", (chainId) => {
46
+ const id = normalizeChainId(chainId);
47
47
  const unsupported = this.isChainUnsupported(id);
48
48
  this.emit("change", { chain: { id, unsupported } });
49
49
  });
50
- _chunkQYMCVNHTjs.__publicField.call(void 0, this, "onDisconnect", () => {
50
+ __publicField(this, "onDisconnect", () => {
51
51
  this.emit("disconnect");
52
52
  });
53
53
  }
@@ -59,7 +59,7 @@ var CoinbaseWalletConnector = class extends _chunkQYMCVNHTjs.Connector {
59
59
  provider.on("disconnect", this.onDisconnect);
60
60
  this.emit("message", { type: "connecting" });
61
61
  const accounts = await provider.enable();
62
- const account = _viem.getAddress.call(void 0, accounts[0]);
62
+ const account = getAddress(accounts[0]);
63
63
  let id = await this.getChainId();
64
64
  let unsupported = this.isChainUnsupported(id);
65
65
  if (chainId && id !== chainId) {
@@ -75,12 +75,12 @@ var CoinbaseWalletConnector = class extends _chunkQYMCVNHTjs.Connector {
75
75
  if (/(user closed modal|accounts received is empty)/i.test(
76
76
  error.message
77
77
  ))
78
- throw new (0, _viem.UserRejectedRequestError)(error);
78
+ throw new UserRejectedRequestError(error);
79
79
  throw error;
80
80
  }
81
81
  }
82
82
  async disconnect() {
83
- if (!_chunkQYMCVNHTjs.__privateGet.call(void 0, this, _provider))
83
+ if (!__privateGet(this, _provider))
84
84
  return;
85
85
  const provider = await this.getProvider();
86
86
  provider.removeListener("accountsChanged", this.onAccountsChanged);
@@ -94,32 +94,32 @@ var CoinbaseWalletConnector = class extends _chunkQYMCVNHTjs.Connector {
94
94
  const accounts = await provider.request({
95
95
  method: "eth_accounts"
96
96
  });
97
- return _viem.getAddress.call(void 0, accounts[0]);
97
+ return getAddress(accounts[0]);
98
98
  }
99
99
  async getChainId() {
100
100
  const provider = await this.getProvider();
101
- const chainId = _chunkOQILYQDOjs.normalizeChainId.call(void 0, provider.chainId);
101
+ const chainId = normalizeChainId(provider.chainId);
102
102
  return chainId;
103
103
  }
104
104
  async getProvider() {
105
- if (!_chunkQYMCVNHTjs.__privateGet.call(void 0, this, _provider)) {
106
- let CoinbaseWalletSDK = (await Promise.resolve().then(() => require("@coinbase/wallet-sdk"))).default;
105
+ if (!__privateGet(this, _provider)) {
106
+ let CoinbaseWalletSDK = (await import("@coinbase/wallet-sdk")).default;
107
107
  if (typeof CoinbaseWalletSDK !== "function" && typeof CoinbaseWalletSDK.default === "function")
108
108
  CoinbaseWalletSDK = CoinbaseWalletSDK.default;
109
- _chunkQYMCVNHTjs.__privateSet.call(void 0, this, _client, new CoinbaseWalletSDK(this.options));
109
+ __privateSet(this, _client, new CoinbaseWalletSDK(this.options));
110
110
  class WalletProvider {
111
111
  }
112
112
  class Client {
113
113
  }
114
- const walletExtensionChainId = _optionalChain([_chunkQYMCVNHTjs.__privateGet.call(void 0, this, _client), 'access', _ => _.walletExtension, 'optionalAccess', _2 => _2.getChainId, 'call', _3 => _3()]);
114
+ const walletExtensionChainId = __privateGet(this, _client).walletExtension?.getChainId();
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 || _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
- _chunkQYMCVNHTjs.__privateSet.call(void 0, this, _provider, _chunkQYMCVNHTjs.__privateGet.call(void 0, this, _client).makeWeb3Provider(jsonRpcUrl, chainId));
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));
121
121
  }
122
- return _chunkQYMCVNHTjs.__privateGet.call(void 0, this, _provider);
122
+ return __privateGet(this, _provider);
123
123
  }
124
124
  async getWalletClient({ chainId } = {}) {
125
125
  const [provider, account] = await Promise.all([
@@ -129,39 +129,39 @@ var CoinbaseWalletConnector = class extends _chunkQYMCVNHTjs.Connector {
129
129
  const chain = this.chains.find((x) => x.id === chainId);
130
130
  if (!provider)
131
131
  throw new Error("provider is required.");
132
- return _viem.createWalletClient.call(void 0, {
132
+ return createWalletClient({
133
133
  account,
134
134
  chain,
135
- transport: _viem.custom.call(void 0, provider)
135
+ transport: custom(provider)
136
136
  });
137
137
  }
138
138
  async isAuthorized() {
139
139
  try {
140
140
  const account = await this.getAccount();
141
141
  return !!account;
142
- } catch (e) {
142
+ } catch {
143
143
  return false;
144
144
  }
145
145
  }
146
146
  async switchChain(chainId) {
147
147
  const provider = await this.getProvider();
148
- const id = _viem.numberToHex.call(void 0, chainId);
148
+ const id = numberToHex(chainId);
149
149
  try {
150
150
  await provider.request({
151
151
  method: "wallet_switchEthereumChain",
152
152
  params: [{ chainId: id }]
153
153
  });
154
- return _nullishCoalesce(this.chains.find((x) => x.id === chainId), () => ( {
154
+ return this.chains.find((x) => x.id === chainId) ?? {
155
155
  id: chainId,
156
156
  name: `Chain ${id}`,
157
157
  network: `${id}`,
158
158
  nativeCurrency: { name: "Ether", decimals: 18, symbol: "ETH" },
159
159
  rpcUrls: { default: { http: [""] }, public: { http: [""] } }
160
- }));
160
+ };
161
161
  } catch (error) {
162
162
  const chain = this.chains.find((x) => x.id === chainId);
163
163
  if (!chain)
164
- throw new (0, _chunkZCAPXGBXjs.ChainNotConfiguredForConnectorError)({
164
+ throw new ChainNotConfiguredForConnectorError({
165
165
  chainId,
166
166
  connectorId: this.id
167
167
  });
@@ -174,17 +174,17 @@ var CoinbaseWalletConnector = class extends _chunkQYMCVNHTjs.Connector {
174
174
  chainId: id,
175
175
  chainName: chain.name,
176
176
  nativeCurrency: chain.nativeCurrency,
177
- rpcUrls: [_nullishCoalesce(_optionalChain([chain, 'access', _9 => _9.rpcUrls, 'access', _10 => _10.public, 'optionalAccess', _11 => _11.http, 'access', _12 => _12[0]]), () => ( ""))],
177
+ rpcUrls: [chain.rpcUrls.public?.http[0] ?? ""],
178
178
  blockExplorerUrls: this.getBlockExplorerUrls(chain)
179
179
  }
180
180
  ]
181
181
  });
182
182
  return chain;
183
183
  } catch (error2) {
184
- throw new (0, _viem.UserRejectedRequestError)(error2);
184
+ throw new UserRejectedRequestError(error2);
185
185
  }
186
186
  }
187
- throw new (0, _viem.SwitchChainError)(error);
187
+ throw new SwitchChainError(error);
188
188
  }
189
189
  }
190
190
  async watchAsset({
@@ -210,6 +210,6 @@ var CoinbaseWalletConnector = class extends _chunkQYMCVNHTjs.Connector {
210
210
  };
211
211
  _client = new WeakMap();
212
212
  _provider = new WeakMap();
213
-
214
-
215
- exports.CoinbaseWalletConnector = CoinbaseWalletConnector;
213
+ export {
214
+ CoinbaseWalletConnector
215
+ };
package/dist/index.js CHANGED
@@ -1,12 +1,12 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
-
3
-
4
- var _chunkZCAPXGBXjs = require('./chunk-ZCAPXGBX.js');
5
-
6
-
7
- var _chunkQYMCVNHTjs = require('./chunk-QYMCVNHT.js');
8
-
9
-
10
-
11
-
12
- exports.ChainNotConfiguredForConnectorError = _chunkZCAPXGBXjs.ChainNotConfiguredForConnectorError; exports.Connector = _chunkQYMCVNHTjs.Connector; exports.ConnectorNotFoundError = _chunkZCAPXGBXjs.ConnectorNotFoundError;
1
+ import {
2
+ ChainNotConfiguredForConnectorError,
3
+ ConnectorNotFoundError
4
+ } from "./chunk-ZCAPXGBX.js";
5
+ import {
6
+ Connector
7
+ } from "./chunk-QYMCVNHT.js";
8
+ export {
9
+ ChainNotConfiguredForConnectorError,
10
+ Connector,
11
+ ConnectorNotFoundError
12
+ };
package/dist/injected.js CHANGED
@@ -1,9 +1,9 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
-
3
- var _chunk4BSCIAHYjs = require('./chunk-4BSCIAHY.js');
4
- require('./chunk-ZCAPXGBX.js');
5
- require('./chunk-OQILYQDO.js');
6
- require('./chunk-QYMCVNHT.js');
7
-
8
-
9
- exports.InjectedConnector = _chunk4BSCIAHYjs.InjectedConnector;
1
+ import {
2
+ InjectedConnector
3
+ } from "./chunk-4BSCIAHY.js";
4
+ import "./chunk-ZCAPXGBX.js";
5
+ import "./chunk-OQILYQDO.js";
6
+ import "./chunk-QYMCVNHT.js";
7
+ export {
8
+ InjectedConnector
9
+ };
package/dist/ledger.js CHANGED
@@ -1,52 +1,52 @@
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
- var _chunkOQILYQDOjs = require('./chunk-OQILYQDO.js');
4
-
5
-
6
-
7
-
8
-
9
-
10
-
11
- var _chunkQYMCVNHTjs = require('./chunk-QYMCVNHT.js');
1
+ import {
2
+ normalizeChainId
3
+ } from "./chunk-OQILYQDO.js";
4
+ import {
5
+ Connector,
6
+ __privateAdd,
7
+ __privateGet,
8
+ __privateMethod,
9
+ __privateSet,
10
+ __publicField
11
+ } from "./chunk-QYMCVNHT.js";
12
12
 
13
13
  // src/ledger.ts
14
-
15
-
16
-
17
- var _connectkitloader = require('@ledgerhq/connect-kit-loader');
18
-
19
-
20
-
21
-
22
-
23
-
24
-
25
- var _viem = require('viem');
14
+ import {
15
+ SupportedProviders,
16
+ loadConnectKit
17
+ } from "@ledgerhq/connect-kit-loader";
18
+ import {
19
+ SwitchChainError,
20
+ UserRejectedRequestError,
21
+ createWalletClient,
22
+ custom,
23
+ getAddress,
24
+ numberToHex
25
+ } from "viem";
26
26
  var _provider, _switchChain, switchChain_fn;
27
- var LedgerConnector = class extends _chunkQYMCVNHTjs.Connector {
27
+ var LedgerConnector = class extends Connector {
28
28
  constructor({
29
29
  chains,
30
30
  options = { enableDebugLogs: false }
31
31
  } = {}) {
32
32
  super({ chains, options });
33
- _chunkQYMCVNHTjs.__privateAdd.call(void 0, this, _switchChain);
34
- _chunkQYMCVNHTjs.__publicField.call(void 0, this, "id", "ledger");
35
- _chunkQYMCVNHTjs.__publicField.call(void 0, this, "name", "Ledger");
36
- _chunkQYMCVNHTjs.__publicField.call(void 0, this, "ready", true);
37
- _chunkQYMCVNHTjs.__privateAdd.call(void 0, this, _provider, void 0);
38
- _chunkQYMCVNHTjs.__publicField.call(void 0, this, "onAccountsChanged", (accounts) => {
33
+ __privateAdd(this, _switchChain);
34
+ __publicField(this, "id", "ledger");
35
+ __publicField(this, "name", "Ledger");
36
+ __publicField(this, "ready", true);
37
+ __privateAdd(this, _provider, void 0);
38
+ __publicField(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
- _chunkQYMCVNHTjs.__publicField.call(void 0, this, "onChainChanged", (chainId) => {
45
- const id = _chunkOQILYQDOjs.normalizeChainId.call(void 0, chainId);
44
+ __publicField(this, "onChainChanged", (chainId) => {
45
+ const id = normalizeChainId(chainId);
46
46
  const unsupported = this.isChainUnsupported(id);
47
47
  this.emit("change", { chain: { id, unsupported } });
48
48
  });
49
- _chunkQYMCVNHTjs.__publicField.call(void 0, this, "onDisconnect", () => {
49
+ __publicField(this, "onDisconnect", () => {
50
50
  this.emit("disconnect");
51
51
  });
52
52
  }
@@ -62,17 +62,17 @@ var LedgerConnector = class extends _chunkQYMCVNHTjs.Connector {
62
62
  const accounts = await provider.request({
63
63
  method: "eth_requestAccounts"
64
64
  });
65
- const account = _viem.getAddress.call(void 0, accounts[0]);
65
+ const account = getAddress(accounts[0]);
66
66
  const id = await this.getChainId();
67
67
  const unsupported = this.isChainUnsupported(id);
68
- this.switchChain = _chunkQYMCVNHTjs.__privateMethod.call(void 0, this, _switchChain, switchChain_fn);
68
+ this.switchChain = __privateMethod(this, _switchChain, switchChain_fn);
69
69
  return {
70
70
  account,
71
71
  chain: { id, unsupported }
72
72
  };
73
73
  } catch (error) {
74
74
  if (error.code === 4001) {
75
- throw new (0, _viem.UserRejectedRequestError)(error);
75
+ throw new UserRejectedRequestError(error);
76
76
  }
77
77
  if (error.code === -32002) {
78
78
  throw error instanceof Error ? error : new Error(String(error));
@@ -82,10 +82,10 @@ var LedgerConnector = class extends _chunkQYMCVNHTjs.Connector {
82
82
  }
83
83
  async disconnect() {
84
84
  const provider = await this.getProvider();
85
- if (_optionalChain([provider, 'optionalAccess', _ => _.disconnect])) {
85
+ if (provider?.disconnect) {
86
86
  await provider.disconnect();
87
87
  }
88
- if (_optionalChain([provider, 'optionalAccess', _2 => _2.removeListener])) {
88
+ if (provider?.removeListener) {
89
89
  provider.removeListener("accountsChanged", this.onAccountsChanged);
90
90
  provider.removeListener("chainChanged", this.onChainChanged);
91
91
  provider.removeListener("disconnect", this.onDisconnect);
@@ -97,7 +97,7 @@ var LedgerConnector = class extends _chunkQYMCVNHTjs.Connector {
97
97
  const accounts = await provider.request({
98
98
  method: "eth_accounts"
99
99
  });
100
- const account = _viem.getAddress.call(void 0, accounts[0]);
100
+ const account = getAddress(accounts[0]);
101
101
  return account;
102
102
  }
103
103
  async getChainId() {
@@ -105,13 +105,13 @@ var LedgerConnector = class extends _chunkQYMCVNHTjs.Connector {
105
105
  const chainId = await provider.request({
106
106
  method: "eth_chainId"
107
107
  });
108
- return _chunkOQILYQDOjs.normalizeChainId.call(void 0, chainId);
108
+ return normalizeChainId(chainId);
109
109
  }
110
110
  async getProvider({ chainId, create } = {
111
111
  create: false
112
112
  }) {
113
- if (!_chunkQYMCVNHTjs.__privateGet.call(void 0, this, _provider) || chainId || create) {
114
- const connectKit = await _connectkitloader.loadConnectKit.call(void 0, );
113
+ if (!__privateGet(this, _provider) || chainId || create) {
114
+ const connectKit = await loadConnectKit();
115
115
  if (this.options.enableDebugLogs) {
116
116
  connectKit.enableDebugLogs();
117
117
  }
@@ -124,13 +124,13 @@ var LedgerConnector = class extends _chunkQYMCVNHTjs.Connector {
124
124
  );
125
125
  connectKit.checkSupport({
126
126
  bridge: this.options.bridge,
127
- providerType: _connectkitloader.SupportedProviders.Ethereum,
127
+ providerType: SupportedProviders.Ethereum,
128
128
  chainId: chainId || this.options.chainId,
129
- rpc: { ...rpc, ..._optionalChain([this, 'access', _3 => _3.options, 'optionalAccess', _4 => _4.rpc]) }
129
+ rpc: { ...rpc, ...this.options?.rpc }
130
130
  });
131
- _chunkQYMCVNHTjs.__privateSet.call(void 0, this, _provider, await connectKit.getProvider());
131
+ __privateSet(this, _provider, await connectKit.getProvider());
132
132
  }
133
- return _chunkQYMCVNHTjs.__privateGet.call(void 0, this, _provider);
133
+ return __privateGet(this, _provider);
134
134
  }
135
135
  async getWalletClient({ chainId } = {}) {
136
136
  const [provider, account] = await Promise.all([
@@ -140,17 +140,17 @@ var LedgerConnector = class extends _chunkQYMCVNHTjs.Connector {
140
140
  const chain = this.chains.find((x) => x.id === chainId);
141
141
  if (!provider)
142
142
  throw new Error("provider is required.");
143
- return _viem.createWalletClient.call(void 0, {
143
+ return createWalletClient({
144
144
  account,
145
145
  chain,
146
- transport: _viem.custom.call(void 0, provider)
146
+ transport: custom(provider)
147
147
  });
148
148
  }
149
149
  async isAuthorized() {
150
150
  try {
151
151
  const account = await this.getAccount();
152
152
  return !!account;
153
- } catch (e) {
153
+ } catch {
154
154
  return false;
155
155
  }
156
156
  }
@@ -159,7 +159,7 @@ _provider = new WeakMap();
159
159
  _switchChain = new WeakSet();
160
160
  switchChain_fn = async function(chainId) {
161
161
  const provider = await this.getProvider();
162
- const id = _viem.numberToHex.call(void 0, chainId);
162
+ const id = numberToHex(chainId);
163
163
  try {
164
164
  await Promise.race([
165
165
  provider.request({
@@ -168,25 +168,25 @@ switchChain_fn = async function(chainId) {
168
168
  }),
169
169
  new Promise(
170
170
  (res) => this.on("change", ({ chain }) => {
171
- if (_optionalChain([chain, 'optionalAccess', _5 => _5.id]) === chainId)
171
+ if (chain?.id === chainId)
172
172
  res(chainId);
173
173
  })
174
174
  )
175
175
  ]);
176
- return _nullishCoalesce(this.chains.find((x) => x.id === chainId), () => ( {
176
+ return this.chains.find((x) => x.id === chainId) ?? {
177
177
  id: chainId,
178
178
  name: `Chain ${id}`,
179
179
  network: `${id}`,
180
180
  nativeCurrency: { name: "Ether", decimals: 18, symbol: "ETH" },
181
181
  rpcUrls: { default: { http: [""] }, public: { http: [""] } }
182
- }));
182
+ };
183
183
  } catch (error) {
184
- const message = typeof error === "string" ? error : _optionalChain([error, 'optionalAccess', _6 => _6.message]);
184
+ const message = typeof error === "string" ? error : error?.message;
185
185
  if (/user rejected request/i.test(message))
186
- throw new (0, _viem.UserRejectedRequestError)(error);
187
- throw new (0, _viem.SwitchChainError)(error);
186
+ throw new UserRejectedRequestError(error);
187
+ throw new SwitchChainError(error);
188
188
  }
189
189
  };
190
-
191
-
192
- exports.LedgerConnector = LedgerConnector;
190
+ export {
191
+ LedgerConnector
192
+ };
package/dist/metaMask.js CHANGED
@@ -1,25 +1,25 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); 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 _chunk4BSCIAHYjs = require('./chunk-4BSCIAHY.js');
4
-
5
-
6
- var _chunkZCAPXGBXjs = require('./chunk-ZCAPXGBX.js');
7
- require('./chunk-OQILYQDO.js');
8
-
9
-
10
-
11
-
12
-
13
- var _chunkQYMCVNHTjs = require('./chunk-QYMCVNHT.js');
1
+ import {
2
+ InjectedConnector
3
+ } from "./chunk-4BSCIAHY.js";
4
+ import {
5
+ ConnectorNotFoundError
6
+ } from "./chunk-ZCAPXGBX.js";
7
+ import "./chunk-OQILYQDO.js";
8
+ import {
9
+ __privateAdd,
10
+ __privateGet,
11
+ __privateSet,
12
+ __publicField
13
+ } from "./chunk-QYMCVNHT.js";
14
14
 
15
15
  // src/metaMask.ts
16
-
17
-
18
-
19
-
20
- var _viem = require('viem');
16
+ import {
17
+ ResourceUnavailableRpcError,
18
+ UserRejectedRequestError,
19
+ getAddress
20
+ } from "viem";
21
21
  var _UNSTABLE_shimOnConnectSelectAccount;
22
- var MetaMaskConnector = class extends _chunk4BSCIAHYjs.InjectedConnector {
22
+ var MetaMaskConnector = class extends InjectedConnector {
23
23
  constructor({
24
24
  chains,
25
25
  options: options_
@@ -29,7 +29,7 @@ var MetaMaskConnector = class extends _chunk4BSCIAHYjs.InjectedConnector {
29
29
  shimDisconnect: true,
30
30
  getProvider() {
31
31
  function getReady(ethereum2) {
32
- const isMetaMask = !!_optionalChain([ethereum2, 'optionalAccess', _ => _.isMetaMask]);
32
+ const isMetaMask = !!ethereum2?.isMetaMask;
33
33
  if (!isMetaMask)
34
34
  return;
35
35
  if (ethereum2.isBraveWallet && !ethereum2._events && !ethereum2._state)
@@ -67,23 +67,23 @@ var MetaMaskConnector = class extends _chunk4BSCIAHYjs.InjectedConnector {
67
67
  if (typeof window === "undefined")
68
68
  return;
69
69
  const ethereum = window.ethereum;
70
- if (_optionalChain([ethereum, 'optionalAccess', _2 => _2.providers]))
70
+ if (ethereum?.providers)
71
71
  return ethereum.providers.find(getReady);
72
72
  return getReady(ethereum);
73
73
  },
74
74
  ...options_
75
75
  };
76
76
  super({ chains, options });
77
- _chunkQYMCVNHTjs.__publicField.call(void 0, this, "id", "metaMask");
78
- _chunkQYMCVNHTjs.__publicField.call(void 0, this, "shimDisconnectKey", `${this.id}.shimDisconnect`);
79
- _chunkQYMCVNHTjs.__privateAdd.call(void 0, this, _UNSTABLE_shimOnConnectSelectAccount, void 0);
80
- _chunkQYMCVNHTjs.__privateSet.call(void 0, this, _UNSTABLE_shimOnConnectSelectAccount, options.UNSTABLE_shimOnConnectSelectAccount);
77
+ __publicField(this, "id", "metaMask");
78
+ __publicField(this, "shimDisconnectKey", `${this.id}.shimDisconnect`);
79
+ __privateAdd(this, _UNSTABLE_shimOnConnectSelectAccount, void 0);
80
+ __privateSet(this, _UNSTABLE_shimOnConnectSelectAccount, options.UNSTABLE_shimOnConnectSelectAccount);
81
81
  }
82
82
  async connect({ chainId } = {}) {
83
83
  try {
84
84
  const provider = await this.getProvider();
85
85
  if (!provider)
86
- throw new (0, _chunkZCAPXGBXjs.ConnectorNotFoundError)();
86
+ throw new ConnectorNotFoundError();
87
87
  if (provider.on) {
88
88
  provider.on("accountsChanged", this.onAccountsChanged);
89
89
  provider.on("chainChanged", this.onChainChanged);
@@ -91,7 +91,7 @@ var MetaMaskConnector = class extends _chunk4BSCIAHYjs.InjectedConnector {
91
91
  }
92
92
  this.emit("message", { type: "connecting" });
93
93
  let account = null;
94
- if (_chunkQYMCVNHTjs.__privateGet.call(void 0, this, _UNSTABLE_shimOnConnectSelectAccount) && _optionalChain([this, 'access', _3 => _3.options, 'optionalAccess', _4 => _4.shimDisconnect]) && !_optionalChain([this, 'access', _5 => _5.storage, 'optionalAccess', _6 => _6.getItem, 'call', _7 => _7(this.shimDisconnectKey)])) {
94
+ if (__privateGet(this, _UNSTABLE_shimOnConnectSelectAccount) && this.options?.shimDisconnect && !this.storage?.getItem(this.shimDisconnectKey)) {
95
95
  account = await this.getAccount().catch(() => null);
96
96
  const isConnected = !!account;
97
97
  if (isConnected)
@@ -103,8 +103,8 @@ var MetaMaskConnector = class extends _chunk4BSCIAHYjs.InjectedConnector {
103
103
  account = await this.getAccount();
104
104
  } catch (error) {
105
105
  if (this.isUserRejectedRequestError(error))
106
- throw new (0, _viem.UserRejectedRequestError)(error);
107
- if (error.code === new (0, _viem.ResourceUnavailableRpcError)(error).code)
106
+ throw new UserRejectedRequestError(error);
107
+ if (error.code === new ResourceUnavailableRpcError(error).code)
108
108
  throw error;
109
109
  }
110
110
  }
@@ -112,7 +112,7 @@ var MetaMaskConnector = class extends _chunk4BSCIAHYjs.InjectedConnector {
112
112
  const accounts = await provider.request({
113
113
  method: "eth_requestAccounts"
114
114
  });
115
- account = _viem.getAddress.call(void 0, accounts[0]);
115
+ account = getAddress(accounts[0]);
116
116
  }
117
117
  let id = await this.getChainId();
118
118
  let unsupported = this.isChainUnsupported(id);
@@ -121,19 +121,19 @@ var MetaMaskConnector = class extends _chunk4BSCIAHYjs.InjectedConnector {
121
121
  id = chain.id;
122
122
  unsupported = this.isChainUnsupported(id);
123
123
  }
124
- if (_optionalChain([this, 'access', _8 => _8.options, 'optionalAccess', _9 => _9.shimDisconnect]))
125
- _optionalChain([this, 'access', _10 => _10.storage, 'optionalAccess', _11 => _11.setItem, 'call', _12 => _12(this.shimDisconnectKey, true)]);
124
+ if (this.options?.shimDisconnect)
125
+ this.storage?.setItem(this.shimDisconnectKey, true);
126
126
  return { account, chain: { id, unsupported }, provider };
127
127
  } catch (error) {
128
128
  if (this.isUserRejectedRequestError(error))
129
- throw new (0, _viem.UserRejectedRequestError)(error);
129
+ throw new UserRejectedRequestError(error);
130
130
  if (error.code === -32002)
131
- throw new (0, _viem.ResourceUnavailableRpcError)(error);
131
+ throw new ResourceUnavailableRpcError(error);
132
132
  throw error;
133
133
  }
134
134
  }
135
135
  };
136
136
  _UNSTABLE_shimOnConnectSelectAccount = new WeakMap();
137
-
138
-
139
- exports.MetaMaskConnector = MetaMaskConnector;
137
+ export {
138
+ MetaMaskConnector
139
+ };