diff --git a/client/src/hooks/useHono.ts b/client/src/hooks/useHono.ts index 73cd896..88d27e4 100644 --- a/client/src/hooks/useHono.ts +++ b/client/src/hooks/useHono.ts @@ -2,7 +2,6 @@ import { useQuery } from '@tanstack/react-query' import { hc } from 'hono/client' import { Client } from 'server/hc' -import { useCurrency } from './useCurrency' import { useQueues } from './useQueues' const url = new URL(window.location.origin) @@ -109,20 +108,21 @@ export function useEthValuesByAccount() { }) } -export function useNetworthTimeSeries() { - const { currency } = useCurrency() - const { data: fiat } = useFiat() - +export function useNetworthTimeSeries(currency: string | undefined) { return useQuery({ - queryKey: ['networthTimeSeries', currency, fiat], + queryKey: ['networthTimeSeries', currency], queryFn: async () => { const res = await honoClient.balances.networth.$get() const json = await res.json() - return json.map((item) => ({ - ...item, - value: item.ethValue / (fiat?.getRate(currency) ?? 1), - })) + // For ETH: all records are valid (they all have ethValue) + // For USD: only records with usdValue are valid + return json + .filter((item) => currency === 'ETH' || item.usdValue != null) + .map((item) => ({ + ...item, + value: currency === 'ETH' ? item.ethValue : (item.usdValue as number), + })) }, }) } diff --git a/client/src/screens/Home.tsx b/client/src/screens/Home.tsx index 9fb630b..5019e08 100644 --- a/client/src/screens/Home.tsx +++ b/client/src/screens/Home.tsx @@ -32,7 +32,7 @@ export function Home() { const { currency } = useCurrency() const { data: fiat } = useFiat() const ethValuesByAccount = useEthValuesByAccount() - const { data: networthTimeSeries } = useNetworthTimeSeries() + const { data: networthTimeSeries } = useNetworthTimeSeries(currency) return ( <> @@ -58,13 +58,15 @@ export function Home() { })()} - Total value + + Total value +