From e454b20428b3a3636310f18903d44bf9b16cfa47 Mon Sep 17 00:00:00 2001 From: Tom Bertrand Date: Thu, 25 Jan 2024 18:59:41 -0500 Subject: [PATCH] ensure the list of scores exists --- server/api/richList.js | 16 +++++++++------- server/cron/coingeckoStats.js | 10 ++++++---- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/server/api/richList.js b/server/api/richList.js index c18b2e1f..75ad2217 100644 --- a/server/api/richList.js +++ b/server/api/richList.js @@ -24,13 +24,15 @@ const getRichListPage = async (page = 1) => "WITHSCORES", (err, list) => { const data = []; - list.forEach(value => { - if (value.startsWith("nano_")) { - data.push({ account: value }); - } else { - data[data.length - 1].balance = parseFloat(value); - } - }); + list && + list.length && + list.forEach(value => { + if (value.startsWith("nano_")) { + data.push({ account: value }); + } else { + data[data.length - 1].balance = parseFloat(value); + } + }); if (err) Sentry.captureException(err); resolve({ data, meta: { total, perPage: PER_PAGE, offset } }); diff --git a/server/cron/coingeckoStats.js b/server/cron/coingeckoStats.js index 0087ec6c..7710fd13 100644 --- a/server/cron/coingeckoStats.js +++ b/server/cron/coingeckoStats.js @@ -46,6 +46,8 @@ const getPriceStats = async fiats => { bitcoin: json.bitcoin, nano: json.nano, }); + + await sleep(25_000); } } catch (err) { console.log("Error", err); @@ -88,7 +90,7 @@ const getMarketStats = async fiats => { nodeCache.set(`${COINGECKO_MARKET_STATS}-${fiat}`, marketStats); - await sleep(20000); + await sleep(20_000); } } catch (err) { // rate limited @@ -213,9 +215,9 @@ const getMarketCapStats = async () => { // CoinGecko rate limit is 10 calls per seconds if (i && !(i % 10)) { - await sleep(25000); + await sleep(25_000); } else { - await sleep(process.env.NODE_ENV === "production" ? 15000 : 150); + await sleep(process.env.NODE_ENV === "production" ? 15_000 : 150); } } @@ -225,7 +227,7 @@ const getMarketCapStats = async () => { }); } else { console.log(`Failed to get top ${top} cryptocurrencies`, cryptocurrencies); - await sleep(10000); + await sleep(10_000); getMarketCapStats(); return;