mirror of
https://github.com/bitbaum/orangecat.git
synced 2026-12-04 19:27:17 +01:00
fix(currency): every BTC display now respects user preference (or strips zeros server-side)
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) <noreply@anthropic.com>
This commit is contained in:
1 parent
ca861b4d06
commit
01347d33dc
8 files changed
+26
-16
No files matched your search
@@ -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) {
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -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({
|
||||
<div className="mt-2 space-y-1">
|
||||
<Progress value={itemProgress} className="h-1" />
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{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))}
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
@@ -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) {
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-2">
|
||||
<div className="flex justify-between text-sm text-muted-foreground">
|
||||
<span>{Number(wishlist.total_funded_btc).toFixed(8)} BTC funded</span>
|
||||
<span>{Number(wishlist.total_target_btc).toFixed(8)} BTC total</span>
|
||||
<span>{displayBTC(Number(wishlist.total_funded_btc))} funded</span>
|
||||
<span>{displayBTC(Number(wishlist.total_target_btc))} total</span>
|
||||
</div>
|
||||
<Progress value={overallProgress} className="h-2" />
|
||||
<div className="flex justify-between text-xs text-muted-foreground">
|
||||
|
||||
@@ -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) {
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-2">
|
||||
<div className="flex justify-between text-sm text-muted-foreground">
|
||||
<span>{totalFunded.toFixed(8)} BTC funded</span>
|
||||
<span>{totalTarget.toFixed(8)} BTC total</span>
|
||||
<span>{displayBTC(totalFunded)} funded</span>
|
||||
<span>{displayBTC(totalTarget)} total</span>
|
||||
</div>
|
||||
<Progress value={overallProgress} className="h-2" />
|
||||
<p className="text-sm text-muted-foreground">
|
||||
@@ -246,8 +247,8 @@ export default async function PublicWishlistPage({ params }: PageProps) {
|
||||
{item.target_amount_btc > 0 && (
|
||||
<div className="mt-3 space-y-1">
|
||||
<div className="flex justify-between text-xs text-muted-foreground">
|
||||
<span>{item.funded_amount_btc.toFixed(8)} BTC</span>
|
||||
<span>{item.target_amount_btc.toFixed(8)} BTC goal</span>
|
||||
<span>{displayBTC(item.funded_amount_btc)}</span>
|
||||
<span>{displayBTC(item.target_amount_btc)} goal</span>
|
||||
</div>
|
||||
<Progress value={itemProgress} className="h-1.5" />
|
||||
</div>
|
||||
|
||||
@@ -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}
|
||||
</div>
|
||||
{!isUser && message.cost_btc && message.cost_btc > 0 && (
|
||||
<div className="mt-2 text-xs text-muted-dim">Cost: {message.cost_btc.toFixed(8)} BTC</div>
|
||||
<div className="mt-2 text-xs text-muted-dim">
|
||||
Cost: {formatAmountBtc(message.cost_btc)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -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({
|
||||
<CardContent className="pt-4 sm:pt-6">
|
||||
<div className="text-center">
|
||||
<div className="text-lg sm:text-xl md:text-2xl lg:text-3xl font-bold text-green-600">
|
||||
₿{stats.totalRaised.toFixed(8)}
|
||||
{formatAmountBtc(stats.totalRaised)}
|
||||
</div>
|
||||
<div className="text-xs sm:text-sm text-muted-foreground mt-1">Total Raised</div>
|
||||
</div>
|
||||
|
||||
@@ -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({
|
||||
)}
|
||||
</div>
|
||||
<div className="text-2xl sm:text-3xl font-bold text-orange-600">
|
||||
{wallet.balance_btc.toFixed(8)} BTC
|
||||
{displayBTC(wallet.balance_btc)}
|
||||
</div>
|
||||
{wallet.balance_updated_at && (
|
||||
<div className="text-xs text-muted-foreground mt-2">
|
||||
@@ -155,7 +156,7 @@ export function WalletCard({
|
||||
<div className="flex justify-between text-sm mb-2">
|
||||
<span className="text-muted-foreground font-medium">Goal</span>
|
||||
<span className="font-semibold text-foreground">
|
||||
{wallet.balance_btc.toFixed(4)} / {wallet.goal_amount} {wallet.goal_currency}
|
||||
{displayBTC(wallet.balance_btc)} / {wallet.goal_amount} {wallet.goal_currency}
|
||||
</span>
|
||||
</div>
|
||||
<div className="w-full bg-muted rounded-full h-2.5 mb-1">
|
||||
|
||||
Reference in new issue
Block a user