@jetthai/cuora 1.1.64 → 1.1.65-doubleWallet

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