@wagmi/core 0.3.5 → 0.3.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.cjs.dev.js +28 -9
- package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.cjs.prod.js +28 -9
- package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.esm.js +28 -9
- package/connectors/metaMask/dist/wagmi-core-connectors-metaMask.cjs.dev.js +10 -8
- package/connectors/metaMask/dist/wagmi-core-connectors-metaMask.cjs.prod.js +10 -8
- package/connectors/metaMask/dist/wagmi-core-connectors-metaMask.esm.js +10 -8
- package/connectors/mock/dist/wagmi-core-connectors-mock.cjs.dev.js +19 -6
- package/connectors/mock/dist/wagmi-core-connectors-mock.cjs.prod.js +19 -6
- package/connectors/mock/dist/wagmi-core-connectors-mock.esm.js +19 -6
- package/connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.cjs.dev.js +28 -5
- package/connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.cjs.prod.js +28 -5
- package/connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.esm.js +28 -5
- package/dist/{base-321ac87a.cjs.dev.js → base-d45bb8f9.cjs.dev.js} +5 -3
- package/dist/{base-41fb6637.esm.js → base-d69e580f.esm.js} +6 -4
- package/dist/{base-6841ebe0.cjs.prod.js → base-ffe4d8ed.cjs.prod.js} +5 -3
- package/dist/{client-4172f963.cjs.dev.js → client-20bfac7f.cjs.dev.js} +66 -12
- package/dist/{client-87c1ff8b.esm.js → client-61f14c97.esm.js} +66 -12
- package/dist/{client-a06c45f3.cjs.prod.js → client-8b124969.cjs.prod.js} +66 -12
- package/dist/declarations/src/actions/accounts/connect.d.ts +3 -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/wagmi-core.cjs.dev.js +6 -3
- package/dist/wagmi-core.cjs.prod.js +6 -3
- package/dist/wagmi-core.esm.js +8 -5
- package/package.json +1 -1
|
@@ -1,8 +1,11 @@
|
|
|
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, j as _classPrivateMethodGet, U as UserRejectedRequestError, h as _classPrivateFieldGet, i as _classPrivateFieldSet, e as SwitchChainError } from '../../../dist/base-d69e580f.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-61f14c97.esm.js';
|
|
4
5
|
import { a as allChains } from '../../../dist/chains-a0a80d94.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
|
-
|
|
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(
|
|
133
|
+
async getProvider() {
|
|
134
|
+
var _this$options;
|
|
135
|
+
|
|
136
|
+
let {
|
|
137
|
+
chainId = ((_this$options = this.options) === null || _this$options === void 0 ? void 0 : _this$options.chainId) || this.chains[0].id,
|
|
138
|
+
create = false
|
|
139
|
+
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
140
|
+
|
|
117
141
|
if (!_classPrivateFieldGet(this, _provider) || create) {
|
|
118
|
-
var _this$
|
|
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
|
}), {}) : {};
|
|
@@ -256,9 +256,11 @@ class Connector extends EventEmitter__default["default"] {
|
|
|
256
256
|
getBlockExplorerUrls(chain) {
|
|
257
257
|
var _chain$blockExplorers;
|
|
258
258
|
|
|
259
|
-
const
|
|
260
|
-
|
|
261
|
-
|
|
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
|
|
|
@@ -250,9 +250,11 @@ class Connector extends EventEmitter {
|
|
|
250
250
|
getBlockExplorerUrls(chain) {
|
|
251
251
|
var _chain$blockExplorers;
|
|
252
252
|
|
|
253
|
-
const
|
|
254
|
-
|
|
255
|
-
|
|
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,
|
|
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 };
|
|
@@ -256,9 +256,11 @@ class Connector extends EventEmitter__default["default"] {
|
|
|
256
256
|
getBlockExplorerUrls(chain) {
|
|
257
257
|
var _chain$blockExplorers;
|
|
258
258
|
|
|
259
|
-
const
|
|
260
|
-
|
|
261
|
-
|
|
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,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var base = require('./base-
|
|
3
|
+
var base = require('./base-d45bb8f9.cjs.dev.js');
|
|
4
4
|
var ethers = require('ethers');
|
|
5
5
|
var create = require('zustand/vanilla');
|
|
6
6
|
var middleware = require('zustand/middleware');
|
|
@@ -64,6 +64,8 @@ const shimKey = 'injected.shimDisconnect';
|
|
|
64
64
|
|
|
65
65
|
var _provider = /*#__PURE__*/new WeakMap();
|
|
66
66
|
|
|
67
|
+
var _switchingChains = /*#__PURE__*/new WeakMap();
|
|
68
|
+
|
|
67
69
|
var _isUserRejectedRequestError = /*#__PURE__*/new WeakSet();
|
|
68
70
|
|
|
69
71
|
class InjectedConnector extends base.Connector {
|
|
@@ -92,6 +94,11 @@ class InjectedConnector extends base.Connector {
|
|
|
92
94
|
value: void 0
|
|
93
95
|
});
|
|
94
96
|
|
|
97
|
+
base._classPrivateFieldInitSpec(this, _switchingChains, {
|
|
98
|
+
writable: true,
|
|
99
|
+
value: void 0
|
|
100
|
+
});
|
|
101
|
+
|
|
95
102
|
base._defineProperty(this, "onAccountsChanged", accounts => {
|
|
96
103
|
if (accounts.length === 0) this.emit('disconnect');else this.emit('change', {
|
|
97
104
|
account: utils.getAddress(accounts[0])
|
|
@@ -110,10 +117,19 @@ class InjectedConnector extends base.Connector {
|
|
|
110
117
|
});
|
|
111
118
|
|
|
112
119
|
base._defineProperty(this, "onDisconnect", () => {
|
|
113
|
-
var _this$options, _getClient$storage;
|
|
120
|
+
var _this$options, _this$options2, _getClient$storage;
|
|
121
|
+
|
|
122
|
+
// We need this as MetaMask can emit the "disconnect" event
|
|
123
|
+
// upon switching chains. This workaround ensures that the
|
|
124
|
+
// user currently isn't in the process of switching chains.
|
|
125
|
+
if ((_this$options = this.options) !== null && _this$options !== void 0 && _this$options.shimChainChangedDisconnect && base._classPrivateFieldGet(this, _switchingChains)) {
|
|
126
|
+
base._classPrivateFieldSet(this, _switchingChains, false);
|
|
127
|
+
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
114
130
|
|
|
115
131
|
this.emit('disconnect');
|
|
116
|
-
if ((_this$
|
|
132
|
+
if ((_this$options2 = this.options) !== null && _this$options2 !== void 0 && _this$options2.shimDisconnect) (_getClient$storage = getClient().storage) === null || _getClient$storage === void 0 ? void 0 : _getClient$storage.removeItem(shimKey);
|
|
117
133
|
});
|
|
118
134
|
|
|
119
135
|
let name = 'Injected';
|
|
@@ -129,8 +145,12 @@ class InjectedConnector extends base.Connector {
|
|
|
129
145
|
}
|
|
130
146
|
|
|
131
147
|
async connect() {
|
|
148
|
+
let {
|
|
149
|
+
chainId
|
|
150
|
+
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
151
|
+
|
|
132
152
|
try {
|
|
133
|
-
var _this$
|
|
153
|
+
var _this$options3, _getClient$storage2;
|
|
134
154
|
|
|
135
155
|
const provider = await this.getProvider();
|
|
136
156
|
if (!provider) throw new base.ConnectorNotFoundError();
|
|
@@ -144,10 +164,18 @@ class InjectedConnector extends base.Connector {
|
|
|
144
164
|
this.emit('message', {
|
|
145
165
|
type: 'connecting'
|
|
146
166
|
});
|
|
147
|
-
const account = await this.getAccount();
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
167
|
+
const account = await this.getAccount(); // Switch to chain if provided
|
|
168
|
+
|
|
169
|
+
let id = await this.getChainId();
|
|
170
|
+
let unsupported = this.isChainUnsupported(id);
|
|
171
|
+
|
|
172
|
+
if (chainId && id !== chainId) {
|
|
173
|
+
const chain = await this.switchChain(chainId);
|
|
174
|
+
id = chain.id;
|
|
175
|
+
unsupported = this.isChainUnsupported(id);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
if ((_this$options3 = this.options) !== null && _this$options3 !== void 0 && _this$options3.shimDisconnect) (_getClient$storage2 = getClient().storage) === null || _getClient$storage2 === void 0 ? void 0 : _getClient$storage2.setItem(shimKey, true);
|
|
151
179
|
return {
|
|
152
180
|
account,
|
|
153
181
|
chain: {
|
|
@@ -164,14 +192,14 @@ class InjectedConnector extends base.Connector {
|
|
|
164
192
|
}
|
|
165
193
|
|
|
166
194
|
async disconnect() {
|
|
167
|
-
var _this$
|
|
195
|
+
var _this$options4, _getClient$storage3;
|
|
168
196
|
|
|
169
197
|
const provider = await this.getProvider();
|
|
170
198
|
if (!(provider !== null && provider !== void 0 && provider.removeListener)) return;
|
|
171
199
|
provider.removeListener('accountsChanged', this.onAccountsChanged);
|
|
172
200
|
provider.removeListener('chainChanged', this.onChainChanged);
|
|
173
201
|
provider.removeListener('disconnect', this.onDisconnect);
|
|
174
|
-
if ((_this$
|
|
202
|
+
if ((_this$options4 = this.options) !== null && _this$options4 !== void 0 && _this$options4.shimDisconnect) (_getClient$storage3 = getClient().storage) === null || _getClient$storage3 === void 0 ? void 0 : _getClient$storage3.removeItem(shimKey);
|
|
175
203
|
}
|
|
176
204
|
|
|
177
205
|
async getAccount() {
|
|
@@ -204,9 +232,9 @@ class InjectedConnector extends base.Connector {
|
|
|
204
232
|
|
|
205
233
|
async isAuthorized() {
|
|
206
234
|
try {
|
|
207
|
-
var _this$
|
|
235
|
+
var _this$options5, _getClient$storage4;
|
|
208
236
|
|
|
209
|
-
if ((_this$
|
|
237
|
+
if ((_this$options5 = this.options) !== null && _this$options5 !== void 0 && _this$options5.shimDisconnect && !((_getClient$storage4 = getClient().storage) !== null && _getClient$storage4 !== void 0 && _getClient$storage4.getItem(shimKey))) return false;
|
|
210
238
|
const provider = await this.getProvider();
|
|
211
239
|
if (!provider) throw new base.ConnectorNotFoundError();
|
|
212
240
|
const accounts = await provider.request({
|
|
@@ -220,6 +248,9 @@ class InjectedConnector extends base.Connector {
|
|
|
220
248
|
}
|
|
221
249
|
|
|
222
250
|
async switchChain(chainId) {
|
|
251
|
+
var _this$options6;
|
|
252
|
+
|
|
253
|
+
if ((_this$options6 = this.options) !== null && _this$options6 !== void 0 && _this$options6.shimChainChangedDisconnect) base._classPrivateFieldSet(this, _switchingChains, true);
|
|
223
254
|
const provider = await this.getProvider();
|
|
224
255
|
if (!provider) throw new base.ConnectorNotFoundError();
|
|
225
256
|
const id = utils.hexValue(chainId);
|
|
@@ -338,6 +369,8 @@ function createStorage(_ref) {
|
|
|
338
369
|
|
|
339
370
|
const storeKey = 'store';
|
|
340
371
|
|
|
372
|
+
var _isAutoConnecting = /*#__PURE__*/new WeakMap();
|
|
373
|
+
|
|
341
374
|
var _lastUsedConnector = /*#__PURE__*/new WeakMap();
|
|
342
375
|
|
|
343
376
|
var _addEffects = /*#__PURE__*/new WeakSet();
|
|
@@ -368,6 +401,11 @@ class Client {
|
|
|
368
401
|
|
|
369
402
|
base._defineProperty(this, "store", void 0);
|
|
370
403
|
|
|
404
|
+
base._classPrivateFieldInitSpec(this, _isAutoConnecting, {
|
|
405
|
+
writable: true,
|
|
406
|
+
value: void 0
|
|
407
|
+
});
|
|
408
|
+
|
|
371
409
|
base._classPrivateFieldInitSpec(this, _lastUsedConnector, {
|
|
372
410
|
writable: true,
|
|
373
411
|
value: void 0
|
|
@@ -457,6 +495,12 @@ class Client {
|
|
|
457
495
|
return this.store.getState().error;
|
|
458
496
|
}
|
|
459
497
|
|
|
498
|
+
get lastUsedChainId() {
|
|
499
|
+
var _this$data, _this$data$chain;
|
|
500
|
+
|
|
501
|
+
return (_this$data = this.data) === null || _this$data === void 0 ? void 0 : (_this$data$chain = _this$data.chain) === null || _this$data$chain === void 0 ? void 0 : _this$data$chain.id;
|
|
502
|
+
}
|
|
503
|
+
|
|
460
504
|
get provider() {
|
|
461
505
|
return this.store.getState().provider;
|
|
462
506
|
}
|
|
@@ -492,11 +536,18 @@ class Client {
|
|
|
492
536
|
var _this$connector$disco, _this$connector;
|
|
493
537
|
|
|
494
538
|
if (this.connector) await ((_this$connector$disco = (_this$connector = this.connector).disconnect) === null || _this$connector$disco === void 0 ? void 0 : _this$connector$disco.call(_this$connector));
|
|
539
|
+
|
|
540
|
+
base._classPrivateFieldSet(this, _isAutoConnecting, false);
|
|
541
|
+
|
|
495
542
|
this.clearState();
|
|
496
543
|
this.store.destroy();
|
|
497
544
|
}
|
|
498
545
|
|
|
499
546
|
async autoConnect() {
|
|
547
|
+
if (base._classPrivateFieldGet(this, _isAutoConnecting)) return;
|
|
548
|
+
|
|
549
|
+
base._classPrivateFieldSet(this, _isAutoConnecting, true);
|
|
550
|
+
|
|
500
551
|
if (!this.connectors.length) return; // Try last used connector first
|
|
501
552
|
|
|
502
553
|
const sorted = base._classPrivateFieldGet(this, _lastUsedConnector) ? [...this.connectors].sort(x => x.id === base._classPrivateFieldGet(this, _lastUsedConnector) ? -1 : 1) : this.connectors;
|
|
@@ -522,6 +573,9 @@ class Client {
|
|
|
522
573
|
data: undefined,
|
|
523
574
|
status: 'disconnected'
|
|
524
575
|
}));
|
|
576
|
+
|
|
577
|
+
base._classPrivateFieldSet(this, _isAutoConnecting, false);
|
|
578
|
+
|
|
525
579
|
return this.data;
|
|
526
580
|
}
|
|
527
581
|
|
|
@@ -1,4 +1,4 @@
|
|
|
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-d69e580f.esm.js';
|
|
2
2
|
import { providers, getDefaultProvider } from 'ethers';
|
|
3
3
|
import create from 'zustand/vanilla';
|
|
4
4
|
import { subscribeWithSelector, persist } from 'zustand/middleware';
|
|
@@ -58,6 +58,8 @@ const shimKey = 'injected.shimDisconnect';
|
|
|
58
58
|
|
|
59
59
|
var _provider = /*#__PURE__*/new WeakMap();
|
|
60
60
|
|
|
61
|
+
var _switchingChains = /*#__PURE__*/new WeakMap();
|
|
62
|
+
|
|
61
63
|
var _isUserRejectedRequestError = /*#__PURE__*/new WeakSet();
|
|
62
64
|
|
|
63
65
|
class InjectedConnector extends Connector {
|
|
@@ -86,6 +88,11 @@ class InjectedConnector extends Connector {
|
|
|
86
88
|
value: void 0
|
|
87
89
|
});
|
|
88
90
|
|
|
91
|
+
_classPrivateFieldInitSpec(this, _switchingChains, {
|
|
92
|
+
writable: true,
|
|
93
|
+
value: void 0
|
|
94
|
+
});
|
|
95
|
+
|
|
89
96
|
_defineProperty(this, "onAccountsChanged", accounts => {
|
|
90
97
|
if (accounts.length === 0) this.emit('disconnect');else this.emit('change', {
|
|
91
98
|
account: getAddress(accounts[0])
|
|
@@ -104,10 +111,19 @@ class InjectedConnector extends Connector {
|
|
|
104
111
|
});
|
|
105
112
|
|
|
106
113
|
_defineProperty(this, "onDisconnect", () => {
|
|
107
|
-
var _this$options, _getClient$storage;
|
|
114
|
+
var _this$options, _this$options2, _getClient$storage;
|
|
115
|
+
|
|
116
|
+
// We need this as MetaMask can emit the "disconnect" event
|
|
117
|
+
// upon switching chains. This workaround ensures that the
|
|
118
|
+
// user currently isn't in the process of switching chains.
|
|
119
|
+
if ((_this$options = this.options) !== null && _this$options !== void 0 && _this$options.shimChainChangedDisconnect && _classPrivateFieldGet(this, _switchingChains)) {
|
|
120
|
+
_classPrivateFieldSet(this, _switchingChains, false);
|
|
121
|
+
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
108
124
|
|
|
109
125
|
this.emit('disconnect');
|
|
110
|
-
if ((_this$
|
|
126
|
+
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
127
|
});
|
|
112
128
|
|
|
113
129
|
let name = 'Injected';
|
|
@@ -123,8 +139,12 @@ class InjectedConnector extends Connector {
|
|
|
123
139
|
}
|
|
124
140
|
|
|
125
141
|
async connect() {
|
|
142
|
+
let {
|
|
143
|
+
chainId
|
|
144
|
+
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
145
|
+
|
|
126
146
|
try {
|
|
127
|
-
var _this$
|
|
147
|
+
var _this$options3, _getClient$storage2;
|
|
128
148
|
|
|
129
149
|
const provider = await this.getProvider();
|
|
130
150
|
if (!provider) throw new ConnectorNotFoundError();
|
|
@@ -138,10 +158,18 @@ class InjectedConnector extends Connector {
|
|
|
138
158
|
this.emit('message', {
|
|
139
159
|
type: 'connecting'
|
|
140
160
|
});
|
|
141
|
-
const account = await this.getAccount();
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
161
|
+
const account = await this.getAccount(); // Switch to chain if provided
|
|
162
|
+
|
|
163
|
+
let id = await this.getChainId();
|
|
164
|
+
let unsupported = this.isChainUnsupported(id);
|
|
165
|
+
|
|
166
|
+
if (chainId && id !== chainId) {
|
|
167
|
+
const chain = await this.switchChain(chainId);
|
|
168
|
+
id = chain.id;
|
|
169
|
+
unsupported = this.isChainUnsupported(id);
|
|
170
|
+
}
|
|
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(shimKey, true);
|
|
145
173
|
return {
|
|
146
174
|
account,
|
|
147
175
|
chain: {
|
|
@@ -158,14 +186,14 @@ class InjectedConnector extends Connector {
|
|
|
158
186
|
}
|
|
159
187
|
|
|
160
188
|
async disconnect() {
|
|
161
|
-
var _this$
|
|
189
|
+
var _this$options4, _getClient$storage3;
|
|
162
190
|
|
|
163
191
|
const provider = await this.getProvider();
|
|
164
192
|
if (!(provider !== null && provider !== void 0 && provider.removeListener)) return;
|
|
165
193
|
provider.removeListener('accountsChanged', this.onAccountsChanged);
|
|
166
194
|
provider.removeListener('chainChanged', this.onChainChanged);
|
|
167
195
|
provider.removeListener('disconnect', this.onDisconnect);
|
|
168
|
-
if ((_this$
|
|
196
|
+
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
197
|
}
|
|
170
198
|
|
|
171
199
|
async getAccount() {
|
|
@@ -198,9 +226,9 @@ class InjectedConnector extends Connector {
|
|
|
198
226
|
|
|
199
227
|
async isAuthorized() {
|
|
200
228
|
try {
|
|
201
|
-
var _this$
|
|
229
|
+
var _this$options5, _getClient$storage4;
|
|
202
230
|
|
|
203
|
-
if ((_this$
|
|
231
|
+
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
232
|
const provider = await this.getProvider();
|
|
205
233
|
if (!provider) throw new ConnectorNotFoundError();
|
|
206
234
|
const accounts = await provider.request({
|
|
@@ -214,6 +242,9 @@ class InjectedConnector extends Connector {
|
|
|
214
242
|
}
|
|
215
243
|
|
|
216
244
|
async switchChain(chainId) {
|
|
245
|
+
var _this$options6;
|
|
246
|
+
|
|
247
|
+
if ((_this$options6 = this.options) !== null && _this$options6 !== void 0 && _this$options6.shimChainChangedDisconnect) _classPrivateFieldSet(this, _switchingChains, true);
|
|
217
248
|
const provider = await this.getProvider();
|
|
218
249
|
if (!provider) throw new ConnectorNotFoundError();
|
|
219
250
|
const id = hexValue(chainId);
|
|
@@ -332,6 +363,8 @@ function createStorage(_ref) {
|
|
|
332
363
|
|
|
333
364
|
const storeKey = 'store';
|
|
334
365
|
|
|
366
|
+
var _isAutoConnecting = /*#__PURE__*/new WeakMap();
|
|
367
|
+
|
|
335
368
|
var _lastUsedConnector = /*#__PURE__*/new WeakMap();
|
|
336
369
|
|
|
337
370
|
var _addEffects = /*#__PURE__*/new WeakSet();
|
|
@@ -362,6 +395,11 @@ class Client {
|
|
|
362
395
|
|
|
363
396
|
_defineProperty(this, "store", void 0);
|
|
364
397
|
|
|
398
|
+
_classPrivateFieldInitSpec(this, _isAutoConnecting, {
|
|
399
|
+
writable: true,
|
|
400
|
+
value: void 0
|
|
401
|
+
});
|
|
402
|
+
|
|
365
403
|
_classPrivateFieldInitSpec(this, _lastUsedConnector, {
|
|
366
404
|
writable: true,
|
|
367
405
|
value: void 0
|
|
@@ -451,6 +489,12 @@ class Client {
|
|
|
451
489
|
return this.store.getState().error;
|
|
452
490
|
}
|
|
453
491
|
|
|
492
|
+
get lastUsedChainId() {
|
|
493
|
+
var _this$data, _this$data$chain;
|
|
494
|
+
|
|
495
|
+
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;
|
|
496
|
+
}
|
|
497
|
+
|
|
454
498
|
get provider() {
|
|
455
499
|
return this.store.getState().provider;
|
|
456
500
|
}
|
|
@@ -486,11 +530,18 @@ class Client {
|
|
|
486
530
|
var _this$connector$disco, _this$connector;
|
|
487
531
|
|
|
488
532
|
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));
|
|
533
|
+
|
|
534
|
+
_classPrivateFieldSet(this, _isAutoConnecting, false);
|
|
535
|
+
|
|
489
536
|
this.clearState();
|
|
490
537
|
this.store.destroy();
|
|
491
538
|
}
|
|
492
539
|
|
|
493
540
|
async autoConnect() {
|
|
541
|
+
if (_classPrivateFieldGet(this, _isAutoConnecting)) return;
|
|
542
|
+
|
|
543
|
+
_classPrivateFieldSet(this, _isAutoConnecting, true);
|
|
544
|
+
|
|
494
545
|
if (!this.connectors.length) return; // Try last used connector first
|
|
495
546
|
|
|
496
547
|
const sorted = _classPrivateFieldGet(this, _lastUsedConnector) ? [...this.connectors].sort(x => x.id === _classPrivateFieldGet(this, _lastUsedConnector) ? -1 : 1) : this.connectors;
|
|
@@ -516,6 +567,9 @@ class Client {
|
|
|
516
567
|
data: undefined,
|
|
517
568
|
status: 'disconnected'
|
|
518
569
|
}));
|
|
570
|
+
|
|
571
|
+
_classPrivateFieldSet(this, _isAutoConnecting, false);
|
|
572
|
+
|
|
519
573
|
return this.data;
|
|
520
574
|
}
|
|
521
575
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var base = require('./base-
|
|
3
|
+
var base = require('./base-ffe4d8ed.cjs.prod.js');
|
|
4
4
|
var ethers = require('ethers');
|
|
5
5
|
var create = require('zustand/vanilla');
|
|
6
6
|
var middleware = require('zustand/middleware');
|
|
@@ -64,6 +64,8 @@ const shimKey = 'injected.shimDisconnect';
|
|
|
64
64
|
|
|
65
65
|
var _provider = /*#__PURE__*/new WeakMap();
|
|
66
66
|
|
|
67
|
+
var _switchingChains = /*#__PURE__*/new WeakMap();
|
|
68
|
+
|
|
67
69
|
var _isUserRejectedRequestError = /*#__PURE__*/new WeakSet();
|
|
68
70
|
|
|
69
71
|
class InjectedConnector extends base.Connector {
|
|
@@ -92,6 +94,11 @@ class InjectedConnector extends base.Connector {
|
|
|
92
94
|
value: void 0
|
|
93
95
|
});
|
|
94
96
|
|
|
97
|
+
base._classPrivateFieldInitSpec(this, _switchingChains, {
|
|
98
|
+
writable: true,
|
|
99
|
+
value: void 0
|
|
100
|
+
});
|
|
101
|
+
|
|
95
102
|
base._defineProperty(this, "onAccountsChanged", accounts => {
|
|
96
103
|
if (accounts.length === 0) this.emit('disconnect');else this.emit('change', {
|
|
97
104
|
account: utils.getAddress(accounts[0])
|
|
@@ -110,10 +117,19 @@ class InjectedConnector extends base.Connector {
|
|
|
110
117
|
});
|
|
111
118
|
|
|
112
119
|
base._defineProperty(this, "onDisconnect", () => {
|
|
113
|
-
var _this$options, _getClient$storage;
|
|
120
|
+
var _this$options, _this$options2, _getClient$storage;
|
|
121
|
+
|
|
122
|
+
// We need this as MetaMask can emit the "disconnect" event
|
|
123
|
+
// upon switching chains. This workaround ensures that the
|
|
124
|
+
// user currently isn't in the process of switching chains.
|
|
125
|
+
if ((_this$options = this.options) !== null && _this$options !== void 0 && _this$options.shimChainChangedDisconnect && base._classPrivateFieldGet(this, _switchingChains)) {
|
|
126
|
+
base._classPrivateFieldSet(this, _switchingChains, false);
|
|
127
|
+
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
114
130
|
|
|
115
131
|
this.emit('disconnect');
|
|
116
|
-
if ((_this$
|
|
132
|
+
if ((_this$options2 = this.options) !== null && _this$options2 !== void 0 && _this$options2.shimDisconnect) (_getClient$storage = getClient().storage) === null || _getClient$storage === void 0 ? void 0 : _getClient$storage.removeItem(shimKey);
|
|
117
133
|
});
|
|
118
134
|
|
|
119
135
|
let name = 'Injected';
|
|
@@ -129,8 +145,12 @@ class InjectedConnector extends base.Connector {
|
|
|
129
145
|
}
|
|
130
146
|
|
|
131
147
|
async connect() {
|
|
148
|
+
let {
|
|
149
|
+
chainId
|
|
150
|
+
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
151
|
+
|
|
132
152
|
try {
|
|
133
|
-
var _this$
|
|
153
|
+
var _this$options3, _getClient$storage2;
|
|
134
154
|
|
|
135
155
|
const provider = await this.getProvider();
|
|
136
156
|
if (!provider) throw new base.ConnectorNotFoundError();
|
|
@@ -144,10 +164,18 @@ class InjectedConnector extends base.Connector {
|
|
|
144
164
|
this.emit('message', {
|
|
145
165
|
type: 'connecting'
|
|
146
166
|
});
|
|
147
|
-
const account = await this.getAccount();
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
167
|
+
const account = await this.getAccount(); // Switch to chain if provided
|
|
168
|
+
|
|
169
|
+
let id = await this.getChainId();
|
|
170
|
+
let unsupported = this.isChainUnsupported(id);
|
|
171
|
+
|
|
172
|
+
if (chainId && id !== chainId) {
|
|
173
|
+
const chain = await this.switchChain(chainId);
|
|
174
|
+
id = chain.id;
|
|
175
|
+
unsupported = this.isChainUnsupported(id);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
if ((_this$options3 = this.options) !== null && _this$options3 !== void 0 && _this$options3.shimDisconnect) (_getClient$storage2 = getClient().storage) === null || _getClient$storage2 === void 0 ? void 0 : _getClient$storage2.setItem(shimKey, true);
|
|
151
179
|
return {
|
|
152
180
|
account,
|
|
153
181
|
chain: {
|
|
@@ -164,14 +192,14 @@ class InjectedConnector extends base.Connector {
|
|
|
164
192
|
}
|
|
165
193
|
|
|
166
194
|
async disconnect() {
|
|
167
|
-
var _this$
|
|
195
|
+
var _this$options4, _getClient$storage3;
|
|
168
196
|
|
|
169
197
|
const provider = await this.getProvider();
|
|
170
198
|
if (!(provider !== null && provider !== void 0 && provider.removeListener)) return;
|
|
171
199
|
provider.removeListener('accountsChanged', this.onAccountsChanged);
|
|
172
200
|
provider.removeListener('chainChanged', this.onChainChanged);
|
|
173
201
|
provider.removeListener('disconnect', this.onDisconnect);
|
|
174
|
-
if ((_this$
|
|
202
|
+
if ((_this$options4 = this.options) !== null && _this$options4 !== void 0 && _this$options4.shimDisconnect) (_getClient$storage3 = getClient().storage) === null || _getClient$storage3 === void 0 ? void 0 : _getClient$storage3.removeItem(shimKey);
|
|
175
203
|
}
|
|
176
204
|
|
|
177
205
|
async getAccount() {
|
|
@@ -204,9 +232,9 @@ class InjectedConnector extends base.Connector {
|
|
|
204
232
|
|
|
205
233
|
async isAuthorized() {
|
|
206
234
|
try {
|
|
207
|
-
var _this$
|
|
235
|
+
var _this$options5, _getClient$storage4;
|
|
208
236
|
|
|
209
|
-
if ((_this$
|
|
237
|
+
if ((_this$options5 = this.options) !== null && _this$options5 !== void 0 && _this$options5.shimDisconnect && !((_getClient$storage4 = getClient().storage) !== null && _getClient$storage4 !== void 0 && _getClient$storage4.getItem(shimKey))) return false;
|
|
210
238
|
const provider = await this.getProvider();
|
|
211
239
|
if (!provider) throw new base.ConnectorNotFoundError();
|
|
212
240
|
const accounts = await provider.request({
|
|
@@ -220,6 +248,9 @@ class InjectedConnector extends base.Connector {
|
|
|
220
248
|
}
|
|
221
249
|
|
|
222
250
|
async switchChain(chainId) {
|
|
251
|
+
var _this$options6;
|
|
252
|
+
|
|
253
|
+
if ((_this$options6 = this.options) !== null && _this$options6 !== void 0 && _this$options6.shimChainChangedDisconnect) base._classPrivateFieldSet(this, _switchingChains, true);
|
|
223
254
|
const provider = await this.getProvider();
|
|
224
255
|
if (!provider) throw new base.ConnectorNotFoundError();
|
|
225
256
|
const id = utils.hexValue(chainId);
|
|
@@ -338,6 +369,8 @@ function createStorage(_ref) {
|
|
|
338
369
|
|
|
339
370
|
const storeKey = 'store';
|
|
340
371
|
|
|
372
|
+
var _isAutoConnecting = /*#__PURE__*/new WeakMap();
|
|
373
|
+
|
|
341
374
|
var _lastUsedConnector = /*#__PURE__*/new WeakMap();
|
|
342
375
|
|
|
343
376
|
var _addEffects = /*#__PURE__*/new WeakSet();
|
|
@@ -368,6 +401,11 @@ class Client {
|
|
|
368
401
|
|
|
369
402
|
base._defineProperty(this, "store", void 0);
|
|
370
403
|
|
|
404
|
+
base._classPrivateFieldInitSpec(this, _isAutoConnecting, {
|
|
405
|
+
writable: true,
|
|
406
|
+
value: void 0
|
|
407
|
+
});
|
|
408
|
+
|
|
371
409
|
base._classPrivateFieldInitSpec(this, _lastUsedConnector, {
|
|
372
410
|
writable: true,
|
|
373
411
|
value: void 0
|
|
@@ -457,6 +495,12 @@ class Client {
|
|
|
457
495
|
return this.store.getState().error;
|
|
458
496
|
}
|
|
459
497
|
|
|
498
|
+
get lastUsedChainId() {
|
|
499
|
+
var _this$data, _this$data$chain;
|
|
500
|
+
|
|
501
|
+
return (_this$data = this.data) === null || _this$data === void 0 ? void 0 : (_this$data$chain = _this$data.chain) === null || _this$data$chain === void 0 ? void 0 : _this$data$chain.id;
|
|
502
|
+
}
|
|
503
|
+
|
|
460
504
|
get provider() {
|
|
461
505
|
return this.store.getState().provider;
|
|
462
506
|
}
|
|
@@ -492,11 +536,18 @@ class Client {
|
|
|
492
536
|
var _this$connector$disco, _this$connector;
|
|
493
537
|
|
|
494
538
|
if (this.connector) await ((_this$connector$disco = (_this$connector = this.connector).disconnect) === null || _this$connector$disco === void 0 ? void 0 : _this$connector$disco.call(_this$connector));
|
|
539
|
+
|
|
540
|
+
base._classPrivateFieldSet(this, _isAutoConnecting, false);
|
|
541
|
+
|
|
495
542
|
this.clearState();
|
|
496
543
|
this.store.destroy();
|
|
497
544
|
}
|
|
498
545
|
|
|
499
546
|
async autoConnect() {
|
|
547
|
+
if (base._classPrivateFieldGet(this, _isAutoConnecting)) return;
|
|
548
|
+
|
|
549
|
+
base._classPrivateFieldSet(this, _isAutoConnecting, true);
|
|
550
|
+
|
|
500
551
|
if (!this.connectors.length) return; // Try last used connector first
|
|
501
552
|
|
|
502
553
|
const sorted = base._classPrivateFieldGet(this, _lastUsedConnector) ? [...this.connectors].sort(x => x.id === base._classPrivateFieldGet(this, _lastUsedConnector) ? -1 : 1) : this.connectors;
|
|
@@ -522,6 +573,9 @@ class Client {
|
|
|
522
573
|
data: undefined,
|
|
523
574
|
status: 'disconnected'
|
|
524
575
|
}));
|
|
576
|
+
|
|
577
|
+
base._classPrivateFieldSet(this, _isAutoConnecting, false);
|
|
578
|
+
|
|
525
579
|
return this.data;
|
|
526
580
|
}
|
|
527
581
|
|