Forráskód Böngészése

feat(insights): improve feed generic icons

Connor Prussin 8 hónapja
szülő
commit
c9631e24f4

+ 3 - 0
apps/insights/src/components/PriceFeedIcon/commodities.svg

@@ -0,0 +1,3 @@
+<svg width="1em" height="1em" viewBox="0 0 36 36" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
+  <path fill-rule="evenodd" d="M15 7.912c.677.879 1.397 1.496 2.053 2.282 2.537-.777 6.56-.906 8.578 1.213.357.376.619.859.619 1.425 0 .347-.098.663-.257.942v3.246c.159.28.257.595.257.942 0 .348-.098.664-.257.943v4.178c.53.889.238 1.63-.362 2.26-.355.372-.832.673-1.364.91-1.067.473-2.488.747-4.017.747-1.53 0-2.95-.274-4.017-.748-.532-.236-1.01-.537-1.364-.91-.335-.351-.585-.796-.616-1.316-.02-.346.15-.736.18-.802C11.398 22.944 9 20.437 9 17.357c0-3.566 3.878-7.062 6-9.445Zm1.007 15.255v.333c-.188.33-.351.494-.051.808.177.186.468.388.886.573.834.37 2.038.619 3.408.619s2.574-.248 3.408-.619c.418-.185.71-.387.886-.573.3-.315.137-.478-.051-.808v-3.31c-1.473.73-3.179.914-4.802.842-1.287 1.582-3.695 2.137-3.684 2.135Zm4.569-3.627c1.257-.037 2.945-.21 3.917-1.136V15.06c-1.16.574-2.488.797-3.77.845.17.497.277.989.277 1.452 0 1.352-.436 2.212-.424 2.183Zm-.532-5.128.206.002c1.337 0 3.29-.137 4.294-1.191.255-.268.255-.514 0-.782-1.463-1.536-4.521-1.395-6.463-.967l.142.187c.648.856 1.31 1.814 1.82 2.751ZM15 10.112c1.599 1.789 4.5 4.61 4.5 7.245 0 2.412-2 4.393-4.5 4.393s-4.5-1.981-4.5-4.393c0-2.635 2.901-5.456 4.5-7.246Z"/>
+</svg>

+ 4 - 0
apps/insights/src/components/PriceFeedIcon/crypto-index.svg

@@ -0,0 +1,4 @@
+<svg width="1em" height="1em" viewBox="0 0 36 36" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
+  <path d="M16.5 6.78a.75.75 0 0 1 .75.75v2.254a8.355 8.355 0 0 1 1.5 0V7.53a.75.75 0 0 1 1.5 0v2.53a8.271 8.271 0 0 1 5.313 4.639.75.75 0 1 1-1.374.6 6.752 6.752 0 0 0-12.378 5.4 6.752 6.752 0 0 0 12.378 0 .75.75 0 1 1 1.374.6 8.271 8.271 0 0 1-5.313 4.64v2.59a.75.75 0 0 1-1.5 0v-2.313a8.34 8.34 0 0 1-1.5 0v2.314a.75.75 0 0 1-1.5 0v-2.59a8.271 8.271 0 0 1-5.313-4.64A8.225 8.225 0 0 1 9.75 18c0-1.172.245-2.288.687-3.3a8.271 8.271 0 0 1 5.313-4.64V7.53a.75.75 0 0 1 .75-.75Z"/>
+  <path d="M15.25 16.8a3 3 0 1 1 0 2.4.75.75 0 1 0-1.375.6 4.5 4.5 0 1 0 0-3.6.75.75 0 1 0 1.374.6Z"/>
+</svg>

+ 3 - 0
apps/insights/src/components/PriceFeedIcon/crypto-redemption-rate.svg

