Skip to content

Commit a690832

Browse files
committed
feat(dev-hub) Requested changes
1 parent 2b80b9c commit a690832

File tree

1 file changed

+32
-36
lines changed
  • apps/developer-hub/src/app/api/search

1 file changed

+32
-36
lines changed

apps/developer-hub/src/app/api/search/route.ts

Lines changed: 32 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -21,45 +21,42 @@ const lazerSchema = z.array(
2121
}),
2222
);
2323

24+
function toAdvancedIndex(
25+
fee: z.infer<typeof hermesSchema>[number],
26+
): AdvancedIndex {
27+
return {
28+
title: `${fee.attributes.symbol} (Core)`,
29+
description: `Price Feed ID: ${fee.id}`,
30+
url: `/price-feeds/core/price-feeds/price-feed-ids?search=${fee.attributes.symbol}`,
31+
id: fee.id,
32+
tag: "price-feed-core",
33+
structuredData: {
34+
headings: [],
35+
contents: [
36+
{ heading: "Symbol", content: fee.attributes.symbol },
37+
{ heading: "ID", content: fee.id },
38+
],
39+
},
40+
};
41+
}
42+
2443
async function getHermesFeeds(): Promise<AdvancedIndex[]> {
2544
try {
26-
const endpoints = [
27-
"https://hermes.pyth.network",
28-
"https://hermes-beta.pyth.network",
29-
];
30-
const responses = await Promise.all(
31-
endpoints.map((url) =>
32-
fetch(`${url}/v2/price_feeds`, {
33-
next: { revalidate: 3600 },
34-
}).then((res) => res.json() as Promise<unknown>),
45+
const results = await Promise.all(
46+
["https://hermes.pyth.network", "https://hermes-beta.pyth.network"].map(
47+
async (url): Promise<AdvancedIndex[]> => {
48+
const hermesResult = await fetch(new URL("/v2/price_feeds", url), {
49+
next: { revalidate: 3600 },
50+
});
51+
const parsed = hermesSchema.safeParse(await hermesResult.json());
52+
return parsed.success
53+
? parsed.data.map((feed) => toAdvancedIndex(feed))
54+
: [];
55+
},
3556
),
3657
);
3758

38-
const allFeeds: AdvancedIndex[] = [];
39-
40-
for (const data of responses) {
41-
const parsed = hermesSchema.safeParse(data);
42-
if (parsed.success) {
43-
for (const feed of parsed.data) {
44-
allFeeds.push({
45-
title: `${feed.attributes.symbol} (Core)`,
46-
description: `Price Feed ID: ${feed.id}`,
47-
url: `/price-feeds/core/price-feeds/price-feed-ids?search=${feed.attributes.symbol}`,
48-
id: feed.id,
49-
tag: "price-feed-core",
50-
structuredData: {
51-
headings: [],
52-
contents: [
53-
{ heading: "Symbol", content: feed.attributes.symbol },
54-
{ heading: "ID", content: feed.id },
55-
],
56-
},
57-
});
58-
}
59-
}
60-
}
61-
62-
return allFeeds;
59+
return results.flat();
6360
} catch (error: unknown) {
6461
throw new Error("Failed to fetch Hermes feeds", { cause: error });
6562
}
@@ -71,8 +68,7 @@ async function getLazerFeeds(): Promise<AdvancedIndex[]> {
7168
"https://history.pyth-lazer.dourolabs.app/history/v1/symbols",
7269
{ next: { revalidate: 3600 } },
7370
);
74-
const data = (await res.json()) as unknown;
75-
const parsed = lazerSchema.safeParse(data);
71+
const parsed = lazerSchema.safeParse(await res.json());
7672

7773
if (!parsed.success) {
7874
return [];

0 commit comments

Comments
 (0)