@jetthai/cuora 1.1.11 → 1.1.13-2

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
@@ -220,7 +220,7 @@ export default function (request) {
220
220
  }),
221
221
  swapContent: assign((context, event) => {
222
222
  const item = event.data
223
- if (item.data?.length) {
223
+ if (item?.data?.length) {
224
224
  return {
225
225
  content: event.data,
226
226
  }
@@ -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,115 @@
1
+ import { assign, createMachine } from 'xstate'
2
+ import payment from '../api/payment.js'
3
+
4
+ export default function (request) {
5
+ return createMachine(
6
+ {
7
+ id: 'promotions',
8
+ initial: 'loading',
9
+ context: {
10
+ noBonus: {
11
+ promotionsNo: 'No Bonus',
12
+ title: 'No Bonus',
13
+ adSmallUrl: [
14
+ {
15
+ url: '~/assets/images/deposit/deposit_img_nobonus_normal.png',
16
+ name: 'No Bonus',
17
+ },
18
+ ],
19
+ descrip: 'no_bonus',
20
+ minimumAmount: 0,
21
+ turnoverLimitMultiple: 1,
22
+ promotionDetail: [],
23
+ withdrawLimitDetail: [],
24
+ limitGameDetail: [],
25
+ },
26
+ promotionsList: [],
27
+ selectedPromo: {},
28
+ joinedPromotion: null,
29
+ },
30
+ states: {
31
+ loading: {
32
+ invoke: {
33
+ src: 'fetchPromotionsList',
34
+ onDone: {
35
+ target: 'loaded',
36
+ actions: 'setInit',
37
+ },
38
+ onError: {
39
+ target: 'fail',
40
+ },
41
+ },
42
+ },
43
+ fetching: {
44
+ invoke: {
45
+ src: 'fetchJoinedPromotion',
46
+ onDone: {
47
+ target: 'loaded',
48
+ actions: 'setJoinedPromotion',
49
+ },
50
+ onError: {
51
+ target: 'fail',
52
+ },
53
+ },
54
+ },
55
+ loaded: {
56
+ on: {
57
+ SELECT_PROMO: {
58
+ actions: 'setSelectedPromo',
59
+ },
60
+ SET_AMOUNT: {
61
+ actions: 'setAmount',
62
+ },
63
+ CONFIRM: {
64
+ target: 'joinning',
65
+ cond: 'isValidAmount',
66
+ },
67
+ },
68
+ },
69
+ fail: {},
70
+ joinning: {},
71
+ },
72
+ },
73
+ {
74
+ actions: {
75
+ setInit: assign((context, event) => {
76
+ return {
77
+ promotionsList: event.data,
78
+ selectedPromo: context.noBonus,
79
+ }
80
+ }),
81
+ setJoinedPromotion: assign((context, event) => {
82
+ return {
83
+ joinedPromotion: event.data,
84
+ }
85
+ }),
86
+ setSelectedPromo: assign((context, event) => {
87
+ return {
88
+ selectedPromo: event.data,
89
+ }
90
+ }),
91
+ setAmount: assign((context, event) => {
92
+ return {
93
+ amount: event.data,
94
+ }
95
+ }),
96
+ },
97
+ guards: {
98
+ isValidAmount: (context, event) => {
99
+ const { minimumAmount, amount } = context
100
+ return minimumAmount <= amount
101
+ },
102
+ },
103
+ services: {
104
+ fetchPromotionsList: async (context, event) => {
105
+ const { data } = await request.send(payment.getPromotionsList())
106
+ return data
107
+ },
108
+ fetchJoinedPromotion: async (context, event) => {
109
+ const { data } = await request.send(payment.getJoinedPromotion())
110
+ return data
111
+ },
112
+ },
113
+ }
114
+ )
115
+ }
@@ -87,16 +87,9 @@ export default function (request) {
87
87
 
88
88
  if (isTopItem) {
89
89
  if (hasSubMenu) {
90
- const isSameBranch = menuItemStack[0].categoryId === inputItem.categoryId
91
- if (isSameBranch) {
92
- return {
93
- previousMenuItemStack: menuItemStack,
94
- }
95
- } else {
96
- return {
97
- previousMenuItemStack: menuItemStack,
98
- menuItemStack: [event.data],
99
- }
90
+ return {
91
+ previousMenuItemStack: menuItemStack,
92
+ menuItemStack: [event.data],
100
93
  }
101
94
  } else {
102
95
  return {
@@ -166,7 +159,7 @@ function isItemInMenu(targetItem, menuList) {
166
159
  } else {
167
160
  if (currentItem.categoryId === targetItem.categoryId) {
168
161
  return true
169
- } else if (currentItem.sub.length) {
162
+ } else if (currentItem.sub?.length) {
170
163
  return isItemInMenu(targetItem, currentItem.sub)
171
164
  } else {
172
165
  return false
@@ -188,6 +181,10 @@ function addLevelProperty(list, level) {
188
181
  const nextLevel = level + 1
189
182
  for (let i = 0; i < list.length; i++) {
190
183
  list[i].level = level
191
- addLevelProperty(list[i].sub, nextLevel)
184
+
185
+ // avoid games in list
186
+ if (!list[i].isGame) {
187
+ addLevelProperty(list[i].sub, nextLevel)
188
+ }
192
189
  }
193
190
  }