Skip to content

Commit 4b21b82

Browse files
committed
fix: types
1 parent 742cee6 commit 4b21b82

File tree

3 files changed

+26
-14
lines changed

3 files changed

+26
-14
lines changed

apps/insights/src/components/ConformanceReport/conformance-report.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@ import type { Interval } from "./types";
1313
import { INTERVALS } from "./types";
1414
import { useDownloadReportForFeed } from "./use-download-report-for-feed";
1515
import { useDownloadReportForPublisher } from "./use-download-report-for-publisher";
16+
import { CLUSTER_NAMES } from "../../services/pyth";
1617

1718
type ConformanceReportProps =
1819
| { isLoading: true }
1920
| {
2021
isLoading?: false | undefined;
2122
symbol?: string;
22-
cluster: "pythnet" | "pythtest-conformance";
23+
cluster: (typeof CLUSTER_NAMES)[number];
2324
publisher?: string;
2425
};
2526

@@ -31,6 +32,9 @@ const ConformanceReport = (props: ConformanceReportProps) => {
3132
const downloadReportForPublisher = useDownloadReportForPublisher();
3233
const logger = useLogger();
3334

35+
/**
36+
* Download the conformance report for the given symbol or publisher
37+
*/
3438
const downloadReport = async () => {
3539
if (props.isLoading) {
3640
return;

apps/insights/src/components/ConformanceReport/use-download-report-for-feed.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { useCallback } from "react";
22

33
import { WEB_API_BASE_URL } from "./constants";
44
import { useDownloadBlob } from "../../hooks/use-download-blob";
5+
import { CLUSTER_NAMES } from "../../services/pyth";
56

67
const PYTHTEST_CONFORMANCE_REFERENCE_PUBLISHER =
78
"HUZu4xMSHbxTWbkXR6jkGdjvDPJLjrpSNXSoUFBRgjWs";
@@ -19,7 +20,7 @@ export const useDownloadReportForFeed = () => {
1920
symbol: string;
2021
publisher: string;
2122
timeframe: string;
22-
cluster: string;
23+
cluster: (typeof CLUSTER_NAMES)[number];
2324
}) => {
2425
const url = new URL("/metrics/conformance", WEB_API_BASE_URL);
2526
url.searchParams.set("symbol", symbol);

apps/insights/src/components/ConformanceReport/use-download-report-for-publisher.tsx

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { WEB_API_BASE_URL } from "./constants";
1616
import type { Interval } from "./types";
1717
import { useDownloadBlob } from "../../hooks/use-download-blob";
1818
import { priceFeedsSchema } from "../../schemas/pyth";
19+
import { CLUSTER_NAMES } from "../../services/pyth";
1920

2021
// If interval is 'daily', set interval_days=1
2122
// If interval is 'weekly', get the previous Sunday and set interval_days=7
@@ -62,7 +63,7 @@ const getRankingDateAndIntervalDays = (date: Date, interval: Interval) => {
6263
}
6364
};
6465

65-
const getFeeds = async (cluster: string) => {
66+
const getFeeds = async (cluster: (typeof CLUSTER_NAMES)[number]) => {
6667
const url = new URL(`/api/pyth/get-feeds`, globalThis.window.origin);
6768
url.searchParams.set("cluster", cluster);
6869
const data = await fetch(url);
@@ -89,7 +90,7 @@ const PublisherQuantityScoreSchema = z.object({
8990
});
9091

9192
const fetchRankingData = async (
92-
cluster: string,
93+
cluster: (typeof CLUSTER_NAMES)[number],
9394
publisher: string,
9495
interval: Interval,
9596
) => {
@@ -140,6 +141,14 @@ const csvHeaders = [
140141
"final_score",
141142
];
142143

144+
const symbolsSort = (a: string, b: string) => {
145+
const aSplit = a.split(".");
146+
const bSplit = b.split(".");
147+
const aLast = aSplit.at(-1);
148+
const bLast = bSplit.at(-1);
149+
return aLast?.localeCompare(bLast ?? "") ?? 0;
150+
};
151+
143152
export const useDownloadReportForPublisher = () => {
144153
const download = useDownloadBlob();
145154

@@ -150,7 +159,7 @@ export const useDownloadReportForPublisher = () => {
150159
interval,
151160
}: {
152161
publisher: string;
153-
cluster: string;
162+
cluster: (typeof CLUSTER_NAMES)[number];
154163
interval: Interval;
155164
}) => {
156165
const [rankingData, allFeeds] = await Promise.all([
@@ -176,11 +185,13 @@ export const useDownloadReportForPublisher = () => {
176185
};
177186
};
178187

179-
const activePriceFeeds = rankingData.quantityRankData[0]?.symbols ?? [];
188+
const activePriceFeeds =
189+
rankingData.quantityRankData[0]?.symbols.sort(symbolsSort) ?? [];
180190

181191
const allSymbols = allFeeds
182-
.flatMap((feed) => feed.symbol)
192+
.map((feed) => feed.symbol)
183193
.filter((symbol: string) => symbol && !symbol.includes("NULL"));
194+
184195
// filter out inactive price feeds
185196
const inactivePriceFeeds = allSymbols
186197
.filter((symbol) => {
@@ -191,13 +202,8 @@ export const useDownloadReportForPublisher = () => {
191202
meta.price.numComponentPrices > 0
192203
);
193204
})
194-
.sort((a, b) => {
195-
const aSplit = a.split(".");
196-
const bSplit = b.split(".");
197-
const aLast = aSplit.at(-1);
198-
const bLast = bSplit.at(-1);
199-
return aLast?.localeCompare(bLast ?? "") ?? 0;
200-
});
205+
.sort(symbolsSort);
206+
201207
const data = [
202208
...activePriceFeeds.map((feed) => ({
203209
...getPriceFeedData(feed),
@@ -212,6 +218,7 @@ export const useDownloadReportForPublisher = () => {
212218
: "unpermissioned",
213219
})),
214220
];
221+
215222
const csv = stringifyCsv(data, { header: true, columns: csvHeaders });
216223
const blob = new Blob([csv], { type: "text/csv;charset=utf-8" });
217224
download(blob, `${publisher}-${cluster}-price-feeds.csv`);

0 commit comments

Comments
 (0)