Skip to content

Commit 1759a24

Browse files
fix: slot list status
1 parent ba31f17 commit 1759a24

File tree

1 file changed

+34
-33
lines changed

1 file changed

+34
-33
lines changed

src/features/Navigation/SlotsRenderer.tsx

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { Box, Flex, Progress, Text } from "@radix-ui/themes";
1111
import { useSlotQueryPublish } from "../../hooks/useSlotQuery";
1212
import type React from "react";
1313
import { memo, useMemo } from "react";
14+
import type { CSSProperties } from "react";
1415
import styles from "./slotsRenderer.module.css";
1516
import PeerIcon from "../../components/PeerIcon";
1617
import { slotsPerLeader } from "../../consts";
@@ -30,6 +31,7 @@ import SlotClient from "../../components/SlotClient";
3031
import { useIsLeaderGroupSkipped } from "../../hooks/useIsLeaderGroupSkipped";
3132
import { isScrollingAtom } from "./atoms";
3233
import useNextSlot from "../../hooks/useNextSlot";
34+
import type { SlotPublish } from "../../api/types";
3335

3436
export default function SlotsRenderer(props: { leaderSlotForGroup: number }) {
3537
const isScrolling = useAtomValue(isScrollingAtom);
@@ -352,6 +354,22 @@ function SlotStatus({
352354
);
353355
}
354356

357+
function getSlotStatusColorStyles(publish?: SlotPublish): CSSProperties {
358+
if (!publish) return {};
359+
if (publish.skipped) return { backgroundColor: slotStatusRed };
360+
switch (publish.level) {
361+
case "incomplete":
362+
return {};
363+
case "completed":
364+
return { borderColor: slotStatusGreen };
365+
case "optimistically_confirmed":
366+
return { backgroundColor: slotStatusGreen };
367+
case "finalized":
368+
case "rooted":
369+
return { backgroundColor: slotStatusTeal };
370+
}
371+
}
372+
355373
function CurrentSlotStatus({ slot }: { slot: number }) {
356374
const currentSlot = useAtomValue(currentSlotAtom);
357375
const queryPublish = useSlotQueryPublish(slot);
@@ -360,19 +378,7 @@ function CurrentSlotStatus({ slot }: { slot: number }) {
360378
const isCurrent = useMemo(() => slot === currentSlot, [slot, currentSlot]);
361379
const colorStyle = useMemo(() => {
362380
if (isCurrent) return { borderColor: slotStatusBlue };
363-
if (!queryPublish.publish) return {};
364-
if (queryPublish.publish.skipped) return { backgroundColor: slotStatusRed };
365-
switch (queryPublish.publish.level) {
366-
case "incomplete":
367-
return {};
368-
case "completed":
369-
return { borderColor: slotStatusGreen };
370-
case "optimistically_confirmed":
371-
return { backgroundColor: slotStatusGreen };
372-
case "finalized":
373-
case "rooted":
374-
return { backgroundColor: slotStatusTeal };
375-
}
381+
return getSlotStatusColorStyles(queryPublish.publish);
376382
}, [isCurrent, queryPublish.publish]);
377383

378384
return (
@@ -387,27 +393,22 @@ function CurrentSlotStatus({ slot }: { slot: number }) {
387393
function PastSlotStatus({ slot }: { slot: number }) {
388394
const queryPublish = useSlotQueryPublish(slot);
389395
const selectedSlot = useAtomValue(selectedSlotAtom);
390-
const backgroundColor = useMemo(() => {
391-
if (!queryPublish.publish) return;
392-
if (queryPublish.publish.skipped) return slotStatusRed;
393-
switch (queryPublish.publish.level) {
394-
case "incomplete":
395-
return;
396-
case "completed":
397-
return slotStatusGreen;
398-
case "optimistically_confirmed":
399-
return slotStatusGreen;
400-
case "finalized":
401-
case "rooted":
402-
if (
403-
selectedSlot !== undefined &&
404-
getSlotGroupLeader(slot) === getSlotGroupLeader(selectedSlot)
405-
) {
406-
return slotStatusTeal;
407-
}
408-
return slotStatusDullTeal;
396+
const colorStyle = useMemo(() => {
397+
const style = getSlotStatusColorStyles(queryPublish.publish);
398+
if (
399+
queryPublish?.publish?.level === "rooted" &&
400+
(selectedSlot === undefined ||
401+
getSlotGroupLeader(slot) !== getSlotGroupLeader(selectedSlot))
402+
) {
403+
style.backgroundColor = slotStatusDullTeal;
409404
}
405+
return style;
410406
}, [queryPublish.publish, selectedSlot, slot]);
411407

412-
return <SlotStatus backgroundColor={backgroundColor} />;
408+
return (
409+
<SlotStatus
410+
borderColor={colorStyle.borderColor}
411+
backgroundColor={colorStyle.backgroundColor}
412+
/>
413+
);
413414
}

0 commit comments

Comments
 (0)