Skip to content

Commit 4982280

Browse files
committed
feat(insights): add publishers & price components from pythtest
1 parent c9c3998 commit 4982280

File tree

39 files changed

+662
-393
lines changed

39 files changed

+662
-393
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"use client";
2+
3+
export { Error as default } from "../../../../components/Error";

apps/insights/src/app/publishers/[key]/layout.ts renamed to apps/insights/src/app/publishers/[cluster]/[key]/layout.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { Metadata } from "next";
22

3-
export { PublishersLayout as default } from "../../../components/Publisher/layout";
3+
export { PublishersLayout as default } from "../../../../components/Publisher/layout";
44

55
export const metadata: Metadata = {
66
title: "Publishers",
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export { Performance as default } from "../../../../components/Publisher/performance";
2+
3+
export const dynamic = "error";
4+
export const revalidate = 3600;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export { PriceFeeds as default } from "../../../../../components/Publisher/price-feeds";
2+
3+
export const dynamic = "error";
4+
export const revalidate = 3600;

apps/insights/src/app/publishers/[key]/error.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.

apps/insights/src/app/publishers/[key]/page.ts

Lines changed: 0 additions & 4 deletions
This file was deleted.

apps/insights/src/app/publishers/[key]/price-feeds/page.ts

Lines changed: 0 additions & 4 deletions
This file was deleted.

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

Lines changed: 50 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,32 @@ import {
1111
useLivePriceComponent,
1212
useLivePriceData,
1313
} from "../../hooks/use-live-price-data";
14+
import type { Cluster } from "../../services/pyth";
1415

1516
export const SKELETON_WIDTH = 20;
1617

1718
export const LivePrice = ({
18-
feedKey,
1919
publisherKey,
20+
...props
2021
}: {
2122
feedKey: string;
2223
publisherKey?: string | undefined;
24+
cluster: Cluster;
2325
}) =>
24-
publisherKey ? (
25-
<LiveComponentPrice feedKey={feedKey} publisherKey={publisherKey} />
26+
publisherKey === undefined ? (
27+
<LiveAggregatePrice {...props} />
2628
) : (
27-
<LiveAggregatePrice feedKey={feedKey} />
29+
<LiveComponentPrice {...props} publisherKey={publisherKey} />
2830
);
2931

30-
const LiveAggregatePrice = ({ feedKey }: { feedKey: string }) => {
31-
const { prev, current } = useLivePriceData(feedKey);
32+
const LiveAggregatePrice = ({
33+
feedKey,
34+
cluster,
35+
}: {
36+
feedKey: string;
37+
cluster: Cluster;
38+
}) => {
39+
const { prev, current } = useLivePriceData(cluster, feedKey);
3240
return (
3341
<Price current={current?.aggregate.price} prev={prev?.aggregate.price} />
3442
);
@@ -37,11 +45,17 @@ const LiveAggregatePrice = ({ feedKey }: { feedKey: string }) => {
3745
const LiveComponentPrice = ({
3846
feedKey,
3947
publisherKey,
48+
cluster,
4049
}: {
4150
feedKey: string;
4251
publisherKey: string;
52+
cluster: Cluster;
4353
}) => {
44-
const { prev, current } = useLivePriceComponent(feedKey, publisherKey);
54+
const { prev, current } = useLivePriceComponent(
55+
cluster,
56+
feedKey,
57+
publisherKey,
58+
);
4559
return <Price current={current?.latest.price} prev={prev?.latest.price} />;
4660
};
4761

@@ -67,31 +81,40 @@ const Price = ({
6781
};
6882

6983
export const LiveConfidence = ({
70-
feedKey,
7184
publisherKey,
85+
...props
7286
}: {
7387
feedKey: string;
7488
publisherKey?: string | undefined;
89+
cluster: Cluster;
7590
}) =>
7691
publisherKey === undefined ? (
77-
<LiveAggregateConfidence feedKey={feedKey} />
92+
<LiveAggregateConfidence {...props} />
7893
) : (
79-
<LiveComponentConfidence feedKey={feedKey} publisherKey={publisherKey} />
94+
<LiveComponentConfidence {...props} publisherKey={publisherKey} />
8095
);
8196

82-
const LiveAggregateConfidence = ({ feedKey }: { feedKey: string }) => {
83-
const { current } = useLivePriceData(feedKey);
97+
const LiveAggregateConfidence = ({
98+
feedKey,
99+
cluster,
100+
}: {
101+
feedKey: string;
102+
cluster: Cluster;
103+
}) => {
104+
const { current } = useLivePriceData(cluster, feedKey);
84105
return <Confidence confidence={current?.aggregate.confidence} />;
85106
};
86107

87108
const LiveComponentConfidence = ({
88109
feedKey,
89110
publisherKey,
111+
cluster,
90112
}: {
91113
feedKey: string;
92114
publisherKey: string;
115+
cluster: Cluster;
93116
}) => {
94-
const { current } = useLivePriceComponent(feedKey, publisherKey);
117+
const { current } = useLivePriceComponent(cluster, feedKey, publisherKey);
95118
return <Confidence confidence={current?.latest.confidence} />;
96119
};
97120

@@ -110,8 +133,14 @@ const Confidence = ({ confidence }: { confidence?: number | undefined }) => {
110133
);
111134
};
112135

113-
export const LiveLastUpdated = ({ feedKey }: { feedKey: string }) => {
114-
const { current } = useLivePriceData(feedKey);
136+
export const LiveLastUpdated = ({
137+
feedKey,
138+
cluster,
139+
}: {
140+
feedKey: string;
141+
cluster: Cluster;
142+
}) => {
143+
const { current } = useLivePriceData(cluster, feedKey);
115144
const formatterWithDate = useDateFormatter({
116145
dateStyle: "short",
117146
timeStyle: "medium",
@@ -137,14 +166,16 @@ type LiveValueProps<T extends keyof PriceData> = {
137166
field: T;
138167
feedKey: string;
139168
defaultValue?: ReactNode | undefined;
169+
cluster: Cluster;
140170
};
141171

142172
export const LiveValue = <T extends keyof PriceData>({
143173
feedKey,
144174
field,
145175
defaultValue,
176+
cluster,
146177
}: LiveValueProps<T>) => {
147-
const { current } = useLivePriceData(feedKey);
178+
const { current } = useLivePriceData(cluster, feedKey);
148179

149180
return current !== undefined || defaultValue !== undefined ? (
150181
(current?.[field]?.toString() ?? defaultValue)
@@ -158,15 +189,17 @@ type LiveComponentValueProps<T extends keyof PriceComponent["latest"]> = {
158189
feedKey: string;
159190
publisherKey: string;
160191
defaultValue?: ReactNode | undefined;
192+
cluster: Cluster;
161193
};
162194

163195
export const LiveComponentValue = <T extends keyof PriceComponent["latest"]>({
164196
feedKey,
165197
field,
166198
publisherKey,
167199
defaultValue,
200+
cluster,
168201
}: LiveComponentValueProps<T>) => {
169-
const { current } = useLivePriceComponent(feedKey, publisherKey);
202+
const { current } = useLivePriceComponent(cluster, feedKey, publisherKey);
170203

171204
return current !== undefined || defaultValue !== undefined ? (
172205
(current?.latest[field].toString() ?? defaultValue)

apps/insights/src/components/PriceComponentDrawer/index.module.scss

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
@use "@pythnetwork/component-library/theme";
22

33
.priceComponentDrawer {
4-
display: grid;
5-
grid-template-rows: repeat(2, max-content);
6-
grid-template-columns: 100%;
7-
gap: theme.spacing(10);
4+
.testFeedMessage {
5+
grid-column: span 2 / span 2;
6+
margin-bottom: theme.spacing(10);
7+
}
88

99
.stats {
1010
display: grid;
1111
grid-template-columns: repeat(3, 1fr);
1212
grid-template-rows: repeat(2, 1fr);
1313
gap: theme.spacing(4);
14+
margin-bottom: theme.spacing(10);
1415
}
1516

1617
.spinner {

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

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import { Flask } from "@phosphor-icons/react/dist/ssr/Flask";
12
import { Button } from "@pythnetwork/component-library/Button";
23
import { Card } from "@pythnetwork/component-library/Card";
34
import { Drawer } from "@pythnetwork/component-library/Drawer";
5+
import { InfoBox } from "@pythnetwork/component-library/InfoBox";
46
import { Select } from "@pythnetwork/component-library/Select";
57
import { Spinner } from "@pythnetwork/component-library/Spinner";
68
import { StatCard } from "@pythnetwork/component-library/StatCard";
@@ -45,28 +47,32 @@ type Props = {
4547
headingExtra?: ReactNode | undefined;
4648
publisherKey: string;
4749
symbol: string;
50+
displaySymbol: string;
4851
feedKey: string;
4952
score: number | undefined;
5053
rank: number | undefined;
5154
status: Status;
52-
navigateButtonText: string;
55+
identifiesPublisher?: boolean | undefined;
5356
navigateHref: string;
5457
firstEvaluation: Date;
58+
cluster: Cluster;
5559
};
5660

5761
export const PriceComponentDrawer = ({
5862
publisherKey,
5963
onClose,
6064
symbol,
65+
displaySymbol,
6166
feedKey,
6267
score,
6368
rank,
6469
title,
6570
status,
6671
headingExtra,
67-
navigateButtonText,
6872
navigateHref,
6973
firstEvaluation,
74+
cluster,
75+
identifiesPublisher,
7076
}: Props) => {
7177
const goToPriceFeedPageOnClose = useRef<boolean>(false);
7278
const [isFeedDrawerOpen, setIsFeedDrawerOpen] = useState(true);
@@ -93,7 +99,7 @@ export const PriceComponentDrawer = ({
9399
const { selectedPeriod, setSelectedPeriod, evaluationPeriods } =
94100
useEvaluationPeriods(firstEvaluation);
95101
const scoreHistoryState = useData(
96-
[Cluster.Pythnet, publisherKey, symbol, selectedPeriod],
102+
[cluster, publisherKey, symbol, selectedPeriod],
97103
getScoreHistory,
98104
);
99105

@@ -108,34 +114,54 @@ export const PriceComponentDrawer = ({
108114
<StatusComponent status={status} />
109115
<RouterProvider navigate={handleOpenFeed}>
110116
<Button size="sm" variant="outline" href={navigateHref}>
111-
{navigateButtonText}
117+
Open {identifiesPublisher ? "Publisher" : "Feed"}
112118
</Button>
113119
</RouterProvider>
114120
</>
115121
}
116122
isOpen={isFeedDrawerOpen}
117123
bodyClassName={styles.priceComponentDrawer}
118124
>
125+
{cluster === Cluster.PythtestConformance && (
126+
<InfoBox
127+
icon={<Flask />}
128+
header={`This publisher is in test`}
129+
className={styles.testFeedMessage}
130+
>
131+
This is a test publisher. Its prices are not included in the Pyth
132+
aggregate price for {displaySymbol}.
133+
</InfoBox>
134+
)}
119135
<div className={styles.stats}>
120136
<StatCard
121137
nonInteractive
122138
header="Aggregate Price"
123139
small
124-
stat={<LivePrice feedKey={feedKey} />}
140+
stat={<LivePrice feedKey={feedKey} cluster={cluster} />}
125141
/>
126142
<StatCard
127143
nonInteractive
128144
header="Publisher Price"
129145
variant="primary"
130146
small
131-
stat={<LivePrice feedKey={feedKey} publisherKey={publisherKey} />}
147+
stat={
148+
<LivePrice
149+
feedKey={feedKey}
150+
publisherKey={publisherKey}
151+
cluster={cluster}
152+
/>
153+
}
132154
/>
133155
<StatCard
134156
nonInteractive
135157
header="Publisher Confidence"
136158
small
137159
stat={
138-
<LiveConfidence feedKey={feedKey} publisherKey={publisherKey} />
160+
<LiveConfidence
161+
feedKey={feedKey}
162+
publisherKey={publisherKey}
163+
cluster={cluster}
164+
/>
139165
}
140166
/>
141167
<StatCard
@@ -147,6 +173,7 @@ export const PriceComponentDrawer = ({
147173
feedKey={feedKey}
148174
publisherKey={publisherKey}
149175
field="publishSlot"
176+
cluster={cluster}
150177
/>
151178
}
152179
/>

0 commit comments

Comments
 (0)