Skip to content

Commit

Permalink
fix: update rate
Browse files Browse the repository at this point in the history
  • Loading branch information
punchanabu committed Oct 15, 2024
1 parent 95fd82f commit 883ab3d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/app/slip/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -32,7 +33,7 @@ export default function Home() {
}

setIsLoading(true);

updateSlipRates();
const slipData = {
total: betAmountNum,
lines: slipItems.map((item) => ({
Expand Down
13 changes: 7 additions & 6 deletions src/store/slip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 883ab3d

Please sign in to comment.