@wagmi/core 0.5.7 → 0.5.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.
@@ -1,4 +1,4 @@
1
- import { l as Connector, _ as _classPrivateMethodInitSpec, t as _defineProperty, u as _classPrivateFieldInitSpec, n as normalizeChainId, U as UserRejectedRequestError, v as _classPrivateFieldGet, w as _classPrivateFieldSet, m as ChainNotConfiguredError, x as _classPrivateMethodGet, A as AddChainError, q as SwitchChainError } from '../../../dist/getProvider-f1dfc7e3.esm.js';
1
+ import { l as Connector, _ as _classPrivateMethodInitSpec, t as _defineProperty, u as _classPrivateFieldInitSpec, n as normalizeChainId, U as UserRejectedRequestError, v as _classPrivateFieldGet, w as _classPrivateFieldSet, m as ChainNotConfiguredError, x as _classPrivateMethodGet, A as AddChainError, q as SwitchChainError } from '../../../dist/getProvider-5b4b62c3.esm.js';
2
2
  import { providers } from 'ethers';
3
3
  import { getAddress, hexValue } from 'ethers/lib/utils';
4
4
  import 'zustand/middleware';
@@ -1,4 +1,4 @@
1
- import { I as InjectedConnector, _ as _classPrivateMethodInitSpec, t as _defineProperty, x as _classPrivateMethodGet, u as _classPrivateFieldInitSpec, w as _classPrivateFieldSet, a as ConnectorNotFoundError, v as _classPrivateFieldGet, g as getClient, U as UserRejectedRequestError, R as ResourceUnavailableError } from '../../../dist/getProvider-f1dfc7e3.esm.js';
1
+ import { I as InjectedConnector, _ as _classPrivateMethodInitSpec, t as _defineProperty, x as _classPrivateMethodGet, u as _classPrivateFieldInitSpec, w as _classPrivateFieldSet, a as ConnectorNotFoundError, v as _classPrivateFieldGet, g as getClient, U as UserRejectedRequestError, R as ResourceUnavailableError } from '../../../dist/getProvider-5b4b62c3.esm.js';
2
2
  import 'zustand/middleware';
3
3
  import 'zustand/vanilla';
4
4
  import 'ethers';
@@ -1,4 +1,4 @@
1
- import { t as _defineProperty, u as _classPrivateFieldInitSpec, w as _classPrivateFieldSet, v as _classPrivateFieldGet, U as UserRejectedRequestError, l as Connector, _ as _classPrivateMethodInitSpec, n as normalizeChainId, x as _classPrivateMethodGet } from '../../../dist/getProvider-f1dfc7e3.esm.js';
1
+ import { t as _defineProperty, u as _classPrivateFieldInitSpec, w as _classPrivateFieldSet, v as _classPrivateFieldGet, U as UserRejectedRequestError, l as Connector, _ as _classPrivateMethodInitSpec, n as normalizeChainId, x as _classPrivateMethodGet } from '../../../dist/getProvider-5b4b62c3.esm.js';
2
2
  import { getAddress } from 'ethers/lib/utils';
3
3
  import { providers } from 'ethers';
4
4
  import EventEmitter from 'eventemitter3';
@@ -1,4 +1,4 @@
1
- import { l as Connector, _ as _classPrivateMethodInitSpec, t as _defineProperty, u as _classPrivateFieldInitSpec, n as normalizeChainId, g as getClient, x as _classPrivateMethodGet, U as UserRejectedRequestError, v as _classPrivateFieldGet, w as _classPrivateFieldSet, q as SwitchChainError } from '../../../dist/getProvider-f1dfc7e3.esm.js';
1
+ import { l as Connector, _ as _classPrivateMethodInitSpec, t as _defineProperty, u as _classPrivateFieldInitSpec, n as normalizeChainId, g as getClient, x as _classPrivateMethodGet, U as UserRejectedRequestError, v as _classPrivateFieldGet, w as _classPrivateFieldSet, q as SwitchChainError } from '../../../dist/getProvider-5b4b62c3.esm.js';
2
2
  import { providers } from 'ethers';
