@jetthai/cuora 1.1.430 → 1.1.431-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.
@@ -476,6 +476,9 @@ export default function (request) {
476
476
 
477
477
  const affiliateCode = storage.get('ac')
478
478
  const nickname = storage.get('nk')
479
+ const phone = storage.get('tp_phone')
480
+ const countryCode = storage.get('tp_countryCode')
481
+ const email = storage.get('tp_email')
479
482
  const messages = {
480
483
  url: window.location.href,
481
484
  channelOrders: [
@@ -497,9 +500,25 @@ export default function (request) {
497
500
  referralObj.nick_name = nickname
498
501
  }
499
502
 
503
+ if (![undefined, 'undefined', null, 'null'].includes(phone)) {
504
+ referralObj.phone = phone
505
+ }
506
+
507
+ if (![undefined, 'undefined', null, 'null'].includes(countryCode)) {
508
+ referralObj.countryCode = countryCode
509
+ }
510
+
511
+ if (![undefined, 'undefined', null, 'null'].includes(email)) {
512
+ referralObj.email = email
513
+ }
514
+
500
515
  referralObj.channel = storage.get('channel') || defaultChannel || channel
501
516
  referralObj.subchannel = storage.get('subchannel') || defaultSubchannel || subchannel
502
517
 
518
+ storage.remove('tp_phone')
519
+ storage.remove('tp_countryCode')
520
+ storage.remove('tp_email')
521
+
503
522
  const fullURL = request.config.fullURL
504
523
 
505
524
  const redirectURL = urljoin(
@@ -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,14 +168,22 @@ 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)}`)
170
173
  return {
171
- selectedAmount: preciseAdd(`${parseFloat(context.selectedAmount || 0)}`, `${parseFloat(event.data)}`),
174
+ selectedAmount: Math.max(result, 0),
172
175
  }
173
176
  } else {
177
+ // 直接設定模式:拒絕 NaN 及負數,返回空物件使 context 不變
178
+ const val = parseFloat(event.data)
179
+ if (isNaN(val) || val < 0) return {}
174
180
  return { selectedAmount: event.data }
175
181
  }
176
182
  }),
177
183
  inputAmount: assign((context, event) => {
184
+ // 驗證輸入值:NaN 或負數時忽略此次輸入
185
+ const val = parseFloat(event.data)
186
+ if (isNaN(val) || val < 0) return {}
178
187
  return { selectedAmount: event.data }
179
188
  }),
180
189
  setAddress: assign((context, event) => {
@@ -231,9 +240,17 @@ export default function (request, context) {
231
240
  const { selectedCrypto, selectedAmount } = context
232
241
  return selectedCrypto && selectedAmount && selectedCrypto.minimum <= +selectedAmount && +selectedAmount <= selectedCrypto.maximum
233
242
  },
243
+ // 提交前最後一道 guard:重新驗證 amount 的合法性(與 isCalculable 同等嚴格)
234
244
  isSubmittable: (context, event) => {
235
245
  const { selectedCrypto, selectedAmount, calculation } = context
236
- return selectedCrypto && selectedAmount && calculation
246
+ return (
247
+ selectedCrypto &&
248
+ selectedAmount &&
249
+ +selectedAmount > 0 &&
250
+ selectedCrypto.minimum <= +selectedAmount &&
251
+ +selectedAmount <= selectedCrypto.maximum &&
252
+ calculation
253
+ )
237
254
  },
238
255
  },
239
256
  services: {
@@ -250,10 +267,15 @@ export default function (request, context) {
250
267
  },
251
268
  submitDeposit: async (context, event) => {
252
269
  const { selectedCrypto, selectedAmount, sourceAddress, promotion } = context
270
+ // 防禦性檢查:將 amount 轉為數字型別,並驗證範圍合法性,避免非法金額送出 API
271
+ const amount = +selectedAmount
272
+ if (!amount || amount <= 0 || amount < selectedCrypto.minimum || amount > selectedCrypto.maximum) {
273
+ throw new Error('INVALID_AMOUNT')
274
+ }
253
275
  return await request.send(
254
276
  payment.submitDepositTransactionCrypto({
255
277
  method: selectedCrypto.method,
256
- amount: selectedAmount,
278
+ amount: amount,
257
279
  cryptoCurrency: selectedCrypto.channel,
258
280
  cryptoNetwork: selectedCrypto.networkCode,
259
281
  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.