@jetthai/cuora 1.1.76 → 1.1.77-cash-1

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,433 @@
1
+ import { assign, createMachine } from 'xstate'
2
+ import payment from '../../api/payment.js'
3
+ import common from '../../api/common.js'
4
+
5
+ export default function (request) {
6
+ const { appSecret } = request.config
7
+ return createMachine(
8
+ {
9
+ id: 'qrcode',
10
+ initial: 'loading',
11
+ context: {
12
+ siteConfig: null,
13
+ qrcodes: null,
14
+ options: null,
15
+
16
+ selectedQrcode: null,
17
+ selectedAmount: null,
18
+
19
+ calculation: null,
20
+
21
+ paymentDetail: [],
22
+ currentCategory: 'qrcode',
23
+ currentMethod: null,
24
+
25
+ result: null,
26
+
27
+ grandTotalEnable: 1,
28
+
29
+ promotion: undefined,
30
+ bonusPreviewData: [],
31
+ },
32
+ states: {
33
+ loading: {
34
+ invoke: {
35
+ src: 'fetchInitData',
36
+ onDone: {
37
+ target: 'loaded',
38
+ actions: 'setInitData',
39
+ },
40
+ onError: {
41
+ target: 'fail',
42
+ },
43
+ },
44
+ },
45
+ fail: {},
46
+ loaded: {
47
+ entry: 'reset',
48
+ on: {
49
+ SELECT_QRCODE: [
50
+ {
51
+ target: 'fetching',
52
+ actions: 'setQrcode',
53
+ cond: (context, event) => {
54
+ const { siteConfig = {}, promotion = {} } = context
55
+ const { walletMode = '', bonusPreviewEnable = '0' } = siteConfig
56
+ return walletMode === '4' && bonusPreviewEnable === '1' && promotion.activityNo != 'none'
57
+ },
58
+ },
59
+ {
60
+ target: 'debouncing',
61
+ actions: ['setQrcode', 'setPromotionDefaultAmount'],
62
+ cond: (context, event) => context.siteConfig?.walletMode === '3' && context.promotion?.minimumAmount,
63
+ },
64
+ {
65
+ actions: 'setQrcode',
66
+ },
67
+ ],
68
+ SELECT_AMOUNT: [
69
+ {
70
+ target: 'pending',
71
+ actions: 'addAmount',
72
+ cond: (context, event) => context.siteConfig?.walletMode === '2' && context.grandTotalEnable === 1,
73
+ },
74
+ {
75
+ target: 'pending',
76
+ actions: 'setAmount',
77
+ cond: 'isFreeWalletMode',
78
+ },
79
+ {
80
+ target: 'debouncing',
81
+ actions: 'addAmount',
82
+ cond: 'isGrandTotalEnable',
83
+ },
84
+ {
85
+ target: 'debouncing',
86
+ actions: 'setAmount',
87
+ },
88
+ ],
89
+ KEY_IN: [
90
+ {
91
+ target: 'pending',
92
+ actions: 'setAmount',
93
+ cond: 'isFreeWalletMode',
94
+ },
95
+ {
96
+ target: 'calculating',
97
+ actions: 'setAmount',
98
+ },
99
+ ],
100
+ },
101
+ },
102
+ pending: {
103
+ on: {
104
+ SELECT_AMOUNT: [
105
+ {
106
+ actions: 'addAmount',
107
+ cond: 'isGrandTotalEnable',
108
+ },
109
+ {
110
+ actions: 'setAmount',
111
+ },
112
+ ],
113
+ KEY_IN: {
114
+ actions: 'setAmount',
115
+ },
116
+ CONFIRM: {
117
+ target: 'calculating',
118
+ },
119
+ BACK: {
120
+ target: 'loaded',
121
+ },
122
+ INPUT: {
123
+ target: 'debouncing',
124
+ actions: 'setAmount',
125
+ },
126
+ },
127
+ },
128
+ debouncing: {
129
+ on: {
130
+ SELECT_AMOUNT: [
131
+ {
132
+ target: 'debouncing',
133
+ actions: 'addAmount',
134
+ cond: (context, event) => context.siteConfig?.walletMode === '2' && context.grandTotalEnable === 1,
135
+ },
136
+ {
137
+ target: 'debouncing',
138
+ actions: 'setAmount',
139
+ cond: 'isFreeWalletMode',
140
+ },
141
+ {
142
+ target: 'debouncing',
143
+ actions: 'addAmount',
144
+ cond: 'isGrandTotalEnable',
145
+ },
146
+ {
147
+ target: 'debouncing',
148
+ actions: 'setAmount',
149
+ },
150
+ ],
151
+ INPUT: {
152
+ target: 'debouncing',
153
+ actions: 'setAmount',
154
+ },
155
+ BACK: {
156
+ target: 'loaded',
157
+ },
158
+ },
159
+ after: {
160
+ 1000: {
161
+ target: 'calculating',
162
+ cond: (context, event) => {
163
+ if (context.selectedQrcode) {
164
+ return context.selectedQrcode.minimum <= context.selectedAmount && context.selectedAmount <= context.selectedQrcode.maximum
165
+ } else {
166
+ return false
167
+ }
168
+ },
169
+ },
170
+ },
171
+ },
172
+ calculable: {
173
+ entry: 'clearCalculation',
174
+ on: {
175
+ SELECT_AMOUNT: [
176
+ {
177
+ target: 'pending',
178
+ actions: 'addAmount',
179
+ cond: (context, event) => context.siteConfig?.walletMode === '2' && context.grandTotalEnable === 1,
180
+ },
181
+ {
182
+ target: 'pending',
183
+ actions: 'setAmount',
184
+ cond: 'isFreeWalletMode',
185
+ },
186
+ {
187
+ target: 'debouncing',
188
+ actions: 'addAmount',
189
+ cond: 'isGrandTotalEnable',
190
+ },
191
+ {
192
+ target: 'debouncing',
193
+ actions: 'setAmount',
194
+ },
195
+ ],
196
+ KEY_IN: {
197
+ target: 'calculating',
198
+ actions: 'setAmount',
199
+ },
200
+ BACK: {
201
+ target: 'loaded',
202
+ },
203
+ },
204
+ },
205
+ calculating: {
206
+ invoke: {
207
+ src: 'fetchCalculation',
208
+ onDone: [
209
+ {
210
+ target: 'submitting',
211
+ actions: 'setCalculation',
212
+ cond: 'isFreeWalletMode',
213
+ },
214
+ {
215
+ target: 'calculated',
216
+ actions: 'setCalculation',
217
+ },
218
+ ],
219
+ onError: {
220
+ target: 'calculable',
221
+ },
222
+ },
223
+ },
224
+ calculated: {
225
+ on: {
226
+ SELECT_AMOUNT: [
227
+ {
228
+ target: 'pending',
229
+ actions: 'addAmount',
230
+ cond: (context, event) => context.siteConfig?.walletMode === '2' && context.grandTotalEnable === 1,
231
+ },
232
+ {
233
+ target: 'pending',
234
+ actions: 'setAmount',
235
+ cond: 'isFreeWalletMode',
236
+ },
237
+ {
238
+ target: 'debouncing',
239
+ actions: 'addAmount',
240
+ cond: 'isGrandTotalEnable',
241
+ },
242
+ {
243
+ target: 'debouncing',
244
+ actions: 'setAmount',
245
+ },
246
+ ],
247
+ KEY_IN: {
248
+ target: 'calculating',
249
+ actions: 'setAmount',
250
+ },
251
+ CONFIRM: {
252
+ target: 'submitting',
253
+ },
254
+ BACK: {
255
+ target: 'loaded',
256
+ },
257
+ CLEAR_CALCULATION: {
258
+ target: 'debouncing',
259
+ actions: 'clearCalculation',
260
+ },
261
+ INPUT: {
262
+ target: 'debouncing',
263
+ actions: 'setAmount',
264
+ },
265
+ SELECT_QRCODE: {
266
+ target: 'debouncing',
267
+ actions: 'setQrcode',
268
+ },
269
+ },
270
+ },
271
+ submitting: {
272
+ invoke: {
273
+ src: 'submitDeposit',
274
+ onDone: {
275
+ target: 'submitted',
276
+ actions: 'setResult',
277
+ },
278
+ onError: {
279
+ target: 'calculated',
280
+ },
281
+ },
282
+ },
283
+ submitted: {
284
+ on: {
285
+ SELECT_QRCODE: [
286
+ {
287
+ target: 'fetching',
288
+ actions: 'setQrcode',
289
+ cond: (context, event) => {
290
+ const { siteConfig = {}, promotion = {} } = context
291
+ const { walletMode = '', bonusPreviewEnable = '0' } = siteConfig
292
+ return walletMode === '4' && bonusPreviewEnable === '1' && promotion.activityNo != 'none'
293
+ },
294
+ },
295
+ {
296
+ target: 'loaded',
297
+ actions: 'setQrcode',
298
+ },
299
+ ],
300
+ },
301
+ },
302
+ },
303
+ on: {
304
+ SET_PROMOTION: {
305
+ actions: 'setPromotion',
306
+ },
307
+ },
308
+ },
309
+ {
310
+ actions: {
311
+ reset: assign((context, event) => {
312
+ return {
313
+ selectedAmount: null,
314
+ calculation: null,
315
+ }
316
+ }),
317
+ setInitData: assign((context, event) => {
318
+ const { siteConfig, paymentDetail } = event.data
319
+ const qrcodes = paymentDetail.filter((element) => element.category === context.currentCategory)
320
+ console.log('qrcodes', qrcodes)
321
+ let selectedQrcode = null
322
+ if (siteConfig.walletMode === '4') {
323
+ selectedQrcode = qrcodes.find((qrcode) => parseFloat(`${qrcode.charge || 0}`) === 0)
324
+ } else {
325
+ selectedQrcode = qrcodes[0]
326
+ }
327
+
328
+ return {
329
+ siteConfig,
330
+ paymentDetail,
331
+ qrcodes,
332
+ selectedQrcode,
333
+ currentMethod: selectedQrcode?.method,
334
+ options: selectedQrcode?.optional,
335
+ grandTotalEnable: selectedQrcode?.grandTotalEnable,
336
+ }
337
+ }),
338
+ setBonusPreview: assign((context, event) => {
339
+ return {
340
+ bonusPreviewData: event.data.bonus,
341
+ }
342
+ }),
343
+ setQrcode: assign((context, event) => {
344
+ return {
345
+ selectedQrcode: event.data,
346
+ currentMethod: event.data.method,
347
+ options: event.data.optional,
348
+ grandTotalEnable: event.data.grandTotalEnable,
349
+ }
350
+ }),
351
+ addAmount: assign((context, event) => {
352
+ return { selectedAmount: parseFloat(context.selectedAmount || 0) + parseFloat(event.data) }
353
+ }),
354
+ setAmount: assign((context, event) => {
355
+ return { selectedAmount: event.data }
356
+ }),
357
+ setCalculation: assign((context, event) => {
358
+ return {
359
+ calculation: event.data,
360
+ }
361
+ }),
362
+ clearCalculation: assign((context, event) => {
363
+ return {
364
+ calculation: null,
365
+ }
366
+ }),
367
+ setResult: assign((context, event) => {
368
+ return {
369
+ result: event.data,
370
+ }
371
+ }),
372
+ setPromotion: assign((context, event) => {
373
+ const promotion = event.data
374
+ return {
375
+ promotion,
376
+ }
377
+ }),
378
+ setPromotionDefaultAmount: assign((context, event) => {
379
+ return {
380
+ selectedAmount: context.promotion.minimumAmount,
381
+ }
382
+ }),
383
+ },
384
+ guards: {
385
+ isFreeWalletMode: (context, event) => {
386
+ return context.siteConfig?.walletMode === '2'
387
+ },
388
+ isGrandTotalEnable: (context, event) => {
389
+ return context.grandTotalEnable === 1
390
+ },
391
+ },
392
+ services: {
393
+ fetchInitData: async (context, event) => {
394
+ const [{ config }, paymentDetail = []] = await Promise.all([
395
+ request.send(common.getConfig({ appSecret })),
396
+ request.send(payment.getPaymentDetail({ transferType: 'DEPOSIT' })),
397
+ ])
398
+ const siteConfig = JSON.parse(window.atob(config))
399
+ return { siteConfig, paymentDetail }
400
+ },
401
+ fetchBonusPreview: async (context, event) => {
402
+ const { currentMethod, promotion } = context
403
+ return await request.send(
404
+ payment.getBonusPreview({
405
+ method: currentMethod,
406
+ promotionsNo: promotion?.activityNo,
407
+ })
408
+ )
409
+ },
410
+ fetchCalculation: async (context, event) => {
411
+ const { currentMethod, selectedAmount, promotion } = context
412
+ return await request.send(
413
+ payment.getDepositExpectedResult({
414
+ method: currentMethod,
415
+ amount: selectedAmount,
416
+ promotionsNo: promotion?.activityNo,
417
+ })
418
+ )
419
+ },
420
+ submitDeposit: async (context, event) => {
421
+ const { currentMethod, selectedAmount, promotion } = context
422
+ return await request.send(
423
+ payment.submitDepositTransaction({
424
+ method: currentMethod,
425
+ amount: selectedAmount,
426
+ promotionsNo: promotion?.activityNo,
427
+ })
428
+ )
429
+ },
430
+ },
431
+ }
432
+ )
433
+ }
@@ -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,
@@ -218,21 +227,16 @@ export default function (request) {
218
227
  setLastPage: assign((context, event) => {
219
228
  const { index, content } = context
220
229
  return {
221
- loadable: false,
222
230
  isLastPage: index >= content?.totalPage - 1,
223
231
  }
224
232
  }),
225
- setFavoriteList: assign((context, event) => {
226
- return {
227
- favoriteList: event.data.data || [],
228
- }
229
- }),
230
233
  setRoom: assign((context, event) => {
231
234
  return {
232
235
  room: event.data,
233
236
  }
234
237
  }),
235
238
  resetContent: assign((context, event) => {
239
+ console.log('resetContent')
236
240
  return {
237
241
  loadable: false,
238
242
  isLastPage: false,
@@ -324,9 +328,19 @@ export default function (request) {
324
328
  },
325
329
  services: {
326
330
  getPageContent: async (context, event) => {
327
- const { room, index, additionEnable } = context
331
+ const { room, index, additionEnable, staticData } = context
328
332
  if (room.categoryId === GAME_SEARCH) {
329
333
  return
334
+ } else if (!request.getToken()) {
335
+ const list = staticData.find((data) => data.category == room.categoryId)?.info || []
336
+
337
+ return [
338
+ {
339
+ data: list.slice(index * 20, (index + 1) * 20),
340
+ totalPage: Math.ceil(list.length / 20),
341
+ timestamp: Math.floor(Date.now() / 1000),
342
+ },
343
+ ]
330
344
  } else if (additionEnable) {
331
345
  const param = { categoryId: room.categoryId, index }
332
346
  return await Promise.all([request.send(api.getListCategory(param)), request.send(api.getListAddition(param))])
@@ -339,6 +353,8 @@ export default function (request) {
339
353
  const { room, content, index, additionEnable } = context
340
354
  if (room.categoryId === GAME_SEARCH) {
341
355
  return
356
+ } else if (!request.getToken()) {
357
+ return []
342
358
  } else if (additionEnable) {
343
359
  return await Promise.all([
344
360
  request.send(
@@ -432,12 +448,22 @@ const oldGuards = {
432
448
 
433
449
  const oldServices = (request) => ({
434
450
  fetchOption: async (context, event) => {
435
- return await request.send(api.getOptionMap())
451
+ if (request.getToken()) {
452
+ return await request.send(api.getOptionMap())
453
+ }
436
454
  },
437
455
  fetchGameSHA: async (context, event) => {
438
- 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
+ }
439
463
  },
440
464
  fetchStatus: async (context, event) => {
441
- return await request.send(api.getGameStatus())
465
+ if (request.getToken()) {
466
+ return await request.send(api.getGameStatus())
467
+ }
442
468
  },
443
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'
@@ -44,9 +41,6 @@ export default {
44
41
  common,
45
42
  deposit,
46
43
  error,
47
- game,
48
- game_v2,
49
- game_favorite,
50
44
  game_favorite_v2,
51
45
  game_search,
52
46
  game_search_v2,
@@ -22,8 +22,8 @@ export default class Request {
22
22
  this.axios.interceptors.request.use((axiosConfig) => {
23
23
  axiosConfig.headers['X-TH1GAMES-VERSION'] = this.config.version
24
24
  axiosConfig.headers['X-TH1GAMES-PLATFORM'] = this.config.platform
25
- if (storage.get(this.key)) {
26
- axiosConfig.headers.Authorization = storage.get(this.key)
25
+ if (this.getToken()) {
26
+ axiosConfig.headers.Authorization = this.getToken()
27
27
  }
28
28
  return axiosConfig
29
29
  })
@@ -51,7 +51,7 @@ export default class Request {
51
51
  async send(req, customToken) {
52
52
  try {
53
53
  const cancelToken = customToken || this.source.token
54
- this._checkToken(req, storage.get(this.key))
54
+ this._checkToken(req)
55
55
  const requestConfig = this._createConfig(req, cancelToken)
56
56
  const { data } = await this.axios.request(requestConfig)
57
57
  return data
@@ -97,10 +97,14 @@ export default class Request {
97
97
  }
98
98
  }
99
99
 
100
- _checkToken(req, token) {
101
- if (!req.isPublic && !token) {
100
+ _checkToken(req) {
101
+ if (!req.isPublic && !this.getToken()) {
102
102
  console.error(req)
103
103
  throw { code: 'ERR_A103', url: req.url }
104
104
  }
105
105
  }
106
+
107
+ getToken() {
108
+ return storage.get(this.key)
109
+ }
106
110
  }