@wagmi/core 0.3.4 → 0.3.7

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 (42) hide show
  1. package/chains/dist/wagmi-core-chains.cjs.dev.js +1 -1
  2. package/chains/dist/wagmi-core-chains.cjs.prod.js +1 -1
  3. package/chains/dist/wagmi-core-chains.esm.js +1 -1
  4. package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.cjs.dev.js +33 -11
  5. package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.cjs.prod.js +33 -11
  6. package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.esm.js +33 -11
  7. package/connectors/metaMask/dist/wagmi-core-connectors-metaMask.cjs.dev.js +11 -9
  8. package/connectors/metaMask/dist/wagmi-core-connectors-metaMask.cjs.prod.js +11 -9
  9. package/connectors/metaMask/dist/wagmi-core-connectors-metaMask.esm.js +11 -9
  10. package/connectors/mock/dist/wagmi-core-connectors-mock.cjs.dev.js +20 -7
  11. package/connectors/mock/dist/wagmi-core-connectors-mock.cjs.prod.js +20 -7
  12. package/connectors/mock/dist/wagmi-core-connectors-mock.esm.js +20 -7
  13. package/connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.cjs.dev.js +29 -6
  14. package/connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.cjs.prod.js +29 -6
  15. package/connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.esm.js +29 -6
  16. package/dist/{base-321ac87a.cjs.dev.js → base-147e77ca.cjs.dev.js} +6 -4
  17. package/dist/{base-6841ebe0.cjs.prod.js → base-f5e9d7e7.cjs.prod.js} +6 -4
  18. package/dist/{base-41fb6637.esm.js → base-f818d190.esm.js} +7 -5
  19. package/dist/{chains-0dd661ab.cjs.prod.js → chains-01801dff.cjs.prod.js} +4 -0
  20. package/dist/{chains-98e2e613.cjs.dev.js → chains-1b1bdb4e.cjs.dev.js} +4 -0
  21. package/dist/{chains-a0a80d94.esm.js → chains-541a65cc.esm.js} +4 -0
  22. package/dist/{client-4172f963.cjs.dev.js → client-b9a38d26.cjs.dev.js} +71 -14
  23. package/dist/{client-87c1ff8b.esm.js → client-ba0c162e.esm.js} +71 -14
  24. package/dist/{client-a06c45f3.cjs.prod.js → client-d8761bad.cjs.prod.js} +71 -14
  25. package/dist/declarations/src/actions/accounts/connect.d.ts +3 -1
  26. package/dist/declarations/src/actions/network-status/fetchFeeData.d.ts +3 -3
  27. package/dist/declarations/src/client.d.ts +2 -1
  28. package/dist/declarations/src/connectors/base.d.ts +7 -2
  29. package/dist/declarations/src/connectors/coinbaseWallet.d.ts +4 -2
  30. package/dist/declarations/src/connectors/injected.d.ts +9 -1
  31. package/dist/declarations/src/connectors/metaMask.d.ts +2 -2
  32. package/dist/declarations/src/connectors/mock/connector.d.ts +6 -2
  33. package/dist/declarations/src/connectors/mock/provider.d.ts +1 -1
  34. package/dist/declarations/src/connectors/walletConnect.d.ts +7 -2
  35. package/dist/declarations/src/types/index.d.ts +2 -0
  36. package/dist/wagmi-core.cjs.dev.js +23 -12
  37. package/dist/wagmi-core.cjs.prod.js +23 -12
  38. package/dist/wagmi-core.esm.js +26 -15
  39. package/package.json +3 -3
  40. package/providers/jsonRpc/dist/wagmi-core-providers-jsonRpc.cjs.dev.js +1 -0
  41. package/providers/jsonRpc/dist/wagmi-core-providers-jsonRpc.cjs.prod.js +1 -0
  42. package/providers/jsonRpc/dist/wagmi-core-providers-jsonRpc.esm.js +1 -0
@@ -2,11 +2,14 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var base = require('../../../dist/base-6841ebe0.cjs.prod.js');
5
+ var base = require('../../../dist/base-f5e9d7e7.cjs.prod.js');
6
6
  var ethers = require('ethers');
