Skip to content

Commit d90eafc

Browse files
committed
feat: working statuses
1 parent 0d17697 commit d90eafc

File tree

15 files changed

+185
-168
lines changed

15 files changed

+185
-168
lines changed

apps/insights/src/app/api/pyth/get-feeds-for-publisher/[publisher]/route.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ export const GET = async (
3838
const filteredFeeds = feeds.filter((feed) =>
3939
feed.price.priceComponents.some((c) => c.publisher === publisher),
4040
);
41-
console.log({filteredFeeds: filteredFeeds.length, feeds: feeds.length})
4241
return new Response(stringify(filteredFeeds), {
4342
headers: {
4443
"Content-Type": "application/json",

apps/insights/src/components/Explanations/index.tsx

Lines changed: 19 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,25 @@ export const ExplainPermissioned = ({
2424
scoreTime,
2525
}: {
2626
scoreTime?: Date | undefined;
27-
}) => {
28-
return (
29-
<Explain size="xs" title="Permissioned Feeds">
30-
<p>
31-
This is the number of <b>Price Feeds</b> that a <b>Publisher</b> has
32-
permissions to publish to. The publisher is not necessarily pushing data
33-
for all the feeds they have access to, and some feeds may not be live
34-
yet.
35-
</p>
36-
{scoreTime && <EvaluationTime scoreTime={scoreTime} />}
37-
</Explain>
38-
);
39-
};
27+
}) => (
28+
<Explain size="xs" title="Permissioned Feeds">
29+
<p>
30+
This is the number of <b>Price Feeds</b> that a <b>Publisher</b> has
31+
permissions to publish to. The publisher is not necessarily pushing data
32+
for all the feeds they have access to, and some feeds may not be live yet.
33+
</p>
34+
{scoreTime && <EvaluationTime scoreTime={scoreTime} />}
35+
</Explain>
36+
);
37+
38+
export const ExplainUnpermissioned = () => (
39+
<Explain size="xs" title="Unpermissioned Feeds">
40+
<p>
41+
This is the number of <b>Price Feeds</b> that a <b>Publisher</b> does not
42+
have permissions to publish to.
43+
</p>
44+
</Explain>
45+
);
4046

4147
export const ExplainAverage = ({
4248
scoreTime,
@@ -96,31 +102,3 @@ export const EvaluationTime = ({ scoreTime }: { scoreTime: Date }) => {
96102
</p>
97103
);
98104
};
99-
100-
export const ExplainActive = () => (
101-
<Explain size="xs" title="Active Feeds">
102-
<p>
103-
This is the number of feeds which the publisher is permissioned for, where
104-
the publisher{"'"}s feed has 50% or better uptime over the last day.
105-
</p>
106-
<NeitherActiveNorInactiveNote />
107-
</Explain>
108-
);
109-
110-
export const ExplainInactive = () => (
111-
<Explain size="xs" title="Inactive Feeds">
112-
<p>
113-
This is the number of feeds which the publisher is permissioned for, but
114-
for which the publisher{"'"}s feed has less than 50% uptime over the last
115-
day.
116-
</p>
117-
<NeitherActiveNorInactiveNote />
118-
</Explain>
119-
);
120-
121-
const NeitherActiveNorInactiveNote = () => (
122-
<p>
123-
Note that a publisher{"'"}s feed may not be considered either active or
124-
inactive if Pyth has not yet calculated quality rankings for it.
125-
</p>
126-
);

apps/insights/src/components/PriceComponentDrawer/index.tsx

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,10 @@ import { z } from "zod";
3636

3737
import styles from "./index.module.scss";
3838
import { Cluster, ClusterToName } from "../../services/pyth";
39-
import type { Status } from "../../status";
4039
import { LiveConfidence, LivePrice, LiveComponentValue } from "../LivePrices";
4140
import { PriceName } from "../PriceName";
4241
import { Score } from "../Score";
43-
import { Status as StatusComponent } from "../Status";
42+
import { StatusLive } from "../Status";
4443

4544
const LineChart = dynamic(
4645
() => import("recharts").then((recharts) => recharts.LineChart),
@@ -58,7 +57,6 @@ type PriceComponent = {
5857
feedKey: string;
5958
score: number | undefined;
6059
rank: number | undefined;
61-
status: Status;
6260
identifiesPublisher?: boolean | undefined;
6361
firstEvaluation?: Date | undefined;
6462
cluster: Cluster;
@@ -134,16 +132,20 @@ export const usePriceComponentDrawer = ({
134132
<RouterProvider navigate={navigate}>
135133
<HeadingExtra
136134
identifiesPublisher={identifiesPublisher}
137-
status={component.status}
138135
cluster={component.cluster}
139136
publisherKey={component.publisherKey}
140137
symbol={component.symbol}
138+
feedKey={component.feedKey}
141139
/>
142140
</RouterProvider>
143141
),
144142
headingAfter: (
145143
<div className={styles.badges}>
146-
<StatusComponent status={component.status} />
144+
<StatusLive
145+
cluster={component.cluster}
146+
feedKey={component.feedKey}
147+
publisherKey={component.publisherKey}
148+
/>
147149
</div>
148150
),
149151
contents: (
@@ -264,18 +266,22 @@ export const usePriceComponentDrawer = ({
264266
};
265267

266268
type HeadingExtraProps = {
267-
status: Status;
268269
identifiesPublisher?: boolean | undefined;
269270
cluster: Cluster;
270271
publisherKey: string;
271272
symbol: string;
273+
feedKey: string;
272274
};
273275

274-
const HeadingExtra = ({ status, ...props }: HeadingExtraProps) => {
276+
const HeadingExtra = ({ feedKey, ...props }: HeadingExtraProps) => {
275277
return (
276278
<>
277279
<div className={styles.bigScreenBadges}>
278-
<StatusComponent status={status} />
280+
<StatusLive
281+
cluster={props.cluster}
282+
feedKey={feedKey}
283+
publisherKey={props.publisherKey}
284+
/>
279285
</div>
280286
<OpenButton
281287
variant="ghost"

apps/insights/src/components/PriceComponentsCard/index.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export type PriceComponent = {
7575
deviationScore: number | undefined;
7676
stalledScore: number | undefined;
7777
cluster: Cluster;
78-
status: StatusType;
78+
status?: StatusType;
7979
feedKey: string;
8080
publisherKey: string;
8181
name: ReactNode;
@@ -187,6 +187,9 @@ export const ResolvedPriceComponentsCard = <
187187
}
188188

189189
case "status": {
190+
if(a.status === undefined || b.status === undefined) {
191+
return 0;
192+
}
190193
const resultByStatus = b.status - a.status;
191194
const result =
192195
resultByStatus === 0
@@ -267,7 +270,9 @@ export const ResolvedPriceComponentsCard = <
267270
cluster={component.cluster}
268271
/>
269272
),
270-
status: <StatusComponent status={component.status} />,
273+
status: component.status !== undefined && (
274+
<StatusComponent status={component.status} />
275+
),
271276
},
272277
})),
273278
[paginatedItems, props.extraColumns, selectComponent],

apps/insights/src/components/PriceFeed/publishers-card.tsx

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
import { Switch } from "@pythnetwork/component-library/Switch";
44
import { useLogger } from "@pythnetwork/component-library/useLogger";
5-
import { useQueryState, parseAsBoolean } from "nuqs";
5+
import { parseAsBoolean, useQueryState } from "nuqs";
66
import { Suspense, useCallback, useMemo } from "react";
77

8+
import { useLivePriceData } from "../../hooks/use-live-price-data";
89
import { Cluster } from "../../services/pyth";
910
import type { PriceComponent } from "../PriceComponentsCard";
1011
import { PriceComponentsCard } from "../PriceComponentsCard";
1112
import { PublisherTag } from "../PublisherTag";
12-
import { useLivePriceData } from '../../hooks/use-live-price-data';
13-
import { Status } from '../../status';
13+
import { getStatus } from "../Status";
1414

1515
type PublishersCardProps =
1616
| { isLoading: true }
@@ -31,7 +31,10 @@ type ResolvedPublishersCardProps = {
3131
symbol: string;
3232
displaySymbol: string;
3333
assetClass: string;
34-
publishers: Omit<PriceComponent, "status" | "symbol" | "displaySymbol" | "assetClass">[];
34+
publishers: Omit<
35+
PriceComponent,
36+
"status" | "symbol" | "displaySymbol" | "assetClass"
37+
>[];
3538
metricsTime?: Date | undefined;
3639
};
3740

@@ -40,7 +43,7 @@ const ResolvedPublishersCard = ({
4043
...props
4144
}: ResolvedPublishersCardProps) => {
4245
const logger = useLogger();
43-
const data = useLivePriceData(Cluster.Pythnet, publishers[0]?.feedKey);
46+
const data = useLivePriceData(Cluster.Pythnet, publishers[0]?.feedKey);
4447

4548
const [includeTestFeeds, setIncludeTestFeeds] = useQueryState(
4649
"includeTestFeeds",
@@ -67,16 +70,10 @@ const data = useLivePriceData(Cluster.Pythnet, publishers[0]?.feedKey);
6770
);
6871

6972
const publishersWithStatus = useMemo(() => {
70-
const currentSlot = data.current?.validSlot;
71-
const isInactive = (publishSlot: number, currentSlot: number) => publishSlot < currentSlot - 100;
72-
7373
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-
7774
return {
78-
...publisher,
79-
status: isPublisherInactive ? Status.Down : Status.Live,
75+
...publisher,
76+
status: getStatus(data.current, publisher.publisherKey),
8077
};
8178
});
8279
}, [publishersFilteredByCluster, data]);
@@ -93,10 +90,14 @@ const data = useLivePriceData(Cluster.Pythnet, publishers[0]?.feedKey);
9390

9491
type PublishersCardImplProps =
9592
| { isLoading: true }
96-
| (ResolvedPublishersCardProps & {
93+
| (Omit<ResolvedPublishersCardProps, 'publishers'> & {
9794
isLoading?: false | undefined;
9895
includeTestFeeds: boolean;
9996
updateIncludeTestFeeds: (newValue: boolean) => void;
97+
publishers: Omit<
98+
PriceComponent,
99+
"symbol" | "displaySymbol" | "assetClass"
100+
>[];
100101
});
101102

102103
const PublishersCardImpl = (props: PublishersCardImplProps) => (

apps/insights/src/components/Publisher/layout.tsx

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ import { ChartCard } from "../ChartCard";
3030
import { Explain } from "../Explain";
3131
import {
3232
ExplainAverage,
33-
ExplainActive,
34-
ExplainInactive,
33+
ExplainPermissioned,
34+
ExplainUnpermissioned,
3535
} from "../Explanations";
3636
import { FormattedNumber } from "../FormattedNumber";
3737
import { PublisherIcon } from "../PublisherIcon";
@@ -350,8 +350,8 @@ const ActiveFeedsCard = async ({
350350
<ActiveFeedsCardImpl
351351
cluster={cluster}
352352
publisherKey={publisherKey}
353-
activeFeeds={publisher.activeFeeds}
354-
inactiveFeeds={publisher.inactiveFeeds}
353+
permissionedFeeds={publisher.permissionedFeeds}
354+
unpermissionedFeeds={publisher.unpermissionedFeeds}
355355
allFeeds={priceFeeds.length}
356356
/>
357357
) : (
@@ -365,34 +365,34 @@ type ActiveFeedsCardImplProps =
365365
isLoading?: false | undefined;
366366
cluster: Cluster;
367367
publisherKey: string;
368-
activeFeeds: number;
369-
inactiveFeeds: number;
368+
permissionedFeeds: number;
369+
unpermissionedFeeds: number;
370370
allFeeds: number;
371371
};
372372

373373
const ActiveFeedsCardImpl = (props: ActiveFeedsCardImplProps) => (
374374
<StatCard
375375
header1={
376376
<>
377-
Active Feeds
378-
<ExplainActive />
377+
Permissioned
378+
<ExplainPermissioned />
379379
</>
380380
}
381381
header2={
382382
<>
383-
<ExplainInactive />
384-
Inactive Feeds
383+
Unpermissioned
384+
<ExplainUnpermissioned />
385385
</>
386386
}
387387
stat1={
388388
props.isLoading ? (
389389
<Skeleton width={10} />
390390
) : (
391391
<Link
392-
href={`/publishers/${ClusterToName[props.cluster]}/${props.publisherKey}/price-feeds?status=Active`}
392+
href={`/publishers/${ClusterToName[props.cluster]}/${props.publisherKey}/price-feeds?status=Permissioned`}
393393
invert
394394
>
395-
{props.activeFeeds}
395+
{props.permissionedFeeds}
396396
</Link>
397397
)
398398
}
@@ -401,10 +401,10 @@ const ActiveFeedsCardImpl = (props: ActiveFeedsCardImplProps) => (
401401
<Skeleton width={10} />
402402
) : (
403403
<Link
404-
href={`/publishers/${ClusterToName[props.cluster]}/${props.publisherKey}/price-feeds?status=Inactive`}
404+
href={`/publishers/${ClusterToName[props.cluster]}/${props.publisherKey}/price-feeds?status=Unpermissioned`}
405405
invert
406406
>
407-
{props.inactiveFeeds}
407+
{props.unpermissionedFeeds}
408408
</Link>
409409
)
410410
}
@@ -415,7 +415,7 @@ const ActiveFeedsCardImpl = (props: ActiveFeedsCardImplProps) => (
415415
<>
416416
<FormattedNumber
417417
maximumFractionDigits={1}
418-
value={(100 * props.activeFeeds) / props.allFeeds}
418+
value={(100 * props.permissionedFeeds) / props.allFeeds}
419419
/>
420420
%
421421
</>
@@ -428,7 +428,7 @@ const ActiveFeedsCardImpl = (props: ActiveFeedsCardImplProps) => (
428428
<>
429429
<FormattedNumber
430430
maximumFractionDigits={1}
431-
value={(100 * props.inactiveFeeds) / props.allFeeds}
431+
value={(100 * props.unpermissionedFeeds) / props.allFeeds}
432432
/>
433433
%
434434
</>
@@ -437,9 +437,9 @@ const ActiveFeedsCardImpl = (props: ActiveFeedsCardImplProps) => (
437437
>
438438
{!props.isLoading && (
439439
<Meter
440-
value={props.activeFeeds}
440+
value={props.permissionedFeeds}
441441
maxValue={props.allFeeds}
442-
label="Active Feeds"
442+
label="Permissioned Feeds"
443443
/>
444444
)}
445445
</StatCard>

0 commit comments

Comments
 (0)