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:
End Nightshade 2026-02-19 18:39:02 -07:00
parent 42dd5eb229
commit 5633c3c4a5
No known key found for this signature in database
2 changed files with 19 additions and 4 deletions

View file

@ -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

View file

@ -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;
}