7
7
  var utils = require('ethers/lib/utils');
8
- var chains = require('../../../dist/chains-0dd661ab.cjs.prod.js');
8
+ var client = require('../../../dist/client-d8761bad.cjs.prod.js');
9
+ var chains = require('../../../dist/chains-01801dff.cjs.prod.js');
9
10
  require('eventemitter3');
11
+ require('zustand/vanilla');
12
+ require('zustand/middleware');
10
13
  require('../../../dist/rpcs-b3c52116.cjs.prod.js');
11
14
 
12
15
  function _interopNamespace(e) {
@@ -80,10 +83,24 @@ class WalletConnectConnector extends base.Connector {
80
83
  }
81
84
 
82
85
  async connect() {
86
+ let {
87
+ chainId
88
+ } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
89
+
83
90
  try {
84
91
  var _provider$connector$p, _provider$connector, _provider$connector$p2;
85
92
 
86
- const provider = await this.getProvider(true);
93
+ let targetChainId = chainId;
94
+
95
+ if (!targetChainId) {
96
+ const lastUsedChainId = client.getClient().lastUsedChainId;
97
+ if (lastUsedChainId && !this.isChainUnsupported(lastUsedChainId)) targetChainId = lastUsedChainId;
98
+ }
99
+
100
+ const provider = await this.getProvider({
101
+ chainId: targetChainId,
102
+ create: true
103
+ });
87
104
  provider.on('accountsChanged', this.onAccountsChanged);
88
105
  provider.on('chainChanged', this.onChainChanged);
89
106
  provider.on('disconnect', this.onDisconnect); // Defer message to the next tick to ensure wallet connect data (provided by `.enable()`) is available
@@ -135,11 +152,17 @@ class WalletConnectConnector extends base.Connector {
135
152
  return chainId;
136
153
  }
137
154
 
138
- async getProvider(create) {
155
+ async getProvider() {
156
+ var _this$options, _this$chains$;
157
+
158
+ let {
159
+ chainId = ((_this$options = this.options) === null || _this$options === void 0 ? void 0 : _this$options.chainId) || ((_this$chains$ = this.chains[0]) === null || _this$chains$ === void 0 ? void 0 : _this$chains$.id),
160
+ create = false
161
+ } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
162
+
139
163
  if (!base._classPrivateFieldGet(this, _provider) || create) {
140
- var _this$options, _this$options2, _this$options3;
164
+ var _this$options2, _this$options3;
141
165
 
142
- const chainId = ((_this$options = this.options) === null || _this$options === void 0 ? void 0 : _this$options.chainId) || this.chains[0].id;
143
166
  const rpc = !((_this$options2 = this.options) !== null && _this$options2 !== void 0 && _this$options2.infuraId) ? this.chains.reduce((rpc, chain) => ({ ...rpc,
144
167
  [chain.id]: chain.rpcUrls.default
145
168
  }), {}) : {};
@@ -1,8 +1,11 @@
1
- import { b as Connector, _ as _classPrivateMethodInitSpec, f as _defineProperty, g as _classPrivateFieldInitSpec, n as normalizeChainId, h as _classPrivateMethodGet, U as UserRejectedRequestError, j as _classPrivateFieldGet, i as _classPrivateFieldSet, e as SwitchChainError } from '../../../dist/base-41fb6637.esm.js';
1
+ import { b as Connector, _ as _classPrivateMethodInitSpec, f as _defineProperty, g as _classPrivateFieldInitSpec, n as normalizeChainId, j as _classPrivateMethodGet, U as UserRejectedRequestError, h as _classPrivateFieldGet, i as _classPrivateFieldSet, e as SwitchChainError } from '../../../dist/base-f818d190.esm.js';
2
2
  import { providers } from 'ethers';
3
3
  import { getAddress, hexValue } from 'ethers/lib/utils';
4
- import { a as allChains } from '../../../dist/chains-a0a80d94.esm.js';
4
+ import { g as getClient } from '../../../dist/client-ba0c162e.esm.js';
5
+ import { a as allChains } from '../../../dist/chains-541a65cc.esm.js';
5
6
  import 'eventemitter3';
7
+ import 'zustand/vanilla';
8
+ import 'zustand/middleware';
6
9
  import '../../../dist/rpcs-7cfbd91c.esm.js';
7
10
 
8
11
  /**
@@ -58,10 +61,24 @@ class WalletConnectConnector extends Connector {
58
61
  }
59
62
 
60
63
  async connect() {
64
+ let {
65
+ chainId
66
+ } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
67
+
61
68
  try {
62
69
  var _provider$connector$p, _provider$connector, _provider$connector$p2;
63
70
 
64
- const provider = await this.getProvider(true);
71
+ let targetChainId = chainId;
72
+
73
+ if (!targetChainId) {
74
+ const lastUsedChainId = getClient().lastUsedChainId;
75
+ if (lastUsedChainId && !this.isChainUnsupported(lastUsedChainId)) targetChainId = lastUsedChainId;
76
+ }
77
+
78
+ const provider = await this.getProvider({
79
+ chainId: targetChainId,
80
+ create: true
81
+ });
65
82
  provider.on('accountsChanged', this.onAccountsChanged);
66
83
  provider.on('chainChanged', this.onChainChanged);
67
84
  provider.on('disconnect', this.onDisconnect); // Defer message to the next tick to ensure wallet connect data (provided by `.enable()`) is available
@@ -113,11 +130,17 @@ class WalletConnectConnector extends Connector {
113
130
  return chainId;
114
131
  }
115
132
 
116
- async getProvider(create) {
133
+ async getProvider() {
134
+ var _this$options, _this$chains$;
135
+
136
+ let {
137
+ chainId = ((_this$options = this.options) === null || _this$options === void 0 ? void 0 : _this$options.chainId) || ((_this$chains$ = this.chains[0]) === null || _this$chains$ === void 0 ? void 0 : _this$chains$.id),
138
+ create = false
139
+ } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
140
+
117
141
  if (!_classPrivateFieldGet(this, _provider) || create) {
118
- var _this$options, _this$options2, _this$options3;
142
+ var _this$options2, _this$options3;
119
143
 
120
- const chainId = ((_this$options = this.options) === null || _this$options === void 0 ? void 0 : _this$options.chainId) || this.chains[0].id;
121
144
  const rpc = !((_this$options2 = this.options) !== null && _this$options2 !== void 0 && _this$options2.infuraId) ? this.chains.reduce((rpc, chain) => ({ ...rpc,
122
145
  [chain.id]: chain.rpcUrls.default
123
146
  }), {}) : {};
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var EventEmitter = require('eventemitter3');
4
- var chains = require('./chains-98e2e613.cjs.dev.js');
4
+ var chains = require('./chains-1b1bdb4e.cjs.dev.js');
5
5
 
6
6
  function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
7
7
 
@@ -256,9 +256,11 @@ class Connector extends EventEmitter__default["default"] {
256
256
  getBlockExplorerUrls(chain) {
257
257
  var _chain$blockExplorers;
258
258
 
259
- const blockExplorer = (_chain$blockExplorers = chain.blockExplorers) === null || _chain$blockExplorers === void 0 ? void 0 : _chain$blockExplorers.default;
260
- if (Array.isArray(blockExplorer)) return blockExplorer.map(x => x.url);
261
- if (blockExplorer !== null && blockExplorer !== void 0 && blockExplorer.url) return [blockExplorer.url];
259
+ const {
260
+ default: blockExplorer,
261
+ ...blockExplorers
262
+ } = (_chain$blockExplorers = chain.blockExplorers) !== null && _chain$blockExplorers !== void 0 ? _chain$blockExplorers : {};
263
+ if (blockExplorer) return [blockExplorer.url, ...Object.values(blockExplorers).map(x => x.url)];
262
264
  return [];
263
265
  }
264
266
 
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var EventEmitter = require('eventemitter3');
4
- var chains = require('./chains-0dd661ab.cjs.prod.js');
4
+ var chains = require('./chains-01801dff.cjs.prod.js');
5
5
 
6
6
  function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
7
7
 
@@ -256,9 +256,11 @@ class Connector extends EventEmitter__default["default"] {
256
256
  getBlockExplorerUrls(chain) {
257
257
  var _chain$blockExplorers;
258
258
 
259
- const blockExplorer = (_chain$blockExplorers = chain.blockExplorers) === null || _chain$blockExplorers === void 0 ? void 0 : _chain$blockExplorers.default;
260
- if (Array.isArray(blockExplorer)) return blockExplorer.map(x => x.url);
261
- if (blockExplorer !== null && blockExplorer !== void 0 && blockExplorer.url) return [blockExplorer.url];
259
+ const {
260
+ default: blockExplorer,
261
+ ...blockExplorers
262
+ } = (_chain$blockExplorers = chain.blockExplorers) !== null && _chain$blockExplorers !== void 0 ? _chain$blockExplorers : {};
263
+ if (blockExplorer) return [blockExplorer.url, ...Object.values(blockExplorers).map(x => x.url)];
262
264
  return [];
263
265
  }
264
266
 
@@ -1,5 +1,5 @@
1
1
  import EventEmitter from 'eventemitter3';
2
- import { d as defaultChains } from './chains-a0a80d94.esm.js';
2
+ import { d as defaultChains } from './chains-541a65cc.esm.js';
3
3
 
4
4
  function _checkPrivateRedeclaration(obj, privateCollection) {
5
5
  if (privateCollection.has(obj)) {
@@ -250,9 +250,11 @@ class Connector extends EventEmitter {
250
250
  getBlockExplorerUrls(chain) {
251
251
  var _chain$blockExplorers;
252
252
 
253
- const blockExplorer = (_chain$blockExplorers = chain.blockExplorers) === null || _chain$blockExplorers === void 0 ? void 0 : _chain$blockExplorers.default;
254
- if (Array.isArray(blockExplorer)) return blockExplorer.map(x => x.url);
255
- if (blockExplorer !== null && blockExplorer !== void 0 && blockExplorer.url) return [blockExplorer.url];
253
+ const {
254
+ default: blockExplorer,
255
+ ...blockExplorers
256
+ } = (_chain$blockExplorers = chain.blockExplorers) !== null && _chain$blockExplorers !== void 0 ? _chain$blockExplorers : {};
257
+ if (blockExplorer) return [blockExplorer.url, ...Object.values(blockExplorers).map(x => x.url)];
256
258
  return [];
257
259
  }
258
260
 
@@ -262,4 +264,4 @@ class Connector extends EventEmitter {
262
264
 
263
265
  }
264
266
 
265
- export { AddChainError as A, ConnectorAlreadyConnectedError as C, ProviderRpcError as P, ResourceUnavailableError as R, SwitchChainNotSupportedError as S, UserRejectedRequestError as U, _classPrivateMethodInitSpec as _, ConnectorNotFoundError as a, Connector as b, ChainNotConfiguredError as c, RpcError as d, SwitchChainError as e, _defineProperty as f, _classPrivateFieldInitSpec as g, _classPrivateMethodGet as h, _classPrivateFieldSet as i, _classPrivateFieldGet as j, normalizeChainId as n };
267
+ export { AddChainError as A, ConnectorAlreadyConnectedError as C, ProviderRpcError as P, ResourceUnavailableError as R, SwitchChainNotSupportedError as S, UserRejectedRequestError as U, _classPrivateMethodInitSpec as _, ConnectorNotFoundError as a, Connector as b, ChainNotConfiguredError as c, RpcError as d, SwitchChainError as e, _defineProperty as f, _classPrivateFieldInitSpec as g, _classPrivateFieldGet as h, _classPrivateFieldSet as i, _classPrivateMethodGet as j, normalizeChainId as n };
@@ -68,6 +68,7 @@ const mainnet = {
68
68
  id: chainId.mainnet,
69
69
  name: 'Ethereum',
70
70
  network: 'homestead',
71
+ ensAddress: '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e',
71
72
  nativeCurrency: {
72
73
  name: 'Ether',
73
74
  symbol: 'ETH',
@@ -87,6 +88,7 @@ const ropsten = {
87
88
  id: chainId.ropsten,
88
89
  name: 'Ropsten',
89
90
  network: 'ropsten',
91
+ ensAddress: '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e',
90
92
  nativeCurrency: {
91
93
  name: 'Ropsten Ether',
92
94
  symbol: 'ropETH',
@@ -107,6 +109,7 @@ const rinkeby = {
107
109
  id: chainId.rinkeby,
108
110
  name: 'Rinkeby',
109
111
  network: 'rinkeby',
112
+ ensAddress: '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e',
110
113
  nativeCurrency: {
111
114
  name: 'Rinkeby Ether',
112
115
  symbol: 'rETH',
@@ -127,6 +130,7 @@ const goerli = {
127
130
  id: chainId.goerli,
128
131
  name: 'Goerli',
129
132
  network: 'goerli',
133
+ ensAddress: '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e',
130
134
  nativeCurrency: {
131
135
  name: 'Goerli Ether',
132
136
  symbol: 'gETH',
@@ -68,6 +68,7 @@ const mainnet = {
68
68
  id: chainId.mainnet,
69
69
  name: 'Ethereum',
70
70
  network: 'homestead',
71
+ ensAddress: '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e',
71
72
  nativeCurrency: {
72
73
  name: 'Ether',
73
74
  symbol: 'ETH',
@@ -87,6 +88,7 @@ const ropsten = {
87
88
  id: chainId.ropsten,
88
89
  name: 'Ropsten',
89
90
  network: 'ropsten',
91
+ ensAddress: '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e',
90
92
  nativeCurrency: {
91
93
  name: 'Ropsten Ether',
92
94
  symbol: 'ropETH',
@@ -107,6 +109,7 @@ const rinkeby = {
107
109
  id: chainId.rinkeby,
108
110
  name: 'Rinkeby',
109
111
  network: 'rinkeby',
112
+ ensAddress: '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e',
110
113
  nativeCurrency: {
111
114
  name: 'Rinkeby Ether',
112
115
  symbol: 'rETH',
@@ -127,6 +130,7 @@ const goerli = {
127
130
  id: chainId.goerli,
128
131
  name: 'Goerli',
129
132
  network: 'goerli',
133
+ ensAddress: '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e',
130
134
  nativeCurrency: {
131
135
  name: 'Goerli Ether',
132
136
  symbol: 'gETH',
@@ -66,6 +66,7 @@ const mainnet = {
66
66
  id: chainId.mainnet,
67
67
  name: 'Ethereum',
68
68
  network: 'homestead',
69
+ ensAddress: '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e',
69
70
  nativeCurrency: {
70
71
  name: 'Ether',
71
72
  symbol: 'ETH',
@@ -85,6 +86,7 @@ const ropsten = {
85
86
  id: chainId.ropsten,
86
87
  name: 'Ropsten',
87
88
  network: 'ropsten',
89
+ ensAddress: '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e',
88
90
  nativeCurrency: {
89
91
  name: 'Ropsten Ether',
90
92
  symbol: 'ropETH',
@@ -105,6 +107,7 @@ const rinkeby = {
105
107
  id: chainId.rinkeby,
106
108
  name: 'Rinkeby',
107
109
  network: 'rinkeby',
110
+ ensAddress: '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e',
108
111
  nativeCurrency: {
109
112
  name: 'Rinkeby Ether',
110
113
  symbol: 'rETH',
@@ -125,6 +128,7 @@ const goerli = {
125
128
  id: chainId.goerli,
126
129
  name: 'Goerli',
127
130
  network: 'goerli',
131
+ ensAddress: '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e',
128
132
  nativeCurrency: {
129
133
  name: 'Goerli Ether',
130
134
  symbol: 'gETH',
@@ -1,11 +1,11 @@
1
1
  'use strict';
2
2
 
3
- var base = require('./base-321ac87a.cjs.dev.js');
3
+ var base = require('./base-147e77ca.cjs.dev.js');
4
4
  var ethers = require('ethers');
5
5
  var create = require('zustand/vanilla');
6
6
  var middleware = require('zustand/middleware');
7
7
  var utils = require('ethers/lib/utils');
8
- var chains = require('./chains-98e2e613.cjs.dev.js');
8
+ var chains = require('./chains-1b1bdb4e.cjs.dev.js');
9
9
 
10
10
  function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
11
11
 
@@ -29,6 +29,8 @@ function getInjectedName(ethereum) {
29
29
 
30
30
 
31
31
  if ((_ethereum$providers = ethereum.providers) !== null && _ethereum$providers !== void 0 && _ethereum$providers.length) {
32
+ var _names$;
33
+
32
34
  // Deduplicate names using Set
33
35
  // Coinbase Wallet puts multiple providers in `ethereum.providers`
34
36
  const nameSet = new Set();
@@ -46,7 +48,8 @@ function getInjectedName(ethereum) {
46
48
  }
47
49
 
48
50
  const names = [...nameSet];
49
- return names.length ? names : names[0];
51
+ if (names.length) return names;
52
+ return (_names$ = names[0]) !== null && _names$ !== void 0 ? _names$ : 'Injected';
50
53
  }
51
54
 
52
55
  return (_getName = getName(ethereum)) !== null && _getName !== void 0 ? _getName : 'Injected';
@@ -64,6 +67,8 @@ const shimKey = 'injected.shimDisconnect';
64
67
 
65
68
  var _provider = /*#__PURE__*/new WeakMap();
66
69
 
70
+ var _switchingChains = /*#__PURE__*/new WeakMap();
71
+
67
72
  var _isUserRejectedRequestError = /*#__PURE__*/new WeakSet();
68
73
 
69
74
  class InjectedConnector extends base.Connector {
@@ -92,6 +97,11 @@ class InjectedConnector extends base.Connector {
92
97
  value: void 0
93
98
  });
94
99
 
100
+ base._classPrivateFieldInitSpec(this, _switchingChains, {
101
+ writable: true,
102
+ value: void 0
103
+ });
104
+
95
105
  base._defineProperty(this, "onAccountsChanged", accounts => {
96
106
  if (accounts.length === 0) this.emit('disconnect');else this.emit('change', {
97
107
  account: utils.getAddress(accounts[0])
@@ -110,10 +120,19 @@ class InjectedConnector extends base.Connector {
110
120
  });
111
121
 
112
122
  base._defineProperty(this, "onDisconnect", () => {
113
- var _this$options, _getClient$storage;
123
+ var _this$options, _this$options2, _getClient$storage;
124
+
125
+ // We need this as MetaMask can emit the "disconnect" event
126
+ // upon switching chains. This workaround ensures that the
127
+ // user currently isn't in the process of switching chains.
128
+ if ((_this$options = this.options) !== null && _this$options !== void 0 && _this$options.shimChainChangedDisconnect && base._classPrivateFieldGet(this, _switchingChains)) {
129
+ base._classPrivateFieldSet(this, _switchingChains, false);
130
+
131
+ return;
132
+ }
114
133
 
115
134
  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);
135
+ 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
136
  });
118
137
 
119
138
  let name = 'Injected';
@@ -129,8 +148,12 @@ class InjectedConnector extends base.Connector {
129
148
  }
130
149
 
131
150
  async connect() {
151
+ let {
152
+ chainId
153
+ } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
154
+
132
155
  try {
133
- var _this$options2, _getClient$storage2;
156
+ var _this$options3, _getClient$storage2;
134
157
 
135
158
  const provider = await this.getProvider();
136
159
  if (!provider) throw new base.ConnectorNotFoundError();
@@ -144,10 +167,18 @@ class InjectedConnector extends base.Connector {
144
167
  this.emit('message', {
145
168
  type: 'connecting'
146
169
  });
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);
170
+ const account = await this.getAccount(); // Switch to chain if provided
171
+
172
+ let id = await this.getChainId();
173
+ let unsupported = this.isChainUnsupported(id);
174
+
175
+ if (chainId && id !== chainId) {
176
+ const chain = await this.switchChain(chainId);
177
+ id = chain.id;
178
+ unsupported = this.isChainUnsupported(id);
179
+ }
180
+
181
+ 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
182
  return {
152
183
  account,
153
184
  chain: {
@@ -164,14 +195,14 @@ class InjectedConnector extends base.Connector {
164
195
  }
165
196
 
166
197
  async disconnect() {
167
- var _this$options3, _getClient$storage3;
198
+ var _this$options4, _getClient$storage3;
168
199
 
169
200
  const provider = await this.getProvider();
170
201
  if (!(provider !== null && provider !== void 0 && provider.removeListener)) return;
171
202
  provider.removeListener('accountsChanged', this.onAccountsChanged);
172
203
  provider.removeListener('chainChanged', this.onChainChanged);
173
204
  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);
205
+ 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
206
  }
176
207
 
177
208
  async getAccount() {
@@ -204,9 +235,9 @@ class InjectedConnector extends base.Connector {
204
235
 
205
236
  async isAuthorized() {
206
237
  try {
207
- var _this$options4, _getClient$storage4;
238
+ var _this$options5, _getClient$storage4;
208
239
 
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;
240
+ 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
241
  const provider = await this.getProvider();
211
242
  if (!provider) throw new base.ConnectorNotFoundError();
212
243
  const accounts = await provider.request({
@@ -220,6 +251,9 @@ class InjectedConnector extends base.Connector {
220
251
  }
221
252
 
222
253
  async switchChain(chainId) {
254
+ var _this$options6;
255
+
256
+ if ((_this$options6 = this.options) !== null && _this$options6 !== void 0 && _this$options6.shimChainChangedDisconnect) base._classPrivateFieldSet(this, _switchingChains, true);
223
257
  const provider = await this.getProvider();
224
258
  if (!provider) throw new base.ConnectorNotFoundError();
225
259
  const id = utils.hexValue(chainId);
@@ -338,6 +372,8 @@ function createStorage(_ref) {
338
372
 
339
373
  const storeKey = 'store';
340
374
 
375
+ var _isAutoConnecting = /*#__PURE__*/new WeakMap();
376
+
341
377
  var _lastUsedConnector = /*#__PURE__*/new WeakMap();
342
378
 
343
379
  var _addEffects = /*#__PURE__*/new WeakSet();
@@ -368,6 +404,11 @@ class Client {
368
404
 
369
405
  base._defineProperty(this, "store", void 0);
370
406
 
407
+ base._classPrivateFieldInitSpec(this, _isAutoConnecting, {
408
+ writable: true,
409
+ value: void 0
410
+ });
411
+
371
412
  base._classPrivateFieldInitSpec(this, _lastUsedConnector, {
372
413
  writable: true,
373
414
  value: void 0
@@ -457,6 +498,12 @@ class Client {
457
498
  return this.store.getState().error;
458
499
  }
459
500
 
501
+ get lastUsedChainId() {
502
+ var _this$data, _this$data$chain;
503
+
504
+ 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;
505
+ }
506
+
460
507
  get provider() {
461
508
  return this.store.getState().provider;
462
509
  }
@@ -492,11 +539,18 @@ class Client {
492
539
  var _this$connector$disco, _this$connector;
493
540
 
494
541
  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));
542
+
543
+ base._classPrivateFieldSet(this, _isAutoConnecting, false);
544
+
495
545
  this.clearState();
496
546
  this.store.destroy();
497
547
  }
498
548
 
499
549
  async autoConnect() {
550
+ if (base._classPrivateFieldGet(this, _isAutoConnecting)) return;
551
+
552
+ base._classPrivateFieldSet(this, _isAutoConnecting, true);
553
+
500
554
  if (!this.connectors.length) return; // Try last used connector first
501
555
 
502
556
  const sorted = base._classPrivateFieldGet(this, _lastUsedConnector) ? [...this.connectors].sort(x => x.id === base._classPrivateFieldGet(this, _lastUsedConnector) ? -1 : 1) : this.connectors;
@@ -522,6 +576,9 @@ class Client {
522
576
  data: undefined,
523
577
  status: 'disconnected'
524
578
  }));
579
+
580
+ base._classPrivateFieldSet(this, _isAutoConnecting, false);
581
+
525
582
  return this.data;
526
583
  }
527
584