1- import Generic from "cryptocurrency-icons/svg/color/generic.svg" ;
21import type { ComponentProps , ComponentType } from "react" ;
32
43import 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
3842const 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">;
5559type SVGComponent = ComponentType < SVGProps > ;
5660type 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