Skip to content

Commit

Permalink
feat: update prices with the platform %
Browse files Browse the repository at this point in the history
  • Loading branch information
brolag committed Feb 23, 2025
1 parent 5b751ea commit 20ba395
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 13 deletions.
2 changes: 1 addition & 1 deletion apps/web/public/locales/es/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@
"grounded": "Molido"
},
"total": "total",
"adding_to_cart": "Añadiendo al carrito...",
"adding_to_cart": "Añadiendo...",
"add_to_cart": "Añadir al carrito",
"shopping_cart_title": "Mi carrito",
"cart_empty_message": "Tu carrito está vacío",
Expand Down
11 changes: 10 additions & 1 deletion apps/web/src/app/_components/features/ProductCatalog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import {
import { api } from "~/trpc/react";
import type { NftMetadata, Product } from "./types";

const MARKET_FEE_BPS = 5000; // 50%

interface ProductCatalogProps {
isConnected?: boolean;
onConnect?: () => void;
Expand All @@ -41,6 +43,11 @@ export default function ProductCatalog({
},
});

const calculateTotalPrice = (price: number): number => {
const fee = (price * MARKET_FEE_BPS) / 10000;
return price + fee;
};

const { data, fetchNextPage, hasNextPage, isFetchingNextPage } =
api.product.getProducts.useInfiniteQuery(
{
Expand Down Expand Up @@ -125,14 +132,16 @@ export default function ProductCatalog({
);
};

const totalPrice = calculateTotalPrice(product.price);

return (
<ProductCard
key={product.id}
image={imageUrl}
region={metadata?.region ?? ""}
farmName={metadata?.farmName ?? ""}
variety={t(product.name)}
price={product.price}
price={totalPrice}
badgeText={t(`strength.${metadata?.strength?.toLowerCase()}`)}
onClick={() => accessProductDetails(product.id)}
onAddToCart={handleAddToCart}
Expand Down
12 changes: 10 additions & 2 deletions apps/web/src/app/shopping-cart/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import {
useStarkContract,
} from "../../services/contractsInterface";

const MARKET_FEE_BPS = 5000; // 50%

interface DeleteModalProps {
isOpen: boolean;
onConfirm: () => void;
Expand Down Expand Up @@ -160,9 +162,15 @@ export default function ShoppingCart() {
}
};

const calculateTotalPrice = (price: number): number => {
const fee = (price * MARKET_FEE_BPS) / 10000;
return price + fee;
};

const totalPrice =
cart?.items.reduce(
(total, item) => total + item.product.price * item.quantity,
(total, item) =>
total + calculateTotalPrice(item.product.price) * item.quantity,
0,
) ?? 0;

Expand Down Expand Up @@ -229,7 +237,7 @@ export default function ShoppingCart() {
</div>
<div className="flex items-center gap-4">
<span className="text-gray-900">
{item.product.price * item.quantity} USD
{calculateTotalPrice(item.product.price) * item.quantity} USD
</span>
<button
type="button"
Expand Down
6 changes: 0 additions & 6 deletions apps/web/src/app/user/register-coffee/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -237,12 +237,6 @@ export default function RegisterCoffee() {
</div>
</div>
<div className="my-8 flex justify-between items-center">
<div className="flex items-center font-medium">
<ArrowPathRoundedSquareIcon className="w-6 h-6 mr-2" />
<label className="text-content-body-default">
{t("operating_fee")}
</label>
</div>
<p className="text-content-body-default">
${operatingFee.toFixed(2)} USD
</p>
Expand Down
22 changes: 19 additions & 3 deletions packages/ui/src/cartSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { Separator } from "./separator";
import { Sidebar } from "./sidebar";
import { Text } from "./typography";

const MARKET_FEE_BPS = 5000; // 50%

interface CartSidebarProps {
isOpen: boolean;
onClose: () => void;
Expand All @@ -20,24 +22,38 @@ export function CartSidebar({
onClose,
children,
title,
totalPrice,
totalPrice: basePrice,
onCheckout,
checkoutLabel = "Checkout",
}: CartSidebarProps) {
const calculateTotalPrice = (price: number): number => {
const fee = (price * MARKET_FEE_BPS) / 10000;
return price + fee;
};

const totalPrice =
basePrice !== undefined ? calculateTotalPrice(basePrice) : undefined;

const footer = totalPrice !== undefined && onCheckout && (
<div className="flex flex-col gap-4 w-full">
<Separator className="mb-2" />
<div className="flex flex-col gap-2">
<div className="flex justify-between items-center">
<Text className="text-base text-gray-500">Subtotal</Text>
<Text className="text-base font-medium">
${totalPrice.toFixed(2)} USD
${basePrice?.toFixed(2)} USD
</Text>
</div>
<div className="flex justify-between items-center">
<Text className="text-base text-gray-500">Fee (50%)</Text>
<Text className="text-base font-medium">
${((totalPrice ?? 0) - (basePrice ?? 0)).toFixed(2)} USD
</Text>
</div>
<div className="flex justify-between items-center">
<Text className="text-base font-semibold">Total</Text>
<Text className="text-lg font-bold">
${totalPrice.toFixed(2)} USD
${totalPrice?.toFixed(2)} USD
</Text>
</div>
</div>
Expand Down

0 comments on commit 20ba395

Please sign in to comment.