@jetthai/cuora 1.1.488 → 1.2.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 (128) hide show
  1. package/.husky/pre-commit +3 -1
  2. package/CHANGELOG.md +0 -349
  3. package/README.md +15 -299
  4. package/package.json +3 -6
  5. package/resetGitBranch.sh +101 -0
  6. package/src/api/activity.js +39 -24
  7. package/src/api/auth.js +35 -4
  8. package/src/api/common.js +1 -8
  9. package/src/api/game.js +10 -0
  10. package/src/api/index.js +1 -3
  11. package/src/api/payment.js +55 -17
  12. package/src/api/user.js +16 -11
  13. package/src/index.js +2 -2
  14. package/src/lib/fingerprint_v3_11_12.js +11433 -0
  15. package/src/machine/activity/activity.js +209 -0
  16. package/src/machine/activity/activity_cash.js +18 -71
  17. package/src/machine/activity/diamond_shop_activity_cash.js +1 -0
  18. package/src/machine/activity/diamond_shop_activity_fc.js +196 -0
  19. package/src/machine/activity/diamond_shop_activity_vn.js +178 -0
  20. package/src/machine/activity/fafafa_activity.js +10 -0
  21. package/src/machine/activity/index.js +12 -0
  22. package/src/machine/activity/invite_friends_activity.js +114 -0
  23. package/src/machine/activity/mini_game_activity.js +68 -0
  24. package/src/machine/activity/return_bonus_activity.js +153 -0
  25. package/src/machine/activity/roulette_activity_v2.js +0 -5
  26. package/src/machine/auth.js +109 -158
  27. package/src/machine/auth_otp_v2.js +177 -0
  28. package/src/machine/auth_otp_v3.js +32 -111
  29. package/src/machine/bank_binding.js +2 -2
  30. package/src/machine/bank_binding_amb.js +145 -0
  31. package/src/machine/bonus.js +75 -0
  32. package/src/machine/common.js +91 -27
  33. package/src/machine/deposit/amb.js +92 -0
  34. package/src/machine/deposit/crypto_bank.js +325 -0
  35. package/src/machine/deposit/crypto_bank_cash.js +8 -19
  36. package/src/machine/deposit/crypto_qrcode.js +148 -0
  37. package/src/machine/deposit/crypto_qrcode_cash.js +41 -26
  38. package/src/machine/deposit/crypto_way.js +247 -0
  39. package/src/machine/deposit/crypto_way_cash.js +32 -52
  40. package/src/machine/deposit/deposit_fc.js +271 -0
  41. package/src/machine/deposit/direct.js +310 -0
  42. package/src/machine/deposit/direct_cash.js +9 -8
  43. package/src/machine/deposit/float.js +374 -0
  44. package/src/machine/deposit/index.js +28 -0
  45. package/src/machine/deposit/krway.js +151 -0
  46. package/src/machine/deposit/loadcard_cash.js +31 -14
  47. package/src/machine/deposit/loadcard_vn.js +351 -0
  48. package/src/machine/deposit/manual_cash.js +10 -8
  49. package/src/machine/deposit/manual_vn.js +458 -0
  50. package/src/machine/deposit/qrcode_cash.js +30 -14
  51. package/src/machine/deposit/qrcode_v2.js +338 -0
  52. package/src/machine/deposit/usdt.js +144 -0
  53. package/src/machine/deposit/virtual_bank_cash.js +2 -5
  54. package/src/machine/deposit/virtual_bank_vn.js +269 -0
  55. package/src/machine/deposit/vpay.js +367 -0
  56. package/src/machine/error.js +0 -7
  57. package/src/machine/game_hot_new.js +79 -0
  58. package/src/machine/game_info.js +12 -5
  59. package/src/machine/game_replay.js +46 -0
  60. package/src/machine/game_search_v2.js +401 -0
  61. package/src/machine/game_v2_1.js +88 -43
  62. package/src/machine/honor_board.js +132 -0
  63. package/src/machine/honor_board_cash.js +18 -15
  64. package/src/machine/inbox.js +12 -0
  65. package/src/machine/index.js +32 -0
  66. package/src/machine/leaderboard.js +11 -8
  67. package/src/machine/merge.js +57 -0
  68. package/src/machine/payment_data.js +86 -0
  69. package/src/machine/promotions.js +170 -0
  70. package/src/machine/ranking.js +25 -43
  71. package/src/machine/reward.js +255 -0
  72. package/src/machine/reward_cash.js +41 -2
  73. package/src/machine/reward_fc.js +98 -0
  74. package/src/machine/roulette_v2.js +25 -20
  75. package/src/machine/side.js +154 -0
  76. package/src/machine/side_cash.js +2 -3
  77. package/src/machine/side_v2.js +209 -0
  78. package/src/machine/user_reset_password.js +15 -4
  79. package/src/machine/user_sign_up.js +60 -46
  80. package/src/machine/vip_table.js +57 -0
  81. package/src/machine/websocket.js +325 -378
  82. package/src/machine/welcome.js +110 -0
  83. package/src/machine/withdraw/index.js +6 -0
  84. package/src/machine/withdraw/withdraw_crypto_cash.js +327 -0
  85. package/src/machine/withdraw/withdraw_krway.js +222 -0
  86. package/src/machine/withdraw/withdraw_manual.js +533 -0
  87. package/src/machine/withdraw/withdraw_manual_cash.js +38 -59
  88. package/src/request/config.js +0 -2
  89. package/src/request/request.js +62 -130
  90. package/src/util/constant.js +2 -6
  91. package/src/util/deviceToken.js +59 -0
  92. package/src/util/index.js +4 -2
  93. package/src/util/math.js +4 -0
  94. package/.claude/commands/sync-ai-prompts.md +0 -93
  95. package/.claude/settings.local.json +0 -23
  96. package/.github/copilot-instructions.md +0 -448
  97. package/.husky/post-checkout +0 -32
  98. package/.husky/pre-push +0 -36
  99. package/AGENTS.md +0 -448
  100. package/AI_PROMPT_SOURCE.md +0 -446
  101. package/CLAUDE.md +0 -448
  102. package/GEMINI.md +0 -448
  103. package/docs/kibana/crypto-way-deposit-amount-bug-analysis.md +0 -1003
  104. package/docs/kibana/play-providerId-error.md +0 -202
  105. package/docs/kibana/play-selectedWalletType.md +0 -1
  106. package/docs/kibana/play-selectedWalletType_2.md +0 -1
  107. package/docs/kibana/play-selectedWalletType_analysis.md +0 -565
  108. package/docs/my-claude/feat-sharon-JT-1790247240-socket/branch-transfer.md +0 -14
  109. package/docs/my-claude/feat-sharon-JT-1790247240-socket/cash-module-preparation.json +0 -40
  110. package/docs/my-claude/feat-sharon-JT-1790247240-socket/cash-module-verification.md +0 -41
  111. package/docs/my-claude/feat-sharon-JT-1790247240-socket/implementation-ledger.md +0 -87
  112. package/docs/my-claude/feat-sharon-JT-1790247240-socket/module-report.md +0 -73
  113. package/docs/my-claude/feat-sharon-JT-1790247240-socket/plan.md +0 -309
  114. package/docs/my-claude/feat-sharon-JT-1790247240-socket/test-cases.md +0 -245
  115. package/docs/my-claude/feat-sharon-JT-1791180540-onesignal/transfer.md +0 -9
  116. package/scripts/auto-version.js +0 -68
  117. package/scripts/auto-version.sh +0 -33
  118. package/scripts/branch-auto-npm-publish.js +0 -29
  119. package/scripts/check-version.sh +0 -36
  120. package/scripts/clean-tags.sh +0 -84
  121. package/src/api/account.js +0 -7
  122. package/src/api/otp.js +0 -5
  123. package/src/util/amount.js +0 -8
  124. package/src/util/err998SentryExtra.js +0 -26
  125. package/src/util/paramStore.js +0 -139
  126. package/src/util/socketPolicy.js +0 -57
  127. package/test/auth_otp_v3.test.js +0 -323
  128. package/tests/websocket.test.mjs +0 -779
