@wagmi/core 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.cjs.dev.js +2 -4
  2. package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.cjs.prod.js +2 -4
  3. package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.esm.js +3 -5
  4. package/connectors/metaMask/dist/wagmi-core-connectors-metaMask.cjs.d.ts +1 -0
  5. package/connectors/metaMask/dist/wagmi-core-connectors-metaMask.cjs.dev.js +62 -0
  6. package/connectors/metaMask/dist/wagmi-core-connectors-metaMask.cjs.js +7 -0
  7. package/connectors/metaMask/dist/wagmi-core-connectors-metaMask.cjs.prod.js +62 -0
  8. package/connectors/metaMask/dist/wagmi-core-connectors-metaMask.esm.js +58 -0
  9. package/connectors/metaMask/package.json +4 -0
  10. package/connectors/mock/dist/wagmi-core-connectors-mock.esm.js +2 -2
  11. package/connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.esm.js +2 -2
  12. package/dist/{base-d5bbf720.esm.js → base-159de546.esm.js} +1 -1
  13. package/dist/{classPrivateMethodGet-93a70bfd.esm.js → classPrivateMethodGet-55c9909f.esm.js} +1 -1
  14. package/dist/client-4d8337e7.cjs.prod.js +606 -0
  15. package/dist/client-5d456446.esm.js +595 -0
  16. package/dist/client-f77a08e4.cjs.dev.js +606 -0
  17. package/dist/declarations/src/actions/contracts/readContract.d.ts +1 -1
  18. package/dist/declarations/src/connectors/coinbaseWallet.d.ts +1 -1
  19. package/dist/declarations/src/connectors/injected.d.ts +4 -3
  20. package/dist/declarations/src/connectors/metaMask.d.ts +13 -0
  21. package/dist/declarations/src/types/index.d.ts +17 -1
  22. package/dist/declarations/src/utils/getInjectedName.d.ts +1 -1
  23. package/dist/declarations/src/utils/index.d.ts +1 -0
  24. package/dist/declarations/src/utils/warn.d.ts +1 -0
  25. package/dist/wagmi-core.cjs.dev.js +63 -612
  26. package/dist/wagmi-core.cjs.prod.js +63 -612
  27. package/dist/wagmi-core.esm.js +10 -554
  28. package/package.json +10 -7
@@ -2,19 +2,16 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var classPrivateMethodGet = require('./classPrivateMethodGet-d7330ed7.cjs.prod.js');
5
+ var client = require('./client-4d8337e7.cjs.prod.js');
6
6
  var base = require('./base-59f3457e.cjs.prod.js');
7
- var ethers = require('ethers');
8
- var create = require('zustand/vanilla');
9
- var middleware = require('zustand/middleware');
7
+ var ethers = require('ethers/lib/ethers');
10
8
  var utils = require('ethers/lib/utils');
11
- var ethers$1 = require('ethers/lib/ethers');
9
+ require('./classPrivateMethodGet-d7330ed7.cjs.prod.js');
10
+ require('ethers');
11
+ require('zustand/vanilla');
12
+ require('zustand/middleware');
12
13
  require('eventemitter3');
13
14
 
14
- function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
15
-
16
- var create__default = /*#__PURE__*/_interopDefault(create);
17
-
18
15
  // https://ethereum.org/en/developers/docs/standards/tokens/erc-20
19
16
  const erc20ABI = ['event Approval(address indexed _owner, address indexed _spender, uint256 _value)', 'event Transfer(address indexed _from, address indexed _to, uint256 _value)', 'function allowance(address _owner, address _spender) public view returns (uint256 remaining)', 'function approve(address _spender, uint256 _value) public returns (bool success)', 'function balanceOf(address _owner) public view returns (uint256 balance)', 'function decimals() public view returns (uint8)', 'function name() public view returns (string)', 'function symbol() public view returns (string)', 'function totalSupply() public view returns (uint256)', 'function transfer(address _to, uint256 _value) public returns (bool success)', 'function transferFrom(address _from, address _to, uint256 _value) public returns (bool success)']; // https://ethereum.org/en/developers/docs/standards/tokens/erc-721
20
17
 
