@@ -9,6 +9,8 @@ import { Cluster } from "../../services/pyth";
99import type { PriceComponent } from "../PriceComponentsCard" ;
1010import { PriceComponentsCard } from "../PriceComponentsCard" ;
1111import { PublisherTag } from "../PublisherTag" ;
12+ import { useLivePriceData } from '../../hooks/use-live-price-data' ;
13+ import { Status } from '../../status' ;
1214
1315type PublishersCardProps =
1416 | { isLoading : true }
@@ -29,7 +31,7 @@ type ResolvedPublishersCardProps = {
2931 symbol : string ;
3032 displaySymbol : string ;
3133 assetClass : string ;
32- publishers : Omit < PriceComponent , "symbol" | "displaySymbol" | "assetClass" > [ ] ;
34+ publishers : Omit < PriceComponent , "status" | " symbol" | "displaySymbol" | "assetClass" > [ ] ;
3335 metricsTime ?: Date | undefined ;
3436} ;
3537
@@ -38,6 +40,7 @@ const ResolvedPublishersCard = ({
3840 ...props
3941} : ResolvedPublishersCardProps ) => {
4042 const logger = useLogger ( ) ;
43+ const data = useLivePriceData ( Cluster . Pythnet , publishers [ 0 ] ?. feedKey ) ;
4144
4245 const [ includeTestFeeds , setIncludeTestFeeds ] = useQueryState (
4346 "includeTestFeeds" ,
@@ -63,11 +66,26 @@ const ResolvedPublishersCard = ({
6366 [ includeTestFeeds , publishers ] ,
6467 ) ;
6568
69+ const publishersWithStatus = useMemo ( ( ) => {
70+ const currentSlot = data . current ?. validSlot ;
71+ const isInactive = ( publishSlot : number , currentSlot : number ) => publishSlot < currentSlot - 100 ;
72+
73+ return publishersFilteredByCluster . map ( ( publisher ) => {
74+ const lastPublishedSlot = data . current ?. priceComponents . find ( ( price ) => price . publisher . toString ( ) === publisher . publisherKey . toString ( ) ) ?. latest . publishSlot ;
75+ const isPublisherInactive = isInactive ( Number ( lastPublishedSlot ?? 0 ) , Number ( currentSlot ?? 0 ) ) ;
76+
77+ return {
78+ ...publisher ,
79+ status : isPublisherInactive ? Status . Down : Status . Live ,
80+ } ;
81+ } ) ;
82+ } , [ publishersFilteredByCluster , data ] ) ;
83+
6684 return (
6785 < PublishersCardImpl
6886 includeTestFeeds = { includeTestFeeds }
6987 updateIncludeTestFeeds = { updateIncludeTestFeeds }
70- publishers = { publishersFilteredByCluster }
88+ publishers = { publishersWithStatus }
7189 { ...props }
7290 />
7391 ) ;
0 commit comments