@@ -0,0 +1,92 @@
1
+ import { assign, createMachine } from 'xstate'
2
+ import payment from '../../api/payment.js'
3
+
4
+ export default function (request) {
5
+ return createMachine(
6
+ {
7
+ id: 'amb',
8
+ initial: 'loading',
9
+ context: {
10
+ bankList: [],
11
+ userAccount: {},
12
+ houseAccountName: null,
13
+ houseAccountNumber: null,
14
+ houseBankName: null,
15
+ method: 'amb',
16
+ },
17
+ states: {
18
+ loading: {
19
+ initial: 'checkingUserAccount',
20
+ states: {
21
+ checkingUserAccount: {
22
+ invoke: {
23
+ src: 'fetchPaymentInfo',
24
+ onDone: [
25
+ {
26
+ target: 'initializing',
27
+ actions: 'setUserAccount',
28
+ cond: 'hasUserAccount',
29
+ },
30
+ { target: '#amb.accountUnbound' },
31
+ ],
32
+ onError: {
33
+ target: '#amb.unavailable',
34
+ },
35
+ },
36
+ },
37
+ initializing: {
38
+ invoke: {
39
+ src: 'initialize',
40
+ onDone: { target: '#amb.finish', actions: 'setInitialization' },
41
+ onError: {
42
+ target: '#amb.unavailable',
43
+ },
44
+ },
45
+ },
46
+ },
47
+ },
48
+ finish: {},
49
+ accountUnbound: {},
50
+ unavailable: {},
51
+ },
52
+ },
53
+ {
54
+ actions: {
55
+ setUserAccount: assign((context, event) => {
56
+ return {
57
+ userAccount: event.data?.[0],
58
+ }
59
+ }),
60
+ setInitialization: assign((context, event) => {
61
+ const { houseAccount, bankList } = event.data
62
+ return {
63
+ houseAccountName: houseAccount.accountName,
64
+ houseAccountNumber: houseAccount.accountNumber,
65
+ houseBankName: houseAccount.bankName,
66
+ bankList: bankList?.data ? bankList.data : bankList,
67
+ }
68
+ }),
69
+ },
70
+ guards: {
71
+ hasUserAccount: (context, event) => {
72
+ return event.data?.[0]
73
+ },
74
+ },
75
+ services: {
76
+ fetchPaymentInfo: async (context, event) => {
77
+ const { bankInfo } = await request.send(payment.getPaymentInfo())
78
+ const filterArray = bankInfo?.filter((item) => item.bindingType !== 'CRYPTO' && item.bindingType !== 'EWALLET')
79
+ return filterArray || []
80
+ },
81
+ initialize: async (context, event) => {
82
+ const { method } = context
83
+ const [houseAccount, bankList] = await Promise.all([
84
+ request.send(payment.submitDepositTransaction({ method })),
85
+ request.send(payment.getBankList(method)),
86
+ ])
87
+ return { houseAccount, bankList }
88
+ },
89
+ },
90
+ }
91
+ )
92
+ }
@@ -0,0 +1,325 @@
1
+ import { assign, createMachine } from 'xstate'
2
+ import padStart from 'lodash/padStart.js'
3
+ import payment from '@jetthai/cuora/src/api/payment.js'
4
+
5
+ export default function (request) {
6
+ const { appSecret } = request.config
7
+ return createMachine(
8
+ {
9
+ id: 'crypto_bank',
10
+ initial: 'loading',
11
+ context: {
12
+ paymentDetails: [],
13
+
14
+ cryptos: [],
15
+ addresses: [],
16
+ cryptoBank: null,
17
+
18
+ amount: null,
19
+ selectedCrypto: null,
20
+ selectedAddress: null,
21
+ selectedBank: null,
22
+
23
+ currentCategory: 'cryptoBank',
24
+ currentPayment: null,
25
+
26
+ calculation: null,
27
+ processing: null,
28
+ result: null,
29
+
30
+ depositTime: null,
31
+ receipt: null,
32
+ proofOptional: false,
33
+
34
+ // use for wallet mode 4
35
+ promotion: null,
36
+ },
37
+ states: {
38
+ loading: {
39
+ initial: 'init1',
40
+ states: {
41
+ init1: {
42
+ invoke: {
43
+ src: 'fetchPayments',
44
+ onDone: {
45
+ target: 'init2',
46
+ actions: 'setPayment',
47
+ },
48
+ onError: {
49
+ target: '#crypto_bank.fail',
50
+ },
51
+ },
52
+ },
53
+ init2: {
54
+ always: [
55
+ {
56
+ target: '#crypto_bank.processing',
57
+ cond: 'isProcessing',
58
+ },
59
+ { target: '#crypto_bank.loaded' },
60
+ ],
61
+ },
62
+ },
63
+ },
64
+ loaded: {
65
+ always: [{ target: 'debouncing', cond: 'isCalculable' }],
66
+ },
67
+ debouncing: {
68
+ after: {
69
+ 1000: {
70
+ target: 'calculating',
71
+ },
72
+ },
73
+ },
74
+ calculating: {
75
+ invoke: {
76
+ src: 'fetchCalculation',
77
+ onDone: {
78
+ target: 'calculated',
79
+ actions: 'setCalculation',
80
+ },
81
+ onError: {
82
+ target: 'loaded',
83
+ },
84
+ },
85
+ },
86
+ calculated: {
87
+ on: {
88
+ SUBMIT: [
89
+ {
90
+ target: 'pending',
91
+ },
92
+ {
93
+ target: 'submitting',
94
+ cond: 'isSubmittable',
95
+ },
96
+ ],
97
+ },
98
+ },
99
+ pending: {
100
+ on: {
101
+ SUBMIT: {
102
+ target: 'submitting',
103
+ cond: 'isSubmittable',
104
+ },
105
+ },
106
+ },
107
+ submitting: {
108
+ invoke: {
109
+ src: 'submitDeposit',
110
+ onDone: {
111
+ target: 'submitted',
112
+ actions: 'setResult',
113
+ },
114
+ onError: {
115
+ target: 'loaded',
116
+ },
117
+ },
118
+ },
119
+ processing: {},
120
+ submitted: {},
121
+ fail: {},
122
+ },
123
+ on: {
124
+ SET_CRYPTO: {
125
+ target: '.loaded',
126
+ actions: 'setCrypto',
127
+ },
128
+ SET_ADDRESS: {
129
+ target: '.loaded',
130
+ actions: 'setAddress',
131
+ },
132
+ SET_AMOUNT: {
133
+ target: '.loaded',
134
+ actions: ['setAmount', 'clearCalculation'],
135
+ },
136
+ SET_PROOF_OPTIONAL: {
137
+ actions: 'setProofOptional',
138
+ },
139
+ CALCULATE: {
140
+ target: '.debouncing',
141
+ actions: 'clearCalculation',
142
+ },
143
+ SET_DEPOSIT_TIME: {
144
+ actions: 'setDepositTime',
145
+ },
146
+ SET_RECEIPT: {
147
+ actions: 'setReceipt',
148
+ },
149
+ SET_PROMOTION: {
150
+ actions: 'setPromotion',
151
+ },
152
+ },
153
+ },
154
+ {
155
+ actions: {
156
+ setPayment: assign((context, event) => {
157
+ const cryptoBank = event.data.find((element) => element.category === context.currentCategory)
158
+ cryptoBank.banks = (cryptoBank.banks || []).map((crypto) => ({
159
+ ...crypto,
160
+ label: crypto.cryptoName,
161
+ value: cryptoBank.method,
162
+ icon: crypto.symbol,
163
+ }))
164
+ const defaultCrypto = []
165
+ cryptoBank.banks?.forEach((bank) => {
166
+ var existingCryptoName = defaultCrypto.find((item) => {
167
+ return item.cryptoName === bank.cryptoName
168
+ })
169
+
170
+ if (!existingCryptoName) {
171
+ defaultCrypto.push(bank)
172
+ }
173
+ })
174
+ const currentPayment = {
175
+ label: defaultCrypto[0]?.network,
176
+ value: defaultCrypto[0]?.network,
177
+ icon: defaultCrypto[0]?.network,
178
+ }
179
+ const defaultAddresses = (cryptoBank.banks || [])
180
+ .filter((element) => element.cryptoName === defaultCrypto[0].cryptoName)
181
+ .map((value, i) => {
182
+ return {
183
+ label: value.address,
184
+ value: value.address,
185
+ icon: null,
186
+ }
187
+ })
188
+
189
+ return {
190
+ cryptos: defaultCrypto,
191
+ addresses: defaultAddresses,
192
+ cryptoBank,
193
+ selectedCrypto: defaultCrypto[0],
194
+ selectedAddress: defaultAddresses[0],
195
+ options: defaultCrypto[0]?.optional,
196
+ currentPayment,
197
+ processing: cryptoBank.processing?.[0],
198
+ }
199
+ }),
200
+ setCrypto: assign((context, event) => {
201
+ const { cryptoBank } = context
202
+ const selectedCrypto = cryptoBank.banks.find((bank) => bank.label === event.data.label)
203
+ const addresses = cryptoBank.banks
204
+ .filter((element) => element.cryptoName === selectedCrypto.cryptoName)
205
+ .map((value, i) => {
206
+ return {
207
+ label: value.address,
208
+ value: value.address,
209
+ icon: null,
210
+ }
211
+ })
212
+ return {
213
+ addresses,
214
+ selectedCrypto: selectedCrypto,
215
+ selectedAddress: addresses[0],
216
+ selectedAmount: null,
217
+ calculation: null,
218
+ options: cryptoBank.optional,
219
+ }
220
+ }),
221
+ setAddress: assign((context, event) => {
222
+ const { cryptoBank, selectedCrypto } = context
223
+ const selectedCryptoByAddress = cryptoBank.banks.find((bank) => bank.label === selectedCrypto.label && bank.address === event.data.value)
224
+ return {
225
+ selectedCrypto: selectedCryptoByAddress,
226
+ selectedAddress: event.data,
227
+ }
228
+ }),
229
+ setAmount: assign((context, event) => {
230
+ return {
231
+ amount: event.data,
232
+ }
233
+ }),
234
+ setCalculation: assign((context, event) => {
235
+ // V2接口轉換中回傳的資料結構不同
236
+ const { data } = event.data
237
+ if (data) {
238
+ return {
239
+ calculation: data,
240
+ }
241
+ } else {
242
+ return {
243
+ calculation: event.data,
244
+ }
245
+ }
246
+ }),
247
+ clearCalculation: assign((context, event) => {
248
+ return {
249
+ calculation: null,
250
+ }
251
+ }),
252
+ setResult: assign((context, event) => {
253
+ return {
254
+ result: event.data,
255
+ }
256
+ }),
257
+ setProofOptional: assign((context, event) => {
258
+ return {
259
+ proofOptional: event.data,
260
+ }
261
+ }),
262
+ setDepositTime: assign((context, event) => {
263
+ return {
264
+ depositTime: event.data,
265
+ }
266
+ }),
267
+ setReceipt: assign((context, event) => {
268
+ return {
269
+ receipt: event.data,
270
+ }
271
+ }),
272
+ setPromotion: assign((context, event) => {
273
+ const promotion = event.data
274
+ return {
275
+ promotion,
276
+ }
277
+ }),
278
+ },
279
+ guards: {
280
+ isCalculable: (context, event) => {
281
+ const { selectedCrypto, selectedAddress, cryptoBank, amount } = context
282
+ return selectedCrypto && selectedAddress && amount && cryptoBank.minimum <= +amount && +amount <= cryptoBank.maximum
283
+ },
284
+ isSubmittable: (context, event) => {
285
+ const { selectedCrypto, selectedAddress, amount, depositTime, receipt, proofOptional } = context
286
+ return selectedCrypto && selectedAddress && amount && depositTime && (receipt || proofOptional)
287
+ },
288
+ isProcessing: (context, event) => {
289
+ return context.processing
290
+ },
291
+ },
292
+ services: {
293
+ fetchPayments: async (context, event) => {
294
+ return await request.send(payment.getPaymentDetail({ transferType: 'DEPOSIT' }))
295
+ },
296
+ fetchCalculation: async (context, event) => {
297
+ const { selectedCrypto, amount, promotion } = context
298
+ return await request.send(
299
+ payment.getCryptoDepositExpectedResult({
300
+ method: selectedCrypto.value,
301
+ amount,
302
+ cryptoCurrency: selectedCrypto.symbol,
303
+ promotionsNo: promotion?.activityNo,
304
+ })
305
+ )
306
+ },
307
+ submitDeposit: async (context, event) => {
308
+ const { selectedCrypto, depositTime, receipt, amount, promotion } = context
309
+ return await request.send(
310
+ payment.submitDepositTransactionCryptoBank({
311
+ method: selectedCrypto.value,
312
+ amount: amount,
313
+ cryptoCurrency: selectedCrypto.symbol,
314
+ cryptoNetwork: selectedCrypto.network,
315
+ sourceAddress: selectedCrypto.address,
316
+ promotionsNo: promotion?.activityNo,
317
+ depositTime,
318
+ receipt,
319
+ })
320
+ )
321
+ },
322
+ },
323
+ }
324
+ )
325
+ }
@@ -1,5 +1,6 @@
1
1
  import { assign, createMachine } from 'xstate'
