@jetthai/cuora 1.1.81 → 1.1.83-cash

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.
@@ -0,0 +1,280 @@
1
+ import { assign, createMachine } from 'xstate'
2
+ import payment from '../../api/payment.js'
3
+ import common from '../../api/common.js'
4
+ import { max } from '../../util'
5
+
6
+ export default function (request, context) {
7
+ const { appSecret } = request.config
8
+ const { promotion, selectedAmount } = context || {}
9
+ return createMachine(
10
+ {
11
+ id: 'qrcode_v_cash',
12
+ initial: 'loading',
13
+ context: {
14
+ siteConfig: null,
15
+ qrcodes: null,
16
+ options: null,
17
+
18
+ selectedQrcode: null,
19
+ selectedAmount,
20
+
21
+ calculation: null,
22
+
23
+ paymentDetail: [],
24
+ currentCategory: 'qrcode',
25
+
26
+ result: null,
27
+
28
+ promotion,
29
+ bonusPreviewData: [],
30
+ },
31
+ states: {
32
+ loading: {
33
+ invoke: {
34
+ src: 'fetchInitData',
35
+ onDone: {
36
+ target: 'loaded',
37
+ actions: 'setInitData',
38
+ },
39
+ onError: {
40
+ target: 'fail',
41
+ },
42
+ },
43
+ },
44
+ fail: {},
45
+ loaded: {
46
+ on: {
47
+ SET_PROMOTION: {
48
+ target: 'debouncing',
49
+ actions: 'setPromotion',
50
+ },
51
+ SELECT_QRCODE: {
52
+ target: 'debouncing',
53
+ actions: 'setQrcode',
54
+ },
55
+ SELECT_AMOUNT: {
56
+ target: 'debouncing',
57
+ actions: 'setAmount',
58
+ },
59
+ INPUT_AMOUNT: {
60
+ target: 'debouncing',
61
+ actions: 'inputAmount',
62
+ },
63
+ },
64
+ },
65
+ debouncing: {
66
+ on: {
67
+ SET_PROMOTION: {
68
+ target: 'debouncing',
69
+ actions: 'setPromotion',
70
+ },
71
+ SELECT_QRCODE: {
72
+ target: 'debouncing',
73
+ actions: 'setQrcode',
74
+ },
75
+ SELECT_AMOUNT: {
76
+ target: 'debouncing',
77
+ actions: 'setAmount',
78
+ },
79
+ INPUT_AMOUNT: {
80
+ target: 'debouncing',
81
+ actions: 'inputAmount',
82
+ },
83
+ },
84
+ after: {
85
+ 1000: [
86
+ {
87
+ target: 'calculating',
88
+ cond: (context, event) => {
89
+ const { selectedQrcode, selectedAmount } = context
90
+ if (selectedQrcode && selectedAmount) {
91
+ return selectedQrcode.minimum <= selectedAmount && selectedAmount <= selectedQrcode.maximum
92
+ } else {
93
+ return false
94
+ }
95
+ },
96
+ },
97
+ {
98
+ target: 'loaded',
99
+ },
100
+ ],
101
+ },
102
+ },
103
+ calculating: {
104
+ invoke: {
105
+ src: 'fetchCalculation',
106
+ onDone: {
107
+ target: 'calculated',
108
+ actions: 'setCalculation',
109
+ },
110
+ onError: {
111
+ target: 'calculated',
112
+ },
113
+ },
114
+ },
115
+ calculated: {
116
+ on: {
117
+ SET_PROMOTION: {
118
+ target: 'debouncing',
119
+ actions: 'setPromotion',
120
+ },
121
+ SELECT_QRCODE: {
122
+ target: 'debouncing',
123
+ actions: 'setQrcode',
124
+ },
125
+ SELECT_AMOUNT: {
126
+ target: 'debouncing',
127
+ actions: 'setAmount',
128
+ },
129
+ INPUT_AMOUNT: {
130
+ target: 'debouncing',
131
+ actions: 'inputAmount',
132
+ },
133
+ CONFIRM: {
134
+ target: 'submitting',
135
+ },
136
+ },
137
+ },
138
+ submitting: {
139
+ invoke: {
140
+ src: 'submitDeposit',
141
+ onDone: {
142
+ target: 'submitted',
143
+ actions: 'setResult',
144
+ },
145
+ onError: {
146
+ target: 'calculated',
147
+ },
148
+ },
149
+ },
150
+ submitted: {},
151
+ },
152
+ },
153
+ {
154
+ actions: {
155
+ setInitData: assign((context, event) => {
156
+ const { selectedAmount } = context
157
+ const { siteConfig, paymentDetail } = event.data
158
+ const qrcodes = paymentDetail
159
+ .filter((element) => element.category === context.currentCategory)
160
+ .map((qrcode) => {
161
+ qrcode.disabled = promotion?.promotionsNo !== 'none' && qrcode.charge > 0
162
+ return qrcode
163
+ })
164
+
165
+ const selectedQrcode = qrcodes.find((qrcode) => !qrcode.disabled)
166
+
167
+ return {
168
+ siteConfig,
169
+ paymentDetail,
170
+ promotion,
171
+ qrcodes,
172
+ selectedQrcode,
173
+ options: selectedQrcode?.optional,
174
+ selectedAmount: max(promotion?.minimumAmount, selectedQrcode?.minimum, selectedAmount, 0),
175
+ }
176
+ }),
177
+ setBonusPreview: assign((context, event) => {
178
+ return {
179
+ bonusPreviewData: event.data.bonus,
180
+ }
181
+ }),
182
+ setPromotion: assign((context, event) => {
183
+ const { selectedAmount } = context
184
+ const promotion = event.data
185
+ const qrcodes = context.qrcodes.map((qrcode) => {
186
+ qrcode.disabled = promotion.promotionsNo !== 'none' && qrcode.charge > 0
187
+ return qrcode
188
+ })
189
+
190
+ const selectedQrcode = qrcodes.find((qrcode) => !qrcode.disabled)
191
+
192
+ return {
193
+ promotion,
194
+ qrcodes,
195
+ selectedQrcode,
196
+ options: selectedQrcode?.optional,
197
+ selectedAmount: max(promotion.minimumAmount, selectedQrcode?.minimum, selectedAmount, 0),
198
+ calculation: null,
199
+ }
200
+ }),
201
+ setQrcode: assign((context, event) => {
202
+ const { promotion, selectedAmount } = context
203
+ const selectedQrcode = event.data
204
+ return {
205
+ selectedQrcode,
206
+ options: selectedQrcode.optional,
207
+ selectedAmount: max(promotion.minimumAmount, selectedAmount, 0),
208
+ calculation: null,
209
+ }
210
+ }),
211
+ setAmount: assign((context, event) => {
212
+ // 現金網可自由填額度,grandTotalEnable 欄位感覺不再需要?
213
+ if (context.selectedQrcode?.grandTotalEnable === 1) {
214
+ return { selectedAmount: parseFloat(context.selectedAmount || 0) + parseFloat(event.data) }
215
+ } else {
216
+ return { selectedAmount: event.data }
217
+ }
218
+ }),
219
+ inputAmount: assign((context, event) => {
220
+ return { selectedAmount: event.data }
221
+ }),
222
+ setCalculation: assign((context, event) => {
223
+ return {
224
+ calculation: event.data,
225
+ }
226
+ }),
227
+ clearCalculation: assign((context, event) => {
228
+ return {
229
+ calculation: null,
230
+ }
231
+ }),
232
+ setResult: assign((context, event) => {
233
+ return {
234
+ result: event.data,
235
+ }
236
+ }),
237
+ },
238
+ guards: {},
239
+ services: {
240
+ fetchInitData: async (context, event) => {
241
+ const [{ config }, paymentDetail = [], promotions] = await Promise.all([
242
+ request.send(common.getConfig({ appSecret })),
243
+ request.send(payment.getPaymentDetail({ transferType: 'DEPOSIT' })),
244
+ ])
245
+ const siteConfig = JSON.parse(window.atob(config))
246
+ return { siteConfig, paymentDetail }
247
+ },
248
+ fetchBonusPreview: async (context, event) => {
249
+ const { selectedQrcode, promotion } = context
250
+ return await request.send(
251
+ payment.getBonusPreview({
252
+ method: selectedQrcode.method,
253
+ promotionsNo: promotion?.promotionsNo,
254
+ })
255
+ )
256
+ },
257
+ fetchCalculation: async (context, event) => {
258
+ const { selectedQrcode, selectedAmount, promotion } = context
259
+ return await request.send(
260
+ payment.getDepositExpectedResult({
261
+ method: selectedQrcode.method,
262
+ amount: selectedAmount,
263
+ promotionsNo: promotion?.promotionsNo,
264
+ })
265
+ )
266
+ },
267
+ submitDeposit: async (context, event) => {
268
+ const { selectedQrcode, selectedAmount, promotion } = context
269
+ return await request.send(
270
+ payment.submitDepositTransaction({
271
+ method: selectedQrcode.method,
272
+ amount: selectedAmount,
273
+ promotionsNo: promotion?.promotionsNo,
274
+ })
275
+ )
276
+ },
277
+ },
278
+ }
279
+ )
280
+ }
@@ -110,8 +110,12 @@ export default function (request) {
110
110
  }
