From f0abd008d1004b0594f6de8359b31ae10b072cbb Mon Sep 17 00:00:00 2001 From: Cho Young-Hwi Date: Mon, 16 Mar 2026 15:14:28 +0000 Subject: [PATCH 1/2] [#177] Fix reader dashboard: use RESERVE_LABEL and truncate decimals Replace hardcoded "$PLOT" with RESERVE_LABEL (WETH on testnet) and truncate formatUnits output to 6 decimal places for readability. Fixes #177 Co-Authored-By: Claude Opus 4.6 (1M context) --- src/app/dashboard/reader/page.tsx | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/app/dashboard/reader/page.tsx b/src/app/dashboard/reader/page.tsx index 94de1dd3..298ef80c 100644 --- a/src/app/dashboard/reader/page.tsx +++ b/src/app/dashboard/reader/page.tsx @@ -8,6 +8,15 @@ import { ReaderPortfolio } from "../../../components/ReaderPortfolio"; import { WriterIdentityClient } from "../../../components/WriterIdentityClient"; import { formatUnits } from "viem"; import { ConnectWallet } from "../../../components/ConnectWallet"; +import { RESERVE_LABEL } from "../../../../lib/contracts/constants"; + +/** Truncate formatUnits output to at most `digits` decimal places */ +function formatTruncated(value: bigint, decimals: number, digits = 6): string { + const raw = formatUnits(value, decimals); + const dot = raw.indexOf("."); + if (dot === -1 || raw.length - dot - 1 <= digits) return raw; + return raw.slice(0, dot + 1 + digits).replace(/0+$/, "").replace(/\.$/, ""); +} const PAGE_SIZE = 50; @@ -93,7 +102,7 @@ export default function ReaderDashboard() { {donations.length > 0 && ( {" "} - · {formatUnits(totalDonated, 18)} $PLOT on this page + · {formatTruncated(totalDonated, 18)} {RESERVE_LABEL} on this page )}

@@ -160,7 +169,7 @@ function DonationRow({ donation }: { donation: Donation }) { )} - {formatUnits(BigInt(donation.amount), 18)} $PLOT + {formatTruncated(BigInt(donation.amount), 18)} {RESERVE_LABEL} ); From 949b2927246143e18670f8781ff18df374dfe4da Mon Sep 17 00:00:00 2001 From: Cho Young-Hwi Date: Mon, 16 Mar 2026 15:17:40 +0000 Subject: [PATCH 2/2] [#177] Use dynamic reserve token decimals instead of hardcoded 18 Fetch PLOT_TOKEN decimals on-chain via publicClient and pass to formatTruncated calls. Falls back to 18 if query hasn't resolved. Co-Authored-By: Claude Opus 4.6 (1M context) --- src/app/dashboard/reader/page.tsx | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/app/dashboard/reader/page.tsx b/src/app/dashboard/reader/page.tsx index 298ef80c..c6722ed1 100644 --- a/src/app/dashboard/reader/page.tsx +++ b/src/app/dashboard/reader/page.tsx @@ -8,7 +8,9 @@ import { ReaderPortfolio } from "../../../components/ReaderPortfolio"; import { WriterIdentityClient } from "../../../components/WriterIdentityClient"; import { formatUnits } from "viem"; import { ConnectWallet } from "../../../components/ConnectWallet"; -import { RESERVE_LABEL } from "../../../../lib/contracts/constants"; +import { RESERVE_LABEL, PLOT_TOKEN } from "../../../../lib/contracts/constants"; +import { publicClient } from "../../../../lib/rpc"; +import { type Address } from "viem"; /** Truncate formatUnits output to at most `digits` decimal places */ function formatTruncated(value: bigint, decimals: number, digits = 6): string { @@ -58,6 +60,18 @@ export default function ReaderDashboard() { enabled: isConnected && !!address, }); + // Fetch reserve token decimals dynamically + const { data: reserveDecimals = 18 } = useQuery({ + queryKey: ["reserve-decimals"], + queryFn: async () => { + return publicClient.readContract({ + address: PLOT_TOKEN as Address, + abi: [{ type: "function", name: "decimals", stateMutability: "view", inputs: [], outputs: [{ name: "", type: "uint8" }] }] as const, + functionName: "decimals", + }); + }, + }); + const donations = data?.rows ?? []; const totalCount = data?.totalCount ?? 0; @@ -102,7 +116,7 @@ export default function ReaderDashboard() { {donations.length > 0 && ( {" "} - · {formatTruncated(totalDonated, 18)} {RESERVE_LABEL} on this page + · {formatTruncated(totalDonated, reserveDecimals)} {RESERVE_LABEL} on this page )}

@@ -117,7 +131,7 @@ export default function ReaderDashboard() {
{donations.map((d) => ( - + ))} {!isLoading && !error && donations.length === 0 && (

@@ -152,7 +166,7 @@ export default function ReaderDashboard() { ); } -function DonationRow({ donation }: { donation: Donation }) { +function DonationRow({ donation, decimals }: { donation: Donation; decimals: number }) { return (

@@ -169,7 +183,7 @@ function DonationRow({ donation }: { donation: Donation }) { )}
- {formatTruncated(BigInt(donation.amount), 18)} {RESERVE_LABEL} + {formatTruncated(BigInt(donation.amount), decimals)} {RESERVE_LABEL}
);