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