Skip to content

Commit 3596f34

Browse files
committed
feat(insights): omit icon when an asset class has no icon
Currently, we display the Generic icon from the cryptocurrency icons set when we have an asset class which no associated icon. However, that icon really doesn't make sense for asset classes that aren't cryptos, so instead this PR just blanks out the icon for such cases.
1 parent e62f2eb commit 3596f34

File tree

1 file changed

+16
-7
lines changed
  • apps/insights/src/components/PriceFeedIcon

1 file changed

+16
-7
lines changed

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

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import Generic from "cryptocurrency-icons/svg/color/generic.svg";
21
import type { ComponentProps, ComponentType } from "react";
32

43
import Commodities from "./commodities.svg";
@@ -26,17 +25,22 @@ export const PriceFeedIcon = ({ assetClass, symbol, ...props }: Props) => {
2625
return Icon ? (
2726
<Icon width="100%" height="100%" viewBox="0 0 32 32" {...props} />
2827
) : (
29-
<GenericIcon assetClass={assetClass} {...props} />
28+
<GenericIcon assetClass="Crypto" {...props} />
3029
);
3130
} else {
32-
return <GenericIcon assetClass={assetClass} {...props} />;
31+
return assetClassHasIcon(assetClass) ? (
32+
<GenericIcon assetClass={assetClass} {...props} />
33+
) : // eslint-disable-next-line unicorn/no-null
34+
null;
3335
}
3436
};
3537

36-
type GenericProps = ComponentProps<"svg"> & { assetClass: string };
38+
type GenericProps = ComponentProps<"svg"> & {
39+
assetClass: keyof typeof ASSET_CLASS_TO_ICON;
40+
};
3741

3842
const GenericIcon = ({ assetClass, ...props }: GenericProps) => {
39-
const Icon = ASSET_CLASS_TO_ICON[assetClass] ?? Generic;
43+
const Icon = ASSET_CLASS_TO_ICON[assetClass];
4044
return (
4145
<Icon
4246
width="100%"
@@ -55,7 +59,7 @@ type SVGProps = ComponentProps<"svg">;
5559
type SVGComponent = ComponentType<SVGProps>;
5660
type SVGRecord = Record<string, SVGComponent>;
5761

58-
const ASSET_CLASS_TO_ICON: Record<string, SVGComponent> = {
62+
const ASSET_CLASS_TO_ICON = {
5963
Commodities,
6064
"Crypto Index": CryptoIndex,
6165
"Crypto Redemption Rate": CryptoRedemptionRate,
@@ -64,4 +68,9 @@ const ASSET_CLASS_TO_ICON: Record<string, SVGComponent> = {
6468
FX: Fx,
6569
Metal,
6670
Rates,
67-
};
71+
} as const;
72+
73+
const assetClassHasIcon = (
74+
assetClass: string,
75+
): assetClass is keyof typeof ASSET_CLASS_TO_ICON =>
76+
Object.keys(ASSET_CLASS_TO_ICON).includes(assetClass);

0 commit comments

Comments
 (0)