@jetthai/cuora 1.1.15-1 → 1.1.16

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,12 +1,15 @@
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: 'qrcode',
8
10
  initial: 'loading',
9
11
  context: {
12
+ siteConfig: null,
10
13
  qrcodes: null,
11
14
  options: null,
12
15
 
@@ -15,7 +18,7 @@ export default function (request) {
15
18
 
16
19
  calculation: null,
17
20
 
18
- paymentDetails: [],
21
+ paymentDetail: [],
19
22
  currentCategory: 'qrcode',
20
23
  currentMethod: null,
21
24
 
@@ -28,15 +31,152 @@ export default function (request) {
28
31
  invoke: {
29
32
  src: 'fetchInitData',
30
33
  onDone: {
31
- target: 'loaded',
32
- actions: 'setInitData',
34
+ target: 'checking',
35
+ actions: ['setInitData', 'preset'],
33
36
  },
34
37
  onError: {
35
38
  target: 'fail',
36
39
  },
37
40
  },
38
41
  },
39
- loaded: {
42
+ checking: {
43
+ always: [{ target: 'promotionApplyMode', cond: 'isPromotionApplyMode' }, { target: 'defaultMode' }],
44
+ },
45
+ promotionApplyMode: {
46
+ initial: 'loaded',
47
+ states: {
48
+ loaded: {
49
+ entry: 'reset',
50
+ on: {
51
+ SELECT_QRCODE: {
52
+ actions: 'setQrcode',
53
+ },
54
+ SELECT_AMOUNT: [
55
+ {
56
+ target: 'submittable',
57
+ actions: 'addAmount',
58
+ cond: (context, event) => context.grandTotalEnable === 1,
59
+ },
60
+ {
61
+ target: 'submittable',
62
+ actions: 'setAmount',
63
+ },
64
+ ],
65
+ KEY_IN: {
66
+ actions: 'setAmount',
67
+ },
68
+ },
69
+ },
70
+ submittable: {
71
+ on: {
72
+ SELECT_AMOUNT: [
73
+ {
74
+ actions: 'addAmount',
75
+ cond: (context, event) => context.grandTotalEnable === 1,
76
+ },
77
+ {
78
+ actions: 'setAmount',
79
+ },
80
+ ],
81
+ KEY_IN: {
82
+ actions: 'setAmount',
83
+ },
84
+ CONFIRM: {
85
+ target: 'debouncing',
86
+ },
87
+ BACK: {
88
+ target: 'loaded',
89
+ },
90
+ },
91
+ },
92
+ debouncing: {
93
+ on: {
94
+ SELECT_AMOUNT: [
95
+ {
96
+ target: 'debouncing',
97
+ actions: 'addAmount',
98
+ cond: (context, event) => context.grandTotalEnable === 1,
99
+ },
100
+ {
101
+ target: 'debouncing',
102
+ actions: 'setAmount',
103
+ },
104
+ ],
105
+ KEY_IN: {
106
+ target: 'debouncing',
107
+ actions: 'setAmount',
108
+ },
109
+ BACK: {
110
+ target: 'loaded',
111
+ },
112
+ },
113
+ after: {
114
+ 1000: {
115
+ target: 'calculating',
116
+ },
117
+ },
118
+ },
119
+ calculable: {
120
+ entry: 'clearCalculation',
121
+ on: {
122
+ SELECT_AMOUNT: [
123
+ {
124
+ target: 'debouncing',
125
+ actions: 'addAmount',
126
+ cond: (context, event) => context.grandTotalEnable === 1,
127
+ },
128
+ {
129
+ target: 'debouncing',
130
+ actions: 'setAmount',
131
+ },
132
+ ],
133
+ KEY_IN: {
134
+ target: 'debouncing',
135
+ actions: 'setAmount',
136
+ },
137
+ CALCULATE: {
138
+ target: 'debouncing',
139
+ },
140
+ BACK: {
141
+ target: 'loaded',
142
+ },
143
+ },
144
+ },
145
+ calculating: {
146
+ invoke: {
147
+ src: 'fetchCalculation',
148
+ onDone: {
149
+ target: 'submitting',
150
+ actions: 'setCalculation',
151
+ },
152
+ onError: {
153
+ target: 'calculable',
154
+ },
155
+ },
156
+ },
157
+ submitting: {
158
+ invoke: {
159
+ src: 'submitDeposit',
160
+ onDone: {
161
+ target: 'submitted',
162
+ actions: 'setResult',
163
+ },
164
+ onError: {
165
+ target: 'submittable',
166
+ },
167
+ },
168
+ },
169
+ submitted: {
170
+ on: {
171
+ SELECT_QRCODE: {
172
+ target: 'loaded',
173
+ actions: 'setQrcode',
174
+ },
175
+ },
176
+ },
177
+ },
178
+ },
179
+ defaultMode: {
40
180
  entry: 'reset',
41
181
  on: {
42
182
  SELECT_QRCODE: {
@@ -77,7 +217,7 @@ export default function (request) {
77
217
  actions: 'setAmount',
78
218
  },
79
219
  BACK: {
80
- target: 'loaded',
220
+ target: 'defaultMode',
81
221
  },
82
222
  },
83
223
  after: {
@@ -109,7 +249,7 @@ export default function (request) {
109
249
  target: 'debouncing',
110
250
  },
111
251
  BACK: {
112
- target: 'loaded',
252
+ target: 'defaultMode',
113
253
  },
114
254
  },
115
255
  },
@@ -146,7 +286,7 @@ export default function (request) {
146
286
  target: 'submitting',
147
287
  },
148
288
  BACK: {
149
- target: 'loaded',
289
+ target: 'defaultMode',
150
290
  },
151
291
  CLEAR_CALCULATION: {
152
292
  target: 'debouncing',
@@ -169,7 +309,7 @@ export default function (request) {
169
309
  submitted: {
170
310
  on: {
171
311
  SELECT_QRCODE: {
172
- target: 'loaded',
312
+ target: 'defaultMode',
173
313
  actions: 'setQrcode',
174
314
  },
175
315
  },
@@ -185,11 +325,11 @@ export default function (request) {
185
325
  }
186
326
  }),
187
327
  setInitData: assign((context, event) => {
188
- const paymentDetails = event.data
189
- const qrcodes = paymentDetails.filter((element) => element.category === context.currentCategory)
328
+ const { paymentDetail } = event.data
329
+ const qrcodes = paymentDetail.filter((element) => element.category === context.currentCategory)
190
330
 
191
331
  return {
192
- paymentDetails,
332
+ paymentDetail,
193
333
  qrcodes,
194
334
  selectedQrcode: qrcodes[0],
195
335
  currentMethod: qrcodes[0].method,
@@ -197,6 +337,12 @@ export default function (request) {
197
337
  grandTotalEnable: qrcodes[0].grandTotalEnable,
198
338
  }
199
339
  }),
340
+ preset: assign((context, event) => {
341
+ const { siteConfig } = event.data
342
+ return {
343
+ siteConfig,
344
+ }
345
+ }),
200
346
  setQrcode: assign((context, event) => {
201
347
  return {
202
348
  selectedQrcode: event.data,
@@ -227,9 +373,19 @@ export default function (request) {
227
373
  }
228
374
  }),
229
375
  },
376
+ guards: {
377
+ isPromotionApplyMode: (context, event) => {
378
+ return context.siteConfig?.promotionApplyMode === '1'
379
+ },
380
+ },
230
381
  services: {
231
382
  fetchInitData: async (context, event) => {
232
- return await request.send(payment.getPaymentDetail({ transferType: 'DEPOSIT' }))
383
+ const [{ config }, paymentDetail = []] = await Promise.all([
384
+ request.send(common.getConfig({ appSecret })),
385
+ request.send(payment.getPaymentDetail({ transferType: 'DEPOSIT' })),
386
+ ])
387
+ const siteConfig = JSON.parse(window.atob(config))
388
+ return { siteConfig, paymentDetail }
233
389
  },
234
390
  fetchCalculation: async (context, event) => {
235
391
  const { currentMethod, selectedAmount } = context
@@ -33,6 +33,7 @@ import leaderboard from './leaderboard.js'
33
33
  import auth_otp_v2 from './auth_otp_v2.js'
34
34
  import auth_otp_v3 from './auth_otp_v3.js'
35
35
  import vip_table from './vip_table.js'
36
+ import promotions from './promotions.js'
36
37
 
37
38
  export default {
38
39
  ...activity,
@@ -71,4 +72,5 @@ export default {
71
72
  auth_otp_v2,
72
73
  auth_otp_v3,
73
74
  vip_table,
75
+ promotions,
74
76
  }
@@ -0,0 +1,139 @@
1
+ import { assign, createMachine } from 'xstate'
2
+ import payment from '../api/payment.js'
3
+ import user from '../api/user.js'
4
+
5
+ export default function (request) {
6
+ return createMachine(
7
+ {
8
+ id: 'promotions',
9
+ initial: 'loading',
10
+ context: {
11
+ noBonus: {
12
+ promotionsNo: 'No Bonus',
13
+ title: 'No Bonus',
14
+ adSmallUrl: [
15
+ {
16
+ url: '~/assets/images/deposit/deposit_img_nobonus_normal.png',
17
+ name: 'No Bonus',
18
+ },
19
+ ],
20
+ descrip: 'no_bonus',
21
+ minimumAmount: 0,
22
+ turnoverLimitMultiple: 1,
23
+ promotionDetail: [],
24
+ withdrawLimitDetail: [],
25
+ limitGameDetail: [],
26
+ },
27
+ oldTargetTurnoverLimit: 0,
28
+ newTargetTurnoverLimit: 0,
29
+ promotionsList: [],
30
+ selectedPromo: {},
31
+ joinedPromotion: null,
32
+ },
33
+ states: {
34
+ loading: {
35
+ invoke: {
36
+ src: 'fetchInitData',
37
+ onDone: {
38
+ target: 'loaded',
39
+ actions: 'setInitData',
40
+ },
41
+ onError: {
42
+ target: 'fail',
43
+ },
44
+ },
45
+ },
46
+ loaded: {
47
+ on: {
48
+ SELECT_PROMO: {
49
+ actions: ['reset', 'setSelectedPromo'],
50
+ },
51
+ SET_AMOUNT: {
52
+ actions: 'setAmount',
53
+ },
54
+ JOIN: {
55
+ target: 'check',
56
+ cond: 'isValidAmount',
57
+ },
58
+ },
59
+ },
60
+ check: {
61
+ entry: 'preset',
62
+ on: {
63
+ CONFIRM: {
64
+ target: 'joinning',
65
+ },
66
+ BACK: {
67
+ target: 'loaded',
68
+ },
69
+ },
70
+ },
71
+ joinning: {
72
+ invoke: {
73
+ src: 'applyPromotion',
74
+ onDone: {
75
+ target: 'joined',
76
+ },
77
+ onError: {
78
+ target: 'fail',
79
+ },
80
+ },
81
+ },
82
+ joined: {},
83
+ fail: {},
84
+ },
85
+ },
86
+ {
87
+ actions: {
88
+ setInitData: assign((context, event) => {
89
+ const { userInfo, promotionsList } = event.data
90
+ const { noBonus } = context
91
+ return {
92
+ promotionsList,
93
+ userInfo,
94
+ selectedPromo: noBonus,
95
+ }
96
+ }),
97
+ setSelectedPromo: assign((context, event) => {
98
+ return {
99
+ selectedPromo: event.data,
100
+ }
101
+ }),
102
+ setAmount: assign((context, event) => {
103
+ return {
104
+ amount: event.data,
105
+ }
106
+ }),
107
+ reset: assign((context, event) => {
108
+ return {
109
+ amount: null,
110
+ }
111
+ }),
112
+ preset: assign((context, event) => {
113
+ const { userInfo, selectedPromo, amount } = context
114
+ const { turnoverLimitMultiple } = selectedPromo
115
+ return {
116
+ oldTargetTurnoverLimit: userInfo.target_withdraw_limit,
117
+ newTargetTurnoverLimit: parseFloat(`${amount}`) * parseFloat(`${turnoverLimitMultiple}`),
118
+ }
119
+ }),
120
+ },
121
+ guards: {
122
+ isValidAmount: (context, event) => {
123
+ const { selectedPromo, amount } = context
124
+ return selectedPromo.minimumAmount <= amount
125
+ },
126
+ },
127
+ services: {
128
+ fetchInitData: async (context, event) => {
129
+ const [userInfo, promotionsList] = await Promise.all([request.send(user.getUserInfo()), request.send(payment.getPromotionsList())])
130
+ return { userInfo, promotionsList }
131
+ },
132
+ applyPromotion: async (context, event) => {
133
+ const { selectedPromo, amount } = context
134
+ return await request.send(payment.applyPromotions({ promotionsNo: selectedPromo.promotionsNo, amount: parseFloat(amount) }))
135
+ },
136
+ },
137
+ }
138
+ )
139
+ }