diff --git a/lib/usd-price.ts b/lib/usd-price.ts index dafef90b..6dbe11ff 100644 --- a/lib/usd-price.ts +++ b/lib/usd-price.ts @@ -117,3 +117,17 @@ export function formatUsdValue(value: number | null): string { if (value < 1_000_000) return `$${(value / 1000).toFixed(2)}K`; return `$${(value / 1_000_000).toFixed(2)}M`; } + +/** + * Format a USD token price with full precision for small values. + * Shows enough significant digits to expose the actual price + * instead of hiding it behind "< $0.01". + */ +export function formatUsdTokenPrice(value: number | null): string { + if (value === null) return "—"; + if (value === 0) return "$0"; + if (value >= 0.01) return formatUsdValue(value); + // For very small values, show 2 significant digits + const digits = Math.max(2, -Math.floor(Math.log10(value)) + 1); + return `$${value.toFixed(digits)}`; +} diff --git a/src/components/TokenPriceBox.tsx b/src/components/TokenPriceBox.tsx index f775d816..38263cf0 100644 --- a/src/components/TokenPriceBox.tsx +++ b/src/components/TokenPriceBox.tsx @@ -1,7 +1,7 @@ "use client"; import { usePlotUsdPrice } from "../hooks/usePlotUsdPrice"; -import { formatUsdValue } from "../../lib/usd-price"; +import { formatUsdTokenPrice } from "../../lib/usd-price"; import { formatPrice } from "../../lib/format"; import { RESERVE_LABEL } from "../../lib/contracts/constants"; @@ -16,7 +16,7 @@ export function TokenPriceBox({ pricePerToken }: { pricePerToken: number }) { return ( <>
- {usdPrice !== null ? formatUsdValue(usdPrice) : `${formatPrice(pricePerToken)} ${RESERVE_LABEL}`} + {usdPrice !== null ? formatUsdTokenPrice(usdPrice) : `${formatPrice(pricePerToken)} ${RESERVE_LABEL}`}
Token Price