diff --git a/src/app/story/[storylineId]/page.tsx b/src/app/story/[storylineId]/page.tsx index f0bec67f..6dd3fb6a 100644 --- a/src/app/story/[storylineId]/page.tsx +++ b/src/app/story/[storylineId]/page.tsx @@ -22,7 +22,7 @@ import { WriterIdentity } from "../../../components/WriterIdentity"; import { ViewCount, ViewTracker } from "../../../components/ViewCount"; import { CommentSection } from "../../../components/CommentSection"; import { MobileActionBar } from "../../../components/MobileActionBar"; -import { UsdPriceTag } from "../../../components/UsdPriceTag"; +import { MarketCapBox } from "../../../components/MarketCapBox"; /** Deduplicate plots by plot_index, keeping the first occurrence. */ function deduplicateByPlotIndex(plots: Plot[]) { @@ -258,8 +258,6 @@ function StoryHeader({ storyline: Storyline; priceInfo: TokenPriceInfo | null; }) { - const reserveLabel = RESERVE_LABEL; - return (

@@ -292,15 +290,11 @@ function StoryHeader({ {priceInfo && (
-
- - Token Price - - - {formatPrice(priceInfo.pricePerToken)} {reserveLabel} - - -
+
Supply Minted diff --git a/src/components/MarketCapBox.tsx b/src/components/MarketCapBox.tsx new file mode 100644 index 00000000..fa32fd79 --- /dev/null +++ b/src/components/MarketCapBox.tsx @@ -0,0 +1,50 @@ +"use client"; + +import { usePlotUsdPrice } from "../hooks/usePlotUsdPrice"; +import { formatUsdValue } from "../../lib/usd-price"; +import { useQuery } from "@tanstack/react-query"; +import { get24hPriceChange } from "../../lib/price"; +import { browserClient } from "../../lib/rpc"; +import { type Address } from "viem"; + +/** + * Client component that displays Market Cap in USD with 24h % change. + * Market Cap = totalSupply * pricePerToken * plotUsd + */ +export function MarketCapBox({ + tokenAddress, + totalSupply, + pricePerToken, +}: { + tokenAddress: string; + totalSupply: number; + pricePerToken: number; +}) { + const { data: plotUsd } = usePlotUsdPrice(); + const { data: priceChange } = useQuery({ + queryKey: ["24h-change", tokenAddress], + queryFn: () => get24hPriceChange(tokenAddress as Address, browserClient), + staleTime: 60000, + }); + + if (!plotUsd) return null; + + const marketCapUsd = totalSupply * pricePerToken * plotUsd; + const changePercent = priceChange?.changePercent ?? null; + + return ( +
+ + Market Cap + + + {formatUsdValue(marketCapUsd)} + {changePercent !== null && ( + = 0 ? "text-accent" : "text-error"}`}> + {changePercent >= 0 ? "+" : ""}{changePercent.toFixed(1)}% + + )} + +
+ ); +}