1
- import Generic from "cryptocurrency-icons/svg/color/generic.svg" ;
2
1
import type { ComponentProps , ComponentType } from "react" ;
3
2
4
3
import Commodities from "./commodities.svg" ;
@@ -26,17 +25,22 @@ export const PriceFeedIcon = ({ assetClass, symbol, ...props }: Props) => {
26
25
return Icon ? (
27
26
< Icon width = "100%" height = "100%" viewBox = "0 0 32 32" { ...props } />
28
27
) : (
29
- < GenericIcon assetClass = { assetClass } { ...props } />
28
+ < GenericIcon assetClass = "Crypto" { ...props } />
30
29
) ;
31
30
} 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 ;
33
35
}
34
36
} ;
35
37
36
- type GenericProps = ComponentProps < "svg" > & { assetClass : string } ;
38
+ type GenericProps = ComponentProps < "svg" > & {
39
+ assetClass : keyof typeof ASSET_CLASS_TO_ICON ;
40
+ } ;
37
41
38
42
const GenericIcon = ( { assetClass, ...props } : GenericProps ) => {
39
- const Icon = ASSET_CLASS_TO_ICON [ assetClass ] ?? Generic ;
43
+ const Icon = ASSET_CLASS_TO_ICON [ assetClass ] ;
40
44
return (
41
45
< Icon
42
46
width = "100%"
@@ -55,7 +59,7 @@ type SVGProps = ComponentProps<"svg">;
55
59
type SVGComponent = ComponentType < SVGProps > ;
56
60
type SVGRecord = Record < string , SVGComponent > ;
57
61
58
- const ASSET_CLASS_TO_ICON : Record < string , SVGComponent > = {
62
+ const ASSET_CLASS_TO_ICON = {
59
63
Commodities,
60
64
"Crypto Index" : CryptoIndex ,
61
65
"Crypto Redemption Rate" : CryptoRedemptionRate ,
@@ -64,4 +68,9 @@ const ASSET_CLASS_TO_ICON: Record<string, SVGComponent> = {
64
68
FX : Fx ,
65
69
Metal,
66
70
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