@jetthai/cuora 1.1.429 → 1.1.430-dev.1

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.
@@ -56,8 +56,9 @@ export default function (request, context) {
56
56
  target: 'calculated',
57
57
  actions: 'setCalculation',
58
58
  },
59
+ // 計算失敗回到 loaded,避免進入 calculated 造成 UI 與 state 不一致
59
60
  onError: {
60
- target: 'calculated',
61
+ target: 'loaded',
61
62
  },
62
63
  },
63
64
  },
@@ -167,8 +168,10 @@ export default function (request, context) {
167
168
  setAmount: assign((context, event) => {
168
169
  // 現金網可自由填額度,grandTotalEnable 欄位感覺不再需要?
169
170
  if (context.selectedCrypto?.grandTotalEnable === 1) {
171
+ // 累加模式:用 Math.max 確保累加結果不低於 0
172
+ const result = preciseAdd(`${parseFloat(context.selectedAmount || 0)}`, `${parseFloat(event.data || '0')}`)
170
173
  return {
171
- selectedAmount: preciseAdd(`${parseFloat(context.selectedAmount || 0)}`, `${parseFloat(event.data)}`),
174
+ selectedAmount: Math.max(result, 0),
172
175
  }
173
176
  } else {
174
177
  return { selectedAmount: event.data }
@@ -231,9 +234,17 @@ export default function (request, context) {
231
234
  const { selectedCrypto, selectedAmount } = context
232
235
  return selectedCrypto && selectedAmount && selectedCrypto.minimum <= +selectedAmount && +selectedAmount <= selectedCrypto.maximum
233
236
  },
237
+ // 提交前最後一道 guard:重新驗證 amount 的合法性(與 isCalculable 同等嚴格)
234
238
  isSubmittable: (context, event) => {
235
239
  const { selectedCrypto, selectedAmount, calculation } = context
236
- return selectedCrypto && selectedAmount && calculation
240
+ return (
241
+ selectedCrypto &&
242
+ selectedAmount &&
243
+ +selectedAmount > 0 &&
244
+ selectedCrypto.minimum <= +selectedAmount &&
245
+ +selectedAmount <= selectedCrypto.maximum &&
246
+ calculation
247
+ )
237
248
  },
238
249
  },
239
250
  services: {
@@ -250,10 +261,15 @@ export default function (request, context) {
250
261
  },
251
262
  submitDeposit: async (context, event) => {
252
263
  const { selectedCrypto, selectedAmount, sourceAddress, promotion } = context
264
+ // 防禦性檢查:將 amount 轉為數字型別,並驗證範圍合法性,避免非法金額送出 API
265
+ const amount = +selectedAmount
266
+ if (!amount || amount <= 0 || amount < selectedCrypto.minimum || amount > selectedCrypto.maximum) {
267
+ throw new Error('INVALID_AMOUNT')
268
+ }
253
269
  return await request.send(
254
270
  payment.submitDepositTransactionCrypto({
255
271
  method: selectedCrypto.method,
256
- amount: selectedAmount,
272
+ amount: amount,
257
273
  cryptoCurrency: selectedCrypto.channel,
258
274
  cryptoNetwork: selectedCrypto.networkCode,
259
275
  sourceAddress: sourceAddress,
@@ -53,6 +53,7 @@ export default function (request) {
53
53
  gameWalletType: null,
54
54
  switchGame: null,
55
55
  isPlaying: false,
56
+ entry: null,
56
57
  },
57
58
  states: {
58
59
  flow: {
@@ -85,15 +86,15 @@ export default function (request) {
85
86
  },
86
87
  ENTER_GAME: {
87
88
  target: 'connecting',
88
- actions: ['setGameInfo', 'setLang', 'setWalletType'],
89
+ actions: ['setGameInfo', 'setLang', 'setEntry', 'setWalletType'],
89
90
  },
90
91
  DEMO_GAME: {
91
92
  target: 'demoGame',
92
- actions: ['setGameInfo', 'setLang', 'setSite'],
93
+ actions: ['setGameInfo', 'setLang', 'setEntry', 'setSite'],
93
94
  },
94
95
  MENU_ENTER_GAME: {
95
96
  target: 'connecting',
96
- actions: ['setGameInfo', 'setLang', 'setWalletType'],
97
+ actions: ['setGameInfo', 'setLang', 'setEntry', 'setWalletType'],
97
98
  },
98
99
  UPDATE: {
99
100
  target: 'updating',
@@ -226,14 +227,14 @@ export default function (request) {
226
227
  },
227
228
  MENU_ENTER_GAME: {
228
229
  target: 'connectSwitching',
229
- actions: ['setSwitch', 'setLang', 'setWalletType'],
230
+ actions: ['setSwitch', 'setLang', 'setEntry', 'setWalletType'],
230
231
  },
231
232
  ENTER_GAME_PAUSE: {
232
233
  actions: ['setIsPlaying', 'resetContent', 'resetSHA'],
233
234
  },
234
235
  ENTER_GAME: {
235
236
  target: 'connecting',
236
- actions: ['setGameInfo', 'setLang', 'setWalletType'],
237
+ actions: ['setGameInfo', 'setLang', 'setEntry', 'setWalletType'],
237
238
  },
238
239
  },
239
240
  },
@@ -247,7 +248,7 @@ export default function (request) {
247
248
  },
248
249
  ENTER_GAME: {
249
250
  target: 'connecting',
250
- actions: ['setGameInfo', 'setLang', 'setWalletType'],
251
+ actions: ['setGameInfo', 'setLang', 'setEntry', 'setWalletType'],
251
252
  },
252
253
  },
253
254
  },
@@ -465,13 +466,18 @@ export default function (request) {
465
466
  const { providerId, gameId, gameTypeId, mappingId, portrait, gameCode, name, gameName } = context.switchGame
466
467
  return { game: { providerId, gameId, gameTypeId, mappingId, portrait: portrait ? 1 : 0, gameCode, name, gameName } }
467
468
  }),
469
+ // 頁面刷新或深層連結時,event.data.walletType 可能為 undefined/null
470
+ // 使用 ?? 確保不會覆蓋 context 中已有的 walletType,避免後端收到 selectedWalletType=null
468
471
  setWalletType: assign((context, event) => {
469
- return { walletType: event.data.walletType }
472
+ return { walletType: event.data.walletType ?? context.walletType }
470
473
  }),
471
474
  setLang: assign((context, event) => {
472
475
  const lang = event.data.locale.replace('-', '_')
473
476
  return { lang }
474
477
  }),
478
+ setEntry: assign((context, event) => {
479
+ return { entry: event?.data?.entrySource }
480
+ }),
475
481
  setSite: assign((context, event) => {
476
482
  const site = event.data.site
477
483
  return { site }
@@ -638,13 +644,13 @@ export default function (request) {
638
644
  }
639
645
  },
640
646
  connectGame: async (context, event) => {
641
- // [防呆] 確保有 providerId 和 gameId
647
+ // [防呆] 確保有 providerId 和 gameId(含字串 "null"/"undefined" 檢查)
642
648
  const { providerId, gameId } = context.game || {}
643
- if (!providerId || !gameId) {
649
+ if (!providerId || !gameId || providerId === 'null' || providerId === 'undefined' || gameId === 'null' || gameId === 'undefined') {
644
650
  return
645
651
  }
646
652
  const returnProviders = ['RSG', 'KP', 'EPICWIN', 'AMBSLOT', 'SEXY_VENUS', 'SEXY_SEXYBCRT', 'PG', 'NPG']
647
- const { lang, isMobile, walletType } = context
653
+ const { lang, entry, isMobile, walletType } = context
648
654
  const { gameTypeId, mappingId } = context.game
649
655
  const params = {
650
656
  provider_id: providerId,
@@ -654,7 +660,8 @@ export default function (request) {
654
660
  is_demo: false,
655
661
  is_mobile: isMobile === 'mobile' ? 'y' : null,
656
662
  lang,
657
- selected_wallet_type: walletType,
663
+ entry_source: entry || 'Other',
664
+ selected_wallet_type: walletType || null, // 統一 undefined → null,確保後端收到一致的值
658
665
  return_url: returnProviders.includes(providerId)
659
666
  ? `${window.location.origin}${context.base}return`
660
667
  : window.location.href?.split('?')?.[0], // For providers to return.
@@ -663,7 +670,7 @@ export default function (request) {
663
670
  return { type, gameToken, gameHtml, gameURL: redirect_url, gameWalletType: wallet_type }
664
671
  },
665
672
  demoGame: async (context, event) => {
666
- const { lang, site, isMobile, game } = context
673
+ const { lang, entry, site, isMobile, game } = context
667
674
  const { providerId, gameId, gameTypeId, mappingId } = context.game
668
675
  const params = {
669
676
  site,
@@ -673,6 +680,7 @@ export default function (request) {
673
680
  mapping_id: mappingId,
674
681
  is_mobile: isMobile === 'mobile' ? 'y' : null,
675
682
  lang,
683
+ entry_source: entry || 'Other',
676
684
  appSecret,
677
685
  }
678
686
  const { type, redirect_url, gameToken, gameHtml, is_demo } = await request.send(api.demoGame(params))
@@ -132,7 +132,7 @@ export default function (request, context) {
132
132
  actions: 'setProcessing',
133
133
  },
134
134
  onError: {
135
- target: 'idle',
135
+ target: '#withdraw_manual_cash.calculated',
136
136
  },
137
137
  },
138
138
  },