Don't reveal the win banner before winner_amount_sats is known (B-50)

winner_user_id is committed as soon as the draw picks a winner, but
winner_amount_sats isn't set until the payout tx is built afterwards
(a real Electrum listunspent round-trip later, in a separate DB
transaction). The frontend revealed the win banner as soon as
winner_user_id appeared, formatPlm(undefined) rendered as "—", and
the toast/result box briefly showed "You won! +— PLM" until the next
poll picked up the real amount. Gate the winner's own reveal on
winner_amount_sats also being non-null; a loss can still reveal
immediately since it never needs the amount.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-31 15:03:42 +02:00
co-authored by Claude Sonnet 5
parent 5cfe2d6f95
commit 9207bbcb8f
+12 -2
View File
@@ -488,11 +488,21 @@ async function refreshRound() {
// myUserId may not be loaded yet on the very first tick after a reload
// (refreshMe() and refreshRound() run concurrently) — fall back to the
// persisted result rather than risk showing nothing or the wrong side.
// winner_user_id is committed as soon as the draw picks a winner, but
// winner_amount_sats isn't set until the payout tx is built afterwards
// (a real Electrum round-trip later) — revealing a win before then would
// show "+— PLM". Only the winner's own reveal needs to wait for it.
const iWon = myUserId != null && data.winner_user_id === myUserId;
const amountReady = !iWon || data.winner_amount_sats != null;
const canReveal =
data.user_played && data.winner_user_id != null && (alreadyKnown || elapsedMs >= minMs) && myUserId != null;
data.user_played &&
data.winner_user_id != null &&
(alreadyKnown || elapsedMs >= minMs) &&
myUserId != null &&
amountReady;
if (canReveal) {
const won = data.winner_user_id === myUserId;
const won = iWon;
if (!alreadyKnown) {
persistResult(data.round_id, won, data.winner_amount_sats);
if (won) {