3
3
  import { getAddress, hexValue } from 'ethers/lib/utils';
4
4
  import 'zustand/middleware';
@@ -1,5 +1,6 @@
1
1
  import { FetchBlockNumberResult } from './fetchBlockNumber';
2
2
  export declare type WatchBlockNumberArgs = {
3
+ chainId?: number;
3
4
  listen: boolean;
4
5
  };
5
6
  export declare type WatchBlockNumberCallback = (blockNumber: FetchBlockNumberResult) => void;
@@ -49,6 +49,7 @@ export declare abstract class Connector<Provider = any, Options = any, Signer =
49
49
  switchChain?(chainId: number): Promise<Chain>;
50
50
  watchAsset?(asset: {
51
51
  address: string;
52
+ decimals?: number;
52
53
  image?: string;
53
54
  symbol: string;
54
55
  }): Promise<boolean>;
@@ -1,2 +1,150 @@
1
1
  export declare const erc20ABI: string[];
2
+ /**
3
+ * [bytes32-flavored ERC-20](https://docs.makerdao.com/smart-contract-modules/mkr-module#4.-gotchas-potential-source-of-user-error)
4
+ * for tokens (ie. Maker) that use bytes32 instead of string.
5
+ */
6
+ export declare const erc20ABI_bytes32: readonly [{
7
+ readonly type: "event";
8
+ readonly name: "Approval";
9
+ readonly inputs: readonly [{
10
+ readonly indexed: true;
11
+ readonly name: "owner";
12
+ readonly type: "address";
13
+ }, {
14
+ readonly indexed: true;
15
+ readonly name: "spender";
16
+ readonly type: "address";
17
+ }, {
18
+ readonly indexed: false;
19
+ readonly name: "value";
20
+ readonly type: "uint256";
21
+ }];
22
+ }, {
23
+ readonly type: "event";
24
+ readonly name: "Transfer";
25
+ readonly inputs: readonly [{
26
+ readonly indexed: true;
27
+ readonly name: "from";
28
+ readonly type: "address";
29
+ }, {
30
+ readonly indexed: true;
31
+ readonly name: "to";
32
+ readonly type: "address";
33
+ }, {
34
+ readonly indexed: false;
35
+ readonly name: "value";
36
+ readonly type: "uint256";
37
+ }];
38
+ }, {
39
+ readonly type: "function";
40
+ readonly name: "allowance";
41
+ readonly stateMutability: "view";
42
+ readonly inputs: readonly [{
43
+ readonly name: "owner";
44
+ readonly type: "address";
45
+ }, {
46
+ readonly name: "spender";
47
+ readonly type: "address";
48
+ }];
49
+ readonly outputs: readonly [{
50
+ readonly name: "";
51
+ readonly type: "uint256";
52
+ }];
53
+ }, {
54
+ readonly type: "function";
55
+ readonly name: "approve";
56
+ readonly stateMutability: "nonpayable";
57
+ readonly inputs: readonly [{
58
+ readonly name: "spender";
59
+ readonly type: "address";
60
+ }, {
61
+ readonly name: "amount";
62
+ readonly type: "uint256";
63
+ }];
64
+ readonly outputs: readonly [{
65
+ readonly name: "";
66
+ readonly type: "bool";
67
+ }];
68
+ }, {
69
+ readonly type: "function";
70
+ readonly name: "balanceOf";
71
+ readonly stateMutability: "view";
72
+ readonly inputs: readonly [{
73
+ readonly name: "account";
74
+ readonly type: "address";
75
+ }];
76
+ readonly outputs: readonly [{
77
+ readonly name: "";
78
+ readonly type: "uint256";
79
+ }];
80
+ }, {
81
+ readonly type: "function";
82
+ readonly name: "decimals";
83
+ readonly stateMutability: "view";
84
+ readonly inputs: readonly [];
85
+ readonly outputs: readonly [{
86
+ readonly name: "";
87
+ readonly type: "uint8";
88
+ }];
89
+ }, {
90
+ readonly type: "function";
91
+ readonly name: "name";
92
+ readonly stateMutability: "view";
93
+ readonly inputs: readonly [];
94
+ readonly outputs: readonly [{
95
+ readonly name: "";
96
+ readonly type: "bytes32";
97
+ }];
98
+ }, {
99
+ readonly type: "function";
100
+ readonly name: "symbol";
101
+ readonly stateMutability: "view";
102
+ readonly inputs: readonly [];
103
+ readonly outputs: readonly [{
104
+ readonly name: "";
105
+ readonly type: "bytes32";
106
+ }];
107
+ }, {
108
+ readonly type: "function";
109
+ readonly name: "totalSupply";
110
+ readonly stateMutability: "view";
111
+ readonly inputs: readonly [];
112
+ readonly outputs: readonly [{
113
+ readonly name: "";
114
+ readonly type: "uint256";
115
+ }];
116
+ }, {
117
+ readonly type: "function";
118
+ readonly name: "transfer";
119
+ readonly stateMutability: "nonpayable";
120
+ readonly inputs: readonly [{
121
+ readonly name: "recipient";
122
+ readonly type: "address";
123
+ }, {
124
+ readonly name: "amount";
125
+ readonly type: "uint256";
126
+ }];
127
+ readonly outputs: readonly [{
128
+ readonly name: "";
129
+ readonly type: "bool";
130
+ }];
131
+ }, {
132
+ readonly type: "function";
133
+ readonly name: "transferFrom";
134
+ readonly stateMutability: "nonpayable";
135
+ readonly inputs: readonly [{
136
+ readonly name: "sender";
137
+ readonly type: "address";
138
+ }, {
139
+ readonly name: "recipient";
140
+ readonly type: "address";
141
+ }, {
142
+ readonly name: "amount";
143
+ readonly type: "uint256";
144
+ }];
145
+ readonly outputs: readonly [{
146
+ readonly name: "";
147
+ readonly type: "bool";
148
+ }];
149
+ }];
2
150
  export declare const erc721ABI: string[];
