-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add status to slot page (#1207)
* feat: add slot status to the slot page * feat: add slot status correctly --------- Co-authored-by: Branko Bosnic <[email protected]>
- Loading branch information
Showing
5 changed files
with
83 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { SlotCommitmentStatus } from "~/models/api/nova/ILatestSlotCommitmentsResponse"; | ||
import { SlotStatus } from "../enums"; | ||
import { PillStatus } from "../ui/enums"; | ||
|
||
export const SLOT_COMMITMENT_STATUS_TO_SLOT_STATUS: Record<SlotCommitmentStatus, SlotStatus> = { | ||
[SlotCommitmentStatus.Committed]: SlotStatus.Committed, | ||
[SlotCommitmentStatus.Finalized]: SlotStatus.Finalized, | ||
}; | ||
|
||
export const SLOT_STATUS_TO_PILL_STATUS: Record<SlotStatus, PillStatus> = { | ||
[SlotStatus.Pending]: PillStatus.Pending, | ||
[SlotStatus.Committed]: PillStatus.Success, | ||
[SlotStatus.Finalized]: PillStatus.Success, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./slot-status.enum"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export enum SlotStatus { | ||
Pending = "pending", | ||
Committed = "committed", | ||
Finalized = "finalized", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { ISlotCommitmentWrapper, SlotCommitmentStatus } from "~/models/api/nova/ILatestSlotCommitmentsResponse"; | ||
import { SlotStatus } from "../enums"; | ||
import { SLOT_COMMITMENT_STATUS_TO_SLOT_STATUS } from "../constants/slot.constants"; | ||
|
||
export function parseSlotIndexFromParams(slotIndex: string): number | undefined { | ||
const slotIndexNum = parseInt(slotIndex, 10); | ||
if (isNaN(slotIndexNum)) { | ||
return; | ||
} | ||
return slotIndexNum; | ||
} | ||
|
||
export function getSlotStatusFromLatestSlotCommitments( | ||
slotIndex: number | undefined, | ||
latestSlotCommitments: ISlotCommitmentWrapper[], | ||
): SlotStatus { | ||
let slotStatus: SlotStatus = SlotStatus.Pending; | ||
|
||
if (slotIndex === undefined) { | ||
return slotStatus; | ||
} | ||
|
||
const newestSlot = latestSlotCommitments[0]; | ||
const oldestSlot = latestSlotCommitments[latestSlotCommitments.length - 1]; | ||
|
||
if (!newestSlot || slotIndex > newestSlot.slotCommitment.slot) { | ||
return slotStatus; | ||
} | ||
|
||
if (slotIndex < oldestSlot.slotCommitment.slot) { | ||
// If searched slot is less than the oldest slot, infer status based on the oldest slot's status | ||
return oldestSlot.status === SlotCommitmentStatus.Finalized ? SlotStatus.Finalized : SlotStatus.Committed; | ||
} | ||
|
||
for (const { slotCommitment, status } of latestSlotCommitments) { | ||
if (slotCommitment.slot >= slotIndex) { | ||
if (status === SlotCommitmentStatus.Finalized) { | ||
slotStatus = SLOT_COMMITMENT_STATUS_TO_SLOT_STATUS[status]; | ||
break; | ||
} | ||
} else { | ||
break; | ||
} | ||
} | ||
|
||
return slotStatus; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters