@@ -11,6 +11,7 @@ import { Box, Flex, Progress, Text } from "@radix-ui/themes";
1111import { useSlotQueryPublish } from "../../hooks/useSlotQuery" ;
1212import type React from "react" ;
1313import { memo , useMemo } from "react" ;
14+ import type { CSSProperties } from "react" ;
1415import styles from "./slotsRenderer.module.css" ;
1516import PeerIcon from "../../components/PeerIcon" ;
1617import { slotsPerLeader } from "../../consts" ;
@@ -30,6 +31,7 @@ import SlotClient from "../../components/SlotClient";
3031import { useIsLeaderGroupSkipped } from "../../hooks/useIsLeaderGroupSkipped" ;
3132import { isScrollingAtom } from "./atoms" ;
3233import useNextSlot from "../../hooks/useNextSlot" ;
34+ import type { SlotPublish } from "../../api/types" ;
3335
3436export 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+
355373function 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 }) {
387393function 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