@@ -0,0 +1,3 @@
+<svg width="1em" height="1em" viewBox="0 0 36 36" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
+  <path d="M16.5 6.78a.75.75 0 0 1 .75.75v2.254a8.353 8.353 0 0 1 1.5 0V7.53a.75.75 0 0 1 1.5 0v2.53a8.266 8.266 0 0 1 4.617 3.365l.393-1.47a.75.75 0 0 1 1.45.389l-.874 3.26a.75.75 0 0 1-.919.53l-3.361-.9a.75.75 0 1 1 .388-1.45l1.655.444A6.752 6.752 0 0 0 11.811 15.3a.75.75 0 1 1-1.374-.6 8.27 8.27 0 0 1 5.313-4.64V7.53a.75.75 0 0 1 .75-.75ZM15.75 25.94v2.59a.75.75 0 0 0 1.5 0v-2.313a8.338 8.338 0 0 0 1.5 0v2.314a.75.75 0 0 0 1.5 0V25.94a8.27 8.27 0 0 0 5.313-4.64.75.75 0 1 0-1.374-.6A6.752 6.752 0 0 1 12.4 21.771l1.656.444a.75.75 0 1 0 .388-1.45l-3.362-.9a.75.75 0 0 0-.918.53l-.874 3.26a.75.75 0 1 0 1.45.389l.393-1.47a8.266 8.266 0 0 0 4.617 3.366Z"/>
+</svg>

+ 3 - 0
apps/insights/src/components/PriceFeedIcon/crypto.svg

@@ -0,0 +1,3 @@
+<svg width="1em" height="1em" viewBox="0 0 36 36" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
+  <path d="M17.25 7.53a.75.75 0 0 0-1.5 0v2.53a8.27 8.27 0 0 0-5.313 4.64A8.225 8.225 0 0 0 9.75 18c0 1.172.245 2.289.687 3.3a8.27 8.27 0 0 0 5.313 4.64v2.59a.75.75 0 0 0 1.5 0v-2.314a8.377 8.377 0 0 0 1.5 0v2.314a.75.75 0 0 0 1.5 0v-2.59a8.27 8.27 0 0 0 5.313-4.64.75.75 0 0 0-1.374-.6 6.752 6.752 0 0 1-12.378-5.4 6.752 6.752 0 0 1 12.378 0 .75.75 0 0 0 1.374-.6 8.27 8.27 0 0 0-5.313-4.64V7.53a.75.75 0 0 0-1.5 0v2.254a8.355 8.355 0 0 0-1.5 0V7.53Z"/>
+</svg>

+ 3 - 0
apps/insights/src/components/PriceFeedIcon/equity.svg

@@ -0,0 +1,3 @@
+<svg width="1em" height="1em" viewBox="0 0 36 36" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
+  <path fill-rule="evenodd" d="M17.47 8.47a.75.75 0 0 1 .53-.22 9.75 9.75 0 1 1-8.445 4.875.75.75 0 0 1 1.025-.274l4.546 2.624a.75.75 0 0 1 .275 1.025A3 3 0 1 0 18 15a.75.75 0 0 1-.75-.75V9a.75.75 0 0 1 .22-.53Zm-7.213 12.38a8.251 8.251 0 0 0 6.993 5.366v-3.779a4.5 4.5 0 0 1-3.342-2.564l-3.65.978Zm3.262-2.426-3.65.978a8.256 8.256 0 0 1 .64-4.86l3.272 1.889a4.502 4.502 0 0 0-.262 1.993Zm5.231 4.013v3.779a8.25 8.25 0 0 0 0-16.432v3.78a4.501 4.501 0 0 1 0 8.873Z"/>
+</svg>

+ 4 - 0
apps/insights/src/components/PriceFeedIcon/fx.svg

