import React from "react";
import { ErrorCard } from "components/common/ErrorCard";
import { ClusterStatus, useCluster } from "providers/cluster";
import { LoadingCard } from "components/common/LoadingCard";
import { TableCardBody } from "components/common/TableCardBody";
import { Epoch } from "components/common/Epoch";
import { Slot } from "components/common/Slot";
import { useEpoch, useFetchEpoch } from "providers/epoch";
import { displayTimestampUtc } from "utils/date";
import { FetchStatus } from "providers/cache";
type Props = { epoch: string };
export function EpochDetailsPage({ epoch }: Props) {
let output;
if (isNaN(Number(epoch))) {
output = ;
} else {
output = ;
}
return (
);
}
type OverviewProps = { epoch: number };
function EpochOverviewCard({ epoch }: OverviewProps) {
const { status, epochSchedule, epochInfo } = useCluster();
const epochState = useEpoch(epoch);
const fetchEpoch = useFetchEpoch();
// Fetch extra epoch info on load
React.useEffect(() => {
if (!epochSchedule || !epochInfo) return;
const currentEpoch = epochInfo.epoch;
if (
epoch <= currentEpoch &&
!epochState &&
status === ClusterStatus.Connected
)
fetchEpoch(epoch, currentEpoch, epochSchedule);
}, [epoch, epochState, epochInfo, epochSchedule, status, fetchEpoch]);
if (!epochSchedule || !epochInfo) {
return ;
}
const currentEpoch = epochInfo.epoch;
if (epoch > currentEpoch) {
return ;
} else if (!epochState?.data) {
if (epochState?.status === FetchStatus.FetchFailed) {
return ;
}
return ;
}
const firstSlot = epochSchedule.getFirstSlotInEpoch(epoch);
const lastSlot = epochSchedule.getLastSlotInEpoch(epoch);
return (
<>
Overview
Epoch |
|
{epoch > 0 && (
Previous Epoch |
|
)}
Next Epoch |
{currentEpoch > epoch ? (
) : (
Epoch in progress
)}
|
First Slot |
|
Last Slot |
|
{epochState.data.firstTimestamp && (
First Block Timestamp |
{displayTimestampUtc(
epochState.data.firstTimestamp * 1000,
true
)}
|
)}
First Block |
|
Last Block |
{epochState.data.lastBlock !== undefined ? (
) : (
Epoch in progress
)}
|
{epochState.data.lastTimestamp && (
Last Block Timestamp |
{displayTimestampUtc(
epochState.data.lastTimestamp * 1000,
true
)}
|
)}
>
);
}