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/client/mongo/schema.js b/server/client/mongo/schema.js index edd625dd..51656ada 100644 --- a/server/client/mongo/schema.js +++ b/server/client/mongo/schema.js @@ -4,7 +4,7 @@ const { EXPIRE_1M, EXPIRE_48H, EXPIRE_7D, - EXPIRE_14D, + // EXPIRE_14D, TOTAL_CONFIRMATIONS_COLLECTION, TOTAL_VOLUME_COLLECTION, LARGE_TRANSACTIONS, @@ -42,7 +42,7 @@ async function createIndexes() { if (!indexExists3) { database .collection(TOTAL_CONFIRMATIONS_COLLECTION) - .createIndex({ createdAt: 1 }, { expireAfterSeconds: EXPIRE_14D, ...extraOptions }); + .createIndex({ createdAt: 1 }, { expireAfterSeconds: EXPIRE_1M, ...extraOptions }); console.log("Index TOTAL_CONFIRMATIONS_COLLECTION createdAt created successfully"); } @@ -50,7 +50,7 @@ async function createIndexes() { if (!indexExists4) { database .collection(TOTAL_VOLUME_COLLECTION) - .createIndex({ createdAt: 1 }, { expireAfterSeconds: EXPIRE_14D, ...extraOptions }); + .createIndex({ createdAt: 1 }, { expireAfterSeconds: EXPIRE_1M, ...extraOptions }); console.log("Index TOTAL_VOLUME_COLLECTION createdAt created successfully"); } diff --git a/server/constants.js b/server/constants.js index 1e5f031e..46e36a89 100644 --- a/server/constants.js +++ b/server/constants.js @@ -11,9 +11,9 @@ const EXPIRE_1Y = EXPIRE_24H * 365; const EXPIRE_5Y = EXPIRE_24H * 365 * 5; const TOTAL_CONFIRMATIONS_COLLECTION = "TOTAL_CONFIRMATIONS"; const TOTAL_CONFIRMATIONS_24H = "TOTAL_CONFIRMATIONS_24H"; +const TOTAL_CONFIRMATIONS_48H = "TOTAL_CONFIRMATIONS_48H"; const TOTAL_CONFIRMATIONS_7D = "TOTAL_CONFIRMATIONS_7D"; const TOTAL_CONFIRMATIONS_14D = "TOTAL_CONFIRMATIONS_14D"; -const TOTAL_CONFIRMATIONS_48H = "TOTAL_CONFIRMATIONS_48H"; const TOTAL_VOLUME_COLLECTION = "TOTAL_VOLUME"; const TOTAL_VOLUME_24H = "TOTAL_VOLUME_24H"; const TOTAL_VOLUME_7D = "TOTAL_VOLUME_7D"; @@ -85,9 +85,9 @@ module.exports = { EXPIRE_5Y, TOTAL_CONFIRMATIONS_COLLECTION, TOTAL_CONFIRMATIONS_24H, + TOTAL_CONFIRMATIONS_48H, TOTAL_CONFIRMATIONS_7D, TOTAL_CONFIRMATIONS_14D, - TOTAL_CONFIRMATIONS_48H, TOTAL_VOLUME_COLLECTION, TOTAL_VOLUME_24H, TOTAL_VOLUME_7D, 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..7af96004 100644 --- a/server/cron/ws.js +++ b/server/cron/ws.js @@ -7,19 +7,18 @@ const { Sentry } = require("../sentry"); const { EXPIRE_1M, EXPIRE_24H, - EXPIRE_1W, + EXPIRE_48H, EXPIRE_7D, EXPIRE_14D, - EXPIRE_48H, TOTAL_CONFIRMATIONS_COLLECTION, TOTAL_CONFIRMATIONS_24H, - TOTAL_CONFIRMATIONS_7D, TOTAL_CONFIRMATIONS_48H, + TOTAL_CONFIRMATIONS_7D, TOTAL_CONFIRMATIONS_14D, TOTAL_VOLUME_COLLECTION, TOTAL_VOLUME_24H, - TOTAL_VOLUME_7D, TOTAL_VOLUME_48H, + TOTAL_VOLUME_7D, TOTAL_VOLUME_14D, CONFIRMATIONS_PER_SECOND, } = require("../constants"); @@ -85,22 +84,22 @@ cron.schedule("*/10 * * * * *", async () => { .then(([{ totalConfirmations24h = 0 } = {}]) => { nodeCache.set(TOTAL_CONFIRMATIONS_24H, totalConfirmations24h); }); - // conf 7d + database .collection(TOTAL_CONFIRMATIONS_COLLECTION) .aggregate([ { $match: { createdAt: { - $gte: new Date(Date.now() - EXPIRE_1W * 1000), + $gte: new Date(Date.now() - EXPIRE_48H * 1000), }, }, }, - { $group: { _id: null, totalConfirmations7d: { $sum: "$value" } } }, + { $group: { _id: null, totalConfirmations48h: { $sum: "$value" } } }, ]) .toArray() - .then(([{ totalConfirmations7d = 0 } = {}]) => { - nodeCache.set(TOTAL_CONFIRMATIONS_7D, totalConfirmations7d); + .then(([{ totalConfirmations48h = 0 } = {}]) => { + nodeCache.set(TOTAL_CONFIRMATIONS_48H, totalConfirmations48h); }); database @@ -109,15 +108,15 @@ cron.schedule("*/10 * * * * *", async () => { { $match: { createdAt: { - $lt: new Date(Date.now() + EXPIRE_48H * 1000), + $gte: new Date(Date.now() - EXPIRE_14D * 1000), }, }, }, - { $group: { _id: null, totalConfirmations48h: { $sum: "$value" } } }, + { $group: { _id: null, totalConfirmations7d: { $sum: "$value" } } }, ]) .toArray() - .then(([{ totalConfirmations48h = 0 } = {}]) => { - nodeCache.set(TOTAL_CONFIRMATIONS_48H, totalConfirmations48h); + .then(([{ totalConfirmations7d = 0 } = {}]) => { + nodeCache.set(TOTAL_CONFIRMATIONS_7D, totalConfirmations7d); }); //conf 1w @@ -144,7 +143,7 @@ cron.schedule("*/10 * * * * *", async () => { { $match: { createdAt: { - $lt: new Date(Date.now() + EXPIRE_24H * 1000), + $gte: new Date(Date.now() - EXPIRE_24H * 1000), }, }, }, @@ -178,7 +177,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), }, }, }, @@ -195,7 +194,7 @@ cron.schedule("*/10 * * * * *", async () => { { $match: { createdAt: { - $lt: new Date(Date.now() + EXPIRE_48H * 1000), + $gte: new Date(Date.now() - EXPIRE_48H * 1000), }, }, }, diff --git a/server/server.js b/server/server.js index 55481fd6..89d7ca3c 100644 --- a/server/server.js +++ b/server/server.js @@ -31,12 +31,12 @@ const path = require("path"); const { nodeCache } = require("./client/cache"); const { TOTAL_CONFIRMATIONS_24H, + TOTAL_CONFIRMATIONS_48H, TOTAL_CONFIRMATIONS_7D, TOTAL_CONFIRMATIONS_14D, TOTAL_VOLUME_24H, - TOTAL_VOLUME_7D, - TOTAL_CONFIRMATIONS_48H, TOTAL_VOLUME_48H, + TOTAL_VOLUME_7D, TOTAL_VOLUME_14D, CONFIRMATIONS_PER_SECOND, NANOTICKER_STATS, @@ -150,12 +150,12 @@ app.get("/api/developer-fund/transactions", async (req, res) => { app.get("/api/market-statistics", async (req, res) => { const cachedConfirmations24h = nodeCache.get(TOTAL_CONFIRMATIONS_24H); + const cachedConfirmations48h = nodeCache.get(TOTAL_CONFIRMATIONS_48H); const cachedConfirmations7d = nodeCache.get(TOTAL_CONFIRMATIONS_7D); const cachedConfirmations14d = nodeCache.get(TOTAL_CONFIRMATIONS_14D); const cachedVolume24h = nodeCache.get(TOTAL_VOLUME_24H); - const cachedVolume7d = nodeCache.get(TOTAL_VOLUME_7D); - const cachedConfirmations48h = nodeCache.get(TOTAL_CONFIRMATIONS_48H); const cachedVolume48h = nodeCache.get(TOTAL_VOLUME_48H); + const cachedVolume7d = nodeCache.get(TOTAL_VOLUME_7D); const cachedVolume14d = nodeCache.get(TOTAL_VOLUME_14D); const nanotpsStats = nodeCache.get(NANOTPS_STATS); const nanoSpeedStats = nodeCache.get(NANOSPEED_STATS); @@ -171,15 +171,14 @@ app.get("/api/market-statistics", async (req, res) => { cryptocurrency: req.query.cryptocurrency, }); - res.send({ [TOTAL_CONFIRMATIONS_24H]: cachedConfirmations24h, + [TOTAL_CONFIRMATIONS_48H]: cachedConfirmations48h, [TOTAL_CONFIRMATIONS_7D]: cachedConfirmations7d, [TOTAL_CONFIRMATIONS_14D]: cachedConfirmations14d, [TOTAL_VOLUME_24H]: cachedVolume24h, - [TOTAL_VOLUME_7D]: cachedVolume7d, - [TOTAL_CONFIRMATIONS_48H]: cachedConfirmations48h, [TOTAL_VOLUME_48H]: cachedVolume48h, + [TOTAL_VOLUME_7D]: cachedVolume7d, [TOTAL_VOLUME_14D]: cachedVolume14d, [BITCOIN_TOTAL_TRANSACTION_FEES_24H]: btcTransactionFees24h, [BITCOIN_TOTAL_TRANSACTION_FEES_7D]: btcTransactionFees7d, diff --git a/src/api/contexts/MarketStatistics.tsx b/src/api/contexts/MarketStatistics.tsx index cb7087b1..d9b95e29 100644 --- a/src/api/contexts/MarketStatistics.tsx +++ b/src/api/contexts/MarketStatistics.tsx @@ -8,9 +8,9 @@ export const TOTAL_CONFIRMATIONS_24H = "TOTAL_CONFIRMATIONS_24H"; export const TOTAL_CONFIRMATIONS_7D = "TOTAL_CONFIRMATIONS_7D"; export const TOTAL_CONFIRMATIONS_14D = "TOTAL_CONFIRMATIONS_14D"; export const TOTAL_VOLUME_24H = "TOTAL_VOLUME_24H"; +export const TOTAL_CONFIRMATIONS_48H = "TOTAL_CONFIRMATIONS_48H"; export const TOTAL_VOLUME_7D = "TOTAL_VOLUME_7D"; export const TOTAL_VOLUME_14D = "TOTAL_VOLUME_14D"; -export const TOTAL_CONFIRMATIONS_48H = "TOTAL_CONFIRMATIONS_48H"; export const TOTAL_VOLUME_48H = "TOTAL_VOLUME_48H"; export const BITCOIN_TOTAL_TRANSACTION_FEES_24H = "BITCOIN_TOTAL_TRANSACTION_FEES_24H"; export const BITCOIN_TOTAL_TRANSACTION_FEES_7D = "BITCOIN_TOTAL_TRANSACTION_FEES_7D"; @@ -21,12 +21,12 @@ export const NANOSPEED_STATS = "NANOSPEED_STATS"; export interface Response { [TOTAL_CONFIRMATIONS_24H]: number; - [TOTAL_CONFIRMATIONS_7D]: number; - [TOTAL_VOLUME_24H]: number; - [TOTAL_VOLUME_7D]: number; [TOTAL_CONFIRMATIONS_48H]: number; + [TOTAL_CONFIRMATIONS_7D]: number; [TOTAL_CONFIRMATIONS_14D]: number; + [TOTAL_VOLUME_24H]: number; [TOTAL_VOLUME_48H]: number; + [TOTAL_VOLUME_7D]: number; [TOTAL_VOLUME_14D]: number; [BITCOIN_TOTAL_TRANSACTION_FEES_24H]: number; [BITCOIN_TOTAL_TRANSACTION_FEES_7D]: number; @@ -66,12 +66,12 @@ let pollMarketStatisticsTimeout: number | undefined; export const MarketStatisticsContext = React.createContext({ marketStatistics: { [TOTAL_CONFIRMATIONS_24H]: 0, + [TOTAL_CONFIRMATIONS_48H]: 0, [TOTAL_CONFIRMATIONS_7D]: 0, [TOTAL_CONFIRMATIONS_14D]: 0, [TOTAL_VOLUME_24H]: 0, - [TOTAL_VOLUME_7D]: 0, - [TOTAL_CONFIRMATIONS_48H]: 0, [TOTAL_VOLUME_48H]: 0, + [TOTAL_VOLUME_7D]: 0, [TOTAL_VOLUME_14D]: 0, [BITCOIN_TOTAL_TRANSACTION_FEES_24H]: 0, [BITCOIN_TOTAL_TRANSACTION_FEES_7D]: 0, diff --git a/src/components/StatisticsChange/index.tsx b/src/components/StatisticsChange/index.tsx index 2c1fbe54..4fb4f527 100644 --- a/src/components/StatisticsChange/index.tsx +++ b/src/components/StatisticsChange/index.tsx @@ -14,11 +14,12 @@ interface StatisticsChangeProps { } const StatisticsChange: React.FC = ({ - value, + value: rawValue, isPercent, isNumber, suffix, }) => { + let value = rawValue; const { theme } = React.useContext(PreferencesContext); const color = ( value === 0 diff --git a/src/pages/Home/index.tsx b/src/pages/Home/index.tsx index 8bb60738..394a56df 100644 --- a/src/pages/Home/index.tsx +++ b/src/pages/Home/index.tsx @@ -16,11 +16,11 @@ import { BITCOIN_TOTAL_TRANSACTION_FEES_48H, MarketStatisticsContext, TOTAL_CONFIRMATIONS_7D, - TOTAL_CONFIRMATIONS_14D, + // TOTAL_CONFIRMATIONS_14D, TOTAL_CONFIRMATIONS_24H, TOTAL_CONFIRMATIONS_48H, TOTAL_VOLUME_7D, - TOTAL_VOLUME_14D, + // TOTAL_VOLUME_14D, TOTAL_VOLUME_24H, TOTAL_VOLUME_48H, } from "api/contexts/MarketStatistics"; @@ -117,60 +117,31 @@ const HomePage = () => { .times(100) .toNumber() : 0; - let onChainVolume48hAgo = 0; - let onChainVolumeChange24h = 0; - if (marketStatistics[TOTAL_VOLUME_24H] && marketStatistics[TOTAL_VOLUME_48H]) { - onChainVolume48hAgo = new BigNumber(marketStatistics[TOTAL_VOLUME_48H]) - .minus(marketStatistics[TOTAL_VOLUME_24H]) - .toNumber(); - onChainVolumeChange24h = new BigNumber(marketStatistics[TOTAL_VOLUME_24H]) - .minus(onChainVolume48hAgo) - .dividedBy(onChainVolume48hAgo) - .times(100) - .toNumber(); - } - - let totalConfirmations48hAgo = 0; - let confirmationChange24h = 0; - - if (marketStatistics[TOTAL_CONFIRMATIONS_24H] && marketStatistics[TOTAL_CONFIRMATIONS_48H]) { - totalConfirmations48hAgo = new BigNumber(marketStatistics[TOTAL_CONFIRMATIONS_48H]) - .minus(marketStatistics[TOTAL_CONFIRMATIONS_24H]) - .toNumber(); - confirmationChange24h = new BigNumber(marketStatistics[TOTAL_CONFIRMATIONS_24H]) - .minus(totalConfirmations48hAgo) - .dividedBy(totalConfirmations48hAgo) - .times(100) - .toNumber(); - } - - // Start here - - let onChainVolume14dAgo = 0; - let onChainVolumeChange7d = 0; - if (marketStatistics[TOTAL_VOLUME_7D] && marketStatistics[TOTAL_VOLUME_14D]) { - onChainVolume14dAgo = new BigNumber(marketStatistics[TOTAL_VOLUME_14D]) - .minus(marketStatistics[TOTAL_VOLUME_7D]) - .toNumber(); - onChainVolumeChange7d = new BigNumber(marketStatistics[TOTAL_VOLUME_7D]) - .minus(onChainVolume14dAgo) - .dividedBy(onChainVolume14dAgo) - .times(100) - .toNumber(); - } - - let totalConfirmations14dAgo = 0; - let confirmationChange7d = 0; - if (marketStatistics[TOTAL_CONFIRMATIONS_7D] && marketStatistics[TOTAL_CONFIRMATIONS_14D]) { - totalConfirmations14dAgo = new BigNumber(marketStatistics[TOTAL_CONFIRMATIONS_14D]) - .minus(marketStatistics[TOTAL_CONFIRMATIONS_7D]) - .toNumber(); - confirmationChange7d = new BigNumber(marketStatistics[TOTAL_CONFIRMATIONS_7D]) - .minus(totalConfirmations14dAgo) - .dividedBy(totalConfirmations14dAgo) - .times(100) - .toNumber(); - } + let onChainVolume48hAgo = 0; + let onChainVolumeChange24h = 0; + if (marketStatistics[TOTAL_VOLUME_24H] && marketStatistics[TOTAL_VOLUME_48H]) { + onChainVolume48hAgo = new BigNumber(marketStatistics[TOTAL_VOLUME_48H]) + .minus(marketStatistics[TOTAL_VOLUME_24H]) + .toNumber(); + onChainVolumeChange24h = new BigNumber(marketStatistics[TOTAL_VOLUME_24H]) + .minus(onChainVolume48hAgo) + .dividedBy(onChainVolume48hAgo) + .times(100) + .toNumber(); + } + + let totalConfirmations48hAgo = 0; + let confirmationChange24h = 0; + if (marketStatistics[TOTAL_CONFIRMATIONS_24H] && marketStatistics[TOTAL_CONFIRMATIONS_48H]) { + totalConfirmations48hAgo = new BigNumber(marketStatistics[TOTAL_CONFIRMATIONS_48H]) + .minus(marketStatistics[TOTAL_CONFIRMATIONS_24H]) + .toNumber(); + confirmationChange24h = new BigNumber(marketStatistics[TOTAL_CONFIRMATIONS_24H]) + .minus(totalConfirmations48hAgo) + .dividedBy(totalConfirmations48hAgo) + .times(100) + .toNumber(); + } React.useEffect(() => { setFormattedLedgerSize(formatBytes(ledgerSize)); @@ -264,17 +235,15 @@ const HomePage = () => { - {is24Hours ?t("pages.home.last24Hours"): t("pages.home.last7Days")} - - - - - + + {is24Hours ? t("pages.home.last24Hours") : t("pages.home.last7Days")} + + + + } extra={ isFeatureActive ? ( @@ -297,7 +266,7 @@ const HomePage = () => { isMarketStatisticsError || !onChainVolumeChange24h } - tooltip={t("tooltips.onChainVolume")} + tooltip={t("tooltips.onChainVolume") as string} title={t("pages.home.onChainVolume")} suffix={ { isLoading={ isMarketStatisticsInitialLoading || isMarketStatisticsError || - !confirmationChange24h || - !confirmationChange7d + !confirmationChange24h } title={t("pages.home.confirmedTransactions")} suffix={ @@ -327,7 +295,11 @@ const HomePage = () => { isPercent /> } - value={marketStatistics[TOTAL_CONFIRMATIONS_24H]} + value={ + is24Hours + ? marketStatistics[TOTAL_CONFIRMATIONS_24H] + : marketStatistics[TOTAL_CONFIRMATIONS_7D] + } /> {isSmallAndLower ? (