mirror of
https://github.com/System-End/scraps.git
synced 2026-04-19 23:22:54 +00:00
fix(shop): show detailed insufficient funds error, add debug logging
- ShopItemModal: show required vs available scraps in error message - Backend: log balance details on try-luck to debug mismatches
This commit is contained in:
parent
42dd5eb229
commit
5633c3c4a5
2 changed files with 19 additions and 4 deletions
|
|
@ -551,10 +551,21 @@ shop.post("/items/:id/try-luck", async ({ params, headers }) => {
|
|||
);
|
||||
|
||||
// Check if user can afford the roll cost
|
||||
const canAffordRoll = await canAfford(user.id, rollCost, tx);
|
||||
const {
|
||||
balance: currentBalance,
|
||||
earned,
|
||||
spent,
|
||||
} = await getUserScrapsBalance(user.id, tx);
|
||||
console.log(
|
||||
`[SHOP] try-luck user=${user.id} item=${itemId} price=${currentItem.price} baseProbability=${currentItem.baseProbability} effectiveProbability=${effectiveProbability} rollCost=${rollCost} balance=${currentBalance} (earned=${earned} spent=${spent})`,
|
||||
);
|
||||
const canAffordRoll = currentBalance >= rollCost;
|
||||
if (!canAffordRoll) {
|
||||
const { balance } = await getUserScrapsBalance(user.id, tx);
|
||||
throw { type: "insufficient_funds", balance, cost: rollCost };
|
||||
throw {
|
||||
type: "insufficient_funds",
|
||||
balance: currentBalance,
|
||||
cost: rollCost,
|
||||
};
|
||||
}
|
||||
|
||||
// Cryptographically secure random: 1-100 inclusive
|
||||
|
|
|
|||
|
|
@ -144,7 +144,11 @@
|
|||
|
||||
if (!response.ok || data.error || !data.success) {
|
||||
alertType = 'error';
|
||||
alertMessage = data.error || $t.shop.failedToTryLuck;
|
||||
if (data.required && data.available !== undefined) {
|
||||
alertMessage = `${data.error}. You need ${data.required} scraps but only have ${data.available}.`;
|
||||
} else {
|
||||
alertMessage = data.error || $t.shop.failedToTryLuck;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue