@talismn/token-rates 0.1.6 → 0.1.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/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # @talismn/token-rates
2
2
 
3
+ ## 0.1.8
4
+
5
+ ### Patch Changes
6
+
7
+ - @talismn/chaindata-provider@0.1.8
8
+
9
+ ## 0.1.7
10
+
11
+ ### Patch Changes
12
+
13
+ - db04d0d: fix: missing token rates and empty token rates requests
14
+ - @talismn/chaindata-provider@0.1.7
15
+
3
16
  ## 0.1.6
4
17
 
5
18
  ### Patch Changes
@@ -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 coingeckoIdToTokenId = Object.fromEntries(Object.values(tokens)
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
- .map(({ id, coingeckoId }) => [coingeckoId, id]));
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(coingeckoIdToTokenId);
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.map((coingeckoId) => {
66
- const tokenId = coingeckoIdToTokenId[coingeckoId];
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.6",
3
+ "version": "0.1.8",
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.6",
33
+ "@talismn/chaindata-provider": "^0.1.8",
34
34
  "axios": "^0.27.2"
35
35
  },
36
36
  "devDependencies": {