Skip to content

Commit 0d17697

Browse files
committed
feat: status updates
1 parent f1c82b6 commit 0d17697

File tree

10 files changed

+53
-53
lines changed

10 files changed

+53
-53
lines changed

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

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

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ export const ResolvedPriceComponentsCard = <
120120
const logger = useLogger();
121121
const collator = useCollator();
122122
const filter = useFilter({ sensitivity: "base", usage: "search" });
123+
123124
const { selectComponent } = usePriceComponentDrawer({
124125
components: priceComponents,
125126
identifiesPublisher,

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import { Cluster } from "../../services/pyth";
99
import type { PriceComponent } from "../PriceComponentsCard";
1010
import { PriceComponentsCard } from "../PriceComponentsCard";
1111
import { PublisherTag } from "../PublisherTag";
12+
import { useLivePriceData } from '../../hooks/use-live-price-data';
13+
import { Status } from '../../status';
1214

1315
type 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
);

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
} from "../../server/pyth";
88
import { getRankingsBySymbol } from "../../services/clickhouse";
99
import { Cluster, ClusterToName } from "../../services/pyth";
10-
import { getStatus } from "../../status";
1110
import { PublisherIcon } from "../PublisherIcon";
1211
import { PublisherTag } from "../PublisherTag";
1312
import { PublishersCard } from "./publishers-card";
@@ -34,7 +33,6 @@ export const Publishers = async ({ params }: Props) => {
3433
const metricsTime = pythnetPublishers.find(
3534
(publisher) => publisher.ranking !== undefined,
3635
)?.ranking?.time;
37-
3836
return feed === undefined ? (
3937
notFound()
4038
) : (
@@ -44,7 +42,7 @@ export const Publishers = async ({ params }: Props) => {
4442
displaySymbol={feed.product.display_symbol}
4543
assetClass={feed.product.asset_type}
4644
publishers={publishers.map(
47-
({ ranking, publisher, status, cluster, knownPublisher }) => ({
45+
({ ranking, publisher, cluster, knownPublisher }) => ({
4846
id: `${publisher}-${ClusterToName[cluster]}`,
4947
feedKey:
5048
cluster === Cluster.Pythnet
@@ -55,7 +53,6 @@ export const Publishers = async ({ params }: Props) => {
5553
deviationScore: ranking?.deviation_score,
5654
stalledScore: ranking?.stalled_score,
5755
cluster,
58-
status,
5956
publisherKey: publisher,
6057
rank: ranking?.final_rank,
6158
firstEvaluation: ranking?.first_ranking_time,
@@ -94,7 +91,6 @@ const getPublishers = async (cluster: Cluster, symbol: string) => {
9491
return {
9592
ranking,
9693
publisher,
97-
status: getStatus(ranking),
9894
cluster,
9995
knownPublisher: lookupPublisher(publisher),
10096
};

apps/insights/src/components/Publisher/get-price-feeds.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { getFeedsForPublisherRequest } from "../../server/pyth";
22
import { getRankingsByPublisher } from "../../services/clickhouse";
33
import { Cluster, ClusterToName } from "../../services/pyth";
4-
import { getStatus } from "../../status";
54

65
export const getPriceFeeds = async (cluster: Cluster, key: string) => {
76
const [feeds, rankings] = await Promise.all([
@@ -17,7 +16,6 @@ export const getPriceFeeds = async (cluster: Cluster, key: string) => {
1716
return {
1817
ranking,
1918
feed,
20-
status: getStatus(ranking),
2119
};
2220
});
2321
};

apps/insights/src/components/Publisher/price-feeds.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import type { PriceComponent } from "../PriceComponentsCard";
88
import { PriceComponentsCard } from "../PriceComponentsCard";
99
import { PriceFeedIcon } from "../PriceFeedIcon";
1010
import { PriceFeedTag } from "../PriceFeedTag";
11+
import { useLivePriceData } from '../../hooks/use-live-price-data';
1112

1213
type Props = {
1314
params: Promise<{
@@ -33,7 +34,7 @@ export const PriceFeeds = async ({ params }: Props) => {
3334
metricsTime={metricsTime}
3435
publisherKey={key}
3536
cluster={parsedCluster}
36-
priceFeeds={feeds.map(({ ranking, feed, status }) => ({
37+
priceFeeds={feeds.map(({ ranking, feed }) => ({
3738
symbol: feed.symbol,
3839
name: (
3940
<PriceFeedTag
@@ -52,7 +53,6 @@ export const PriceFeeds = async ({ params }: Props) => {
5253
uptimeScore: ranking?.uptime_score,
5354
deviationScore: ranking?.deviation_score,
5455
stalledScore: ranking?.stalled_score,
55-
status,
5656
feedKey: feed.product.price_account,
5757
nameAsString: feed.product.display_symbol,
5858
id: feed.product.price_account,
@@ -72,12 +72,12 @@ type PriceFeedsCardProps =
7272
isLoading?: false | undefined;
7373
publisherKey: string;
7474
cluster: Cluster;
75-
priceFeeds: Omit<PriceComponent, "cluster" | "publisherKey">[];
75+
priceFeeds: Omit<PriceComponent, "status" | "cluster" | "publisherKey">[];
7676
metricsTime?: Date | undefined;
7777
};
7878

79-
const PriceFeedsCard = (props: PriceFeedsCardProps) => (
80-
<PriceComponentsCard
79+
const PriceFeedsCard = (props: PriceFeedsCardProps) =>
80+
<PriceComponentsCard
8181
label="Price Feeds"
8282
searchPlaceholder="Feed symbol"
8383
nameLoadingSkeleton={<PriceFeedTag isLoading />}
@@ -103,5 +103,4 @@ const PriceFeedsCard = (props: PriceFeedsCardProps) => (
103103
),
104104
})),
105105
})}
106-
/>
107-
);
106+
/>

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,28 @@ export const Status = ({ status }: { status: StatusType }) => (
1010

1111
const getVariant = (status: StatusType) => {
1212
switch (status) {
13-
case StatusType.Active: {
13+
case StatusType.Live: {
1414
return "success";
1515
}
16-
case StatusType.Inactive: {
16+
case StatusType.Down: {
1717
return "error";
1818
}
19-
case StatusType.Unranked: {
20-
return "disabled";
21-
}
19+
// case StatusType.Unranked: {
20+
// return "disabled";
21+
// }
2222
}
2323
};
2424

2525
const getText = (status: StatusType) => {
2626
switch (status) {
27-
case StatusType.Active: {
28-
return "Active";
29-
}
30-
case StatusType.Inactive: {
31-
return "Inactive";
27+
case StatusType.Live: {
28+
return "Live";
3229
}
33-
case StatusType.Unranked: {
34-
return "Unranked";
30+
case StatusType.Down: {
31+
return "Down";
3532
}
33+
// case StatusType.Unranked: {
34+
// return "Unranked";
35+
// }
3636
}
3737
};

apps/insights/src/hooks/use-live-price-data.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export const LivePriceDataProvider = (props: LivePriceDataProviderProps) => {
3535
return <LivePriceDataContext value={priceData} {...props} />;
3636
};
3737

38-
export const useLivePriceData = (cluster: Cluster, feedKey: string) => {
38+
export const useLivePriceData = (cluster: Cluster, feedKey?: string) => {
3939
const { addSubscription, removeSubscription } =
4040
useLivePriceDataContext()[cluster];
4141

@@ -45,6 +45,9 @@ export const useLivePriceData = (cluster: Cluster, feedKey: string) => {
4545
}>({ current: undefined, prev: undefined });
4646

4747
useEffect(() => {
48+
if(!feedKey) {
49+
return;
50+
}
4851
addSubscription(feedKey, setData);
4952
return () => {
5053
removeSubscription(feedKey, setData);

apps/insights/src/services/clickhouse.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ const _getPublishers = async (cluster: Cluster) =>
3737
publisher,
3838
time,
3939
avg(final_score) AS averageScore,
40-
countIf(uptime_score >= 0.5) AS activeFeeds,
41-
countIf(uptime_score < 0.5) AS inactiveFeeds
4240
FROM publisher_quality_ranking
4341
WHERE cluster = {cluster:String}
4442
AND time = (

apps/insights/src/status.ts

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,22 @@
11
export enum Status {
2-
Unranked,
3-
Inactive,
4-
Active,
2+
Down,
3+
Live,
54
}
65

7-
export const getStatus = (ranking?: { uptime_score: number }): Status => {
8-
if (ranking) {
9-
return ranking.uptime_score >= 0.5 ? Status.Active : Status.Inactive;
10-
} else {
11-
return Status.Unranked;
12-
}
13-
};
14-
156
export const STATUS_NAMES = {
16-
[Status.Active]: "Active",
17-
[Status.Inactive]: "Inactive",
18-
[Status.Unranked]: "Unranked",
7+
[Status.Live]: "Live",
8+
[Status.Down]: "Down",
199
} as const;
2010

2111
export type StatusName = (typeof STATUS_NAMES)[Status];
2212

2313
export const statusNameToStatus = (name: string): Status | undefined => {
2414
switch (name) {
25-
case "Active": {
26-
return Status.Active;
27-
}
28-
case "Inactive": {
29-
return Status.Inactive;
15+
case "Live": {
16+
return Status.Live;
3017
}
31-
case "Unranked": {
32-
return Status.Unranked;
18+
case "Down": {
19+
return Status.Down;
3320
}
3421
default: {
3522
return undefined;

0 commit comments

Comments
 (0)