Skip to content
Closed
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
73 changes: 57 additions & 16 deletions apps/insights/src/components/LivePrices/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,37 @@ import {
useLivePriceComponent,
useLivePriceData,
} from "../../hooks/use-live-price-data";
import { Cluster } from "../../services/pyth";

export const SKELETON_WIDTH = 20;

export const LivePrice = ({
feedKey,
publisherKey,
cluster = Cluster.Pythnet,
}: {
feedKey: string;
publisherKey?: string | undefined;
cluster?: Cluster;
}) =>
publisherKey ? (
<LiveComponentPrice feedKey={feedKey} publisherKey={publisherKey} />
<LiveComponentPrice
feedKey={feedKey}
publisherKey={publisherKey}
cluster={cluster}
/>
) : (
<LiveAggregatePrice feedKey={feedKey} />
<LiveAggregatePrice feedKey={feedKey} cluster={cluster} />
);

const LiveAggregatePrice = ({ feedKey }: { feedKey: string }) => {
const { prev, current } = useLivePriceData(feedKey);
const LiveAggregatePrice = ({
feedKey,
cluster,
}: {
feedKey: string;
cluster: Cluster;
}) => {
const { prev, current } = useLivePriceData(feedKey, cluster);
return (
<Price current={current?.aggregate.price} prev={prev?.aggregate.price} />
);
Expand All @@ -37,11 +50,17 @@ const LiveAggregatePrice = ({ feedKey }: { feedKey: string }) => {
const LiveComponentPrice = ({
feedKey,
publisherKey,
cluster,
}: {
feedKey: string;
publisherKey: string;
cluster: Cluster;
}) => {
const { prev, current } = useLivePriceComponent(feedKey, publisherKey);
const { prev, current } = useLivePriceComponent(
feedKey,
publisherKey,
cluster,
);
return <Price current={current?.latest.price} prev={prev?.latest.price} />;
};

Expand Down Expand Up @@ -69,29 +88,43 @@ const Price = ({
export const LiveConfidence = ({
feedKey,
publisherKey,
cluster = Cluster.Pythnet,
}: {
feedKey: string;
publisherKey?: string | undefined;
cluster?: Cluster;
}) =>
publisherKey === undefined ? (
<LiveAggregateConfidence feedKey={feedKey} />
<LiveAggregateConfidence feedKey={feedKey} cluster={cluster} />
) : (
<LiveComponentConfidence feedKey={feedKey} publisherKey={publisherKey} />
<LiveComponentConfidence
feedKey={feedKey}
publisherKey={publisherKey}
cluster={cluster}
/>
);

const LiveAggregateConfidence = ({ feedKey }: { feedKey: string }) => {
const { current } = useLivePriceData(feedKey);
const LiveAggregateConfidence = ({
feedKey,
cluster,
}: {
feedKey: string;
cluster: Cluster;
}) => {
const { current } = useLivePriceData(feedKey, cluster);
return <Confidence confidence={current?.aggregate.confidence} />;
};

const LiveComponentConfidence = ({
feedKey,
publisherKey,
cluster,
}: {
feedKey: string;
publisherKey: string;
cluster: Cluster;
}) => {
const { current } = useLivePriceComponent(feedKey, publisherKey);
const { current } = useLivePriceComponent(feedKey, publisherKey, cluster);
return <Confidence confidence={current?.latest.confidence} />;
};

Expand All @@ -110,8 +143,14 @@ const Confidence = ({ confidence }: { confidence?: number | undefined }) => {
);
};

export const LiveLastUpdated = ({ feedKey }: { feedKey: string }) => {
const { current } = useLivePriceData(feedKey);
export const LiveLastUpdated = ({
feedKey,
cluster = Cluster.Pythnet,
}: {
feedKey: string;
cluster?: Cluster;
}) => {
const { current } = useLivePriceData(feedKey, cluster);
const formatterWithDate = useDateFormatter({
dateStyle: "short",
timeStyle: "medium",
Expand Down Expand Up @@ -143,8 +182,9 @@ export const LiveValue = <T extends keyof PriceData>({
feedKey,
field,
defaultValue,
}: LiveValueProps<T>) => {
const { current } = useLivePriceData(feedKey);
cluster = Cluster.Pythnet,
}: LiveValueProps<T> & { cluster?: Cluster }) => {
const { current } = useLivePriceData(feedKey, cluster);

return current !== undefined || defaultValue !== undefined ? (
(current?.[field]?.toString() ?? defaultValue)
Expand All @@ -165,8 +205,9 @@ export const LiveComponentValue = <T extends keyof PriceComponent["latest"]>({
field,
publisherKey,
defaultValue,
}: LiveComponentValueProps<T>) => {
const { current } = useLivePriceComponent(feedKey, publisherKey);
cluster = Cluster.Pythnet,
}: LiveComponentValueProps<T> & { cluster?: Cluster }) => {
const { current } = useLivePriceComponent(feedKey, publisherKey, cluster);

return current !== undefined || defaultValue !== undefined ? (
(current?.latest[field].toString() ?? defaultValue)
Expand Down
17 changes: 14 additions & 3 deletions apps/insights/src/components/PriceComponentDrawer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,21 +121,31 @@ export const PriceComponentDrawer = ({
nonInteractive
header="Aggregate Price"
small
stat={<LivePrice feedKey={feedKey} />}
stat={<LivePrice feedKey={feedKey} cluster={Cluster.Pythnet} />}
/>
<StatCard
nonInteractive
header="Publisher Price"
variant="primary"
small
stat={<LivePrice feedKey={feedKey} publisherKey={publisherKey} />}
stat={
<LivePrice
feedKey={feedKey}
publisherKey={publisherKey}
cluster={Cluster.Pythnet}
/>
}
/>
<StatCard
nonInteractive
header="Publisher Confidence"
small
stat={
<LiveConfidence feedKey={feedKey} publisherKey={publisherKey} />
<LiveConfidence
feedKey={feedKey}
publisherKey={publisherKey}
cluster={Cluster.Pythnet}
/>
}
/>
<StatCard
Expand All @@ -147,6 +157,7 @@ export const PriceComponentDrawer = ({
feedKey={feedKey}
publisherKey={publisherKey}
field="publishSlot"
cluster={Cluster.Pythnet}
/>
}
/>
Expand Down
3 changes: 3 additions & 0 deletions apps/insights/src/components/PriceComponentsCard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -212,18 +212,21 @@ export const ResolvedPriceComponentsCard = <T extends PriceComponent>({
feedKey={component.feedKey}
publisherKey={component.publisherKey}
field="publishSlot"
cluster={Cluster.Pythnet}
/>
),
price: (
<LivePrice
feedKey={component.feedKey}
publisherKey={component.publisherKey}
cluster={Cluster.Pythnet}
/>
),
confidence: (
<LiveConfidence
feedKey={component.feedKey}
publisherKey={component.publisherKey}
cluster={Cluster.Pythnet}
/>
),
}),
Expand Down
22 changes: 19 additions & 3 deletions apps/insights/src/components/PriceFeed/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,21 @@ export const PriceFeedLayout = async ({ children, params }: Props) => {
<StatCard
variant="primary"
header="Aggregated Price"
stat={<LivePrice feedKey={feed.product.price_account} />}
stat={
<LivePrice
feedKey={feed.product.price_account}
cluster={Cluster.Pythnet}
/>
}
/>
<StatCard
header="Confidence"
stat={<LiveConfidence feedKey={feed.product.price_account} />}
stat={
<LiveConfidence
feedKey={feed.product.price_account}
cluster={Cluster.Pythnet}
/>
}
corner={
<AlertTrigger>
<Button
Expand Down Expand Up @@ -159,7 +169,12 @@ export const PriceFeedLayout = async ({ children, params }: Props) => {
/>
<StatCard
header="Last Updated"
stat={<LiveLastUpdated feedKey={feed.product.price_account} />}
stat={
<LiveLastUpdated
feedKey={feed.product.price_account}
cluster={Cluster.Pythnet}
/>
}
/>
</section>
</section>
Expand All @@ -177,6 +192,7 @@ export const PriceFeedLayout = async ({ children, params }: Props) => {
<Badge size="xs" style="filled" variant="neutral">
<LiveValue
feedKey={feed.product.price_account}
cluster={Cluster.Pythnet}
field="numComponentPrices"
defaultValue={feed.price.numComponentPrices}
/>
Expand Down
5 changes: 4 additions & 1 deletion apps/insights/src/components/PriceFeeds/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,10 @@ const FeaturedFeedsCard = <T extends ElementType>({
<PriceFeedTag symbol={feed.symbol} />
{showPrices && (
<div className={styles.prices}>
<LivePrice feedKey={feed.product.price_account} />
<LivePrice
feedKey={feed.product.price_account}
cluster={Cluster.Pythnet}
/>
<PriceFeedChangePercent
className={styles.changePercent}
feedKey={feed.product.price_account}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { useFilter, useCollator } from "react-aria";

import { usePriceFeeds } from "../../hooks/use-price-feeds";
import { useQueryParamFilterPagination } from "../../hooks/use-query-param-filter-pagination";
import { Cluster } from "../../services/pyth";
import { AssetClassTag } from "../AssetClassTag";
import { FeedKey } from "../FeedKey";
import {
Expand Down Expand Up @@ -128,12 +129,15 @@ const ResolvedPriceFeedsCard = ({ priceFeeds, ...props }: Props) => {
numPublishers: (
<LiveValue
field="numQuoters"
cluster={Cluster.Pythnet}
feedKey={key}
defaultValue={numQuoters}
/>
),
price: <LivePrice feedKey={key} />,
confidenceInterval: <LiveConfidence feedKey={key} />,
price: <LivePrice feedKey={key} cluster={Cluster.Pythnet} />,
confidenceInterval: (
<LiveConfidence feedKey={key} cluster={Cluster.Pythnet} />
),
priceFeedName: <PriceFeedTag compact symbol={symbol} />,
assetClass: <AssetClassTag symbol={symbol} />,
priceFeedId: <FeedKey size="xs" variant="ghost" feedKey={key} />,
Expand Down
Loading
Loading