@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
package/dist/wagmi-core.esm.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { g as getClient, C as ConnectorAlreadyConnectedError, a as ConnectorNotFoundError, b as ChainMismatchError, U as UserRejectedRequestError, c as
|
|
2
|
-
export { A as AddChainError,
|
|
1
|
+
import { g as getClient, C as ConnectorAlreadyConnectedError, a as ConnectorNotFoundError, b as ChainMismatchError, U as UserRejectedRequestError, c as ContractResultDecodeError, d as ContractMethodDoesNotExistError, e as getProvider, P as ProviderChainsNotFound, f as ChainDoesNotSupportMulticallError, h as ContractMethodRevertedError, i as ContractMethodNoResultError, n as normalizeChainId, S as SwitchChainNotSupportedError } from './getProvider-5b4b62c3.esm.js';
|
|
2
|
+
export { A as AddChainError, f as ChainDoesNotSupportMulticallError, b as ChainMismatchError, m as ChainNotConfiguredError, k as Client, l as Connector, C as ConnectorAlreadyConnectedError, a as ConnectorNotFoundError, d as ContractMethodDoesNotExistError, i as ContractMethodNoResultError, h as ContractMethodRevertedError, c as ContractResultDecodeError, I as InjectedConnector, P as ProviderChainsNotFound, o as ProviderRpcError, R as ResourceUnavailableError, p as RpcError, q as SwitchChainError, S as SwitchChainNotSupportedError, U as UserRejectedRequestError, j as createClient, r as createStorage, e as getProvider, s as noopStorage, n as normalizeChainId } from './getProvider-5b4b62c3.esm.js';
|
|
3
3
|
import { providers, Contract as Contract$1 } from 'ethers';
|
|
4
4
|
import { Contract, logger } from 'ethers/lib/ethers';
|
|
5
|
-
import { FormatTypes, formatUnits, getAddress, isAddress, Logger } from 'ethers/lib/utils';
|
|
6
|
-
import { m as mainnet } from './chains-
|
|
7
|
-
export { a as allChains, c as chain, b as chainId, d as defaultChains, e as defaultL2Chains, f as etherscanBlockExplorers } from './chains-
|
|
5
|
+
import { FormatTypes, parseBytes32String, formatUnits, getAddress, isAddress, Logger } from 'ethers/lib/utils';
|
|
6
|
+
import { m as mainnet } from './chains-8c76af1b.esm.js';
|
|
7
|
+
export { a as allChains, c as chain, b as chainId, d as defaultChains, e as defaultL2Chains, f as etherscanBlockExplorers } from './chains-8c76af1b.esm.js';
|
|
8
8
|
import shallow from 'zustand/shallow';
|
|
9
|
-
|
|
9
|
+
import { d as debounce } from './debounce-0862bf88.esm.js';
|
|
10
|
+
export { a as alchemyRpcUrls, i as infuraRpcUrls, p as publicRpcUrls } from './rpcs-8d636858.esm.js';
|
|
10
11
|
import 'zustand/middleware';
|
|
11
12
|
import 'zustand/vanilla';
|
|
12
13
|
import 'eventemitter3';
|
|
@@ -213,7 +214,156 @@ function parseContractResult(_ref) {
|
|
|
213
214
|
}
|
|
214
215
|
|
|
215
216
|
// https://ethereum.org/en/developers/docs/standards/tokens/erc-20
|
|
216
|
-
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)'];
|
|
217
|
+
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)'];
|
|
218
|
+
/**
|
|
219
|
+
* [bytes32-flavored ERC-20](https://docs.makerdao.com/smart-contract-modules/mkr-module#4.-gotchas-potential-source-of-user-error)
|
|
220
|
+
* for tokens (ie. Maker) that use bytes32 instead of string.
|
|
221
|
+
*/
|
|
222
|
+
|
|
223
|
+
const erc20ABI_bytes32 = [{
|
|
224
|
+
type: 'event',
|
|
225
|
+
name: 'Approval',
|
|
226
|
+
inputs: [{
|
|
227
|
+
indexed: true,
|
|
228
|
+
name: 'owner',
|
|
229
|
+
type: 'address'
|
|
230
|
+
}, {
|
|
231
|
+
indexed: true,
|
|
232
|
+
name: 'spender',
|
|
233
|
+
type: 'address'
|
|
234
|
+
}, {
|
|
235
|
+
indexed: false,
|
|
236
|
+
name: 'value',
|
|
237
|
+
type: 'uint256'
|
|
238
|
+
}]
|
|
239
|
+
}, {
|
|
240
|
+
type: 'event',
|
|
241
|
+
name: 'Transfer',
|
|
242
|
+
inputs: [{
|
|
243
|
+
indexed: true,
|
|
244
|
+
name: 'from',
|
|
245
|
+
type: 'address'
|
|
246
|
+
}, {
|
|
247
|
+
indexed: true,
|
|
248
|
+
name: 'to',
|
|
249
|
+
type: 'address'
|
|
250
|
+
}, {
|
|
251
|
+
indexed: false,
|
|
252
|
+
name: 'value',
|
|
253
|
+
type: 'uint256'
|
|
254
|
+
}]
|
|
255
|
+
}, {
|
|
256
|
+
type: 'function',
|
|
257
|
+
name: 'allowance',
|
|
258
|
+
stateMutability: 'view',
|
|
259
|
+
inputs: [{
|
|
260
|
+
name: 'owner',
|
|
261
|
+
type: 'address'
|
|
262
|
+
}, {
|
|
263
|
+
name: 'spender',
|
|
264
|
+
type: 'address'
|
|
265
|
+
}],
|
|
266
|
+
outputs: [{
|
|
267
|
+
name: '',
|
|
268
|
+
type: 'uint256'
|
|
269
|
+
}]
|
|
270
|
+
}, {
|
|
271
|
+
type: 'function',
|
|
272
|
+
name: 'approve',
|
|
273
|
+
stateMutability: 'nonpayable',
|
|
274
|
+
inputs: [{
|
|
275
|
+
name: 'spender',
|
|
276
|
+
type: 'address'
|
|
277
|
+
}, {
|
|
278
|
+
name: 'amount',
|
|
279
|
+
type: 'uint256'
|
|
280
|
+
}],
|
|
281
|
+
outputs: [{
|
|
282
|
+
name: '',
|
|
283
|
+
type: 'bool'
|
|
284
|
+
}]
|
|
285
|
+
}, {
|
|
286
|
+
type: 'function',
|
|
287
|
+
name: 'balanceOf',
|
|
288
|
+
stateMutability: 'view',
|
|
289
|
+
inputs: [{
|
|
290
|
+
name: 'account',
|
|
291
|
+
type: 'address'
|
|
292
|
+
}],
|
|
293
|
+
outputs: [{
|
|
294
|
+
name: '',
|
|
295
|
+
type: 'uint256'
|
|
296
|
+
}]
|
|
297
|
+
}, {
|
|
298
|
+
type: 'function',
|
|
299
|
+
name: 'decimals',
|
|
300
|
+
stateMutability: 'view',
|
|
301
|
+
inputs: [],
|
|
302
|
+
outputs: [{
|
|
303
|
+
name: '',
|
|
304
|
+
type: 'uint8'
|
|
305
|
+
}]
|
|
306
|
+
}, {
|
|
307
|
+
type: 'function',
|
|
308
|
+
name: 'name',
|
|
309
|
+
stateMutability: 'view',
|
|
310
|
+
inputs: [],
|
|
311
|
+
outputs: [{
|
|
312
|
+
name: '',
|
|
313
|
+
type: 'bytes32'
|
|
314
|
+
}]
|
|
315
|
+
}, {
|
|
316
|
+
type: 'function',
|
|
317
|
+
name: 'symbol',
|
|
318
|
+
stateMutability: 'view',
|
|
319
|
+
inputs: [],
|
|
320
|
+
outputs: [{
|
|
321
|
+
name: '',
|
|
322
|
+
type: 'bytes32'
|
|
323
|
+
}]
|
|
324
|
+
}, {
|
|
325
|
+
type: 'function',
|
|
326
|
+
name: 'totalSupply',
|
|
327
|
+
stateMutability: 'view',
|
|
328
|
+
inputs: [],
|
|
329
|
+
outputs: [{
|
|
330
|
+
name: '',
|
|
331
|
+
type: 'uint256'
|
|
332
|
+
}]
|
|
333
|
+
}, {
|
|
334
|
+
type: 'function',
|
|
335
|
+
name: 'transfer',
|
|
336
|
+
stateMutability: 'nonpayable',
|
|
337
|
+
inputs: [{
|
|
338
|
+
name: 'recipient',
|
|
339
|
+
type: 'address'
|
|
340
|
+
}, {
|
|
341
|
+
name: 'amount',
|
|
342
|
+
type: 'uint256'
|
|
343
|
+
}],
|
|
344
|
+
outputs: [{
|
|
345
|
+
name: '',
|
|
346
|
+
type: 'bool'
|
|
347
|
+
}]
|
|
348
|
+
}, {
|
|
349
|
+
type: 'function',
|
|
350
|
+
name: 'transferFrom',
|
|
351
|
+
stateMutability: 'nonpayable',
|
|
352
|
+
inputs: [{
|
|
353
|
+
name: 'sender',
|
|
354
|
+
type: 'address'
|
|
355
|
+
}, {
|
|
356
|
+
name: 'recipient',
|
|
357
|
+
type: 'address'
|
|
358
|
+
}, {
|
|
359
|
+
name: 'amount',
|
|
360
|
+
type: 'uint256'
|
|
361
|
+
}],
|
|
362
|
+
outputs: [{
|
|
363
|
+
name: '',
|
|
364
|
+
type: 'bool'
|
|
365
|
+
}]
|
|
366
|
+
}]; // https://ethereum.org/en/developers/docs/standards/tokens/erc-721
|
|
217
367
|
|
|
218
368
|
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'];
|
|
219
369
|
|
|
@@ -370,33 +520,65 @@ async function fetchToken(_ref) {
|
|
|
370
520
|
chainId,
|
|
371
521
|
formatUnits: units = 'ether'
|
|
372
522
|
} = _ref;
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
523
|
+
|
|
524
|
+
async function fetchToken_(_ref2) {
|
|
525
|
+
let {
|
|
526
|
+
contractInterface
|
|
527
|
+
} = _ref2;
|
|
528
|
+
const erc20Config = {
|
|
529
|
+
addressOrName: address,
|
|
530
|
+
contractInterface,
|
|
531
|
+
chainId
|
|
532
|
+
};
|
|
533
|
+
const [decimals, name, symbol, totalSupply] = await readContracts({
|
|
534
|
+
allowFailure: false,
|
|
535
|
+
contracts: [{ ...erc20Config,
|
|
536
|
+
functionName: 'decimals'
|
|
537
|
+
}, { ...erc20Config,
|
|
538
|
+
functionName: 'name'
|
|
539
|
+
}, { ...erc20Config,
|
|
540
|
+
functionName: 'symbol'
|
|
541
|
+
}, { ...erc20Config,
|
|
542
|
+
functionName: 'totalSupply'
|
|
543
|
+
}]
|
|
544
|
+
});
|
|
545
|
+
return {
|
|
546
|
+
address,
|
|
547
|
+
decimals,
|
|
548
|
+
name,
|
|
549
|
+
symbol,
|
|
550
|
+
totalSupply: {
|
|
551
|
+
formatted: formatUnits(totalSupply, units),
|
|
552
|
+
value: totalSupply
|
|
553
|
+
}
|
|
554
|
+
};
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
try {
|
|
558
|
+
return await fetchToken_({
|
|
559
|
+
contractInterface: erc20ABI
|
|
560
|
+
});
|
|
561
|
+
} catch (err) {
|
|
562
|
+
// In the chance that there is an error upon decoding the contract result,
|
|
563
|
+
// it could be likely that the contract data is represented as bytes32 instead
|
|
564
|
+
// of a string.
|
|
565
|
+
if (err instanceof ContractResultDecodeError) {
|
|
566
|
+
const {
|
|
567
|
+
name,
|
|
568
|
+
symbol,
|
|
569
|
+
...rest
|
|
570
|
+
} = await fetchToken_({
|
|
571
|
+
contractInterface: erc20ABI_bytes32
|
|
572
|
+
});
|
|
573
|
+
return {
|
|
574
|
+
name: parseBytes32String(name),
|
|
575
|
+
symbol: parseBytes32String(symbol),
|
|
576
|
+
...rest
|
|
577
|
+
};
|
|
398
578
|
}
|
|
399
|
-
|
|
579
|
+
|
|
580
|
+
throw err;
|
|
581
|
+
}
|
|
400
582
|
}
|
|
401
583
|
|
|
402
584
|
/**
|
|
@@ -468,9 +650,9 @@ function getWebSocketProvider() {
|
|
|
468
650
|
chainId
|
|
469
651
|
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
470
652
|
const client = getClient();
|
|
471
|
-
if (chainId
|
|
653
|
+
if (chainId) return client.getWebSocketProvider({
|
|
472
654
|
chainId
|
|
473
|
-
});
|
|
655
|
+
}) || client.webSocketProvider;
|
|
474
656
|
return client.webSocketProvider;
|
|
475
657
|
}
|
|
476
658
|
|
|
@@ -791,24 +973,35 @@ async function fetchBlockNumber() {
|
|
|
791
973
|
}
|
|
792
974
|
|
|
793
975
|
function watchBlockNumber(args, callback) {
|
|
794
|
-
var
|
|
795
|
-
|
|
976
|
+
var _getWebSocketProvider;
|
|
977
|
+
|
|
978
|
+
// We need to debounce the listener as we want to opt-out
|
|
979
|
+
// of the behavior where ethers emits a "block" event for
|
|
980
|
+
// every block that was missed in between the `pollingInterval`.
|
|
981
|
+
// We are setting a wait time of 1 as emitting an event in
|
|
982
|
+
// ethers takes ~0.1ms.
|
|
983
|
+
const debouncedCallback = debounce(callback, 1);
|
|
796
984
|
let previousProvider;
|
|
797
985
|
|
|
798
986
|
const createListener = provider => {
|
|
799
987
|
if (previousProvider) {
|
|
800
988
|
var _previousProvider;
|
|
801
989
|
|
|
802
|
-
(_previousProvider = previousProvider) === null || _previousProvider === void 0 ? void 0 : _previousProvider.off('block',
|
|
990
|
+
(_previousProvider = previousProvider) === null || _previousProvider === void 0 ? void 0 : _previousProvider.off('block', debouncedCallback);
|
|
803
991
|
}
|
|
804
992
|
|
|
805
|
-
provider.on('block',
|
|
993
|
+
provider.on('block', debouncedCallback);
|
|
806
994
|
previousProvider = provider;
|
|
807
995
|
};
|
|
808
996
|
|
|
809
|
-
const
|
|
810
|
-
|
|
997
|
+
const provider_ = (_getWebSocketProvider = getWebSocketProvider({
|
|
998
|
+
chainId: args.chainId
|
|
999
|
+
})) !== null && _getWebSocketProvider !== void 0 ? _getWebSocketProvider : getProvider({
|
|
1000
|
+
chainId: args.chainId
|
|
1001
|
+
});
|
|
811
1002
|
if (args.listen) createListener(provider_);
|
|
1003
|
+
let active = true;
|
|
1004
|
+
const client = getClient();
|
|
812
1005
|
const unsubscribe = client.subscribe(_ref => {
|
|
813
1006
|
let {
|
|
814
1007
|
provider,
|
|
@@ -825,17 +1018,25 @@ function watchBlockNumber(args, callback) {
|
|
|
825
1018
|
} = _ref2;
|
|
826
1019
|
const provider_ = webSocketProvider !== null && webSocketProvider !== void 0 ? webSocketProvider : provider;
|
|
827
1020
|
|
|
828
|
-
if (args.listen && provider_) {
|
|
1021
|
+
if (args.listen && !args.chainId && provider_) {
|
|
829
1022
|
createListener(provider_);
|
|
830
1023
|
}
|
|
831
1024
|
|
|
832
|
-
|
|
1025
|
+
const blockNumber = await fetchBlockNumber({
|
|
1026
|
+
chainId: args.chainId
|
|
1027
|
+
});
|
|
1028
|
+
if (!active) return;
|
|
1029
|
+
callback(blockNumber);
|
|
833
1030
|
}, {
|
|
834
1031
|
equalityFn: shallow
|
|
835
1032
|
});
|
|
836
1033
|
return () => {
|
|
1034
|
+
var _previousProvider2;
|
|
1035
|
+
|
|
1036
|
+
active = false;
|
|
837
1037
|
unsubscribe();
|
|
838
|
-
provider_ === null || provider_ === void 0 ? void 0 : provider_.off('block',
|
|
1038
|
+
provider_ === null || provider_ === void 0 ? void 0 : provider_.off('block', debouncedCallback);
|
|
1039
|
+
(_previousProvider2 = previousProvider) === null || _previousProvider2 === void 0 ? void 0 : _previousProvider2.off('block', debouncedCallback);
|
|
839
1040
|
};
|
|
840
1041
|
}
|
|
841
1042
|
|
|
@@ -1237,12 +1438,7 @@ async function fetchBalance(_ref) {
|
|
|
1237
1438
|
});
|
|
1238
1439
|
|
|
1239
1440
|
if (token) {
|
|
1240
|
-
|
|
1241
|
-
addressOrName: token,
|
|
1242
|
-
contractInterface: erc20ABI,
|
|
1243
|
-
chainId
|
|
1244
|
-
}; // Convert ENS name to address if required
|
|
1245
|
-
|
|
1441
|
+
// Convert ENS name to address if required
|
|
1246
1442
|
let resolvedAddress;
|
|
1247
1443
|
if (isAddress(addressOrName)) resolvedAddress = addressOrName;else {
|
|
1248
1444
|
const address = await provider.resolveName(addressOrName); // Same error `provider.getBalance` throws for invalid ENS name
|
|
@@ -1252,23 +1448,58 @@ async function fetchBalance(_ref) {
|
|
|
1252
1448
|
});
|
|
1253
1449
|
resolvedAddress = address;
|
|
1254
1450
|
}
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
}
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1451
|
+
|
|
1452
|
+
const fetchContractBalance = async _ref2 => {
|
|
1453
|
+
let {
|
|
1454
|
+
contractInterface
|
|
1455
|
+
} = _ref2;
|
|
1456
|
+
const erc20Config = {
|
|
1457
|
+
addressOrName: token,
|
|
1458
|
+
contractInterface,
|
|
1459
|
+
chainId
|
|
1460
|
+
};
|
|
1461
|
+
const [value, decimals, symbol] = await readContracts({
|
|
1462
|
+
allowFailure: false,
|
|
1463
|
+
contracts: [{ ...erc20Config,
|
|
1464
|
+
functionName: 'balanceOf',
|
|
1465
|
+
args: resolvedAddress
|
|
1466
|
+
}, { ...erc20Config,
|
|
1467
|
+
functionName: 'decimals'
|
|
1468
|
+
}, { ...erc20Config,
|
|
1469
|
+
functionName: 'symbol'
|
|
1470
|
+
}]
|
|
1471
|
+
});
|
|
1472
|
+
return {
|
|
1473
|
+
decimals,
|
|
1474
|
+
formatted: formatUnits(value !== null && value !== void 0 ? value : '0', unit !== null && unit !== void 0 ? unit : decimals),
|
|
1475
|
+
symbol,
|
|
1476
|
+
value
|
|
1477
|
+
};
|
|
1271
1478
|
};
|
|
1479
|
+
|
|
1480
|
+
try {
|
|
1481
|
+
return await fetchContractBalance({
|
|
1482
|
+
contractInterface: erc20ABI
|
|
1483
|
+
});
|
|
1484
|
+
} catch (err) {
|
|
1485
|
+
// In the chance that there is an error upon decoding the contract result,
|
|
1486
|
+
// it could be likely that the contract data is represented as bytes32 instead
|
|
1487
|
+
// of a string.
|
|
1488
|
+
if (err instanceof ContractResultDecodeError) {
|
|
1489
|
+
const {
|
|
1490
|
+
symbol,
|
|
1491
|
+
...rest
|
|
1492
|
+
} = await fetchContractBalance({
|
|
1493
|
+
contractInterface: erc20ABI_bytes32
|
|
1494
|
+
});
|
|
1495
|
+
return {
|
|
1496
|
+
symbol: parseBytes32String(symbol),
|
|
1497
|
+
...rest
|
|
1498
|
+
};
|
|
1499
|
+
}
|
|
1500
|
+
|
|
1501
|
+
throw err;
|
|
1502
|
+
}
|
|
1272
1503
|
}
|
|
1273
1504
|
|
|
1274
1505
|
const chains = [...(client.provider.chains || []), ...((_client$chains = client.chains) !== null && _client$chains !== void 0 ? _client$chains : [])];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "../../dist/declarations/src/internal";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { d as debounce } from '../../dist/debounce-0862bf88.esm.js';
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@wagmi/core",
|
|
3
3
|
"description": "Vanilla JS library for Ethereum",
|
|
4
4
|
"license": "WAGMIT",
|
|
5
|
-
"version": "0.5.
|
|
5
|
+
"version": "0.5.8",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "https://github.com/wagmi-dev/wagmi.git",
|
|
@@ -49,6 +49,10 @@
|
|
|
49
49
|
"module": "./connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.esm.js",
|
|
50
50
|
"default": "./connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.cjs.js"
|
|
51
51
|
},
|
|
52
|
+
"./internal": {
|
|
53
|
+
"module": "./internal/dist/wagmi-core-internal.esm.js",
|
|
54
|
+
"default": "./internal/dist/wagmi-core-internal.cjs.js"
|
|
55
|
+
},
|
|
52
56
|
"./providers/alchemy": {
|
|
53
57
|
"module": "./providers/alchemy/dist/wagmi-core-providers-alchemy.esm.js",
|
|
54
58
|
"default": "./providers/alchemy/dist/wagmi-core-providers-alchemy.cjs.js"
|
|
@@ -70,6 +74,7 @@
|
|
|
70
74
|
"files": [
|
|
71
75
|
"/chains",
|
|
72
76
|
"/connectors",
|
|
77
|
+
"/internal",
|
|
73
78
|
"/providers",
|
|
74
79
|
"/dist"
|
|
75
80
|
],
|
|
@@ -81,6 +86,7 @@
|
|
|
81
86
|
"connectors/metaMask.ts",
|
|
82
87
|
"connectors/walletConnect.ts",
|
|
83
88
|
"connectors/mock/index.ts",
|
|
89
|
+
"internal.ts",
|
|
84
90
|
"providers/alchemy.ts",
|
|
85
91
|
"providers/public.ts",
|
|
86
92
|
"providers/infura.ts",
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var ethers = require('ethers');
|
|
6
|
-
var rpcs = require('../../../dist/rpcs-
|
|
6
|
+
var rpcs = require('../../../dist/rpcs-d2cd65f1.cjs.dev.js');
|
|
7
7
|
|
|
8
8
|
function alchemyProvider() {
|
|
9
9
|
let {
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var ethers = require('ethers');
|
|
6
|
-
var rpcs = require('../../../dist/rpcs-
|
|
6
|
+
var rpcs = require('../../../dist/rpcs-edec227e.cjs.prod.js');
|
|
7
7
|
|
|
8
8
|
function alchemyProvider() {
|
|
9
9
|
let {
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// are you seeing an error that a default export doesn't exist but your source file has a default export?
|
|
2
|
+
// you should run `yarn` or `yarn preconstruct dev` if preconstruct dev isn't in your postinstall hook
|
|
3
|
+
|
|
4
|
+
// curious why you need to?
|
|
5
|
+
// this file exists so that you can import from the entrypoint normally
|
|
6
|
+
// except that it points to your source file and you don't need to run build constantly
|
|
7
|
+
// which means we need to re-export all of the modules from your source file
|
|
8
|
+
// and since export * doesn't include default exports, we need to read your source file
|
|
9
|
+
// to check for a default export and re-export it if it exists
|
|
10
|
+
// it's not ideal, but it works pretty well ¯\_(ツ)_/¯
|
|
11
|
+
export * from "../../../src/providers/coinbaseNode";
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// this file might look strange and you might be wondering what it's for
|
|
3
|
+
// it's lets you import your source files by importing this entrypoint
|
|
4
|
+
// as you would import it if it was built with preconstruct build
|
|
5
|
+
// this file is slightly different to some others though
|
|
6
|
+
// it has a require hook which compiles your code with Babel
|
|
7
|
+
// this means that you don't have to set up @babel/register or anything like that
|
|
8
|
+
// but you can still require this module and it'll be compiled
|
|
9
|
+
|
|
10
|
+
// this bit of code imports the require hook and registers it
|
|
11
|
+
let unregister = require("../../../../../node_modules/.pnpm/@preconstruct+hook@0.4.0/node_modules/@preconstruct/hook").___internalHook(typeof __dirname === 'undefined' ? undefined : __dirname, "../../../../..", "../../..");
|
|
12
|
+
|
|
13
|
+
// this re-exports the source file
|
|
14
|
+
module.exports = require("../../../src/providers/coinbaseNode.ts");
|
|
15
|
+
|
|
16
|
+
unregister();
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var ethers = require('ethers');
|
|
6
|
-
var rpcs = require('../../../dist/rpcs-
|
|
6
|
+
var rpcs = require('../../../dist/rpcs-d2cd65f1.cjs.dev.js');
|
|
7
7
|
|
|
8
8
|
function infuraProvider() {
|
|
9
9
|
let {
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var ethers = require('ethers');
|
|
6
|
-
var rpcs = require('../../../dist/rpcs-
|
|
6
|
+
var rpcs = require('../../../dist/rpcs-edec227e.cjs.prod.js');
|
|
7
7
|
|
|
8
8
|
function infuraProvider() {
|
|
9
9
|
let {
|