@wagmi/connectors 2.3.0-cjs → 2.4.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.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { C as Connector, a as ConnectorData, b as ConnectorEvents, W as WindowProvider } from './base-0473abd3.js';
1
+ export { C as Connector, a as ConnectorData, b as ConnectorEvents, W as WindowProvider } from './base-2dd7facf.js';
2
2
  import '@wagmi/chains';
3
3
  import 'eventemitter3';
4
4
  import 'viem';
@@ -15,4 +15,6 @@ declare class ConnectorNotFoundError extends Error {
15
15
  message: string;
16
16
  }
17
17
 
18
- export { ChainNotConfiguredForConnectorError, ConnectorNotFoundError };
18
+ declare function normalizeChainId(chainId: string | number | bigint): number;
19
+
20
+ export { ChainNotConfiguredForConnectorError, ConnectorNotFoundError, normalizeChainId };
package/dist/index.js CHANGED
@@ -1,12 +1,16 @@
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
+ normalizeChainId
7
+ } from "./chunk-OQILYQDO.js";
8
+ import {
9
+ Connector
10
+ } from "./chunk-QYMCVNHT.js";
11
+ export {
12
+ ChainNotConfiguredForConnectorError,
13
+ Connector,
14
+ ConnectorNotFoundError,
15
+ normalizeChainId
16
+ };
@@ -1,7 +1,7 @@
1
1
  import * as viem from 'viem';
2
2
  import { Address } from 'viem';
3
3
  import { Chain } from '@wagmi/chains';
4
- import { W as WindowProvider, C as Connector } from './base-0473abd3.js';
4
+ import { W as WindowProvider, C as Connector } from './base-2dd7facf.js';
5
5
  import 'eventemitter3';
6
6
 
7
7
  type InjectedConnectorOptions = {
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-Z2P63ELM.js";
4
+ import "./chunk-ZCAPXGBX.js";
5
+ import "./chunk-OQILYQDO.js";
6
+ import "./chunk-QYMCVNHT.js";
7
+ export {
8
+ InjectedConnector
9
+ };
package/dist/ledger.d.ts CHANGED
@@ -1,27 +1,52 @@
1
1
  import * as viem from 'viem';
2
2
  import { EthereumProvider } from '@ledgerhq/connect-kit-loader';
3
3
  import { Chain } from '@wagmi/chains';
4
- import { C as Connector, a as ConnectorData } from './base-0473abd3.js';
4
+ import { EthereumProviderOptions } from '@walletconnect/ethereum-provider/dist/types/EthereumProvider';
5
+ import { C as Connector } from './base-2dd7facf.js';
5
6
  import 'eventemitter3';
6
7
 
7
- type LedgerConnectorOptions = {
8
+ type LedgerConnectorWcV1Options = {
9
+ walletConnectVersion?: 1;
8
10
  bridge?: string;
9
11
  chainId?: number;
10
- enableDebugLogs?: boolean;
11
12
  rpc?: {
12
13
  [chainId: number]: string;
13
14
  };
14
15
  };
16
+ type LedgerConnectorWcV2Options = {
17
+ walletConnectVersion?: 2;
18
+ projectId?: EthereumProviderOptions['projectId'];
19
+ requiredChains?: number[];
20
+ requiredMethods?: string[];
21
+ optionalMethods?: string[];
22
+ requiredEvents?: string[];
23
+ optionalEvents?: string[];
24
+ };
25
+ type LedgerConnectorOptions = {
26
+ enableDebugLogs?: boolean;
27
+ } & (LedgerConnectorWcV1Options | LedgerConnectorWcV2Options);
28
+ type ConnectConfig = {
29
+ /** Target chain to connect to. */
30
+ chainId?: number;
31
+ };
15
32
  declare class LedgerConnector extends Connector<EthereumProvider, LedgerConnectorOptions> {
16
33
  #private;
17
34
  readonly id = "ledger";
18
35
  readonly name = "Ledger";
19
36
  readonly ready = true;
20
- constructor({ chains, options, }?: {
37
+ get walletConnectVersion(): 1 | 2;
38
+ constructor(config: {
21
39
  chains?: Chain[];
22
- options?: LedgerConnectorOptions;
40
+ options: LedgerConnectorOptions;
23
41
  });
24
- connect(): Promise<Required<ConnectorData>>;
42
+ connect({ chainId }?: ConnectConfig): Promise<{
43
+ account: `0x${string}`;
44
+ chain: {
45
+ id: number;
46
+ unsupported: boolean;
47
+ };
48
+ provider: EthereumProvider;
49
+ }>;
25
50
  disconnect(): Promise<void>;
26
51
  getAccount(): Promise<`0x${string}`>;
27
52
  getChainId(): Promise<number>;
@@ -284,9 +309,11 @@ declare class LedgerConnector extends Connector<EthereumProvider, LedgerConnecto
284
309
  };
285
310
  }>;
286
311
  isAuthorized(): Promise<boolean>;
312
+ switchChain(chainId: number): Promise<Chain>;
287
313
  protected onAccountsChanged: (accounts: string[]) => void;
288
314
  protected onChainChanged: (chainId: number | string) => void;
289
315
  protected onDisconnect: () => void;
316
+ protected onConnect: () => void;
290
317
  }
291
318
 
292
319
  export { LedgerConnector };