@jetthai/cuora 1.1.126 → 1.1.128-dev-2

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 (71) hide show
  1. package/CHANGELOG.md +428 -0
  2. package/package.json +1 -1
  3. package/src/api/activity.js +28 -0
  4. package/src/api/auth.js +6 -0
  5. package/src/api/common.js +2 -1
  6. package/src/api/game.js +5 -4
  7. package/src/api/mailbox.js +9 -5
  8. package/src/api/payment.js +103 -8
  9. package/src/api/user.js +2 -0
  10. package/src/machine/activity/activity.js +56 -16
  11. package/src/machine/activity/activity_cash.js +78 -14
  12. package/src/machine/activity/cash_rain_activity.js +153 -0
  13. package/src/machine/activity/diamond_shop_activity_cash.js +57 -92
  14. package/src/machine/activity/diamond_shop_activity_vn.js +54 -89
  15. package/src/machine/activity/fafafa_activity.js +8 -1
  16. package/src/machine/activity/friend_invite_friends_activity.js +3 -1
  17. package/src/machine/activity/index.js +6 -0
  18. package/src/machine/activity/instant_rebate_activity.js +214 -0
  19. package/src/machine/activity/roulette_activity_v2.js +11 -2
  20. package/src/machine/activity/sign_in_activity.js +20 -13
  21. package/src/machine/activity/vip_card_activity.js +140 -0
  22. package/src/machine/auth.js +54 -5
  23. package/src/machine/bank_binding.js +112 -12
  24. package/src/machine/bank_binding_amb.js +6 -1
  25. package/src/machine/common.js +92 -24
  26. package/src/machine/deposit/amb.js +5 -3
  27. package/src/machine/deposit/crypto.js +14 -10
  28. package/src/machine/deposit/crypto_bank.js +317 -0
  29. package/src/machine/deposit/crypto_bank_cash.js +280 -0
  30. package/src/machine/deposit/crypto_button.js +9 -5
  31. package/src/machine/deposit/crypto_cash.js +2 -5
  32. package/src/machine/deposit/crypto_qrcode.js +147 -0
  33. package/src/machine/deposit/crypto_qrcode_cash.js +131 -0
  34. package/src/machine/deposit/crypto_way.js +220 -0
  35. package/src/machine/deposit/crypto_way_cash.js +242 -0
  36. package/src/machine/deposit/direct.js +2 -11
  37. package/src/machine/deposit/direct_cash.js +6 -26
  38. package/src/machine/deposit/float.js +5 -3
  39. package/src/machine/deposit/index.js +14 -0
  40. package/src/machine/deposit/krway.js +151 -0
  41. package/src/machine/deposit/loadcard_cash.js +6 -27
  42. package/src/machine/deposit/loadcard_vn.js +2 -10
  43. package/src/machine/deposit/manual_cash.js +89 -38
  44. package/src/machine/deposit/manual_vn.js +104 -48
  45. package/src/machine/deposit/qrcode_cash.js +12 -23
  46. package/src/machine/deposit/qrcode_v2.js +3 -8
  47. package/src/machine/deposit/usdt_cash.js +0 -2
  48. package/src/machine/deposit/vpay.js +5 -3
  49. package/src/machine/game_info.js +57 -0
  50. package/src/machine/game_search_cash.js +390 -0
  51. package/src/machine/game_search_v2.js +4 -4
  52. package/src/machine/game_v2_1.js +131 -7
  53. package/src/machine/honor_board_cash.js +63 -0
  54. package/src/machine/inbox.js +259 -34
  55. package/src/machine/index.js +8 -2
  56. package/src/machine/leaderboard.js +31 -8
  57. package/src/machine/reward_cash.js +1 -1
  58. package/src/machine/side_v2.js +1 -1
  59. package/src/machine/user_photo.js +65 -0
  60. package/src/machine/user_sign_up.js +71 -7
  61. package/src/machine/withdraw/index.js +6 -0
  62. package/src/machine/withdraw/withdraw_crypto.js +1 -66
  63. package/src/machine/withdraw/withdraw_crypto2.js +540 -0
  64. package/src/machine/withdraw/withdraw_krway.js +207 -0
  65. package/src/machine/withdraw/withdraw_manual.js +595 -0
  66. package/src/machine/withdraw/withdraw_manual_cash.js +44 -14
  67. package/src/machine/withdraw/withdraw_vn.js +42 -7
  68. package/src/machine/withdraw/withdraw_vn2.js +64 -37
  69. package/src/util/constant.js +18 -0
  70. package/src/util/deviceToken.js +2 -2
  71. package/src/machine/game_search.js +0 -244
