"use client"; import dynamic from "next/dynamic"; import { Suspense, useState, useCallback, useMemo } from "react"; import { useDateFormatter, useNumberFormatter } from "react-aria"; import { ResponsiveContainer, Tooltip, Area, XAxis, YAxis } from "recharts"; import type { CategoricalChartState } from "recharts/types/chart/types"; import styles from "./ois-apy-history.module.scss"; const AreaChart = dynamic( () => import("recharts").then((recharts) => recharts.AreaChart), { ssr: false, }, ); const CHART_HEIGHT = 104; type Props = { apyHistory: Point[]; }; type Point = { date: Date; apy: number; }; export const OisApyHistory = ({ apyHistory }: Props) => { const [selectedPoint, setSelectedPoint] = useState< (typeof apyHistory)[number] | undefined >(undefined); const updateSelectedPoint = useCallback( (chart: CategoricalChartState) => { setSelectedPoint( (chart.activePayload as { payload: Point }[] | undefined)?.[0]?.payload, ); }, [setSelectedPoint], ); const currentPoint = useMemo( () => selectedPoint ?? apyHistory.at(-1), [selectedPoint, apyHistory], ); const dateFormatter = useDateFormatter(); const numberFormatter = useNumberFormatter({ maximumFractionDigits: 2 }); return (

APY History

{currentPoint && (
{numberFormatter.format(currentPoint.apy)}% {dateFormatter.format(currentPoint.date)}
)} } > <>} />
); };