@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,541 @@
1
+ import { assign, createMachine } from 'xstate'
2
+ import findLastIndex from 'lodash/findLastIndex.js'
3
+ import payment from '../../api/payment.js'
4
+ import user from '../../api/user.js'
5
+
6
+ export default function (request) {
7
+ const { appSecret } = request.config
8
+ return createMachine(
9
+ {
10
+ id: 'withdraw_manual',
11
+ predictableActionArguments: true,
12
+ initial: 'loading',
13
+ context: {
14
+ mode: null,
15
+ siteConfig: null,
16
+ userInfo: null,
17
+ paymentDetail: [],
18
+ bindingPaymentInfo: {},
19
+ bindingPaymentList: {},
20
+ boundBanks: [],
21
+ balance: null,
22
+ charge: null,
23
+ realAmount: null,
24
+ applyId: null,
25
+ currentBank: null,
26
+ currentWithdrawLimit: null,
27
+ targetWithdrawLimit: null,
28
+ attachmentType: null, // null | 'withdraw' | 'pool'
29
+ enableWithdrawAmount: 0,
30
+ enableWithdraw: false,
31
+ withdrawRules: [],
32
+ withdrawRule: {},
33
+ withdrawCheck: {},
34
+ freeGameDetail: [],
35
+ amount: null,
36
+ calculation: null,
37
+
38
+ // otp
39
+ requestId: null,
40
+ status: null,
41
+ target: null,
42
+ ttl: null,
43
+ },
44
+ states: {
45
+ loading: {
46
+ invoke: {
47
+ src: 'fetchInitData',
48
+ onDone: {
49
+ target: 'pending',
50
+ actions: ['setInitData', 'preset'],
51
+ },
52
+ onError: {
53
+ target: 'fail',
54
+ },
55
+ },
56
+ },
57
+ pending: {
58
+ on: {
59
+ SET_MODE: {
60
+ target: 'fetching',
61
+ actions: 'setMode',
62
+ },
63
+ },
64
+ },
65
+ fetching: {
66
+ invoke: {
67
+ src: 'fetchWithdrawRules',
68
+ onDone: {
69
+ target: 'cash',
70
+ actions: 'updateWithdrawCondition',
71
+ },
72
+ onError: {
73
+ target: '#withdraw_manual.fail',
74
+ },
75
+ },
76
+ },
77
+ cash: {
78
+ initial: 'checking',
79
+ states: {
80
+ checking: {
81
+ always: [
82
+ { target: 'inProcessing', cond: 'haveProcessing' },
83
+ { target: 'unbound', cond: 'isBankNotBound' },
84
+ { target: 'withdrawCheck' },
85
+ ],
86
+ },
87
+ withdrawCheck: {
88
+ invoke: {
89
+ src: 'withdrawCheck',
90
+ onDone: [
91
+ {
92
+ target: 'checkingWithdrawStatus',
93
+ actions: assign((context, event) => {
94
+ return {
95
+ withdrawCheck: event.data,
96
+ }
97
+ }),
98
+ },
99
+ ],
100
+ onError: {
101
+ target: '#withdraw_manual.fail',
102
+ },
103
+ },
104
+ },
105
+ checkingWithdrawStatus: {
106
+ always: [
107
+ // 提款最低存款金額
108
+ { target: 'notWithdrawMinDepositAmount', cond: 'isNotWithdrawMinDepositAmount' },
109
+ // 提款冷卻時間
110
+ { target: 'passWithdrawCooldownTime', cond: 'isPassWithdrawCooldownTime' },
111
+ // 提款服務時間
112
+ { target: 'withdrawServiceTime', cond: 'isNotWIthdrawServiceTime' },
113
+ { target: 'notWithdrawable', cond: 'isNotWithdrawable' },
114
+ { target: 'withdrawable' },
115
+ ],
116
+ },
117
+ notWithdrawMinDepositAmount: {},
118
+ passWithdrawCooldownTime: {},
119
+ withdrawServiceTime: {},
120
+ notWithdrawable: {},
121
+ unbound: {
122
+ // to bank_binding.js
123
+ },
124
+ inProcessing: {},
125
+ withdrawable: {
126
+ on: {
127
+ SET_CURRENT_BANK: {
128
+ actions: assign((context, event) => {
129
+ return {
130
+ currentBank: event.data,
131
+ }
132
+ }),
133
+ },
134
+ SET_ATTACHMENT_TYPE: {
135
+ actions: 'setAttachmentType',
136
+ },
137
+ SUBMIT: [
138
+ {
139
+ target: 'pooling',
140
+ cond: (context, event) => {
141
+ const { amount, attachmentType } = context
142
+ return attachmentType === 'pool' && amount > 0
143
+ },
144
+ },
145
+ {
146
+ target: 'submitting',
147
+ cond: 'isAvailableAmount',
148
+ },
149
+ ],
150
+ },
151
+ },
152
+ debouncing: {
153
+ after: {
154
+ 1000: [
155
+ {
156
+ target: 'calculating',
157
+ cond: 'isAvailableAmount',
158
+ },
159
+ {
160
+ target: 'withdrawable',
161
+ },
162
+ ],
163
+ },
164
+ },
165
+ calculating: {
166
+ invoke: {
167
+ src: 'fetchCalculation',
168
+ onDone: {
169
+ target: 'withdrawable',
170
+ actions: 'setCalculation',
171
+ },
172
+ onError: {
173
+ target: 'withdrawable',
174
+ },
175
+ },
176
+ },
177
+ submitting: {
178
+ invoke: {
179
+ src: 'submitWithdraw',
180
+ onDone: [
181
+ {
182
+ target: '#withdraw_manual.otp',
183
+ actions: 'setOtp',
184
+ cond: 'isOtpRequired',
185
+ },
186
+ {
187
+ target: 'submitted',
188
+ },
189
+ ],
190
+ onError: {
191
+ target: 'withdrawable',
192
+ },
193
+ },
194
+ },
195
+ submitted: {
196
+ entry: assign((context, event) => {
197
+ const { applyId, balance, realAmount, charge } = event.data
198
+ return { applyId, balance, realAmount, charge }
199
+ }),
200
+ invoke: {
201
+ src: 'fetchPaymentData',
202
+ onDone: {
203
+ target: 'inProcessing',
204
+ actions: 'setPaymentData',
205
+ },
206
+ onError: {
207
+ target: '#withdraw_manual.fail',
208
+ },
209
+ },
210
+ },
211
+ pooling: {
212
+ invoke: {
213
+ src: 'pool',
214
+ onDone: { target: 'pooled' },
215
+ onError: {
216
+ target: 'withdrawable',
217
+ },
218
+ },
219
+ },
220
+ pooled: {},
221
+ },
222
+ on: {
223
+ SET_AMOUNT: {
224
+ actions: ['setAmount', 'clearCalculation'],
225
+ },
226
+ CALCULATE: {
227
+ target: '.debouncing',
228
+ },
229
+ },
230
+ },
231
+ otp: {
232
+ type: 'parallel',
233
+ states: {
234
+ countdown: {
235
+ after: {
236
+ 1000: {
237
+ target: 'countdown',
238
+ actions: 'decreaseTtl',
239
+ cond: (context) => context.ttl > 0,
240
+ },
241
+ },
242
+ },
243
+ verification: {
244
+ initial: 'idle',
245
+ states: {
246
+ idle: {
247
+ on: {
248
+ ACKNOWLEDGE: {
249
+ target: 'acknowledging',
250
+ },
251
+ RESET_OTP: {
252
+ target: 'reset',
253
+ },
254
+ BACK: [
255
+ {
256
+ target: '#withdraw_manual.cash.withdrawable',
257
+ },
258
+ ],
259
+ },
260
+ },
261
+ acknowledging: {
262
+ invoke: {
263
+ src: 'acknowledge',
264
+ onDone: [
265
+ {
266
+ target: '#withdraw_manual.cash.submitted',
267
+ },
268
+ ],
269
+ onError: {
270
+ target: 'idle',
271
+ },
272
+ },
273
+ },
274
+ reset: {
275
+ invoke: {
276
+ src: 'resetOtp',
277
+ onDone: {
278
+ target: 'idle',
279
+ actions: 'setVerificationData',
280
+ },
281
+ onError: { target: 'idle' },
282
+ },
283
+ },
284
+ },
285
+ },
286
+ },
287
+ },
288
+ fail: {},
289
+ },
290
+ on: {
291
+ REFRESH: {
292
+ target: 'loading',
293
+ },
294
+ },
295
+ },
296
+ {
297
+ actions: {
298
+ setInitData: assign((context, event) => {
299
+ const { bindingPaymentList = {}, bindingPaymentInfo = {} } = event.data
300
+ const toBeUsed = new Set(['bankList', 'cryptoList', 'ewalletList'])
301
+ const combinedData = []
302
+ const types = Object.keys(bindingPaymentInfo)
303
+ for (let i = 0; i < types.length; i++) {
304
+ const type = types[i]
305
+ if (!toBeUsed.has(type)) {
306
+ continue
307
+ }
308
+ const list = bindingPaymentInfo[type]
309
+ if (Array.isArray(list)) {
310
+ combinedData.push(...list)
311
+ } else if (list !== undefined) {
312
+ combinedData.push(list)
313
+ }
314
+ }
315
+ return { bindingPaymentList, bindingPaymentInfo, boundBanks: combinedData, currentBank: combinedData[0] }
316
+ }),
317
+ preset: assign((context, event) => {
318
+ return {
319
+ attachmentType: 'withdraw',
320
+ }
321
+ }),
322
+ setMode: assign((context, event) => {
323
+ return {
324
+ mode: event.data,
325
+ }
326
+ }),
327
+ updateWithdrawCondition: assign((context, event) => {
328
+ const { enableWithdraw, enableWithdrawAmount, currentWithdrawLimit, targetWithdrawLimit, balance, freeGameDetail, freeGameExpired } =
329
+ event.data
330
+ const withdrawRules = event.data?.rules || []
331
+ const rules = withdrawRules.filter((rule) => rule.maxWithdrawAmount > 0)
332
+ const lastMatchedIndex = findLastIndex(rules, (rule) => balance >= rule.greaterEqualThen)
333
+
334
+ let maxWithdrawAmount = 0
335
+
336
+ if (lastMatchedIndex > -1) {
337
+ rules[lastMatchedIndex].match = true
338
+ maxWithdrawAmount = rules[lastMatchedIndex].maxWithdrawAmount
339
+ } else if (rules.length > 0) {
340
+ maxWithdrawAmount = rules[0].maxWithdrawAmount
341
+ } else {
342
+ maxWithdrawAmount = balance
343
+ }
344
+
345
+ return {
346
+ balance,
347
+ currentWithdrawLimit,
348
+ targetWithdrawLimit,
349
+ maxWithdrawAmount,
350
+ enableWithdrawAmount: +enableWithdrawAmount,
351
+ enableWithdraw,
352
+ withdrawRules,
353
+ freeGameDetail,
354
+ freeGameExpired,
355
+ }
356
+ }),
357
+ setWithdrawRulePreview: assign((context, event) => {
358
+ return {
359
+ withdrawRule: event.data,
360
+ }
361
+ }),
362
+ setPaymentData: assign((context, event) => {
363
+ const { paymentDetail } = event.data
364
+ return { paymentDetail }
365
+ }),
366
+ setOtp: assign((context, event) => {
367
+ const { requestId, status, target, ttl } = event.data
368
+ return {
369
+ requestId,
370
+ status,
371
+ target,
372
+ ttl,
373
+ }
374
+ }),
375
+ decreaseTtl: assign((context, evnet) => {
376
+ const second = context.ttl
377
+ return {
378
+ ttl: Math.max(second - 1, 0),
379
+ }
380
+ }),
381
+ setVerificationData: assign((context, event) => {
382
+ const { requestId, ttl, target } = event.data
383
+ return {
384
+ requestId,
385
+ ttl,
386
+ target,
387
+ }
388
+ }),
389
+ setAttachmentType: assign((context, event) => {
390
+ return {
391
+ attachmentType: event.data,
392
+ }
393
+ }),
394
+ setCalculation: assign((context, event) => {
395
+ // V2接口轉換中回傳的資料結構不同
396
+ const { data } = event.data
397
+ if (data) {
398
+ return {
399
+ calculation: data,
400
+ }
401
+ } else {
402
+ return {
403
+ calculation: event.data,
404
+ }
405
+ }
406
+ }),
407
+ clearCalculation: assign((context, event) => {
408
+ return {
409
+ calculation: null,
410
+ }
411
+ }),
412
+ setAmount: assign((context, event) => {
413
+ return {
414
+ amount: event.data,
415
+ }
416
+ }),
417
+ },
418
+ guards: {
419
+ isAvailableAmount: (context, event) => {
420
+ const { paymentDetail, currentBank, amount, userInfo } = context
421
+ const { minimum = 0, maximum = 0 } = paymentDetail?.[0] || {}
422
+ const { balance = 0 } = userInfo || {}
423
+ const lastMax = Math.min(parseFloat(balance), maximum)
424
+ return !!currentBank && amount > 0 && minimum <= amount && amount <= lastMax
425
+ },
426
+ hasAttachmentType: (context, event) => {
427
+ return ['withdraw', 'pool'].includes(context.attachmentType)
428
+ },
429
+ haveProcessing: (context, event) => {
430
+ return (context.paymentDetail?.[0]?.processing || []).length > 0
431
+ },
432
+ isBankNotBound: (context, event) => {
433
+ return !context.boundBanks?.length
434
+ },
435
+ isConvertible: (context, event) => {
436
+ const { enableWithdraw, freeGameDetail } = context
437
+ const isFreeGame = freeGameDetail?.length > 0
438
+ if (isFreeGame) {
439
+ return freeGameDetail[0]?.freeGameCount === freeGameDetail[0]?.freeGameUsedCount
440
+ } else {
441
+ return enableWithdraw
442
+ }
443
+ },
444
+ isNotWithdrawable: (context, event) => {
445
+ const { balance, enableWithdraw, paymentDetail } = context
446
+ const minWithdrawAmount = paymentDetail[0]?.minimum || 0
447
+ return !enableWithdraw || balance < minWithdrawAmount
448
+ },
449
+ isOtpRequired: (context, event) => {
450
+ return event.data?.status === 'otp-verifying'
451
+ },
452
+ isNotWithdrawMinDepositAmount: (context, event) => {
453
+ const { withdrawCheck } = context
454
+ return !withdrawCheck?.passDepositeLimit
455
+ },
456
+ isPassWithdrawCooldownTime: (context, event) => {
457
+ const { withdrawCheck } = context
458
+ return !withdrawCheck?.passWithdrawCooldownTime
459
+ },
460
+ isNotWIthdrawServiceTime: (context, event) => {
461
+ const { withdrawCheck } = context
462
+ return !withdrawCheck?.withdrawInServiceTime
463
+ },
464
+ },
465
+ services: {
466
+ fetchInitData: async (context, event) => {
467
+ const [bindingPaymentList = {}, bindingPaymentInfo = {}] = await Promise.all([
468
+ request.send(payment.getBindingPaymentList({ appSecret })),
469
+ request.send(payment.getBindingPaymentInfo({ appSecret })),
470
+ ])
471
+ return { bindingPaymentList, bindingPaymentInfo }
472
+ },
473
+ fetchPaymentData: async (context, event) => {
474
+ const paymentDetail = await request.send(payment.getPaymentDetail({ transferType: 'WITHDRAW' }))
475
+ return { paymentDetail }
476
+ },
477
+ fetchWithdrawRules: async (context, event) => {
478
+ const { mode } = context
479
+ return await request.send(payment.getDoubleWalletWithdrawRule({ walletType: mode }))
480
+ },
481
+ fetchWithdrawRulePreview: async (context, event) => {
482
+ const data = await request.send(payment.getWithdrawRulePreview({ applyType: 'giveup' }))
483
+ return data
484
+ },
485
+ fetchCalculation: async (context, event) => {
486
+ const { paymentDetail, currentBank, amount } = context
487
+ const { method } = paymentDetail?.[0] || {}
488
+ const { cryptoCurrency } = currentBank || {}
489
+ return await request.send(payment.getCryptoWithdrawExpectedResult({ method, amount, cryptoCurrency }))
490
+ },
491
+ submitWithdraw: async (context, event) => {
492
+ const { currentBank, amount } = context
493
+ const { method } = context.paymentDetail[0]
494
+ const { bindingType } = currentBank || {}
495
+
496
+ let branchTemp = ''
497
+ if (bindingType === 'BANK' && !['GCASH', 'PAYM', 'PIX'].includes(currentBank.bankCode)) {
498
+ branchTemp = currentBank.branch
499
+ }
500
+
501
+ return await request.send(
502
+ payment.submitWithdrawTransactionManual({
503
+ method,
504
+ amount,
505
+ applyerBankCode: currentBank.bankCode || currentBank.walletCode,
506
+ applyerAccountNumber: currentBank.accountNumber,
507
+ applyerIfscCode: currentBank.ifscCode,
508
+ branch: branchTemp,
509
+ holderName: currentBank.holderName,
510
+ cryptoCurrency: currentBank.cryptoCurrency,
511
+ cryptoNetwork: currentBank.cryptoNetwork,
512
+ targetAddress: currentBank.cryptoAddress,
513
+ })
514
+ )
515
+ },
516
+ convertFreeCredit: async (context, event) => {
517
+ return await request.send(payment.convertFreeCredit({ exchangeType: 1 }))
518
+ },
519
+ resetOtp: async (context, event) => {
520
+ const { requestId, target } = context
521
+ return await request.send(user.otpReset({ requestId, target }))
522
+ },
523
+ acknowledge: async (context, event) => {
524
+ const { requestId, target } = context
525
+ const code = event.data
526
+ return await request.send(user.otpAcknowledge({ requestId, target, code }))
527
+ },
528
+ pool: async (context, event) => {
529
+ const { amount } = context
530
+ return await request.send(payment.restore({ amount }))
531
+ },
532
+ giveUp: async (context, event) => {
533
+ return await request.send(payment.giveUp())
534
+ },
535
+ withdrawCheck: async (context, event) => {
536
+ return await request.send(payment.withdrawCheck())
537
+ },
538
+ },
539
+ }
540
+ )
541
+ }