Skip to content

Commit c794842

Browse files
authored
Merge pull request #2394 from pyth-network/cprussin/ui-43-fix-dash-equity-icon-using-dash-crypto-icon-incorrectly
fix(insights): ensure crypto icons are only used for cryptos
2 parents 0f27385 + 2da11e5 commit c794842

File tree

6 files changed

+40
-32
lines changed

6 files changed

+40
-32
lines changed

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type { ComponentProps } from "react";
44
import { icons } from "./icons";
55

66
type OwnProps = {
7+
assetClass: string;
78
symbol: string;
89
};
910
type Props = Omit<
@@ -12,12 +13,18 @@ type Props = Omit<
1213
> &
1314
OwnProps;
1415

15-
export const PriceFeedIcon = ({ symbol, ...props }: Props) => {
16-
const firstPart = symbol.split("/")[0];
17-
const Icon =
18-
firstPart && firstPart in icons
16+
export const PriceFeedIcon = ({ assetClass, symbol, ...props }: Props) => {
17+
const Icon = getIcon(assetClass, symbol);
18+
return <Icon width="100%" height="100%" viewBox="0 0 32 32" {...props} />;
19+
};
20+
21+
const getIcon = (assetClass: string, symbol: string) => {
22+
if (assetClass === "Crypto") {
23+
const firstPart = symbol.split("/")[0];
24+
return firstPart && firstPart in icons
1925
? icons[firstPart as keyof typeof icons]
2026
: Generic;
21-
22-
return <Icon width="100%" height="100%" viewBox="0 0 32 32" {...props} />;
27+
} else {
28+
return Generic;
29+
}
2330
};

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import {
2525
YesterdaysPricesProvider,
2626
PriceFeedChangePercent,
2727
} from "../PriceFeedChangePercent";
28-
import { PriceFeedIcon } from "../PriceFeedIcon";
2928
import { PriceFeedTag } from "../PriceFeedTag";
3029

3130
const PRICE_FEEDS_ANCHOR = "priceFeeds";
@@ -127,10 +126,6 @@ export const PriceFeeds = async () => {
127126
id={PRICE_FEEDS_ANCHOR}
128127
priceFeeds={priceFeeds.activeFeeds.map((feed) => ({
129128
symbol: feed.symbol,
130-
icon: <PriceFeedIcon symbol={feed.product.display_symbol} />,
131-
id: feed.product.price_account,
132-
displaySymbol: feed.product.display_symbol,
133-
assetClass: feed.product.asset_type,
134129
exponent: feed.price.exponent,
135130
numQuoters: feed.price.numQuoters,
136131
}))}

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,14 @@ const getLabels = (assetClass?: string | undefined) => {
1313
if (assetClass === undefined) {
1414
return LABELS.ambiguous;
1515
} else {
16-
const lowercaseAssetClass = assetClass.toLowerCase();
17-
return lowercaseAssetClass in LABELS
18-
? LABELS[lowercaseAssetClass as keyof typeof LABELS]
16+
return assetClass in LABELS
17+
? LABELS[assetClass as keyof typeof LABELS]
1918
: LABELS.default;
2019
}
2120
};
2221

2322
const LABELS = {
24-
rates: {
23+
Rates: {
2524
plural: {
2625
upcase: "YIELDS",
2726
title: "Yields",

apps/insights/src/components/Publisher/layout.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ import { FormattedDate } from "../FormattedDate";
3838
import { FormattedNumber } from "../FormattedNumber";
3939
import { FormattedTokens } from "../FormattedTokens";
4040
import { Meter } from "../Meter";
41-
import { PriceFeedIcon } from "../PriceFeedIcon";
4241
import { PublisherIcon } from "../PublisherIcon";
4342
import { PublisherKey } from "../PublisherKey";
4443
import { PublisherTag } from "../PublisherTag";
@@ -90,14 +89,9 @@ export const PublishersLayout = async ({ children, params }: Props) => {
9089
publisherKey={key}
9190
priceFeeds={priceFeeds.map(({ feed, ranking, status }) => ({
9291
symbol: feed.symbol,
93-
displaySymbol: feed.product.display_symbol,
94-
description: feed.product.description,
95-
icon: <PriceFeedIcon symbol={feed.product.display_symbol} />,
96-
feedKey: feed.product.price_account,
9792
score: ranking?.final_score,
9893
rank: ranking?.final_rank,
9994
firstEvaluation: ranking?.first_ranking_time,
100-
assetClass: feed.product.asset_type,
10195
status,
10296
}))}
10397
>

apps/insights/src/components/Publisher/price-feed-drawer-provider.tsx

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import { useLogger } from "@pythnetwork/app-logger";
44
import { parseAsString, useQueryState } from "nuqs";
55
import {
6-
type ReactNode,
76
type ComponentProps,
87
Suspense,
98
createContext,
@@ -12,6 +11,7 @@ import {
1211
use,
1312
} from "react";
1413

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

3333
type PriceFeed = {
3434
symbol: string;
35-
displaySymbol: string;
36-
description: string;
37-
icon: ReactNode;
38-
feedKey: string;
3935
score: number | undefined;
4036
rank: number | undefined;
4137
status: Status;
4238
firstEvaluation: Date | undefined;
43-
assetClass: string;
4439
};
4540

4641
export const PriceFeedDrawerProvider = (
@@ -57,6 +52,7 @@ const PriceFeedDrawerProviderImpl = ({
5752
children,
5853
cluster,
5954
}: PriceFeedDrawerProviderProps) => {
55+
const contextPriceFeeds = usePriceFeeds();
6056
const logger = useLogger();
6157
const [selectedSymbol, setSelectedSymbol] = useQueryState(
6258
"price-feed",
@@ -72,10 +68,22 @@ const PriceFeedDrawerProviderImpl = ({
7268
},
7369
[setSelectedSymbol, logger],
7470
);
75-
const selectedFeed = useMemo(
76-
() => priceFeeds.find((feed) => feed.symbol === selectedSymbol),
77-
[selectedSymbol, priceFeeds],
78-
);
71+
const selectedFeed = useMemo(() => {
72+
if (selectedSymbol === "") {
73+
return;
74+
} else {
75+
const feed = priceFeeds.find((feed) => feed.symbol === selectedSymbol);
76+
const contextFeed = contextPriceFeeds.get(selectedSymbol);
77+
78+
return feed === undefined || contextFeed === undefined
79+
? undefined
80+
: {
81+
...feed,
82+
...contextFeed,
83+
feedKey: contextFeed.key[cluster],
84+
};
85+
}
86+
}, [selectedSymbol, priceFeeds, contextPriceFeeds, cluster]);
7987
const handleClose = useCallback(() => {
8088
updateSelectedSymbol("");
8189
}, [updateSelectedSymbol]);

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,12 @@ const PriceFeedsProvider = async ({ children }: { children: ReactNode }) => {
8181
feed.symbol,
8282
{
8383
displaySymbol: feed.product.display_symbol,
84-
icon: <PriceFeedIcon symbol={feed.product.display_symbol} />,
84+
icon: (
85+
<PriceFeedIcon
86+
assetClass={feed.product.asset_type}
87+
symbol={feed.product.display_symbol}
88+
/>
89+
),
8590
description: feed.product.description,
8691
key: {
8792
[Cluster.Pythnet]: feed.product.price_account,

0 commit comments

Comments
 (0)