import clsx from "clsx"; import type { CryptocurrenciesListResponse } from "~/types/crypto-api"; import { formatPercentage } from "~/utils/format"; function TopCard({ header, value, footer, percentChange }) { return (

{header}

{value}

{percentChange !== null && ( 0 ? "bg-emerald-100 text-emerald-700" : "bg-rose-100 text-rose-700" )} > {formatPercentage(percentChange)} )}

{footer}

); } export function TopCards({ currencies }: { currencies: CryptocurrenciesListResponse["currencies"]; }) { const bitcoin = currencies.find((c) => c.slug === "bitcoin")!; const gainersCount = currencies.filter((c) => c.percent_change_24h > 0).length; const losersCount = currencies.filter((c) => c.percent_change_24h < 0).length; const averagePriceChange = currencies.reduce((prev, current) => prev + current.percent_change_24h, 0) / currencies.length; const totalVolume = currencies.reduce((prev, current) => prev + current.volume_24h, 0); const averageVolume = totalVolume / currencies.length; return (
); }