@@ -0,0 +1,540 @@
1
+ import { assign, createMachine } from 'xstate'
2
+ import findLastIndex from 'lodash/findLastIndex.js'
3
+ import payment from '../../api/payment.js'
4
+ import common from '../../api/common.js'
5
+ import user from '../../api/user.js'
6
+ import api from '../../api/payment.js'
7
+
8
+ export default function (request) {
9
+ const { appSecret } = request.config
10
+ return createMachine(
11
+ {
12
+ id: 'withdraw_crypto2',
13
+ initial: 'loading',
14
+ context: {
15
+ mode: null,
16
+ siteConfig: null,
17
+ balance: null,
18
+
19
+ methods: [],
20
+ paymentDetail: [],
21
+
22
+ currentWithdrawLimit: null,
23
+ targetWithdrawLimit: null,
24
+
25
+ maxWithdrawAmount: null,
26
+ availableWithdrawAmount: null,
27
+ enableWithdraw: false,
28
+ enableWithdrawAmount: 0,
29
+ withdrawRules: [],
30
+ withdrawRule: {},
31
+ attachmentType: null, // null | 'withdraw' | 'pool'
32
+ networks: [],
33
+ selectedNetwork: null,
34
+ address: '',
35
+ amount: null,
36
+ charge: null,
37
+ realAmount: null,
38
+
39
+ // otp
40
+ requestId: null,
41
+ status: null,
42
+ target: null,
43
+ ttl: null,
44
+ },
45
+ states: {
46
+ loading: {
47
+ invoke: {
48
+ src: 'fetchInitData',
49
+ onDone: {
50
+ target: 'pending',
51
+ actions: ['setInitData', 'preset'],
52
+ },
53
+ onError: {
54
+ target: 'fail',
55
+ },
56
+ },
57
+ },
58
+ pending: {
59
+ on: {
60
+ SET_MODE: {
61
+ target: 'fetching',
62
+ actions: 'setMode',
63
+ },
64
+ },
65
+ },
66
+ fetching: {
67
+ invoke: {
68
+ src: 'fetchWithdrawRules',
69
+ onDone: {
70
+ target: 'mode',
71
+ actions: 'updateWithdrawCondition',
72
+ },
73
+ onError: {
74
+ target: '#withdraw_crypto2.fail',
75
+ },
76
+ },
77
+ },
78
+ mode: {
79
+ always: [{ target: 'activity', cond: 'isActivity' }, { target: 'cash' }],
80
+ },
81
+ activity: {
82
+ initial: 'checking',
83
+ states: {
84
+ checking: {
85
+ always: [{ target: 'convertible', cond: 'isConvertible' }, { target: 'notConvertible' }],
86
+ },
87
+ notConvertible: {
88
+ on: {
89
+ GIVE_UP: {
90
+ target: 'fetchWithdrawRule',
91
+ },
92
+ },
93
+ },
94
+ fetchWithdrawRule: {
95
+ invoke: {
96
+ src: 'fetchWithdrawRulePreview',
97
+ onDone: {
98
+ target: 'giveUp',
99
+ actions: 'setWithdrawRulePreview',
100
+ },
101
+ onError: {
102
+ target: 'notConvertible',
103
+ },
104
+ },
105
+ },
106
+ giveUp: {
107
+ on: {
108
+ CONFIRM: {
109
+ target: 'givingUp',
110
+ },
111
+ BACK: {
112
+ target: 'notConvertible',
113
+ },
114
+ },
115
+ },
116
+ givingUp: {
117
+ invoke: {
118
+ src: 'giveUp',
119
+ onDone: {
120
+ target: 'gaveUp',
121
+ },
122
+ onError: {
123
+ target: '#withdraw_crypto2.fail',
124
+ },
125
+ },
126
+ },
127
+ gaveUp: {},
128
+ convertible: {
129
+ on: {
130
+ SUBMIT: {
131
+ target: 'converting',
132
+ actions: 'setAttachmentType',
133
+ },
134
+ },
135
+ },
136
+ converting: {
137
+ invoke: {
138
+ src: 'convertFreeCredit',
139
+ onDone: [
140
+ {
141
+ target: '#withdraw_crypto2.otp',
142
+ actions: 'setOtp',
143
+ cond: 'isOtpRequired',
144
+ },
145
+ { target: 'converted' },
146
+ ],
147
+ onError: {
148
+ target: 'convertible',
149
+ },
150
+ },
151
+ },
152
+ converted: {
153
+ always: [{ target: '#withdraw_crypto2.cash.withdrawable', cond: 'hasAttachmentType' }],
154
+ },
155
+ },
156
+ },
157
+ cash: {
158
+ initial: 'checking',
159
+ states: {
160
+ checking: {
161
+ always: [
162
+ { target: 'inProcessing', cond: 'haveProcessing' },
163
+ { target: 'notWithdrawable', cond: 'isNotWithdrawable' },
164
+ { target: 'withdrawable' },
165
+ ],
166
+ },
167
+ notWithdrawable: {},
168
+ inProcessing: {},
169
+ withdrawable: {
170
+ on: {
171
+ SET_NETWORK: {
172
+ actions: ['resetCharge', 'setNetwork'],
173
+ },
174
+ SET_ADDRESS: {
175
+ actions: 'setAddress',
176
+ },
177
+ SET_AMOUNT: {
178
+ actions: ['resetCharge', 'setAmount'],
179
+ },
180
+ CALCULATE: {
181
+ target: 'calculating',
182
+ cond: 'isCalculable',
183
+ },
184
+ PREVIEW: {
185
+ target: 'submittable',
186
+ cond: 'isSubmittable',
187
+ },
188
+ SET_ATTACHMENT_TYPE: {
189
+ actions: 'setAttachmentType',
190
+ },
191
+ POOL: {
192
+ target: 'pooling',
193
+ cond: (context, event) => {
194
+ const { amount, attachmentType } = context
195
+ return attachmentType === 'pool' && amount > 0
196
+ },
197
+ },
198
+ },
199
+ },
200
+ calculating: {
201
+ entry: 'resetCharge',
202
+ invoke: {
203
+ src: 'fetchCalculation',
204
+ onDone: {
205
+ target: 'withdrawable',
206
+ actions: 'setCalculatedResult',
207
+ },
208
+ onError: {
209
+ target: 'withdrawable',
210
+ },
211
+ },
212
+ },
213
+ submittable: {
214
+ on: {
215
+ SUBMIT: [
216
+ {
217
+ target: 'pooling',
218
+ cond: (context, event) => {
219
+ const { amount, attachmentType } = context
220
+ return attachmentType === 'pool' && amount > 0
221
+ },
222
+ },
223
+ {
224
+ target: 'submitting',
225
+ },
226
+ ],
227
+ BACK: {
228
+ target: 'withdrawable',
229
+ },
230
+ },
231
+ },
232
+ submitting: {
233
+ invoke: {
234
+ src: 'submitWithdraw',
235
+ onDone: [
236
+ {
237
+ target: '#withdraw_crypto2.otp',
238
+ actions: 'setOtp',
239
+ cond: 'isOtpRequired',
240
+ },
241
+ {
242
+ target: 'submitted',
243
+ },
244
+ ],
245
+ onError: {
246
+ target: 'withdrawable',
247
+ },
248
+ },
249
+ },
250
+ submitted: {},
251
+ pooling: {
252
+ invoke: {
253
+ src: 'pool',
254
+ onDone: { target: 'pooled' },
255
+ onError: {
256
+ target: 'withdrawable',
257
+ },
258
+ },
259
+ },
260
+ pooled: {},
261
+ },
262
+ },
263
+ otp: {
264
+ type: 'parallel',
265
+ states: {
266
+ countdown: {
267
+ after: {
268
+ 1000: {
269
+ target: 'countdown',
270
+ actions: 'decreaseTtl',
271
+ cond: (context) => context.ttl > 0,
272
+ },
273
+ },
274
+ },
275
+ verification: {
276
+ initial: 'idle',
277
+ states: {
278
+ idle: {
279
+ on: {
280
+ ACKNOWLEDGE: {
281
+ target: 'acknowledging',
282
+ },
283
+ RESET_OTP: {
284
+ target: 'reset',
285
+ },
286
+ BACK: [
287
+ {
288
+ target: '#withdraw_crypto2.activity.convertible',
289
+ cond: 'isFree',
290
+ },
291
+ {
292
+ target: '#withdraw_crypto2.cash.submittable',
293
+ },
294
+ ],
295
+ },
296
+ },
297
+ acknowledging: {
298
+ invoke: {
299
+ src: 'acknowledge',
300
+ onDone: [
301
+ {
302
+ target: '#withdraw_crypto2.activity.converted',
303
+ cond: 'isFree',
304
+ },
305
+ {
306
+ target: '#withdraw_crypto2.cash.submitted',
307
+ },
308
+ ],
309
+ onError: {
310
+ target: 'idle',
311
+ },
312
+ },
313
+ },
314
+ reset: {
315
+ invoke: {
316
+ src: 'resetOtp',
317
+ onDone: {
318
+ target: 'idle',
319
+ actions: 'setVerificationData',
320
+ },
321
+ onError: { target: 'idle' },
322
+ },
323
+ },
324
+ },
325
+ },
326
+ },
327
+ },
328
+ fail: {},
329
+ },
330
+ on: {
331
+ REFRESH: {
332
+ target: 'loading',
333
+ },
334
+ },
335
+ },
336
+ {
337
+ actions: {
338
+ setInitData: assign((context, event) => {
339
+ const method = event.data.paymentDetail?.[0]
340
+ return {
341
+ paymentDetail: event.data.paymentDetail,
342
+ crypto: method,
343
+ networks:
344
+ method?.networkName?.map?.((value, i) => {
345
+ return {
346
+ label: method?.networkOptional?.[i],
347
+ value,
348
+ icon: value,
349
+ }
350
+ }) || [],
351
+ }
352
+ }),
353
+ preset: assign((context, event) => {
354
+ const { siteConfig } = context
355
+ const methods = siteConfig?.paymentMethods?.withdraw || []
356
+ return {
357
+ methods,
358
+ attachmentType: siteConfig.walletMode > 0 ? 'withdraw' : null,
359
+ }
360
+ }),
361
+ setMode: assign((context, event) => {
362
+ return {
363
+ mode: event.data,
364
+ }
365
+ }),
366
+ updateWithdrawCondition: assign((context, event) => {
367
+ const { enableWithdraw, enableWithdrawAmount, currentWithdrawLimit, targetWithdrawLimit, balance } = event.data
368
+ const withdrawRules = event.data?.rules || []
369
+ const rules = withdrawRules.filter((rule) => rule.maxWithdrawAmount > 0)
370
+ const lastMatchedIndex = findLastIndex(rules, (rule) => balance >= rule.greaterEqualThen)
371
+
372
+ let maxWithdrawAmount = 0
373
+
374
+ if (lastMatchedIndex > -1) {
375
+ rules[lastMatchedIndex].match = true
376
+ maxWithdrawAmount = rules[lastMatchedIndex].maxWithdrawAmount
377
+ } else if (rules.length > 0) {
378
+ maxWithdrawAmount = rules[0].maxWithdrawAmount
379
+ } else {
380
+ maxWithdrawAmount = balance
381
+ }
382
+
383
+ return {
384
+ balance,
385
+ currentWithdrawLimit,
386
+ targetWithdrawLimit,
387
+ maxWithdrawAmount,
388
+ enableWithdrawAmount: +enableWithdrawAmount,
389
+ enableWithdraw,
390
+ withdrawRules,
391
+ }
392
+ }),
393
+ setWithdrawRulePreview: assign((context, event) => {
394
+ return {
395
+ withdrawRule: event.data,
396
+ }
397
+ }),
398
+ setNetwork: assign((context, event) => {
399
+ return {
400
+ selectedNetwork: event.data,
401
+ }
402
+ }),
403
+ setAddress: assign((context, event) => {
404
+ return {
405
+ address: event.data,
406
+ }
407
+ }),
408
+ setAmount: assign((context, event) => {
409
+ return {
410
+ amount: event.data,
411
+ }
412
+ }),
413
+ setCalculatedResult: assign((context, event) => {
414
+ return {
415
+ charge: event.data.charge,
416
+ }
417
+ }),
418
+ resetCharge: assign((context, event) => {
419
+ return {
420
+ charge: null,
421
+ }
422
+ }),
423
+ setOtp: assign((context, event) => {
424
+ const { requestId, status, target, ttl } = event.data
425
+ return {
426
+ requestId,
427
+ status,
428
+ target,
429
+ ttl,
430
+ }
431
+ }),
432
+ decreaseTtl: assign((context, evnet) => {
433
+ const second = context.ttl
434
+ return {
435
+ ttl: Math.max(second - 1, 0),
436
+ }
437
+ }),
438
+ setVerificationData: assign((context, event) => {
439
+ const { requestId, ttl, target } = event.data
440
+ return {
441
+ requestId,
442
+ ttl,
443
+ target,
444
+ }
445
+ }),
446
+ setAttachmentType: assign((context, event) => {
447
+ return {
448
+ attachmentType: event.data,
449
+ }
450
+ }),
451
+ },
452
+ guards: {
453
+ isActivity: (context, event) => {
454
+ return context.mode === 'ACTIVITY'
455
+ },
456
+ hasAttachmentType: (context, event) => {
457
+ return ['withdraw', 'pool'].includes(context.attachmentType)
458
+ },
459
+ haveProcessing: (context, event) => {
460
+ return (context.paymentDetail?.[0]?.processing || []).length > 0
461
+ },
462
+ isSubmittable: (context, event) => {
463
+ const { selectedNetwork, address, amount, charge } = context
464
+ return selectedNetwork && address && amount && charge
465
+ },
466
+ isConvertible: (context, event) => {
467
+ const { enableWithdraw } = context
468
+ return enableWithdraw
469
+ },
470
+ isNotWithdrawable: (context, event) => {
471
+ const { enableWithdraw } = context
472
+ return !enableWithdraw
473
+ },
474
+ isCalculable: (context, event) => {
475
+ const { selectedNetwork, amount } = context
476
+ return selectedNetwork && amount
477
+ },
478
+ isOtpRequired: (context, event) => {
479
+ return event.data?.status === 'otp-verifying'
480
+ },
481
+ },
482
+ services: {
483
+ fetchInitData: async (context, event) => {
484
+ const paymentDetail = await request.send(payment.getPaymentDetail({ transferType: 'WITHDRAW' }))
485
+ return { paymentDetail }
486
+ },
487
+ fetchWithdrawRules: async (context, event) => {
488
+ const { mode } = context
489
+ return await request.send(payment.getDoubleWalletWithdrawRule({ walletType: mode }))
490
+ },
491
+ fetchWithdrawRulePreview: async (context, event) => {
492
+ const data = await request.send(payment.getWithdrawRulePreview({ applyType: 'giveup' }))
493
+ return data
494
+ },
495
+ submitWithdraw: async (context, event) => {
496
+ const { crypto, selectedNetwork, address, amount } = context
497
+ return await request.send(
498
+ api.submitWithdrawTransactionCrypto({
499
+ method: crypto.method,
500
+ amount,
501
+ cryptoCurrency: crypto.channel,
502
+ cryptoNetwork: selectedNetwork.value,
503
+ targetAddress: address,
504
+ })
505
+ )
506
+ },
507
+ convertFreeCredit: async (context, event) => {
508
+ return await request.send(payment.convertFreeCredit({ exchangeType: 1 }))
509
+ },
510
+ fetchCalculation: async (context, event) => {
511
+ const { crypto, selectedNetwork, amount } = context
512
+ const method = crypto.method
513
+ return await request.send(
514
+ api.getWithdrawExpectedResult({
515
+ method,
516
+ amount,
517
+ cryptoNetwork: selectedNetwork.value,
518
+ })
519
+ )
520
+ },
521
+ resetOtp: async (context, event) => {
522
+ const { requestId, target } = context
523
+ return await request.send(user.otpReset({ requestId, target }))
524
+ },
525
+ acknowledge: async (context, event) => {
526
+ const { requestId, target } = context
527
+ const code = event.data
528
+ return await request.send(user.otpAcknowledge({ requestId, target, code }))
529
+ },
530
+ pool: async (context, event) => {
531
+ const { amount } = context
532
+ return await request.send(payment.restore({ amount }))
533
+ },
534
+ giveUp: async (context, event) => {
535
+ return await request.send(payment.giveUp())
536
+ },
537
+ },
538
+ }
539
+ )
540
+ }