Преглед на файлове

fix: properly handle stringifying values

Connor Prussin преди 8 месеца
родител
ревизия
5ca129803f
променени са 1 файла, в които са добавени 12 реда и са изтрити 5 реда
  1. 12 5
      apps/insights/src/components/LivePrices/index.tsx

+ 12 - 5
apps/insights/src/components/LivePrices/index.tsx

@@ -178,11 +178,18 @@ export const LiveValue = <T extends keyof PriceData>({
 }: LiveValueProps<T>) => {
   const { current } = useLivePriceData(cluster, feedKey);
 
-  return current !== undefined || defaultValue !== undefined ? (
-    (current?.[field]?.toString() ?? defaultValue)
-  ) : (
-    <Skeleton width={SKELETON_WIDTH} />
-  );
+  if (current !== undefined || defaultValue !== undefined) {
+    const value = current?.[field];
+    if (typeof value === "string") {
+      return value;
+    } else if (typeof value === "number" || typeof value === "bigint") {
+      return value.toString();
+    } else {
+      return value ? JSON.stringify(value) : defaultValue;
+    }
+  } else {
+    return <Skeleton width={SKELETON_WIDTH} />;
+  }
 };
 
 type LiveComponentValueProps<T extends keyof PriceComponent["latest"]> = {