@jetthai/cuora 1.1.65-doubleWallet-2 → 1.1.65

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.
@@ -1,16 +1,13 @@
1
1
  import { assign, createMachine } from 'xstate'
2
2
  import payment from '../../api/payment.js'
3
- import common from '../../api/common.js'
4
3
 
5
4
  export default function (request) {
6
- const { appSecret } = request.config
7
5
  return createMachine(
8
6
  {
9
7
  id: 'manual',
10
8
  initial: 'loading',
11
9
  context: {
12
- siteConfig: null,
13
- paymentDetail: [],
10
+ paymentDetails: [],
14
11
 
15
12
  houseBanks: [],
16
13
  playerBanks: [],
@@ -76,10 +73,6 @@ export default function (request) {
76
73
  states: {
77
74
  promotion: {
78
75
  always: [
79
- {
80
- target: 'idle',
81
- cond: 'isDoubleWalletMode',
82
- },
83
76
  {
84
77
  target: 'calculating',
85
78
  actions: 'setPromotionDefaultAmount',
@@ -124,26 +117,8 @@ export default function (request) {
124
117
  actions: 'clearCalculation',
125
118
  },
126
119
  TRANSACT: {
127
- target: 'checking',
128
- cond: 'isCalculated',
129
- },
130
- },
131
- },
132
- checking: {
133
- always: [
134
- {
135
- target: 'pending',
136
- cond: (context, event) => context.siteConfig?.walletMode === '4' && !!context.calculation,
137
- },
138
- {
139
- target: '#manual.step2',
140
- },
141
- ],
142
- },
143
- pending: {
144
- on: {
145
- CONFIRM: {
146
120
  target: '#manual.step2',
121
+ cond: 'isCalculated',
147
122
  },
148
123
  },
149
124
  },
@@ -229,16 +204,15 @@ export default function (request) {
229
204
  {
230
205
  actions: {
231
206
  setInitData: assign((context, event) => {
232
- const { siteConfig, paymentInfo, paymentDetail } = event.data
207
+ const { paymentInfo, paymentDetails } = event.data
233
208
  const bankInfoList = paymentInfo?.bankInfo || []
234
- const currentPayment = paymentDetail.find((element) => element.category === context.currentCategory)
209
+ const currentPayment = paymentDetails.find((element) => element.category === context.currentCategory)
235
210
  const houseBanks = currentPayment.banks.map((item) => {
236
211
  item.bankCode = item.bankName
237
212
  return item
238
213
  })
239
214
  return {
240
- siteConfig,
241
- paymentDetail,
215
+ paymentDetails,
242
216
  currentPayment,
243
217
  method: currentPayment.method,
244
218
  houseBanks,
@@ -339,9 +313,6 @@ export default function (request) {
339
313
  }),
340
314
  },
341
315
  guards: {
342
- isDoubleWalletMode: (context, event) => {
343
- return context.siteConfig?.walletMode === '4'
344
- },
345
316
  isCalculable: (context, event) => {
346
317
  const {
347
318
  amount,
@@ -365,16 +336,13 @@ export default function (request) {
365
336
  },
366
337
  services: {
367
338
  fetchInitData: async (context, event) => {
368
- const [{ config }, paymentInfo, paymentDetail] = await Promise.all([
369
- request.send(common.getConfig({ appSecret })),
339
+ const [paymentInfo, paymentDetails] = await Promise.all([
370
340
  request.send(payment.getPaymentInfo()),
371
341
  request.send(payment.getPaymentDetail({ transferType: 'DEPOSIT' })),
372
342
  ])
373
- const siteConfig = JSON.parse(window.atob(config))
374
343
  return {
375
- siteConfig,
376
344
  paymentInfo,
377
- paymentDetail,
345
+ paymentDetails,
378
346
  }
379
347
  },
380
348
  fetchBanksList: async (context, event) => {
@@ -26,9 +26,8 @@ export default function (request) {
26
26
 
27
27
  grandTotalEnable: 1,
28
28
 
29
- // use for wallet mode 3 & 4
29
+ // use for wallet mode 3
30
30
  promotion: null,
31
- bonusPreviewData: [],
32
31
  },
33
32
  states: {
34
33
  loading: {
@@ -36,7 +35,7 @@ export default function (request) {
36
35
  src: 'fetchInitData',
37
36
  onDone: {
38
37
  target: 'checking',
39
- actions: 'setInitData',
38
+ actions: ['setInitData', 'preset'],
40
39
  },
41
40
  onError: {
42
41
  target: 'fail',
@@ -45,113 +44,177 @@ export default function (request) {
45
44
  },
46
45
  checking: {
47
46
  always: [
48
- {
49
- target: 'fetching',
50
- cond: (context, event) => {
51
- const { siteConfig = {}, promotion = {} } = context
52
- const { walletMode = '', bonusPreviewEnable = '0' } = siteConfig
53
- return walletMode === '4' && bonusPreviewEnable === '1' && promotion.activityNo != 'none'
54
- },
55
- },
47
+ { target: 'newWalletMode', cond: 'isNewWalletMode' },
56
48
  {
57
49
  target: 'debouncing',
58
50
  actions: 'setPromotionDefaultAmount',
59
- cond: (context, event) => {
60
- const { siteConfig = {}, promotion = {} } = context
61
- return siteConfig.walletMode === '3' && !!promotion?.minimumAmount
62
- },
51
+ cond: 'hasMinPromotionDeposit',
63
52
  },
64
- { target: 'loaded' },
53
+ { target: 'defaultMode' },
65
54
  ],
66
55
  },
67
- fetching: {
68
- invoke: {
69
- src: 'fetchBonusPreview',
70
- onDone: {
71
- target: 'loaded',
72
- actions: 'setBonusPreview',
56
+ newWalletMode: {
57
+ initial: 'loaded',
58
+ states: {
59
+ loaded: {
60
+ entry: 'reset',
61
+ on: {
62
+ SELECT_QRCODE: {
63
+ actions: 'setQrcode',
64
+ },
65
+ SELECT_AMOUNT: [
66
+ {
67
+ target: 'pending',
68
+ actions: 'addAmount',
69
+ cond: (context, event) => context.grandTotalEnable === 1,
70
+ },
71
+ {
72
+ target: 'pending',
73
+ actions: 'setAmount',
74
+ },
75
+ ],
76
+ KEY_IN: {
77
+ target: 'pending',
78
+ actions: 'setAmount',
79
+ },
80
+ },
73
81
  },
74
- onError: {
75
- target: 'loaded',
82
+ pending: {
83
+ on: {
84
+ SELECT_AMOUNT: [
85
+ {
86
+ actions: 'addAmount',
87
+ cond: (context, event) => context.grandTotalEnable === 1,
88
+ },
89
+ {
90
+ actions: 'setAmount',
91
+ },
92
+ ],
93
+ KEY_IN: {
94
+ actions: 'setAmount',
95
+ },
96
+ CONFIRM: {
97
+ target: 'debouncing',
98
+ },
99
+ BACK: {
100
+ target: 'loaded',
101
+ },
102
+ },
103
+ },
104
+ debouncing: {
105
+ on: {
106
+ SELECT_AMOUNT: [
107
+ {
108
+ target: 'debouncing',
109
+ actions: 'addAmount',
110
+ cond: (context, event) => context.grandTotalEnable === 1,
111
+ },
112
+ {
113
+ target: 'debouncing',
114
+ actions: 'setAmount',
115
+ },
116
+ ],
117
+ KEY_IN: {
118
+ target: 'debouncing',
119
+ actions: 'setAmount',
120
+ },
121
+ BACK: {
122
+ target: 'loaded',
123
+ },
124
+ },
125
+ after: {
126
+ 1000: {
127
+ target: 'calculating',
128
+ },
129
+ },
130
+ },
131
+ calculable: {
132
+ entry: 'clearCalculation',
133
+ on: {
134
+ SELECT_AMOUNT: [
135
+ {
136
+ target: 'debouncing',
137
+ actions: 'addAmount',
138
+ cond: (context, event) => context.grandTotalEnable === 1,
139
+ },
140
+ {
141
+ target: 'debouncing',
142
+ actions: 'setAmount',
143
+ },
144
+ ],
145
+ KEY_IN: {
146
+ target: 'debouncing',
147
+ actions: 'setAmount',
148
+ },
149
+ CALCULATE: {
150
+ target: 'debouncing',
151
+ },
152
+ BACK: {
153
+ target: 'loaded',
154
+ },
155
+ },
156
+ },
157
+ calculating: {
158
+ invoke: {
159
+ src: 'fetchCalculation',
160
+ onDone: {
161
+ target: 'submitting',
162
+ actions: 'setCalculation',
163
+ },
164
+ onError: {
165
+ target: 'calculable',
166
+ },
167
+ },
168
+ },
169
+ submitting: {
170
+ invoke: {
171
+ src: 'submitDeposit',
172
+ onDone: {
173
+ target: 'submitted',
174
+ actions: 'setResult',
175
+ },
176
+ onError: {
177
+ target: 'pending',
178
+ },
179
+ },
180
+ },
181
+ submitted: {
182
+ on: {
183
+ SELECT_QRCODE: {
184
+ target: 'loaded',
185
+ actions: 'setQrcode',
186
+ },
187
+ },
76
188
  },
77
189
  },
78
190
  },
79
- fail: {},
80
- loaded: {
191
+ defaultMode: {
81
192
  entry: 'reset',
82
193
  on: {
83
194
  SELECT_QRCODE: [
84
- {
85
- target: 'fetching',
86
- actions: 'setQrcode',
87
- cond: (context, event) => {
88
- const { siteConfig = {}, promotion = {} } = context
89
- const { walletMode = '', bonusPreviewEnable = '0' } = siteConfig
90
- return walletMode === '4' && bonusPreviewEnable === '1' && promotion.activityNo != 'none'
91
- },
92
- },
93
195
  {
94
196
  target: 'debouncing',
95
197
  actions: ['setQrcode', 'setPromotionDefaultAmount'],
96
- cond: (context, event) => context.siteConfig?.walletMode === '3' && context.promotion?.minimumAmount,
198
+ cond: 'hasMinPromotionDeposit',
97
199
  },
98
200
  {
99
201
  actions: 'setQrcode',
100
202
  },
101
203
  ],
102
204
  SELECT_AMOUNT: [
103
- {
104
- target: 'pending',
105
- actions: 'addAmount',
106
- cond: (context, event) => context.siteConfig?.walletMode === '2' && context.grandTotalEnable === 1,
107
- },
108
- {
109
- target: 'pending',
110
- actions: 'setAmount',
111
- cond: 'isFreeWalletMode',
112
- },
113
205
  {
114
206
  target: 'debouncing',
115
207
  actions: 'addAmount',
116
- cond: 'isGrandTotalEnable',
208
+ cond: (context, event) => context.grandTotalEnable === 1,
117
209
  },
118
210
  {
119
211
  target: 'debouncing',
120
212
  actions: 'setAmount',
121
213
  },
122
214
  ],
123
- KEY_IN: [
124
- {
125
- target: 'pending',
126
- actions: 'setAmount',
127
- cond: 'isFreeWalletMode',
128
- },
129
- {
130
- target: 'calculating',
131
- actions: 'setAmount',
132
- },
133
- ],
134
- },
135
- },
136
- pending: {
137
- on: {
138
- SELECT_AMOUNT: [
139
- {
140
- actions: 'addAmount',
141
- cond: 'isGrandTotalEnable',
142
- },
143
- {
144
- actions: 'setAmount',
145
- },
146
- ],
147
215
  KEY_IN: {
148
- actions: 'setAmount',
149
- },
150
- CONFIRM: {
151
216
  target: 'calculating',
152
- },
153
- BACK: {
154
- target: 'loaded',
217
+ actions: 'setAmount',
155
218
  },
156
219
  },
157
220
  },
@@ -161,25 +224,19 @@ export default function (request) {
161
224
  {
162
225
  target: 'debouncing',
163
226
  actions: 'addAmount',
164
- cond: (context, event) => context.siteConfig?.walletMode === '2' && context.grandTotalEnable === 1,
165
- },
166
- {
167
- target: 'debouncing',
168
- actions: 'setAmount',
169
- cond: 'isFreeWalletMode',
170
- },
171
- {
172
- target: 'debouncing',
173
- actions: 'addAmount',
174
- cond: 'isGrandTotalEnable',
227
+ cond: (context, event) => context.grandTotalEnable === 1,
175
228
  },
176
229
  {
177
230
  target: 'debouncing',
178
231
  actions: 'setAmount',
179
232
  },
180
233
  ],
234
+ KEY_IN: {
235
+ target: 'debouncing',
236
+ actions: 'setAmount',
237
+ },
181
238
  BACK: {
182
- target: 'loaded',
239
+ target: 'defaultMode',
183
240
  },
184
241
  },
185
242
  after: {
@@ -188,24 +245,15 @@ export default function (request) {
188
245
  },
189
246
  },
190
247
  },
248
+ fail: {},
191
249
  calculable: {
192
250
  entry: 'clearCalculation',
193
251
  on: {
194
252
  SELECT_AMOUNT: [
195
- {
196
- target: 'pending',
197
- actions: 'addAmount',
198
- cond: (context, event) => context.siteConfig?.walletMode === '2' && context.grandTotalEnable === 1,
199
- },
200
- {
201
- target: 'pending',
202
- actions: 'setAmount',
203
- cond: 'isFreeWalletMode',
204
- },
205
253
  {
206
254
  target: 'debouncing',
207
255
  actions: 'addAmount',
208
- cond: 'isGrandTotalEnable',
256
+ cond: (context, event) => context.grandTotalEnable === 1,
209
257
  },
210
258
  {
211
259
  target: 'debouncing',
@@ -213,28 +261,24 @@ export default function (request) {
213
261
  },
214
262
  ],
215
263
  KEY_IN: {
216
- target: 'calculating',
264
+ target: 'debouncing',
217
265
  actions: 'setAmount',
218
266
  },
267
+ CALCULATE: {
268
+ target: 'debouncing',
269
+ },
219
270
  BACK: {
220
- target: 'loaded',
271
+ target: 'defaultMode',
221
272
  },
222
273
  },
223
274
  },
224
275
  calculating: {
225
276
  invoke: {
226
277
  src: 'fetchCalculation',
227
- onDone: [
228
- {
229
- target: 'submitting',
230
- actions: 'setCalculation',
231
- cond: 'isFreeWalletMode',
232
- },
233
- {
234
- target: 'calculated',
235
- actions: 'setCalculation',
236
- },
237
- ],
278
+ onDone: {
279
+ target: 'calculated',
280
+ actions: 'setCalculation',
281
+ },
238
282
  onError: {
239
283
  target: 'calculable',
240
284
  },
@@ -243,20 +287,10 @@ export default function (request) {
243
287
  calculated: {
244
288
  on: {
245
289
  SELECT_AMOUNT: [
246
- {
247
- target: 'pending',
248
- actions: 'addAmount',
249
- cond: (context, event) => context.siteConfig?.walletMode === '2' && context.grandTotalEnable === 1,
250
- },
251
- {
252
- target: 'pending',
253
- actions: 'setAmount',
254
- cond: 'isFreeWalletMode',
255
- },
256
290
  {
257
291
  target: 'debouncing',
258
292
  actions: 'addAmount',
259
- cond: 'isGrandTotalEnable',
293
+ cond: (context, event) => context.grandTotalEnable === 1,
260
294
  },
261
295
  {
262
296
  target: 'debouncing',
@@ -264,14 +298,14 @@ export default function (request) {
264
298
  },
265
299
  ],
266
300
  KEY_IN: {
267
- target: 'calculating',
301
+ target: 'debouncing',
268
302
  actions: 'setAmount',
269
303
  },
270
304
  CONFIRM: {
271
305
  target: 'submitting',
272
306
  },
273
307
  BACK: {
274
- target: 'loaded',
308
+ target: 'defaultMode',
275
309
  },
276
310
  CLEAR_CALCULATION: {
277
311
  target: 'debouncing',
@@ -293,21 +327,10 @@ export default function (request) {
293
327
  },
294
328
  submitted: {
295
329
  on: {
296
- SELECT_QRCODE: [
297
- {
298
- target: 'fetching',
299
- actions: 'setQrcode',
300
- cond: (context, event) => {
301
- const { siteConfig = {}, promotion = {} } = context
302
- const { walletMode = '', bonusPreviewEnable = '0' } = siteConfig
303
- return walletMode === '4' && bonusPreviewEnable === '1' && promotion.activityNo != 'none'
304
- },
305
- },
306
- {
307
- target: 'loaded',
308
- actions: 'setQrcode',
309
- },
310
- ],
330
+ SELECT_QRCODE: {
331
+ target: 'defaultMode',
332
+ actions: 'setQrcode',
333
+ },
311
334
  },
312
335
  },
313
336
  },
@@ -326,11 +349,10 @@ export default function (request) {
326
349
  }
327
350
  }),
328
351
  setInitData: assign((context, event) => {
329
- const { siteConfig, paymentDetail } = event.data
352
+ const { paymentDetail } = event.data
330
353
  const qrcodes = paymentDetail.filter((element) => element.category === context.currentCategory)
331
354
 
332
355
  return {
333
- siteConfig,
334
356
  paymentDetail,
335
357
  qrcodes,
336
358
  selectedQrcode: qrcodes[0],
@@ -339,9 +361,10 @@ export default function (request) {
339
361
  grandTotalEnable: qrcodes[0].grandTotalEnable,
340
362
  }
341
363
  }),
342
- setBonusPreview: assign((context, event) => {
364
+ preset: assign((context, event) => {
365
+ const { siteConfig } = event.data
343
366
  return {
344
- bonusPreviewData: event.data.bonus,
367
+ siteConfig,
345
368
  }
346
369
  }),
347
370
  setQrcode: assign((context, event) => {
@@ -386,11 +409,11 @@ export default function (request) {
386
409
  }),
387
410
  },
388
411
  guards: {
389
- isFreeWalletMode: (context, event) => {
412
+ isNewWalletMode: (context, event) => {
390
413
  return context.siteConfig?.walletMode === '2'
391
414
  },
392
- isGrandTotalEnable: (context, event) => {
393
- return context.grandTotalEnable === 1
415
+ hasMinPromotionDeposit: (context, event) => {
416
+ return context.promotion?.minimumAmount
394
417
  },
395
418
  },
396
419
  services: {
@@ -402,13 +425,6 @@ export default function (request) {
402
425
  const siteConfig = JSON.parse(window.atob(config))
403
426
  return { siteConfig, paymentDetail }
404
427
  },
405
- fetchBonusPreview: async (context, event) => {
406
- const { currentMethod, promotion } = context
407
- return await request.send({
408
- paymentMethod: currentMethod,
409
- promotionsNo: promotion?.activityNo,
410
- })
411
- },
412
428
  fetchCalculation: async (context, event) => {
413
429
  const { currentMethod, selectedAmount, promotion } = context
414
430
  return await request.send(