@@ -1,4 +1,4 @@
1
- export { erc20ABI, erc721ABI } from './abis';
1
+ export { erc20ABI, erc20ABI_bytes32, erc721ABI } from './abis';
2
2
  export { etherscanBlockExplorers } from './blockExplorers';
3
3
  export type { BlockExplorer, BlockExplorerName } from './blockExplorers';
4
4
  export { chain, chainId, allChains, defaultChains, defaultL2Chains, } from './chains';
@@ -1096,4 +1096,4 @@ function getProvider() {
1096
1096
  return client.provider;
1097
1097
  }
1098
1098
 
1099
- export { AddChainError as A, ConnectorAlreadyConnectedError as C, InjectedConnector as I, ProviderChainsNotFound as P, ResourceUnavailableError as R, SwitchChainNotSupportedError as S, UserRejectedRequestError as U, _classPrivateMethodInitSpec as _, ConnectorNotFoundError as a, ChainMismatchError as b, ContractMethodDoesNotExistError as c, getProvider as d, ChainDoesNotSupportMulticallError as e, ContractMethodRevertedError as f, getClient as g, ContractMethodNoResultError as h, ContractResultDecodeError as i, createClient as j, Client as k, Connector as l, ChainNotConfiguredError as m, normalizeChainId as n, ProviderRpcError as o, RpcError as p, SwitchChainError as q, createStorage as r, noopStorage as s, _defineProperty as t, _classPrivateFieldInitSpec as u, _classPrivateFieldGet as v, _classPrivateFieldSet as w, _classPrivateMethodGet as x };
1099
+ export { AddChainError as A, ConnectorAlreadyConnectedError as C, InjectedConnector as I, ProviderChainsNotFound as P, ResourceUnavailableError as R, SwitchChainNotSupportedError as S, UserRejectedRequestError as U, _classPrivateMethodInitSpec as _, ConnectorNotFoundError as a, ChainMismatchError as b, ContractResultDecodeError as c, ContractMethodDoesNotExistError as d, getProvider as e, ChainDoesNotSupportMulticallError as f, getClient as g, ContractMethodRevertedError as h, ContractMethodNoResultError as i, createClient as j, Client as k, Connector as l, ChainNotConfiguredError as m, normalizeChainId as n, ProviderRpcError as o, RpcError as p, SwitchChainError as q, createStorage as r, noopStorage as s, _defineProperty as t, _classPrivateFieldInitSpec as u, _classPrivateFieldGet as v, _classPrivateFieldSet as w, _classPrivateMethodGet as x };
@@ -220,7 +220,156 @@ function parseContractResult(_ref) {
220
220
  }
