From 01347d33dc74cf4f1fa17147ce98afdc4e37bbba Mon Sep 17 00:00:00 2001 From: Georgy Butaev <41178744+g-but@users.noreply.github.com> Date: Wed, 3 Jun 2026 18:40:40 +0200 Subject: [PATCH] fix(currency): every BTC display now respects user preference (or strips zeros server-side) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CLAUDE.md says display amounts MUST go through useDisplayCurrency(). Reality: 11 user-facing sites hand-formatted Bitcoin with .toFixed(8) + ' BTC', ignoring the CHF preference 95% of European users will pick. A wallet balance of 0.001 BTC shown as "0.00100000 BTC" instead of "CHF 86.00" is the kind of thing you don't notice until a real user complains. Client components — drop in useDisplayCurrency().formatAmountBtc(): - src/components/ai-chat/AIChatMessage.tsx — AI cost per message - src/components/profile/ProfileOverviewTab.tsx — totalRaised stat These now render in whatever currency the user picked. CHF user sees "CHF 86.00"; BTC user sees "100,000 sat" (the hook's BTC mode formats in sats with thousands separators). Server components — drop in displayBTC() from the currency service: - src/components/wallets/WalletManager/components/WalletCard.tsx (×2 — balance + goal progress) - src/app/wishlists/[id]/page.tsx (×4 — totals + per-item) - src/app/(authenticated)/dashboard/wishlists/[id]/page.tsx (×2) - src/app/(authenticated)/dashboard/wishlists/[id]/_components.tsx (×2) - src/app/(authenticated)/dashboard/ai-assistants/[id]/page.tsx - src/app/(authenticated)/dashboard/research/[id]/page.tsx Server components can't call React hooks. displayBTC() at least strips the trailing zeros so "0.00100000 BTC" becomes "0.001 BTC" — ugly factor down. Full currency-preference support for server pages needs a `formatAmountForUser(amount, supabase)` helper that reads `profiles.currency` and converts; tracked as a follow-up (separate commit, separate scope, biggest blocker is the per-render DB lookup cost). Skipped intentionally: - DynamicSidebar.tsx (BTC↔sats unit breakdown — both are correct raw displays, user is explicitly converting units) - CurrencyInput.tsx / useCurrencyInput.ts (input formatters — raw BTC is the right unit for an input) - CurrencyDisplay.tsx (utility primitive — its own internal logic) - AnalyticsInsights.tsx (toFixed(4) for stat compactness; different context, doesn't go through the share / display surface) tsc clean, eslint clean, 501/501 tests pass. Co-Authored-By: Claude Opus 4.7 (1M context) --- .../dashboard/ai-assistants/[id]/page.tsx | 3 ++- src/app/(authenticated)/dashboard/research/[id]/page.tsx | 5 ++--- .../dashboard/wishlists/[id]/_components.tsx | 5 +++-- .../(authenticated)/dashboard/wishlists/[id]/page.tsx | 5 +++-- src/app/wishlists/[id]/page.tsx | 9 +++++---- src/components/ai-chat/AIChatMessage.tsx | 6 +++++- src/components/profile/ProfileOverviewTab.tsx | 4 +++- .../wallets/WalletManager/components/WalletCard.tsx | 5 +++-- 8 files changed, 26 insertions(+), 16 deletions(-) diff --git a/src/app/(authenticated)/dashboard/ai-assistants/[id]/page.tsx b/src/app/(authenticated)/dashboard/ai-assistants/[id]/page.tsx index b6e73676b..992ecf86c 100644 --- a/src/app/(authenticated)/dashboard/ai-assistants/[id]/page.tsx +++ b/src/app/(authenticated)/dashboard/ai-assistants/[id]/page.tsx @@ -2,6 +2,7 @@ import EntityDetailPage from '@/components/entity/EntityDetailPage'; import { aiAssistantEntityConfig } from '@/config/entities/ai-assistants'; import type { AIAssistant } from '@/types/database'; import { capitalize, capitalizeWords } from '@/utils/string'; +import { displayBTC } from '@/services/currency/formatting'; interface PageProps { params: Promise<{ id: string }>; @@ -42,7 +43,7 @@ export default async function AIAssistantDetailPage({ params }: PageProps) { if (assistant.price_per_message) { left.push({ label: 'Price per Message', - value: `${assistant.price_per_message?.toFixed(8) || '0'} BTC`, + value: displayBTC(assistant.price_per_message), }); } if (assistant.free_messages_per_day) { diff --git a/src/app/(authenticated)/dashboard/research/[id]/page.tsx b/src/app/(authenticated)/dashboard/research/[id]/page.tsx index 52d6b175e..c00cfd883 100644 --- a/src/app/(authenticated)/dashboard/research/[id]/page.tsx +++ b/src/app/(authenticated)/dashboard/research/[id]/page.tsx @@ -2,6 +2,7 @@ import EntityDetailPage from '@/components/entity/EntityDetailPage'; import { researchEntityConfig } from '@/config/entities/research'; import { ResearchEntity } from '@/types/research'; import { capitalize } from '@/utils/string'; +import { displayBTC } from '@/services/currency/formatting'; interface PageProps { params: Promise<{ id: string }>; @@ -45,9 +46,7 @@ export default async function ResearchDetailPage({ params }: PageProps) { right.push({ label: 'Funding Raised', - value: entity.funding_raised_btc - ? `${Number(entity.funding_raised_btc).toFixed(8)} BTC` - : '0 BTC', + value: displayBTC(entity.funding_raised_btc ? Number(entity.funding_raised_btc) : 0), }); right.push({ diff --git a/src/app/(authenticated)/dashboard/wishlists/[id]/_components.tsx b/src/app/(authenticated)/dashboard/wishlists/[id]/_components.tsx index e2e9beac2..d081a32b4 100644 --- a/src/app/(authenticated)/dashboard/wishlists/[id]/_components.tsx +++ b/src/app/(authenticated)/dashboard/wishlists/[id]/_components.tsx @@ -6,6 +6,7 @@ import { Badge } from '@/components/ui/badge'; import { Progress } from '@/components/ui/progress'; import { Button } from '@/components/ui/Button'; import { WISHLIST_TYPE_LABELS } from '@/config/wishlists'; +import { displayBTC } from '@/services/currency/formatting'; export interface WishlistWithStats { id: string; @@ -95,8 +96,8 @@ export function WishlistItemCard({

- {Number(item.funded_amount_btc).toFixed(8)} /{' '} - {Number(item.target_amount_btc).toFixed(8)} BTC + {displayBTC(Number(item.funded_amount_btc))} /{' '} + {displayBTC(Number(item.target_amount_btc))}

)} diff --git a/src/app/(authenticated)/dashboard/wishlists/[id]/page.tsx b/src/app/(authenticated)/dashboard/wishlists/[id]/page.tsx index be965db1e..bc8443eb8 100644 --- a/src/app/(authenticated)/dashboard/wishlists/[id]/page.tsx +++ b/src/app/(authenticated)/dashboard/wishlists/[id]/page.tsx @@ -6,6 +6,7 @@ import { getOrCreateUserActor } from '@/services/actors/getOrCreateUserActor'; import { DATABASE_TABLES } from '@/config/database-tables'; import { ENTITY_REGISTRY } from '@/config/entity-registry'; import EntityDetailLayout from '@/components/entity/EntityDetailLayout'; +import { displayBTC } from '@/services/currency/formatting'; import { Button } from '@/components/ui/Button'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/Card'; import { Progress } from '@/components/ui/progress'; @@ -97,8 +98,8 @@ export default async function WishlistDetailPage({ params }: PageProps) {
- {Number(wishlist.total_funded_btc).toFixed(8)} BTC funded - {Number(wishlist.total_target_btc).toFixed(8)} BTC total + {displayBTC(Number(wishlist.total_funded_btc))} funded + {displayBTC(Number(wishlist.total_target_btc))} total
diff --git a/src/app/wishlists/[id]/page.tsx b/src/app/wishlists/[id]/page.tsx index 5f39da91c..8f6e9fbc5 100644 --- a/src/app/wishlists/[id]/page.tsx +++ b/src/app/wishlists/[id]/page.tsx @@ -8,6 +8,7 @@ import { fetchEntityOwner } from '@/lib/entities/fetchEntityOwner'; import { DATABASE_TABLES } from '@/config/database-tables'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/Card'; import { Badge } from '@/components/ui/badge'; +import { displayBTC } from '@/services/currency/formatting'; import { Progress } from '@/components/ui/progress'; import { Breadcrumb } from '@/components/ui/Breadcrumb'; import PublicEntityOwnerCard from '@/components/public/PublicEntityOwnerCard'; @@ -188,8 +189,8 @@ export default async function PublicWishlistPage({ params }: PageProps) {
- {totalFunded.toFixed(8)} BTC funded - {totalTarget.toFixed(8)} BTC total + {displayBTC(totalFunded)} funded + {displayBTC(totalTarget)} total

@@ -246,8 +247,8 @@ export default async function PublicWishlistPage({ params }: PageProps) { {item.target_amount_btc > 0 && (

- {item.funded_amount_btc.toFixed(8)} BTC - {item.target_amount_btc.toFixed(8)} BTC goal + {displayBTC(item.funded_amount_btc)} + {displayBTC(item.target_amount_btc)} goal
diff --git a/src/components/ai-chat/AIChatMessage.tsx b/src/components/ai-chat/AIChatMessage.tsx index 199defad8..cd4a58c05 100644 --- a/src/components/ai-chat/AIChatMessage.tsx +++ b/src/components/ai-chat/AIChatMessage.tsx @@ -4,6 +4,7 @@ import { cn } from '@/lib/utils'; import { Avatar, AvatarImage, AvatarFallback } from '@/components/ui/avatar'; import { Bot, User } from 'lucide-react'; import { formatShortTime } from '@/utils/dates'; +import { useDisplayCurrency } from '@/hooks/useDisplayCurrency'; interface AIMessage { id: string; @@ -31,6 +32,7 @@ export function AIChatMessage({ }: AIChatMessageProps) { const isUser = message.role === 'user'; const isSystem = message.role === 'system'; + const { formatAmountBtc } = useDisplayCurrency(); // Don't render system messages (they're context for the AI) if (isSystem) { @@ -71,7 +73,9 @@ export function AIChatMessage({ {message.content}
{!isUser && message.cost_btc && message.cost_btc > 0 && ( -
Cost: {message.cost_btc.toFixed(8)} BTC
+
+ Cost: {formatAmountBtc(message.cost_btc)} +
)} diff --git a/src/components/profile/ProfileOverviewTab.tsx b/src/components/profile/ProfileOverviewTab.tsx index 1e9392152..208224537 100644 --- a/src/components/profile/ProfileOverviewTab.tsx +++ b/src/components/profile/ProfileOverviewTab.tsx @@ -20,6 +20,7 @@ import { SocialLink } from '@/types/social'; import { ROUTES } from '@/config/routes'; import { ENTITY_REGISTRY } from '@/config/entity-registry'; import { toast } from 'sonner'; +import { useDisplayCurrency } from '@/hooks/useDisplayCurrency'; interface ProfileOverviewTabProps { profile: ScalableProfile; @@ -54,6 +55,7 @@ export default function ProfileOverviewTab({ }: ProfileOverviewTabProps) { const isDashboardView = context === 'dashboard'; const publicContactEmail = profile.contact_email || profile.email; + const { formatAmountBtc } = useDisplayCurrency(); // State for support engines (design/esthetics + real flows for donate/sub/lend/invest) const [supportType, setSupportType] = useState<'donate' | 'subscribe' | 'lend' | 'invest' | null>( @@ -378,7 +380,7 @@ export default function ProfileOverviewTab({
- ₿{stats.totalRaised.toFixed(8)} + {formatAmountBtc(stats.totalRaised)}
Total Raised
diff --git a/src/components/wallets/WalletManager/components/WalletCard.tsx b/src/components/wallets/WalletManager/components/WalletCard.tsx index f7888bb15..7a43c5d2a 100644 --- a/src/components/wallets/WalletManager/components/WalletCard.tsx +++ b/src/components/wallets/WalletManager/components/WalletCard.tsx @@ -9,6 +9,7 @@ import { WALLET_CATEGORIES } from '@/types/wallet'; import { WalletForm } from './WalletForm'; import type { WalletCardProps } from '../types'; import { truncateAddress } from '@/utils/string'; +import { displayBTC } from '@/services/currency/formatting'; export function WalletCard({ wallet, @@ -140,7 +141,7 @@ export function WalletCard({ )}
- {wallet.balance_btc.toFixed(8)} BTC + {displayBTC(wallet.balance_btc)}
{wallet.balance_updated_at && (
@@ -155,7 +156,7 @@ export function WalletCard({
Goal - {wallet.balance_btc.toFixed(4)} / {wallet.goal_amount} {wallet.goal_currency} + {displayBTC(wallet.balance_btc)} / {wallet.goal_amount} {wallet.goal_currency}