-
Notifications
You must be signed in to change notification settings - Fork 225
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2206 from pyth-network/cprussin/add-component-table
feat(staking): add price components table
- Loading branch information
Showing
64 changed files
with
1,794 additions
and
999 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
import type { Metadata } from "next"; | ||
|
||
import { client } from "../../../services/pyth"; | ||
import { getData } from "../../../services/pyth"; | ||
export { PriceFeedLayout as default } from "../../../components/PriceFeed/layout"; | ||
|
||
export const metadata: Metadata = { | ||
title: "Price Feeds", | ||
}; | ||
|
||
export const generateStaticParams = async () => { | ||
const data = await client.getData(); | ||
return data.symbols.map((symbol) => ({ slug: encodeURIComponent(symbol) })); | ||
const data = await getData(); | ||
return data.map(({ symbol }) => ({ slug: encodeURIComponent(symbol) })); | ||
}; |
11 changes: 11 additions & 0 deletions
11
apps/insights/src/app/price-feeds/[slug]/price-components/[componentId]/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
type Props = { | ||
params: Promise<{ | ||
componentId: string; | ||
}>; | ||
}; | ||
|
||
const PriceFeedComponent = async ({ params }: Props) => { | ||
const { componentId } = await params; | ||
return componentId; | ||
}; | ||
export default PriceFeedComponent; |
1 change: 1 addition & 0 deletions
1
apps/insights/src/app/price-feeds/[slug]/price-components/layout.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { PriceComponents as default } from "../../../../components/PriceFeed/price-components"; |
4 changes: 3 additions & 1 deletion
4
apps/insights/src/app/price-feeds/[slug]/price-components/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
export { PriceComponents as default } from "../../../../components/PriceFeed/price-components"; | ||
// eslint-disable-next-line unicorn/no-null | ||
const Page = () => null; | ||
export default Page; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { unstable_cache } from "next/cache"; | ||
import { parse, stringify } from "superjson"; | ||
|
||
export const cache = <T, P extends unknown[]>( | ||
fn: (...params: P) => Promise<T>, | ||
keys?: Parameters<typeof unstable_cache>[1], | ||
opts?: Parameters<typeof unstable_cache>[2], | ||
) => { | ||
const cachedFn = unstable_cache( | ||
async (params: P): Promise<string> => stringify(await fn(...params)), | ||
keys, | ||
opts, | ||
); | ||
|
||
return async (...params: P): Promise<T> => parse(await cachedFn(params)); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
"use client"; | ||
|
||
import { useMemo } from "react"; | ||
import { useNumberFormatter } from "react-aria"; | ||
|
||
type Props = Parameters<typeof useNumberFormatter>[0] & { | ||
value: number; | ||
}; | ||
|
||
export const FormattedNumber = ({ value, ...args }: Props) => { | ||
const numberFormatter = useNumberFormatter(args); | ||
return useMemo(() => numberFormatter.format(value), [numberFormatter, value]); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
import { ButtonLink } from "@pythnetwork/component-library/Button"; | ||
import { Button } from "@pythnetwork/component-library/Button"; | ||
|
||
export const NotFound = () => ( | ||
<div> | ||
<h1>Not Found</h1> | ||
<p>{"The page you're looking for isn't here"}</p> | ||
<ButtonLink href="/">Go Home</ButtonLink> | ||
<Button href="/">Go Home</Button> | ||
</div> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
apps/insights/src/components/PriceFeed/price-component-drawer.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
"use client"; | ||
|
||
import { Drawer } from "@pythnetwork/component-library/Drawer"; | ||
import { | ||
useSelectedLayoutSegment, | ||
usePathname, | ||
useRouter, | ||
} from "next/navigation"; | ||
import { type ReactNode, useMemo, useCallback } from "react"; | ||
|
||
type Props = { | ||
children: ReactNode; | ||
}; | ||
|
||
export const PriceComponentDrawer = ({ children }: Props) => { | ||
const pathname = usePathname(); | ||
const segment = useSelectedLayoutSegment(); | ||
const prevUrl = useMemo( | ||
() => | ||
segment ? pathname.replace(new RegExp(`/${segment}$`), "") : pathname, | ||
[pathname, segment], | ||
); | ||
const router = useRouter(); | ||
|
||
const onOpenChange = useCallback( | ||
(isOpen: boolean) => { | ||
if (!isOpen) { | ||
router.push(prevUrl); | ||
} | ||
}, | ||
[router, prevUrl], | ||
); | ||
|
||
return ( | ||
<Drawer | ||
title="Hello!" | ||
closeHref={prevUrl} | ||
onOpenChange={onOpenChange} | ||
isOpen={segment !== null} | ||
> | ||
{children} | ||
</Drawer> | ||
); | ||
}; |
Oops, something went wrong.