From ebe14415f6f678c7a91d436f53ba8d0ba52f7825 Mon Sep 17 00:00:00 2001 From: Justin Starry Date: Tue, 4 Aug 2020 22:18:09 +0800 Subject: [PATCH] Use more accurate epoch duration calculation in explorer (#11359) --- explorer/src/components/StatsCard.tsx | 8 ++++++-- explorer/src/utils/index.tsx | 7 +++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/explorer/src/components/StatsCard.tsx b/explorer/src/components/StatsCard.tsx index 09ebddaa02..c404531249 100644 --- a/explorer/src/components/StatsCard.tsx +++ b/explorer/src/components/StatsCard.tsx @@ -62,12 +62,16 @@ function StatsCardBody() { } const currentBlock = rootSlot.toLocaleString("en-US"); - const { avgBlockTime_1min, epochInfo } = dashboardInfo; + const { avgBlockTime_1h, avgBlockTime_1min, epochInfo } = dashboardInfo; + const hourlyBlockTime = Math.round(1000 * avgBlockTime_1h); const averageBlockTime = Math.round(1000 * avgBlockTime_1min) + "ms"; const { slotIndex, slotsInEpoch } = epochInfo; const currentEpoch = epochInfo.epoch.toString(); const epochProgress = ((100 * slotIndex) / slotsInEpoch).toFixed(1) + "%"; - const epochTimeRemaining = slotsToHumanString(slotsInEpoch - slotIndex); + const epochTimeRemaining = slotsToHumanString( + slotsInEpoch - slotIndex, + hourlyBlockTime + ); const averageTps = Math.round(performanceInfo.avgTPS); const transactionCount = ; diff --git a/explorer/src/utils/index.tsx b/explorer/src/utils/index.tsx index 3e88917821..e7fb806bfb 100644 --- a/explorer/src/utils/index.tsx +++ b/explorer/src/utils/index.tsx @@ -52,6 +52,9 @@ HUMANIZER.addLanguage("short", { decimal: ".", }); -export function slotsToHumanString(slots: number): string { - return HUMANIZER.humanize(slots * MS_PER_SLOT); +export function slotsToHumanString( + slots: number, + slotTime = MS_PER_SLOT +): string { + return HUMANIZER.humanize(slots * slotTime); }