Skip to content

Commit 9e29e54

Browse files
committed
refactor: cleanup
1 parent 8daffbb commit 9e29e54

File tree

14 files changed

+33
-35
lines changed

14 files changed

+33
-35
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
import { NextResponse } from "next/server";
22
import { stringify } from "superjson";
33

4-
import { getFeeds } from '../../../../../server/pyth/get-feeds';
4+
import { getFeedsCached } from '../../../../../server/pyth/get-feeds';
55
import { Cluster } from "../../../../../services/pyth";
66

77
export const GET = async (request: Request, { params }: { params: Promise<{ publisher: string }> }) => {
88
const { publisher } = await params;
9-
// get cluster from query params
109
const { searchParams } = new URL(request.url);
1110
const cluster = Number.parseInt(searchParams.get("cluster") ?? Cluster.Pythnet.toString()) as Cluster;
11+
1212
// check if cluster is valid
1313
if (cluster && !Object.values(Cluster).includes(cluster)) {
1414
return NextResponse.json({ error: "Invalid cluster" }, { status: 400 });
1515
}
16+
1617
if (!publisher) {
1718
return NextResponse.json({ error: "Publisher is required" }, { status: 400 });
1819
}
19-
const feeds = await getFeeds(cluster);
20+
21+
const feeds = await getFeedsCached(cluster);
22+
2023
const filteredFeeds = feeds.filter((feed) => feed.price.priceComponents.some((c) => c.publisher === publisher));
2124

2225
return new Response(stringify(filteredFeeds), {

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,15 @@ export const GET = async (request: Request, { params }: { params: Promise<{ symb
88
const { symbol } = await params;
99
const { searchParams } = new URL(request.url);
1010
const cluster = Number.parseInt(searchParams.get("cluster") ?? Cluster.Pythnet.toString()) as Cluster;
11+
1112
// check if cluster is valid
1213
if (cluster && !Object.values(Cluster).includes(cluster)) {
1314
return NextResponse.json({ error: "Invalid cluster" }, { status: 400 });
1415
}
16+
1517
const feeds = await getFeedsCached(cluster);
1618
const feed = feeds.find((feed) => feed.symbol === symbol);
19+
1720
return new Response(stringify(feed), {
1821
headers: {
1922
'Content-Type': 'application/json',

apps/insights/src/app/api/pyth/get-feeds/route.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,21 @@ export const GET = async (request: Request) => {
1010
const { searchParams } = new URL(request.url);
1111
const excludePriceComponents = searchParams.get("excludePriceComponents") === "true";
1212
const cluster = Number.parseInt(searchParams.get("cluster") ?? Cluster.Pythnet.toString()) as Cluster;
13+
1314
// check if cluster is valid
1415
if (cluster && !Object.values(Cluster).includes(cluster)) {
1516
return NextResponse.json({ error: "Invalid cluster" }, { status: 400 });
1617
}
1718

1819
let feeds = await getFeedsCached(cluster) as Omit<z.infer<typeof priceFeedsSchema>[number], 'price'>[];
20+
1921
if(excludePriceComponents) {
2022
feeds = feeds.map((feed) => ({
2123
...feed,
2224
price: undefined,
2325
}));
2426
}
27+
2528
return new Response(stringify(feeds), {
2629
headers: {
2730
'Content-Type': 'application/json',

apps/insights/src/app/api/pyth/get-publishers/[symbol]/route.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,17 @@ export const GET = async (request: Request, { params }: { params: Promise<{ symb
88
// get cluster from query params
99
const { searchParams } = new URL(request.url);
1010
const cluster = Number.parseInt(searchParams.get("cluster") ?? Cluster.Pythnet.toString()) as Cluster;
11+
1112
// check if cluster is valid
1213
if (cluster && !Object.values(Cluster).includes(cluster)) {
1314
return NextResponse.json({ error: "Invalid cluster" }, { status: 400 });
1415
}
16+
1517
if (!symbol) {
1618
return NextResponse.json({ error: "Symbol is required" }, { status: 400 });
1719
}
20+
1821
const map = await getPublishersForCluster(cluster);
22+
1923
return NextResponse.json(map[symbol] ?? []);
2024
};

apps/insights/src/app/price-feeds/[slug]/layout.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { Metadata } from "next";
22
import { notFound } from "next/navigation";
33
import type { ReactNode } from "react";
44

5-
import { getFeeds } from "../../../server/pyth/get-feeds";
5+
import { getFeedsCached } from "../../../server/pyth/get-feeds";
66
import { Cluster } from "../../../services/pyth";
77

88
export { PriceFeedLayout as default } from "../../../components/PriceFeed/layout";
@@ -20,7 +20,7 @@ export const generateMetadata = async ({
2020
}: Props): Promise<Metadata> => {
2121
const [{ slug }, feeds] = await Promise.all([
2222
params,
23-
getFeeds(Cluster.Pythnet),
23+
getFeedsCached(Cluster.Pythnet),
2424
]);
2525
const symbol = decodeURIComponent(slug);
2626
const feed = feeds.find((item) => item.symbol === symbol);

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import PriceFeedsLight from "./price-feeds-light.svg";
99
import PublishersDark from "./publishers-dark.svg";
1010
import PublishersLight from "./publishers-light.svg";
1111
import { TabList } from "./tab-list";
12-
import { getFeeds } from "../../server/pyth/get-feeds";
12+
import { getFeedsCached } from "../../server/pyth/get-feeds";
1313
import { Cluster } from "../../services/pyth";
1414
import {
1515
totalVolumeTraded,
@@ -24,10 +24,9 @@ import { FormattedDate } from "../FormattedDate";
2424
import { FormattedNumber } from "../FormattedNumber";
2525

2626
export const Overview = async () => {
27-
// eslint-disable-next-line no-console
28-
console.log('overview');
29-
const priceFeeds = await getFeeds(Cluster.Pythnet);
27+
const priceFeeds = await getFeedsCached(Cluster.Pythnet);
3028
const today = new Date();
29+
3130
const feedCounts = [
3231
...activeFeeds.map(({ date, numFeeds }) => ({
3332
x: date,
@@ -40,6 +39,7 @@ export const Overview = async () => {
4039
y: priceFeeds.length,
4140
},
4241
];
42+
4343
return (
4444
<div className={styles.overview}>
4545
<h1 className={styles.header}>Overview</h1>

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ export const Publishers = async ({ params }: Props) => {
2323
const { slug } = await params;
2424
const symbol = decodeURIComponent(slug);
2525

26-
const start = Date.now();
2726
const [
2827
feed,
2928
testFeed,
@@ -35,9 +34,7 @@ export const Publishers = async ({ params }: Props) => {
3534
getPublishers(Cluster.Pythnet, symbol),
3635
getPublishers(Cluster.PythtestConformance, symbol),
3736
]);
38-
const end = Date.now();
39-
// eslint-disable-next-line no-console
40-
console.info(`Publishers took ${(end - start).toString()}ms`);
37+
4138
const publishers = [...pythnetPublishers, ...pythtestConformancePublishers];
4239
const metricsTime = pythnetPublishers.find(
4340
(publisher) => publisher.ranking !== undefined,

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { AssetClassTable } from "./asset-class-table";
1919
import { ComingSoonList } from "./coming-soon-list";
2020
import styles from "./index.module.scss";
2121
import { PriceFeedsCard } from "./price-feeds-card";
22-
import { getFeeds } from "../../server/pyth/get-feeds";
22+
import { getFeedsCached } from "../../server/pyth/get-feeds";
2323
import { Cluster } from "../../services/pyth";
2424
import { priceFeeds as priceFeedsStaticConfig } from "../../static-data/price-feeds";
2525
import { activeChains } from "../../static-data/stats";
@@ -290,9 +290,7 @@ const FeaturedFeedsCard = <T extends ElementType>({
290290
);
291291

292292
const getPriceFeeds = async () => {
293-
// eslint-disable-next-line no-console
294-
console.log('getPriceFeeds');
295-
const priceFeeds = await getFeeds(Cluster.Pythnet);
293+
const priceFeeds = await getFeedsCached(Cluster.Pythnet);
296294
const activeFeeds = priceFeeds.filter((feed) => isActive(feed));
297295
const comingSoon = priceFeeds.filter((feed) => !isActive(feed));
298296
return { activeFeeds, comingSoon };

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
} from "../../config/server";
1212
import { LivePriceDataProvider } from "../../hooks/use-live-price-data";
1313
import { getPublishersCached } from '../../server/clickhouse';
14-
import { getFeeds } from '../../server/pyth/get-feeds';
14+
import { getFeedsCached } from '../../server/pyth/get-feeds';
1515
import { Cluster } from "../../services/pyth";
1616
import { PriceFeedIcon } from "../PriceFeedIcon";
1717
import { PublisherIcon } from "../PublisherIcon";
@@ -75,9 +75,7 @@ const getPublishersForSearchDialog = async (cluster: Cluster) => {
7575
};
7676

7777
const getFeedsForSearchDialog = async (cluster: Cluster) => {
78-
// eslint-disable-next-line no-console
79-
console.log('getFeedsForSearchDialog');
80-
const feeds = await getFeeds(cluster);
78+
const feeds = await getFeedsCached(cluster);
8179

8280
return feeds.map((feed) => ({
8381
symbol: feed.symbol,

apps/insights/src/config/server.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Disable the following rule because this file is the intended place to declare
22
// and load all env variables.
3-
/* eslint-disable n/no-process-env */
3+
/* eslint-disable n/no-process-env, @typescript-eslint/no-non-null-assertion, turbo/no-undeclared-env-vars */
44

55
import { Redis } from 'ioredis';
66
import "server-only";
@@ -83,15 +83,13 @@ export function getRedis(): Redis {
8383

8484
export const PUBLIC_URL = (() => {
8585
if (IS_PRODUCTION_SERVER) {
86-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion, turbo/no-undeclared-env-vars
86+
8787
return `https://${process.env.VERCEL_PROJECT_PRODUCTION_URL!}`;
8888
} else if (IS_PREVIEW_SERVER) {
89-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion, turbo/no-undeclared-env-vars
9089
return `https://${process.env.VERCEL_URL!}`;
9190
} else {
9291
return `http://localhost:3003`;
9392
}
9493
})();
9594

96-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion, turbo/no-undeclared-env-vars
9795
export const VERCEL_AUTOMATION_BYPASS_SECRET = process.env.VERCEL_AUTOMATION_BYPASS_SECRET!;

0 commit comments

Comments
 (0)