@jetthai/cuora 1.1.66-sabai-6 → 1.1.67

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