221
221
 
222
222
  // https://ethereum.org/en/developers/docs/standards/tokens/erc-20
223
- 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
223
+ 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)'];
224
+ /**
225
+ * [bytes32-flavored ERC-20](https://docs.makerdao.com/smart-contract-modules/mkr-module#4.-gotchas-potential-source-of-user-error)
226
+ * for tokens (ie. Maker) that use bytes32 instead of string.
227
+ */
228
+
229
+ const erc20ABI_bytes32 = [{
230
+ type: 'event',
231
+ name: 'Approval',
232
+ inputs: [{
233
+ indexed: true,
234
+ name: 'owner',
235
+ type: 'address'
236
+ }, {
237
+ indexed: true,
238
+ name: 'spender',
239
+ type: 'address'
240
+ }, {
241
+ indexed: false,
242
+ name: 'value',
243
+ type: 'uint256'
244
+ }]
245
+ }, {
246
+ type: 'event',
247
+ name: 'Transfer',
248
+ inputs: [{
249
+ indexed: true,
250
+ name: 'from',
251
+ type: 'address'
252
+ }, {
253
+ indexed: true,
254
+ name: 'to',
255
+ type: 'address'
256
+ }, {
257
+ indexed: false,
258
+ name: 'value',
259
+ type: 'uint256'
260
+ }]
261
+ }, {
262
+ type: 'function',
263
+ name: 'allowance',
264
+ stateMutability: 'view',
265
+ inputs: [{
266
+ name: 'owner',
267
+ type: 'address'
268
+ }, {
269
+ name: 'spender',
270
+ type: 'address'
271
+ }],
272
+ outputs: [{
273
+ name: '',
274
+ type: 'uint256'
275
+ }]
276
+ }, {
277
+ type: 'function',
278
+ name: 'approve',
279
+ stateMutability: 'nonpayable',
280
+ inputs: [{
281
+ name: 'spender',
282
+ type: 'address'
283
+ }, {
284
+ name: 'amount',
285
+ type: 'uint256'
286
+ }],
287
+ outputs: [{
288
+ name: '',
289
+ type: 'bool'
290
+ }]
291
+ }, {
292
+ type: 'function',
293
+ name: 'balanceOf',
294
+ stateMutability: 'view',
295
+ inputs: [{
296
+ name: 'account',
297
+ type: 'address'
298
+ }],
299
+ outputs: [{
300
+ name: '',
301
+ type: 'uint256'
302
+ }]
303
+ }, {
304
+ type: 'function',
305
+ name: 'decimals',
306
+ stateMutability: 'view',
307
+ inputs: [],
308
+ outputs: [{
309
+ name: '',
310
+ type: 'uint8'
311
+ }]
312
+ }, {
313
+ type: 'function',
314
+ name: 'name',
315
+ stateMutability: 'view',
316
+ inputs: [],
317
+ outputs: [{
318
+ name: '',
319
+ type: 'bytes32'
320
+ }]
321
+ }, {
322
+ type: 'function',
323
+ name: 'symbol',
324
+ stateMutability: 'view',
325
+ inputs: [],
326
+ outputs: [{
327
+ name: '',
328
+ type: 'bytes32'
329
+ }]
330
+ }, {
331
+ type: 'function',
332
+ name: 'totalSupply',
333
+ stateMutability: 'view',
334
+ inputs: [],
335
+ outputs: [{
336
+ name: '',
337
+ type: 'uint256'
338
+ }]
339
+ }, {
340
+ type: 'function',
341
+ name: 'transfer',
342
+ stateMutability: 'nonpayable',
343
+ inputs: [{
344
+ name: 'recipient',
345
+ type: 'address'
346
+ }, {
347
+ name: 'amount',
348
+ type: 'uint256'
349
+ }],
350
+ outputs: [{
351
+ name: '',
352
+ type: 'bool'
353
+ }]
354
+ }, {
355
+ type: 'function',
356
+ name: 'transferFrom',
357
+ stateMutability: 'nonpayable',
358
+ inputs: [{
359
+ name: 'sender',
360
+ type: 'address'
361
+ }, {
362
+ name: 'recipient',
363
+ type: 'address'
364
+ }, {
365
+ name: 'amount',
366
+ type: 'uint256'
367
+ }],
368
+ outputs: [{
369
+ name: '',
370
+ type: 'bool'
371
+ }]
372
+ }]; // https://ethereum.org/en/developers/docs/standards/tokens/erc-721
224
373
 
