From 883ab3d256c349f8a16e0e7abef6718bb164ba89 Mon Sep 17 00:00:00 2001 From: Sirawit Chanaburanasak Date: Tue, 15 Oct 2024 12:36:19 +0700 Subject: [PATCH] fix: update rate --- src/app/slip/page.tsx | 3 ++- src/store/slip.ts | 13 +++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/app/slip/page.tsx b/src/app/slip/page.tsx index ca4946f..bb0c360 100644 --- a/src/app/slip/page.tsx +++ b/src/app/slip/page.tsx @@ -15,6 +15,7 @@ export default function Home() { const slipItems = useSlipStore((state) => state.slipItems); const totalRate = useSlipStore((state) => state.totalRate); const updateSlipRates = useSlipStore((state) => state.updateSlipRates); + const [betAmount, setBetAmount] = useState(""); const [isLoading, setIsLoading] = useState(false); @@ -32,7 +33,7 @@ export default function Home() { } setIsLoading(true); - + updateSlipRates(); const slipData = { total: betAmountNum, lines: slipItems.map((item) => ({ diff --git a/src/store/slip.ts b/src/store/slip.ts index 9511bb8..096536b 100644 --- a/src/store/slip.ts +++ b/src/store/slip.ts @@ -96,12 +96,13 @@ export const useSlipStore = create( const matchData = await getMatchById(slip.match_id); if (matchData?.success) { - if (slip.rate == 0) { - return { ...slip, rate: 2 }; - } - - const updatedRate = matchData.data.rate || slip.rate; - return { ...slip, rate: updatedRate }; + const newRate = slip.betting_on === slip.team_a_color + ? matchData.data.team_a_rate + : slip.betting_on === slip.team_b_color + ? matchData.data.team_b_rate + : slip.rate; + + return { ...slip, rate: newRate || 2 }; } return slip;