@@ -0,0 +1,4 @@
+<svg width="1em" height="1em" viewBox="0 0 36 36" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
+  <path d="M11.51 9.275a4.875 4.875 0 0 1 5.24.816.75.75 0 1 0 1-1.118A6.375 6.375 0 0 0 7.166 13H6.08a.75.75 0 0 0 0 1.5h1.046v1H6.079a.75.75 0 0 0 0 1.5h1.093a6.375 6.375 0 0 0 10.578 3.977.75.75 0 0 0-1-1.118A4.874 4.874 0 0 1 8.687 17h3.642a.75.75 0 0 0 0-1.5H8.625v-1h4.954a.75.75 0 0 0 0-1.5h-4.9a4.875 4.875 0 0 1 2.83-3.725Z"/>
+  <path fill-rule="evenodd" d="M24.75 12.875a.75.75 0 0 0-1.5 0V14h-.5a3.875 3.875 0 0 0 0 7.75h.5v4.75h-1.125a2.375 2.375 0 0 1-2.375-2.375.75.75 0 0 0-1.5 0A3.875 3.875 0 0 0 22.125 28h1.125v1.125a.75.75 0 0 0 1.5 0V28h1.125a3.875 3.875 0 0 0 0-7.75H24.75V15.5h.5a2.374 2.374 0 0 1 2.375 2.375.75.75 0 0 0 1.5 0A3.874 3.874 0 0 0 25.25 14h-.5v-1.125Zm-1.5 2.625h-.5a2.375 2.375 0 1 0 0 4.75h.5V15.5Zm1.5 6.25v4.75h1.125a2.375 2.375 0 1 0 0-4.75H24.75Z"/>
+</svg>

+ 45 - 0
apps/insights/src/components/PriceFeedIcon/index.module.scss

@@ -0,0 +1,45 @@
+@use "@pythnetwork/component-library/theme";
+
+.generic {
+  border-radius: theme.border-radius("md");
+
+  &[data-asset-class="Commodities"] {
+    background: theme.pallette-color("zinc", 400);
+    fill: theme.pallette-color("zinc", 700);
+  }
+
+  &[data-asset-class="Crypto Index"] {
+    background: theme.pallette-color("fuchsia", 300);
+    fill: theme.pallette-color("fuchsia", 700);
+  }
+
+  &[data-asset-class="Crypto Redemption Rate"] {
+    background: theme.pallette-color("pink", 300);
+    fill: theme.pallette-color("pink", 700);
+  }
+
+  &[data-asset-class="Crypto"] {
+    background: theme.pallette-color("violet", 300);
+    fill: theme.pallette-color("violet", 700);
+  }
+
+  &[data-asset-class="Equity"] {
+    background: theme.pallette-color("rose", 300);
+    fill: theme.pallette-color("rose", 700);
+  }
+
+  &[data-asset-class="FX"] {
+    background: theme.pallette-color("indigo", 300);
+    fill: theme.pallette-color("indigo", 700);
+  }
+
+  &[data-asset-class="Metal"] {
+    background: theme.pallette-color("orange", 300);
+    fill: theme.pallette-color("orange", 700);
+  }
+
+  &[data-asset-class="Rates"] {
+    background: theme.pallette-color("emerald", 300);
+    fill: theme.pallette-color("stone", 700);
+  }
+}

+ 51 - 14
apps/insights/src/components/PriceFeedIcon/index.tsx

@@ -1,30 +1,67 @@
 import Generic from "cryptocurrency-icons/svg/color/generic.svg";
-import type { ComponentProps } from "react";
+import type { ComponentProps, ComponentType } from "react";
 
+import Commodities from "./commodities.svg";
+import CryptoIndex from "./crypto-index.svg";
+import CryptoRedemptionRate from "./crypto-redemption-rate.svg";
+import Crypto from "./crypto.svg";
+import Equity from "./equity.svg";
+import Fx from "./fx.svg";
 import { icons } from "./icons";
+import styles from "./index.module.scss";
+import Metal from "./metal.svg";
+import Rates from "./rates.svg";
 
 type OwnProps = {
   assetClass: string;
   symbol: string;
 };
-type Props = Omit<
-  ComponentProps<typeof Generic>,
-  keyof OwnProps | "width" | "height" | "viewBox"
-> &
+type Props = Omit<SVGProps, keyof OwnProps | "width" | "height" | "viewBox"> &
   OwnProps;
 
 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;
+    const Icon = firstPart ? (icons as SVGRecord)[firstPart] : undefined;
+    return Icon ? (
+      <Icon width="100%" height="100%" viewBox="0 0 32 32" {...props} />
+    ) : (
+      <GenericIcon assetClass={assetClass} {...props} />
+    );
   } else {
-    return Generic;
+    return <GenericIcon assetClass={assetClass} {...props} />;
   }
 };