225
374
  const erc721ABI = ['event Approval(address indexed _owner, address indexed _approved, uint256 indexed _tokenId)', 'event ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved)', 'event Transfer(address indexed _from, address indexed _to, uint256 indexed _tokenId)', 'function approve(address _approved, uint256 _tokenId) external payable', 'function balanceOf(address _owner) external view returns (uint256)', 'function getApproved(uint256 _tokenId) external view returns (address)', 'function isApprovedForAll(address _owner, address _operator) external view returns (bool)', 'function name() view returns (string memory)', 'function ownerOf(uint256 _tokenId) external view returns (address)', 'function safeTransferFrom(address _from, address _to, uint256 _tokenId) external payable', 'function safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes data) external payable', 'function setApprovalForAll(address _operator, bool _approved) external', 'function symbol() view returns (string memory)', 'function tokenByIndex(uint256 _index) view returns (uint256)', 'function tokenOfOwnerByIndex(address _owner, uint256 _index) view returns (uint256 tokenId)', 'function tokenURI(uint256 _tokenId) view returns (string memory)', 'function totalSupply() view returns (uint256)', 'function transferFrom(address _from, address _to, uint256 _tokenId) external payable'];
226
375
 
@@ -377,33 +526,65 @@ async function fetchToken(_ref) {
377
526
  chainId,
378
527
  formatUnits: units = 'ether'
379
528
  } = _ref;
380
- const erc20Config = {
381
- addressOrName: address,
382
- contractInterface: erc20ABI,
383
- chainId
384
- };
385
- const [decimals, name, symbol, totalSupply] = await readContracts({
386
- allowFailure: false,
387
- contracts: [{ ...erc20Config,
388
- functionName: 'decimals'
389
- }, { ...erc20Config,
390
- functionName: 'name'
391
- }, { ...erc20Config,
392
- functionName: 'symbol'
393
- }, { ...erc20Config,
394
- functionName: 'totalSupply'
395
- }]
396
- });
397
- return {
398
- address,
399
- decimals,
400
- name,
401
- symbol,
402
- totalSupply: {
403
- formatted: utils.formatUnits(totalSupply, units),
404
- value: totalSupply
529
+
530
+ async function fetchToken_(_ref2) {
531
+ let {
532
+ contractInterface
533
+ } = _ref2;
534
+ const erc20Config = {
535
+ addressOrName: address,
536
+ contractInterface,
537
+ chainId
538
+ };
539
+ const [decimals, name, symbol, totalSupply] = await readContracts({
540
+ allowFailure: false,
541
+ contracts: [{ ...erc20Config,
542
+ functionName: 'decimals'
543
+ }, { ...erc20Config,
544
+ functionName: 'name'
545
+ }, { ...erc20Config,
546
+ functionName: 'symbol'
547
+ }, { ...erc20Config,
548
+ functionName: 'totalSupply'
549
+ }]
550
+ });
551
+ return {
552
+ address,
553
+ decimals,
554
+ name,
555
+ symbol,
556
+ totalSupply: {
557
+ formatted: utils.formatUnits(totalSupply, units),
558
+ value: totalSupply
559
+ }
560
+ };
561
+ }
562
+
563
+ try {
564
+ return await fetchToken_({
565
+ contractInterface: erc20ABI
566
+ });
567
+ } catch (err) {
568
+ // In the chance that there is an error upon decoding the contract result,
569
+ // it could be likely that the contract data is represented as bytes32 instead
570
+ // of a string.
571
+ if (err instanceof getProvider.ContractResultDecodeError) {
572
+ const {
573
+ name,
574
+ symbol,
575
+ ...rest
576
+ } = await fetchToken_({
577
+ contractInterface: erc20ABI_bytes32
578
+ });
579
+ return {
580
+ name: utils.parseBytes32String(name),
581
+ symbol: utils.parseBytes32String(symbol),
582
+ ...rest
583
+ };
405
584
  }
406
- };
585
+
586
+ throw err;
587
+ }
407
588
  }
