-
Notifications
You must be signed in to change notification settings - Fork 309
feat(dev-hub) Include feeds in the search #3211
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
5 Skipped Deployments
|
cprussin
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, great work! Minor suggestions to help make the code a bit cleaner but up to you if you care to implement them.
| const endpoints = [ | ||
| "https://hermes.pyth.network", | ||
| "https://hermes-beta.pyth.network", | ||
| ]; | ||
| const responses = await Promise.all( | ||
| endpoints.map((url) => | ||
| fetch(`${url}/v2/price_feeds`, { | ||
| next: { revalidate: 3600 }, | ||
| }).then((res) => res.json() as Promise<unknown>), | ||
| ), | ||
| ); | ||
|
|
||
| const allFeeds: AdvancedIndex[] = []; | ||
|
|
||
| for (const data of responses) { | ||
| const parsed = hermesSchema.safeParse(data); | ||
| if (parsed.success) { | ||
| for (const feed of parsed.data) { | ||
| allFeeds.push({ | ||
| title: `${feed.attributes.symbol} (Core)`, | ||
| description: `Price Feed ID: ${feed.id}`, | ||
| url: `/price-feeds/core/price-feeds/price-feed-ids?search=${feed.attributes.symbol}`, | ||
| id: feed.id, | ||
| tag: "price-feed-core", | ||
| structuredData: { | ||
| headings: [], | ||
| contents: [ | ||
| { heading: "Symbol", content: feed.attributes.symbol }, | ||
| { heading: "ID", content: feed.id }, | ||
| ], | ||
| }, | ||
| }); | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| const endpoints = [ | |
| "https://hermes.pyth.network", | |
| "https://hermes-beta.pyth.network", | |
| ]; | |
| const responses = await Promise.all( | |
| endpoints.map((url) => | |
| fetch(`${url}/v2/price_feeds`, { | |
| next: { revalidate: 3600 }, | |
| }).then((res) => res.json() as Promise<unknown>), | |
| ), | |
| ); | |
| const allFeeds: AdvancedIndex[] = []; | |
| for (const data of responses) { | |
| const parsed = hermesSchema.safeParse(data); | |
| if (parsed.success) { | |
| for (const feed of parsed.data) { | |
| allFeeds.push({ | |
| title: `${feed.attributes.symbol} (Core)`, | |
| description: `Price Feed ID: ${feed.id}`, | |
| url: `/price-feeds/core/price-feeds/price-feed-ids?search=${feed.attributes.symbol}`, | |
| id: feed.id, | |
| tag: "price-feed-core", | |
| structuredData: { | |
| headings: [], | |
| contents: [ | |
| { heading: "Symbol", content: feed.attributes.symbol }, | |
| { heading: "ID", content: feed.id }, | |
| ], | |
| }, | |
| }); | |
| } | |
| } | |
| } | |
| const [hermesFeeds, hermesBetaFeeds] = await Promise.all( | |
| [HERMES_URL, HERMES_BETA_URL].map((url) => { | |
| const hermesResult = await fetch(new URL('/v2/price_feeds', url), { | |
| next: { revalidate: 3600 }, | |
| }); | |
| const parsed = hermesSchema.safeParse(await hermesResult.json()); | |
| return parsed.success | |
| ? parsed.data.map(feed => toAdvancedIndex(feed)) | |
| : undefined | |
| }) | |
| ); | |
| return [...hermesFeeds, ...hermesBetaFeeds]; |
And then just add a toAdvancedIndex: (fee: z.infer<typeof hermesSchema>[number]) => AdvancedFeed function.
Simpler, requires less procedural / mutable object building, and keeps processing close to data fetching.
| const data = (await res.json()) as unknown; | ||
| const parsed = lazerSchema.safeParse(data); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| const data = (await res.json()) as unknown; | |
| const parsed = lazerSchema.safeParse(data); | |
| const parsed = lazerSchema.safeParse(await res.json()); |
Little trick when using zod schemas with fetch that avoids the awkward need to typecast to unknown
Summary
Rationale
How has this been tested?