Skip to content

feat(insights): mostly finish publishers index page #2167

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

Merged
merged 1 commit into from
Dec 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions apps/insights/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@
"@pythnetwork/client": "catalog:",
"@pythnetwork/component-library": "workspace:*",
"@pythnetwork/fonts": "workspace:*",
"@pythnetwork/hermes-client": "workspace:*",
"@pythnetwork/known-publishers": "workspace:*",
"@pythnetwork/next-root": "workspace:*",
"@react-hookz/web": "catalog:",
"@solana/web3.js": "catalog:",
"bs58": "catalog:",
"clsx": "catalog:",
"cryptocurrency-icons": "catalog:",
"dnum": "catalog:",
"framer-motion": "catalog:",
"next": "catalog:",
"next-themes": "catalog:",
Expand All @@ -41,6 +43,7 @@
"react-aria": "catalog:",
"react-aria-components": "catalog:",
"react-dom": "catalog:",
"recharts": "catalog:",
"swr": "catalog:",
"zod": "catalog:"
},
Expand All @@ -49,6 +52,7 @@
"@cprussin/jest-config": "catalog:",
"@cprussin/prettier-config": "catalog:",
"@cprussin/tsconfig": "catalog:",
"@pythnetwork/staking-sdk": "workspace:",
"@svgr/webpack": "catalog:",
"@types/jest": "catalog:",
"@types/node": "catalog:",
Expand Down
13 changes: 8 additions & 5 deletions apps/insights/src/app/global-error.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
"use client";

import { LoggerProvider } from "@pythnetwork/app-logger/provider";
import type { ComponentProps } from "react";

import { Error } from "../components/Error";

const GlobalError = (props: ComponentProps<typeof Error>) => (
<html lang="en" dir="ltr">
<body>
<Error {...props} />
</body>
</html>
<LoggerProvider>
<html lang="en" dir="ltr">
<body>
<Error {...props} />
</body>
</html>
</LoggerProvider>
);
export default GlobalError;
1 change: 0 additions & 1 deletion apps/insights/src/app/publishers/layout.ts

This file was deleted.

1 change: 0 additions & 1 deletion apps/insights/src/app/publishers/loading.ts

This file was deleted.

4 changes: 2 additions & 2 deletions apps/insights/src/app/yesterdays-prices/route.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import type { NextRequest } from "next/server";
import { z } from "zod";

import { client } from "../../clickhouse";
import { client } from "../../services/clickhouse";

export async function GET(req: NextRequest) {
const symbols = req.nextUrl.searchParams.getAll("symbols");
const rows = await client.query({
query:
"select * from insights_yesterdays_prices(symbols={symbols: Array(String)})",
"select symbol, price from insights_yesterdays_prices(symbols={symbols: Array(String)})",
query_params: { symbols },
});
const result = await rows.json();
Expand Down
21 changes: 21 additions & 0 deletions apps/insights/src/components/AsyncValue/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"use client";

import { Skeleton } from "@pythnetwork/component-library/Skeleton";
import { Suspense, use } from "react";

type Props<T> = {
placeholderWidth: number;
valuePromise: Promise<T>;
};

export const AsyncValue = <T,>({
placeholderWidth,
valuePromise,
}: Props<T>) => (
<Suspense fallback={<Skeleton width={placeholderWidth} />}>
<ResolvedValue valuePromise={valuePromise} />
</Suspense>
);

const ResolvedValue = <T,>({ valuePromise }: Pick<Props<T>, "valuePromise">) =>
use(valuePromise);
26 changes: 26 additions & 0 deletions apps/insights/src/components/FormattedTokens/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"use client";

import * as dnum from "dnum";
import { useMemo } from "react";
import { useLocale } from "react-aria";

const DECIMALS = 6;

type Props = {
mode?: "compact" | "wholePart" | "full";
children: bigint;
};

export const FormattedTokens = ({ children, mode = "compact" }: Props) => {
const { locale } = useLocale();
const value = useMemo(
() =>
dnum.format([children, DECIMALS], {
compact: mode === "compact",
locale,
}),
[children, locale, mode],
);

return mode === "wholePart" ? value.split(".")[0] : value;
};
7 changes: 0 additions & 7 deletions apps/insights/src/components/H1/index.module.scss

This file was deleted.

10 changes: 0 additions & 10 deletions apps/insights/src/components/H1/index.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion apps/insights/src/components/LivePrices/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
import { useNumberFormatter } from "react-aria";

import styles from "./index.module.scss";
import { client, subscribe } from "../../pyth";
import { client, subscribe } from "../../services/pyth";

export const SKELETON_WIDTH = 20;

Expand Down
5 changes: 0 additions & 5 deletions apps/insights/src/components/Loading/index.module.scss

This file was deleted.

12 changes: 0 additions & 12 deletions apps/insights/src/components/Loading/index.tsx

This file was deleted.

8 changes: 8 additions & 0 deletions apps/insights/src/components/Overview/index.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,12 @@

.overview {
@include theme.max-width;

.header {
@include theme.h3;

color: theme.color("heading");
font-weight: theme.font-weight("semibold");
margin: theme.spacing(6) 0;
}
}
3 changes: 1 addition & 2 deletions apps/insights/src/components/Overview/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import styles from "./index.module.scss";
import { H1 } from "../H1";

export const Overview = () => (
<div className={styles.overview}>
<H1>Overview</H1>
<h1 className={styles.header}>Overview</h1>
</div>
);

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,49 +6,36 @@
Drawer,
DrawerTrigger,
} from "@pythnetwork/component-library/Drawer";
import { Skeleton } from "@pythnetwork/component-library/Skeleton";
import { StatCard } from "@pythnetwork/component-library/StatCard";
import { Table } from "@pythnetwork/component-library/Table";
import { usePathname } from "next/navigation";
import { createSerializer } from "nuqs";
import { Suspense, use, useMemo } from "react";
import { type ReactNode, useMemo } from "react";
import { useCollator } from "react-aria";

