From 38e86d755b2e0784b9859b92b512385dc8c0cec0 Mon Sep 17 00:00:00 2001
From: parsa aghaei
Date: Sat, 25 Jul 2026 12:14:08 +0330
Subject: [PATCH] fix(wallet, pet-profile): ensure wallet balance deduction and
map petId in order history sync
---
.../application/components/CheckoutPage.tsx | 39 ++++++++++---------
frontend/application/lib/store/cartStore.ts | 2 +
2 files changed, 22 insertions(+), 19 deletions(-)
diff --git a/frontend/application/components/CheckoutPage.tsx b/frontend/application/components/CheckoutPage.tsx
index 1c2ee978..d1037787 100644
--- a/frontend/application/components/CheckoutPage.tsx
+++ b/frontend/application/components/CheckoutPage.tsx
@@ -78,25 +78,26 @@ export default function CheckoutPage() {
const activePet = getActivePet();
try {
- // 1. If using wallet, deduct available balance (up to totalAmount)
- let walletDeducted = 0;
- if (paymentMethod === 'wallet' && profile.walletBalance > 0) {
- walletDeducted = Math.min(profile.walletBalance, totalAmount);
- const newBalance = profile.walletBalance - walletDeducted;
- const newTransaction = {
- id: `TR-${Math.floor(Math.random() * 90000) + 10000}`,
- type: 'purchase' as const,
- amount: walletDeducted,
- date: new Date().toISOString(),
- status: 'success' as const
- };
- useUserStore.setState((state) => ({
- profile: {
- ...state.profile,
- walletBalance: newBalance,
- transactions: [newTransaction, ...(state.profile.transactions || [])]
- }
- }));
+ // 1. Deduct wallet balance if payment method is wallet
+ if (paymentMethod === 'wallet') {
+ const walletDeducted = Math.min(profile.walletBalance || 0, totalAmount);
+ if (walletDeducted > 0) {
+ const newBalance = (profile.walletBalance || 0) - walletDeducted;
+ const newTransaction = {
+ id: `TR-${Math.floor(Math.random() * 90000) + 10000}`,
+ type: 'purchase' as const,
+ amount: walletDeducted,
+ date: new Date().toISOString(),
+ status: 'success' as const
+ };
+ useUserStore.setState((state) => ({
+ profile: {
+ ...state.profile,
+ walletBalance: newBalance,
+ transactions: [newTransaction, ...(state.profile.transactions || [])]
+ }
+ }));
+ }
}
// 2. Register the order in the backend
diff --git a/frontend/application/lib/store/cartStore.ts b/frontend/application/lib/store/cartStore.ts
index d609d93c..d7b98740 100644
--- a/frontend/application/lib/store/cartStore.ts
+++ b/frontend/application/lib/store/cartStore.ts
@@ -143,6 +143,8 @@ export const useCartStore = create()(
total: Number(bo.totalAmount),
charityDonation: Number(bo.charityDonation),
status: bo.status,
+ petId: bo.petId || bo.pet?.id,
+ shippingAddress: bo.shippingAddress,
trackingNumber: bo.trackingNumber || `CN-${Math.floor(Math.random() * 90000) + 10000}`
}));
set({ orders: mappedOrders });