"use client"; import { Skeleton } from "@pythnetwork/component-library/Skeleton"; import clsx from "clsx"; import { type ComponentProps, type ReactNode, Fragment } from "react"; import styles from "./index.module.scss"; import { usePriceFeeds } from "../../hooks/use-price-feeds"; import { omitKeys } from "../../omit-keys"; type OwnProps = { compact?: boolean | undefined } & ( | { isLoading: true } | { isLoading?: false; symbol: string; } ); type Props = Omit, keyof OwnProps> & OwnProps; export const PriceFeedTag = (props: Props) => { return props.isLoading ? ( ) : ( ); }; const LoadedPriceFeedTag = ({ symbol, ...props }: Props & { isLoading?: false }) => { const feed = usePriceFeeds().get(symbol); if (feed) { const [firstPart, ...rest] = feed.displaySymbol.split("/"); return ( ); } else { throw new NoSuchFeedError(symbol); } }; type OwnImplProps = { compact?: boolean | undefined } & ( | { isLoading: true } | { isLoading?: false; feedName: [string, ...string[]]; icon: ReactNode; description: string; } ); type ImplProps = Omit, keyof OwnImplProps> & OwnImplProps; const PriceFeedTagImpl = ({ className, compact, ...props }: ImplProps) => { return (
{props.isLoading ? ( ) : (
{props.icon}
)}
{props.isLoading ? ( ) : ( <> {props.feedName[0]} {props.feedName.slice(1).map((part, i) => ( / {part} ))} )}
{!compact && (
{props.isLoading ? ( ) : ( props.description.split("/")[0] )}
)}
); }; class NoSuchFeedError extends Error { constructor(symbol: string) { super(`No feed exists named ${symbol}`); this.name = "NoSuchFeedError"; } }