开始滚动前获取余额时,如果网络错误,添加错误后的处理(await后面记得都要做未响应的处理)

This commit is contained in:
TJH 2026-06-25 15:32:23 +08:00
parent ee79975ea7
commit 51dad4f431
2 changed files with 27 additions and 5 deletions

View File

@ -754,4 +754,27 @@ export class SlotBar extends Component {
this.betIndex = 0; this.betIndex = 0;
this.setBet(this.betGrade[this.betIndex]); this.setBet(this.betGrade[this.betIndex]);
} }
private _refreshingBalance: boolean = false;
async refreshBalanceFromServer(): Promise<number | null> {
if (this._refreshingBalance) return this.getBalance();
this._refreshingBalance = true;
try {
const res = await callGameBalanceApi({});
const balance = Number(res.Balance);
if (!Number.isFinite(balance)) {
console.warn("[SlotBar] invalid balance response:", res);
return null;
}
this.setBalance(balance);
return balance;
} catch (err) {
console.error("[SlotBar] refresh balance failed:", err);
return null;
} finally {
this.scheduleOnce(() => {
this._refreshingBalance = false;
}, 1)
}
}
} }

View File

@ -220,12 +220,11 @@ export class SlotScene extends Component {
this.slotBar.setWin(0); this.slotBar.setWin(0);
} }
let curBalanceData = await callGameBalanceApi({ GameId: getGameId() }) let curBalanceData = await this.slotBar.refreshBalanceFromServer()
let curBalance = curBalanceData.Balance if (!curBalanceData) {
if (!curBalance) { curBalanceData = this.slotBar.getBalance()
curBalance = this.slotBar.getBalance()
} }
if (curBalance < (buyType == 1 ? this.slotBar.getBet() * this.gameInfo.BuyMul : (this.isDoubleWin ? this.slotBar.getdisplayBet() : this.slotBar.getBet())) && !this.isFreeSpin && !this.spinInfo.Frb.Ongoing) { if (curBalanceData < (buyType == 1 ? this.slotBar.getBet() * this.gameInfo.BuyMul : (this.isDoubleWin ? this.slotBar.getdisplayBet() : this.slotBar.getBet())) && !this.isFreeSpin && !this.spinInfo.Frb.Ongoing) {
//余额不足不经过服务器,在客户端拦截 //余额不足不经过服务器,在客户端拦截
this.showErrorTip(2, "", () => { this.slotBar.onConfirmErr2() }); this.showErrorTip(2, "", () => { this.slotBar.onConfirmErr2() });
this.handleErrSpin(true); this.handleErrSpin(true);