+
+type GenericProps = ComponentProps<"svg"> & { assetClass: string };
+
+const GenericIcon = ({ assetClass, ...props }: GenericProps) => {
+  const Icon = ASSET_CLASS_TO_ICON[assetClass] ?? Generic;
+  return (
+    <Icon
+      width="100%"
+      height="100%"
+      className={styles.generic}
+      data-asset-class={assetClass}
+      {...(!(assetClass in ASSET_CLASS_TO_ICON) && {
+        viewBox: "0 0 32 32",
+      })}
+      {...props}
+    />
+  );
+};
+
+type SVGProps = ComponentProps<"svg">;
+type SVGComponent = ComponentType<SVGProps>;
+type SVGRecord = Record<string, SVGComponent>;
+
+const ASSET_CLASS_TO_ICON: Record<string, SVGComponent> = {
+  Commodities,
+  "Crypto Index": CryptoIndex,
+  "Crypto Redemption Rate": CryptoRedemptionRate,
+  Crypto,
+  Equity,
+  FX: Fx,
+  Metal,
+  Rates,
+};

+ 3 - 0
apps/insights/src/components/PriceFeedIcon/metal.svg

@@ -0,0 +1,3 @@
+<svg width="1em" height="1em" viewBox="0 0 36 36" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
+  <path d="M13.247 10.335a2.25 2.25 0 0 1 2.2-1.779h5.106a2.25 2.25 0 0 1 2.2 1.779l.927 4.32a2.25 2.25 0 0 1-2.2 2.722h-6.96a2.25 2.25 0 0 1-2.2-2.721l.927-4.321Zm2.2-.279a.75.75 0 0 0-.734.593l-.926 4.321a.75.75 0 0 0 .733.907h6.96a.75.75 0 0 0 .733-.907l-.926-4.321a.75.75 0 0 0-.734-.593h-5.106ZM19.47 20.401a2.25 2.25 0 0 1 2.2-1.778h5.107a2.25 2.25 0 0 1 2.2 1.778l.927 4.321a2.25 2.25 0 0 1-2.2 2.722h-6.96a2.25 2.25 0 0 1-2.2-2.722l.927-4.321Zm2.2-.278a.75.75 0 0 0-.732.592l-.927 4.322a.75.75 0 0 0 .734.907h6.959a.75.75 0 0 0 .733-.907l-.926-4.322a.75.75 0 0 0-.733-.592H21.67ZM9.223 18.623a2.25 2.25 0 0 0-2.2 1.778l-.927 4.321a2.25 2.25 0 0 0 2.2 2.722h6.96a2.25 2.25 0 0 0 2.2-2.722l-.927-4.321a2.25 2.25 0 0 0-2.2-1.778H9.223Zm-.734 2.092a.75.75 0 0 1 .734-.592h5.106a.75.75 0 0 1 .733.592l.927 4.322a.75.75 0 0 1-.734.907H8.296a.75.75 0 0 1-.733-.907l.926-4.322Z"/>
+</svg>

+ 5 - 0
apps/insights/src/components/PriceFeedIcon/rates.svg

@@ -0,0 +1,5 @@
+<svg width="1em" height="1em" viewBox="0 0 36 36" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
+  <path d="M9.75 13.125a3.375 3.375 0 1 1 6.75 0 3.375 3.375 0 0 1-6.75 0Zm3.375-1.875a1.875 1.875 0 1 0 0 3.75 1.875 1.875 0 0 0 0-3.75Z"/>
+  <path d="m25.28 11.78-13.5 13.5a.75.75 0 1 1-1.06-1.06l13.5-13.5a.75.75 0 1 1 1.06 1.06Z"/>
+  <path d="M22.875 19.5a3.375 3.375 0 1 0 0 6.75 3.375 3.375 0 0 0 0-6.75ZM21 22.875a1.875 1.875 0 1 1 3.75 0 1.875 1.875 0 0 1-3.75 0Z"/>
+</svg>