diff --git a/src/app/dashboard/writer/page.tsx b/src/app/dashboard/writer/page.tsx index 2e2a8c11..6db83ebb 100644 --- a/src/app/dashboard/writer/page.tsx +++ b/src/app/dashboard/writer/page.tsx @@ -2,7 +2,9 @@ import { useAccount } from "wagmi"; import { useQuery } from "@tanstack/react-query"; +import { formatUnits } from "viem"; import { supabase, type Storyline } from "../../../../lib/supabase"; +import { getTokenTVL } from "../../../../lib/price"; import { DeadlineCountdown } from "../../../components/DeadlineCountdown"; import { ClaimRoyalties } from "../../../components/ClaimRoyalties"; import { WriterTradingStats } from "../../../components/WriterTradingStats"; @@ -119,11 +121,12 @@ function StorylineDetail({ storyline, writerAddress }: { storyline: Storyline; w
- Deadline - - - {storyline.has_deadline ? "72h" : "none"} + Donations + {storyline.token_address + ? + : + }
@@ -146,3 +149,38 @@ function StorylineDetail({ storyline, writerAddress }: { storyline: Storyline; w ); } + +function DonationCount({ storylineId, tokenAddress }: { storylineId: number; tokenAddress: string }) { + const { data } = useQuery({ + queryKey: ["donation-count", storylineId, tokenAddress], + queryFn: async () => { + const [tvlData, rows] = await Promise.all([ + getTokenTVL(tokenAddress as Address), + supabase + ? // eslint-disable-next-line @typescript-eslint/no-explicit-any + (supabase.from("donations") as any) + .select("amount") + .eq("storyline_id", storylineId) + .then((r: { data: { amount: string }[] | null }) => r.data) + : null, + ]); + const decimals = tvlData?.decimals ?? 18; + if (!rows || rows.length === 0) return { total: BigInt(0), count: 0, decimals }; + const total = (rows as { amount: string }[]).reduce( + (sum, d) => sum + BigInt(d.amount), + BigInt(0), + ); + return { total, count: rows.length, decimals }; + }, + }); + + if (!data || data.count === 0) { + return ; + } + + return ( + + {formatUnits(data.total, data.decimals)} ({data.count}) + + ); +} diff --git a/src/components/DeadlineCountdown.tsx b/src/components/DeadlineCountdown.tsx index 8b8d619d..07cb5a9b 100644 --- a/src/components/DeadlineCountdown.tsx +++ b/src/components/DeadlineCountdown.tsx @@ -19,9 +19,8 @@ export function DeadlineCountdown({ lastPlotTime }: { lastPlotTime: string }) { if (remaining === null) { return (
- Deadline: + Next plot due in --:--:-- - remaining
); } @@ -40,12 +39,11 @@ export function DeadlineCountdown({ lastPlotTime }: { lastPlotTime: string }) { return (
- Deadline: + Next plot due in {String(hours).padStart(2, "0")}:{String(minutes).padStart(2, "0")}: {String(seconds).padStart(2, "0")} - remaining
); } diff --git a/src/components/WriterTradingStats.tsx b/src/components/WriterTradingStats.tsx index 552e8fca..1aa36d3b 100644 --- a/src/components/WriterTradingStats.tsx +++ b/src/components/WriterTradingStats.tsx @@ -100,8 +100,7 @@ export function WriterTradingStats({ storyline }: WriterTradingStatsProps) { : "—"} - {donationsTotal !== undefined && decimals !== undefined && `D: ${formatUnits(donationsTotal, decimals)}`} - {royaltyData && decimals !== undefined && ` R: ${formatUnits(royaltyData.unclaimed, decimals)}`} + {royaltyData && decimals !== undefined && `Royalties: ${formatUnits(royaltyData.unclaimed, decimals)}`}