@wagmi/core 0.5.6 → 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.
- package/chains/dist/wagmi-core-chains.cjs.dev.js +2 -2
- package/chains/dist/wagmi-core-chains.cjs.prod.js +2 -2
- package/chains/dist/wagmi-core-chains.esm.js +2 -2
- package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.cjs.dev.js +10 -6
- package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.cjs.prod.js +10 -6
- package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.esm.js +10 -6
- package/connectors/metaMask/dist/wagmi-core-connectors-metaMask.cjs.dev.js +3 -3
- package/connectors/metaMask/dist/wagmi-core-connectors-metaMask.cjs.prod.js +3 -3
- package/connectors/metaMask/dist/wagmi-core-connectors-metaMask.esm.js +3 -3
- package/connectors/mock/dist/wagmi-core-connectors-mock.cjs.dev.js +3 -3
- package/connectors/mock/dist/wagmi-core-connectors-mock.cjs.prod.js +3 -3
- package/connectors/mock/dist/wagmi-core-connectors-mock.esm.js +3 -3
- package/connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.cjs.dev.js +3 -3
- package/connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.cjs.prod.js +3 -3
- package/connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.esm.js +3 -3
- package/dist/{chains-868f0ac6.cjs.prod.js → chains-789e0c2e.cjs.prod.js} +2 -1
- package/dist/{chains-a22bcfea.esm.js → chains-8c76af1b.esm.js} +2 -1
- package/dist/{chains-4fdb21bc.cjs.dev.js → chains-ec1de502.cjs.dev.js} +2 -1
- package/dist/debounce-0862bf88.esm.js +18 -0
- package/dist/debounce-2d836dc9.cjs.prod.js +20 -0
- package/dist/debounce-46ac0312.cjs.dev.js +20 -0
- package/dist/declarations/src/actions/network-status/watchBlockNumber.d.ts +1 -0
- package/dist/declarations/src/client.d.ts +11 -1
- package/dist/declarations/src/connectors/base.d.ts +1 -0
- package/dist/declarations/src/constants/abis.d.ts +148 -0
- package/dist/declarations/src/constants/index.d.ts +1 -1
- package/dist/declarations/src/constants/rpcs.d.ts +1 -1
- package/dist/declarations/src/internal.d.ts +1 -0
- package/dist/declarations/src/utils/debounce.d.ts +1 -0
- package/dist/declarations/src/utils/index.d.ts +1 -0
- package/dist/{getProvider-b220fed1.cjs.prod.js → getProvider-1b3eeda8.cjs.dev.js} +60 -20
- package/dist/{getProvider-a3c8cf52.esm.js → getProvider-5b4b62c3.esm.js} +61 -21
- package/dist/{getProvider-3a26f086.cjs.dev.js → getProvider-ad4ce6a4.cjs.prod.js} +60 -20
- package/dist/{rpcs-6e1b1718.esm.js → rpcs-8d636858.esm.js} +1 -0
- package/dist/{rpcs-3326627e.cjs.dev.js → rpcs-d2cd65f1.cjs.dev.js} +1 -0
- package/dist/{rpcs-45537550.cjs.prod.js → rpcs-edec227e.cjs.prod.js} +1 -0
- package/dist/wagmi-core.cjs.dev.js +294 -63
- package/dist/wagmi-core.cjs.prod.js +294 -63
- package/dist/wagmi-core.esm.js +297 -66
- package/internal/dist/wagmi-core-internal.cjs.d.ts +1 -0
- package/internal/dist/wagmi-core-internal.cjs.dev.js +9 -0
- package/internal/dist/wagmi-core-internal.cjs.js +7 -0
- package/internal/dist/wagmi-core-internal.cjs.prod.js +9 -0
- package/internal/dist/wagmi-core-internal.esm.js +1 -0
- package/internal/package.json +4 -0
- package/package.json +7 -1
- package/providers/alchemy/dist/wagmi-core-providers-alchemy.cjs.dev.js +1 -1
- package/providers/alchemy/dist/wagmi-core-providers-alchemy.cjs.prod.js +1 -1
- package/providers/alchemy/dist/wagmi-core-providers-alchemy.esm.js +1 -1
- package/providers/coinbaseNode/dist/wagmi-core-providers-coinbaseNode.cjs.d.ts +11 -0
- package/providers/coinbaseNode/dist/wagmi-core-providers-coinbaseNode.cjs.js +16 -0
- package/providers/infura/dist/wagmi-core-providers-infura.cjs.dev.js +1 -1
- package/providers/infura/dist/wagmi-core-providers-infura.cjs.prod.js +1 -1
- package/providers/infura/dist/wagmi-core-providers-infura.esm.js +1 -1
|
@@ -2,13 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var getProvider = require('./getProvider-
|
|
5
|
+
var getProvider = require('./getProvider-ad4ce6a4.cjs.prod.js');
|
|
6
6
|
var ethers = require('ethers');
|
|
7
7
|
var ethers$1 = require('ethers/lib/ethers');
|
|
8
8
|
var utils = require('ethers/lib/utils');
|
|
9
|
-
var chains = require('./chains-
|
|
9
|
+
var chains = require('./chains-789e0c2e.cjs.prod.js');
|
|
10
10
|
var shallow = require('zustand/shallow');
|
|
11
|
-
var
|
|
11
|
+
var debounce = require('./debounce-2d836dc9.cjs.prod.js');
|
|
12
|
+
var rpcs = require('./rpcs-edec227e.cjs.prod.js');
|
|
12
13
|
require('zustand/middleware');
|
|
13
14
|
require('zustand/vanilla');
|
|
14
15
|
require('eventemitter3');
|
|
@@ -219,7 +220,156 @@ function parseContractResult(_ref) {
|
|
|
219
220
|
}
|
|
220
221
|
|
|
221
222
|
// https://ethereum.org/en/developers/docs/standards/tokens/erc-20
|
|
222
|
-
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)'];
|
|
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
|
|
223
373
|
|
|
224
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'];
|
|
225
375
|
|
|
@@ -376,33 +526,65 @@ async function fetchToken(_ref) {
|
|
|
376
526
|
chainId,
|
|
377
527
|
formatUnits: units = 'ether'
|
|
378
528
|
} = _ref;
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
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
|
+
};
|
|
404
584
|
}
|
|
405
|
-
|
|
585
|
+
|
|
586
|
+
throw err;
|
|
587
|
+
}
|
|
406
588
|
}
|
|
407
589
|
|
|
408
590
|
/**
|
|
@@ -474,9 +656,9 @@ function getWebSocketProvider() {
|
|
|
474
656
|
chainId
|
|
475
657
|
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
476
658
|
const client = getProvider.getClient();
|
|
477
|
-
if (chainId
|
|
659
|
+
if (chainId) return client.getWebSocketProvider({
|
|
478
660
|
chainId
|
|
479
|
-
});
|
|
661
|
+
}) || client.webSocketProvider;
|
|
480
662
|
return client.webSocketProvider;
|
|
481
663
|
}
|
|
482
664
|
|
|
@@ -797,24 +979,35 @@ async function fetchBlockNumber() {
|
|
|
797
979
|
}
|
|
798
980
|
|
|
799
981
|
function watchBlockNumber(args, callback) {
|
|
800
|
-
var
|
|
801
|
-
|
|
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);
|
|
802
990
|
let previousProvider;
|
|
803
991
|
|
|
804
992
|
const createListener = provider => {
|
|
805
993
|
if (previousProvider) {
|
|
806
994
|
var _previousProvider;
|
|
807
995
|
|
|
808
|
-
(_previousProvider = previousProvider) === null || _previousProvider === void 0 ? void 0 : _previousProvider.off('block',
|
|
996
|
+
(_previousProvider = previousProvider) === null || _previousProvider === void 0 ? void 0 : _previousProvider.off('block', debouncedCallback);
|
|
809
997
|
}
|
|
810
998
|
|
|
811
|
-
provider.on('block',
|
|
999
|
+
provider.on('block', debouncedCallback);
|
|
812
1000
|
previousProvider = provider;
|
|
813
1001
|
};
|
|
814
1002
|
|
|
815
|
-
const
|
|
816
|
-
|
|
1003
|
+
const provider_ = (_getWebSocketProvider = getWebSocketProvider({
|
|
1004
|
+
chainId: args.chainId
|
|
1005
|
+
})) !== null && _getWebSocketProvider !== void 0 ? _getWebSocketProvider : getProvider.getProvider({
|
|
1006
|
+
chainId: args.chainId
|
|
1007
|
+
});
|
|
817
1008
|
if (args.listen) createListener(provider_);
|
|
1009
|
+
let active = true;
|
|
1010
|
+
const client = getProvider.getClient();
|
|
818
1011
|
const unsubscribe = client.subscribe(_ref => {
|
|
819
1012
|
let {
|
|
820
1013
|
provider,
|
|
@@ -831,17 +1024,25 @@ function watchBlockNumber(args, callback) {
|
|
|
831
1024
|
} = _ref2;
|
|
832
1025
|
const provider_ = webSocketProvider !== null && webSocketProvider !== void 0 ? webSocketProvider : provider;
|
|
833
1026
|
|
|
834
|
-
if (args.listen && provider_) {
|
|
1027
|
+
if (args.listen && !args.chainId && provider_) {
|
|
835
1028
|
createListener(provider_);
|
|
836
1029
|
}
|
|
837
1030
|
|
|
838
|
-
|
|
1031
|
+
const blockNumber = await fetchBlockNumber({
|
|
1032
|
+
chainId: args.chainId
|
|
1033
|
+
});
|
|
1034
|
+
if (!active) return;
|
|
1035
|
+
callback(blockNumber);
|
|
839
1036
|
}, {
|
|
840
1037
|
equalityFn: shallow__default["default"]
|
|
841
1038
|
});
|
|
842
1039
|
return () => {
|
|
1040
|
+
var _previousProvider2;
|
|
1041
|
+
|
|
1042
|
+
active = false;
|
|
843
1043
|
unsubscribe();
|
|
844
|
-
provider_ === null || provider_ === void 0 ? void 0 : provider_.off('block',
|
|
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);
|
|
845
1046
|
};
|
|
846
1047
|
}
|
|
847
1048
|
|
|
@@ -1243,12 +1444,7 @@ async function fetchBalance(_ref) {
|
|
|
1243
1444
|
});
|
|
1244
1445
|
|
|
1245
1446
|
if (token) {
|
|
1246
|
-
|
|
1247
|
-
addressOrName: token,
|
|
1248
|
-
contractInterface: erc20ABI,
|
|
1249
|
-
chainId
|
|
1250
|
-
}; // Convert ENS name to address if required
|
|
1251
|
-
|
|
1447
|
+
// Convert ENS name to address if required
|
|
1252
1448
|
let resolvedAddress;
|
|
1253
1449
|
if (utils.isAddress(addressOrName)) resolvedAddress = addressOrName;else {
|
|
1254
1450
|
const address = await provider.resolveName(addressOrName); // Same error `provider.getBalance` throws for invalid ENS name
|
|
@@ -1258,23 +1454,58 @@ async function fetchBalance(_ref) {
|
|
|
1258
1454
|
});
|
|
1259
1455
|
resolvedAddress = address;
|
|
1260
1456
|
}
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
}
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
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
|
+
};
|
|
1277
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
|
+
}
|
|
1278
1509
|
}
|
|
1279
1510
|
|
|
1280
1511
|
const chains = [...(client.provider.chains || []), ...((_client$chains = client.chains) !== null && _client$chains !== void 0 ? _client$chains : [])];
|