@wagmi/core 0.3.3 → 0.3.6

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.
Files changed (32) hide show
  1. package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.cjs.dev.js +28 -9
  2. package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.cjs.prod.js +28 -9
  3. package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.esm.js +28 -9
  4. package/connectors/metaMask/dist/wagmi-core-connectors-metaMask.cjs.dev.js +10 -8
  5. package/connectors/metaMask/dist/wagmi-core-connectors-metaMask.cjs.prod.js +10 -8
  6. package/connectors/metaMask/dist/wagmi-core-connectors-metaMask.esm.js +10 -8
  7. package/connectors/mock/dist/wagmi-core-connectors-mock.cjs.dev.js +19 -6
  8. package/connectors/mock/dist/wagmi-core-connectors-mock.cjs.prod.js +19 -6
  9. package/connectors/mock/dist/wagmi-core-connectors-mock.esm.js +19 -6
  10. package/connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.cjs.dev.js +31 -6
  11. package/connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.cjs.prod.js +31 -6
  12. package/connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.esm.js +31 -6
  13. package/dist/{base-321ac87a.cjs.dev.js → base-d45bb8f9.cjs.dev.js} +5 -3
  14. package/dist/{base-41fb6637.esm.js → base-d69e580f.esm.js} +6 -4
  15. package/dist/{base-6841ebe0.cjs.prod.js → base-ffe4d8ed.cjs.prod.js} +5 -3
  16. package/dist/{client-4172f963.cjs.dev.js → client-20bfac7f.cjs.dev.js} +66 -12
  17. package/dist/{client-87c1ff8b.esm.js → client-61f14c97.esm.js} +66 -12
  18. package/dist/{client-a06c45f3.cjs.prod.js → client-8b124969.cjs.prod.js} +66 -12
  19. package/dist/declarations/src/actions/accounts/connect.d.ts +3 -1
  20. package/dist/declarations/src/actions/network-status/fetchFeeData.d.ts +3 -3
  21. package/dist/declarations/src/client.d.ts +1 -0
  22. package/dist/declarations/src/connectors/base.d.ts +7 -2
  23. package/dist/declarations/src/connectors/coinbaseWallet.d.ts +4 -2
  24. package/dist/declarations/src/connectors/injected.d.ts +9 -1
  25. package/dist/declarations/src/connectors/metaMask.d.ts +2 -2
  26. package/dist/declarations/src/connectors/mock/connector.d.ts +6 -2
  27. package/dist/declarations/src/connectors/mock/provider.d.ts +1 -1
  28. package/dist/declarations/src/connectors/walletConnect.d.ts +7 -2
  29. package/dist/wagmi-core.cjs.dev.js +9 -6
  30. package/dist/wagmi-core.cjs.prod.js +9 -6
  31. package/dist/wagmi-core.esm.js +11 -8
  32. package/package.json +2 -3
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var base = require('./base-6841ebe0.cjs.prod.js');
3
+ var base = require('./base-ffe4d8ed.cjs.prod.js');
4
4
  var ethers = require('ethers');
5
5
  var create = require('zustand/vanilla');
6
6
  var middleware = require('zustand/middleware');
@@ -64,6 +64,8 @@ const shimKey = 'injected.shimDisconnect';
64
64
 
65
65
  var _provider = /*#__PURE__*/new WeakMap();
66
66
 
67
+ var _switchingChains = /*#__PURE__*/new WeakMap();
68
+
67
69
  var _isUserRejectedRequestError = /*#__PURE__*/new WeakSet();
68
70
 
69
71
  class InjectedConnector extends base.Connector {
@@ -92,6 +94,11 @@ class InjectedConnector extends base.Connector {
92
94
  value: void 0
93
95
  });
94
96
 
