From 965cedca05de611642b73df2dd6100872fbafff1 Mon Sep 17 00:00:00 2001 From: Tiago Yamamoto Date: Mon, 22 Dec 2025 16:31:39 -0300 Subject: [PATCH] fix(marketplace): add centralized formatCurrency/formatCents utilities to prevent toFixed errors --- marketplace/src/components/ProductCard.tsx | 3 ++- marketplace/src/pages/Cart.tsx | 10 ++++++---- marketplace/src/pages/Dashboard.tsx | 3 ++- marketplace/src/pages/Inventory.tsx | 3 ++- marketplace/src/pages/Orders.tsx | 3 ++- marketplace/src/pages/SellerDashboard.tsx | 3 ++- marketplace/src/utils/format.ts | 20 ++++++++++++++++++++ 7 files changed, 36 insertions(+), 9 deletions(-) create mode 100644 marketplace/src/utils/format.ts diff --git a/marketplace/src/components/ProductCard.tsx b/marketplace/src/components/ProductCard.tsx index efd4145..06fb799 100644 --- a/marketplace/src/components/ProductCard.tsx +++ b/marketplace/src/components/ProductCard.tsx @@ -1,4 +1,5 @@ import { ProductWithDistance } from '../types/product' +import { formatCents } from '../utils/format' interface ProductCardProps { product: ProductWithDistance @@ -38,7 +39,7 @@ export const ProductCard = ({ product, onAddToCart }: ProductCardProps) => {
- R$ {(product.price_cents / 100).toFixed(2).replace('.', ',')} + {formatCents(product.price_cents)}

Itens: {summary.totalItems}

-

R$ {summary.totalValue.toFixed(2)}

+

R$ {formatCurrency(summary.totalValue)}

{items.length === 0 ? ( @@ -58,7 +59,7 @@ export function CartPage() {

Preço

-

R$ {item.unitPrice.toFixed(2)}

+

R$ {formatCurrency(item.unitPrice)}

Subtotal

- R$ {(item.quantity * item.unitPrice).toFixed(2)} + R$ {formatCurrency(item.quantity * item.unitPrice)}

@@ -109,3 +110,4 @@ export function CartPage() { ) } + diff --git a/marketplace/src/pages/Dashboard.tsx b/marketplace/src/pages/Dashboard.tsx index a9a98be..218fbd4 100644 --- a/marketplace/src/pages/Dashboard.tsx +++ b/marketplace/src/pages/Dashboard.tsx @@ -3,6 +3,7 @@ import { FixedSizeList as List, ListChildComponentProps } from 'react-window' import { Product } from '../types/product' import { useCartStore } from '../stores/cartStore' import { Shell } from '../layouts/Shell' +import { formatCents } from '../utils/format' // Mock data updated to match new Product interface const mockProducts: Product[] = Array.from({ length: 500 }).map((_, idx) => { @@ -33,7 +34,7 @@ function DenseRow({ index, style, data }: ListChildComponentProps) {
{product.description}
{product.batch}
{product.expires_at}
-
R$ {(product.price_cents / 100).toFixed(2)}
+
{formatCents(product.price_cents)}