@jetthai/cuora 1.1.429 → 1.1.430-dev.0

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,
@@ -465,8 +465,10 @@ export default function (request) {
465
465
  const { providerId, gameId, gameTypeId, mappingId, portrait, gameCode, name, gameName } = context.switchGame
466
466
  return { game: { providerId, gameId, gameTypeId, mappingId, portrait: portrait ? 1 : 0, gameCode, name, gameName } }
467
467
  }),
468
+ // 頁面刷新或深層連結時,event.data.walletType 可能為 undefined/null
469
+ // 使用 ?? 確保不會覆蓋 context 中已有的 walletType,避免後端收到 selectedWalletType=null
468
470
  setWalletType: assign((context, event) => {
469
- return { walletType: event.data.walletType }
471
+ return { walletType: event.data.walletType ?? context.walletType }
470
472
  }),
471
473
  setLang: assign((context, event) => {
472
474
  const lang = event.data.locale.replace('-', '_')
@@ -638,9 +640,9 @@ export default function (request) {
638
640
  }
639
641
  },
640
642
  connectGame: async (context, event) => {
641
- // [防呆] 確保有 providerId 和 gameId
643
+ // [防呆] 確保有 providerId 和 gameId(含字串 "null"/"undefined" 檢查)
642
644
  const { providerId, gameId } = context.game || {}
643
- if (!providerId || !gameId) {
645
+ if (!providerId || !gameId || providerId === 'null' || providerId === 'undefined' || gameId === 'null' || gameId === 'undefined') {
644
646
  return
645
647
  }
646
648
  const returnProviders = ['RSG', 'KP', 'EPICWIN', 'AMBSLOT', 'SEXY_VENUS', 'SEXY_SEXYBCRT', 'PG', 'NPG']
@@ -654,7 +656,7 @@ export default function (request) {
654
656
  is_demo: false,
655
657
  is_mobile: isMobile === 'mobile' ? 'y' : null,
656
658
  lang,
657
- selected_wallet_type: walletType,
659
+ selected_wallet_type: walletType || null, // 統一 undefined → null,確保後端收到一致的值
658
660
  return_url: returnProviders.includes(providerId)
659
661
  ? `${window.location.origin}${context.base}return`
660
662
  : window.location.href?.split('?')?.[0], // For providers to return.
@@ -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
  },