97
+ base._classPrivateFieldInitSpec(this, _switchingChains, {
98
+ writable: true,
99
+ value: void 0
100
+ });
101
+
95
102
  base._defineProperty(this, "onAccountsChanged", accounts => {
96
103
  if (accounts.length === 0) this.emit('disconnect');else this.emit('change', {
97
104
  account: utils.getAddress(accounts[0])
@@ -110,10 +117,19 @@ class InjectedConnector extends base.Connector {
110
117
  });
111
118
 
112
119
  base._defineProperty(this, "onDisconnect", () => {
113
- var _this$options, _getClient$storage;
120
+ var _this$options, _this$options2, _getClient$storage;
121
+
122
+ // We need this as MetaMask can emit the "disconnect" event
123
+ // upon switching chains. This workaround ensures that the
124
+ // user currently isn't in the process of switching chains.
125
+ if ((_this$options = this.options) !== null && _this$options !== void 0 && _this$options.shimChainChangedDisconnect && base._classPrivateFieldGet(this, _switchingChains)) {
126
+ base._classPrivateFieldSet(this, _switchingChains, false);
127
+
128
+ return;
129
+ }
114
130
 
115
131
  this.emit('disconnect');
116
- if ((_this$options = this.options) !== null && _this$options !== void 0 && _this$options.shimDisconnect) (_getClient$storage = getClient().storage) === null || _getClient$storage === void 0 ? void 0 : _getClient$storage.removeItem(shimKey);
132
+ if ((_this$options2 = this.options) !== null && _this$options2 !== void 0 && _this$options2.shimDisconnect) (_getClient$storage = getClient().storage) === null || _getClient$storage === void 0 ? void 0 : _getClient$storage.removeItem(shimKey);
117
133
  });
118
134
 
119
135
  let name = 'Injected';
@@ -129,8 +145,12 @@ class InjectedConnector extends base.Connector {
129
145
  }
130
146
 
131
147
  async connect() {
148
+ let {
149
+ chainId
150
+ } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
151
+
132
152
  try {
133
- var _this$options2, _getClient$storage2;
153
+ var _this$options3, _getClient$storage2;
134
154
 
135
155
  const provider = await this.getProvider();
136
156
  if (!provider) throw new base.ConnectorNotFoundError();
@@ -144,10 +164,18 @@ class InjectedConnector extends base.Connector {
144
164
  this.emit('message', {
145
165
  type: 'connecting'
146
166
  });
147
- const account = await this.getAccount();
148
- const id = await this.getChainId();
149
- const unsupported = this.isChainUnsupported(id);
150
- if ((_this$options2 = this.options) !== null && _this$options2 !== void 0 && _this$options2.shimDisconnect) (_getClient$storage2 = getClient().storage) === null || _getClient$storage2 === void 0 ? void 0 : _getClient$storage2.setItem(shimKey, true);
167
+ const account = await this.getAccount(); // Switch to chain if provided
168
+
169
+ let id = await this.getChainId();
170
+ let unsupported = this.isChainUnsupported(id);
171
+
172
+ if (chainId && id !== chainId) {
173
+ const chain = await this.switchChain(chainId);
174
+ id = chain.id;
175
+ unsupported = this.isChainUnsupported(id);
176
+ }
177
+
178
+ if ((_this$options3 = this.options) !== null && _this$options3 !== void 0 && _this$options3.shimDisconnect) (_getClient$storage2 = getClient().storage) === null || _getClient$storage2 === void 0 ? void 0 : _getClient$storage2.setItem(shimKey, true);
151
179
  return {
152
180
  account,
153
181
  chain: {
@@ -164,14 +192,14 @@ class InjectedConnector extends base.Connector {
164
192
  }
165
193
 
166
194
  async disconnect() {
167
- var _this$options3, _getClient$storage3;
195
+ var _this$options4, _getClient$storage3;
168
196
 
169
197
  const provider = await this.getProvider();
170
198
  if (!(provider !== null && provider !== void 0 && provider.removeListener)) return;
171
199
  provider.removeListener('accountsChanged', this.onAccountsChanged);
172
200
  provider.removeListener('chainChanged', this.onChainChanged);
173
201
  provider.removeListener('disconnect', this.onDisconnect);
174
- if ((_this$options3 = this.options) !== null && _this$options3 !== void 0 && _this$options3.shimDisconnect) (_getClient$storage3 = getClient().storage) === null || _getClient$storage3 === void 0 ? void 0 : _getClient$storage3.removeItem(shimKey);
202
+ if ((_this$options4 = this.options) !== null && _this$options4 !== void 0 && _this$options4.shimDisconnect) (_getClient$storage3 = getClient().storage) === null || _getClient$storage3 === void 0 ? void 0 : _getClient$storage3.removeItem(shimKey);
175
203
  }
176
204
 
177
205
  async getAccount() {
@@ -204,9 +232,9 @@ class InjectedConnector extends base.Connector {
204
232
 
205
233
  async isAuthorized() {
206
234
  try {
207
- var _this$options4, _getClient$storage4;
235
+ var _this$options5, _getClient$storage4;
208
236
 
209
- if ((_this$options4 = this.options) !== null && _this$options4 !== void 0 && _this$options4.shimDisconnect && !((_getClient$storage4 = getClient().storage) !== null && _getClient$storage4 !== void 0 && _getClient$storage4.getItem(shimKey))) return false;
237
+ if ((_this$options5 = this.options) !== null && _this$options5 !== void 0 && _this$options5.shimDisconnect && !((_getClient$storage4 = getClient().storage) !== null && _getClient$storage4 !== void 0 && _getClient$storage4.getItem(shimKey))) return false;
210
238
  const provider = await this.getProvider();
211
239
  if (!provider) throw new base.ConnectorNotFoundError();
212
240
  const accounts = await provider.request({
@@ -220,6 +248,9 @@ class InjectedConnector extends base.Connector {
220
248
  }
221
249
 
222
250
  async switchChain(chainId) {
251
+ var _this$options6;
252
+
253
+ if ((_this$options6 = this.options) !== null && _this$options6 !== void 0 && _this$options6.shimChainChangedDisconnect) base._classPrivateFieldSet(this, _switchingChains, true);
223
254
  const provider = await this.getProvider();
224
255
  if (!provider) throw new base.ConnectorNotFoundError();
225
256
  const id = utils.hexValue(chainId);
@@ -338,6 +369,8 @@ function createStorage(_ref) {
338
369
 
339
370
  const storeKey = 'store';
340
371
 
372
+ var _isAutoConnecting = /*#__PURE__*/new WeakMap();
373
+
341
374
  var _lastUsedConnector = /*#__PURE__*/new WeakMap();
342
375
 
343
376
  var _addEffects = /*#__PURE__*/new WeakSet();
@@ -368,6 +401,11 @@ class Client {
368
401
 
369
402
  base._defineProperty(this, "store", void 0);
370
403
 
404
+ base._classPrivateFieldInitSpec(this, _isAutoConnecting, {
405
+ writable: true,
406
+ value: void 0
407
+ });
408
+
371
409
  base._classPrivateFieldInitSpec(this, _lastUsedConnector, {
372
410
  writable: true,
373
411
  value: void 0
@@ -457,6 +495,12 @@ class Client {
457
495
  return this.store.getState().error;
458
496
  }
459
497
 
498
+ get lastUsedChainId() {
499
+ var _this$data, _this$data$chain;
500
+
501
+ return (_this$data = this.data) === null || _this$data === void 0 ? void 0 : (_this$data$chain = _this$data.chain) === null || _this$data$chain === void 0 ? void 0 : _this$data$chain.id;
502
+ }
503
+
460
504
  get provider() {
461
505
  return this.store.getState().provider;
462
506
  }
@@ -492,11 +536,18 @@ class Client {
492
536
  var _this$connector$disco, _this$connector;
493
537
 
494
538
  if (this.connector) await ((_this$connector$disco = (_this$connector = this.connector).disconnect) === null || _this$connector$disco === void 0 ? void 0 : _this$connector$disco.call(_this$connector));
539
+
540
+ base._classPrivateFieldSet(this, _isAutoConnecting, false);
541
+
495
542
  this.clearState();
496
543
  this.store.destroy();
497
544
  }
498
545
 
499
546
  async autoConnect() {
547
+ if (base._classPrivateFieldGet(this, _isAutoConnecting)) return;
548
+
549
+ base._classPrivateFieldSet(this, _isAutoConnecting, true);
550
+
500
551
  if (!this.connectors.length) return; // Try last used connector first
501
552
 
502
553
  const sorted = base._classPrivateFieldGet(this, _lastUsedConnector) ? [...this.connectors].sort(x => x.id === base._classPrivateFieldGet(this, _lastUsedConnector) ? -1 : 1) : this.connectors;
@@ -522,6 +573,9 @@ class Client {
522
573
  data: undefined,
523
574
  status: 'disconnected'
524
575
  }));
576
+
577
+ base._classPrivateFieldSet(this, _isAutoConnecting, false);
578
+
525
579
  return this.data;
526
580
  }
527
581
 
@@ -2,6 +2,8 @@ import { Client } from '../../client';
2
2
  import { Connector, ConnectorData } from '../../connectors';
3
3
  import { Provider } from '../../types';
4
4
  export declare type ConnectArgs = {
5
+ /** Chain ID to connect to */
6
+ chainId?: number;
5
7
  /** Connector to connect */
6
8
  connector: Connector;
7
9
  };
@@ -12,5 +14,5 @@ export declare type ConnectResult<TProvider extends Provider = Provider> = {
12
14
  connector: Client<TProvider>['connector'];
13
15
  provider: Data<TProvider>['provider'];
14
16
  };
15
- export declare function connect<TProvider extends Provider = Provider>({ connector, }: ConnectArgs): Promise<ConnectResult<TProvider>>;
17
+ export declare function connect<TProvider extends Provider = Provider>({ chainId, connector, }: ConnectArgs): Promise<ConnectResult<TProvider>>;
16
18
  export {};
@@ -8,9 +8,9 @@ export declare type FetchFeeDataArgs = {
8
8
  };
9
9
  export declare type FetchFeeDataResult = providers.FeeData & {
10
10
  formatted: {
11
- gasPrice: string;
12
- maxFeePerGas: string;
13
- maxPriorityFeePerGas: string;
11
+ gasPrice: string | null;
12
+ maxFeePerGas: string | null;
13
+ maxPriorityFeePerGas: string | null;
14
14
  };
15
15
  };
16
16
  export declare function fetchFeeData({ chainId, formatUnits: units, }?: FetchFeeDataArgs): Promise<FetchFeeDataResult>;
@@ -60,6 +60,7 @@ export declare class Client<TProvider extends Provider = Provider, TWebSocketPro
60
60
  get connector(): Connector<any, any> | undefined;
61
61
  get data(): Data<TProvider> | undefined;
62
62
  get error(): Error | undefined;
63
+ get lastUsedChainId(): number | undefined;
63
64
  get provider(): TProvider;
64
65
  get status(): "connecting" | "connected" | "reconnecting" | "disconnected";
65
66
  get subscribe(): {
@@ -34,11 +34,16 @@ export declare abstract class Connector<Provider = any, Options = any> extends E
34
34
  chains?: Chain[];
35
35
  options: Options;
36
36
  });
37
- abstract connect(): Promise<Required<ConnectorData>>;
37
+ abstract connect(config?: {
38
+ chainId?: number;
39
+ }): Promise<Required<ConnectorData>>;
38
40
  abstract disconnect(): Promise<void>;
39
41
  abstract getAccount(): Promise<string>;
40
42
  abstract getChainId(): Promise<number>;
41
- abstract getProvider(create?: boolean): Promise<Provider>;
43
+ abstract getProvider(config?: {
44
+ chainId?: number;
45
+ create?: boolean;
46
+ }): Promise<Provider>;
42
47
  abstract getSigner(): Promise<Signer>;
43
48
  abstract isAuthorized(): Promise<boolean>;
44
49
  switchChain?(chainId: number): Promise<Chain>;
@@ -20,11 +20,13 @@ export declare class CoinbaseWalletConnector extends Connector<CoinbaseWalletPro
20
20
  readonly id = "coinbaseWallet";
21
21
  readonly name = "Coinbase Wallet";
22
22
  readonly ready = true;
23
- constructor(config: {
23
+ constructor({ chains, options }: {
24
24
  chains?: Chain[];
25
25
  options: Options;
26
26
  });
27
- connect(): Promise<{
27
+ connect({ chainId }: {
28
+ chainId?: number;
29
+ }): Promise<{
28
30
  account: string;
29
31
  chain: {
30
32
  id: number;
@@ -4,6 +4,12 @@ import { Connector } from './base';
4
4
  export declare type InjectedConnectorOptions = {
5
5
  /** Name of connector */
6
6
  name?: string | ((detectedName: string | string[]) => string);
7
+ /**
8
+ * MetaMask 10.9.3 emits disconnect event when chain is changed.
9
+ * This flag prevents the `"disconnect"` event from being emitted upon switching chains.
10
+ * @see https://github.com/MetaMask/metamask-extension/issues/13375#issuecomment-1027663334
11
+ */
12
+ shimChainChangedDisconnect?: boolean;
7
13
  /**
8
14
  * MetaMask and other injected providers do not support programmatic disconnect.
9
15
  * This flag simulates the disconnect behavior by keeping track of connection status in storage.
@@ -21,7 +27,9 @@ export declare class InjectedConnector extends Connector<Window['ethereum'], Inj
21
27
  chains?: Chain[];
22
28
  options?: InjectedConnectorOptions;
23
29
  });
24
- connect(): Promise<{
30
+ connect({ chainId }?: {
31
+ chainId?: number;
32
+ }): Promise<{
25
33
  account: string;
26
34
  chain: {
27
35
  id: number;
@@ -1,11 +1,11 @@
1
1
  import { Chain } from '../types';
2
2
  import { InjectedConnector, InjectedConnectorOptions } from './injected';
3
- export declare type MetaMaskConnectorOptions = Pick<InjectedConnectorOptions, 'shimDisconnect'>;
3
+ export declare type MetaMaskConnectorOptions = Pick<InjectedConnectorOptions, 'shimChainChangedDisconnect' | 'shimDisconnect'>;
4
4
  export declare class MetaMaskConnector extends InjectedConnector {
5
5
  #private;
6
6
  readonly id = "metaMask";
7
7
  readonly ready: boolean;
8
- constructor({ chains, options, }?: {
8
+ constructor({ chains, options: options_, }?: {
9
9
  chains?: Chain[];
10
10
  options?: MetaMaskConnectorOptions;
11
11
  });
@@ -10,7 +10,9 @@ export declare class MockConnector extends Connector<MockProvider, MockProviderO
10
10
  chains?: Chain[];
11
11
  options: MockProviderOptions;
12
12
  });
13
- connect(): Promise<{
13
+ connect({ chainId }?: {
14
+ chainId?: number;
15
+ }): Promise<{
14
16
  account: string;
15
17
  chain: {
16
18
  id: number;
@@ -21,7 +23,9 @@ export declare class MockConnector extends Connector<MockProvider, MockProviderO
21
23
  disconnect(): Promise<void>;
22
24
  getAccount(): Promise<string>;
23
25
  getChainId(): Promise<number>;
24
- getProvider(): Promise<MockProvider>;
26
+ getProvider({ chainId }?: {
27
+ chainId?: number;
28
+ }): Promise<MockProvider>;
25
29
  getSigner(): Promise<import("ethers").Signer>;
26
30
  isAuthorized(): Promise<boolean>;
27
31
  watchAsset(asset: {
@@ -1,13 +1,13 @@
1
1
  import { default as EventEmitter } from 'eventemitter3';
2
2
  import { Signer, providers } from 'ethers';
3
3
  export declare type MockProviderOptions = {
4
+ chainId?: number;
4
5
  flags?: {
5
6
  isAuthorized?: boolean;
6
7
  failConnect?: boolean;
7
8
  failSwitchChain?: boolean;
8
9
  noSwitchChain?: boolean;
9
10
  };
10
- network?: number | string;
11
11
  signer: Signer;
12
12
  };
13
13
  declare type Events = {
@@ -12,7 +12,9 @@ export declare class WalletConnectConnector extends Connector<WalletConnectProvi
12
12
  chains?: Chain[];
13
13
  options: WalletConnectOptions;
14
14
  });
15
- connect(): Promise<{
15
+ connect({ chainId }?: {
16
+ chainId?: number;
17
+ }): Promise<{
16
18
  account: string;
17
19
  chain: {
18
20
  id: number;
@@ -23,7 +25,10 @@ export declare class WalletConnectConnector extends Connector<WalletConnectProvi
23
25
  disconnect(): Promise<void>;
24
26
  getAccount(): Promise<string>;
25
27
  getChainId(): Promise<number>;
26
- getProvider(create?: boolean): Promise<WalletConnectProvider>;
28
+ getProvider({ chainId, create, }?: {
29
+ chainId?: number | undefined;
30
+ create?: boolean | undefined;
31
+ }): Promise<WalletConnectProvider>;
27
32
  getSigner(): Promise<providers.JsonRpcSigner>;
28
33
  isAuthorized(): Promise<boolean>;
29
34
  protected onAccountsChanged: (accounts: string[]) => void;
@@ -2,8 +2,8 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var client = require('./client-4172f963.cjs.dev.js');
6
- var base = require('./base-321ac87a.cjs.dev.js');
5
+ var client = require('./client-20bfac7f.cjs.dev.js');
6
+ var base = require('./base-d45bb8f9.cjs.dev.js');
7
7
  var ethers$1 = require('ethers/lib/ethers');
8
8
  var utils = require('ethers/lib/utils');
9
9
  var chains = require('./chains-98e2e613.cjs.dev.js');
@@ -124,11 +124,14 @@ function fallbackProvider(targetQuorum, minQuorum, providers_, _ref4) {
124
124
 
125
125
  async function connect(_ref) {
126
126
  let {
127
+ chainId,
127
128
  connector
128
129
  } = _ref;
129
130
  const activeConnector = client.client.connector;
130
131
  if (connector.id === (activeConnector === null || activeConnector === void 0 ? void 0 : activeConnector.id)) throw new base.ConnectorAlreadyConnectedError();
131
- const data = await connector.connect();
132
+ const data = await connector.connect({
133
+ chainId
134
+ });
132
135
  client.client.setLastUsedConnector(connector.id);
133
136
  client.client.setState(x => ({ ...x,
134
137
  connector,
@@ -627,9 +630,9 @@ async function fetchFeeData() {
627
630
  });
628
631
  const feeData = await provider.getFeeData();
629
632
  const formatted = {
630
- gasPrice: utils.formatUnits(feeData.gasPrice, units),
631
- maxFeePerGas: utils.formatUnits(feeData.maxFeePerGas, units),
632
- maxPriorityFeePerGas: utils.formatUnits(feeData.maxPriorityFeePerGas, units)
633
+ gasPrice: feeData.gasPrice ? utils.formatUnits(feeData.gasPrice, units) : null,
634
+ maxFeePerGas: feeData.maxFeePerGas ? utils.formatUnits(feeData.maxFeePerGas, units) : null,
635
+ maxPriorityFeePerGas: feeData.maxPriorityFeePerGas ? utils.formatUnits(feeData.maxPriorityFeePerGas, units) : null
633
636
  };
634
637
  return { ...feeData,
635
638
  formatted
@@ -2,8 +2,8 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var client = require('./client-a06c45f3.cjs.prod.js');
6
- var base = require('./base-6841ebe0.cjs.prod.js');
5
+ var client = require('./client-8b124969.cjs.prod.js');
6
+ var base = require('./base-ffe4d8ed.cjs.prod.js');
7
7
  var ethers$1 = require('ethers/lib/ethers');
8
8
  var utils = require('ethers/lib/utils');
9
9
  var chains = require('./chains-0dd661ab.cjs.prod.js');
@@ -124,11 +124,14 @@ function fallbackProvider(targetQuorum, minQuorum, providers_, _ref4) {
124
124
 
125
125
  async function connect(_ref) {
126
126
  let {
127
+ chainId,
127
128
  connector
128
129
  } = _ref;
129
130
  const activeConnector = client.client.connector;
130
131
  if (connector.id === (activeConnector === null || activeConnector === void 0 ? void 0 : activeConnector.id)) throw new base.ConnectorAlreadyConnectedError();
131
- const data = await connector.connect();
132
+ const data = await connector.connect({
133
+ chainId
134
+ });
132
135
  client.client.setLastUsedConnector(connector.id);
133
136
  client.client.setState(x => ({ ...x,
134
137
  connector,
@@ -627,9 +630,9 @@ async function fetchFeeData() {
627
630
  });
628
631
  const feeData = await provider.getFeeData();
629
632
  const formatted = {
630
- gasPrice: utils.formatUnits(feeData.gasPrice, units),
631
- maxFeePerGas: utils.formatUnits(feeData.maxFeePerGas, units),
632
- maxPriorityFeePerGas: utils.formatUnits(feeData.maxPriorityFeePerGas, units)
633
+ gasPrice: feeData.gasPrice ? utils.formatUnits(feeData.gasPrice, units) : null,
634
+ maxFeePerGas: feeData.maxFeePerGas ? utils.formatUnits(feeData.maxFeePerGas, units) : null,
635
+ maxPriorityFeePerGas: feeData.maxPriorityFeePerGas ? utils.formatUnits(feeData.maxPriorityFeePerGas, units) : null
633
636
  };
634
637
  return { ...feeData,
635
638
  formatted
@@ -1,7 +1,7 @@
1
- import { c as client, g as getClient } from './client-87c1ff8b.esm.js';
2
- export { C as Client, I as InjectedConnector, a as createClient, b as createStorage, n as noopStorage } from './client-87c1ff8b.esm.js';
3
- import { C as ConnectorAlreadyConnectedError, a as ConnectorNotFoundError, U as UserRejectedRequestError, S as SwitchChainNotSupportedError } from './base-41fb6637.esm.js';
4
- export { A as AddChainError, c as ChainNotConfiguredError, b as Connector, C as ConnectorAlreadyConnectedError, a as ConnectorNotFoundError, P as ProviderRpcError, R as ResourceUnavailableError, d as RpcError, e as SwitchChainError, S as SwitchChainNotSupportedError, U as UserRejectedRequestError, n as normalizeChainId } from './base-41fb6637.esm.js';
1
+ import { c as client, g as getClient } from './client-61f14c97.esm.js';
2
+ export { C as Client, I as InjectedConnector, a as createClient, b as createStorage, n as noopStorage } from './client-61f14c97.esm.js';
3
+ import { C as ConnectorAlreadyConnectedError, a as ConnectorNotFoundError, U as UserRejectedRequestError, S as SwitchChainNotSupportedError } from './base-d69e580f.esm.js';
4
+ export { A as AddChainError, c as ChainNotConfiguredError, b as Connector, C as ConnectorAlreadyConnectedError, a as ConnectorNotFoundError, P as ProviderRpcError, R as ResourceUnavailableError, d as RpcError, e as SwitchChainError, S as SwitchChainNotSupportedError, U as UserRejectedRequestError, n as normalizeChainId } from './base-d69e580f.esm.js';
5
5
  import { Contract } from 'ethers/lib/ethers';
6
6
  import { formatUnits, getAddress } from 'ethers/lib/utils';
7
7
  import { a as allChains } from './chains-a0a80d94.esm.js';
@@ -123,11 +123,14 @@ function fallbackProvider(targetQuorum, minQuorum, providers_, _ref4) {
123
123
 
124
124
  async function connect(_ref) {
125
125
  let {
126
+ chainId,
126
127
  connector
127
128
  } = _ref;
128
129
  const activeConnector = client.connector;
129
130
  if (connector.id === (activeConnector === null || activeConnector === void 0 ? void 0 : activeConnector.id)) throw new ConnectorAlreadyConnectedError();
130
- const data = await connector.connect();
131
+ const data = await connector.connect({
132
+ chainId
133
+ });
131
134
  client.setLastUsedConnector(connector.id);
132
135
  client.setState(x => ({ ...x,
133
136
  connector,
@@ -626,9 +629,9 @@ async function fetchFeeData() {
626
629
  });
627
630
  const feeData = await provider.getFeeData();
628
631
  const formatted = {
629
- gasPrice: formatUnits(feeData.gasPrice, units),
630
- maxFeePerGas: formatUnits(feeData.maxFeePerGas, units),
631
- maxPriorityFeePerGas: formatUnits(feeData.maxPriorityFeePerGas, units)
632
+ gasPrice: feeData.gasPrice ? formatUnits(feeData.gasPrice, units) : null,
633
+ maxFeePerGas: feeData.maxFeePerGas ? formatUnits(feeData.maxFeePerGas, units) : null,
634
+ maxPriorityFeePerGas: feeData.maxPriorityFeePerGas ? formatUnits(feeData.maxPriorityFeePerGas, units) : null
632
635
  };
633
636
  return { ...feeData,
634
637
  formatted
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@wagmi/core",
3
3
  "description": "Vanilla JS library for Ethereum",
4
4
  "license": "WAGMIT",
5
- "version": "0.3.3",
5
+ "version": "0.3.6",
6
6
  "repository": "tmm/wagmi",
7
7
  "author": "awkweb.eth",
8
8
  "ethereum": "awkweb.eth",
@@ -100,6 +100,5 @@
100
100
  "dapps",
101
101
  "wallet",
102
102
  "web3"
103
- ],
104
- "readme": "# @wagmi/core\n\n## Documentation\n\nFor full documentation and examples, visit [wagmi.sh](https://wagmi.sh).\n\n## Installation\n\nInstall wagmi and its ethers peer dependency.\n\n```bash\nnpm install @wagmi/core ethers\n```\n\n## Community\n\nCheck out the following places for more wagmi-related content:\n\n- Join the [discussions on GitHub](https://github.com/tmm/wagmi/discussions)\n- Follow [@awkweb](https://twitter.com/awkweb) and [@wagmi_sh](https://twitter.com/wagmi_sh) on Twitter for project updates\n- Sign the [guestbook](https://github.com/tmm/wagmi/discussions/2)\n- Share [your project/organization](https://github.com/tmm/wagmi/discussions/201) using wagmi\n\n## Support\n\nIf you find wagmi useful, please consider supporting development. Thank you 🙏\n\n- [GitHub Sponsors](https://github.com/sponsors/tmm?metadata_campaign=readme_core)\n- [Gitcoin Grant](https://gitcoin.co/grants/4493/wagmi-react-hooks-library-for-ethereum)\n- [awkweb.eth](https://etherscan.io/enslookup-search?search=awkweb.eth)\n"
103
+ ]
105
104
  }