@wagmi/core 0.3.1 → 0.3.4
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.d.ts +1 -0
- package/chains/dist/wagmi-core-chains.cjs.dev.js +22 -0
- package/chains/dist/wagmi-core-chains.cjs.js +7 -0
- package/chains/dist/wagmi-core-chains.cjs.prod.js +22 -0
- package/chains/dist/wagmi-core-chains.esm.js +2 -0
- package/chains/package.json +4 -0
- package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.cjs.dev.js +4 -3
- package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.cjs.prod.js +4 -3
- package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.esm.js +2 -1
- package/connectors/metaMask/dist/wagmi-core-connectors-metaMask.cjs.dev.js +3 -2
- package/connectors/metaMask/dist/wagmi-core-connectors-metaMask.cjs.prod.js +3 -2
- package/connectors/metaMask/dist/wagmi-core-connectors-metaMask.esm.js +3 -2
- package/connectors/mock/dist/wagmi-core-connectors-mock.cjs.dev.js +4 -3
- package/connectors/mock/dist/wagmi-core-connectors-mock.cjs.prod.js +4 -3
- package/connectors/mock/dist/wagmi-core-connectors-mock.esm.js +2 -1
- package/connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.cjs.dev.js +9 -6
- package/connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.cjs.prod.js +9 -6
- package/connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.esm.js +7 -4
- package/dist/base-321ac87a.cjs.dev.js +288 -0
- package/dist/base-41fb6637.esm.js +265 -0
- package/dist/base-6841ebe0.cjs.prod.js +288 -0
- package/dist/chains-0dd661ab.cjs.prod.js +349 -0
- package/dist/chains-98e2e613.cjs.dev.js +349 -0
- package/dist/chains-a0a80d94.esm.js +329 -0
- package/dist/{client-edc73358.cjs.prod.js → client-4172f963.cjs.dev.js} +4 -3
- package/dist/{client-1ab99bf8.esm.js → client-87c1ff8b.esm.js} +2 -1
- package/dist/{client-db513093.cjs.dev.js → client-a06c45f3.cjs.prod.js} +4 -3
- package/dist/declarations/src/chains.d.ts +1 -0
- package/dist/declarations/src/constants/chains.d.ts +33 -2
- package/dist/declarations/src/index.d.ts +2 -3
- package/dist/declarations/src/types/index.d.ts +11 -4
- package/dist/declarations/src/{chains → utils}/configureChains.d.ts +2 -2
- package/dist/declarations/src/utils/index.d.ts +2 -0
- package/dist/wagmi-core.cjs.dev.js +118 -117
- package/dist/wagmi-core.cjs.prod.js +118 -117
- package/dist/wagmi-core.esm.js +108 -106
- package/package.json +12 -7
- package/dist/base-3a506159.cjs.dev.js +0 -602
- package/dist/base-997b4fec.esm.js +0 -573
- package/dist/base-cb4198f3.cjs.prod.js +0 -602
- package/dist/declarations/src/chains/index.d.ts +0 -2
|
@@ -2,11 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var client = require('./client-
|
|
6
|
-
var base = require('./base-
|
|
7
|
-
var ethers = require('ethers/lib/ethers');
|
|
5
|
+
var client = require('./client-4172f963.cjs.dev.js');
|
|
6
|
+
var base = require('./base-321ac87a.cjs.dev.js');
|
|
7
|
+
var ethers$1 = require('ethers/lib/ethers');
|
|
8
8
|
var utils = require('ethers/lib/utils');
|
|
9
|
-
var
|
|
9
|
+
var chains = require('./chains-98e2e613.cjs.dev.js');
|
|
10
|
+
var ethers = require('ethers');
|
|
10
11
|
var rpcs = require('./rpcs-9c4eb960.cjs.dev.js');
|
|
11
12
|
require('zustand/vanilla');
|
|
12
13
|
require('zustand/middleware');
|
|
@@ -20,6 +21,107 @@ const erc721ABI = ['event Approval(address indexed _owner, address indexed _appr
|
|
|
20
21
|
// https://github.com/ethers-io/ethers.js/blob/master/packages/units/src.ts/index.ts#L10-L18
|
|
21
22
|
const units = ['wei', 'kwei', 'mwei', 'gwei', 'szabo', 'finney', 'ether'];
|
|
22
23
|
|
|
24
|
+
function configureChains(defaultChains, providers) {
|
|
25
|
+
let {
|
|
26
|
+
minQuorum = 1,
|
|
27
|
+
targetQuorum = 1,
|
|
28
|
+
stallTimeout
|
|
29
|
+
} = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
30
|
+
if (targetQuorum < minQuorum) throw new Error('quorum cannot be lower than minQuorum');
|
|
31
|
+
let chains = [];
|
|
32
|
+
const providers_ = {};
|
|
33
|
+
const webSocketProviders_ = {};
|
|
34
|
+
|
|
35
|
+
for (const chain of defaultChains) {
|
|
36
|
+
let configExists = false;
|
|
37
|
+
|
|
38
|
+
for (const provider of providers) {
|
|
39
|
+
const apiConfig = provider(chain); // If no API configuration was found (ie. no RPC URL) for
|
|
40
|
+
// this provider, then we skip and check the next one.
|
|
41
|
+
|
|
42
|
+
if (!apiConfig) continue;
|
|
43
|
+
configExists = true;
|
|
44
|
+
|
|
45
|
+
if (!chains.some(_ref => {
|
|
46
|
+
let {
|
|
47
|
+
id
|
|
48
|
+
} = _ref;
|
|
49
|
+
return id === chain.id;
|
|
50
|
+
})) {
|
|
51
|
+
chains = [...chains, apiConfig.chain];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
providers_[chain.id] = [...(providers_[chain.id] || []), apiConfig.provider];
|
|
55
|
+
|
|
56
|
+
if (apiConfig.webSocketProvider) {
|
|
57
|
+
webSocketProviders_[chain.id] = [...(webSocketProviders_[chain.id] || []), apiConfig.webSocketProvider];
|
|
58
|
+
}
|
|
59
|
+
} // If no API configuration was found across the providers
|
|
60
|
+
// then we throw an error to the consumer.
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
if (!configExists) {
|
|
64
|
+
throw new Error(["Could not find valid provider configuration for chain \"".concat(chain.name, "\".\n"), "You may need to add `jsonRpcProvider` to `configureChains` with the chain's RPC URLs.", 'Read more: https://wagmi.sh/docs/providers/jsonRpc'].join('\n'));
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return {
|
|
69
|
+
chains,
|
|
70
|
+
provider: _ref2 => {
|
|
71
|
+
let {
|
|
72
|
+
chainId
|
|
73
|
+
} = _ref2;
|
|
74
|
+
const chainProviders = providers_[chainId && chains.some(x => x.id === chainId) ? chainId : defaultChains[0].id];
|
|
75
|
+
if (chainProviders.length === 1) return chainProviders[0]();
|
|
76
|
+
return fallbackProvider(targetQuorum, minQuorum, chainProviders, {
|
|
77
|
+
stallTimeout
|
|
78
|
+
});
|
|
79
|
+
},
|
|
80
|
+
webSocketProvider: _ref3 => {
|
|
81
|
+
let {
|
|
82
|
+
chainId
|
|
83
|
+
} = _ref3;
|
|
84
|
+
const chainWebSocketProviders = webSocketProviders_[chainId && chains.some(x => x.id === chainId) ? chainId : defaultChains[0].id];
|
|
85
|
+
if (!chainWebSocketProviders) return undefined;
|
|
86
|
+
if (chainWebSocketProviders.length === 1) return chainWebSocketProviders[0](); // WebSockets do not work with `fallbackProvider`
|
|
87
|
+
// Default to first available
|
|
88
|
+
|
|
89
|
+
return chainWebSocketProviders[0]();
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function fallbackProvider(targetQuorum, minQuorum, providers_, _ref4) {
|
|
95
|
+
let {
|
|
96
|
+
stallTimeout
|
|
97
|
+
} = _ref4;
|
|
98
|
+
|
|
99
|
+
try {
|
|
100
|
+
return new ethers.providers.FallbackProvider(providers_.map((chainProvider, index) => {
|
|
101
|
+
var _provider$priority, _provider$stallTimeou;
|
|
102
|
+
|
|
103
|
+
const provider = chainProvider();
|
|
104
|
+
return {
|
|
105
|
+
provider,
|
|
106
|
+
priority: (_provider$priority = provider.priority) !== null && _provider$priority !== void 0 ? _provider$priority : index,
|
|
107
|
+
stallTimeout: (_provider$stallTimeou = provider.stallTimeout) !== null && _provider$stallTimeou !== void 0 ? _provider$stallTimeou : stallTimeout,
|
|
108
|
+
weight: provider.weight
|
|
109
|
+
};
|
|
110
|
+
}), targetQuorum);
|
|
111
|
+
} catch (error) {
|
|
112
|
+
var _error$message;
|
|
113
|
+
|
|
114
|
+
if (error !== null && error !== void 0 && (_error$message = error.message) !== null && _error$message !== void 0 && _error$message.includes('quorum will always fail; larger than total weight')) {
|
|
115
|
+
if (targetQuorum === minQuorum) throw error;
|
|
116
|
+
return fallbackProvider(targetQuorum - 1, minQuorum, providers_, {
|
|
117
|
+
stallTimeout
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
throw error;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
23
125
|
async function connect(_ref) {
|
|
24
126
|
let {
|
|
25
127
|
connector
|
|
@@ -111,7 +213,7 @@ async function fetchBalance(_ref) {
|
|
|
111
213
|
});
|
|
112
214
|
|
|
113
215
|
if (token) {
|
|
114
|
-
const contract = new ethers.Contract(token, erc20ABI, provider);
|
|
216
|
+
const contract = new ethers$1.Contract(token, erc20ABI, provider);
|
|
115
217
|
const [value, decimals, symbol] = await Promise.all([contract.balanceOf(addressOrName), contract.decimals(), contract.symbol()]);
|
|
116
218
|
return {
|
|
117
219
|
decimals,
|
|
@@ -122,9 +224,9 @@ async function fetchBalance(_ref) {
|
|
|
122
224
|
};
|
|
123
225
|
}
|
|
124
226
|
|
|
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 : []), ...
|
|
227
|
+
const chains$1 = [...((_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 : []), ...chains.allChains];
|
|
126
228
|
const value = await provider.getBalance(addressOrName);
|
|
127
|
-
const chain = chains.find(x => x.id === provider.network.chainId);
|
|
229
|
+
const chain = chains$1.find(x => x.id === provider.network.chainId);
|
|
128
230
|
return {
|
|
129
231
|
decimals: (_chain$nativeCurrency = chain === null || chain === void 0 ? void 0 : (_chain$nativeCurrency2 = chain.nativeCurrency) === null || _chain$nativeCurrency2 === void 0 ? void 0 : _chain$nativeCurrency2.decimals) !== null && _chain$nativeCurrency !== void 0 ? _chain$nativeCurrency : 18,
|
|
130
232
|
formatted: utils.formatUnits(value, unit),
|
|
@@ -159,7 +261,7 @@ function getNetwork() {
|
|
|
159
261
|
const client$1 = client.getClient();
|
|
160
262
|
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
263
|
const activeChains = (_client$chains = client$1.chains) !== null && _client$chains !== void 0 ? _client$chains : [];
|
|
162
|
-
const activeChain = (_find = [...activeChains, ...
|
|
264
|
+
const activeChain = (_find = [...activeChains, ...chains.allChains].find(x => x.id === chainId)) !== null && _find !== void 0 ? _find : {
|
|
163
265
|
id: chainId,
|
|
164
266
|
name: "Chain ".concat(chainId),
|
|
165
267
|
network: "".concat(chainId),
|
|
@@ -282,7 +384,7 @@ function getContract(_ref) {
|
|
|
282
384
|
contractInterface,
|
|
283
385
|
signerOrProvider
|
|
284
386
|
} = _ref;
|
|
285
|
-
return new ethers
|
|
387
|
+
return new ethers.Contract(addressOrName, contractInterface, signerOrProvider);
|
|
286
388
|
}
|
|
287
389
|
|
|
288
390
|
async function readContract(contractConfig, functionName) {
|
|
@@ -543,7 +645,7 @@ async function fetchToken(_ref) {
|
|
|
543
645
|
const provider = getProvider({
|
|
544
646
|
chainId
|
|
545
647
|
});
|
|
546
|
-
const contract = new ethers.Contract(address, erc20ABI, provider);
|
|
648
|
+
const contract = new ethers$1.Contract(address, erc20ABI, provider);
|
|
547
649
|
const [symbol, decimals, totalSupply] = await Promise.all([contract.symbol(), contract.decimals(), contract.totalSupply()]);
|
|
548
650
|
const token = {
|
|
549
651
|
address,
|
|
@@ -589,107 +691,6 @@ async function waitForTransaction(_ref) {
|
|
|
589
691
|
return await promise;
|
|
590
692
|
}
|
|
591
693
|
|
|
592
|
-
function configureChains(defaultChains, providers) {
|
|
593
|
-
let {
|
|
594
|
-
minQuorum = 1,
|
|
595
|
-
targetQuorum = 1,
|
|
596
|
-
stallTimeout
|
|
597
|
-
} = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
598
|
-
if (targetQuorum < minQuorum) throw new Error('quorum cannot be lower than minQuorum');
|
|
599
|
-
let chains = [];
|
|
600
|
-
const providers_ = {};
|
|
601
|
-
const webSocketProviders_ = {};
|
|
602
|
-
|
|
603
|
-
for (const chain of defaultChains) {
|
|
604
|
-
let configExists = false;
|
|
605
|
-
|
|
606
|
-
for (const provider of providers) {
|
|
607
|
-
const apiConfig = provider(chain); // If no API configuration was found (ie. no RPC URL) for
|
|
608
|
-
// this provider, then we skip and check the next one.
|
|
609
|
-
|
|
610
|
-
if (!apiConfig) continue;
|
|
611
|
-
configExists = true;
|
|
612
|
-
|
|
613
|
-
if (!chains.some(_ref => {
|
|
614
|
-
let {
|
|
615
|
-
id
|
|
616
|
-
} = _ref;
|
|
617
|
-
return id === chain.id;
|
|
618
|
-
})) {
|
|
619
|
-
chains = [...chains, apiConfig.chain];
|
|
620
|
-
}
|
|
621
|
-
|
|
622
|
-
providers_[chain.id] = [...(providers_[chain.id] || []), apiConfig.provider];
|
|
623
|
-
|
|
624
|
-
if (apiConfig.webSocketProvider) {
|
|
625
|
-
webSocketProviders_[chain.id] = [...(webSocketProviders_[chain.id] || []), apiConfig.webSocketProvider];
|
|
626
|
-
}
|
|
627
|
-
} // If no API configuration was found across the providers
|
|
628
|
-
// then we throw an error to the consumer.
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
if (!configExists) {
|
|
632
|
-
throw new Error(["Could not find valid provider configuration for chain \"".concat(chain.name, "\".\n"), "You may need to add `jsonRpcProvider` to `configureChains` with the chain's RPC URLs.", 'Read more: https://wagmi.sh/docs/providers/jsonRpc'].join('\n'));
|
|
633
|
-
}
|
|
634
|
-
}
|
|
635
|
-
|
|
636
|
-
return {
|
|
637
|
-
chains,
|
|
638
|
-
provider: _ref2 => {
|
|
639
|
-
let {
|
|
640
|
-
chainId
|
|
641
|
-
} = _ref2;
|
|
642
|
-
const chainProviders = providers_[chainId && chains.some(x => x.id === chainId) ? chainId : defaultChains[0].id];
|
|
643
|
-
if (chainProviders.length === 1) return chainProviders[0]();
|
|
644
|
-
return fallbackProvider(targetQuorum, minQuorum, chainProviders, {
|
|
645
|
-
stallTimeout
|
|
646
|
-
});
|
|
647
|
-
},
|
|
648
|
-
webSocketProvider: _ref3 => {
|
|
649
|
-
let {
|
|
650
|
-
chainId
|
|
651
|
-
} = _ref3;
|
|
652
|
-
const chainWebSocketProviders = webSocketProviders_[chainId && chains.some(x => x.id === chainId) ? chainId : defaultChains[0].id];
|
|
653
|
-
if (!chainWebSocketProviders) return undefined;
|
|
654
|
-
if (chainWebSocketProviders.length === 1) return chainWebSocketProviders[0](); // WebSockets do not work with `fallbackProvider`
|
|
655
|
-
// Default to first available
|
|
656
|
-
|
|
657
|
-
return chainWebSocketProviders[0]();
|
|
658
|
-
}
|
|
659
|
-
};
|
|
660
|
-
}
|
|
661
|
-
|
|
662
|
-
function fallbackProvider(targetQuorum, minQuorum, providers_, _ref4) {
|
|
663
|
-
let {
|
|
664
|
-
stallTimeout
|
|
665
|
-
} = _ref4;
|
|
666
|
-
|
|
667
|
-
try {
|
|
668
|
-
return new ethers$1.providers.FallbackProvider(providers_.map((chainProvider, index) => {
|
|
669
|
-
var _provider$priority, _provider$stallTimeou;
|
|
670
|
-
|
|
671
|
-
const provider = chainProvider();
|
|
672
|
-
return {
|
|
673
|
-
provider,
|
|
674
|
-
priority: (_provider$priority = provider.priority) !== null && _provider$priority !== void 0 ? _provider$priority : index,
|
|
675
|
-
stallTimeout: (_provider$stallTimeou = provider.stallTimeout) !== null && _provider$stallTimeou !== void 0 ? _provider$stallTimeou : stallTimeout,
|
|
676
|
-
weight: provider.weight
|
|
677
|
-
};
|
|
678
|
-
}), targetQuorum);
|
|
679
|
-
} catch (error) {
|
|
680
|
-
var _error$message;
|
|
681
|
-
|
|
682
|
-
if (error !== null && error !== void 0 && (_error$message = error.message) !== null && _error$message !== void 0 && _error$message.includes('quorum will always fail; larger than total weight')) {
|
|
683
|
-
if (targetQuorum === minQuorum) throw error;
|
|
684
|
-
return fallbackProvider(targetQuorum - 1, minQuorum, providers_, {
|
|
685
|
-
stallTimeout
|
|
686
|
-
});
|
|
687
|
-
}
|
|
688
|
-
|
|
689
|
-
throw error;
|
|
690
|
-
}
|
|
691
|
-
}
|
|
692
|
-
|
|
693
694
|
exports.Client = client.Client;
|
|
694
695
|
exports.InjectedConnector = client.InjectedConnector;
|
|
695
696
|
exports.createClient = client.createClient;
|
|
@@ -706,13 +707,13 @@ exports.RpcError = base.RpcError;
|
|
|
706
707
|
exports.SwitchChainError = base.SwitchChainError;
|
|
707
708
|
exports.SwitchChainNotSupportedError = base.SwitchChainNotSupportedError;
|
|
708
709
|
exports.UserRejectedRequestError = base.UserRejectedRequestError;
|
|
709
|
-
exports.allChains = base.allChains;
|
|
710
|
-
exports.chain = base.chain;
|
|
711
|
-
exports.chainId = base.chainId;
|
|
712
|
-
exports.defaultChains = base.defaultChains;
|
|
713
|
-
exports.defaultL2Chains = base.defaultL2Chains;
|
|
714
|
-
exports.etherscanBlockExplorers = base.etherscanBlockExplorers;
|
|
715
710
|
exports.normalizeChainId = base.normalizeChainId;
|
|
711
|
+
exports.allChains = chains.allChains;
|
|
712
|
+
exports.chain = chains.chain;
|
|
713
|
+
exports.chainId = chains.chainId;
|
|
714
|
+
exports.defaultChains = chains.defaultChains;
|
|
715
|
+
exports.defaultL2Chains = chains.defaultL2Chains;
|
|
716
|
+
exports.etherscanBlockExplorers = chains.etherscanBlockExplorers;
|
|
716
717
|
exports.alchemyRpcUrls = rpcs.alchemyRpcUrls;
|
|
717
718
|
exports.infuraRpcUrls = rpcs.infuraRpcUrls;
|
|
718
719
|
exports.configureChains = configureChains;
|
|
@@ -2,11 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var client = require('./client-
|
|
6
|
-
var base = require('./base-
|
|
7
|
-
var ethers = require('ethers/lib/ethers');
|
|
5
|
+
var client = require('./client-a06c45f3.cjs.prod.js');
|
|
6
|
+
var base = require('./base-6841ebe0.cjs.prod.js');
|
|
7
|
+
var ethers$1 = require('ethers/lib/ethers');
|
|
8
8
|
var utils = require('ethers/lib/utils');
|
|
9
|
-
var
|
|
9
|
+
var chains = require('./chains-0dd661ab.cjs.prod.js');
|
|
10
|
+
var ethers = require('ethers');
|
|
10
11
|
var rpcs = require('./rpcs-b3c52116.cjs.prod.js');
|
|
11
12
|
require('zustand/vanilla');
|
|
12
13
|
require('zustand/middleware');
|
|
@@ -20,6 +21,107 @@ const erc721ABI = ['event Approval(address indexed _owner, address indexed _appr
|
|
|
20
21
|
// https://github.com/ethers-io/ethers.js/blob/master/packages/units/src.ts/index.ts#L10-L18
|
|
21
22
|
const units = ['wei', 'kwei', 'mwei', 'gwei', 'szabo', 'finney', 'ether'];
|
|
22
23
|
|
|
24
|
+
function configureChains(defaultChains, providers) {
|
|
25
|
+
let {
|
|
26
|
+
minQuorum = 1,
|
|
27
|
+
targetQuorum = 1,
|
|
28
|
+
stallTimeout
|
|
29
|
+
} = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
30
|
+
if (targetQuorum < minQuorum) throw new Error('quorum cannot be lower than minQuorum');
|
|
31
|
+
let chains = [];
|
|
32
|
+
const providers_ = {};
|
|
33
|
+
const webSocketProviders_ = {};
|
|
34
|
+
|
|
35
|
+
for (const chain of defaultChains) {
|
|
36
|
+
let configExists = false;
|
|
37
|
+
|
|
38
|
+
for (const provider of providers) {
|
|
39
|
+
const apiConfig = provider(chain); // If no API configuration was found (ie. no RPC URL) for
|
|
40
|
+
// this provider, then we skip and check the next one.
|
|
41
|
+
|
|
42
|
+
if (!apiConfig) continue;
|
|
43
|
+
configExists = true;
|
|
44
|
+
|
|
45
|
+
if (!chains.some(_ref => {
|
|
46
|
+
let {
|
|
47
|
+
id
|
|
48
|
+
} = _ref;
|
|
49
|
+
return id === chain.id;
|
|
50
|
+
})) {
|
|
51
|
+
chains = [...chains, apiConfig.chain];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
providers_[chain.id] = [...(providers_[chain.id] || []), apiConfig.provider];
|
|
55
|
+
|
|
56
|
+
if (apiConfig.webSocketProvider) {
|
|
57
|
+
webSocketProviders_[chain.id] = [...(webSocketProviders_[chain.id] || []), apiConfig.webSocketProvider];
|
|
58
|
+
}
|
|
59
|
+
} // If no API configuration was found across the providers
|
|
60
|
+
// then we throw an error to the consumer.
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
if (!configExists) {
|
|
64
|
+
throw new Error(["Could not find valid provider configuration for chain \"".concat(chain.name, "\".\n"), "You may need to add `jsonRpcProvider` to `configureChains` with the chain's RPC URLs.", 'Read more: https://wagmi.sh/docs/providers/jsonRpc'].join('\n'));
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return {
|
|
69
|
+
chains,
|
|
70
|
+
provider: _ref2 => {
|
|
71
|
+
let {
|
|
72
|
+
chainId
|
|
73
|
+
} = _ref2;
|
|
74
|
+
const chainProviders = providers_[chainId && chains.some(x => x.id === chainId) ? chainId : defaultChains[0].id];
|
|
75
|
+
if (chainProviders.length === 1) return chainProviders[0]();
|
|
76
|
+
return fallbackProvider(targetQuorum, minQuorum, chainProviders, {
|
|
77
|
+
stallTimeout
|
|
78
|
+
});
|
|
79
|
+
},
|
|
80
|
+
webSocketProvider: _ref3 => {
|
|
81
|
+
let {
|
|
82
|
+
chainId
|
|
83
|
+
} = _ref3;
|
|
84
|
+
const chainWebSocketProviders = webSocketProviders_[chainId && chains.some(x => x.id === chainId) ? chainId : defaultChains[0].id];
|
|
85
|
+
if (!chainWebSocketProviders) return undefined;
|
|
86
|
+
if (chainWebSocketProviders.length === 1) return chainWebSocketProviders[0](); // WebSockets do not work with `fallbackProvider`
|
|
87
|
+
// Default to first available
|
|
88
|
+
|
|
89
|
+
return chainWebSocketProviders[0]();
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function fallbackProvider(targetQuorum, minQuorum, providers_, _ref4) {
|
|
95
|
+
let {
|
|
96
|
+
stallTimeout
|
|
97
|
+
} = _ref4;
|
|
98
|
+
|
|
99
|
+
try {
|
|
100
|
+
return new ethers.providers.FallbackProvider(providers_.map((chainProvider, index) => {
|
|
101
|
+
var _provider$priority, _provider$stallTimeou;
|
|
102
|
+
|
|
103
|
+
const provider = chainProvider();
|
|
104
|
+
return {
|
|
105
|
+
provider,
|
|
106
|
+
priority: (_provider$priority = provider.priority) !== null && _provider$priority !== void 0 ? _provider$priority : index,
|
|
107
|
+
stallTimeout: (_provider$stallTimeou = provider.stallTimeout) !== null && _provider$stallTimeou !== void 0 ? _provider$stallTimeou : stallTimeout,
|
|
108
|
+
weight: provider.weight
|
|
109
|
+
};
|
|
110
|
+
}), targetQuorum);
|
|
111
|
+
} catch (error) {
|
|
112
|
+
var _error$message;
|
|
113
|
+
|
|
114
|
+
if (error !== null && error !== void 0 && (_error$message = error.message) !== null && _error$message !== void 0 && _error$message.includes('quorum will always fail; larger than total weight')) {
|
|
115
|
+
if (targetQuorum === minQuorum) throw error;
|
|
116
|
+
return fallbackProvider(targetQuorum - 1, minQuorum, providers_, {
|
|
117
|
+
stallTimeout
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
throw error;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
23
125
|
async function connect(_ref) {
|
|
24
126
|
let {
|
|
25
127
|
connector
|
|
@@ -111,7 +213,7 @@ async function fetchBalance(_ref) {
|
|
|
111
213
|
});
|
|
112
214
|
|
|
113
215
|
if (token) {
|
|
114
|
-
const contract = new ethers.Contract(token, erc20ABI, provider);
|
|
216
|
+
const contract = new ethers$1.Contract(token, erc20ABI, provider);
|
|
115
217
|
const [value, decimals, symbol] = await Promise.all([contract.balanceOf(addressOrName), contract.decimals(), contract.symbol()]);
|
|
116
218
|
return {
|
|
117
219
|
decimals,
|
|
@@ -122,9 +224,9 @@ async function fetchBalance(_ref) {
|
|
|
122
224
|
};
|
|
123
225
|
}
|
|
124
226
|
|
|
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 : []), ...
|
|
227
|
+
const chains$1 = [...((_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 : []), ...chains.allChains];
|
|
126
228
|
const value = await provider.getBalance(addressOrName);
|
|
127
|
-
const chain = chains.find(x => x.id === provider.network.chainId);
|
|
229
|
+
const chain = chains$1.find(x => x.id === provider.network.chainId);
|
|
128
230
|
return {
|
|
129
231
|
decimals: (_chain$nativeCurrency = chain === null || chain === void 0 ? void 0 : (_chain$nativeCurrency2 = chain.nativeCurrency) === null || _chain$nativeCurrency2 === void 0 ? void 0 : _chain$nativeCurrency2.decimals) !== null && _chain$nativeCurrency !== void 0 ? _chain$nativeCurrency : 18,
|
|
130
232
|
formatted: utils.formatUnits(value, unit),
|
|
@@ -159,7 +261,7 @@ function getNetwork() {
|
|
|
159
261
|
const client$1 = client.getClient();
|
|
160
262
|
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
263
|
const activeChains = (_client$chains = client$1.chains) !== null && _client$chains !== void 0 ? _client$chains : [];
|
|
162
|
-
const activeChain = (_find = [...activeChains, ...
|
|
264
|
+
const activeChain = (_find = [...activeChains, ...chains.allChains].find(x => x.id === chainId)) !== null && _find !== void 0 ? _find : {
|
|
163
265
|
id: chainId,
|
|
164
266
|
name: "Chain ".concat(chainId),
|
|
165
267
|
network: "".concat(chainId),
|
|
@@ -282,7 +384,7 @@ function getContract(_ref) {
|
|
|
282
384
|
contractInterface,
|
|
283
385
|
signerOrProvider
|
|
284
386
|
} = _ref;
|
|
285
|
-
return new ethers
|
|
387
|
+
return new ethers.Contract(addressOrName, contractInterface, signerOrProvider);
|
|
286
388
|
}
|
|
287
389
|
|
|
288
390
|
async function readContract(contractConfig, functionName) {
|
|
@@ -543,7 +645,7 @@ async function fetchToken(_ref) {
|
|
|
543
645
|
const provider = getProvider({
|
|
544
646
|
chainId
|
|
545
647
|
});
|
|
546
|
-
const contract = new ethers.Contract(address, erc20ABI, provider);
|
|
648
|
+
const contract = new ethers$1.Contract(address, erc20ABI, provider);
|
|
547
649
|
const [symbol, decimals, totalSupply] = await Promise.all([contract.symbol(), contract.decimals(), contract.totalSupply()]);
|
|
548
650
|
const token = {
|
|
549
651
|
address,
|
|
@@ -589,107 +691,6 @@ async function waitForTransaction(_ref) {
|
|
|
589
691
|
return await promise;
|
|
590
692
|
}
|
|
591
693
|
|
|
592
|
-
function configureChains(defaultChains, providers) {
|
|
593
|
-
let {
|
|
594
|
-
minQuorum = 1,
|
|
595
|
-
targetQuorum = 1,
|
|
596
|
-
stallTimeout
|
|
597
|
-
} = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
598
|
-
if (targetQuorum < minQuorum) throw new Error('quorum cannot be lower than minQuorum');
|
|
599
|
-
let chains = [];
|
|
600
|
-
const providers_ = {};
|
|
601
|
-
const webSocketProviders_ = {};
|
|
602
|
-
|
|
603
|
-
for (const chain of defaultChains) {
|
|
604
|
-
let configExists = false;
|
|
605
|
-
|
|
606
|
-
for (const provider of providers) {
|
|
607
|
-
const apiConfig = provider(chain); // If no API configuration was found (ie. no RPC URL) for
|
|
608
|
-
// this provider, then we skip and check the next one.
|
|
609
|
-
|
|
610
|
-
if (!apiConfig) continue;
|
|
611
|
-
configExists = true;
|
|
612
|
-
|
|
613
|
-
if (!chains.some(_ref => {
|
|
614
|
-
let {
|
|
615
|
-
id
|
|
616
|
-
} = _ref;
|
|
617
|
-
return id === chain.id;
|
|
618
|
-
})) {
|
|
619
|
-
chains = [...chains, apiConfig.chain];
|
|
620
|
-
}
|
|
621
|
-
|
|
622
|
-
providers_[chain.id] = [...(providers_[chain.id] || []), apiConfig.provider];
|
|
623
|
-
|
|
624
|
-
if (apiConfig.webSocketProvider) {
|
|
625
|
-
webSocketProviders_[chain.id] = [...(webSocketProviders_[chain.id] || []), apiConfig.webSocketProvider];
|
|
626
|
-
}
|
|
627
|
-
} // If no API configuration was found across the providers
|
|
628
|
-
// then we throw an error to the consumer.
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
if (!configExists) {
|
|
632
|
-
throw new Error(["Could not find valid provider configuration for chain \"".concat(chain.name, "\".\n"), "You may need to add `jsonRpcProvider` to `configureChains` with the chain's RPC URLs.", 'Read more: https://wagmi.sh/docs/providers/jsonRpc'].join('\n'));
|
|
633
|
-
}
|
|
634
|
-
}
|
|
635
|
-
|
|
636
|
-
return {
|
|
637
|
-
chains,
|
|
638
|
-
provider: _ref2 => {
|
|
639
|
-
let {
|
|
640
|
-
chainId
|
|
641
|
-
} = _ref2;
|
|
642
|
-
const chainProviders = providers_[chainId && chains.some(x => x.id === chainId) ? chainId : defaultChains[0].id];
|
|
643
|
-
if (chainProviders.length === 1) return chainProviders[0]();
|
|
644
|
-
return fallbackProvider(targetQuorum, minQuorum, chainProviders, {
|
|
645
|
-
stallTimeout
|
|
646
|
-
});
|
|
647
|
-
},
|
|
648
|
-
webSocketProvider: _ref3 => {
|
|
649
|
-
let {
|
|
650
|
-
chainId
|
|
651
|
-
} = _ref3;
|
|
652
|
-
const chainWebSocketProviders = webSocketProviders_[chainId && chains.some(x => x.id === chainId) ? chainId : defaultChains[0].id];
|
|
653
|
-
if (!chainWebSocketProviders) return undefined;
|
|
654
|
-
if (chainWebSocketProviders.length === 1) return chainWebSocketProviders[0](); // WebSockets do not work with `fallbackProvider`
|
|
655
|
-
// Default to first available
|
|
656
|
-
|
|
657
|
-
return chainWebSocketProviders[0]();
|
|
658
|
-
}
|
|
659
|
-
};
|
|
660
|
-
}
|
|
661
|
-
|
|
662
|
-
function fallbackProvider(targetQuorum, minQuorum, providers_, _ref4) {
|
|
663
|
-
let {
|
|
664
|
-
stallTimeout
|
|
665
|
-
} = _ref4;
|
|
666
|
-
|
|
667
|
-
try {
|
|
668
|
-
return new ethers$1.providers.FallbackProvider(providers_.map((chainProvider, index) => {
|
|
669
|
-
var _provider$priority, _provider$stallTimeou;
|
|
670
|
-
|
|
671
|
-
const provider = chainProvider();
|
|
672
|
-
return {
|
|
673
|
-
provider,
|
|
674
|
-
priority: (_provider$priority = provider.priority) !== null && _provider$priority !== void 0 ? _provider$priority : index,
|
|
675
|
-
stallTimeout: (_provider$stallTimeou = provider.stallTimeout) !== null && _provider$stallTimeou !== void 0 ? _provider$stallTimeou : stallTimeout,
|
|
676
|
-
weight: provider.weight
|
|
677
|
-
};
|
|
678
|
-
}), targetQuorum);
|
|
679
|
-
} catch (error) {
|
|
680
|
-
var _error$message;
|
|
681
|
-
|
|
682
|
-
if (error !== null && error !== void 0 && (_error$message = error.message) !== null && _error$message !== void 0 && _error$message.includes('quorum will always fail; larger than total weight')) {
|
|
683
|
-
if (targetQuorum === minQuorum) throw error;
|
|
684
|
-
return fallbackProvider(targetQuorum - 1, minQuorum, providers_, {
|
|
685
|
-
stallTimeout
|
|
686
|
-
});
|
|
687
|
-
}
|
|
688
|
-
|
|
689
|
-
throw error;
|
|
690
|
-
}
|
|
691
|
-
}
|
|
692
|
-
|
|
693
694
|
exports.Client = client.Client;
|
|
694
695
|
exports.InjectedConnector = client.InjectedConnector;
|
|
695
696
|
exports.createClient = client.createClient;
|
|
@@ -706,13 +707,13 @@ exports.RpcError = base.RpcError;
|
|
|
706
707
|
exports.SwitchChainError = base.SwitchChainError;
|
|
707
708
|
exports.SwitchChainNotSupportedError = base.SwitchChainNotSupportedError;
|
|
708
709
|
exports.UserRejectedRequestError = base.UserRejectedRequestError;
|
|
709
|
-
exports.allChains = base.allChains;
|
|
710
|
-
exports.chain = base.chain;
|
|
711
|
-
exports.chainId = base.chainId;
|
|
712
|
-
exports.defaultChains = base.defaultChains;
|
|
713
|
-
exports.defaultL2Chains = base.defaultL2Chains;
|
|
714
|
-
exports.etherscanBlockExplorers = base.etherscanBlockExplorers;
|
|
715
710
|
exports.normalizeChainId = base.normalizeChainId;
|
|
711
|
+
exports.allChains = chains.allChains;
|
|
712
|
+
exports.chain = chains.chain;
|
|
713
|
+
exports.chainId = chains.chainId;
|
|
714
|
+
exports.defaultChains = chains.defaultChains;
|
|
715
|
+
exports.defaultL2Chains = chains.defaultL2Chains;
|
|
716
|
+
exports.etherscanBlockExplorers = chains.etherscanBlockExplorers;
|
|
716
717
|
exports.alchemyRpcUrls = rpcs.alchemyRpcUrls;
|
|
717
718
|
exports.infuraRpcUrls = rpcs.infuraRpcUrls;
|
|
718
719
|
exports.configureChains = configureChains;
|