@talismn/token-rates 0.1.6 → 0.1.7
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/CHANGELOG.md +7 -0
- package/dist/TokenRates.js +14 -6
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
package/dist/TokenRates.js
CHANGED
@@ -38,15 +38,23 @@ const coingeckoCurrencies = [
|
|
38
38
|
function fetchTokenRates(tokens) {
|
39
39
|
return __awaiter(this, void 0, void 0, function* () {
|
40
40
|
// create a map from `coingeckoId` -> `tokenId` for each token
|
41
|
-
const
|
41
|
+
const coingeckoIdToTokenIds = Object.values(tokens)
|
42
42
|
// ignore testnet tokens
|
43
43
|
.filter(({ isTestnet }) => !isTestnet)
|
44
44
|
// ignore tokens which don't have a coingeckoId
|
45
45
|
.filter(hasCoingeckoId)
|
46
46
|
// get each token's coingeckoId
|
47
|
-
.
|
47
|
+
.reduce((coingeckoIdToTokenIds, { id, coingeckoId }) => {
|
48
|
+
if (!coingeckoIdToTokenIds[coingeckoId])
|
49
|
+
coingeckoIdToTokenIds[coingeckoId] = [];
|
50
|
+
coingeckoIdToTokenIds[coingeckoId].push(id);
|
51
|
+
return coingeckoIdToTokenIds;
|
52
|
+
}, {});
|
48
53
|
// create a list of coingeckoIds we want to fetch
|
49
|
-
const coingeckoIds = Object.keys(
|
54
|
+
const coingeckoIds = Object.keys(coingeckoIdToTokenIds);
|
55
|
+
// skip network request if there is nothing for us to fetch
|
56
|
+
if (coingeckoIds.length < 1)
|
57
|
+
return {};
|
50
58
|
// construct a coingecko request
|
51
59
|
const idsSerialized = coingeckoIds.join(",");
|
52
60
|
const currenciesSerialized = coingeckoCurrencies.join(",");
|
@@ -62,13 +70,13 @@ function fetchTokenRates(tokens) {
|
|
62
70
|
.get(queryUrl)
|
63
71
|
.then((response) => response.data);
|
64
72
|
// build a TokenRatesList from the token prices result
|
65
|
-
const ratesList = Object.fromEntries(coingeckoIds.
|
66
|
-
const
|
73
|
+
const ratesList = Object.fromEntries(coingeckoIds.flatMap((coingeckoId) => {
|
74
|
+
const tokenIds = coingeckoIdToTokenIds[coingeckoId];
|
67
75
|
const rates = (0, types_1.NewTokenRates)();
|
68
76
|
for (const currency of coingeckoCurrencies) {
|
69
77
|
rates[currency] = ((coingeckoPrices || {})[coingeckoId] || {})[currency] || null;
|
70
78
|
}
|
71
|
-
return [tokenId, rates];
|
79
|
+
return tokenIds.map((tokenId) => [tokenId, rates]);
|
72
80
|
}));
|
73
81
|
// return the TokenRatesList
|
74
82
|
return ratesList;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@talismn/token-rates",
|
3
|
-
"version": "0.1.
|
3
|
+
"version": "0.1.7",
|
4
4
|
"author": "Talisman",
|
5
5
|
"homepage": "https://talisman.xyz",
|
6
6
|
"license": "UNLICENSED",
|
@@ -30,7 +30,7 @@
|
|
30
30
|
"clean": "rm -rf dist && rm -rf .turbo rm -rf node_modules"
|
31
31
|
},
|
32
32
|
"dependencies": {
|
33
|
-
"@talismn/chaindata-provider": "^0.1.
|
33
|
+
"@talismn/chaindata-provider": "^0.1.7",
|
34
34
|
"axios": "^0.27.2"
|
35
35
|
},
|
36
36
|
"devDependencies": {
|