Skip to content

fix(insights): ensure crypto icons are only used for cryptos #2394

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
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
19 changes: 13 additions & 6 deletions apps/insights/src/components/PriceFeedIcon/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { ComponentProps } from "react";
import { icons } from "./icons";

type OwnProps = {
assetClass: string;
symbol: string;
};
type Props = Omit<
Expand All @@ -12,12 +13,18 @@ type Props = Omit<
> &
OwnProps;

export const PriceFeedIcon = ({ symbol, ...props }: Props) => {
const firstPart = symbol.split("/")[0];
const Icon =
firstPart && firstPart in icons
export const PriceFeedIcon = ({ assetClass, symbol, ...props }: Props) => {
const Icon = getIcon(assetClass, symbol);
return <Icon width="100%" height="100%" viewBox="0 0 32 32" {...props} />;
};

const getIcon = (assetClass: string, symbol: string) => {
if (assetClass === "Crypto") {
const firstPart = symbol.split("/")[0];
return firstPart && firstPart in icons
? icons[firstPart as keyof typeof icons]
: Generic;

return <Icon width="100%" height="100%" viewBox="0 0 32 32" {...props} />;
} else {
return Generic;
}
};
5 changes: 0 additions & 5 deletions apps/insights/src/components/PriceFeeds/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import {
YesterdaysPricesProvider,
PriceFeedChangePercent,
} from "../PriceFeedChangePercent";
import { PriceFeedIcon } from "../PriceFeedIcon";
import { PriceFeedTag } from "../PriceFeedTag";

const PRICE_FEEDS_ANCHOR = "priceFeeds";
Expand Down Expand Up @@ -127,10 +126,6 @@ export const PriceFeeds = async () => {
id={PRICE_FEEDS_ANCHOR}
priceFeeds={priceFeeds.activeFeeds.map((feed) => ({
symbol: feed.symbol,
icon: <PriceFeedIcon symbol={feed.product.display_symbol} />,
id: feed.product.price_account,
displaySymbol: feed.product.display_symbol,
assetClass: feed.product.asset_type,
exponent: feed.price.exponent,
numQuoters: feed.price.numQuoters,
}))}
Expand Down
7 changes: 3 additions & 4 deletions apps/insights/src/components/PriceName/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@ const getLabels = (assetClass?: string | undefined) => {
if (assetClass === undefined) {
return LABELS.ambiguous;
} else {
const lowercaseAssetClass = assetClass.toLowerCase();
return lowercaseAssetClass in LABELS
? LABELS[lowercaseAssetClass as keyof typeof LABELS]
return assetClass in LABELS
? LABELS[assetClass as keyof typeof LABELS]
: LABELS.default;
}
};

const LABELS = {
rates: {
Rates: {
plural: {
upcase: "YIELDS",
title: "Yields",
Expand Down
6 changes: 0 additions & 6 deletions apps/insights/src/components/Publisher/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import { FormattedDate } from "../FormattedDate";
import { FormattedNumber } from "../FormattedNumber";
import { FormattedTokens } from "../FormattedTokens";
import { Meter } from "../Meter";
import { PriceFeedIcon } from "../PriceFeedIcon";
import { PublisherIcon } from "../PublisherIcon";
import { PublisherKey } from "../PublisherKey";
import { PublisherTag } from "../PublisherTag";
Expand Down Expand Up @@ -90,14 +89,9 @@ export const PublishersLayout = async ({ children, params }: Props) => {
publisherKey={key}
priceFeeds={priceFeeds.map(({ feed, ranking, status }) => ({
symbol: feed.symbol,
displaySymbol: feed.product.display_symbol,
description: feed.product.description,
icon: <PriceFeedIcon symbol={feed.product.display_symbol} />,
feedKey: feed.product.price_account,
score: ranking?.final_score,
rank: ranking?.final_rank,
firstEvaluation: ranking?.first_ranking_time,
assetClass: feed.product.asset_type,
status,
}))}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import { useLogger } from "@pythnetwork/app-logger";
import { parseAsString, useQueryState } from "nuqs";
import {
type ReactNode,
type ComponentProps,
Suspense,
createContext,
Expand All @@ -12,6 +11,7 @@ import {
use,
} from "react";

import { usePriceFeeds } from "../../hooks/use-price-feeds";
import type { Cluster } from "../../services/pyth";
import type { Status } from "../../status";
import { PriceComponentDrawer } from "../PriceComponentDrawer";
Expand All @@ -32,15 +32,10 @@ type PriceFeedDrawerProviderProps = Omit<

type PriceFeed = {
symbol: string;
displaySymbol: string;
description: string;
icon: ReactNode;
feedKey: string;
score: number | undefined;
rank: number | undefined;
status: Status;
firstEvaluation: Date | undefined;
assetClass: string;
};

export const PriceFeedDrawerProvider = (
Expand All @@ -57,6 +52,7 @@ const PriceFeedDrawerProviderImpl = ({
children,
cluster,
}: PriceFeedDrawerProviderProps) => {
const contextPriceFeeds = usePriceFeeds();
const logger = useLogger();
const [selectedSymbol, setSelectedSymbol] = useQueryState(
"price-feed",
Expand All @@ -72,10 +68,22 @@ const PriceFeedDrawerProviderImpl = ({
},
[setSelectedSymbol, logger],
);
const selectedFeed = useMemo(
() => priceFeeds.find((feed) => feed.symbol === selectedSymbol),
[selectedSymbol, priceFeeds],
);
const selectedFeed = useMemo(() => {
if (selectedSymbol === "") {
return;
} else {
const feed = priceFeeds.find((feed) => feed.symbol === selectedSymbol);
const contextFeed = contextPriceFeeds.get(selectedSymbol);

return feed === undefined || contextFeed === undefined
? undefined
: {
...feed,
...contextFeed,
feedKey: contextFeed.key[cluster],
};
}
}, [selectedSymbol, priceFeeds, contextPriceFeeds, cluster]);
const handleClose = useCallback(() => {
updateSelectedSymbol("");
}, [updateSelectedSymbol]);
Expand Down
7 changes: 6 additions & 1 deletion apps/insights/src/components/Root/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,12 @@ const PriceFeedsProvider = async ({ children }: { children: ReactNode }) => {
feed.symbol,
{
displaySymbol: feed.product.display_symbol,
icon: <PriceFeedIcon symbol={feed.product.display_symbol} />,
icon: (
<PriceFeedIcon
assetClass={feed.product.asset_type}
symbol={feed.product.display_symbol}
/>
),
description: feed.product.description,
key: {
[Cluster.Pythnet]: feed.product.price_account,
Expand Down
Loading