@wagmi/core 0.4.1 → 0.4.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { d as Connector, _ as _classPrivateMethodInitSpec, i as _defineProperty, j as _classPrivateFieldInitSpec, n as normalizeChainId, U as UserRejectedRequestError, k as _classPrivateFieldGet, l as _classPrivateFieldSet, e as ChainNotConfiguredError, m as _classPrivateMethodGet, A as AddChainError, h as SwitchChainError } from '../../../dist/base-e66f9622.esm.js';
1
+ import { d as Connector, l as _classPrivateMethodInitSpec, _ as _defineProperty, i as _classPrivateFieldInitSpec, n as normalizeChainId, U as UserRejectedRequestError, j as _classPrivateFieldGet, k as _classPrivateFieldSet, e as ChainNotConfiguredError, m as _classPrivateMethodGet, A as AddChainError, h as SwitchChainError } from '../../../dist/base-68ec937e.esm.js';
2
2
  import { providers } from 'ethers';
3
3
  import { getAddress, hexValue } from 'ethers/lib/utils';
4
4
  import 'eventemitter3';
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var base = require('../../../dist/base-e71ae4b2.cjs.dev.js');
6
- var client = require('../../../dist/client-53f2119c.cjs.dev.js');
6
+ var client = require('../../../dist/client-90ae4735.cjs.dev.js');
7
7
  require('eventemitter3');
8
8
  require('../../../dist/chains-d970ee8d.cjs.dev.js');
9
9
  require('../../../dist/rpcs-f1d24f0e.cjs.dev.js');
@@ -14,6 +14,8 @@ require('ethers/lib/utils');
14
14
 
15
15
  var _provider = /*#__PURE__*/new WeakMap();
16
16
 
17
+ var _UNSTABLE_shimOnConnectSelectAccount = /*#__PURE__*/new WeakMap();
18
+
17
19
  var _getReady = /*#__PURE__*/new WeakSet();
18
20
 
19
21
  var _findProvider = /*#__PURE__*/new WeakSet();
@@ -47,6 +49,75 @@ class MetaMaskConnector extends client.InjectedConnector {
47
49
  writable: true,
48
50
  value: void 0
49
51
  });
52
+
53
+ base._classPrivateFieldInitSpec(this, _UNSTABLE_shimOnConnectSelectAccount, {
54
+ writable: true,
55
+ value: void 0
56
+ });
57
+
58
+ base._classPrivateFieldSet(this, _UNSTABLE_shimOnConnectSelectAccount, options.UNSTABLE_shimOnConnectSelectAccount);
59
+ }
60
+
61
+ async connect() {
62
+ let {
63
+ chainId
64
+ } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
65
+
66
+ try {
67
+ var _this$options, _getClient$storage, _this$options2, _getClient$storage2;
68
+
69
+ const provider = await this.getProvider();
70
+ if (!provider) throw new base.ConnectorNotFoundError();
71
+
72
+ if (provider.on) {
73
+ provider.on('accountsChanged', this.onAccountsChanged);
74
+ provider.on('chainChanged', this.onChainChanged);
75
+ provider.on('disconnect', this.onDisconnect);
76
+ }
77
+
78
+ this.emit('message', {
79
+ type: 'connecting'
80
+ }); // Attempt to show wallet select prompt with `wallet_requestPermissions` when
81
+ // `shimDisconnect` is active and account is in disconnected state (flag in storage)
82
+
83
+ if (base._classPrivateFieldGet(this, _UNSTABLE_shimOnConnectSelectAccount) && (_this$options = this.options) !== null && _this$options !== void 0 && _this$options.shimDisconnect && !((_getClient$storage = client.getClient().storage) !== null && _getClient$storage !== void 0 && _getClient$storage.getItem(client.shimDisconnectKey))) {
84
+ const accounts = await provider.request({
85
+ method: 'eth_accounts'
86
+ }).catch(() => []);
87
+ const isConnected = !!accounts[0];
88
+ if (isConnected) await provider.request({
89
+ method: 'wallet_requestPermissions',
90
+ params: [{
91
+ eth_accounts: {}
92
+ }]
93
+ });
94
+ }
95
+
96
+ const account = await this.getAccount(); // Switch to chain if provided
97
+
98
+ let id = await this.getChainId();
99
+ let unsupported = this.isChainUnsupported(id);
100
+
101
+ if (chainId && id !== chainId) {
102
+ const chain = await this.switchChain(chainId);
103
+ id = chain.id;
104
+ unsupported = this.isChainUnsupported(id);
105
+ }
106
+
107
+ if ((_this$options2 = this.options) !== null && _this$options2 !== void 0 && _this$options2.shimDisconnect) (_getClient$storage2 = client.getClient().storage) === null || _getClient$storage2 === void 0 ? void 0 : _getClient$storage2.setItem(client.shimDisconnectKey, true);
108
+ return {
109
+ account,
110
+ chain: {
111
+ id,
112
+ unsupported
113
+ },
114
+ provider
115
+ };
116
+ } catch (error) {
117
+ if (this.isUserRejectedRequestError(error)) throw new base.UserRejectedRequestError(error);
118
+ if (error.code === -32002) throw new base.ResourceUnavailableError(error);
119
+ throw error;
120
+ }
50
121
  }
51
122
 
52
123
  async getProvider() {
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var base = require('../../../dist/base-2d484f6c.cjs.prod.js');
6
- var client = require('../../../dist/client-1feb9121.cjs.prod.js');
6
+ var client = require('../../../dist/client-0140ab1f.cjs.prod.js');
7
7
  require('eventemitter3');
8
8
  require('../../../dist/chains-865492ea.cjs.prod.js');
9
9
  require('../../../dist/rpcs-1fd0a12f.cjs.prod.js');
@@ -14,6 +14,8 @@ require('ethers/lib/utils');
14
14
 
15
15
  var _provider = /*#__PURE__*/new WeakMap();
16
16
 
17
+ var _UNSTABLE_shimOnConnectSelectAccount = /*#__PURE__*/new WeakMap();
18
+
17
19
  var _getReady = /*#__PURE__*/new WeakSet();
18
20
 
19
21
  var _findProvider = /*#__PURE__*/new WeakSet();
@@ -47,6 +49,75 @@ class MetaMaskConnector extends client.InjectedConnector {
47
49
  writable: true,
48
50
  value: void 0
49
51
  });