@@ -23,606 +20,60 @@ const erc721ABI = ['event Approval(address indexed _owner, address indexed _appr
23
20
  // https://github.com/ethers-io/ethers.js/blob/master/packages/units/src.ts/index.ts#L10-L18
24
21
  const units = ['wei', 'kwei', 'mwei', 'gwei', 'szabo', 'finney', 'ether'];
25
22
 
26
- const injectedProvidersLookup = {
27
- isMetaMask: 'MetaMask',
28
- // Place other options below in alphabetical order
29
- isBraveWallet: 'Brave Wallet',
30
- isCoinbaseWallet: 'Coinbase Wallet',
31
- isFrame: 'Frame',
32
- isTally: 'Tally'
33
- };
34
- const injectedOptions = Object.entries(injectedProvidersLookup);
35
- function getInjectedName(ethereum) {
36
- if (!ethereum) return 'Injected';
37
-
38
- for (const [key, val] of injectedOptions) {
39
- if (ethereum[key]) return val;
40
- }
41
-
42
- return 'Injected';
43
- }
44
-
45
- const shimKey = 'injected.shimDisconnect';
46
-
47
- var _provider = /*#__PURE__*/new WeakMap();
48
-
49
- class InjectedConnector extends base.Connector {
50
- constructor(config) {
51
- super({ ...config,
52
- options: {
53
- shimDisconnect: true,
54
- ...(config === null || config === void 0 ? void 0 : config.options)
55
- }
56
- });
57
-
58
- base._defineProperty(this, "id", 'injected');
59
-
60
- base._defineProperty(this, "name", void 0);
61
-
62
- base._defineProperty(this, "ready", typeof window != 'undefined' && !!window.ethereum);
63
-
64
- base._classPrivateFieldInitSpec(this, _provider, {
65
- writable: true,
66
- value: void 0
67
- });
68
-
69
- base._defineProperty(this, "onAccountsChanged", accounts => {
70
- if (accounts.length === 0) this.emit('disconnect');else this.emit('change', {
71
- account: utils.getAddress(accounts[0])
72
- });
73
- });
74
-
75
- base._defineProperty(this, "onChainChanged", chainId => {
76
- const id = base.normalizeChainId(chainId);
77
- const unsupported = this.isChainUnsupported(id);
78
- this.emit('change', {
79
- chain: {
80
- id,
81
- unsupported
82
- }
83
- });
84
- });
85
-
86
- base._defineProperty(this, "onDisconnect", () => {
87
- var _this$options, _getClient$storage;
88
-
89
- this.emit('disconnect');
90
- if ((_this$options = this.options) !== null && _this$options !== void 0 && _this$options.shimDisconnect) (_getClient$storage = getClient().storage) === null || _getClient$storage === void 0 ? void 0 : _getClient$storage.removeItem(shimKey);
91
- });
92
-
93
- let name = 'Injected';
94
- if (typeof window !== 'undefined') name = getInjectedName(window.ethereum);
95
- this.name = name;
96
- }
97
-
98
- async connect() {
99
- try {
100
- var _this$options2, _getClient$storage2;
101
-
102
- const provider = await this.getProvider();
103
- if (!provider) throw new base.ConnectorNotFoundError();
104
-
105
- if (provider.on) {
106
- provider.on('accountsChanged', this.onAccountsChanged);
107
- provider.on('chainChanged', this.onChainChanged);
108
- provider.on('disconnect', this.onDisconnect);
109
- }
110
-
111
- this.emit('message', {
112
- type: 'connecting'
113
- });
114
- const account = await this.getAccount();
115
- const id = await this.getChainId();
116
- const unsupported = this.isChainUnsupported(id);
117
- if ((_this$options2 = this.options) !== null && _this$options2 !== void 0 && _this$options2.shimDisconnect) (_getClient$storage2 = getClient().storage) === null || _getClient$storage2 === void 0 ? void 0 : _getClient$storage2.setItem(shimKey, true);
118
- return {
119
- account,
120
- chain: {
121
- id,
122
- unsupported
123
- },
124
- provider
125
- };
126
- } catch (error) {
127
- if (error.code === 4001) throw new base.UserRejectedRequestError();
128
- throw error;
129
- }
130
- }
131
-
132
- async disconnect() {
133
- var _this$options3, _getClient$storage3;
134
-
135
- const provider = await this.getProvider();
136
- if (!(provider !== null && provider !== void 0 && provider.removeListener)) return;
137
- provider.removeListener('accountsChanged', this.onAccountsChanged);
138
- provider.removeListener('chainChanged', this.onChainChanged);
139
- provider.removeListener('disconnect', this.onDisconnect);
140
- if ((_this$options3 = this.options) !== null && _this$options3 !== void 0 && _this$options3.shimDisconnect) (_getClient$storage3 = getClient().storage) === null || _getClient$storage3 === void 0 ? void 0 : _getClient$storage3.removeItem(shimKey);
141
- }
142
-
143
- async getAccount() {
144
- const provider = await this.getProvider();
145
- if (!provider) throw new base.ConnectorNotFoundError();
146
- const accounts = await provider.request({
147
- method: 'eth_requestAccounts'
148
- }); // return checksum address
149
-
150
- return utils.getAddress(accounts[0]);
151
- }
152
-
153
- async getChainId() {
154
- const provider = await this.getProvider();
155
- if (!provider) throw new base.ConnectorNotFoundError();
156
- return await provider.request({
157
- method: 'eth_chainId'
158
- }).then(base.normalizeChainId);
159
- }
160
-
161
- async getProvider() {
162
- if (typeof window !== 'undefined' && !!window.ethereum) base._classPrivateFieldSet(this, _provider, window.ethereum);
163
- return base._classPrivateFieldGet(this, _provider);
164
- }
165
-
166
- async getSigner() {
167
- const [provider, account] = await Promise.all([this.getProvider(), this.getAccount()]);
168
- return new ethers.providers.Web3Provider(provider).getSigner(account);
169
- }
170
-
171
- async isAuthorized() {
172
- try {
173
- var _this$options4, _getClient$storage4;
174
-
175
- if ((_this$options4 = this.options) !== null && _this$options4 !== void 0 && _this$options4.shimDisconnect && !((_getClient$storage4 = getClient().storage) !== null && _getClient$storage4 !== void 0 && _getClient$storage4.getItem(shimKey))) return false;
176
- const provider = await this.getProvider();
177
- if (!provider) throw new base.ConnectorNotFoundError();
178
- const accounts = await provider.request({
179
- method: 'eth_accounts'
180
- });
181
- const account = accounts[0];
182
- return !!account;
183
- } catch {
184
- return false;
185
- }
186
- }
187
-
188
- async switchChain(chainId) {
189
- const provider = await this.getProvider();
190
- if (!provider) throw new base.ConnectorNotFoundError();
191
- const id = utils.hexValue(chainId);
192
-
193
- try {
194
- var _chains$find;
195
-
196
- await provider.request({
197
- method: 'wallet_switchEthereumChain',
198
- params: [{
199
- chainId: id
200
- }]
201
- });
202
- const chains = [...this.chains, ...base.allChains];
203
- return (_chains$find = chains.find(x => x.id === chainId)) !== null && _chains$find !== void 0 ? _chains$find : {
204
- id: chainId,
205
- name: "Chain ".concat(id),
206
- rpcUrls: {
207
- default: ''
208
- }
209
- };
210
- } catch (error) {
211
- // Indicates chain is not added to provider
212
- if (error.code === 4902) {
213
- try {
214
- const chain = this.chains.find(x => x.id === chainId);
215
- if (!chain) throw new base.ChainNotConfiguredError();
216
- await provider.request({
217
- method: 'wallet_addEthereumChain',
218
- params: [{
219
- chainId: id,
220
- chainName: chain.name,
221
- nativeCurrency: chain.nativeCurrency,
222
- rpcUrls: [chain.rpcUrls.default],
223
- blockExplorerUrls: this.getBlockExplorerUrls(chain)
224
- }]
225
- });
226
- return chain;
227
- } catch (addError) {
228
- throw new base.AddChainError();
229
- }
230
- } else if (error.code === 4001) throw new base.UserRejectedRequestError();else throw new base.SwitchChainError();
231
- }
232
- }
233
-
234
- async watchAsset(_ref) {
235
- let {
236
- address,
237
- decimals = 18,
238
- image,
239
- symbol
240
- } = _ref;
241
- const provider = await this.getProvider();
242
- if (!provider) throw new base.ConnectorNotFoundError();
243
- return await provider.request({
244
- method: 'wallet_watchAsset',
245
- params: {
246
- type: 'ERC20',
247
- options: {
248
- address,
249
- decimals,
250
- image,
251
- symbol
252
- }
253
- }
254
- });
255
- }
256
-
257
- }
258
-
259
- const noopStorage = {
260
- getItem: _key => '',
261
- setItem: (_key, _value) => null,
262
- removeItem: _key => null
263
- };
264
- function createStorage(_ref) {
265
- let {
266
- storage,
267
- key: prefix = 'wagmi'
268
- } = _ref;
269
- return { ...storage,
270
- getItem: function (key) {
271
- let defaultState = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
272
- const value = storage.getItem("".concat(prefix, ".").concat(key));
273
-
274
- try {
275
- return value ? JSON.parse(value) : defaultState;
276
- } catch (error) {
277
- console.warn(error);
278
- return defaultState;
279
- }
280
- },
281
- setItem: (key, value) => {
282
- if (value === null) {
283
- storage.removeItem("".concat(prefix, ".").concat(key));
284
- } else {
285
- try {
286
- storage.setItem("".concat(prefix, ".").concat(key), JSON.stringify(value));
287
- } catch (err) {
288
- console.error(err);
289
- }
290
- }
291
- },
292
- removeItem: key => storage.removeItem("".concat(prefix, ".").concat(key))
293
- };
294
- }
295
-
296
- const storeKey = 'store';
297
-
298
- var _lastUsedConnector = /*#__PURE__*/new WeakMap();
299
-
300
- var _addEffects = /*#__PURE__*/new WeakSet();
301
-
302
- class Client {
303
- constructor() {
304
- var _config$autoConnect, _config$connectors, _config$provider, _config$storage;
305
-
306
- let config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
307
-
308
- classPrivateMethodGet._classPrivateMethodInitSpec(this, _addEffects);
309
-
310
- base._defineProperty(this, "config", void 0);
311
-
312
- base._defineProperty(this, "storage", void 0);
313
-
314
- base._defineProperty(this, "store", void 0);
315
-
316
- base._classPrivateFieldInitSpec(this, _lastUsedConnector, {
317
- writable: true,
318
- value: void 0
319
- });
320
-
321
- // Set default values for config
322
- const autoConnect = (_config$autoConnect = config.autoConnect) !== null && _config$autoConnect !== void 0 ? _config$autoConnect : false;
323
-
324
- const _connectors = (_config$connectors = config.connectors) !== null && _config$connectors !== void 0 ? _config$connectors : [new InjectedConnector()];
325
-
326
- const _provider = (_config$provider = config.provider) !== null && _config$provider !== void 0 ? _config$provider : config => {
327
- try {
328
- return ethers.getDefaultProvider(config.chainId);
329
- } catch {
330
- return ethers.getDefaultProvider();
331
- }
332
- };
333
-
334
- const storage = (_config$storage = config.storage) !== null && _config$storage !== void 0 ? _config$storage : createStorage({
335
- storage: typeof window !== 'undefined' ? window.localStorage : noopStorage
336
- });
337
- const _webSocketProvider = config.webSocketProvider; // Check status for autoConnect flag
338
-
339
- let status = 'disconnected';
340
-
341
- let _chainId;
342
-
343
- if (autoConnect) {
344
- try {
345
- var _JSON$parse, _JSON$parse$state, _data$chain;
346
-
347
- const rawState = storage.getItem(storeKey, '');
348
- const data = (_JSON$parse = JSON.parse(rawState || '{}')) === null || _JSON$parse === void 0 ? void 0 : (_JSON$parse$state = _JSON$parse.state) === null || _JSON$parse$state === void 0 ? void 0 : _JSON$parse$state.data; // If account exists in localStorage, set status to reconnecting
349
-
350
- status = data !== null && data !== void 0 && data.account ? 'reconnecting' : 'connecting';
351
- _chainId = data === null || data === void 0 ? void 0 : (_data$chain = data.chain) === null || _data$chain === void 0 ? void 0 : _data$chain.id; // eslint-disable-next-line no-empty
352
- } catch (_error) {}
353
- } // Evaluate initial store values
354
-
355
-
356
- const connectors_ = typeof _connectors === 'function' ? _connectors({
357
- chainId: _chainId
358
- }) : _connectors;
359
- const provider_ = typeof _provider === 'function' ? _provider({
360
- chainId: _chainId
361
- }) : _provider;
362
- const webSocketProvider_ = typeof _webSocketProvider === 'function' ? _webSocketProvider({
363
- chainId: _chainId
364
- }) : _webSocketProvider; // Create store
365
-
366
- this.store = create__default["default"](middleware.subscribeWithSelector(middleware.persist(() => ({
367
- connectors: connectors_,
368
- provider: provider_,
369
- status,
370
- webSocketProvider: webSocketProvider_
371
- }), {
372
- name: storeKey,
373
- getStorage: () => storage,
374
- partialize: state => {
375
- var _state$data, _state$data2;
376
-
377
- return { ...(autoConnect && {
378
- data: {
379
- account: state === null || state === void 0 ? void 0 : (_state$data = state.data) === null || _state$data === void 0 ? void 0 : _state$data.account,
380
- chain: state === null || state === void 0 ? void 0 : (_state$data2 = state.data) === null || _state$data2 === void 0 ? void 0 : _state$data2.chain
381
- }
382
- }),
383
- chains: state === null || state === void 0 ? void 0 : state.chains
384
- };
385
- },
386
- version: 1
387
- })));
388
- this.config = {
389
- autoConnect,
390
- connectors: _connectors,
391
- provider: _provider,
392
- storage,
393
- webSocketProvider: _webSocketProvider
394
- };
395
- this.storage = storage;
396
-
397
- base._classPrivateFieldSet(this, _lastUsedConnector, storage === null || storage === void 0 ? void 0 : storage.getItem('wallet'));
398
-
399
- classPrivateMethodGet._classPrivateMethodGet(this, _addEffects, _addEffects2).call(this);
400
- }
401
-
402
- get chains() {
403
- return this.store.getState().chains;
404
- }
405
-
406
- get connectors() {
407
- return this.store.getState().connectors;
408
- }
409
-
410
- get connector() {
411
- return this.store.getState().connector;
412
- }
413
-
414
- get data() {
415
- return this.store.getState().data;
416
- }
417
-
418
- get error() {
419
- return this.store.getState().error;
420
- }
421
-
422
- get provider() {
423
- return this.store.getState().provider;
424
- }
425
-
426
- get status() {
427
- return this.store.getState().status;
428
- }
429
-
430
- get subscribe() {
431
- return this.store.subscribe;
432
- }
433
-
434
- get webSocketProvider() {
435
- return this.store.getState().webSocketProvider;
436
- }
437
-
438
- setState(updater) {
439
- const newState = typeof updater === 'function' ? updater(this.store.getState()) : updater;
440
- this.store.setState(newState, true);
441
- }
442
-
443
- clearState() {
444
- this.setState(x => ({ ...x,
445
- connector: undefined,
446
- data: undefined,
447
- error: undefined,
448
- status: 'disconnected'
449
- }));
450
- }
451
-
452
- async destroy() {
453
- var _this$connector$disco, _this$connector;
454
-
455
- 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));
456
- this.clearState();
457
- this.store.destroy();
458
- }
459
-
460
- async autoConnect() {
461
- if (!this.connectors.length) return; // Try last used connector first
462
-
463
- const sorted = base._classPrivateFieldGet(this, _lastUsedConnector) ? [...this.connectors].sort(x => x.id === base._classPrivateFieldGet(this, _lastUsedConnector) ? -1 : 1) : this.connectors;
464
- let connected = false;
465
-
466
- for (const connector of sorted) {
467
- if (!connector.ready || !connector.isAuthorized) continue;
468
- const isAuthorized = await connector.isAuthorized();
469
- if (!isAuthorized) continue;
470
- const data = await connector.connect();
471
- this.setState(x => ({ ...x,
472
- connector,
473
- chains: connector === null || connector === void 0 ? void 0 : connector.chains,
474
- data,
475
- status: 'connected'
476
- }));
477
- connected = true;
478
- break;
479
- } // If connecting didn't succeed, set to disconnected
480
-
481
-
482
- if (!connected) this.setState(x => ({ ...x,
483
- status: 'disconnected'
484
- }));
485
- return this.data;
486
- }
487
-
488
- setLastUsedConnector() {
489
- var _this$storage;
490
-
491
- let lastUsedConnector = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
492
- (_this$storage = this.storage) === null || _this$storage === void 0 ? void 0 : _this$storage.setItem('wallet', lastUsedConnector);
493
- }
494
-
495
- }
496
-
497
- function _addEffects2() {
498
- const onChange = data => {
499
- this.setState(x => ({ ...x,
500
- data: { ...x.data,
501
- ...data
502
- }
503
- }));
504
- };
505
-
506
- const onDisconnect = () => {
507
- this.clearState();
508
- };
509
-
510
- const onError = error => {
511
- this.setState(x => ({ ...x,
512
- error
513
- }));
514
- };
515
-
516
- this.store.subscribe(_ref => {
517
- let {
518
- connector
519
- } = _ref;
520
- return connector;
521
- }, (connector, prevConnector) => {
522
- var _prevConnector$off, _prevConnector$off2, _prevConnector$off3, _connector$on, _connector$on2, _connector$on3;
523
-
524
- prevConnector === null || prevConnector === void 0 ? void 0 : (_prevConnector$off = prevConnector.off) === null || _prevConnector$off === void 0 ? void 0 : _prevConnector$off.call(prevConnector, 'change', onChange);
525
- prevConnector === null || prevConnector === void 0 ? void 0 : (_prevConnector$off2 = prevConnector.off) === null || _prevConnector$off2 === void 0 ? void 0 : _prevConnector$off2.call(prevConnector, 'disconnect', onDisconnect);
526
- prevConnector === null || prevConnector === void 0 ? void 0 : (_prevConnector$off3 = prevConnector.off) === null || _prevConnector$off3 === void 0 ? void 0 : _prevConnector$off3.call(prevConnector, 'error', onError);
527
- if (!connector) return;
528
- (_connector$on = connector.on) === null || _connector$on === void 0 ? void 0 : _connector$on.call(connector, 'change', onChange);
529
- (_connector$on2 = connector.on) === null || _connector$on2 === void 0 ? void 0 : _connector$on2.call(connector, 'disconnect', onDisconnect);
530
- (_connector$on3 = connector.on) === null || _connector$on3 === void 0 ? void 0 : _connector$on3.call(connector, 'error', onError);
531
- });
532
- const {
533
- connectors,
534
- provider,
535
- webSocketProvider
536
- } = this.config;
537
- const subscribeConnectors = typeof connectors === 'function';
538
- const subscribeProvider = typeof provider === 'function';
539
- const subscribeWebSocketProvider = typeof webSocketProvider === 'function';
540
- if (subscribeConnectors || subscribeProvider || subscribeWebSocketProvider) this.store.subscribe(_ref2 => {
541
- var _data$chain2;
542
-
543
- let {
544
- data
545
- } = _ref2;
546
- return data === null || data === void 0 ? void 0 : (_data$chain2 = data.chain) === null || _data$chain2 === void 0 ? void 0 : _data$chain2.id;
547
- }, chainId => {
548
- this.setState(x => ({ ...x,
549
- connectors: subscribeConnectors ? connectors({
550
- chainId
551
- }) : x.connectors,
552
- provider: subscribeProvider ? provider({
553
- chainId
554
- }) : x.provider,
555
- webSocketProvider: subscribeWebSocketProvider ? webSocketProvider({
556
- chainId
557
- }) : x.webSocketProvider
558
- }));
559
- });
560
- }
561
-
562
- let client;
563
- function createClient(config) {
564
- const client_ = new Client(config);
565
- client = client_;
566
- return client_;
567
- }
568
- function getClient() {
569
- return client;
570
- }
571
-
572
23
  async function connect(_ref) {
573
24
  let {
574
25
  connector
575
26
  } = _ref;
576
- const activeConnector = client.connector;
27
+ const activeConnector = client.client.connector;
577
28
  if (connector.id === (activeConnector === null || activeConnector === void 0 ? void 0 : activeConnector.id)) throw new base.ConnectorAlreadyConnectedError();
578
29
  const data = await connector.connect();
579
- client.setLastUsedConnector(connector.id);
580
- client.setState(x => ({ ...x,
30
+ client.client.setLastUsedConnector(connector.id);
31
+ client.client.setState(x => ({ ...x,
581
32
  connector,
582
33
  chains: connector === null || connector === void 0 ? void 0 : connector.chains,
583
34
  data
584
35
  }));
585
- client.storage.setItem('connected', true);
36
+ client.client.storage.setItem('connected', true);
586
37
  return { ...data,
587
38
  connector
588
39
  };
589
40
  }
590
41
 
591
42
  async function disconnect() {
592
- const client = getClient();
593
- if (client.connector) await client.connector.disconnect();
594
- client.clearState();
595
- client.storage.removeItem('connected');
43
+ const client$1 = client.getClient();
44
+ if (client$1.connector) await client$1.connector.disconnect();
45
+ client$1.clearState();
46
+ client$1.storage.removeItem('connected');
596
47
  }
597
48
 
598
49
  function getProvider() {
599
50
  let {
600
51
  chainId
601
52
  } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
602
- const client = getClient();
603
- if (chainId && typeof client.config.provider === 'function') return client.config.provider({
53
+ const client$1 = client.getClient();
54
+ if (chainId && typeof client$1.config.provider === 'function') return client$1.config.provider({
604
55
  chainId
605
56
  });
606
- return client.provider;
57
+ return client$1.provider;
607
58
  }
608
59
 
609
60
  function getWebSocketProvider() {
610
61
  let {
611
62
  chainId
612
63
  } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
613
- const client = getClient();
614
- if (chainId && typeof client.config.webSocketProvider === 'function') return client.config.webSocketProvider({
64
+ const client$1 = client.getClient();
65
+ if (chainId && typeof client$1.config.webSocketProvider === 'function') return client$1.config.webSocketProvider({
615
66
  chainId
616
67
  });
617
- return client.webSocketProvider;
68
+ return client$1.webSocketProvider;
618
69
  }
619
70
 
620
71
  function watchProvider(args, callback) {
621
- const client = getClient();
72
+ const client$1 = client.getClient();
622
73
 
623
74
  const handleChange = async () => callback(getProvider(args));
624
75
 
625
- const unsubscribe = client.subscribe(_ref => {
76
+ const unsubscribe = client$1.subscribe(_ref => {
626
77
  let {
627
78
  provider
628
79
  } = _ref;
@@ -632,11 +83,11 @@ function watchProvider(args, callback) {
632
83
  }
633
84
 
634
85
  function watchWebSocketProvider(args, callback) {
635
- const client = getClient();
86
+ const client$1 = client.getClient();
636
87
 
637
88
  const handleChange = async () => callback(getWebSocketProvider(args));
638
89
 
639
- const unsubscribe = client.subscribe(_ref => {
90
+ const unsubscribe = client$1.subscribe(_ref => {
640
91
  let {
641
92
  webSocketProvider
642
93
  } = _ref;
@@ -654,13 +105,13 @@ async function fetchBalance(_ref) {
654
105
  formatUnits: unit = 'ether',
655
106
  token
656
107
  } = _ref;
657
- const client = getClient();
108
+ const client$1 = client.getClient();
658
109
  const provider = getProvider({
659
110
  chainId
660
111
  });
661
112
 
662
113
  if (token) {
663
- const contract = new ethers$1.Contract(token, erc20ABI, provider);
114
+ const contract = new ethers.Contract(token, erc20ABI, provider);
664
115
  const [value, decimals, symbol] = await Promise.all([contract.balanceOf(addressOrName), contract.decimals(), contract.symbol()]);
665
116
  return {
666
117
  decimals,
@@ -671,7 +122,7 @@ async function fetchBalance(_ref) {
671
122
  };
672
123
  }
673
124
 
674
- const chains = [...((_client$connector$cha = (_client$connector = client.connector) === null || _client$connector === void 0 ? void 0 : _client$connector.chains) !== null && _client$connector$cha !== void 0 ? _client$connector$cha : []), ...base.allChains];
125
+ const chains = [...((_client$connector$cha = (_client$connector = client$1.connector) === null || _client$connector === void 0 ? void 0 : _client$connector.chains) !== null && _client$connector$cha !== void 0 ? _client$connector$cha : []), ...base.allChains];
675
126
  const value = await provider.getBalance(addressOrName);
676
127
  const chain = chains.find(x => x.id === provider.network.chainId);
677
128
  return {
@@ -686,8 +137,8 @@ async function fetchBalance(_ref) {
686
137
  async function fetchSigner() {
687
138
  var _client$connector, _client$connector$get;
688
139
 
689
- const client = getClient();
690
- const signer = (await ((_client$connector = client.connector) === null || _client$connector === void 0 ? void 0 : (_client$connector$get = _client$connector.getSigner) === null || _client$connector$get === void 0 ? void 0 : _client$connector$get.call(_client$connector))) || null;
140
+ const client$1 = client.getClient();
141
+ const signer = (await ((_client$connector = client$1.connector) === null || _client$connector === void 0 ? void 0 : (_client$connector$get = _client$connector.getSigner) === null || _client$connector$get === void 0 ? void 0 : _client$connector$get.call(_client$connector))) || null;
691
142
  return signer;
692
143
  }
693
144
 
@@ -695,7 +146,7 @@ function getAccount() {
695
146
  const {
696
147
  data,
697
148
  connector
698
- } = getClient();
149
+ } = client.getClient();
699
150
  return {
700
151
  address: data === null || data === void 0 ? void 0 : data.account,
701
152
  connector
@@ -705,9 +156,9 @@ function getAccount() {
705
156
  function getNetwork() {
706
157
  var _client$data, _client$data$chain, _client$chains, _find, _client$data2;
707
158
 
708
- const client = getClient();
709
- const chainId = (_client$data = client.data) === null || _client$data === void 0 ? void 0 : (_client$data$chain = _client$data.chain) === null || _client$data$chain === void 0 ? void 0 : _client$data$chain.id;
710
- const activeChains = (_client$chains = client.chains) !== null && _client$chains !== void 0 ? _client$chains : [];
159
+ const client$1 = client.getClient();
160
+ const chainId = (_client$data = client$1.data) === null || _client$data === void 0 ? void 0 : (_client$data$chain = _client$data.chain) === null || _client$data$chain === void 0 ? void 0 : _client$data$chain.id;
161
+ const activeChains = (_client$chains = client$1.chains) !== null && _client$chains !== void 0 ? _client$chains : [];
711
162
  const activeChain = (_find = [...activeChains, ...base.allChains].find(x => x.id === chainId)) !== null && _find !== void 0 ? _find : {
712
163
  id: chainId,
713
164
  name: "Chain ".concat(chainId),
@@ -717,7 +168,7 @@ function getNetwork() {
717
168
  };
718
169
  return {
719
170
  chain: chainId ? { ...activeChain,
720
- ...((_client$data2 = client.data) === null || _client$data2 === void 0 ? void 0 : _client$data2.chain),
171
+ ...((_client$data2 = client$1.data) === null || _client$data2 === void 0 ? void 0 : _client$data2.chain),
721
172
  id: chainId
722
173
  } : undefined,
723
174
  chains: activeChains
@@ -755,18 +206,18 @@ async function switchNetwork(_ref) {
755
206
  let {
756
207
  chainId
757
208
  } = _ref;
758
- const client = getClient();
759
- if (!((_client$connector = client.connector) !== null && _client$connector !== void 0 && _client$connector.switchChain)) throw new base.SwitchChainNotSupportedError();
760
- const chain = await client.connector.switchChain(chainId);
209
+ const client$1 = client.getClient();
210
+ if (!((_client$connector = client$1.connector) !== null && _client$connector !== void 0 && _client$connector.switchChain)) throw new base.SwitchChainNotSupportedError();
211
+ const chain = await client$1.connector.switchChain(chainId);
761
212
  return chain;
762
213
  }
763
214
 
764
215
  function watchAccount(callback) {
765
- const client = getClient();
216
+ const client$1 = client.getClient();
766
217
 
767
218
  const handleChange = () => callback(getAccount());
768
219
 
769
- const unsubscribe = client.subscribe(_ref => {
220
+ const unsubscribe = client$1.subscribe(_ref => {
770
221
  let {
771
222
  data,
772
223
  connector
@@ -782,11 +233,11 @@ function watchAccount(callback) {
782
233
  }
783
234
 
784
235
  function watchNetwork(callback) {
785
- const client = getClient();
236
+ const client$1 = client.getClient();
786
237
 
787
238
  const handleChange = () => callback(getNetwork());
788
239
 
789
- const unsubscribe = client.subscribe(_ref => {
240
+ const unsubscribe = client$1.subscribe(_ref => {
790
241
  var _data$chain;
791
242
 
792
243
  let {
@@ -804,11 +255,11 @@ function watchNetwork(callback) {
804
255
  }
805
256
 
806
257
  function watchSigner(callback) {
807
- const client = getClient();
258
+ const client$1 = client.getClient();
808
259
 
809
260
  const handleChange = async () => callback(await fetchSigner());
810
261
 
811
- const unsubscribe = client.subscribe(_ref => {
262
+ const unsubscribe = client$1.subscribe(_ref => {
812
263
  var _data$chain;
813
264
 
814
265
  let {
@@ -832,7 +283,7 @@ function getContract(_ref) {
832
283
  contractInterface,
833
284
  signerOrProvider
834
285
  } = _ref;
835
- return new ethers$1.Contract(addressOrName, contractInterface, signerOrProvider);
286
+ return new ethers.Contract(addressOrName, contractInterface, signerOrProvider);
836
287
  }
837
288
 
838
289
  async function readContract(contractConfig, functionName) {
@@ -885,8 +336,8 @@ eventName, callback) {
885
336
  };
886
337
 
887
338
  watchEvent();
888
- const client = getClient();
889
- const unsubscribe = client.subscribe(_ref => {
339
+ const client$1 = client.getClient();
340
+ const unsubscribe = client$1.subscribe(_ref => {
890
341
  let {
891
342
  provider,
892
343
  webSocketProvider
@@ -933,10 +384,10 @@ function watchBlockNumber(args, callback) {
933
384
  prevProvider = provider;
934
385
  };
935
386
 
936
- const client = getClient();
937
- const provider_ = (_client$webSocketProv = client.webSocketProvider) !== null && _client$webSocketProv !== void 0 ? _client$webSocketProv : client.provider;
387
+ const client$1 = client.getClient();
388
+ const provider_ = (_client$webSocketProv = client$1.webSocketProvider) !== null && _client$webSocketProv !== void 0 ? _client$webSocketProv : client$1.provider;
938
389
  if (args.listen) createListener(provider_);
939
- const unsubscribe = client.subscribe(_ref => {
390
+ const unsubscribe = client$1.subscribe(_ref => {
940
391
  let {
941
392
  provider,
942
393
  webSocketProvider
@@ -969,14 +420,14 @@ function watchBlockNumber(args, callback) {
969
420
  function watchReadContract(contractConfig, functionName) {
970
421
  let config = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
971
422
  let callback = arguments.length > 3 ? arguments[3] : undefined;
972
- const client = getClient();
423
+ const client$1 = client.getClient();
973
424
 
974
425
  const handleChange = async () => callback(await readContract(contractConfig, functionName, config));
975
426
 
976
427
  const unwatch = config.listenToBlock ? watchBlockNumber({
977
428
  listen: true
978
429
  }, handleChange) : undefined;
979
- const unsubscribe = client.subscribe(_ref => {
430
+ const unsubscribe = client$1.subscribe(_ref => {
980
431
  let {
981
432
  provider
982
433
  } = _ref;
@@ -993,12 +444,12 @@ async function writeContract(contractConfig, functionName) {
993
444
  args,
994
445
  overrides
995
446
  } = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
996
- const client = getClient();
997
- if (!client.connector) throw new base.ConnectorNotFoundError();
447
+ const client$1 = client.getClient();
448
+ if (!client$1.connector) throw new base.ConnectorNotFoundError();
998
449
  const params = [...(Array.isArray(args) ? args : args ? [args] : []), ...(overrides ? [overrides] : [])];
999
450
 
1000
451
  try {
1001
- const signer = await client.connector.getSigner();
452
+ const signer = await client$1.connector.getSigner();
1002
453
  const contract = getContract(contractConfig);
1003
454
  const contractWithSigner = contract.connect(signer);
1004
455
  const contractFunction = contractWithSigner[functionName];
@@ -1094,7 +545,7 @@ async function fetchToken(_ref) {
1094
545
  const provider = getProvider({
1095
546
  chainId
1096
547
  });
1097
- const contract = new ethers$1.Contract(address, erc20ABI, provider);
548
+ const contract = new ethers.Contract(address, erc20ABI, provider);
1098
549
  const [symbol, decimals, totalSupply] = await Promise.all([contract.symbol(), contract.decimals(), contract.totalSupply()]);
1099
550
  const token = {
1100
551
  address,
@@ -1141,6 +592,14 @@ async function waitForTransaction(_ref) {
1141
592
  return await promise;
1142
593
  }
1143
594
 
595
+ exports.Client = client.Client;
596
+ exports.InjectedConnector = client.InjectedConnector;
597
+ exports.WagmiClient = client.Client;
598
+ exports.createClient = client.createClient;
599
+ exports.createStorage = client.createStorage;
600
+ exports.createWagmiClient = client.createClient;
601
+ exports.createWagmiStorage = client.createStorage;
602
+ exports.noopStorage = client.noopStorage;
1144
603
  exports.AddChainError = base.AddChainError;
1145
604
  exports.ChainNotConfiguredError = base.ChainNotConfiguredError;
1146
605
  exports.Connector = base.Connector;
@@ -1158,14 +617,7 @@ exports.defaultL2Chains = base.defaultL2Chains;
1158
617
  exports.etherscanBlockExplorers = base.etherscanBlockExplorers;
1159
618
  exports.infuraRpcUrls = base.infuraRpcUrls;
1160
619
  exports.normalizeChainId = base.normalizeChainId;
1161
- exports.Client = Client;
1162
- exports.InjectedConnector = InjectedConnector;
1163
- exports.WagmiClient = Client;
1164
620
  exports.connect = connect;
1165
- exports.createClient = createClient;
1166
- exports.createStorage = createStorage;
1167
- exports.createWagmiClient = createClient;
1168
- exports.createWagmiStorage = createStorage;
1169
621
  exports.disconnect = disconnect;
1170
622
  exports.erc20ABI = erc20ABI;
1171
623
  exports.erc721ABI = erc721ABI;
@@ -1183,7 +635,6 @@ exports.getContract = getContract;
1183
635
  exports.getNetwork = getNetwork;
1184
636
  exports.getProvider = getProvider;
1185
637
  exports.getWebSocketProvider = getWebSocketProvider;
1186
- exports.noopStorage = noopStorage;
1187
638
  exports.readContract = readContract;
1188
639
  exports.sendTransaction = sendTransaction;
1189
640
  exports.signMessage = signMessage;