@wagmi/core 0.3.5 → 0.3.8
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.
- package/chains/dist/wagmi-core-chains.cjs.dev.js +2 -1
- package/chains/dist/wagmi-core-chains.cjs.prod.js +2 -1
- package/chains/dist/wagmi-core-chains.esm.js +1 -1
- package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.cjs.dev.js +33 -11
- package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.cjs.prod.js +33 -11
- package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.esm.js +33 -11
- package/connectors/metaMask/dist/wagmi-core-connectors-metaMask.cjs.dev.js +11 -9
- package/connectors/metaMask/dist/wagmi-core-connectors-metaMask.cjs.prod.js +11 -9
- package/connectors/metaMask/dist/wagmi-core-connectors-metaMask.esm.js +11 -9
- package/connectors/mock/dist/wagmi-core-connectors-mock.cjs.dev.js +20 -7
- package/connectors/mock/dist/wagmi-core-connectors-mock.cjs.prod.js +20 -7
- package/connectors/mock/dist/wagmi-core-connectors-mock.esm.js +20 -7
- package/connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.cjs.dev.js +29 -6
- package/connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.cjs.prod.js +29 -6
- package/connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.esm.js +29 -6
- package/dist/{base-41fb6637.esm.js → base-4c248b82.esm.js} +7 -5
- package/dist/{base-321ac87a.cjs.dev.js → base-9fa7951e.cjs.dev.js} +6 -4
- package/dist/{base-6841ebe0.cjs.prod.js → base-b7c3f31e.cjs.prod.js} +6 -4
- package/dist/{chains-a0a80d94.esm.js → chains-42648bc5.esm.js} +17 -3
- package/dist/{chains-0dd661ab.cjs.prod.js → chains-7204b2dd.cjs.prod.js} +17 -2
- package/dist/{chains-98e2e613.cjs.dev.js → chains-b4a51a84.cjs.dev.js} +17 -2
- package/dist/{client-a06c45f3.cjs.prod.js → client-a774f14a.cjs.prod.js} +71 -14
- package/dist/{client-4172f963.cjs.dev.js → client-d5a20a13.cjs.dev.js} +71 -14
- package/dist/{client-87c1ff8b.esm.js → client-e01209d5.esm.js} +71 -14
- package/dist/declarations/src/actions/accounts/connect.d.ts +3 -1
- package/dist/declarations/src/chains.d.ts +1 -1
- package/dist/declarations/src/client.d.ts +1 -0
- package/dist/declarations/src/connectors/base.d.ts +7 -2
- package/dist/declarations/src/connectors/coinbaseWallet.d.ts +4 -2
- package/dist/declarations/src/connectors/injected.d.ts +9 -1
- package/dist/declarations/src/connectors/metaMask.d.ts +2 -2
- package/dist/declarations/src/connectors/mock/connector.d.ts +6 -2
- package/dist/declarations/src/connectors/mock/provider.d.ts +1 -1
- package/dist/declarations/src/connectors/walletConnect.d.ts +7 -2
- package/dist/declarations/src/constants/chains.d.ts +3 -0
- package/dist/declarations/src/types/index.d.ts +2 -0
- package/dist/wagmi-core.cjs.dev.js +20 -9
- package/dist/wagmi-core.cjs.prod.js +20 -9
- package/dist/wagmi-core.esm.js +23 -12
- package/package.json +3 -3
- package/providers/jsonRpc/dist/wagmi-core-providers-jsonRpc.cjs.dev.js +1 -0
- package/providers/jsonRpc/dist/wagmi-core-providers-jsonRpc.cjs.prod.js +1 -0
- package/providers/jsonRpc/dist/wagmi-core-providers-jsonRpc.esm.js +1 -0
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var base = require('./base-
|
|
3
|
+
var base = require('./base-b7c3f31e.cjs.prod.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-
|
|
8
|
+
var chains = require('./chains-7204b2dd.cjs.prod.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
|
-
|
|
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$
|
|
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$
|
|
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
|
-
|
|
149
|
-
|
|
150
|
-
|
|
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$
|
|
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$
|
|
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$
|
|
238
|
+
var _this$options5, _getClient$storage4;
|
|
208
239
|
|
|
209
|
-
if ((_this$
|
|
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
|
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var base = require('./base-
|
|
3
|
+
var base = require('./base-9fa7951e.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-
|
|
8
|
+
var chains = require('./chains-b4a51a84.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
|
-
|
|
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$
|
|
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$
|
|
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
|
-
|
|
149
|
-
|
|
150
|
-
|
|
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$
|
|
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$
|
|
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$
|
|
238
|
+
var _this$options5, _getClient$storage4;
|
|
208
239
|
|
|
209
|
-
if ((_this$
|
|
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
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { b as Connector, _ as _classPrivateMethodInitSpec, f as _defineProperty, g as _classPrivateFieldInitSpec, n as normalizeChainId,
|
|
1
|
+
import { b as Connector, _ as _classPrivateMethodInitSpec, f as _defineProperty, g as _classPrivateFieldInitSpec, n as normalizeChainId, h as _classPrivateFieldGet, i as _classPrivateFieldSet, a as ConnectorNotFoundError, j as _classPrivateMethodGet, U as UserRejectedRequestError, R as ResourceUnavailableError, c as ChainNotConfiguredError, A as AddChainError, e as SwitchChainError } from './base-4c248b82.esm.js';
|
|
2
2
|
import { providers, getDefaultProvider } from 'ethers';
|
|
3
3
|
import create from 'zustand/vanilla';
|
|
4
4
|
import { subscribeWithSelector, persist } from 'zustand/middleware';
|
|
5
5
|
import { getAddress, hexValue } from 'ethers/lib/utils';
|
|
6
|
-
import { a as allChains } from './chains-
|
|
6
|
+
import { a as allChains } from './chains-42648bc5.esm.js';
|
|
7
7
|
|
|
8
8
|
function getInjectedName(ethereum) {
|
|
9
9
|
var _ethereum$providers, _getName;
|
|
@@ -23,6 +23,8 @@ function getInjectedName(ethereum) {
|
|
|
23
23
|
|
|
24
24
|
|
|
25
25
|
if ((_ethereum$providers = ethereum.providers) !== null && _ethereum$providers !== void 0 && _ethereum$providers.length) {
|
|
26
|
+
var _names$;
|
|
27
|
+
|
|
26
28
|
// Deduplicate names using Set
|
|
27
29
|
// Coinbase Wallet puts multiple providers in `ethereum.providers`
|
|
28
30
|
const nameSet = new Set();
|
|
@@ -40,7 +42,8 @@ function getInjectedName(ethereum) {
|
|
|
40
42
|
}
|
|
41
43
|
|
|
42
44
|
const names = [...nameSet];
|
|
43
|
-
|
|
45
|
+
if (names.length) return names;
|
|
46
|
+
return (_names$ = names[0]) !== null && _names$ !== void 0 ? _names$ : 'Injected';
|
|
44
47
|
}
|
|
45
48
|
|
|
46
49
|
return (_getName = getName(ethereum)) !== null && _getName !== void 0 ? _getName : 'Injected';
|
|
@@ -58,6 +61,8 @@ const shimKey = 'injected.shimDisconnect';
|
|
|
58
61
|
|
|
59
62
|
var _provider = /*#__PURE__*/new WeakMap();
|
|
60
63
|
|
|
64
|
+
var _switchingChains = /*#__PURE__*/new WeakMap();
|
|
65
|
+
|
|
61
66
|
var _isUserRejectedRequestError = /*#__PURE__*/new WeakSet();
|
|
62
67
|
|
|
63
68
|
class InjectedConnector extends Connector {
|
|
@@ -86,6 +91,11 @@ class InjectedConnector extends Connector {
|
|
|
86
91
|
value: void 0
|
|
87
92
|
});
|
|
88
93
|
|
|
94
|
+
_classPrivateFieldInitSpec(this, _switchingChains, {
|
|
95
|
+
writable: true,
|
|
96
|
+
value: void 0
|
|
97
|
+
});
|
|
98
|
+
|
|
89
99
|
_defineProperty(this, "onAccountsChanged", accounts => {
|
|
90
100
|
if (accounts.length === 0) this.emit('disconnect');else this.emit('change', {
|
|
91
101
|
account: getAddress(accounts[0])
|
|
@@ -104,10 +114,19 @@ class InjectedConnector extends Connector {
|
|
|
104
114
|
});
|
|
105
115
|
|
|
106
116
|
_defineProperty(this, "onDisconnect", () => {
|
|
107
|
-
var _this$options, _getClient$storage;
|
|
117
|
+
var _this$options, _this$options2, _getClient$storage;
|
|
118
|
+
|
|
119
|
+
// We need this as MetaMask can emit the "disconnect" event
|
|
120
|
+
// upon switching chains. This workaround ensures that the
|
|
121
|
+
// user currently isn't in the process of switching chains.
|
|
122
|
+
if ((_this$options = this.options) !== null && _this$options !== void 0 && _this$options.shimChainChangedDisconnect && _classPrivateFieldGet(this, _switchingChains)) {
|
|
123
|
+
_classPrivateFieldSet(this, _switchingChains, false);
|
|
124
|
+
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
108
127
|
|
|
109
128
|
this.emit('disconnect');
|
|
110
|
-
if ((_this$
|
|
129
|
+
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);
|
|
111
130
|
});
|
|
112
131
|
|
|
113
132
|
let name = 'Injected';
|
|
@@ -123,8 +142,12 @@ class InjectedConnector extends Connector {
|
|
|
123
142
|
}
|
|
124
143
|
|
|
125
144
|
async connect() {
|
|
145
|
+
let {
|
|
146
|
+
chainId
|
|
147
|
+
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
148
|
+
|
|
126
149
|
try {
|
|
127
|
-
var _this$
|
|
150
|
+
var _this$options3, _getClient$storage2;
|
|
128
151
|
|
|
129
152
|
const provider = await this.getProvider();
|
|
130
153
|
if (!provider) throw new ConnectorNotFoundError();
|
|
@@ -138,10 +161,18 @@ class InjectedConnector extends Connector {
|
|
|
138
161
|
this.emit('message', {
|
|
139
162
|
type: 'connecting'
|
|
140
163
|
});
|
|
141
|
-
const account = await this.getAccount();
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
164
|
+
const account = await this.getAccount(); // Switch to chain if provided
|
|
165
|
+
|
|
166
|
+
let id = await this.getChainId();
|
|
167
|
+
let unsupported = this.isChainUnsupported(id);
|
|
168
|
+
|
|
169
|
+
if (chainId && id !== chainId) {
|
|
170
|
+
const chain = await this.switchChain(chainId);
|
|
171
|
+
id = chain.id;
|
|
172
|
+
unsupported = this.isChainUnsupported(id);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
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);
|
|
145
176
|
return {
|
|
146
177
|
account,
|
|
147
178
|
chain: {
|
|
@@ -158,14 +189,14 @@ class InjectedConnector extends Connector {
|
|
|
158
189
|
}
|
|
159
190
|
|
|
160
191
|
async disconnect() {
|
|
161
|
-
var _this$
|
|
192
|
+
var _this$options4, _getClient$storage3;
|
|
162
193
|
|
|
163
194
|
const provider = await this.getProvider();
|
|
164
195
|
if (!(provider !== null && provider !== void 0 && provider.removeListener)) return;
|
|
165
196
|
provider.removeListener('accountsChanged', this.onAccountsChanged);
|
|
166
197
|
provider.removeListener('chainChanged', this.onChainChanged);
|
|
167
198
|
provider.removeListener('disconnect', this.onDisconnect);
|
|
168
|
-
if ((_this$
|
|
199
|
+
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);
|
|
169
200
|
}
|
|
170
201
|
|
|
171
202
|
async getAccount() {
|
|
@@ -198,9 +229,9 @@ class InjectedConnector extends Connector {
|
|
|
198
229
|
|
|
199
230
|
async isAuthorized() {
|
|
200
231
|
try {
|
|
201
|
-
var _this$
|
|
232
|
+
var _this$options5, _getClient$storage4;
|
|
202
233
|
|
|
203
|
-
if ((_this$
|
|
234
|
+
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;
|
|
204
235
|
const provider = await this.getProvider();
|
|
205
236
|
if (!provider) throw new ConnectorNotFoundError();
|
|
206
237
|
const accounts = await provider.request({
|
|
@@ -214,6 +245,9 @@ class InjectedConnector extends Connector {
|
|
|
214
245
|
}
|
|
215
246
|
|
|
216
247
|
async switchChain(chainId) {
|
|
248
|
+
var _this$options6;
|
|
249
|
+
|
|
250
|
+
if ((_this$options6 = this.options) !== null && _this$options6 !== void 0 && _this$options6.shimChainChangedDisconnect) _classPrivateFieldSet(this, _switchingChains, true);
|
|
217
251
|
const provider = await this.getProvider();
|
|
218
252
|
if (!provider) throw new ConnectorNotFoundError();
|
|
219
253
|
const id = hexValue(chainId);
|
|
@@ -332,6 +366,8 @@ function createStorage(_ref) {
|
|
|
332
366
|
|
|
333
367
|
const storeKey = 'store';
|
|
334
368
|
|
|
369
|
+
var _isAutoConnecting = /*#__PURE__*/new WeakMap();
|
|
370
|
+
|
|
335
371
|
var _lastUsedConnector = /*#__PURE__*/new WeakMap();
|
|
336
372
|
|
|
337
373
|
var _addEffects = /*#__PURE__*/new WeakSet();
|
|
@@ -362,6 +398,11 @@ class Client {
|
|
|
362
398
|
|
|
363
399
|
_defineProperty(this, "store", void 0);
|
|
364
400
|
|
|
401
|
+
_classPrivateFieldInitSpec(this, _isAutoConnecting, {
|
|
402
|
+
writable: true,
|
|
403
|
+
value: void 0
|
|
404
|
+
});
|
|
405
|
+
|
|
365
406
|
_classPrivateFieldInitSpec(this, _lastUsedConnector, {
|
|
366
407
|
writable: true,
|
|
367
408
|
value: void 0
|
|
@@ -451,6 +492,12 @@ class Client {
|
|
|
451
492
|
return this.store.getState().error;
|
|
452
493
|
}
|
|
453
494
|
|
|
495
|
+
get lastUsedChainId() {
|
|
496
|
+
var _this$data, _this$data$chain;
|
|
497
|
+
|
|
498
|
+
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;
|
|
499
|
+
}
|
|
500
|
+
|
|
454
501
|
get provider() {
|
|
455
502
|
return this.store.getState().provider;
|
|
456
503
|
}
|
|
@@ -486,11 +533,18 @@ class Client {
|
|
|
486
533
|
var _this$connector$disco, _this$connector;
|
|
487
534
|
|
|
488
535
|
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));
|
|
536
|
+
|
|
537
|
+
_classPrivateFieldSet(this, _isAutoConnecting, false);
|
|
538
|
+
|
|
489
539
|
this.clearState();
|
|
490
540
|
this.store.destroy();
|
|
491
541
|
}
|
|
492
542
|
|
|
493
543
|
async autoConnect() {
|
|
544
|
+
if (_classPrivateFieldGet(this, _isAutoConnecting)) return;
|
|
545
|
+
|
|
546
|
+
_classPrivateFieldSet(this, _isAutoConnecting, true);
|
|
547
|
+
|
|
494
548
|
if (!this.connectors.length) return; // Try last used connector first
|
|
495
549
|
|
|
496
550
|
const sorted = _classPrivateFieldGet(this, _lastUsedConnector) ? [...this.connectors].sort(x => x.id === _classPrivateFieldGet(this, _lastUsedConnector) ? -1 : 1) : this.connectors;
|
|
@@ -516,6 +570,9 @@ class Client {
|
|
|
516
570
|
data: undefined,
|
|
517
571
|
status: 'disconnected'
|
|
518
572
|
}));
|
|
573
|
+
|
|
574
|
+
_classPrivateFieldSet(this, _isAutoConnecting, false);
|
|
575
|
+
|
|
519
576
|
return this.data;
|
|
520
577
|
}
|
|
521
578
|
|
|
@@ -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 {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { arbitrum, arbitrumRinkeby, goerli, hardhat, kovan, localhost, mainnet, optimism, optimismKovan, polygon, polygonMumbai, rinkeby, ropsten, } from './constants/chains';
|
|
1
|
+
export { arbitrum, arbitrumRinkeby, foundry, goerli, hardhat, kovan, localhost, mainnet, optimism, optimismKovan, polygon, polygonMumbai, rinkeby, ropsten, } from './constants/chains';
|
|
@@ -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(): {
|