开始滚动前获取余额时,如果网络错误,添加错误后的处理(await后面记得都要做未响应的处理)
All checks were successful
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 1m18s
All checks were successful
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 1m18s
This commit is contained in:
parent
ee79975ea7
commit
313f6ae647
@ -754,4 +754,27 @@ export class SlotBar extends Component {
|
||||
this.betIndex = 0;
|
||||
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)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -220,12 +220,11 @@ export class SlotScene extends Component {
|
||||
this.slotBar.setWin(0);
|
||||
}
|
||||
|
||||
let curBalanceData = await callGameBalanceApi({ GameId: getGameId() })
|
||||
let curBalance = curBalanceData.Balance
|
||||
if (!curBalance) {
|
||||
curBalance = this.slotBar.getBalance()
|
||||
let curBalanceData = await this.slotBar.refreshBalanceFromServer()
|
||||
if (!curBalanceData) {
|
||||
curBalanceData = 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.handleErrSpin(true);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user