@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,7 +1,9 @@
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: 'float',
@@ -9,6 +11,7 @@ export default function (request) {
9
11
  context: {
10
12
  method: 'amb_float',
11
13
  userAccount: {},
14
+ siteConfig: null,
12
15
  amount: 0,
13
16
 
14
17
  bankList: [],
@@ -25,6 +28,9 @@ export default function (request) {
25
28
 
26
29
  grandTotalEnable: 1,
27
30
  ttl: 120,
31
+
32
+ promotion: null,
33
+ bonusPreviewData: [],
28
34
  },
29
35
  states: {
30
36
  loading: {
@@ -49,7 +55,10 @@ export default function (request) {
49
55
  initializing: {
50
56
  invoke: {
51
57
  src: 'initialize',
52
- onDone: { target: '#float.loaded', actions: 'setInitialization' },
58
+ onDone: {
59
+ target: '#float.loaded',
60
+ actions: 'setInitialization',
61
+ },
53
62
  onError: {
54
63
  target: '#float.unavailable',
55
64
  },
@@ -57,14 +66,38 @@ export default function (request) {
57
66
  },
58
67
  },
59
68
  },
69
+ checking: {
70
+ always: [
71
+ {
72
+ target: 'fetching',
73
+ cond: (context, event) => {
74
+ const { siteConfig = {}, promotion = {} } = context
75
+ const { walletMode = '', bonusPreviewEnable = '0' } = siteConfig
76
+ return walletMode === '4' && bonusPreviewEnable === '1' && promotion.activityNo != 'none'
77
+ },
78
+ },
79
+ { target: 'loaded' },
80
+ ],
81
+ },
82
+ fetching: {
83
+ invoke: {
84
+ src: 'fetchBonusPreview',
85
+ onDone: {
86
+ target: 'loaded',
87
+ actions: 'setBonusPreview',
88
+ },
89
+ onError: {
90
+ target: 'loaded',
91
+ },
92
+ },
93
+ },
60
94
  loaded: {
61
- entry: 'reset',
62
95
  on: {
63
96
  SELECT_AMOUNT: [
64
97
  {
65
98
  target: 'debouncing',
66
99
  actions: 'addAmount',
67
- cond: (context, event) => context.grandTotalEnable === 1,
100
+ cond: 'isGrandTotalEnable',
68
101
  },
69
102
  {
70
103
  target: 'debouncing',
@@ -75,6 +108,10 @@ export default function (request) {
75
108
  target: 'calculating',
76
109
  actions: 'setAmount',
77
110
  },
111
+ CLEAR_CALCULATION: {
112
+ target: 'debouncing',
113
+ actions: 'clearCalculation',
114
+ },
78
115
  },
79
116
  },
80
117
  debouncing: {
@@ -83,7 +120,7 @@ export default function (request) {
83
120
  {
84
121
  target: 'debouncing',
85
122
  actions: 'addAmount',
86
- cond: (context, event) => context.grandTotalEnable === 1,
123
+ cond: 'isGrandTotalEnable',
87
124
  },
88
125
  {
89
126
  target: 'debouncing',
@@ -94,9 +131,6 @@ export default function (request) {
94
131
  target: 'debouncing',
95
132
  actions: 'setAmount',
96
133
  },
97
- BACK: {
98
- target: 'loaded',
99
- },
100
134
  },
101
135
  after: {
102
136
  1000: {
@@ -111,7 +145,7 @@ export default function (request) {
111
145
  {
112
146
  target: 'debouncing',
113
147
  actions: 'addAmount',
114
- cond: (context, event) => context.grandTotalEnable === 1,
148
+ cond: 'isGrandTotalEnable',
115
149
  },
116
150
  {
117
151
  target: 'debouncing',
@@ -122,11 +156,12 @@ export default function (request) {
122
156
  target: 'debouncing',
123
157
  actions: 'setAmount',
124
158
  },
125
- CALCULATE: {
159
+ CLEAR_CALCULATION: {
126
160
  target: 'debouncing',
161
+ actions: 'clearCalculation',
127
162
  },
128
- BACK: {
129
- target: 'loaded',
163
+ CLEAR: {
164
+ actions: 'setAmount',
130
165
  },
131
166
  },
132
167
  },
@@ -148,7 +183,7 @@ export default function (request) {
148
183
  {
149
184
  target: 'debouncing',
150
185
  actions: 'addAmount',
151
- cond: (context, event) => context.grandTotalEnable === 1,
186
+ cond: 'isGrandTotalEnable',
152
187
  },
153
188
  {
154
189
  target: 'debouncing',
@@ -162,8 +197,8 @@ export default function (request) {
162
197
  CONFIRM: {
163
198
  target: 'submitting',
164
199
  },
165
- BACK: {
166
- target: 'loaded',
200
+ CLEAR: {
201
+ actions: 'setAmount',
167
202
  },
168
203
  CLEAR_CALCULATION: {
169
204
  target: 'debouncing',
@@ -174,7 +209,10 @@ export default function (request) {
174
209
  submitting: {
175
210
  invoke: {
176
211
  src: 'submitDeposit',
177
- onDone: { target: 'countdown', actions: 'setHouseBank' },
212
+ onDone: {
213
+ target: 'countdown',
214
+ actions: 'setHouseBank',
215
+ },
178
216
  onError: {
179
217
  target: 'calculated',
180
218
  },
@@ -197,6 +235,11 @@ export default function (request) {
197
235
  accountUnbound: {},
198
236
  unavailable: {},
199
237
  },
238
+ on: {
239
+ SET_PROMOTION: {
240
+ actions: 'setPromotion',
241
+ },
242
+ },
200
243
  },
201
244
  {
202
245
  actions: {
@@ -205,6 +248,17 @@ export default function (request) {
205
248
  userAccount: event.data.bankInfo?.[0],
206
249
  }
207
250
  }),
251
+ setPromotion: assign((context, event) => {
252
+ const promotion = event.data
253
+ return {
254
+ promotion,
255
+ }
256
+ }),
257
+ setBonusPreview: assign((context, event) => {
258
+ return {
259
+ bonusPreviewData: event.data.bonus,
260
+ }
261
+ }),
208
262
  setHouseBank: assign((context, event) => {
209
263
  const { accountName, accountNumber, bankName, amount } = event.data
210
264
  return {
@@ -215,9 +269,10 @@ export default function (request) {
215
269
  }
216
270
  }),
217
271
  setInitialization: assign((context, event) => {
218
- const { housePayment, bankList } = event.data
272
+ const { siteConfig, housePayment, bankList } = event.data
219
273
  const { optional, minimum, maximum, grandTotalEnable } = housePayment
220
274
  return {
275
+ siteConfig,
221
276
  options: optional,
222
277
  minimum,
223
278
  maximum,
@@ -232,11 +287,8 @@ export default function (request) {
232
287
  }
233
288
  }),
234
289
  setAmount: assign((context, event) => {
235
- return { amount: event.data }
236
- }),
237
- clear: assign((context, event) => {
238
290
  return {
239
- amount: 0,
291
+ amount: event.data,
240
292
  }
241
293
  }),
242
294
  setCalculation: assign((context, event) => {
@@ -260,32 +312,47 @@ export default function (request) {
260
312
  hasUserAccount: (context, event) => {
261
313
  return event.data.bankInfo?.[0]
262
314
  },
315
+ isGrandTotalEnable: (context, event) => {
316
+ return context.grandTotalEnable === 1
317
+ },
263
318
  },
264
319
  services: {
265
320
  fetchPaymentInfo: async (context, event) => {
266
321
  return await request.send(payment.getPaymentInfo())
267
322
  },
268
323
  initialize: async (context, event) => {
269
- const [payments, bankList] = await Promise.all([
324
+ const [{ config }, payments, bankList] = await Promise.all([
325
+ request.send(common.getConfig({ appSecret })),
270
326
  request.send(payment.getPaymentDetail({ transferType: 'DEPOSIT' })),
271
327
  request.send(payment.getBankList('amb')),
272
328
  ])
273
- return { housePayment: payments.find((payment) => payment.method === context.method), bankList }
329
+ const siteConfig = JSON.parse(window.atob(config))
330
+ return { siteConfig, housePayment: payments.find((payment) => payment.method === context.method), bankList }
331
+ },
332
+ fetchBonusPreview: async (context, event) => {
333
+ const { method, promotion } = context
334
+ return await request.send({
335
+ paymentMethod: method,
336
+ promotionsNo: promotion?.activityNo,
337
+ })
274
338
  },
275
339
  submitDeposit: async (context, event) => {
340
+ const { method, amount, promotion } = context
276
341
  return await request.send(
277
342
  payment.submitDepositTransaction({
278
- method: context.method,
279
- amount: context.amount,
343
+ method,
344
+ amount,
345
+ promotionsNo: promotion?.activityNo,
280
346
  })
281
347
  )
282
348
  },
283
349
  fetchCalculation: async (context, event) => {
284
- const { currentMethod, selectedAmount } = context
350
+ const { method, amount, promotion } = context
285
351
  return await request.send(
286
352
  payment.getDepositExpectedResult({
287
- method: context.method,
288
- amount: context.amount,
353
+ method,
354
+ amount,
355
+ promotionsNo: promotion?.activityNo,
289
356
  })
290
357
  )
291
358
  },
@@ -25,6 +25,10 @@ export default function (request) {
25
25
  currentMethod: null,
26
26
  currentPayment: null,
27
27
  result: null,
28
+
29
+ // use for wallet mode 4
30
+ promotion: null,
31
+ bonusPreviewData: [],
28
32
  },
29
33
  states: {
30
34
  loading: {
@@ -32,7 +36,7 @@ export default function (request) {
32
36
  src: 'fetchInitData',
33
37
  onDone: {
34
38
  target: 'checking',
35
- actions: ['setInitData', 'preset'],
39
+ actions: 'setInitData',
36
40
  },
37
41
  onError: {
38
42
  target: 'fail',
@@ -40,135 +44,72 @@ export default function (request) {
40
44
  },
41
45
  },
42
46
  checking: {
43
- always: [{ target: 'newWalletMode', cond: 'isNewWalletMode' }, { target: 'defaultMode' }],
44
- },
45
- newWalletMode: {
46
- initial: 'loaded',
47
- states: {
48
- loaded: {
49
- entry: 'reset',
50
- on: {
51
- SELECT_CARD: {
52
- actions: 'setCard',
53
- },
54
- SELECT_AMOUNT: {
55
- target: 'pending',
56
- actions: 'setAmount',
57
- },
58
- },
59
- },
60
- pending: {
61
- on: {
62
- SELECT_AMOUNT: {
63
- actions: 'setAmount',
64
- },
65
- CONFIRM: {
66
- target: 'debouncing',
67
- },
68
- BACK: {
69
- target: 'loaded',
70
- },
47
+ 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'
71
54
  },
72
55
  },
73
- debouncing: {
74
- on: {
75
- SELECT_AMOUNT: {
76
- target: 'debouncing',
77
- actions: 'setAmount',
78
- },
79
- BACK: {
80
- target: 'loaded',
81
- },
82
- },
83
- after: {
84
- 1000: {
85
- target: 'calculating',
86
- },
87
- },
56
+ { target: 'loaded' },
57
+ ],
58
+ },
59
+ fetching: {
60
+ invoke: {
61
+ src: 'fetchBonusPreview',
62
+ onDone: {
63
+ target: 'loaded',
64
+ actions: 'setBonusPreview',
88
65
  },
89
- calculable: {
90
- entry: 'clearCalculation',
91
- on: {
92
- SELECT_AMOUNT: {
93
- target: 'debouncing',
94
- actions: 'setAmount',
95
- },
96
- CALCULATE: {
97
- target: 'debouncing',
98
- },
99
- BACK: {
100
- target: 'loaded',
101
- },
102
- },
66
+ onError: {
67
+ target: 'loaded',
103
68
  },
104
- calculating: {
105
- invoke: {
106
- src: 'fetchCalculation',
107
- onDone: [
108
- {
109
- target: 'submitting',
110
- actions: 'setCalculation',
111
- cond: 'jumpLinkEnable',
112
- },
113
- {
114
- target: 'cardInfo',
115
- actions: 'setCalculation',
116
- },
117
- ],
118
- onError: {
119
- target: 'calculable',
69
+ },
70
+ },
71
+ fail: {},
72
+ loaded: {
73
+ entry: 'reset',
74
+ on: {
75
+ SELECT_CARD: [
76
+ {
77
+ target: 'fetching',
78
+ actions: 'setCard',
79
+ cond: (context, event) => {
80
+ const { siteConfig = {}, promotion = {} } = context
81
+ const { walletMode = '', bonusPreviewEnable = '0' } = siteConfig
82
+ return walletMode === '4' && bonusPreviewEnable === '1' && promotion.activityNo != 'none'
120
83
  },
121
84
  },
122
- },
123
- cardInfo: {
124
- on: {
125
- INPUT_CARD_NUMBER: {
126
- actions: 'setCardNumber',
127
- },
128
- INPUT_SERIAL_NUMBER: {
129
- actions: 'setSerialNumber',
130
- },
131
- SUBMIT: {
132
- target: 'submitting',
133
- cond: 'isSubmittable',
134
- },
135
- SELECT_CARD: {
136
- target: 'loaded',
137
- actions: 'setCard',
138
- },
85
+ {
86
+ actions: 'setCard',
139
87
  },
140
- },
141
- submitting: {
142
- invoke: {
143
- src: 'submitDeposit',
144
- onDone: {
145
- target: 'submitted',
146
- actions: 'setResult',
147
- },
148
- onError: {
149
- target: 'loaded',
150
- },
88
+ ],
89
+ SELECT_AMOUNT: [
90
+ {
91
+ target: 'pending',
92
+ actions: 'setAmount',
93
+ cond: 'isFreeWalletMode',
151
94
  },
152
- },
153
- submitted: {
154
- on: {
155
- BACK: {
156
- target: 'loaded',
157
- },
95
+ {
96
+ target: 'debouncing',
97
+ actions: 'setAmount',
158
98
  },
159
- },
99
+ ],
160
100
  },
161
101
  },
162
- defaultMode: {
163
- entry: 'reset',
102
+ pending: {
164
103
  on: {
165
- SELECT_CARD: {
166
- actions: 'setCard',
167
- },
168
104
  SELECT_AMOUNT: {
169
- target: 'debouncing',
170
105
  actions: 'setAmount',
171
106
  },
107
+ CONFIRM: {
108
+ target: 'calculating',
109
+ },
110
+ BACK: {
111
+ target: 'loaded',
112
+ },
172
113
  },
173
114
  },
174
115
  debouncing: {
@@ -178,7 +119,7 @@ export default function (request) {
178
119
  actions: 'setAmount',
179
120
  },
180
121
  BACK: {
181
- target: 'defaultMode',
122
+ target: 'loaded',
182
123
  },
183
124
  },
184
125
  after: {
@@ -187,22 +128,6 @@ export default function (request) {
187
128
  },
188
129
  },
189
130
  },
190
- fail: {},
191
- calculable: {
192
- entry: 'clearCalculation',
193
- on: {
194
- SELECT_AMOUNT: {
195
- target: 'debouncing',
196
- actions: 'setAmount',
197
- },
198
- CALCULATE: {
199
- target: 'debouncing',
200
- },
201
- BACK: {
202
- target: 'defaultMode',
203
- },
204
- },
205
- },
206
131
  calculating: {
207
132
  invoke: {
208
133
  src: 'fetchCalculation',
@@ -215,6 +140,18 @@ export default function (request) {
215
140
  },
216
141
  },
217
142
  },
143
+ calculable: {
144
+ entry: 'clearCalculation',
145
+ on: {
146
+ SELECT_AMOUNT: {
147
+ target: 'debouncing',
148
+ actions: 'setAmount',
149
+ },
150
+ BACK: {
151
+ target: 'loaded',
152
+ },
153
+ },
154
+ },
218
155
  calculated: {
219
156
  on: {
220
157
  SELECT_AMOUNT: {
@@ -231,7 +168,7 @@ export default function (request) {
231
168
  },
232
169
  ],
233
170
  BACK: {
234
- target: 'defaultMode',
171
+ target: 'loaded',
235
172
  },
236
173
  CLEAR_CALCULATION: {
237
174
  target: 'debouncing',
@@ -251,10 +188,21 @@ export default function (request) {
251
188
  target: 'submitting',
252
189
  cond: 'isSubmittable',
253
190
  },
254
- SELECT_CARD: {
255
- target: 'defaultMode',
256
- actions: 'setCard',
257
- },
191
+ SELECT_CARD: [
192
+ {
193
+ target: 'fetching',
194
+ actions: 'setCard',
195
+ cond: (context, event) => {
196
+ const { siteConfig = {}, promotion = {} } = context
197
+ const { walletMode = '', bonusPreviewEnable = '0' } = siteConfig
198
+ return walletMode === '4' && bonusPreviewEnable === '1' && promotion.activityNo != 'none'
199
+ },
200
+ },
201
+ {
202
+ target: 'loaded',
203
+ actions: 'setCard',
204
+ },
205
+ ],
258
206
  },
259
207
  },
260
208
  submitting: {
@@ -265,18 +213,23 @@ export default function (request) {
265
213
  actions: 'setResult',
266
214
  },
267
215
  onError: {
268
- target: 'defaultMode',
216
+ target: 'loaded',
269
217
  },
270
218
  },
271
219
  },
272
220
  submitted: {
273
221
  on: {
274
222
  BACK: {
275
- target: 'defaultMode',
223
+ target: 'loaded',
276
224
  },
277
225
  },
278
226
  },
279
227
  },
228
+ on: {
229
+ SET_PROMOTION: {
230
+ actions: 'setPromotion',
231
+ },
232
+ },
280
233
  },
281
234
  {
282
235
  actions: {
@@ -289,9 +242,10 @@ export default function (request) {
289
242
  }
290
243
  }),
291
244
  setInitData: assign((context, event) => {
292
- const { paymentDetail } = event.data
245
+ const { siteConfig, paymentDetail } = event.data
293
246
  const cards = paymentDetail.filter((element) => element.category === context.currentCategory)
294
247
  return {
248
+ siteConfig,
295
249
  paymentDetail,
296
250
  cards,
297
251
  selectedCard: cards[0],
@@ -299,10 +253,9 @@ export default function (request) {
299
253
  options: cards[0].optional,
300
254
  }
301
255
  }),
302
- preset: assign((context, event) => {
303
- const { siteConfig } = event.data
256
+ setBonusPreview: assign((context, event) => {
304
257
  return {
305
- siteConfig,
258
+ bonusPreviewData: event.data.bonus,
306
259
  }
307
260
  }),
308
261
  setCard: assign((context, event) => {
@@ -340,9 +293,15 @@ export default function (request) {
340
293
  result: event.data,
341
294
  }
342
295
  }),
296
+ setPromotion: assign((context, event) => {
297
+ const promotion = event.data
298
+ return {
299
+ promotion,
300
+ }
301
+ }),
343
302
  },
344
303
  guards: {
345
- isNewWalletMode: (context, event) => {
304
+ isFreeWalletMode: (context, event) => {
346
305
  return context.siteConfig?.walletMode === '2'
347
306
  },
348
307
  isSubmittable: (context, event) => {
@@ -363,17 +322,25 @@ export default function (request) {
363
322
  const siteConfig = JSON.parse(window.atob(config))
364
323
  return { siteConfig, paymentDetail }
365
324
  },
325
+ fetchBonusPreview: async (context, event) => {
326
+ const { currentMethod, promotion } = context
327
+ return await request.send({
328
+ paymentMethod: currentMethod,
329
+ promotionsNo: promotion?.activityNo,
330
+ })
331
+ },
366
332
  fetchCalculation: async (context, event) => {
367
- const { currentMethod, selectedAmount } = context
333
+ const { currentMethod, selectedAmount, promotion } = context
368
334
  return await request.send(
369
335
  payment.getDepositExpectedResult({
370
336
  method: currentMethod,
371
337
  amount: selectedAmount,
338
+ promotionsNo: promotion?.activityNo,
372
339
  })
373
340
  )
374
341
  },
375
342
  submitDeposit: async (context, event) => {
376
- const { currentMethod, selectedCard, selectedAmount, cardNumber, serialNumber } = context
343
+ const { currentMethod, selectedCard, selectedAmount, cardNumber, serialNumber, promotion } = context
377
344
  return await request.send(
378
345
  payment.submitDepositTransactionLoadcard({
379
346
  method: currentMethod,
@@ -381,6 +348,7 @@ export default function (request) {
381
348
  card_type: selectedCard.channel_id,
382
349
  card_code: cardNumber,
383
350
  card_seri: serialNumber,
351
+ promotionsNo: promotion?.activityNo,
384
352
  })
385
353
  )
386
354
  },