Skip to content

Commit

Permalink
feat: Add hook for Slot/Epoch to time conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
msarcev committed Feb 12, 2024
1 parent 5cd5fd7 commit 6781ff2
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions client/src/helpers/nova/hooks/useNovaTimeConvert.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { useNetworkInfoNova } from "../networkInfo";
import {
slotIndexToEpochIndexConverter,
slotIndexToUnixTimeRangeConverter,
unixTimestampToEpochIndexConverter,
unixTimestampToSlotIndexConverter,
} from "../novaTimeUtils";

export function useNovaTimeConvert(): {
unixTimestampToSlotIndex: ((unixTimestampSeconds: number) => number) | null;
slotIndexToTimeRange: ((slotIndex: number) => { from: number; to: number }) | null;
slotIndexToEpochIndex: ((targetSlotIndex: number) => number) | null;
unixTimestampToEpochIndex: ((unixTimestampSeconds: number) => number) | null;
} {
const { protocolInfo } = useNetworkInfoNova((s) => s.networkInfo);

return {
unixTimestampToSlotIndex: protocolInfo ? unixTimestampToSlotIndexConverter(protocolInfo) : null,
slotIndexToTimeRange: protocolInfo ? slotIndexToUnixTimeRangeConverter(protocolInfo) : null,
slotIndexToEpochIndex: protocolInfo ? slotIndexToEpochIndexConverter(protocolInfo) : null,
unixTimestampToEpochIndex: protocolInfo ? unixTimestampToEpochIndexConverter(protocolInfo) : null,
};
}

0 comments on commit 6781ff2

Please sign in to comment.