111
111
  },
112
112
  fetchList: async (context, event) => {
113
- const { data } = await request.send(api.getListMyFavorite())
114
- return data
113
+ if (request.getToken()) {
114
+ const { data } = await request.send(api.getListMyFavorite())
115
+ return data
116
+ } else {
117
+ return []
118
+ }
115
119
  },
116
120
  },
117
121
  }
@@ -26,6 +26,7 @@ export default function (request) {
26
26
  timestamp: null,
27
27
  totalPage: 0,
28
28
  },
29
+ staticData: [],
29
30
  // play params
30
31
  game: {
31
32
  providerId: null,
@@ -46,6 +47,9 @@ export default function (request) {
46
47
  idle: {
47
48
  enter: 'clearGameInfo',
48
49
  on: {
50
+ SET_STATIC_DATA: {
51
+ actions: 'setStaticData',
52
+ },
49
53
  SET_ADDITION_ENABLE: {
50
54
  actions: 'setAdditionEnable',
51
55
  },
@@ -205,6 +209,11 @@ export default function (request) {
205
209
  },
206
210
  {
207
211
  actions: {
212
+ setStaticData: assign((context, event) => {
213
+ return {
214
+ staticData: event.data,
215
+ }
216
+ }),
208
217
  setAdditionEnable: assign((context, event) => {
209
218
  return {
210
219
  additionEnable: event.data,
@@ -221,11 +230,6 @@ export default function (request) {
221
230
  isLastPage: index >= content?.totalPage - 1,
222
231
  }
223
232
  }),
224
- setFavoriteList: assign((context, event) => {
225
- return {
226
- favoriteList: event.data.data || [],
227
- }
228
- }),
229
233
  setRoom: assign((context, event) => {
230
234
  return {
231
235
  room: event.data,
@@ -323,9 +327,19 @@ export default function (request) {
323
327
  },
324
328
  services: {
325
329
  getPageContent: async (context, event) => {
326
- const { room, index, additionEnable } = context
330
+ const { room, index, additionEnable, staticData } = context
327
331
  if (room.categoryId === GAME_SEARCH) {
328
332
  return
333
+ } else if (!request.getToken()) {
334
+ const list = staticData.find((data) => data.category == room.categoryId)?.info || []
335
+
336
+ return [
337
+ {
338
+ data: list.slice(index * 20, (index + 1) * 20),
339
+ totalPage: Math.ceil(list.length / 20),
340
+ timestamp: Math.floor(Date.now() / 1000),
341
+ },
342
+ ]
329
343
  } else if (additionEnable) {
330
344
  const param = { categoryId: room.categoryId, index }
331
345
  return await Promise.all([request.send(api.getListCategory(param)), request.send(api.getListAddition(param))])
@@ -338,6 +352,8 @@ export default function (request) {
338
352
  const { room, content, index, additionEnable } = context
339
353
  if (room.categoryId === GAME_SEARCH) {
340
354
  return
355
+ } else if (!request.getToken()) {
356
+ return []
341
357
  } else if (additionEnable) {
342
358
  return await Promise.all([
343
359
  request.send(
@@ -368,6 +384,7 @@ export default function (request) {
368
384
  }
369
385
  },
370
386
  connectGame: async (context, event) => {
387
+ const returnProviders = ['RSG', 'KP', 'EPICWIN', 'KA', 'AMBSLOT', 'SEXY_VENUS', 'SEXY_SEXYBCRT', 'PG', 'NPG']
371
388
  const { lang, isMobile } = context
372
389
  const { providerId, gameId, gameTypeId, mappingId } = context.game
373
390
  const params = {
@@ -378,7 +395,7 @@ export default function (request) {
378
395
  is_demo: false,
379
396
  is_mobile: isMobile,
380
397
  lang,
381
- return_url: window.location.href,
398
+ return_url: returnProviders.includes(providerId) ? `${window.location.origin}/return` : window.location.href, // For providers to return.
382
399
  }
383
400
  const { redirect_url } = await request.send(api.playGame(params))
384
401
  return { gameURL: redirect_url }
@@ -431,12 +448,22 @@ const oldGuards = {
431
448
 
432
449
  const oldServices = (request) => ({
433
450
  fetchOption: async (context, event) => {
434
- return await request.send(api.getOptionMap())
451
+ if (request.getToken()) {
452
+ return await request.send(api.getOptionMap())
453
+ }
435
454
  },
436
455
  fetchGameSHA: async (context, event) => {
437
- return await request.send(api.getGameSHA())
456
+ if (request.getToken()) {
457
+ return await request.send(api.getGameSHA())
458
+ } else {
459
+ return {
460
+ status: null,
461
+ }
462
+ }
438
463
  },
439
464
  fetchStatus: async (context, event) => {
440
- return await request.send(api.getGameStatus())
465
+ if (request.getToken()) {
466
+ return await request.send(api.getGameStatus())
467
+ }
441
468
  },
442
469
  })
@@ -3,10 +3,7 @@ import auth from './auth.js'
3
3
  import welcome from './welcome.js'
4
4
  import common from './common.js'
5
5
  import error from './error.js'
6
- import game from './game.js'
7
- import game_v2 from './game_v2.js'
8
6
  import game_v2_1 from './game_v2_1.js'
9
- import game_favorite from './game_favorite.js'
10
7
  import game_favorite_v2 from './game_favorite_v2.js'
11
8
  import game_search from './game_search.js'
12
9
  import game_search_v2 from './game_search_v2.js'
@@ -16,6 +13,7 @@ import merge from './merge.js'
16
13
  import payment_data from './payment_data.js'
17
14
  import reward_fc from './reward_fc.js'
18
15
  import reward from './reward.js'
16
+ import reward_cash from './reward_cash.js'
19
17
  import setting from './setting.js'
20
18
  import side from './side.js'
21
19
  import side_v2 from './side_v2.js'
@@ -44,9 +42,6 @@ export default {
44
42
  common,
45
43
  deposit,
46
44
  error,
47
- game,
48
- game_v2,
49
- game_favorite,
50
45
  game_favorite_v2,
51
46
  game_search,
52
47
  game_search_v2,
@@ -55,6 +50,7 @@ export default {
55
50
  merge,
56
51
  payment_data,
57
52
  reward,
53
+ reward_cash,
58
54
  reward_fc,
59
55
  setting,
60
56
  side,
@@ -0,0 +1,220 @@
1
+ import { createMachine, assign, send } from 'xstate'
2
+ import activity from '../api/activity.js'
3
+ import payment from '../api/payment.js'
4
+
5
+ export default function (request) {
6
+ const { appSecret } = request.config
7
+ return createMachine(
8
+ {
9
+ id: 'reward_cash',
10
+ type: 'parallel',
11
+ context: {
12
+ hasAuth: false,
13
+ otherRewardList: [],
14
+ pointsRewardList: [],
15
+ rewardList: [],
16
+ activityNo: null,
17
+ receiveNo: null,
18
+ withdrawRule: {},
19
+ callback: () => {},
20
+ },
21
+ states: {
22
+ timer: {
23
+ initial: 'checking',
24
+ states: {
25
+ checking: {
26
+ always: [
27
+ {
28
+ target: 'loading',
29
+ cond: (context, event) => {
30
+ return context.hasAuth
31
+ },
32
+ },
33
+ ],
34
+ },
35
+ loading: {
36
+ invoke: {
37
+ src: 'fetchRewardList',
38
+ onDone: {
39
+ target: 'pending',
40
+ actions: 'setRewardList',
41
+ },
42
+ onError: {
43
+ target: 'pending',
44
+ },
45
+ },
46
+ },
47
+ pending: {
48
+ after: {
49
+ 20000: { target: 'loading' },
50
+ },
51
+ },
52
+ },
53
+ on: {
54
+ REFRESH: {
55
+ target: '.loading',
56
+ },
57
+ },
58
+ },
59
+ reward: {
60
+ initial: 'idle',
61
+ states: {
62
+ idle: {
63
+ on: {
64
+ FETCH_WITHDRAW_RULE: {
65
+ target: 'fetching',
66
+ actions: 'setRewardData',
67
+ },
68
+ RECEIVE_REWARD: {
69
+ target: 'receiving',
70
+ actions: 'setCallback',
71
+ },
72
+ RECEIVE_ALL_POINTS: {
73
+ target: 'allPointsReceiving',
74
+ actions: 'setCallback',
75
+ },
76
+ },
77
+ },
78
+ fetching: {
79
+ invoke: {
80
+ src: 'fetchWithdrawRulePreview',
81
+ onDone: {
82
+ target: 'pending',
83
+ actions: 'setWithdrawRulePreview',
84
+ },
85
+ onError: {
86
+ target: 'idle',
87
+ },
88
+ },
89
+ },
90
+ pending: {
91
+ on: {
92
+ RECEIVE_REWARD: {
93
+ target: 'receiving',
94
+ actions: 'setCallback',
95
+ },
96
+ BACK: {
97
+ target: 'idle',
98
+ },
99
+ },
100
+ },
101
+ receiving: {
102
+ invoke: {
103
+ src: 'receiveReward',
104
+ onDone: {
105
+ target: 'received',
106
+ actions: [send({ type: 'REFRESH' }), 'doCallback'],
107
+ },
108
+ onError: {
109
+ target: 'idle',
110
+ },
111
+ },
112
+ },
113
+ received: {
114
+ after: {
115
+ 0: {
116
+ target: 'idle',
117
+ },
118
+ },
119
+ },
120
+ allPointsReceiving: {
121
+ invoke: {
122
+ src: 'receiveAllPoints',
123
+ onDone: {
124
+ target: 'idle',
125
+ actions: [send({ type: 'REFRESH' }), 'doCallback'],
126
+ },
127
+ onError: {
128
+ target: 'idle',
129
+ },
130
+ },
131
+ },
132
+ },
133
+ },
134
+ },
135
+ on: {
136
+ SET_AUTH: {
137
+ target: '.timer.checking',
138
+ actions: 'setAuth',
139
+ cond: (context, event) => {
140
+ console.log(context.hasAuth, event.data)
141
+ return context.hasAuth !== event.data
142
+ },
143
+ },
144
+ },
145
+ },
146
+ {
147
+ actions: {
148
+ setAuth: assign((context, event) => {
149
+ return { hasAuth: event.data }
150
+ }),
151
+ setRewardList: assign((context, event) => {
152
+ return {
153
+ otherRewardList: event.data[0]?.data || [],
154
+ pointsRewardList: event.data[1]?.data || [],
155
+ rewardList: event.data[2]?.data || [],
156
+ }
157
+ }),
158
+ setRewardData: assign((context, event) => {
159
+ const { activityNo, receiveNo } = event.data
160
+ return {
161
+ activityNo,
162
+ receiveNo,
163
+ }
164
+ }),
165
+ setCallback: assign((context, event) => {
166
+ return {
167
+ callback: event.data?.callback || (() => {}),
168
+ }
169
+ }),
170
+ doCallback: (context, event) => {
171
+ context.callback()
172
+ },
173
+ setWithdrawRulePreview: assign((context, event) => {
174
+ return {
175
+ withdrawRule: event.data,
176
+ }
177
+ }),
178
+ },
179
+ services: {
180
+ fetchRewardList: async (context, event) => {
181
+ const getRewardAPI = request.send(activity.getRewardList({ count: 30, appSecret }))
182
+ const getPointsRewardAPI = request.send(
183
+ activity.getRewardList({
184
+ rewardType: 'POINTS',
185
+ count: 30,
186
+ appSecret,
187
+ })
188
+ )
189
+ const getOtherRewardAPI = request.send(
190
+ activity.getRewardList({
191
+ rewardType: 'CASH,FREE',
192
+ count: 30,
193
+ appSecret,
194
+ })
195
+ )
196
+ const [otherRewardList, pointsRewardList, rewardList] = await Promise.all([getOtherRewardAPI, getPointsRewardAPI, getRewardAPI])
197
+ return [otherRewardList, pointsRewardList, rewardList]
198
+ },
199
+ fetchWithdrawRulePreview: async (context, event) => {
200
+ const { receiveNo } = context
201
+ const data = await request.send(
202
+ payment.getWithdrawRulePreview({
203
+ applyType: 'activity',
204
+ applyNo: receiveNo,
205
+ amount: null,
206
+ })
207
+ )
208
+ return data
209
+ },
210
+ receiveReward: async (context, event) => {
211
+ const { activityNo, receiveNo, attended } = event.data
212
+ return await request.send(activity.getReward({ activityNo, receiveNo, appSecret, attended }))
213
+ },
214
+ receiveAllPoints: async (context, event) => {
215
+ return await request.send(activity.collect({ collectType: 'collectPoints', appSecret }))
216
+ },
217
+ },
218
+ }
219
+ )
220
+ }
@@ -1,5 +1,6 @@
1
1
  import { assign, createMachine } from 'xstate'
2
2
  import user from '../api/user.js'
3
+ import payment from '../api/payment.js'
3
4
 
4
5
  export default function (request) {
5
6
  return createMachine(
@@ -8,6 +9,7 @@ export default function (request) {
8
9
  initial: 'fetching',
9
10
  context: {
10
11
  userInfo: {},
12
+ bankList: [],
11
13
  },
12
14
  states: {
13
15
  fetching: {
@@ -47,13 +49,17 @@ export default function (request) {
47
49
  actions: {
48
50
  setUserInfo: assign((context, event) => {
49
51
  return {
50
- userInfo: event.data,
52
+ userInfo: event.data.userInfo,
53
+ bankList: event.data.bankList,
51
54
  }
52
55
  }),
53
56
  },
54
57
  services: {
55
58
  fetchUserInfo: async (context, event) => {
56
- return await request.send(user.getUserInfo())
59
+ const paymentDetail = await request.send(payment.getPaymentDetail({ transferType: 'WITHDRAW' }))
60
+ const method = paymentDetail.find((payment) => payment.category === 'manual').method
61
+ const [bankList, userInfo] = await Promise.all([request.send(payment.getBankList(method)), request.send(user.getUserInfo())])
62
+ return { bankList, userInfo }
57
63
  },
58
64
  updateUserInfo: async (context, event) => {
59
65
  return await request.send(user.updateUserInfo(event.data))