@jetthai/cuora 1.1.488 → 2.0.0-beta.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.
Files changed (212) hide show
  1. package/.husky/pre-commit +3 -1
  2. package/BREAKING_CHANGES.md +9 -0
  3. package/CHANGELOG.md +3 -316
  4. package/README.md +15 -299
  5. package/package.json +5 -5
  6. package/resetGitBranch.sh +101 -0
  7. package/src/api/account.js +1 -0
  8. package/src/api/activity.js +39 -24
  9. package/src/api/auth.js +36 -5
  10. package/src/api/common.js +3 -5
  11. package/src/api/game.js +10 -0
  12. package/src/api/payment.js +55 -17
  13. package/src/api/user.js +16 -10
  14. package/src/index.js +2 -2
  15. package/src/lib/fingerprint_v3_11_12.js +11433 -0
  16. package/src/machine/activity/activity.js +213 -0
  17. package/src/machine/activity/activity_cash.js +36 -84
  18. package/src/machine/activity/cash_rain_activity.js +1 -0
  19. package/src/machine/activity/continue_deposit_activity.js +1 -0
  20. package/src/machine/activity/deposit_activity.js +1 -0
  21. package/src/machine/activity/diamond_shop_activity_cash.js +8 -0
  22. package/src/machine/activity/diamond_shop_activity_fc.js +197 -0
  23. package/src/machine/activity/diamond_shop_activity_vn.js +179 -0
  24. package/src/machine/activity/fafafa_activity.js +11 -0
  25. package/src/machine/activity/friend_invite_friends_activity.js +7 -8
  26. package/src/machine/activity/index.js +12 -0
  27. package/src/machine/activity/instant_rebate_activity.js +1 -0
  28. package/src/machine/activity/invite_friends_activity.js +115 -0
  29. package/src/machine/activity/jackpot.js +1 -0
  30. package/src/machine/activity/mini_game_activity.js +69 -0
  31. package/src/machine/activity/otp_verified_activity.js +1 -0
  32. package/src/machine/activity/ranking_activity.js +1 -0
  33. package/src/machine/activity/return_bonus_activity.js +155 -0
  34. package/src/machine/activity/roulette_activity_v2.js +1 -0
  35. package/src/machine/activity/sign_in_activity.js +1 -0
  36. package/src/machine/activity/sign_in_monthly_activity.js +2 -1
  37. package/src/machine/activity/specify_bets_activity.js +1 -0
  38. package/src/machine/activity/specify_turnover_activity.js +1 -0
  39. package/src/machine/activity/time_bomb_activity.js +1 -0
  40. package/src/machine/activity/vip_card_activity.js +1 -0
  41. package/src/machine/auth.js +112 -149
  42. package/src/machine/auth_otp_v2.js +178 -0
  43. package/src/machine/auth_otp_v3.js +22 -64
  44. package/src/machine/bank_binding.js +3 -2
  45. package/src/machine/bank_binding_amb.js +146 -0
  46. package/src/machine/bonus.js +76 -0
  47. package/src/machine/common.js +98 -14
  48. package/src/machine/deposit/amb.js +93 -0
  49. package/src/machine/deposit/crypto_bank.js +340 -0
  50. package/src/machine/deposit/crypto_bank_cash.js +35 -20
  51. package/src/machine/deposit/crypto_qrcode.js +158 -0
  52. package/src/machine/deposit/crypto_qrcode_cash.js +64 -26
  53. package/src/machine/deposit/crypto_way.js +253 -0
  54. package/src/machine/deposit/crypto_way_cash.js +37 -48
  55. package/src/machine/deposit/deposit_fc.js +272 -0
  56. package/src/machine/deposit/direct.js +311 -0
  57. package/src/machine/deposit/direct_cash.js +10 -8
  58. package/src/machine/deposit/float.js +375 -0
  59. package/src/machine/deposit/index.js +28 -0
  60. package/src/machine/deposit/krway.js +152 -0
  61. package/src/machine/deposit/loadcard_cash.js +32 -14
  62. package/src/machine/deposit/loadcard_vn.js +352 -0
  63. package/src/machine/deposit/manual_cash.js +11 -8
  64. package/src/machine/deposit/manual_vn.js +459 -0
  65. package/src/machine/deposit/qrcode_cash.js +32 -15
  66. package/src/machine/deposit/qrcode_v2.js +339 -0
  67. package/src/machine/deposit/usdt.js +163 -0
  68. package/src/machine/deposit/usdt_cash.js +15 -1
  69. package/src/machine/deposit/virtual_bank_cash.js +12 -13
  70. package/src/machine/deposit/virtual_bank_vn.js +270 -0
  71. package/src/machine/deposit/vpay.js +374 -0
  72. package/src/machine/error.js +1 -7
  73. package/src/machine/game_betslip.js +1 -0
  74. package/src/machine/game_favorite_v2.js +1 -0
  75. package/src/machine/game_hot_new.js +80 -0
  76. package/src/machine/game_info.js +13 -1
  77. package/src/machine/game_replay.js +47 -0
  78. package/src/machine/game_search_cash.js +1 -0
  79. package/src/machine/game_search_v2.js +402 -0
  80. package/src/machine/game_v2_1.js +126 -39
  81. package/src/machine/honor_board.js +133 -0
  82. package/src/machine/honor_board_cash.js +28 -22
  83. package/src/machine/inbox.js +105 -43
  84. package/src/machine/index.js +32 -0
  85. package/src/machine/leaderboard.js +12 -8
  86. package/src/machine/merge.js +58 -0
  87. package/src/machine/navbar.js +3 -1
  88. package/src/machine/payment_data.js +87 -0
  89. package/src/machine/promotions.js +163 -0
  90. package/src/machine/ranking.js +30 -45
  91. package/src/machine/reward.js +256 -0
  92. package/src/machine/reward_cash.js +42 -2
  93. package/src/machine/reward_fc.js +99 -0
  94. package/src/machine/roulette_v2.js +11 -14
  95. package/src/machine/setting.js +1 -0
  96. package/src/machine/side.js +160 -0
  97. package/src/machine/side_cash.js +3 -3
  98. package/src/machine/side_v2.js +223 -0
  99. package/src/machine/user_info.js +1 -0
  100. package/src/machine/user_photo.js +1 -0
  101. package/src/machine/user_reset_password.js +14 -0
  102. package/src/machine/user_sign_up.js +61 -46
  103. package/src/machine/vip_table.js +58 -0
  104. package/src/machine/websocket.js +349 -374
  105. package/src/machine/welcome.js +111 -0
  106. package/src/machine/withdraw/index.js +6 -0
  107. package/src/machine/withdraw/withdraw_crypto_cash.js +328 -0
  108. package/src/machine/withdraw/withdraw_krway.js +223 -0
  109. package/src/machine/withdraw/withdraw_manual.js +541 -0
  110. package/src/machine/withdraw/withdraw_manual_cash.js +39 -59
  111. package/src/request/config.js +0 -2
  112. package/src/request/request.js +60 -124
  113. package/src/util/constant.js +2 -6
  114. package/src/util/deviceToken.js +60 -0
  115. package/src/util/index.js +4 -2
  116. package/src/util/math.js +4 -0
  117. package/src/util/storage.js +4 -3
  118. package/test/api.behavior.test.js +69 -0
  119. package/test/api.contract.test.js +18 -0
  120. package/test/config.test.js +27 -0
  121. package/test/deviceToken.test.js +139 -0
  122. package/test/helpers.coverage.test.js +11 -0
  123. package/test/helpers.js +91 -0
  124. package/test/index.exports.test.js +14 -0
  125. package/test/machine.activity.core.coverage.test.js +337 -0
  126. package/test/machine.activity.gap.coverage.test.js +252 -0
  127. package/test/machine.activity.more.coverage.test.js +180 -0
  128. package/test/machine.activity_plus_and_binding_amb.coverage.test.js +201 -0
  129. package/test/machine.activity_timer_bonus.coverage.test.js +136 -0
  130. package/test/machine.activity_welcome.low.coverage.test.js +211 -0
  131. package/test/machine.amb_rewardfc_websocket.more.coverage.test.js +201 -0
  132. package/test/machine.auth.coverage.test.js +215 -0
  133. package/test/machine.bank_binding.test.js +143 -0
  134. package/test/machine.binding_otp_krway.coverage.test.js +223 -0
  135. package/test/machine.contract.test.js +50 -0
  136. package/test/machine.crypto_bank.coverage.test.js +270 -0
  137. package/test/machine.crypto_way.coverage.test.js +108 -0
  138. package/test/machine.crypto_way_cash.coverage.test.js +114 -0
  139. package/test/machine.definition.test.js +137 -0
  140. package/test/machine.deposit.manual.coverage.test.js +365 -0
  141. package/test/machine.deposit_fc.coverage.test.js +126 -0
  142. package/test/machine.direct.coverage.test.js +96 -0
  143. package/test/machine.direct_cash.coverage.test.js +108 -0
  144. package/test/machine.error.coverage.test.js +37 -0
  145. package/test/machine.events.test.js +126 -0
  146. package/test/machine.favorite_jackpot.coverage.test.js +82 -0
  147. package/test/machine.float.coverage.test.js +136 -0
  148. package/test/machine.flow.test.js +226 -0
  149. package/test/machine.game_hot_new_vip_table.coverage.test.js +105 -0
  150. package/test/machine.game_search_cash.coverage.test.js +155 -0
  151. package/test/machine.game_search_v2.test.js +199 -0
  152. package/test/machine.game_user_profile.coverage.test.js +100 -0
  153. package/test/machine.honor_board.test.js +133 -0
  154. package/test/machine.inbox.common.coverage.test.js +304 -0
  155. package/test/machine.loadcard_cash.coverage.test.js +101 -0
  156. package/test/machine.loadcard_vn.coverage.test.js +122 -0
  157. package/test/machine.misc.coverage.test.js +361 -0
  158. package/test/machine.more2.coverage.test.js +261 -0
  159. package/test/machine.options.execution.test.js +272 -0
  160. package/test/machine.priority.coverage.test.js +603 -0
  161. package/test/machine.qrcode_cash.coverage.test.js +107 -0
  162. package/test/machine.qrcode_v2.coverage.test.js +121 -0
  163. package/test/machine.regression.test.js +82 -0
  164. package/test/machine.roulette_v2.test.js +142 -0
  165. package/test/machine.side_reward_reset.coverage.test.js +220 -0
  166. package/test/machine.targeted.coverage.test.js +313 -0
  167. package/test/machine.usdt.coverage.test.js +95 -0
  168. package/test/machine.usdt_cash.coverage.test.js +73 -0
  169. package/test/machine.vip_card_activity.test.js +114 -0
  170. package/test/machine.virtual_bank_cash.coverage.test.js +105 -0
  171. package/test/machine.virtual_bank_vn.coverage.test.js +105 -0
  172. package/test/machine.vpay.coverage.test.js +142 -0
  173. package/test/machine.withdraw_crypto_cash.coverage.test.js +166 -0
  174. package/test/machine.withdraw_krway.coverage.test.js +123 -0
  175. package/test/machine.withdraw_manual.coverage.test.js +185 -0
  176. package/test/machine.withdraw_manual_cash.coverage.test.js +123 -0
  177. package/test/request.test.js +325 -0
  178. package/test/util.storage.errors.test.js +47 -0
  179. package/test/util.test.js +41 -0
  180. package/.claude/commands/sync-ai-prompts.md +0 -93
  181. package/.claude/settings.local.json +0 -23
  182. package/.github/copilot-instructions.md +0 -448
  183. package/.husky/post-checkout +0 -32
  184. package/.husky/pre-push +0 -36
  185. package/AGENTS.md +0 -448
  186. package/AI_PROMPT_SOURCE.md +0 -446
  187. package/CLAUDE.md +0 -448
  188. package/GEMINI.md +0 -448
  189. package/docs/kibana/crypto-way-deposit-amount-bug-analysis.md +0 -1003
  190. package/docs/kibana/play-providerId-error.md +0 -202
  191. package/docs/kibana/play-selectedWalletType.md +0 -1
  192. package/docs/kibana/play-selectedWalletType_2.md +0 -1
  193. package/docs/kibana/play-selectedWalletType_analysis.md +0 -565
  194. package/docs/my-claude/feat-sharon-JT-1790247240-socket/branch-transfer.md +0 -14
  195. package/docs/my-claude/feat-sharon-JT-1790247240-socket/cash-module-preparation.json +0 -40
  196. package/docs/my-claude/feat-sharon-JT-1790247240-socket/cash-module-verification.md +0 -41
  197. package/docs/my-claude/feat-sharon-JT-1790247240-socket/implementation-ledger.md +0 -87
  198. package/docs/my-claude/feat-sharon-JT-1790247240-socket/module-report.md +0 -73
  199. package/docs/my-claude/feat-sharon-JT-1790247240-socket/plan.md +0 -309
  200. package/docs/my-claude/feat-sharon-JT-1790247240-socket/test-cases.md +0 -245
  201. package/docs/my-claude/feat-sharon-JT-1791180540-onesignal/transfer.md +0 -9
  202. package/scripts/auto-version.js +0 -68
  203. package/scripts/auto-version.sh +0 -33
  204. package/scripts/branch-auto-npm-publish.js +0 -29
  205. package/scripts/check-version.sh +0 -36
  206. package/scripts/clean-tags.sh +0 -84
  207. package/src/util/amount.js +0 -8
  208. package/src/util/err998SentryExtra.js +0 -26
  209. package/src/util/paramStore.js +0 -139
  210. package/src/util/socketPolicy.js +0 -57
  211. package/test/auth_otp_v3.test.js +0 -323
  212. package/tests/websocket.test.mjs +0 -779