408
589
 
409
590
  /**
@@ -798,18 +979,17 @@ async function fetchBlockNumber() {
798
979
  }
799
980
 
800
981
  function watchBlockNumber(args, callback) {
801
- var _client$webSocketProv;
802
-
982
+ var _getWebSocketProvider;
983
+
984
+ // We need to debounce the listener as we want to opt-out
985
+ // of the behavior where ethers emits a "block" event for
986
+ // every block that was missed in between the `pollingInterval`.
987
+ // We are setting a wait time of 1 as emitting an event in
988
+ // ethers takes ~0.1ms.
989
+ const debouncedCallback = debounce.debounce(callback, 1);
803
990
  let previousProvider;
804
991
 
805
992
  const createListener = provider => {
806
- // We need to debounce the listener as we want to opt-out
807
- // of the behavior where ethers emits a "block" event for
808
- // every block that was missed in between the `pollingInterval`.
809
- // We are setting a wait time of 1 as emitting an event in
810
- // ethers takes ~0.1ms.
811
- const debouncedCallback = debounce.debounce(callback, 1);
812
-
813
993
  if (previousProvider) {
814
994
  var _previousProvider;
815
995
 
@@ -820,9 +1000,14 @@ function watchBlockNumber(args, callback) {
820
1000
  previousProvider = provider;
821
1001
  };
822
1002
 
823
- const client = getProvider.getClient();
824
- const provider_ = (_client$webSocketProv = client.webSocketProvider) !== null && _client$webSocketProv !== void 0 ? _client$webSocketProv : client.provider;
1003
+ const provider_ = (_getWebSocketProvider = getWebSocketProvider({
1004
+ chainId: args.chainId
1005
+ })) !== null && _getWebSocketProvider !== void 0 ? _getWebSocketProvider : getProvider.getProvider({
1006
+ chainId: args.chainId
1007
+ });
825
1008
  if (args.listen) createListener(provider_);
1009
+ let active = true;
1010
+ const client = getProvider.getClient();
826
1011
  const unsubscribe = client.subscribe(_ref => {
827
1012
  let {
828
1013
  provider,
@@ -839,17 +1024,25 @@ function watchBlockNumber(args, callback) {
839
1024
  } = _ref2;
840
1025
  const provider_ = webSocketProvider !== null && webSocketProvider !== void 0 ? webSocketProvider : provider;
841
1026
 
842
- if (args.listen && provider_) {
1027
+ if (args.listen && !args.chainId && provider_) {
843
1028
  createListener(provider_);
844
1029
  }
845
1030
 
846
- callback(await fetchBlockNumber());
1031
+ const blockNumber = await fetchBlockNumber({
1032
+ chainId: args.chainId
1033
+ });
1034
+ if (!active) return;
1035
+ callback(blockNumber);
847
1036
  }, {
848
1037
  equalityFn: shallow__default["default"]
849
1038
  });
850
1039
  return () => {
1040
+ var _previousProvider2;
1041
+
1042
+ active = false;
851
1043
  unsubscribe();
852
- provider_ === null || provider_ === void 0 ? void 0 : provider_.off('block', callback);
1044
+ provider_ === null || provider_ === void 0 ? void 0 : provider_.off('block', debouncedCallback);
1045
+ (_previousProvider2 = previousProvider) === null || _previousProvider2 === void 0 ? void 0 : _previousProvider2.off('block', debouncedCallback);
853
1046
  };
854
1047
  }
855
1048
 
@@ -1251,12 +1444,7 @@ async function fetchBalance(_ref) {
1251
1444
  });
1252
1445
 
1253
1446
  if (token) {
1254
- const erc20Config = {
1255
- addressOrName: token,
1256
- contractInterface: erc20ABI,
1257
- chainId
1258
- }; // Convert ENS name to address if required
1259
-
1447
+ // Convert ENS name to address if required
1260
1448
  let resolvedAddress;
1261
1449
  if (utils.isAddress(addressOrName)) resolvedAddress = addressOrName;else {
1262
1450
  const address = await provider.resolveName(addressOrName); // Same error `provider.getBalance` throws for invalid ENS name
@@ -1266,23 +1454,58 @@ async function fetchBalance(_ref) {
1266
1454
  });
1267
1455
  resolvedAddress = address;
1268
1456
  }
1269
- const [value, decimals, symbol] = await readContracts({
1270
- allowFailure: false,
1271
- contracts: [{ ...erc20Config,
1272
- functionName: 'balanceOf',
1273
- args: resolvedAddress
1274
- }, { ...erc20Config,
1275
- functionName: 'decimals'
1276
- }, { ...erc20Config,
1277
- functionName: 'symbol'
1278
- }]
1279
- });
1280
- return {
1281
- decimals,
1282
- formatted: utils.formatUnits(value !== null && value !== void 0 ? value : '0', unit !== null && unit !== void 0 ? unit : decimals),
1283
- symbol,
1284
- value
1457
+
1458
+ const fetchContractBalance = async _ref2 => {
1459
+ let {
1460
+ contractInterface
1461
+ } = _ref2;
1462
+ const erc20Config = {
1463
+ addressOrName: token,
1464
+ contractInterface,
1465
+ chainId
1466
+ };
1467
+ const [value, decimals, symbol] = await readContracts({
1468
+ allowFailure: false,
1469
+ contracts: [{ ...erc20Config,
1470
+ functionName: 'balanceOf',
1471
+ args: resolvedAddress
1472
+ }, { ...erc20Config,
1473
+ functionName: 'decimals'
1474
+ }, { ...erc20Config,
1475
+ functionName: 'symbol'
1476
+ }]
1477
+ });
1478
+ return {
1479
+ decimals,
1480
+ formatted: utils.formatUnits(value !== null && value !== void 0 ? value : '0', unit !== null && unit !== void 0 ? unit : decimals),
1481
+ symbol,
1482
+ value
1483
+ };
1285
1484
  };
1485
+
1486
+ try {
1487
+ return await fetchContractBalance({
1488
+ contractInterface: erc20ABI
1489
+ });
1490
+ } catch (err) {
1491
+ // In the chance that there is an error upon decoding the contract result,
1492
+ // it could be likely that the contract data is represented as bytes32 instead
1493
+ // of a string.
1494
+ if (err instanceof getProvider.ContractResultDecodeError) {
1495
+ const {
1496
+ symbol,
1497
+ ...rest
1498
+ } = await fetchContractBalance({
1499
+ contractInterface: erc20ABI_bytes32
1500
+ });
1501
+ return {
1502
+ symbol: utils.parseBytes32String(symbol),
1503
+ ...rest
1504
+ };
1505
+ }
1506
+
1507
+ throw err;
1508
+ }
1286
1509
  }
1287
1510
 
1288
1511
  const chains = [...(client.provider.chains || []), ...((_client$chains = client.chains) !== null && _client$chains !== void 0 ? _client$chains : [])];