52
+
53
+ base._classPrivateFieldInitSpec(this, _UNSTABLE_shimOnConnectSelectAccount, {
54
+ writable: true,
55
+ value: void 0
56
+ });
57
+
58
+ base._classPrivateFieldSet(this, _UNSTABLE_shimOnConnectSelectAccount, options.UNSTABLE_shimOnConnectSelectAccount);
59
+ }
60
+
61
+ async connect() {
62
+ let {
63
+ chainId
64
+ } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
65
+
66
+ try {
67
+ var _this$options, _getClient$storage, _this$options2, _getClient$storage2;
68
+
69
+ const provider = await this.getProvider();
70
+ if (!provider) throw new base.ConnectorNotFoundError();
71
+
72
+ if (provider.on) {
73
+ provider.on('accountsChanged', this.onAccountsChanged);
74
+ provider.on('chainChanged', this.onChainChanged);
75
+ provider.on('disconnect', this.onDisconnect);
76
+ }
77
+
78
+ this.emit('message', {
79
+ type: 'connecting'
80
+ }); // Attempt to show wallet select prompt with `wallet_requestPermissions` when
81
+ // `shimDisconnect` is active and account is in disconnected state (flag in storage)
82
+
83
+ if (base._classPrivateFieldGet(this, _UNSTABLE_shimOnConnectSelectAccount) && (_this$options = this.options) !== null && _this$options !== void 0 && _this$options.shimDisconnect && !((_getClient$storage = client.getClient().storage) !== null && _getClient$storage !== void 0 && _getClient$storage.getItem(client.shimDisconnectKey))) {
84
+ const accounts = await provider.request({
85
+ method: 'eth_accounts'
86
+ }).catch(() => []);
87
+ const isConnected = !!accounts[0];
88
+ if (isConnected) await provider.request({
89
+ method: 'wallet_requestPermissions',
90
+ params: [{
91
+ eth_accounts: {}
92
+ }]
93
+ });
94
+ }
95
+
96
+ const account = await this.getAccount(); // Switch to chain if provided
97
+
98
+ let id = await this.getChainId();
99
+ let unsupported = this.isChainUnsupported(id);
100
+
101
+ if (chainId && id !== chainId) {
102
+ const chain = await this.switchChain(chainId);
103
+ id = chain.id;
104
+ unsupported = this.isChainUnsupported(id);
105
+ }
106
+
107
+ if ((_this$options2 = this.options) !== null && _this$options2 !== void 0 && _this$options2.shimDisconnect) (_getClient$storage2 = client.getClient().storage) === null || _getClient$storage2 === void 0 ? void 0 : _getClient$storage2.setItem(client.shimDisconnectKey, true);
108
+ return {
109
+ account,
110
+ chain: {
111
+ id,
112
+ unsupported
113
+ },
114
+ provider
115
+ };
116
+ } catch (error) {
117
+ if (this.isUserRejectedRequestError(error)) throw new base.UserRejectedRequestError(error);
118
+ if (error.code === -32002) throw new base.ResourceUnavailableError(error);
119
+ throw error;
120
+ }
50
121
  }
51
122
 
52
123
  async getProvider() {
@@ -1,5 +1,5 @@
1
- import { _ as _classPrivateMethodInitSpec, i as _defineProperty, m as _classPrivateMethodGet, j as _classPrivateFieldInitSpec, l as _classPrivateFieldSet, k as _classPrivateFieldGet } from '../../../dist/base-e66f9622.esm.js';
2
- import { I as InjectedConnector } from '../../../dist/client-ffba0e25.esm.js';
1
+ import { l as _classPrivateMethodInitSpec, _ as _defineProperty, m as _classPrivateMethodGet, i as _classPrivateFieldInitSpec, k as _classPrivateFieldSet, b as ConnectorNotFoundError, j as _classPrivateFieldGet, U as UserRejectedRequestError, R as ResourceUnavailableError } from '../../../dist/base-68ec937e.esm.js';
2
+ import { I as InjectedConnector, g as getClient, s as shimDisconnectKey } from '../../../dist/client-5df5c2eb.esm.js';
3
3
  import 'eventemitter3';
4
4
  import '../../../dist/chains-c389721d.esm.js';
5
5
  import '../../../dist/rpcs-b73a8f60.esm.js';
@@ -10,6 +10,8 @@ import 'ethers/lib/utils';
10
10
 
11
11
  var _provider = /*#__PURE__*/new WeakMap();
12
12
 
13
+ var _UNSTABLE_shimOnConnectSelectAccount = /*#__PURE__*/new WeakMap();
14
+
13
15
  var _getReady = /*#__PURE__*/new WeakSet();
14
16
 
15
17
  var _findProvider = /*#__PURE__*/new WeakSet();
@@ -43,6 +45,75 @@ class MetaMaskConnector extends InjectedConnector {
43
45
  writable: true,
44
46
  value: void 0
45
47
  });
48
+
49
+ _classPrivateFieldInitSpec(this, _UNSTABLE_shimOnConnectSelectAccount, {
50
+ writable: true,
51
+ value: void 0
52
+ });
53
+
54
+ _classPrivateFieldSet(this, _UNSTABLE_shimOnConnectSelectAccount, options.UNSTABLE_shimOnConnectSelectAccount);
55
+ }
56
+
57
+ async connect() {
58
+ let {
59
+ chainId
60
+ } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
61
+
62
+ try {
63
+ var _this$options, _getClient$storage, _this$options2, _getClient$storage2;
64
+
65
+ const provider = await this.getProvider();
66
+ if (!provider) throw new ConnectorNotFoundError();
67
+
68
+ if (provider.on) {
69
+ provider.on('accountsChanged', this.onAccountsChanged);
70
+ provider.on('chainChanged', this.onChainChanged);
71
+ provider.on('disconnect', this.onDisconnect);
72
+ }
73
+
74
+ this.emit('message', {
75
+ type: 'connecting'
76
+ }); // Attempt to show wallet select prompt with `wallet_requestPermissions` when
77
+ // `shimDisconnect` is active and account is in disconnected state (flag in storage)
78
+
79
+ if (_classPrivateFieldGet(this, _UNSTABLE_shimOnConnectSelectAccount) && (_this$options = this.options) !== null && _this$options !== void 0 && _this$options.shimDisconnect && !((_getClient$storage = getClient().storage) !== null && _getClient$storage !== void 0 && _getClient$storage.getItem(shimDisconnectKey))) {
80
+ const accounts = await provider.request({
81
+ method: 'eth_accounts'
82
+ }).catch(() => []);
83
+ const isConnected = !!accounts[0];
84
+ if (isConnected) await provider.request({
85
+ method: 'wallet_requestPermissions',
86
+ params: [{
87
+ eth_accounts: {}
88
+ }]
89
+ });
90
+ }
91
+
92
+ const account = await this.getAccount(); // Switch to chain if provided
93
+
94
+ let id = await this.getChainId();
95
+ let unsupported = this.isChainUnsupported(id);
96
+
97
+ if (chainId && id !== chainId) {
98
+ const chain = await this.switchChain(chainId);
99
+ id = chain.id;
100
+ unsupported = this.isChainUnsupported(id);
101
+ }
102
+
103
+ 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(shimDisconnectKey, true);
104
+ return {
105
+ account,
106
+ chain: {
107
+ id,
108
+ unsupported
109
+ },
110
+ provider
111
+ };
112
+ } catch (error) {
113
+ if (this.isUserRejectedRequestError(error)) throw new UserRejectedRequestError(error);
114
+ if (error.code === -32002) throw new ResourceUnavailableError(error);
115
+ throw error;
116
+ }
46
117
  }
47
118
 
