@jetthai/cuora 1.1.15 → 1.1.17

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,155 @@
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
+ turnoverLimitStatus: '',
27
+ originalTurnoverLimit: 0,
28
+ originalMaxWithdrawAmount: 0,
29
+ originalLimitGameDetail: [],
30
+ newTurnoverLimit: 0,
31
+ newMaxWithdrawAmount: 0,
32
+ newLimitGameDetail: [],
33
+ promotionsList: [],
34
+ selectedPromo: {},
35
+ },
36
+ states: {
37
+ loading: {
38
+ invoke: {
39
+ src: 'fetchInitData',
40
+ onDone: {
41
+ target: 'loaded',
42
+ actions: 'setInitData',
43
+ },
44
+ onError: {
45
+ target: 'fail',
46
+ },
47
+ },
48
+ },
49
+ loaded: {
50
+ on: {
51
+ SELECT_PROMO: {
52
+ actions: ['reset', 'setSelectedPromo'],
53
+ },
54
+ SET_AMOUNT: {
55
+ actions: 'setAmount',
56
+ },
57
+ JOIN: {
58
+ target: 'fetching',
59
+ cond: 'isValidAmount',
60
+ },
61
+ },
62
+ },
63
+ fetching: {
64
+ invoke: {
65
+ src: 'fetchWithdrawRulePreview',
66
+ onDone: {
67
+ target: 'pending',
68
+ actions: 'setWithdrawRulePreview',
69
+ },
70
+ onError: {
71
+ target: 'loaded',
72
+ },
73
+ },
74
+ },
75
+ pending: {
76
+ on: {
77
+ CONFIRM: {
78
+ target: 'joinning',
79
+ },
80
+ BACK: {
81
+ target: 'loaded',
82
+ },
83
+ },
84
+ },
85
+ joinning: {
86
+ invoke: {
87
+ src: 'applyPromotion',
88
+ onDone: {
89
+ target: 'joined',
90
+ },
91
+ onError: {
92
+ target: 'fail',
93
+ },
94
+ },
95
+ },
96
+ joined: {},
97
+ fail: {},
98
+ },
99
+ },
100
+ {
101
+ actions: {
102
+ setInitData: assign((context, event) => {
103
+ const { promotionsList } = event.data
104
+ const { noBonus } = context
105
+ return {
106
+ promotionsList,
107
+ selectedPromo: noBonus,
108
+ }
109
+ }),
110
+ setSelectedPromo: assign((context, event) => {
111
+ return {
112
+ selectedPromo: event.data,
113
+ }
114
+ }),
115
+ setAmount: assign((context, event) => {
116
+ return {
117
+ amount: event.data,
118
+ }
119
+ }),
120
+ setWithdrawRulePreview: assign((context, event) => {
121
+ return {
122
+ ...event.data,
123
+ }
124
+ }),
125
+ reset: assign((context, event) => {
126
+ return {
127
+ amount: null,
128
+ }
129
+ }),
130
+ },
131
+ guards: {
132
+ isValidAmount: (context, event) => {
133
+ const { selectedPromo, amount } = context
134
+ return selectedPromo.minimumAmount <= amount
135
+ },
136
+ },
137
+ services: {
138
+ fetchInitData: async (context, event) => {
139
+ return await request.send(payment.getPromotionsList())
140
+ },
141
+ fetchWithdrawRulePreview: async (context, event) => {
142
+ const { selectedPromo, amount } = context
143
+ const { data } = await request.send(
144
+ payment.getWithdrawRulePreview({ applyType: 'promotions', applyNo: selectedPromo.promotionsNo, amount: parseFloat(amount) })
145
+ )
146
+ return data
147
+ },
148
+ applyPromotion: async (context, event) => {
149
+ const { selectedPromo, amount } = context
150
+ return await request.send(payment.applyPromotions({ promotionsNo: selectedPromo.promotionsNo, amount: parseFloat(amount) }))
151
+ },
152
+ },
153
+ }
154
+ )
155
+ }
@@ -1,5 +1,6 @@
1
1
  import { createMachine, assign, send } from 'xstate'
2
2
  import activity from '../api/activity.js'
