Skip to content

Commit f0659ce

Browse files
authored
Merge pull request #2206 from pyth-network/cprussin/add-component-table
feat(staking): add price components table
2 parents 956f53e + 3a9c600 commit f0659ce

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+1794
-999
lines changed

apps/insights/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"react-aria-components": "catalog:",
4545
"react-dom": "catalog:",
4646
"recharts": "catalog:",
47+
"superjson": "catalog:",
4748
"swr": "catalog:",
4849
"zod": "catalog:"
4950
},
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import type { Metadata } from "next";
22

3-
import { client } from "../../../services/pyth";
3+
import { getData } from "../../../services/pyth";
44
export { PriceFeedLayout as default } from "../../../components/PriceFeed/layout";
55

66
export const metadata: Metadata = {
77
title: "Price Feeds",
88
};
99

1010
export const generateStaticParams = async () => {
11-
const data = await client.getData();
12-
return data.symbols.map((symbol) => ({ slug: encodeURIComponent(symbol) }));
11+
const data = await getData();
12+
return data.map(({ symbol }) => ({ slug: encodeURIComponent(symbol) }));
1313
};
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
type Props = {
2+
params: Promise<{
3+
componentId: string;
4+
}>;
5+
};
6+
7+
const PriceFeedComponent = async ({ params }: Props) => {
8+
const { componentId } = await params;
9+
return componentId;
10+
};
11+
export default PriceFeedComponent;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { PriceComponents as default } from "../../../../components/PriceFeed/price-components";
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
export { PriceComponents as default } from "../../../../components/PriceFeed/price-components";
1+
// eslint-disable-next-line unicorn/no-null
2+
const Page = () => null;
3+
export default Page;

apps/insights/src/cache.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { unstable_cache } from "next/cache";
2+
import { parse, stringify } from "superjson";
3+
4+
export const cache = <T, P extends unknown[]>(
5+
fn: (...params: P) => Promise<T>,
6+
keys?: Parameters<typeof unstable_cache>[1],
7+
opts?: Parameters<typeof unstable_cache>[2],
8+
) => {
9+
const cachedFn = unstable_cache(
10+
async (params: P): Promise<string> => stringify(await fn(...params)),
11+
keys,
12+
opts,
13+
);
14+
15+
return async (...params: P): Promise<T> => parse(await cachedFn(params));
16+
};

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,31 @@
33
import { Check } from "@phosphor-icons/react/dist/ssr/Check";
44
import { Copy } from "@phosphor-icons/react/dist/ssr/Copy";
55
import { useLogger } from "@pythnetwork/app-logger";
6-
import { Button } from "@pythnetwork/component-library/Button";
6+
import {
7+
type Props as ButtonProps,
8+
Button,
9+
} from "@pythnetwork/component-library/Button";
710
import clsx from "clsx";
8-
import { type ComponentProps, useCallback, useEffect, useState } from "react";
11+
import { type ElementType, useCallback, useEffect, useState } from "react";
912

1013
import styles from "./index.module.scss";
1114

1215
type OwnProps = {
1316
text: string;
1417
};
1518

16-
type Props = Omit<
17-
ComponentProps<typeof Button>,
19+
type Props<T extends ElementType> = Omit<
20+
ButtonProps<T>,
1821
keyof OwnProps | "onPress" | "afterIcon"
1922
> &
2023
OwnProps;
2124

22-
export const CopyButton = ({ text, children, className, ...props }: Props) => {
25+
export const CopyButton = <T extends ElementType>({
26+
text,
27+
children,
28+
className,
29+
...props
30+
}: Props<T>) => {
2331
const [isCopied, setIsCopied] = useState(false);
2432
const logger = useLogger();
2533
const copy = useCallback(() => {
Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import base58 from "bs58";
21
import { useMemo, type ComponentProps } from "react";
32

3+
import { toHex, truncateHex } from "../../hex";
44
import { CopyButton } from "../CopyButton";
55

66
type OwnProps = {
@@ -22,24 +22,11 @@ export const FeedKey = ({ feed, ...props }: Props) => {
2222
() => toHex(feed.product.price_account),
2323
[feed.product.price_account],
2424
);
25-
const truncatedKey = useMemo(
26-
() => toTruncatedHex(feed.product.price_account),
27-
[feed.product.price_account],
28-
);
25+
const truncatedKey = useMemo(() => truncateHex(key), [key]);
2926

3027
return (
3128
<CopyButton text={key} {...props}>
3229
{truncatedKey}
3330
</CopyButton>
3431
);
3532
};
36-
37-
const toHex = (value: string) => toHexString(base58.decode(value));
38-
39-
const toTruncatedHex = (value: string) => {
40-
const hex = toHex(value);
41-
return `${hex.slice(0, 6)}...${hex.slice(-4)}`;
42-
};
43-
44-
const toHexString = (byteArray: Uint8Array) =>
45-
`0x${Array.from(byteArray, (byte) => byte.toString(16).padStart(2, "0")).join("")}`;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"use client";
2+
3+
import { useMemo } from "react";
4+
import { useNumberFormatter } from "react-aria";
5+
6+
type Props = Parameters<typeof useNumberFormatter>[0] & {
7+
value: number;
8+
};
9+
10+
export const FormattedNumber = ({ value, ...args }: Props) => {
11+
const numberFormatter = useNumberFormatter(args);
12+
return useMemo(() => numberFormatter.format(value), [numberFormatter, value]);
13+
};

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export const LayoutTransition = ({ children, ...props }: Props) => {
5353

5454
return (
5555
<AnimatePresence
56-
mode="wait"
56+
mode="popLayout"
5757
initial={false}
5858
onExitComplete={updatePrevSegment}
5959
custom={{ segment, prevSegment: prevSegment.current }}

0 commit comments

Comments
 (0)