48
119
  async getProvider() {
@@ -1,4 +1,4 @@
1
- import { i as _defineProperty, j as _classPrivateFieldInitSpec, l as _classPrivateFieldSet, k as _classPrivateFieldGet, U as UserRejectedRequestError, d as Connector, _ as _classPrivateMethodInitSpec, n as normalizeChainId, m as _classPrivateMethodGet } from '../../../dist/base-e66f9622.esm.js';
1
+ import { _ as _defineProperty, i as _classPrivateFieldInitSpec, k as _classPrivateFieldSet, j as _classPrivateFieldGet, U as UserRejectedRequestError, d as Connector, l as _classPrivateMethodInitSpec, n as normalizeChainId, m as _classPrivateMethodGet } from '../../../dist/base-68ec937e.esm.js';
2
2
  import { getAddress } from 'ethers/lib/utils';
3
3
  import EventEmitter from 'eventemitter3';
4
4
  import { providers } from 'ethers';
@@ -5,7 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var base = require('../../../dist/base-e71ae4b2.cjs.dev.js');
6
6
  var ethers = require('ethers');
7
7
  var utils = require('ethers/lib/utils');
8
- var client = require('../../../dist/client-53f2119c.cjs.dev.js');
8
+ var client = require('../../../dist/client-90ae4735.cjs.dev.js');
9
9
  require('eventemitter3');
10
10
  require('../../../dist/chains-d970ee8d.cjs.dev.js');
11
11
  require('../../../dist/rpcs-f1d24f0e.cjs.dev.js');
@@ -98,7 +98,8 @@ class WalletConnectConnector extends base.Connector {
98
98
  }
99
99
 
100
100
  const provider = await this.getProvider({
101
- chainId: targetChainId
101
+ chainId: targetChainId,
102
+ create: true
102
103
  });
103
104
  provider.on('accountsChanged', this.onAccountsChanged);
104
105
  provider.on('chainChanged', this.onChainChanged);
@@ -153,10 +154,12 @@ class WalletConnectConnector extends base.Connector {
153
154
 
154
155
  async getProvider() {
155
156
  let {
156
- chainId
157
+ chainId,
158
+ create
157
159
  } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
158
160
 
159
- if (!base._classPrivateFieldGet(this, _provider) || chainId) {
161
+ // Force create new provider
162
+ if (!base._classPrivateFieldGet(this, _provider) || chainId || create) {
160
163
  var _this$options, _this$options2;
161
164
 
162
165
  const rpc = !((_this$options = this.options) !== null && _this$options !== void 0 && _this$options.infuraId) ? this.chains.reduce((rpc, chain) => ({ ...rpc,
@@ -5,7 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var base = require('../../../dist/base-2d484f6c.cjs.prod.js');
6
6
  var ethers = require('ethers');
7
7
  var utils = require('ethers/lib/utils');
8
- var client = require('../../../dist/client-1feb9121.cjs.prod.js');
8
+ var client = require('../../../dist/client-0140ab1f.cjs.prod.js');
9
9
  require('eventemitter3');
10
10
  require('../../../dist/chains-865492ea.cjs.prod.js');
11
11
  require('../../../dist/rpcs-1fd0a12f.cjs.prod.js');
@@ -98,7 +98,8 @@ class WalletConnectConnector extends base.Connector {
98
98
  }
99
99
 
100
100
  const provider = await this.getProvider({
101
- chainId: targetChainId
101
+ chainId: targetChainId,
102
+ create: true
102
103
  });
103
104
  provider.on('accountsChanged', this.onAccountsChanged);
104
105
  provider.on('chainChanged', this.onChainChanged);
@@ -153,10 +154,12 @@ class WalletConnectConnector extends base.Connector {
153
154
 
154
155
  async getProvider() {
155
156
  let {
156
- chainId
157
+ chainId,
158
+ create
157
159
  } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
158
160
 
159
- if (!base._classPrivateFieldGet(this, _provider) || chainId) {
161
+ // Force create new provider
162
+ if (!base._classPrivateFieldGet(this, _provider) || chainId || create) {
160
163
  var _this$options, _this$options2;
161
164
 
162
165
  const rpc = !((_this$options = this.options) !== null && _this$options !== void 0 && _this$options.infuraId) ? this.chains.reduce((rpc, chain) => ({ ...rpc,
@@ -1,7 +1,7 @@
1
- import { d as Connector, _ as _classPrivateMethodInitSpec, i as _defineProperty, j as _classPrivateFieldInitSpec, n as normalizeChainId, m as _classPrivateMethodGet, U as UserRejectedRequestError, k as _classPrivateFieldGet, l as _classPrivateFieldSet, h as SwitchChainError } from '../../../dist/base-e66f9622.esm.js';
1
+ import { d as Connector, l as _classPrivateMethodInitSpec, _ as _defineProperty, i as _classPrivateFieldInitSpec, n as normalizeChainId, m as _classPrivateMethodGet, U as UserRejectedRequestError, j as _classPrivateFieldGet, k as _classPrivateFieldSet, h as SwitchChainError } from '../../../dist/base-68ec937e.esm.js';
2
2
  import { providers } from 'ethers';
3
3
  import { getAddress, hexValue } from 'ethers/lib/utils';
4
- import { g as getClient } from '../../../dist/client-ffba0e25.esm.js';
4
+ import { g as getClient } from '../../../dist/client-5df5c2eb.esm.js';
5
5
  import 'eventemitter3';
6
6
  import '../../../dist/chains-c389721d.esm.js';
7
7
  import '../../../dist/rpcs-b73a8f60.esm.js';
@@ -76,7 +76,8 @@ class WalletConnectConnector extends Connector {
76
76
  }
77
77
 
78
78
  const provider = await this.getProvider({
79
- chainId: targetChainId
79
+ chainId: targetChainId,
80
+ create: true
80
81
  });
81
82
  provider.on('accountsChanged', this.onAccountsChanged);
82
83
  provider.on('chainChanged', this.onChainChanged);
@@ -131,10 +132,12 @@ class WalletConnectConnector extends Connector {
131
132
 
132
133
  async getProvider() {
133
134
  let {
134
- chainId
135
+ chainId,
136
+ create
135
137
  } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
136
138
 
137
- if (!_classPrivateFieldGet(this, _provider) || chainId) {
139
+ // Force create new provider
140
+ if (!_classPrivateFieldGet(this, _provider) || chainId || create) {
138
141
  var _this$options, _this$options2;
139
142
 
140
143
  const rpc = !((_this$options = this.options) !== null && _this$options !== void 0 && _this$options.infuraId) ? this.chains.reduce((rpc, chain) => ({ ...rpc,
@@ -300,4 +300,4 @@ class Connector extends EventEmitter {
300
300
 
301
301
  }
302
302
 
303
- export { AddChainError as A, ConnectorAlreadyConnectedError as C, ProviderChainsNotFound as P, ResourceUnavailableError as R, SwitchChainNotSupportedError as S, UserRejectedRequestError as U, _classPrivateMethodInitSpec as _, ChainDoesNotSupportMulticallError as a, ConnectorNotFoundError as b, ChainMismatchError as c, Connector as d, ChainNotConfiguredError as e, ProviderRpcError as f, RpcError as g, SwitchChainError as h, _defineProperty as i, _classPrivateFieldInitSpec as j, _classPrivateFieldGet as k, _classPrivateFieldSet as l, _classPrivateMethodGet as m, normalizeChainId as n };
303
+ export { AddChainError as A, ConnectorAlreadyConnectedError as C, ProviderChainsNotFound as P, ResourceUnavailableError as R, SwitchChainNotSupportedError as S, UserRejectedRequestError as U, _defineProperty as _, ChainDoesNotSupportMulticallError as a, ConnectorNotFoundError as b, ChainMismatchError as c, Connector as d, ChainNotConfiguredError as e, ProviderRpcError as f, RpcError as g, SwitchChainError as h, _classPrivateFieldInitSpec as i, _classPrivateFieldGet as j, _classPrivateFieldSet as k, _classPrivateMethodInitSpec as l, _classPrivateMethodGet as m, normalizeChainId as n };
@@ -56,14 +56,12 @@ function getInjectedName(ethereum) {
56
56
  return (_getName = getName(ethereum)) !== null && _getName !== void 0 ? _getName : 'Injected';
57
57
  }
58
58
 
59
- const shimKey = 'injected.shimDisconnect';
59
+ const shimDisconnectKey = 'injected.shimDisconnect';
60
60
 
61
61
  var _provider = /*#__PURE__*/new WeakMap();
62
62
 
63
63
  var _switchingChains = /*#__PURE__*/new WeakMap();
64
64
 
65
- var _isUserRejectedRequestError = /*#__PURE__*/new WeakSet();
66
-
67
65
  class InjectedConnector extends base.Connector {
68
66
  constructor() {
69
67
  let {
@@ -77,8 +75,6 @@ class InjectedConnector extends base.Connector {
77
75
  options
78
76
  });
79
77
 
80
- base._classPrivateMethodInitSpec(this, _isUserRejectedRequestError);
81
-
82
78
  base._defineProperty(this, "id", void 0);
83
79
 
84
80
  base._defineProperty(this, "name", void 0);
@@ -124,8 +120,9 @@ class InjectedConnector extends base.Connector {
124
120
  return;
125
121
  }
126
122
 
127
- this.emit('disconnect');
128
- 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);
123
+ this.emit('disconnect'); // Remove shim signalling wallet is disconnected
124
+
125
+ 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(shimDisconnectKey);
129
126
  });
130
127
 
131
128
  let name = 'Injected';
@@ -169,9 +166,10 @@ class InjectedConnector extends base.Connector {
169
166
  const chain = await this.switchChain(chainId);
170
167
  id = chain.id;
171
168
  unsupported = this.isChainUnsupported(id);
172
- }
169
+ } // Add shim to storage signalling wallet is connected
173
170
 
174
- 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);
171
+
172
+ 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(shimDisconnectKey, true);
175
173
  return {
176
174
  account,
177
175
  chain: {
@@ -181,7 +179,7 @@ class InjectedConnector extends base.Connector {
181
179
  provider
182
180
  };
183
181
  } catch (error) {
184
- if (base._classPrivateMethodGet(this, _isUserRejectedRequestError, _isUserRejectedRequestError2).call(this, error)) throw new base.UserRejectedRequestError(error);
182
+ if (this.isUserRejectedRequestError(error)) throw new base.UserRejectedRequestError(error);
185
183
  if (error.code === -32002) throw new base.ResourceUnavailableError(error);
186
184
  throw error;
187
185
  }
@@ -194,8 +192,9 @@ class InjectedConnector extends base.Connector {
194
192
  if (!(provider !== null && provider !== void 0 && provider.removeListener)) return;
195
193
  provider.removeListener('accountsChanged', this.onAccountsChanged);
196
194
  provider.removeListener('chainChanged', this.onChainChanged);
197
- provider.removeListener('disconnect', this.onDisconnect);
198
- 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);
195
+ provider.removeListener('disconnect', this.onDisconnect); // Remove shim signalling wallet is disconnected
196
+
197
+ 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(shimDisconnectKey);
199
198
  }
200
199
 
201
200
  async getAccount() {
@@ -230,7 +229,8 @@ class InjectedConnector extends base.Connector {
230
229
  try {
231
230
  var _this$options5, _getClient$storage4;
232
231
 
233
- 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;
232
+ if ((_this$options5 = this.options) !== null && _this$options5 !== void 0 && _this$options5.shimDisconnect && // If shim does not exist in storage, wallet is disconnected
233
+ !((_getClient$storage4 = getClient().storage) !== null && _getClient$storage4 !== void 0 && _getClient$storage4.getItem(shimDisconnectKey))) return false;
234
234
  const provider = await this.getProvider();
235
235
  if (!provider) throw new base.ConnectorNotFoundError();
236
236
  const accounts = await provider.request({
@@ -292,12 +292,12 @@ class InjectedConnector extends base.Connector {
292
292
  });
293
293
  return chain;
294
294
  } catch (addError) {
295
- if (base._classPrivateMethodGet(this, _isUserRejectedRequestError, _isUserRejectedRequestError2).call(this, addError)) throw new base.UserRejectedRequestError(error);
295
+ if (this.isUserRejectedRequestError(addError)) throw new base.UserRejectedRequestError(error);
296
296
  throw new base.AddChainError();
297
297
  }
298
298
  }
299
299
 
300
- if (base._classPrivateMethodGet(this, _isUserRejectedRequestError, _isUserRejectedRequestError2).call(this, error)) throw new base.UserRejectedRequestError(error);
300
+ if (this.isUserRejectedRequestError(error)) throw new base.UserRejectedRequestError(error);
301
301
  throw new base.SwitchChainError(error);
302
302
  }
303
303
  }
@@ -325,10 +325,10 @@ class InjectedConnector extends base.Connector {
325
325
  });
326
326
  }
327
327
 
328
- }
328
+ isUserRejectedRequestError(error) {
329
+ return error.code === 4001;
330
+ }
329
331
 
330
- function _isUserRejectedRequestError2(error) {
331
- return error.code === 4001;
332
332
  }
333
333
 
334
334
  const noopStorage = {
@@ -636,18 +636,18 @@ function _addEffects2() {
636
636
  });
637
637
  }
638
638
 
639
- exports.client = void 0;
639
+ let client;
640
640
  function createClient(config) {
641
641
  const client_ = new Client(config);
642
- exports.client = client_;
642
+ client = client_;
643
643
  return client_;
644
644
  }
645
645
  function getClient() {
646
- if (!exports.client) {
646
+ if (!client) {
647
647
  throw new Error('No wagmi client found. Ensure you have set up a client: https://wagmi.sh/docs/client');
648
648
  }
649
649
 
650
- return exports.client;
650
+ return client;
651
651
  }
652
652
 
653
653
  exports.Client = Client;
@@ -656,3 +656,4 @@ exports.createClient = createClient;
656
656
  exports.createStorage = createStorage;
657
657
  exports.getClient = getClient;
658
658
  exports.noopStorage = noopStorage;
659
+ exports.shimDisconnectKey = shimDisconnectKey;
@@ -1,4 +1,4 @@
1
- import { d as Connector, _ as _classPrivateMethodInitSpec, i as _defineProperty, j as _classPrivateFieldInitSpec, n as normalizeChainId, k as _classPrivateFieldGet, l as _classPrivateFieldSet, b as ConnectorNotFoundError, m as _classPrivateMethodGet, U as UserRejectedRequestError, R as ResourceUnavailableError, e as ChainNotConfiguredError, A as AddChainError, h as SwitchChainError } from './base-e66f9622.esm.js';
1
+ import { d as Connector, _ as _defineProperty, i as _classPrivateFieldInitSpec, n as normalizeChainId, j as _classPrivateFieldGet, k as _classPrivateFieldSet, b as ConnectorNotFoundError, U as UserRejectedRequestError, R as ResourceUnavailableError, e as ChainNotConfiguredError, A as AddChainError, h as SwitchChainError, l as _classPrivateMethodInitSpec, m as _classPrivateMethodGet } from './base-68ec937e.esm.js';
2
2
  import create from 'zustand/vanilla';
3
3
  import { subscribeWithSelector, persist } from 'zustand/middleware';
4
4
  import { providers } from 'ethers';
@@ -50,14 +50,12 @@ function getInjectedName(ethereum) {
50
50
  return (_getName = getName(ethereum)) !== null && _getName !== void 0 ? _getName : 'Injected';
51
51
  }
52
52
 
53
- const shimKey = 'injected.shimDisconnect';
53
+ const shimDisconnectKey = 'injected.shimDisconnect';
54
54
 
55
55
  var _provider = /*#__PURE__*/new WeakMap();
56
56
 
57
57
  var _switchingChains = /*#__PURE__*/new WeakMap();
58
58
 
59
- var _isUserRejectedRequestError = /*#__PURE__*/new WeakSet();
60
-
61
59
  class InjectedConnector extends Connector {
62
60
  constructor() {
63
61
  let {
@@ -71,8 +69,6 @@ class InjectedConnector extends Connector {
71
69
  options
72
70
  });
73
71
 
74
- _classPrivateMethodInitSpec(this, _isUserRejectedRequestError);
75
-
76
72
  _defineProperty(this, "id", void 0);
77
73
 
78
74
  _defineProperty(this, "name", void 0);
@@ -118,8 +114,9 @@ class InjectedConnector extends Connector {
118
114
  return;
119
115
  }
120
116
 
121
- this.emit('disconnect');
122
- 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
+ this.emit('disconnect'); // Remove shim signalling wallet is disconnected
118
+
119
+ 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(shimDisconnectKey);
123
120
  });
124
121
 
125
122
  let name = 'Injected';
@@ -163,9 +160,10 @@ class InjectedConnector extends Connector {
163
160
  const chain = await this.switchChain(chainId);
164
161
  id = chain.id;
165
162
  unsupported = this.isChainUnsupported(id);
166
- }
163
+ } // Add shim to storage signalling wallet is connected
167
164
 
168
- 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);
165
+
166
+ 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(shimDisconnectKey, true);
169
167
  return {
170
168
  account,
171
169
  chain: {
@@ -175,7 +173,7 @@ class InjectedConnector extends Connector {
175
173
  provider
176
174
  };
177
175
  } catch (error) {
178
- if (_classPrivateMethodGet(this, _isUserRejectedRequestError, _isUserRejectedRequestError2).call(this, error)) throw new UserRejectedRequestError(error);
176
+ if (this.isUserRejectedRequestError(error)) throw new UserRejectedRequestError(error);
179
177
  if (error.code === -32002) throw new ResourceUnavailableError(error);
180
178
  throw error;
181
179
  }
@@ -188,8 +186,9 @@ class InjectedConnector extends Connector {
188
186
  if (!(provider !== null && provider !== void 0 && provider.removeListener)) return;
189
187
  provider.removeListener('accountsChanged', this.onAccountsChanged);
190
188
  provider.removeListener('chainChanged', this.onChainChanged);
191
- provider.removeListener('disconnect', this.onDisconnect);
192
- 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);
189
+ provider.removeListener('disconnect', this.onDisconnect); // Remove shim signalling wallet is disconnected
190
+
191
+ 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(shimDisconnectKey);
193
192
  }
194
193
 
195
194
  async getAccount() {
@@ -224,7 +223,8 @@ class InjectedConnector extends Connector {
224
223
  try {
225
224
  var _this$options5, _getClient$storage4;
226
225
 
227
- 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;
226
+ if ((_this$options5 = this.options) !== null && _this$options5 !== void 0 && _this$options5.shimDisconnect && // If shim does not exist in storage, wallet is disconnected
227
+ !((_getClient$storage4 = getClient().storage) !== null && _getClient$storage4 !== void 0 && _getClient$storage4.getItem(shimDisconnectKey))) return false;
228
228
  const provider = await this.getProvider();
229
229
  if (!provider) throw new ConnectorNotFoundError();
230
230
  const accounts = await provider.request({
@@ -286,12 +286,12 @@ class InjectedConnector extends Connector {
286
286
  });
287
287
  return chain;
288
288
  } catch (addError) {
289
- if (_classPrivateMethodGet(this, _isUserRejectedRequestError, _isUserRejectedRequestError2).call(this, addError)) throw new UserRejectedRequestError(error);
289
+ if (this.isUserRejectedRequestError(addError)) throw new UserRejectedRequestError(error);
290
290
  throw new AddChainError();
291
291
  }
292
292
  }
293
293
 
294
- if (_classPrivateMethodGet(this, _isUserRejectedRequestError, _isUserRejectedRequestError2).call(this, error)) throw new UserRejectedRequestError(error);
294
+ if (this.isUserRejectedRequestError(error)) throw new UserRejectedRequestError(error);
295
295
  throw new SwitchChainError(error);
296
296
  }
297
297
  }
@@ -319,10 +319,10 @@ class InjectedConnector extends Connector {
319
319
  });
320
320
  }
321
321
 
322
- }
322
+ isUserRejectedRequestError(error) {
323
+ return error.code === 4001;
324
+ }
323
325
 
324
- function _isUserRejectedRequestError2(error) {
325
- return error.code === 4001;
326
326
  }
327
327
 
328
328
  const noopStorage = {
@@ -644,4 +644,4 @@ function getClient() {
644
644
  return client;
645
645
  }
646
646
 
647
- export { Client as C, InjectedConnector as I, createClient as a, createStorage as b, client as c, getClient as g, noopStorage as n };
647
+ export { Client as C, InjectedConnector as I, createStorage as a, createClient as c, getClient as g, noopStorage as n, shimDisconnectKey as s };
@@ -56,14 +56,12 @@ function getInjectedName(ethereum) {
56
56
  return (_getName = getName(ethereum)) !== null && _getName !== void 0 ? _getName : 'Injected';
57
57
  }
58
58
 
59
- const shimKey = 'injected.shimDisconnect';
59
+ const shimDisconnectKey = 'injected.shimDisconnect';
60
60
 
61
61
  var _provider = /*#__PURE__*/new WeakMap();
62
62
 
63
63
  var _switchingChains = /*#__PURE__*/new WeakMap();
64
64
 
65
- var _isUserRejectedRequestError = /*#__PURE__*/new WeakSet();
66
-
67
65
  class InjectedConnector extends base.Connector {
68
66
  constructor() {
69
67
  let {
@@ -77,8 +75,6 @@ class InjectedConnector extends base.Connector {
77
75
  options
78
76
  });
79
77
 
80
- base._classPrivateMethodInitSpec(this, _isUserRejectedRequestError);
81
-
82
78
  base._defineProperty(this, "id", void 0);
83
79
 
84
80
  base._defineProperty(this, "name", void 0);
@@ -124,8 +120,9 @@ class InjectedConnector extends base.Connector {
124
120
  return;
125
121
  }
126
122
 
127
- this.emit('disconnect');
128
- 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);
123
+ this.emit('disconnect'); // Remove shim signalling wallet is disconnected
124
+
125
+ 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(shimDisconnectKey);
129
126
  });
130
127
 
131
128
  let name = 'Injected';
@@ -169,9 +166,10 @@ class InjectedConnector extends base.Connector {
169
166
  const chain = await this.switchChain(chainId);
170
167
  id = chain.id;
171
168
  unsupported = this.isChainUnsupported(id);
172
- }
169
+ } // Add shim to storage signalling wallet is connected
173
170
 
174
- 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);
171
+
172
+ 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(shimDisconnectKey, true);
175
173
  return {
176
174
  account,
177
175
  chain: {
@@ -181,7 +179,7 @@ class InjectedConnector extends base.Connector {
181
179
  provider
182
180
  };
183
181
  } catch (error) {
184
- if (base._classPrivateMethodGet(this, _isUserRejectedRequestError, _isUserRejectedRequestError2).call(this, error)) throw new base.UserRejectedRequestError(error);
182
+ if (this.isUserRejectedRequestError(error)) throw new base.UserRejectedRequestError(error);
185
183
  if (error.code === -32002) throw new base.ResourceUnavailableError(error);
186
184
  throw error;
187
185
  }
@@ -194,8 +192,9 @@ class InjectedConnector extends base.Connector {
194
192
  if (!(provider !== null && provider !== void 0 && provider.removeListener)) return;
195
193
  provider.removeListener('accountsChanged', this.onAccountsChanged);
196
194
  provider.removeListener('chainChanged', this.onChainChanged);
197
- provider.removeListener('disconnect', this.onDisconnect);
198
- 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);
195
+ provider.removeListener('disconnect', this.onDisconnect); // Remove shim signalling wallet is disconnected
196
+
197
+ 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(shimDisconnectKey);
199
198
  }
200
199
 
201
200
  async getAccount() {
@@ -230,7 +229,8 @@ class InjectedConnector extends base.Connector {
230
229
  try {
231
230
  var _this$options5, _getClient$storage4;
232
231
 
233
- 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;
232
+ if ((_this$options5 = this.options) !== null && _this$options5 !== void 0 && _this$options5.shimDisconnect && // If shim does not exist in storage, wallet is disconnected
233
+ !((_getClient$storage4 = getClient().storage) !== null && _getClient$storage4 !== void 0 && _getClient$storage4.getItem(shimDisconnectKey))) return false;
234
234
  const provider = await this.getProvider();
235
235
  if (!provider) throw new base.ConnectorNotFoundError();
236
236
  const accounts = await provider.request({
@@ -292,12 +292,12 @@ class InjectedConnector extends base.Connector {
292
292
  });
293
293
  return chain;
294
294
  } catch (addError) {
295
- if (base._classPrivateMethodGet(this, _isUserRejectedRequestError, _isUserRejectedRequestError2).call(this, addError)) throw new base.UserRejectedRequestError(error);
295
+ if (this.isUserRejectedRequestError(addError)) throw new base.UserRejectedRequestError(error);
296
296
  throw new base.AddChainError();
297
297
  }
298
298
  }
299
299
 
300
- if (base._classPrivateMethodGet(this, _isUserRejectedRequestError, _isUserRejectedRequestError2).call(this, error)) throw new base.UserRejectedRequestError(error);
300
+ if (this.isUserRejectedRequestError(error)) throw new base.UserRejectedRequestError(error);
301
301
  throw new base.SwitchChainError(error);
302
302
  }
303
303
  }
@@ -325,10 +325,10 @@ class InjectedConnector extends base.Connector {
325
325
  });
326
326
  }
327
327
 
328
- }
328
+ isUserRejectedRequestError(error) {
329
+ return error.code === 4001;
330
+ }
329
331
 
330
- function _isUserRejectedRequestError2(error) {
331
- return error.code === 4001;
332
332
  }
333
333
 
334
334
  const noopStorage = {
@@ -636,18 +636,18 @@ function _addEffects2() {
636
636
  });
637
637
  }
638
638
 
639
- exports.client = void 0;
639
+ let client;
640
640
  function createClient(config) {
641
641
  const client_ = new Client(config);
642
- exports.client = client_;
642
+ client = client_;
643
643
  return client_;
644
644
  }
645
645
  function getClient() {
646
- if (!exports.client) {
646
+ if (!client) {
647
647
  throw new Error('No wagmi client found. Ensure you have set up a client: https://wagmi.sh/docs/client');
648
648
  }
649
649
 
650
- return exports.client;
650
+ return client;
651
651
  }
652
652
 
653
653
  exports.Client = Client;
@@ -656,3 +656,4 @@ exports.createClient = createClient;
656
656
  exports.createStorage = createStorage;
657
657
  exports.getClient = getClient;
658
658
  exports.noopStorage = noopStorage;
659
+ exports.shimDisconnectKey = shimDisconnectKey;
@@ -18,6 +18,7 @@ export declare type InjectedConnectorOptions = {
18
18
  */
19
19
  shimDisconnect?: boolean;
20
20
  };
21
+ export declare const shimDisconnectKey = "injected.shimDisconnect";
21
22
  export declare class InjectedConnector extends Connector<Window['ethereum'], InjectedConnectorOptions | undefined> {
22
23
  #private;
23
24
  readonly id: string;
@@ -53,4 +54,5 @@ export declare class InjectedConnector extends Connector<Window['ethereum'], Inj
53
54
  protected onAccountsChanged: (accounts: string[]) => void;
54
55
  protected onChainChanged: (chainId: number | string) => void;
55
56
  protected onDisconnect: () => void;
57
+ protected isUserRejectedRequestError(error: unknown): boolean;
56
58
  }
@@ -1,6 +1,11 @@
1
1
  import { Chain } from '../types';
2
2
  import { InjectedConnector, InjectedConnectorOptions } from './injected';
3
- export declare type MetaMaskConnectorOptions = Pick<InjectedConnectorOptions, 'shimChainChangedDisconnect' | 'shimDisconnect'>;
3
+ export declare type MetaMaskConnectorOptions = Pick<InjectedConnectorOptions, 'shimChainChangedDisconnect' | 'shimDisconnect'> & {
4
+ /**
5
+ * While "disconnected" with `shimDisconnect`, allows user to select a different MetaMask account (than the currently connected account) when trying to connect.
6
+ */
7
+ UNSTABLE_shimOnConnectSelectAccount?: boolean;
8
+ };
4
9
  export declare class MetaMaskConnector extends InjectedConnector {
5
10
  #private;
6
11
  readonly id = "metaMask";
@@ -9,5 +14,15 @@ export declare class MetaMaskConnector extends InjectedConnector {
9
14
  chains?: Chain[];
10
15
  options?: MetaMaskConnectorOptions;
11
16
  });
17
+ connect({ chainId }?: {
18
+ chainId?: number;
19
+ }): Promise<{
20
+ account: string;
21
+ chain: {
22
+ id: number;
23
+ unsupported: boolean;
24
+ };
25
+ provider: Ethereum;
26
+ }>;
12
27
  getProvider(): Promise<Ethereum | undefined>;
13
28
  }
@@ -25,8 +25,9 @@ export declare class WalletConnectConnector extends Connector<WalletConnectProvi
25
25
  disconnect(): Promise<void>;
26
26
  getAccount(): Promise<string>;
27
27
  getChainId(): Promise<number>;
28
- getProvider({ chainId }?: {
28
+ getProvider({ chainId, create, }?: {
29
29
  chainId?: number;
30
+ create?: boolean;
30
31
  }): Promise<WalletConnectProvider>;
31
32
  getSigner({ chainId }?: {
32
33
  chainId?: number;
@@ -35,7 +35,7 @@ export declare type Chain = {
35
35
  /** Flag for test networks */
36
36
  testnet?: boolean;
37
37
  };
38
- export declare type ChainProviderFn<TProvider extends Provider = Provider, TWebSocketProvider extends WebSocketProvider = WebSocketProvider, TChain extends Chain = Chain> = (chain: TChain) => {
38
+ export declare type ChainProviderFn<TProvider extends Provider = providers.BaseProvider, TWebSocketProvider extends WebSocketProvider = providers.WebSocketProvider, TChain extends Chain = Chain> = (chain: TChain) => {
39
39
  chain: TChain;
40
40
  provider: () => ProviderWithFallbackConfig<TProvider>;
41
41
  webSocketProvider?: () => TWebSocketProvider;
@@ -65,6 +65,17 @@ declare global {
65
65
  /** Currently ignored. */
66
66
  iconUrls?: string[];
67
67
  };
68
+ type WalletPermissionCaveat = {
69
+ type: string;
70
+ value: any;
71
+ };
72
+ type WalletPermission = {
73
+ caveats: WalletPermissionCaveat[];
74
+ date: number;
75
+ id: string;
76
+ invoker: `http://${string}` | `https://${string}`;
77
+ parentCapability: 'eth_accounts' | string;
78
+ };
68
79
  type WatchAssetParams = {
69
80
  /** In the future, other standards will be supported */
70
81
  type: 'ERC20';
@@ -138,6 +149,19 @@ declare global {
138
149
  request(args: {
139
150
  method: 'web3_clientVersion';
140
151
  }): Promise<string>;
152
+ /**
153
+ * EIP-2255: Wallet Permissions System
154
+ * https://eips.ethereum.org/EIPS/eip-2255
155
+ */
156
+ request(args: {
157
+ method: 'wallet_requestPermissions';
158
+ params: [{
159
+ eth_accounts: Record<string, any>;
160
+ }];
161
+ }): Promise<WalletPermission[]>;
162
+ request(args: {
163
+ method: 'wallet_getPermissions';
164
+ }): Promise<WalletPermission[]>;
141
165
  /**
142
166
  * EIP-3085: Wallet Add Ethereum Chain RPC Method
143
167
  * https://eips.ethereum.org/EIPS/eip-3085
@@ -20,7 +20,7 @@ export declare function configureChains<TProvider extends Provider = Provider, T
20
20
  });
21
21
  readonly webSocketProvider: ({ chainId }: {
22
22
  chainId?: number | undefined;
23
- }) => {
23
+ }) => (TWebSocketProvider & {
24
24
  chains: TChain[];
25
- } | undefined;
25
+ }) | undefined;
26
26
  };
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var client = require('./client-53f2119c.cjs.dev.js');
5
+ var client = require('./client-90ae4735.cjs.dev.js');
6
6
  var base = require('./base-e71ae4b2.cjs.dev.js');
7
7
  var ethers$1 = require('ethers/lib/ethers');
8
8
  var utils = require('ethers/lib/utils');
@@ -84,20 +84,17 @@ function configureChains(defaultChains, providers) {
84
84
  });
85
85
  },
86
86
  webSocketProvider: _ref3 => {
87
- var _defaultChains$2, _chainWebSocketProvid, _chainWebSocketProvid2;
87
+ var _defaultChains$2, _chainWebSocketProvid;
88
88
 
89
89
  let {
90
90
  chainId
91
91
  } = _ref3;
92
92
  const activeChainId = chainId && chains.some(x => x.id === chainId) ? chainId : (_defaultChains$2 = defaultChains[0]) === null || _defaultChains$2 === void 0 ? void 0 : _defaultChains$2.id;
93
93
  const chainWebSocketProviders = webSocketProviders_[activeChainId];
94
- if (!chainWebSocketProviders) return undefined;
95
- if (chainWebSocketProviders.length === 1) return Object.assign(((_chainWebSocketProvid = chainWebSocketProviders[0]) === null || _chainWebSocketProvid === void 0 ? void 0 : _chainWebSocketProvid.call(chainWebSocketProviders)) || {}, {
96
- chains
97
- }); // WebSockets do not work with `fallbackProvider`
94
+ if (!chainWebSocketProviders) return undefined; // WebSockets do not work with `fallbackProvider`
98
95
  // Default to first available
99
96
 
100
- return Object.assign(((_chainWebSocketProvid2 = chainWebSocketProviders[0]) === null || _chainWebSocketProvid2 === void 0 ? void 0 : _chainWebSocketProvid2.call(chainWebSocketProviders)) || {}, {
97
+ return Object.assign(((_chainWebSocketProvid = chainWebSocketProviders[0]) === null || _chainWebSocketProvid === void 0 ? void 0 : _chainWebSocketProvid.call(chainWebSocketProviders)) || {}, {
101
98
  chains
102
99
  });
103
100
  }
@@ -186,29 +183,30 @@ async function connect(_ref) {
186
183
  chainId,
187
184
  connector
188
185
  } = _ref;
189
- const activeConnector = client.client.connector;
186
+ const client$1 = client.getClient();
187
+ const activeConnector = client$1.connector;
190
188
  if (connector.id === (activeConnector === null || activeConnector === void 0 ? void 0 : activeConnector.id)) throw new base.ConnectorAlreadyConnectedError();
191
189
 
192
190
  try {
193
- client.client.setState(x => ({ ...x,
191
+ client$1.setState(x => ({ ...x,
194
192
  status: 'connecting'
195
193
  }));
196
194
  const data = await connector.connect({
197
195
  chainId
198
196
  });
199
- client.client.setLastUsedConnector(connector.id);
200
- client.client.setState(x => ({ ...x,
197
+ client$1.setLastUsedConnector(connector.id);
198
+ client$1.setState(x => ({ ...x,
201
199
  connector,
202
200
  chains: connector === null || connector === void 0 ? void 0 : connector.chains,
203
201
  data,
204
202
  status: 'connected'
205
203
  }));
206
- client.client.storage.setItem('connected', true);
204
+ client$1.storage.setItem('connected', true);
207
205
  return { ...data,
208
206
  connector
209
207
  };
210
208
  } catch (err) {
211
- client.client.setState(x => ({ ...x,
209
+ client$1.setState(x => ({ ...x,
212
210
  status: 'disconnected'
213
211
  }));
214
212
  throw err;
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var client = require('./client-1feb9121.cjs.prod.js');
5
+ var client = require('./client-0140ab1f.cjs.prod.js');
6
6
  var base = require('./base-2d484f6c.cjs.prod.js');
7
7
  var ethers$1 = require('ethers/lib/ethers');
8
8
  var utils = require('ethers/lib/utils');
@@ -84,20 +84,17 @@ function configureChains(defaultChains, providers) {
84
84
  });
85
85
  },
86
86
  webSocketProvider: _ref3 => {
87
- var _defaultChains$2, _chainWebSocketProvid, _chainWebSocketProvid2;
87
+ var _defaultChains$2, _chainWebSocketProvid;
88
88
 
89
89
  let {
90
90
  chainId
91
91
  } = _ref3;
92
92
  const activeChainId = chainId && chains.some(x => x.id === chainId) ? chainId : (_defaultChains$2 = defaultChains[0]) === null || _defaultChains$2 === void 0 ? void 0 : _defaultChains$2.id;
93
93
  const chainWebSocketProviders = webSocketProviders_[activeChainId];
94
- if (!chainWebSocketProviders) return undefined;
95
- if (chainWebSocketProviders.length === 1) return Object.assign(((_chainWebSocketProvid = chainWebSocketProviders[0]) === null || _chainWebSocketProvid === void 0 ? void 0 : _chainWebSocketProvid.call(chainWebSocketProviders)) || {}, {
96
- chains
97
- }); // WebSockets do not work with `fallbackProvider`
94
+ if (!chainWebSocketProviders) return undefined; // WebSockets do not work with `fallbackProvider`
98
95
  // Default to first available
99
96
 
100
- return Object.assign(((_chainWebSocketProvid2 = chainWebSocketProviders[0]) === null || _chainWebSocketProvid2 === void 0 ? void 0 : _chainWebSocketProvid2.call(chainWebSocketProviders)) || {}, {
97
+ return Object.assign(((_chainWebSocketProvid = chainWebSocketProviders[0]) === null || _chainWebSocketProvid === void 0 ? void 0 : _chainWebSocketProvid.call(chainWebSocketProviders)) || {}, {
101
98
  chains
102
99
  });
103
100
  }
@@ -186,29 +183,30 @@ async function connect(_ref) {
186
183
  chainId,
187
184
  connector
188
185
  } = _ref;
189
- const activeConnector = client.client.connector;
186
+ const client$1 = client.getClient();
187
+ const activeConnector = client$1.connector;
190
188
  if (connector.id === (activeConnector === null || activeConnector === void 0 ? void 0 : activeConnector.id)) throw new base.ConnectorAlreadyConnectedError();
191
189
 
192
190
  try {
193
- client.client.setState(x => ({ ...x,
191
+ client$1.setState(x => ({ ...x,
194
192
  status: 'connecting'
195
193
  }));
196
194
  const data = await connector.connect({
197
195
  chainId
198
196
  });
199
- client.client.setLastUsedConnector(connector.id);
200
- client.client.setState(x => ({ ...x,
197
+ client$1.setLastUsedConnector(connector.id);
198
+ client$1.setState(x => ({ ...x,
201
199
  connector,
202
200
  chains: connector === null || connector === void 0 ? void 0 : connector.chains,
203
201
  data,
204
202
  status: 'connected'
205
203
  }));
206
- client.client.storage.setItem('connected', true);
204
+ client$1.storage.setItem('connected', true);
207
205
  return { ...data,
208
206
  connector
209
207
  };
210
208
  } catch (err) {
211
- client.client.setState(x => ({ ...x,
209
+ client$1.setState(x => ({ ...x,
212
210
  status: 'disconnected'
213
211
  }));
214
212
  throw err;
@@ -1,7 +1,7 @@
1
- import { c as client, g as getClient } from './client-ffba0e25.esm.js';
2
- export { C as Client, I as InjectedConnector, a as createClient, b as createStorage, n as noopStorage } from './client-ffba0e25.esm.js';
3
- import { C as ConnectorAlreadyConnectedError, P as ProviderChainsNotFound, a as ChainDoesNotSupportMulticallError, b as ConnectorNotFoundError, c as ChainMismatchError, U as UserRejectedRequestError, n as normalizeChainId, S as SwitchChainNotSupportedError } from './base-e66f9622.esm.js';
4
- export { A as AddChainError, a as ChainDoesNotSupportMulticallError, c as ChainMismatchError, e as ChainNotConfiguredError, d as Connector, C as ConnectorAlreadyConnectedError, b as ConnectorNotFoundError, P as ProviderChainsNotFound, f as ProviderRpcError, R as ResourceUnavailableError, g as RpcError, h as SwitchChainError, S as SwitchChainNotSupportedError, U as UserRejectedRequestError, n as normalizeChainId } from './base-e66f9622.esm.js';
1
+ import { g as getClient } from './client-5df5c2eb.esm.js';
2
+ export { C as Client, I as InjectedConnector, c as createClient, a as createStorage, n as noopStorage } from './client-5df5c2eb.esm.js';
3
+ import { C as ConnectorAlreadyConnectedError, P as ProviderChainsNotFound, a as ChainDoesNotSupportMulticallError, b as ConnectorNotFoundError, c as ChainMismatchError, U as UserRejectedRequestError, n as normalizeChainId, S as SwitchChainNotSupportedError } from './base-68ec937e.esm.js';
4
+ export { A as AddChainError, a as ChainDoesNotSupportMulticallError, c as ChainMismatchError, e as ChainNotConfiguredError, d as Connector, C as ConnectorAlreadyConnectedError, b as ConnectorNotFoundError, P as ProviderChainsNotFound, f as ProviderRpcError, R as ResourceUnavailableError, g as RpcError, h as SwitchChainError, S as SwitchChainNotSupportedError, U as UserRejectedRequestError, n as normalizeChainId } from './base-68ec937e.esm.js';
5
5
  import { logger, Contract as Contract$1 } from 'ethers/lib/ethers';
6
6
  import { isAddress, Logger, formatUnits, getAddress } from 'ethers/lib/utils';
7
7
  import { providers, Contract } from 'ethers';
@@ -78,20 +78,17 @@ function configureChains(defaultChains, providers) {
78
78
  });
79
79
  },
80
80
  webSocketProvider: _ref3 => {
81
- var _defaultChains$2, _chainWebSocketProvid, _chainWebSocketProvid2;
81
+ var _defaultChains$2, _chainWebSocketProvid;
82
82
 
83
83
  let {
84
84
  chainId
85
85
  } = _ref3;
86
86
  const activeChainId = chainId && chains.some(x => x.id === chainId) ? chainId : (_defaultChains$2 = defaultChains[0]) === null || _defaultChains$2 === void 0 ? void 0 : _defaultChains$2.id;
87
87
  const chainWebSocketProviders = webSocketProviders_[activeChainId];
88
- if (!chainWebSocketProviders) return undefined;
89
- if (chainWebSocketProviders.length === 1) return Object.assign(((_chainWebSocketProvid = chainWebSocketProviders[0]) === null || _chainWebSocketProvid === void 0 ? void 0 : _chainWebSocketProvid.call(chainWebSocketProviders)) || {}, {
90
- chains
91
- }); // WebSockets do not work with `fallbackProvider`
88
+ if (!chainWebSocketProviders) return undefined; // WebSockets do not work with `fallbackProvider`
92
89
  // Default to first available
93
90
 
94
- return Object.assign(((_chainWebSocketProvid2 = chainWebSocketProviders[0]) === null || _chainWebSocketProvid2 === void 0 ? void 0 : _chainWebSocketProvid2.call(chainWebSocketProviders)) || {}, {
91
+ return Object.assign(((_chainWebSocketProvid = chainWebSocketProviders[0]) === null || _chainWebSocketProvid === void 0 ? void 0 : _chainWebSocketProvid.call(chainWebSocketProviders)) || {}, {
95
92
  chains
96
93
  });
97
94
  }
@@ -180,6 +177,7 @@ async function connect(_ref) {
180
177
  chainId,
181
178
  connector
182
179
  } = _ref;
180
+ const client = getClient();
183
181
  const activeConnector = client.connector;
184
182
  if (connector.id === (activeConnector === null || activeConnector === void 0 ? void 0 : activeConnector.id)) throw new ConnectorAlreadyConnectedError();
185
183
 
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.4.1",
5
+ "version": "0.4.4",
6
6
  "repository": "tmm/wagmi",
7
7
  "author": "awkweb.eth",
8
8
  "ethereum": "awkweb.eth",