This commit is contained in:
zhx 2026-06-12 00:47:52 +08:00
parent 55cce7745c
commit 51645bf47a

View File

@ -3007,10 +3007,84 @@
return resultFor(selfGesture, opponentGesture);
}
function numberFromFields(source, fields) {
if (!source) return null;
for (var i = 0; i < fields.length; i += 1) {
if (
!Object.prototype.hasOwnProperty.call(
source,
fields[i]
)
) {
continue;
}
var raw = source[fields[i]];
if (raw === null || raw === undefined || raw === '') {
continue;
}
var value = Number(raw);
if (Number.isFinite(value)) return value;
}
return null;
}
function totalFeeBPSForMatch(match) {
var config = state.config || {};
var feeBPS = numberFromFields(match, [
'fee_bps',
'feeBps',
]);
var poolBPS = numberFromFields(match, [
'pool_bps',
'poolBps',
]);
if (feeBPS === null) {
feeBPS = numberFromFields(config, [
'fee_bps',
'feeBps',
]);
}
if (poolBPS === null) {
poolBPS = numberFromFields(config, [
'pool_bps',
'poolBps',
]);
}
if (feeBPS === null && poolBPS === null) return null;
return Math.max(
0,
Math.min(10000, (feeBPS || 0) + (poolBPS || 0))
);
}
function estimatedPayoutFromFee(match) {
var stakeCoin =
numberFromFields(match, ['stake_coin', 'stakeCoin']) ||
state.selectedStake ||
0;
var totalFeeBPS = totalFeeBPSForMatch(match);
if (!stakeCoin || totalFeeBPS === null) return 0;
return Math.max(
0,
Math.trunc(
(stakeCoin * 2 * (10000 - totalFeeBPS)) / 10000
)
);
}
function payoutFromMatch(match, result) {
var self = findSelfParticipant(match);
if (self && self.payout_coin > 0) return self.payout_coin;
if (result === 'draw') return 0;
var payoutCoin = numberFromFields(self, [
'payout_coin',
'payoutCoin',
]);
if (payoutCoin !== null) {
return Math.max(0, Math.trunc(payoutCoin));
}
if (result !== 'win') return 0;
// 真实局缺少 payout_coin 时不能再展示未扣点的 2 倍押注。
// 兜底只能按本局或配置里的 fee_bps + pool_bps 估算。
if (match) return estimatedPayoutFromFee(match);
return state.selectedStake * 2;
}