3
+ import payment from '../api/payment.js'
3
4
 
4
5
  export default function (request) {
5
6
  const { appSecret } = request.config
@@ -11,6 +12,15 @@ export default function (request) {
11
12
  otherRewardList: [],
12
13
  pointsRewardList: [],
13
14
  rewardList: [],
15
+ activityNo: null,
16
+ receiveNo: null,
17
+ turnoverLimitStatus: 'NEW',
18
+ originalTurnoverLimit: 0,
19
+ originalMaxWithdrawAmount: 0,
20
+ originalLimitGameDetail: [],
21
+ newTurnoverLimit: 0,
22
+ newMaxWithdrawAmount: 0,
23
+ newLimitGameDetail: [],
14
24
  callback: () => {},
15
25
  },
16
26
  states: {
@@ -46,6 +56,10 @@ export default function (request) {
46
56
  states: {
47
57
  idle: {
48
58
  on: {
59
+ FETCH_WITHDRAW_RULE: {
60
+ target: 'fetching',
61
+ actions: 'setRewardData',
62
+ },
49
63
  RECEIVE_REWARD: {
50
64
  target: 'receiving',
51
65
  actions: 'setCallback',
@@ -56,11 +70,33 @@ export default function (request) {
56
70
  },
57
71
  },
58
72
  },
73
+ fetching: {
74
+ invoke: {
75
+ src: 'fetchWithdrawRulePreview',
76
+ onDone: {
77
+ target: 'pending',
78
+ actions: 'setWithdrawRulePreview',
79
+ },
80
+ onError: {
81
+ target: 'idle',
82
+ },
83
+ },
84
+ },
85
+ pending: {
86
+ on: {
87
+ RECEIVE_REWARD: {
88
+ target: 'receiving',
89
+ },
90
+ BACK: {
91
+ target: 'idle',
92
+ },
93
+ },
94
+ },
59
95
  receiving: {
60
96
  invoke: {
61
97
  src: 'receiveReward',
62
98
  onDone: {
63
- target: 'idle',
99
+ target: 'received',
64
100
  actions: [send({ type: 'REFRESH' }), 'doCallback'],
65
101
  },
66
102
  onError: {
@@ -68,6 +104,11 @@ export default function (request) {
68
104
  },
69
105
  },
70
106
  },
107
+ received: {
108
+ 0: {
109
+ target: 'idle',
110
+ },
111
+ },
71
112
  allPointsReceiving: {
72
113
  invoke: {
73
114
  src: 'receiveAllPoints',
@@ -93,6 +134,13 @@ export default function (request) {
93
134
  rewardList: event.data[2]?.data || [],
94
135
  }
95
136
  }),
137
+ setRewardData: assign((context, event) => {
138
+ const { activityNo, receiveNo } = event.data
139
+ return {
140
+ activityNo,
141
+ receiveNo,
142
+ }
143
+ }),
96
144
  setCallback: assign((context, event) => {
97
145
  return {
98
146
  callback: event.data?.callback || (() => {}),
@@ -101,6 +149,11 @@ export default function (request) {
101
149
  doCallback: (context, event) => {
102
150
  context.callback()
103
151
  },
152
+ setWithdrawRulePreview: (context, event) => {
153
+ return {
154
+ ...event.data,
155
+ }
156
+ },
104
157
  },
105
158
  services: {
106
159
  fetchRewardList: async (context, event) => {
@@ -110,6 +163,11 @@ export default function (request) {
110
163
  const [otherRewardList, pointsRewardList, rewardList] = await Promise.all([getOtherRewardAPI, getPointsRewardAPI, getRewardAPI])
111
164
  return [otherRewardList, pointsRewardList, rewardList]
112
165
  },
166
+ fetchWithdrawRulePreview: async (context, event) => {
167
+ const { receiveNo } = context
168
+ const { data } = await request.send(payment.getWithdrawRulePreview({ applyType: 'activity', applyNo: receiveNo, amount: null }))
169
+ return data
170
+ },
113
171
  receiveReward: async (context, event) => {
114
172
  const { activityNo, receiveNo, attended } = event.data
115
173
  return await request.send(activity.getReward({ activityNo, receiveNo, appSecret, attended }))