diff --git a/src/features/market-detail/components/charts/rate-chart.tsx b/src/features/market-detail/components/charts/rate-chart.tsx index 6d7b748b..8b04c9ec 100644 --- a/src/features/market-detail/components/charts/rate-chart.tsx +++ b/src/features/market-detail/components/charts/rate-chart.tsx @@ -44,26 +44,29 @@ function RateChart({ marketId, chainId, market }: RateChartProps) { apyAtTarget: true, }); - const handleTimeframeChange = (timeframe: '1d' | '7d' | '30d' | '3m' | '6m') => { - setTimeframe(timeframe); - }; - - const getChartData = useMemo(() => { + const chartData = useMemo(() => { if (!historicalData?.rates) return []; const { supplyApy, borrowApy, apyAtTarget } = historicalData.rates; - return supplyApy.map((point: TimeseriesDataPoint, index: number) => { - const supplyVal = isAprDisplay ? convertApyToApr(point.y) : point.y; - const borrowVal = isAprDisplay ? convertApyToApr(borrowApy[index]?.y ?? 0) : (borrowApy[index]?.y ?? 0); - const targetVal = isAprDisplay ? convertApyToApr(apyAtTarget[index]?.y ?? 0) : (apyAtTarget[index]?.y ?? 0); + return supplyApy + .map((point: TimeseriesDataPoint, index: number) => { + // Skip data points with null values + if (point.y === null || borrowApy[index]?.y === null || apyAtTarget[index]?.y === null) { + return null; + } + + const supplyVal = isAprDisplay ? convertApyToApr(point.y) : point.y; + const borrowVal = isAprDisplay ? convertApyToApr(borrowApy[index]?.y ?? 0) : (borrowApy[index]?.y ?? 0); + const targetVal = isAprDisplay ? convertApyToApr(apyAtTarget[index]?.y ?? 0) : (apyAtTarget[index]?.y ?? 0); - return { - x: point.x, - supplyApy: supplyVal, - borrowApy: borrowVal, - apyAtTarget: targetVal, - }; - }); + return { + x: point.x, + supplyApy: supplyVal, + borrowApy: borrowVal, + apyAtTarget: targetVal, + }; + }) + .filter((point): point is NonNullable => point !== null); }, [historicalData, isAprDisplay]); const formatPercentage = (value: number) => `${(value * 100).toFixed(2)}%`; @@ -72,7 +75,9 @@ function RateChart({ marketId, chainId, market }: RateChartProps) { const getAverage = (data: TimeseriesDataPoint[] | undefined) => { if (!data || data.length === 0) return 0; - return data.reduce((sum, point) => sum + point.y, 0) / data.length; + const validPoints = data.filter((point) => point.y !== null); + if (validPoints.length === 0) return 0; + return validPoints.reduce((sum, point) => sum + point.y, 0) / validPoints.length; }; const currentSupplyRate = toDisplayRate(market.state.supplyApy); @@ -124,7 +129,7 @@ function RateChart({ marketId, chainId, market }: RateChartProps) {