Skip to content

Commit

Permalink
fix home page stats
Browse files Browse the repository at this point in the history
  • Loading branch information
tombertrand committed Jan 12, 2024
1 parent 853a161 commit 4e891ae
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 15 deletions.
4 changes: 2 additions & 2 deletions server/api/representative.js
Original file line number Diff line number Diff line change
@@ -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");

Expand Down Expand Up @@ -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 = {
Expand Down
12 changes: 6 additions & 6 deletions server/cron/distribution.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand All @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions server/cron/ws.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const { Sentry } = require("../sentry");
const {
EXPIRE_1M,
EXPIRE_24H,
EXPIRE_1W,
EXPIRE_7D,
EXPIRE_7D,
EXPIRE_14D,
EXPIRE_48H,
Expand Down Expand Up @@ -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),
},
},
},
Expand All @@ -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),
},
},
},
Expand Down Expand Up @@ -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),
},
},
},
Expand Down
15 changes: 12 additions & 3 deletions src/pages/Home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {
Expand Down Expand Up @@ -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()}
/>
Expand All @@ -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 ? (
Expand Down

0 comments on commit 4e891ae

Please sign in to comment.