diff --git a/client/src/app/routes/nova/EpochPage.tsx b/client/src/app/routes/nova/EpochPage.tsx index 75ea1f33e..447c1cfa5 100644 --- a/client/src/app/routes/nova/EpochPage.tsx +++ b/client/src/app/routes/nova/EpochPage.tsx @@ -55,9 +55,10 @@ const EpochPage: React.FC> = ({ ? candidates?.map((candidate) => candidate.validator).filter((validator) => validator.active) : epochCommittee?.committee; + const epochStartTime = moment.unix(epochUnixTimeRange.from); + const epochEndTime = moment.unix(epochUnixTimeRange.to - 1); + if (registrationTime) { - const epochStartTime = moment.unix(epochUnixTimeRange.from); - const epochEndTime = moment.unix(epochUnixTimeRange.to - 1); epochFrom = epochStartTime.format("DD MMM HH:mm:ss"); epochTo = epochEndTime.format("DD MMM HH:mm:ss"); @@ -70,6 +71,8 @@ const EpochPage: React.FC> = ({ if (isFutureEpoch) { const diffToEpochStart = moment.unix(epochUnixTimeRange.from).diff(moment()); futureEpochStartsIn = moment(diffToEpochStart).format("H:mm:ss"); + epochFrom = epochStartTime.format("DD MMM YYYY HH:mm:ss"); + epochTo = epochEndTime.format("DD MMM YYYY HH:mm:ss"); } return ( @@ -97,20 +100,20 @@ const EpochPage: React.FC> = ({
To:
{epochTo}
+
+
Time remaining:
+
{isFutureEpoch ? "Not started" : epochTimeRemaining}
+
+
+
Progress:
+
{isFutureEpoch ? "0%" : `${epochProgressPercent}%`}
+
+
+
Registration end:
+
{isFutureEpoch ? "-" : registrationTimeRemaining}
+
{!isFutureEpoch && ( <> -
-
Time remaining:
-
{epochTimeRemaining}
-
-
-
Progress:
-
{epochProgressPercent}%
-
-
-
Registration end:
-
{registrationTimeRemaining}
-
Total pool stake:
{epochCommittee?.totalStake ?? 0}
diff --git a/client/src/helpers/nova/hooks/useEpochProgress.ts b/client/src/helpers/nova/hooks/useEpochProgress.ts index 4cc136704..33b57fc23 100644 --- a/client/src/helpers/nova/hooks/useEpochProgress.ts +++ b/client/src/helpers/nova/hooks/useEpochProgress.ts @@ -1,6 +1,7 @@ import moment from "moment"; import { useEffect, useState } from "react"; import { useNovaTimeConvert } from "./useNovaTimeConvert"; +import { NumberHelper } from "~helpers/numberHelper"; /** * Returns the epoch progress information for the provided index or the current epoch if no index is provided. @@ -35,13 +36,24 @@ export function useEpochProgress(index?: number): { }; }, [index]); + const determineCurrentEpochIndex = (providedIndex: number | undefined, currentTime: number): number => { + if (providedIndex !== undefined && NumberHelper.isNumber(providedIndex)) { + return providedIndex; + } else if (unixTimestampToEpochIndex) { + const epochIndex = unixTimestampToEpochIndex(currentTime); + if (!NumberHelper.isNumber(epochIndex)) { + throw new Error("Failed to convert timestamp to a valid epoch index."); + } + return epochIndex; + } else { + throw new Error("unixTimestampToEpochIndex function is unavailable."); + } + }; + const checkEpochIndex = () => { if (unixTimestampToEpochIndex && epochIndexToUnixTimeRange) { const now = moment().unix(); - let currentEpochIndex = index ?? null; - if (!currentEpochIndex) { - currentEpochIndex = unixTimestampToEpochIndex(now); - } + const currentEpochIndex = determineCurrentEpochIndex(index, now); const epochTimeRange = epochIndexToUnixTimeRange(currentEpochIndex); diff --git a/client/src/helpers/numberHelper.ts b/client/src/helpers/numberHelper.ts index 65b44b46c..924d46406 100644 --- a/client/src/helpers/numberHelper.ts +++ b/client/src/helpers/numberHelper.ts @@ -12,4 +12,8 @@ export class NumberHelper { public static isNumeric(value: string): boolean { return /^-?\d+$/.test(value); } + + public static isNumber(value?: number | null): boolean { + return value !== null && value !== undefined && !isNaN(value); + } }