@jetthai/cuora 1.1.427-qa.1 → 1.1.428-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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jetthai/cuora",
3
- "version": "1.1.427-qa.1",
3
+ "version": "1.1.428-dev.0",
4
4
  "description": "",
5
5
  "main": "./src/index.js",
6
6
  "type": "module",
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env node
2
+ // Copyright 2024 The Terasology Foundation
2
3
 
3
4
  // dev/qa 分支自動計算下一個 prerelease 版號
4
5
  // 版號格式:{master 版號}-{分支名}.{遞增編號}
@@ -120,4 +120,9 @@ export default {
120
120
  method: 'post',
121
121
  params: { startDate, endDate, appSecret },
122
122
  }),
123
+ getMissionHistory: ({ activityNo, appSecret }) => ({
124
+ url: 'activities/mission-history',
125
+ method: 'get',
126
+ params: { activityNo, appSecret },
127
+ }),
123
128
  }
@@ -110,6 +110,28 @@ export default function (request) {
110
110
  },
111
111
  },
112
112
  otpChecking: {
113
+ initial: 'pending',
114
+ states: {
115
+ pending: {
116
+ after: {
117
+ TIMEOUT: {
118
+ target: 'fetching',
119
+ },
120
+ },
121
+ },
122
+ fetching: {
123
+ invoke: {
124
+ src: 'fetchUserInfo',
125
+ onDone: {
126
+ target: 'pending',
127
+ actions: ['setUserInfo', 'extendToken'],
128
+ },
129
+ onError: {
130
+ target: 'pending',
131
+ },
132
+ },
133
+ },
134
+ },
113
135
  on: {
114
136
  OTP_VERIFIED: {
115
137
  target: 'loginSuccess',
@@ -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,