@@ -0,0 +1,459 @@
1
+ import { assign, createMachine } from 'xstate'
2
+ import payment from '../../api/payment.js'
3
+
4
+ export default function (request) {
5
+ const { appSecret } = request.config
6
+
7
+ return createMachine(
8
+ {
9
+ id: 'manual',
10
+ predictableActionArguments: true,
11
+ initial: 'loading',
12
+ context: {
13
+ siteConfig: null,
14
+ paymentDetail: [],
15
+ allBankList: [],
16
+ houseBanks: [],
17
+ playerBanks: [],
18
+
19
+ amount: null,
20
+ selectedHouseBank: null,
21
+ selectedUserBank: null,
22
+ userAccountNumber: null,
23
+ userIfscCode: null,
24
+ userAccountName: null,
25
+ userAccountBranchName: null,
26
+ userAccountBranchCode: null,
27
+ transactionId: null,
28
+ depositTime: null,
29
+ receipt: null,
30
+
31
+ currentCategory: 'manual',
32
+ method: null,
33
+ currentPayment: null,
34
+ currentApplyerBank: null,
35
+
36
+ calculation: null,
37
+ processing: null,
38
+
39
+ // use for wallet mode 3
40
+ promotion: null,
41
+ },
42
+ states: {
43
+ loading: {
44
+ initial: 'init1',
45
+ states: {
46
+ init1: {
47
+ invoke: {
48
+ src: 'fetchPaymentDetail',
49
+ onDone: {
50
+ target: 'init2',
51
+ actions: 'setInitData',
52
+ },
53
+ onError: {
54
+ target: '#manual.fail',
55
+ },
56
+ },
57
+ },
58
+ init2: {
59
+ always: [
60
+ {
61
+ target: '#manual.processing',
62
+ cond: 'isProcessing',
63
+ },
64
+ ],
65
+ invoke: {
66
+ src: 'fetchBanks',
67
+ onDone: {
68
+ target: '#manual.step1',
69
+ actions: 'setBanks',
70
+ },
71
+ onError: {
72
+ target: '#manual.fail',
73
+ },
74
+ },
75
+ },
76
+ },
77
+ },
78
+ step1: {
79
+ initial: 'idle',
80
+ states: {
81
+ idle: {},
82
+ calculating: {
83
+ invoke: {
84
+ src: 'fetchCalculation',
85
+ onDone: {
86
+ target: 'idle',
87
+ actions: 'setCalculation',
88
+ },
89
+ onError: {
90
+ target: 'idle',
91
+ },
92
+ },
93
+ },
94
+ debouncing: {
95
+ after: {
96
+ 1000: [{ target: 'calculating', cond: 'isCalculable' }, { target: 'idle' }],
97
+ },
98
+ },
99
+ },
100
+ on: {
101
+ SET_AMOUNT: {
102
+ actions: ['setAmount', 'clearCalculation'],
103
+ },
104
+ CALCULATE: {
105
+ target: '.debouncing',
106
+ },
107
+ SELECT_HOUSE_BANK: {
108
+ actions: 'setHouseBank',
109
+ },
110
+ CLEAR_CALCULATION: {
111
+ target: '.debouncing',
112
+ actions: 'clearCalculation',
113
+ },
114
+ TRANSACT: {
115
+ target: 'checking',
116
+ cond: 'isCalculated',
117
+ },
118
+ },
119
+ },
120
+ checking: {
121
+ always: [
122
+ {
123
+ target: 'pending',
124
+ cond: (context, event) => {
125
+ const { calculation, promotion } = context
126
+ const { promotionsNo, activityNo } = promotion
127
+ const isNoBonus = promotionsNo === 'none' || activityNo === 'none'
128
+ return !!calculation && !isNoBonus
129
+ },
130
+ },
131
+ {
132
+ target: '#manual.step2',
133
+ },
134
+ ],
135
+ },
136
+ pending: {
137
+ on: {
138
+ CONFIRM: {
139
+ target: '#manual.step2',
140
+ },
141
+ },
142
+ },
143
+ step2: {
144
+ initial: 'idle',
145
+ states: {
146
+ idle: {},
147
+ calculating: {
148
+ invoke: {
149
+ src: 'fetchCalculation',
150
+ onDone: {
151
+ target: 'idle',
152
+ actions: 'setCalculation',
153
+ },
154
+ onError: {
155
+ target: 'idle',
156
+ },
157
+ },
158
+ },
159
+ debouncing: {
160
+ after: {
161
+ 1000: [{ target: 'calculating', cond: 'isCalculable' }, { target: 'idle' }],
162
+ },
163
+ },
164
+ submitting: {
165
+ invoke: {
166
+ src: 'submitDeposit',
167
+ onDone: {
168
+ target: '#manual.submitted',
169
+ actions: 'setProcessing',
170
+ },
171
+ onError: {
172
+ target: 'idle',
173
+ },
174
+ },
175
+ },
176
+ },
177
+ on: {
178
+ SET_AMOUNT: {
179
+ actions: ['setAmount', 'clearCalculation'],
180
+ },
181
+ CALCULATE: {
182
+ target: '.debouncing',
183
+ },
184
+ SELECT_HOUSE_BANK: {
185
+ actions: 'setHouseBank',
186
+ },
187
+ SELECT_USER_BANK: {
188
+ actions: 'setUserBank',
189
+ },
190
+ INPUT_USER_ACCOUNT_BRANCH_NAME: {
191
+ actions: 'setUserAccountBranchName',
192
+ },
193
+ INPUT_USER_ACCOUNT_BRANCH_CODE: {
194
+ actions: 'setUserAccountBranchCode',
195
+ },
196
+ INPUT_USER_ACCOUNT_NUMBER: {
197
+ actions: 'setUserAccountNumber',
198
+ },
199
+ INPUT_USER_IFSC_CODE: {
200
+ actions: 'setUserIfscCode',
201
+ },
202
+ INPUT_TRANSACTION_ID: {
203
+ actions: 'setTransactionId',
204
+ },
205
+ INPUT_USER_ACCOUNT_NAME: {
206
+ actions: 'setUserAccountName',
207
+ },
208
+ SET_DEPOSIT_TIME: {
209
+ actions: 'setDepositTime',
210
+ },
211
+ SET_RECEIPT: {
212
+ actions: 'setReceipt',
213
+ },
214
+ CLEAR_CALCULATION: {
215
+ target: '.debouncing',
216
+ actions: 'clearCalculation',
217
+ },
218
+ SUBMIT: {
219
+ target: '.submitting',
220
+ },
221
+ },
222
+ },
223
+ processing: {},
224
+ submitted: {},
225
+ fail: {},
226
+ },
227
+ on: {
228
+ SET_PROMOTION: {
229
+ actions: 'setPromotion',
230
+ },
231
+ },
232
+ },
233
+ {
234
+ actions: {
235
+ setInitData: assign((context, event) => {
236
+ const paymentDetail = event.data || []
237
+ const currentPayment = paymentDetail.find((element) => element.category === context.currentCategory)
238
+ const { method, banks = [], processing } = currentPayment || {}
239
+ const houseBanks = banks.map((item) => {
240
+ item.bankCode = item.bankName
241
+ return item
242
+ })
243
+
244
+ return {
245
+ paymentDetail,
246
+ currentPayment,
247
+ method,
248
+ houseBanks,
249
+ selectedHouseBank: houseBanks[0],
250
+ processing: processing?.[0],
251
+ }
252
+ }),
253
+ setBanks: assign((context, event) => {
254
+ const { bindingPaymentInfo = {}, bindingPaymentList = {} } = event.data || {}
255
+ const userBankLsit = bindingPaymentInfo.bankList || []
256
+ const allBankList = bindingPaymentList.bankList || []
257
+ const { currentPayment, houseBanks, selectedHouseBank } = context
258
+ const { banks = [] } = currentPayment
259
+
260
+ const formettedPlayerBanks = userBankLsit.map((bank) => {
261
+ bank.shortName = `${bank.bankCode} ${bank.accountNumber.slice(-5)}`
262
+ bank.imageUrl = allBankList.find((item) => item.bankCode === bank.bankCode)?.imageUrl
263
+ return bank
264
+ })
265
+ const playerBanks = [...formettedPlayerBanks, ...allBankList]
266
+
267
+ const newHouseBanks = houseBanks.map((houseBank) => {
268
+ return { ...houseBank, ...allBankList.find((bank) => houseBank.bankName === bank.bankCode) }
269
+ })
270
+ const newSelectedHouseBank = { ...selectedHouseBank, ...allBankList.find((bank) => selectedHouseBank.bankName === bank.bankCode) }
271
+
272
+ return {
273
+ playerBanks,
274
+ houseBanks: newHouseBanks,
275
+ selectedHouseBank: newSelectedHouseBank,
276
+ selectedUserBank: playerBanks[0],
277
+ userAccountNumber: playerBanks[0].accountNumber,
278
+ userIfscCode: playerBanks[0].ifscCode,
279
+ userAccountName: playerBanks[0].holderName,
280
+ userAccountBranchName: playerBanks[0].branch,
281
+ userAccountBranchCode: playerBanks[0].branchCode,
282
+ }
283
+ }),
284
+ setHouseBank: assign((context, event) => {
285
+ return {
286
+ selectedHouseBank: event.data,
287
+ }
288
+ }),
289
+ setAmount: assign((context, event) => {
290
+ return {
291
+ amount: event.data,
292
+ }
293
+ }),
294
+ setCalculation: assign((context, event) => {
295
+ // V2接口轉換中回傳的資料結構不同
296
+ const { data } = event.data
297
+ if (data) {
298
+ return {
299
+ calculation: data,
300
+ }
301
+ } else {
302
+ return {
303
+ calculation: event.data,
304
+ }
305
+ }
306
+ }),
307
+ setProcessing: assign((context, event) => {
308
+ return {
309
+ processing: event.data,
310
+ }
311
+ }),
312
+ clearCalculation: assign((context, event) => {
313
+ return {
314
+ calculation: null,
315
+ }
316
+ }),
317
+ setUserBank: assign((context, event) => {
318
+ const { accountNumber, ifscCode, holderName, branch, branchCode } = event.data
319
+ return {
320
+ selectedUserBank: event.data,
321
+ userAccountNumber: accountNumber,
322
+ userIfscCode: ifscCode,
323
+ userAccountName: holderName,
324
+ userAccountBranchName: branch,
325
+ userAccountBranchCode: branchCode,
326
+ }
327
+ }),
328
+ setUserAccountBranchName: assign((context, event) => {
329
+ return {
330
+ userAccountBranchName: event.data,
331
+ }
332
+ }),
333
+ setUserAccountBranchCode: assign((context, event) => {
334
+ return {
335
+ userAccountBranchCode: event.data,
336
+ }
337
+ }),
338
+ setUserAccountNumber: assign((context, event) => {
339
+ return {
340
+ userAccountNumber: event.data,
341
+ }
342
+ }),
343
+ setUserIfscCode: assign((context, event) => {
344
+ return {
345
+ userIfscCode: event.data,
346
+ }
347
+ }),
348
+ setTransactionId: assign((context, event) => {
349
+ return {
350
+ transactionId: event.data,
351
+ }
352
+ }),
353
+ setUserAccountName: assign((context, event) => {
354
+ return {
355
+ userAccountName: event.data,
356
+ }
357
+ }),
358
+ setDepositTime: assign((context, event) => {
359
+ return {
360
+ depositTime: event.data,
361
+ }
362
+ }),
363
+ setReceipt: assign((context, event) => {
364
+ return {
365
+ receipt: event.data,
366
+ }
367
+ }),
368
+ setPromotion: assign((context, event) => {
369
+ return {
370
+ promotion: event.data,
371
+ }
372
+ }),
373
+ setPromotionDefaultAmount: assign((context, event) => {
374
+ return {
375
+ amount: context.promotion.minimumAmount,
376
+ }
377
+ }),
378
+ },
379
+ guards: {
380
+ isCalculable: (context, event) => {
381
+ const {
382
+ amount,
383
+ currentPayment: { maximum, minimum },
384
+ } = context
385
+ return amount && minimum <= +amount && +amount <= maximum
386
+ },
387
+ isCalculated: (context, event) => {
388
+ return context.calculation
389
+ },
390
+ isProcessing: (context, event) => {
391
+ return context.processing
392
+ },
393
+ hasMinPromotionDeposit: (context, event) => {
394
+ return context.promotion?.minimumAmount
395
+ },
396
+ },
397
+ services: {
398
+ fetchPaymentDetail: async (context, event) => {
399
+ return await request.send(payment.getPaymentDetail({ transferType: 'DEPOSIT' }))
400
+ },
401
+ fetchBanks: async (context, event) => {
402
+ const [bindingPaymentInfo, bindingPaymentList] = await Promise.all([
403
+ request.send(payment.getBindingPaymentInfo({ appSecret })),
404
+ request.send(payment.getBindingPaymentList({ appSecret })),
405
+ ])
406
+
407
+ return { bindingPaymentInfo, bindingPaymentList }
408
+ },
409
+ fetchCalculation: async (context, event) => {
410
+ const { method, amount, promotion } = context
411
+ return await request.send(
412
+ payment.getDepositExpectedResult({
413
+ method,
414
+ amount: Number(amount),
415
+ promotionsNo: promotion?.activityNo,
416
+ })
417
+ )
418
+ },
419
+ submitDeposit: async (context, event) => {
420
+ const {
421
+ method,
422
+ amount,
423
+ selectedHouseBank,
424
+ selectedUserBank,
425
+ userAccountNumber,
426
+ userIfscCode,
427
+ userAccountName,
428
+ userAccountBranchName,
429
+ userAccountBranchCode,
430
+ transactionId,
431
+ depositTime,
432
+ receipt,
433
+ promotion,
434
+ } = context
435
+ return await request.send(
436
+ payment.submitDepositTransactionBank({
437
+ method,
438
+ amount,
439
+ targetBankCode: selectedHouseBank.bankName,
440
+ targetAccountNumber: selectedHouseBank.accountNumber,
441
+ targetIfscCode: selectedHouseBank.ifscCode,
442
+ targetUpi: selectedHouseBank.upi,
443
+ applyerBankCode: selectedUserBank.bankCode,
444
+ applyerAccountNumber: userAccountNumber,
445
+ applyerIfscCode: userIfscCode,
446
+ applyerHolderName: userAccountName,
447
+ applyerBranch: userAccountBranchName,
448
+ applyerBranchCode: userAccountBranchCode,
449
+ transactionId,
450
+ depositTime,
451
+ receipt,
452
+ promotionsNo: promotion?.activityNo,
453
+ })
454
+ )
455
+ },
456
+ },
457
+ }
458
+ )
459
+ }
@@ -1,12 +1,13 @@
1
1
  import { assign, createMachine } from 'xstate'
