From 6781ff2412c102cf4b1bee6da33b99e3ef6aa913 Mon Sep 17 00:00:00 2001 From: Mario Sarcevic Date: Mon, 12 Feb 2024 20:10:26 +0100 Subject: [PATCH] feat: Add hook for Slot/Epoch to time conversions --- .../helpers/nova/hooks/useNovaTimeConvert.ts | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 client/src/helpers/nova/hooks/useNovaTimeConvert.ts diff --git a/client/src/helpers/nova/hooks/useNovaTimeConvert.ts b/client/src/helpers/nova/hooks/useNovaTimeConvert.ts new file mode 100644 index 000000000..26a30f777 --- /dev/null +++ b/client/src/helpers/nova/hooks/useNovaTimeConvert.ts @@ -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, + }; +}