2
2
  import payment from '@jetthai/cuora/src/api/payment.js'
3
+ import { max } from '../../util/index.js'
3
4
 
4
5
  export default function (request, context) {
5
6
  const { paymentDetail = [], promotion, selectedAmount, siteConfig } = context || {}
@@ -81,15 +82,10 @@ export default function (request, context) {
81
82
  actions: 'setResult',
82
83
  },
83
84
  onError: {
84
- target: 'fail',
85
+ target: 'calculated',
85
86
  },
86
87
  },
87
88
  },
88
- fail: {
89
- after: {
90
- 0: { target: 'calculated' },
91
- },
92
- },
93
89
  submitted: {},
94
90
  },
95
91
  on: {
@@ -97,7 +93,6 @@ export default function (request, context) {
97
93
  target: '.debouncing',
98
94
  actions: 'setPromotion',
99
95
  internal: false,
100
- cond: 'isPromotionChanged',
101
96
  },
102
97
  SET_CRYPTO: {
103
98
  target: '.debouncing',
@@ -182,6 +177,7 @@ export default function (request, context) {
182
177
  addresses,
183
178
  selectedCrypto: selectedCrypto,
184
179
  selectedAddress: addresses[0],
180
+ selectedAmount: null,
185
181
  calculation: null,
186
182
  options: cryptoBank.optional,
187
183
  }
@@ -229,9 +225,11 @@ export default function (request, context) {
229
225
  }
230
226
  }),
