From 4e891ae66ba54e341cd26c3456a126f390d18c12 Mon Sep 17 00:00:00 2001 From: Tom Bertrand Date: Fri, 12 Jan 2024 05:24:36 -0500 Subject: [PATCH] fix home page stats --- server/api/representative.js | 4 ++-- server/cron/distribution.js | 12 ++++++------ server/cron/ws.js | 8 ++++---- src/pages/Home/index.tsx | 15 ++++++++++++--- 4 files changed, 24 insertions(+), 15 deletions(-) diff --git a/server/api/representative.js b/server/api/representative.js index f26fd2e4..18f56d19 100644 --- a/server/api/representative.js +++ b/server/api/representative.js @@ -1,5 +1,5 @@ const { nodeCache } = require("../client/cache"); -const { REPRESENTATIVE, EXPIRE_1W } = require("../constants"); +const { REPRESENTATIVE, EXPIRE_7D } = require("../constants"); const { rpc } = require("../rpc"); const { Sentry } = require("../sentry"); @@ -51,7 +51,7 @@ const setRepresentatives = async ({ metrics, peers }) => { Sentry.captureException(err); } - nodeCache.set(REPRESENTATIVE, representatives, EXPIRE_1W); + nodeCache.set(REPRESENTATIVE, representatives, EXPIRE_7D); }; module.exports = { diff --git a/server/cron/distribution.js b/server/cron/distribution.js index 00251ebd..0499b543 100644 --- a/server/cron/distribution.js +++ b/server/cron/distribution.js @@ -11,7 +11,7 @@ const { client: redisClient } = require("../client/redis"); const { Sentry } = require("../sentry"); const { EXPIRE_24H, - EXPIRE_1W, + EXPIRE_7D, DISTRIBUTION, DELEGATORS, DORMANT_FUNDS, @@ -260,8 +260,8 @@ const doDistributionCron = async () => { console.log(`Distribution cron finished in ${(new Date() - startTime) / 1000}s`); - nodeCache.set(DISTRIBUTION, distribution, EXPIRE_1W); - nodeCache.set(DORMANT_FUNDS, dormantFunds, EXPIRE_1W); + nodeCache.set(DISTRIBUTION, distribution, EXPIRE_7D); + nodeCache.set(DORMANT_FUNDS, dormantFunds, EXPIRE_7D); nodeCache.set(KNOWN_EXCHANGES, knownExchanges, EXPIRE_24H); // @NOTE manual add for now @@ -324,14 +324,14 @@ const getDistributionData = () => { distribution = fs.existsSync(DISTRIBUTION_PATH) ? JSON.parse(fs.readFileSync(DISTRIBUTION_PATH, "utf8")) : []; - nodeCache.set(DISTRIBUTION, distribution, EXPIRE_1W); + nodeCache.set(DISTRIBUTION, distribution, EXPIRE_7D); } if (!dormantFunds) { dormantFunds = fs.existsSync(DORMANT_FUNDS_PATH) ? JSON.parse(fs.readFileSync(DORMANT_FUNDS_PATH, "utf8")) : {}; - nodeCache.set(DORMANT_FUNDS, dormantFunds, EXPIRE_1W); + nodeCache.set(DORMANT_FUNDS, dormantFunds, EXPIRE_7D); } if (!knownExchanges) { @@ -343,7 +343,7 @@ const getDistributionData = () => { if (!status) { status = fs.existsSync(STATUS_PATH) ? JSON.parse(fs.readFileSync(STATUS_PATH, "utf8")) : {}; - nodeCache.set(STATUS, status, EXPIRE_1W); + nodeCache.set(STATUS, status, EXPIRE_7D); } return { diff --git a/server/cron/ws.js b/server/cron/ws.js index 6d9132dd..994cc410 100644 --- a/server/cron/ws.js +++ b/server/cron/ws.js @@ -7,7 +7,7 @@ const { Sentry } = require("../sentry"); const { EXPIRE_1M, EXPIRE_24H, - EXPIRE_1W, + EXPIRE_7D, EXPIRE_7D, EXPIRE_14D, EXPIRE_48H, @@ -75,7 +75,7 @@ cron.schedule("*/10 * * * * *", async () => { { $match: { createdAt: { - $gte: new Date(Date.now() - EXPIRE_24H * 1000), + $lt: new Date(Date.now() - EXPIRE_24H * 1000), }, }, }, @@ -92,7 +92,7 @@ cron.schedule("*/10 * * * * *", async () => { { $match: { createdAt: { - $gte: new Date(Date.now() - EXPIRE_1W * 1000), + $lt: new Date(Date.now() - EXPIRE_7D * 1000), }, }, }, @@ -178,7 +178,7 @@ cron.schedule("*/10 * * * * *", async () => { { $match: { createdAt: { - $lt: new Date(Date.now() +TOTAL_VOLUME_14D * 1000), + $lt: new Date(Date.now() + TOTAL_VOLUME_14D * 1000), }, }, }, diff --git a/src/pages/Home/index.tsx b/src/pages/Home/index.tsx index 70ec633d..c4ec98e5 100644 --- a/src/pages/Home/index.tsx +++ b/src/pages/Home/index.tsx @@ -128,8 +128,13 @@ const HomePage = () => { .dividedBy(onChainVolume48hAgo) .times(100) .toNumber(); + // if(onChainVolumeChange24h === Infinity){ + // onChainVolumeChange24h = 0; + // } } + console.log("~~~onChainVolumeChange24h", onChainVolumeChange24h); + let totalConfirmations48hAgo = 0; let confirmationChange24h = 0; if (marketStatistics[TOTAL_CONFIRMATIONS_24H] && marketStatistics[TOTAL_CONFIRMATIONS_48H]) { @@ -302,7 +307,11 @@ const HomePage = () => { isPercent /> } - value={new BigNumber(is24Hours?marketStatistics[TOTAL_VOLUME_24H]:marketStatistics[TOTAL_VOLUME_7D]) + value={new BigNumber( + is24Hours + ? marketStatistics[TOTAL_VOLUME_48H] + : marketStatistics[TOTAL_VOLUME_14D], + ) .decimalPlaces(5) .toNumber()} /> @@ -322,8 +331,8 @@ const HomePage = () => { } value={ is24Hours - ? marketStatistics[TOTAL_CONFIRMATIONS_24H] - : marketStatistics[TOTAL_CONFIRMATIONS_7D] + ? marketStatistics[TOTAL_CONFIRMATIONS_48H] + : marketStatistics[TOTAL_CONFIRMATIONS_14D] } /> {isSmallAndLower ? (