@betorigami/games 3.4.11 → 3.4.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -16,6 +16,7 @@ export declare class PlinkoGame extends GameComponent {
16
16
  private ballsInFlight;
17
17
  private lastSubBassTime;
18
18
  private pendingResultsByBetId;
19
+ private balanceLedger;
19
20
  private betQueue;
20
21
  private _plinkoManualEl?;
21
22
  private _plinkoAutoEl?;
@@ -0,0 +1,16 @@
1
+ import { default as Big } from 'big.js';
2
+ export interface DisplayedBalance {
3
+ read: () => Big;
4
+ write: (balance: Big) => void;
5
+ }
6
+ export declare class PlinkoBalanceLedger {
7
+ private readonly displayedBalance;
8
+ private shortfall;
9
+ constructor(displayedBalance: DisplayedBalance);
10
+ placeBet<T extends {
11
+ success: boolean;
12
+ }>(stake: string | Big, request: () => Promise<T>): Promise<T>;
13
+ creditPayout(payout: string | Big): void;
14
+ private debitBet;
15
+ private refundBet;
16
+ }
package/dist/index.mjs CHANGED
@@ -26958,13 +26958,36 @@ const plinkoGameStyles = i$a`
26958
26958
  height: 100%;
26959
26959
  }
26960
26960
  `;
26961
+ class PlinkoBalanceLedger {
26962
+ constructor(oe) {
26963
+ this.displayedBalance = oe, this.shortfall = Big("0");
26964
+ }
26965
+ async placeBet(oe, Me) {
26966
+ const Oe = Big(oe);
26967
+ this.debitBet(Oe);
26968
+ const vt = await Me();
26969
+ return vt.success || this.refundBet(Oe), vt;
26970
+ }
26971
+ creditPayout(oe) {
26972
+ const Me = this.displayedBalance.read().minus(this.shortfall).plus(oe), Oe = Me.lt("0");
26973
+ this.shortfall = Oe ? Me.neg() : Big("0"), this.displayedBalance.write(Oe ? Big("0") : Me);
26974
+ }
26975
+ debitBet(oe) {
26976
+ const Me = this.displayedBalance.read().minus(this.shortfall).minus(oe), Oe = Me.lt("0");
26977
+ this.shortfall = Oe ? Me.neg() : Big("0"), this.displayedBalance.write(Oe ? Big("0") : Me);
26978
+ }
26979
+ refundBet(oe) {
26980
+ const Me = this.displayedBalance.read().minus(this.shortfall).plus(oe), Oe = Me.lt("0");
26981
+ this.shortfall = Oe ? Me.neg() : Big("0"), this.displayedBalance.write(Oe ? Big("0") : Me);
26982
+ }
26983
+ }
26961
26984
  var __defProp$7 = Object.defineProperty, __getOwnPropDesc$7 = Object.getOwnPropertyDescriptor, __decorateClass$7 = (te, oe, Me, Oe) => {
26962
26985
  for (var vt, At = Oe > 1 ? void 0 : Oe ? __getOwnPropDesc$7(oe, Me) : oe, Vt = te.length - 1; Vt >= 0; Vt--) (vt = te[Vt]) && (At = (Oe ? vt(oe, Me, At) : vt(At)) || At);
26963
26986
  return Oe && At && __defProp$7(oe, Me, At), At;
26964
26987
  };
26965
26988
  let PlinkoGame = class extends Lt {
26966
26989
  constructor() {
26967
- super(), this.history = [], this.riskLevel = Jt$1.MEDIUM_RISK, this.rowCount = 12, this.ballsInFlight = 0, this.lastSubBassTime = 0, this.pendingResultsByBetId = /* @__PURE__ */ new Map(), this.betQueue = new np((te) => this.handleBetExecution(te), { maxQueueSize: 3, maxConcurrent: 5 }), new vd(this, [{ key: " ", callback: () => Wt.clickBetButton(this.manualOrAuto, this._plinkoManualEl, this._plinkoAutoEl), options: { repeat: !0, repeatInterval: 200, disabled: () => !this.gameData?.hotkeysOpenEnabled || Wt.isBetButtonDisabled(this.manualOrAuto, this._plinkoManualEl, this._plinkoAutoEl) } }]);
26990
+ super(), this.history = [], this.riskLevel = Jt$1.MEDIUM_RISK, this.rowCount = 12, this.ballsInFlight = 0, this.lastSubBassTime = 0, this.pendingResultsByBetId = /* @__PURE__ */ new Map(), this.balanceLedger = new PlinkoBalanceLedger({ read: () => Big(this.gameData.balance), write: (te) => this.gameData.updateBalance(te) }), this.betQueue = new np((te) => this.handleBetExecution(te), { maxQueueSize: 3, maxConcurrent: 5 }), new vd(this, [{ key: " ", callback: () => Wt.clickBetButton(this.manualOrAuto, this._plinkoManualEl, this._plinkoAutoEl), options: { repeat: !0, repeatInterval: 200, disabled: () => !this.gameData?.hotkeysOpenEnabled || Wt.isBetButtonDisabled(this.manualOrAuto, this._plinkoManualEl, this._plinkoAutoEl) } }]);
26968
26991
  }
26969
26992
  get isGameInProgress() {
26970
26993
  return this.autobetInProgress || this.autobetStopping || this.ballsInFlight > 0;
@@ -26980,20 +27003,17 @@ let PlinkoGame = class extends Lt {
26980
27003
  }
26981
27004
  async handleBetExecution(te, oe) {
26982
27005
  if (!this.gameData?.currency) return { success: !1, error: l$1("alerts.gameError", this.gameData?.language || k) };
26983
- const Me = Big(this.gameData.balance);
26984
27006
  try {
26985
- if (this.isDemoMode && Me.lt(te)) throw new Error(l$1("alerts.insufficientBalance", this.gameData?.language || k));
26986
- this.gameData.updateBalance(Me.minus(te));
26987
- const Oe = await this.plinkoApi.startBet({ language: this.gameData.language, amount: te, riskLevel: this.riskLevel, rowCount: this.rowCount, meta: oe ? vp(oe) : void 0 });
26988
- if (Oe.success) {
26989
- const { data: vt } = Oe, At = Number(vt.multiplier), Vt = vt.betActions.filter((Qa) => Qa.data?.PLINKO)[1], Ut = Vt?.data?.PLINKO, Da = (Ut && "result" in Ut ? Ut.result : []).reduce((Qa, $s) => Qa + $s, 0);
26990
- return vt.id && this.pendingResultsByBetId.set(vt.id, { multiplier: At, payout: vt.payout ? Big(vt.payout) : Big(0) }), this.updateHistoryWithBet(vt), this.gameData.instantBetEnabled ? this._plinkoContentEl?.triggerInstantResult?.(this.gameData.edge, At, vt.id) : this._plinkoContentEl?.dropBallForResult(Da, vt.id), Oe;
27007
+ if (this.isDemoMode && Big(this.gameData.balance).lt(te)) throw new Error(l$1("alerts.insufficientBalance", this.gameData?.language || k));
27008
+ const Me = await this.balanceLedger.placeBet(te, () => this.plinkoApi.startBet({ language: this.gameData.language, amount: te, riskLevel: this.riskLevel, rowCount: this.rowCount, meta: oe ? vp(oe) : void 0 }));
27009
+ if (Me.success) {
27010
+ const { data: Oe } = Me, vt = Number(Oe.multiplier), At = Oe.betActions.filter((Da) => Da.data?.PLINKO)[1], Vt = At?.data?.PLINKO, Ut = (Vt && "result" in Vt ? Vt.result : []).reduce((Da, Qa) => Da + Qa, 0);
27011
+ return Oe.id && this.pendingResultsByBetId.set(Oe.id, { multiplier: vt, payout: Oe.payout ? Big(Oe.payout) : Big(0) }), this.updateHistoryWithBet(Oe), this.gameData.instantBetEnabled ? this._plinkoContentEl?.triggerInstantResult?.(this.gameData.edge, vt, Oe.id) : this._plinkoContentEl?.dropBallForResult(Ut, Oe.id), Me;
26991
27012
  }
26992
- throw this.checkSessionExpired(Oe.errorCode ?? Sa.UNKNOWN), new Error(Oe.error);
26993
- } catch (Oe) {
26994
- this.gameData.updateBalance(Me);
26995
- const vt = Oe instanceof Error ? Oe.message : l$1("alerts.gameError", this.gameData?.language || k);
26996
- return this.showError(vt), { success: !1, error: vt };
27013
+ throw this.checkSessionExpired(Me.errorCode ?? Sa.UNKNOWN), new Error(Me.error);
27014
+ } catch (Me) {
27015
+ const Oe = Me instanceof Error ? Me.message : l$1("alerts.gameError", this.gameData?.language || k);
27016
+ return this.showError(Oe), { success: !1, error: Oe };
26997
27017
  }
26998
27018
  }
26999
27019
  async queuedBetExecution(te) {
@@ -27032,7 +27052,7 @@ let PlinkoGame = class extends Lt {
27032
27052
  }
27033
27053
  handleBinHit(te) {
27034
27054
  const { multiplier: oe, payout: Me } = this.resolveMultiplierAndWin(te);
27035
- this.gameData?.updateBalance(Big(this.gameData.balance).plus(Me)), this.playResultSound(oe);
27055
+ this.balanceLedger.creditPayout(Me), this.playResultSound(oe);
27036
27056
  }
27037
27057
  render() {
27038
27058
  const te = this.gameData?.mainWidth >= 768, oe = Math.max(...this.binMultipliers) || 1, Me = wp(this.gameData);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@betorigami/games",
3
- "version": "3.4.11",
3
+ "version": "3.4.12",
4
4
  "author": "",
5
5
  "license": "UNLICENSED",
6
6
  "description": "",
@@ -23,14 +23,14 @@
23
23
  },
24
24
  "dependencies": {
25
25
  "@betorigami/game-calculations": "10.1.0",
26
- "@betorigami/game-ui-shared": "1.7.0",
27
- "@betorigami/game-ui-wheel": "1.1.5",
28
26
  "@lit/context": "^1.1.5",
29
27
  "big.js": "^7.0.1",
30
28
  "lit": "^3.3.0",
31
29
  "lottie-web": "^5.13.0",
32
30
  "matter-js": "^0.18.0",
33
- "web-haptics": "^0.0.6"
31
+ "web-haptics": "^0.0.6",
32
+ "@betorigami/game-ui-shared": "1.7.0",
33
+ "@betorigami/game-ui-wheel": "1.1.5"
34
34
  },
35
35
  "devDependencies": {
36
36
  "@playwright/test": "^1.53.0",