231
227
  setPromotion: assign((context, event) => {
228
+ const { cryptoBank, selectedAmount } = context
232
229
  const promotion = event.data
233
230
  return {
234
231
  promotion,
232
+ selectedAmount: max(promotion.minimumAmount, cryptoBank.minimum, selectedAmount, 0),
235
233
  calculation: null,
236
234
  }
237
235
  }),
@@ -247,18 +245,9 @@ export default function (request, context) {
247
245
  }),
248
246
  },
249
247
  guards: {
250
- isPromotionChanged: (context, event) => {
251
- return event.data?.promotionsNo !== context.promotion?.promotionsNo
252
- },
253
248
  isCalculable: (context, event) => {
254
- const { selectedCrypto, selectedAddress, selectedAmount } = context
255
- return (
256
- selectedCrypto &&
257
- selectedAddress &&
258
- selectedAmount &&
259
- selectedCrypto.minimum <= +selectedAmount &&
260
- +selectedAmount <= selectedCrypto.maximum
261
- )
249
+ const { selectedCrypto, selectedAddress, cryptoBank, selectedAmount } = context
250
+ return selectedCrypto && selectedAddress && selectedAmount && cryptoBank.minimum <= +selectedAmount && +selectedAmount <= cryptoBank.maximum
262
251
  },
263
252
  isSubmittable: (context, event) => {
264
253
  const { selectedCrypto, selectedAddress, selectedAmount, depositTime, receipt, calculation, siteConfig } = context
@@ -292,7 +281,7 @@ export default function (request, context) {
292
281
  method: selectedCrypto.value,
293
282
  amount: selectedAmount,
294
283
  cryptoCurrency: selectedCrypto.symbol,
295
- cryptoNetwork: selectedCrypto.networkCode,
284
+ cryptoNetwork: selectedCrypto.network,
296
285
  sourceAddress: selectedCrypto.address,
297
286
  promotionsNo: promotion?.promotionsNo,
298
287
  depositTime,
@@ -0,0 +1,148 @@
1
+ import { assign, createMachine } from 'xstate'
2
+ import payment from '@jetthai/cuora/src/api/payment.js'
3
+
4
+ export default function (request) {
5
+ return createMachine(
6
+ {
7
+ id: 'crypto_qrcode',
8
+ initial: 'loading',
9
+ context: {
10
+ paymentDetails: [],
11
+ currentCategory: 'cryptoQrcode',
12
+ currentPayment: null,
13
+ cryptos: [],
14
+ selectedCrypto: null,
15
+
16
+ resultMap: {},
17
+ result: {
18
+ action: '',
19
+ cdtime: null,
20
+ accountNumber: '', // crypto address
21
+ currency: '',
22
+ network: '',
23
+ name: '',
24
+ qrcode: '',
25
+ },
26
+ },
27
+ states: {
28
+ loading: {
29
+ invoke: {
30
+ src: 'fetchPaymentDetail',
31
+ onDone: {
32
+ target: 'fetching',
33
+ actions: 'setInitData',
34
+ },
35
+ onError: {
36
+ target: 'fail',
37
+ },
38
+ },
39
+ },
40
+ finding: {
41
+ always: [
42
+ {
43
+ target: 'idle',
44
+ actions: 'setResultFromLocal',
45
+ cond: 'isFound',
46
+ },
47
+ {
48
+ target: 'fetching',
49
+ },
50
+ ],
51
+ },
52
+ fetching: {
53
+ invoke: {
54
+ src: 'submitDeposit',
55
+ onDone: {
56
+ target: 'idle',
57
+ actions: 'setResult',
58
+ },
59
+ onError: {
60
+ target: 'idle',
61
+ },
62
+ },
63
+ },
64
+ idle: {},
65
+ fail: {},
66
+ },
67
+ on: {
68
+ SET_CRYPTO: {
69
+ target: '.finding',
70
+ actions: 'setCrypto',
71
+ },
72
+ },
73
+ },
74
+ {
75
+ actions: {
76
+ setInitData: assign((context, event) => {
77
+ const paymentDetail = event.data || []
78
+ const payments = paymentDetail.filter((item) => item.transferType === 'deposit' && item.category === context.currentCategory)
79
+ const cryptos = payments?.map((value, i) => {
80
+ return {
81
+ ...value,
82
+ label: value?.cryptoOptional[0],
83
+ network: value?.networkName[0],
84
+ icon: value?.channel,
85
+ }
86
+ })
87
+ return {
88
+ cryptos,
89
+ selectedCrypto: cryptos[0],
90
+ currentPayment: cryptos[0],
91
+ }
92
+ }),
93
+ setCrypto: assign((context, event) => {
94
+ const { cryptos } = context
95
+ const selectedCrypto = cryptos.find((crypto) => crypto.label === event.data.label)
96
+ return { selectedCrypto }
97
+ }),
98
+ setResultFromLocal: assign((context, event) => {
99
+ const { resultMap, selectedCrypto } = context
100
+ return { result: resultMap[selectedCrypto.network] }
101
+ }),
102
+ setResult: assign((context, event) => {
103
+ const { resultMap, selectedCrypto } = context
104
+ const { action, cdtime, accountNumber, currency, network, name, qrcode, redirect } = event.data
105
+ const result = {
106
+ action,
107
+ cdtime,
108
+ accountNumber,
109
+ currency,
110
+ network,
111
+ name,
112
+ qrcode,
113
+ redirect,
114
+ }
115
+
116
+ return {
117
+ result,
118
+ resultMap: {
119
+ ...resultMap,
120
+ [selectedCrypto.network]: result,
121
+ },
122
+ }
123
+ }),
124
+ },
125
+ guards: {
126
+ isFound: (context, event) => {
127
+ const { resultMap, selectedCrypto } = context
128
+ return resultMap[selectedCrypto.network]
129
+ },
130
+ },
131
+ services: {
132
+ fetchPaymentDetail: async (context, event) => {
133
+ return await request.send(payment.getPaymentDetail({ transferType: 'DEPOSIT' }))
134
+ },
135
+ submitDeposit: async (context, event) => {
136
+ const { currentPayment, selectedCrypto } = context
137
+ return await request.send(
138
+ payment.submitDepositTransactionCrypto({
139
+ method: currentPayment.method,
140
+ cryptoCurrency: currentPayment.channel,
141
+ cryptoNetwork: selectedCrypto.network,
142
+ })
143
+ )
144
+ },
145
+ },
146
+ }
147
+ )
148
+ }