@maktubbet/sdk 3.2.24 → 3.3.3

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.
@@ -16751,6 +16751,39 @@ function useCrashSocket({ enabled, accessToken, onMessage }) {
16751
16751
 
16752
16752
  // src/crash/components/CrashGameInner.tsx
16753
16753
  var import_jsx_runtime72 = require("react/jsx-runtime");
16754
+ var SS_ROUND_KEY = "__maktub_crash_round";
16755
+ var SS_BET_KEY = "__maktub_crash_bet_round";
16756
+ var SS_CASHOUT_KEY = "__maktub_crash_cashout_round";
16757
+ function getCurrentRoundId() {
16758
+ try {
16759
+ return sessionStorage.getItem(SS_ROUND_KEY);
16760
+ } catch {
16761
+ return null;
16762
+ }
16763
+ }
16764
+ function setCurrentRoundId(roundId) {
16765
+ try {
16766
+ sessionStorage.setItem(SS_ROUND_KEY, roundId);
16767
+ } catch {
16768
+ }
16769
+ }
16770
+ function wasProcessed(key) {
16771
+ const roundId = getCurrentRoundId();
16772
+ if (!roundId) return false;
16773
+ try {
16774
+ return sessionStorage.getItem(key) === roundId;
16775
+ } catch {
16776
+ return false;
16777
+ }
16778
+ }
16779
+ function markProcessed(key) {
16780
+ const roundId = getCurrentRoundId();
16781
+ if (!roundId) return;
16782
+ try {
16783
+ sessionStorage.setItem(key, roundId);
16784
+ } catch {
16785
+ }
16786
+ }
16754
16787
  var GROWTH_SPEED = 6e-5;
16755
16788
  function CrashGame({ userName }) {
16756
16789
  const betSound2 = useSoundEffect(bet_default);
@@ -16809,6 +16842,9 @@ function CrashGame({ userName }) {
16809
16842
  switch (msg.type) {
16810
16843
  case "round:phase": {
16811
16844
  const serverPhase = msg.phase;
16845
+ if (msg.roundId) {
16846
+ setCurrentRoundId(msg.roundId);
16847
+ }
16812
16848
  if (serverPhase === "waiting") {
16813
16849
  setPhase("waiting");
16814
16850
  setRoundBets([]);
@@ -16888,18 +16924,24 @@ function CrashGame({ userName }) {
16888
16924
  };
16889
16925
  setRoundBets((prev) => [...prev.filter((b) => b.userId !== msg.userId), entry]);
16890
16926
  if (msg.userId === socket.userId) {
16891
- userHasBetRef.current = true;
16892
- setUserHasBet(true);
16893
- setIsMutating(false);
16894
- setActiveBetData({
16895
- id: `ws-bet-${Date.now()}`,
16896
- game: "crash",
16897
- isActive: true,
16898
- amount: msg.amount,
16899
- payout: 0,
16900
- payoutMultiplier: 0,
16901
- state: { crashPoint: 0, cashoutMultiplier: 0 }
16902
- });
16927
+ if (!wasProcessed(SS_BET_KEY)) {
16928
+ markProcessed(SS_BET_KEY);
16929
+ if (msg.amount > 0) {
16930
+ setBalanceSync(balanceRef.current - msg.amount);
16931
+ }
16932
+ userHasBetRef.current = true;
16933
+ setUserHasBet(true);
16934
+ setIsMutating(false);
16935
+ setActiveBetData({
16936
+ id: `ws-bet-${Date.now()}`,
16937
+ game: "crash",
16938
+ isActive: true,
16939
+ amount: msg.amount,
16940
+ payout: 0,
16941
+ payoutMultiplier: 0,
16942
+ state: { crashPoint: 0, cashoutMultiplier: 0 }
16943
+ });
16944
+ }
16903
16945
  }
16904
16946
  break;
16905
16947
  }
@@ -16908,11 +16950,15 @@ function CrashGame({ userName }) {
16908
16950
  (b) => b.userId === msg.userId ? { ...b, cashoutMultiplier: msg.multiplier, payout: msg.payout } : b
16909
16951
  ));
16910
16952
  if (msg.userId === socket.userId) {
16953
+ console.log("[crash-sdk] bet:cashedOut", { userId: msg.userId, socketUserId: socket.userId, payout: msg.payout, wasProcessed: wasProcessed(SS_CASHOUT_KEY), roundId: getCurrentRoundId(), storedCashout: sessionStorage.getItem(SS_CASHOUT_KEY), balanceBefore: balanceRef.current });
16954
+ if (wasProcessed(SS_CASHOUT_KEY)) break;
16955
+ markProcessed(SS_CASHOUT_KEY);
16911
16956
  userCashedOutRef.current = true;
16912
16957
  setUserCashedOut(true);
16913
16958
  winSound2.play();
16914
16959
  const payout = msg.payout;
16915
16960
  const newBalance = balanceRef.current + payout;
16961
+ console.log("[crash-sdk] setBalanceSync", { payout, newBalance });
16916
16962
  setBalanceSync(newBalance);
16917
16963
  setIsMutating(false);
16918
16964
  addStat({
@@ -16937,6 +16983,9 @@ function CrashGame({ userName }) {
16937
16983
  break;
16938
16984
  }
16939
16985
  case "bet:rejected": {
16986
+ if (betAmountRef.current > 0 && userHasBetRef.current === false) {
16987
+ setBalanceSync(balanceRef.current + betAmountRef.current);
16988
+ }
16940
16989
  setUserHasBet(false);
16941
16990
  setIsMutating(false);
16942
16991
  if (wsBetResultRef.current) {
@@ -17177,7 +17226,6 @@ function CrashGame({ userName }) {
17177
17226
  status: "lose"
17178
17227
  };
17179
17228
  }
17180
- setBalanceSync(balance - amount);
17181
17229
  setIsMutating(true);
17182
17230
  socket.send({ type: "bet:place", amount, autoCashout: autoCashoutTarget });
17183
17231
  return {