2
2
  import payment from '../../api/payment.js'
3
- import { isAmountInRange } from '../../util/amount.js'
3
+ import { max } from '../../util/index.js'
4
4
 
5
5
  export default function (request, context) {
6
6
  const { paymentDetail = [], promotion, selectedAmount } = context || {}
7
7
  return createMachine(
8
8
  {
9
9
  id: 'qrcode_cash',
10
+ predictableActionArguments: true,
10
11
  initial: 'loading',
11
12
  context: {
12
13
  paymentDetail,
@@ -46,7 +47,22 @@ export default function (request, context) {
46
47
  debouncing: {
47
48
  entry: 'clearCalculation',
48
49
  after: {
49
- 1000: [{ target: 'calculating', cond: 'isCalculable' }, { target: 'loaded' }],
50
+ 1000: [
51
+ {
52
+ target: 'calculating',
53
+ cond: (context, event) => {
54
+ const { selectedQrcode, selectedAmount } = context
55
+ if (selectedQrcode && selectedAmount) {
56
+ return selectedQrcode.minimum <= selectedAmount && selectedAmount <= selectedQrcode.maximum
57
+ } else {
58
+ return false
59
+ }
60
+ },
61
+ },
62
+ {
63
+ target: 'loaded',
64
+ },
65
+ ],
50
66
  },
51
67
  },
52
68
  calculating: {
@@ -65,7 +81,6 @@ export default function (request, context) {
65
81
  on: {
66
82
  SUBMIT: {
67
83
  target: 'submitting',
68
- cond: 'isSubmittable',
69
84
  },
70
85
  },
71
86
  },
@@ -88,7 +103,6 @@ export default function (request, context) {
88
103
  target: '.debouncing',
89
104
  actions: 'setPromotion',
90
105
  internal: false,
91
- cond: 'isPromotionChanged',
92
106
  },
93
107
  SELECT_QRCODE: {
94
108
  target: '.debouncing',
@@ -110,7 +124,7 @@ export default function (request, context) {
110
124
  {
111
125
  actions: {
112
126
  setInitData: assign((context, event) => {
113
- const { paymentDetail } = context
127
+ const { paymentDetail, selectedAmount, promotion } = context
114
128
  const qrcodes = paymentDetail.filter((element) => element.category === context.currentCategory && element.transferType === 'deposit')
115
129
  const selectedQrcode = qrcodes[0]
116
130
  return {
@@ -118,22 +132,30 @@ export default function (request, context) {
118
132
  qrcodes,
119
133
  selectedQrcode,
120
134
  options: selectedQrcode?.optional,
135
+ selectedAmount: max(promotion?.minimumAmount, selectedQrcode?.minimum, selectedAmount, 0),
121
136
  }
122
137
  }),
123
138
  setPromotion: assign((context, event) => {
124
- // 通道清單不隨活動改變(qrcodes 由 setInitData 從 paymentDetail 產生),
125
- // 因此切換活動只清計算結果、保留使用者已選的通道;重設成 qrcodes[0] 會讓
126
- // 使用者選的通道被打回第一個,且重算的是錯誤通道的獎金
139
+ const { selectedAmount } = context
140
+ const promotion = event.data || {}
141
+ const qrcodes = Array.isArray(context.qrcodes) ? context.qrcodes : []
142
+ const selectedQrcode = qrcodes[0]
127
143
  return {
128
- promotion: event.data,
144
+ promotion,
145
+ qrcodes,
146
+ selectedQrcode,
147
+ options: selectedQrcode?.optional,
148
+ selectedAmount: max(promotion?.minimumAmount, selectedQrcode?.minimum, selectedAmount, 0),
129
149
  calculation: null,
130
150
  }
131
151
  }),
132
152
  setQrcode: assign((context, event) => {
153
+ const { promotion, selectedAmount } = context
133
154
  const selectedQrcode = event.data
134
155
  return {
135
156
  selectedQrcode,
136
157
  options: selectedQrcode.optional,
158
+ selectedAmount: max(promotion.minimumAmount, selectedAmount, 0),
137
159
  calculation: null,
138
160
  }
139
161
  }),
@@ -173,14 +195,9 @@ export default function (request, context) {
173
195
  }),
174
196
  },
175
197
  guards: {
176
- isPromotionChanged: (context, event) => {
177
- return event.data?.promotionsNo !== context.promotion?.promotionsNo
178
- },
179
198
  hasQrcodeMethods: (context, event) => {
180
- return context.paymentDetail?.filter((element) => element.category === context.currentCategory).length > 0
199
+ return context.paymentDetail?.some((element) => element.category === context.currentCategory) || false
181
200
  },
182
- isCalculable: ({ selectedQrcode, selectedAmount }) => isAmountInRange(selectedAmount, selectedQrcode),
183
- isSubmittable: ({ selectedQrcode, selectedAmount }) => isAmountInRange(selectedAmount, selectedQrcode),
184
201
  },
185
202
  services: {
186
203
  fetchCalculation: async (context, event) => {