import styles from "./asset-classes-card.module.scss";
import { queryParams, useQuery } from "./use-query";
import { serialize, useQueryParams } from "./query-params";

type Props = {
numFeedsByAssetClassPromise: Promise<Record<string, number>>;
numFeedsByAssetClass: Record<string, number>;
children: ReactNode;
};

export const AssetClassesCard = ({ numFeedsByAssetClassPromise }: Props) => (
<Suspense
fallback={
<StatCard stat={<Skeleton width={10} />} {...sharedStatCardProps} />
}
>
<ResolvedAssetClassesCard
numFeedsByAssetClassPromise={numFeedsByAssetClassPromise}
/>
</Suspense>
);

const ResolvedAssetClassesCard = ({ numFeedsByAssetClassPromise }: Props) => {
const numFeedsByAssetClass = use(numFeedsByAssetClassPromise);
export const AssetClassesDrawer = ({
numFeedsByAssetClass,
children,
}: Props) => {
const numAssetClasses = useMemo(
() => Object.keys(numFeedsByAssetClass).length,
[numFeedsByAssetClass],
);

return (
<DrawerTrigger>
<StatCard stat={numAssetClasses} {...sharedStatCardProps} />
{children}
<Drawer
title={
<div className={styles.drawerTitle}>
<>
<span>Asset Classes</span>
<Badge>{numAssetClasses}</Badge>
</div>
</>
}
>
{({ close }) => (
Expand All @@ -62,10 +49,6 @@
);
};

const sharedStatCardProps = {
header: "Asset Classes",
};

type AssetClassTableProps = {
numFeedsByAssetClass: Record<string, number>;
closeDrawer: () => void;
Expand All @@ -77,29 +60,27 @@
}: AssetClassTableProps) => {
const collator = useCollator();
const pathname = usePathname();
const { updateAssetClass } = useQuery();
const { updateAssetClass, updateSearch } = useQueryParams();
const assetClassRows = useMemo(
() =>
Object.entries(numFeedsByAssetClass)
.sort(([a], [b]) => collator.compare(a, b))
.map(([assetClass, count]) => {
const serialize = createSerializer(queryParams);
return {
id: assetClass,
href: `${pathname}${serialize({ assetClass })}`,
onAction: () => {
closeDrawer();
setTimeout(() => {
updateAssetClass(assetClass);
}, CLOSE_DURATION_IN_MS);
},
data: {
assetClass,
count: <Badge style="outline">{count}</Badge>,
},
};
}),
.map(([assetClass, count]) => ({
id: assetClass,
href: `${pathname}${serialize({ assetClass })}`,
onAction: () => {
closeDrawer();
setTimeout(() => {
updateAssetClass(assetClass);
updateSearch("");
}, CLOSE_DURATION_IN_MS);
},
data: {
assetClass,
count: <Badge style="outline">{count}</Badge>,
},
})),
[numFeedsByAssetClass, collator, closeDrawer, pathname, updateAssetClass],

Check warning on line 83 in apps/insights/src/components/PriceFeeds/asset-classes-drawer.tsx

View workflow job for this annotation

GitHub Actions / test

React Hook useMemo has a missing dependency: 'updateSearch'. Either include it or remove the dependency array
);
return (
<Table
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@use "@pythnetwork/component-library/theme";

.searchBar {
width: 100%;
padding: theme.spacing(3);
display: flex;
flex-flow: row nowrap;
gap: theme.spacing(3);
flex: none;
}

.priceFeeds {
overflow: auto;
flex-grow: 1;
}
Loading
Loading