@jetthai/cuora 1.1.74-2 → 1.1.74-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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jetthai/cuora",
3
- "version": "1.1.74-2",
3
+ "version": "1.1.74-cash",
4
4
  "description": "",
5
5
  "main": "./src/index.js",
6
6
  "type": "module",
@@ -9,7 +9,7 @@ export default function (request) {
9
9
  context: {
10
10
  activityNo: null,
11
11
  activityDetail: null,
12
- duration: null,
12
+ duration: 0,
13
13
  },
14
14
  initial: 'idle',
15
15
  states: {
@@ -62,7 +62,7 @@ export default function (request) {
62
62
  }),
63
63
  setDuration: assign((context, event) => {
64
64
  return {
65
- duration: context?.activityDetail?.deadline - new Date().getTime() / 1000,
65
+ duration: Math.max(context?.activityDetail?.deadline - new Date().getTime() / 1000, 0),
66
66
  }
67
67
  }),
68
68
  },
@@ -13,6 +13,7 @@ export default function (request) {
13
13
  isAutoReceiving: true,
14
14
  activityNo: null,
15
15
  activityDetail: null,
16
+ duration: 0,
16
17
 
17
18
  // 領獎後得到的資訊
18
19
  awards: [],
@@ -44,12 +45,18 @@ export default function (request) {
44
45
  always: [{ target: 'awardable', cond: 'isAwardable' }, { target: 'awarded' }],
45
46
  },
46
47
  awardable: {
48
+ entry: 'setDuration',
47
49
  on: {
48
50
  AWARD_PRIZE: {
49
51
  target: 'awarding',
50
52
  actions: 'setCallback',
51
53
  },
52
54
  },
55
+ after: {
56
+ 1000: {
57
+ target: 'awardable',
58
+ },
59
+ },
53
60
  },
54
61
  awarded: {
55
62
  on: {
@@ -122,6 +129,11 @@ export default function (request) {
122
129
  doCallback: (context, event) => {
123
130
  context.callback()
124
131
  },
132
+ setDuration: assign((context, event) => {
133
+ return {
134
+ duration: Math.max(context?.activityDetail?.periodEndTime - new Date().getTime() / 1000, 0),
135
+ }
136
+ }),
125
137
  },
126
138
  guards: {
127
139
  isActivityChanged: (context, event) => {
@@ -10,6 +10,7 @@ export default function (request) {
10
10
  activityNo: null,
11
11
  activityDetail: null,
12
12
  callback: () => {},
13
+ duration: 0,
13
14
  },
14
15
  initial: 'idle',
15
16
  states: {
@@ -40,7 +41,14 @@ export default function (request) {
40
41
  { target: 'receivable', cond: 'isReceivable' },
41
42
  ],
42
43
  },
43
- ongoing: {},
44
+ ongoing: {
45
+ entry: 'setDuration',
46
+ after: {
47
+ 1000: {
48
+ target: 'ongoing',
49
+ },
50
+ },
51
+ },
44
52
  received: {},
45
53
  receivable: {
46
54
  on: {
@@ -84,6 +92,11 @@ export default function (request) {
84
92
  doCallback: (context, event) => {
85
93
  context.callback(event.data.type)
86
94
  },
95
+ setDuration: assign((context, event) => {
96
+ return {
97
+ duration: Math.max(context?.activityDetail?.activityEndTime - new Date().getTime() / 1000, 0),
98
+ }
99
+ }),
87
100
  },
88
101
  guards: {
89
102
  isReceivable: (context, event) => {
@@ -345,11 +345,11 @@ export default function (request) {
345
345
  const referralObj = {}
346
346
  if (![undefined, 'undefined', null, 'null'].includes(referralCode)) {
347
347
  referralObj.referralCode = referralCode
348
+ } else {
349
+ ;(referralObj.channel = storage.get('channel') || defaultChannel || channel),
350
+ (referralObj.subchannel = storage.get('subchannel') || defaultSubchannel || subchannel)
348
351
  }
349
352
 
350
- referralObj.channel = storage.get('channel') || defaultChannel || channel
351
- referralObj.subchannel = storage.get('subchannel') || defaultSubchannel || subchannel
352
-
353
353
  const redirectURL = urljoin(
354
354
  request.config.fullURL,
355
355
  'login?' +
@@ -105,7 +105,7 @@ export default function (request) {
105
105
  actions: 'setAmount',
106
106
  },
107
107
  CONFIRM: {
108
- target: 'debouncing',
108
+ target: 'calculating',
109
109
  },
110
110
  BACK: {
111
111
  target: 'loaded',
@@ -131,22 +131,10 @@ export default function (request) {
131
131
  calculating: {
132
132
  invoke: {
133
133
  src: 'fetchCalculation',
134
- onDone: [
135
- {
136
- target: 'submitting',
137
- actions: 'setCalculation',
138
- cond: 'jumpLinkEnable',
139
- },
140
- {
141
- target: 'cardInfo',
142
- actions: 'setCalculation',
143
- cond: 'isFreeWalletMode',
144
- },
145
- {
146
- target: 'calculated',
147
- actions: 'setCalculation',
148
- },
149
- ],
134
+ onDone: {
135
+ target: 'calculated',
136
+ actions: 'setCalculation',
137
+ },
150
138
  onError: {
151
139
  target: 'calculable',
152
140
  },
@@ -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,
@@ -222,17 +231,13 @@ export default function (request) {
222
231
  isLastPage: index >= content?.totalPage - 1,
223
232
  }
224
233
  }),
225
- setFavoriteList: assign((context, event) => {
226
- return {
227
- favoriteList: event.data.data || [],
228
- }
229
- }),
230
234
  setRoom: assign((context, event) => {
231
235
  return {
232
236
  room: event.data,
233
237
  }
234
238
  }),
235
239
  resetContent: assign((context, event) => {
240
+ console.log('resetContent')
236
241
  return {
237
242
  loadable: false,
238
243
  isLastPage: false,
@@ -324,9 +329,19 @@ export default function (request) {
324
329
  },
325
330
  services: {
326
331
  getPageContent: async (context, event) => {
327
- const { room, index, additionEnable } = context
332
+ const { room, index, additionEnable, staticData } = context
328
333
  if (room.categoryId === GAME_SEARCH) {
329
334
  return
335
+ } else if (!request.getToken()) {
336
+ const list = staticData.find((data) => data.category == room.categoryId)?.info || []
337
+
338
+ return [
339
+ {
340
+ data: list.slice(index * 20, (index + 1) * 20),
341
+ totalPage: Math.ceil(list.length / 20),
342
+ timestamp: Math.floor(Date.now() / 1000),
343
+ },
344
+ ]
330
345
  } else if (additionEnable) {
331
346
  const param = { categoryId: room.categoryId, index }
332
347
  return await Promise.all([request.send(api.getListCategory(param)), request.send(api.getListAddition(param))])
@@ -339,6 +354,8 @@ export default function (request) {
339
354
  const { room, content, index, additionEnable } = context
340
355
  if (room.categoryId === GAME_SEARCH) {
341
356
  return
357
+ } else if (!request.getToken()) {
358
+ return []
342
359
  } else if (additionEnable) {
343
360
  return await Promise.all([
344
361
  request.send(
@@ -432,12 +449,22 @@ const oldGuards = {
432
449
 
433
450
  const oldServices = (request) => ({
434
451
  fetchOption: async (context, event) => {
435
- return await request.send(api.getOptionMap())
452
+ if (request.getToken()) {
453
+ return await request.send(api.getOptionMap())
454
+ }
436
455
  },
437
456
  fetchGameSHA: async (context, event) => {
438
- return await request.send(api.getGameSHA())
457
+ if (request.getToken()) {
458
+ return await request.send(api.getGameSHA())
459
+ } else {
460
+ return {
461
+ status: null,
462
+ }
463
+ }
439
464
  },
440
465
  fetchStatus: async (context, event) => {
441
- return await request.send(api.getGameStatus())
466
+ if (request.getToken()) {
467
+ return await request.send(api.getGameStatus())
468
+ }
442
469
  },
443
470
  })
@@ -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,
@@ -127,11 +127,11 @@ export default function (request) {
127
127
  const referralObj = {}
128
128
  if (![undefined, 'undefined', null, 'null'].includes(referralCode)) {
129
129
  referralObj.referralCode = referralCode
130
+ } else {
131
+ ;(referralObj.channel = storage.get('channel') || defaultChannel || channel),
132
+ (referralObj.subchannel = storage.get('subchannel') || defaultSubchannel || subchannel)
130
133
  }
131
134
 
132
- referralObj.channel = storage.get('channel') || defaultChannel || channel
133
- referralObj.subchannel = storage.get('subchannel') || defaultSubchannel || subchannel
134
-
135
135
  return await request.send(
136
136
  auth.register({
137
137
  ...signUpData,
@@ -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
  }
@@ -1,285 +0,0 @@
1
- import { assign, createMachine } from 'xstate'
2
- import api from '../api/game.js'
3
- import UAParser from 'ua-parser-js'
4
-
5
- // const UAParser = require('ua-parser-js')
6
-
7
- export default function (request) {
8
- return createMachine(
9
- {
10
- id: 'game',
11
- type: 'parallel',
12
- context: {
13
- roomId: null,
14
- room: null,
15
- list: [],
16
- gameList: [],
17
- // play params
18
- game: {
19
- provider: null,
20
- game_id: null,
21
- game_type: null,
22
- mapping_id: null,
23
- portrait: null,
24
- },
25
- lang: 'en_US',
26
- isMobile: new UAParser().getResult().device.type,
27
- gameURL: null,
28
- // game database
29
- sha: {
30
- category: null,
31
- status: null,
32
- },
33
- isCategoryChanged: false,
34
- isStatusChanged: false,
35
- statusMap: {},
36
- optionMap: {},
37
- },
38
- states: {
39
- flow: {
40
- initial: 'idle',
41
- states: {
42
- idle: {
43
- enter: 'clearGameInfo',
44
- on: {
45
- SET_ROOM: {
46
- target: 'loading',
47
- actions: 'setRoom',
48
- cond: (context, event) => {
49
- return context.room?.id !== event.data?.id
50
- },
51
- },
52
- ENTER_GAME: {
53
- target: 'connecting',
54
- actions: ['setGameInfo', 'setLang'],
55
- },
56
- },
57
- },
58
- loading: {
59
- invoke: {
60
- src: 'getRoomItems',
61
- onDone: {
62
- target: 'idle',
63
- actions: 'setList',
64
- },
65
- onError: {
66
- target: 'idle',
67
- actions: assign({ list: [] }),
68
- },
69
- },
70
- },
71
- connecting: {
72
- invoke: {
73
- src: 'connectGame',
74
- onDone: {
75
- target: 'playing',
76
- actions: 'setGameURL',
77
- },
78
- onError: {
79
- target: 'idle',
80
- },
81
- },
82
- },
83
- playing: {
84
- on: {
85
- EXIT_GAME: {
86
- target: 'disconnect',
87
- },
88
- },
89
- },
90
- disconnect: {
91
- invoke: {
92
- src: 'disconnectGame',
93
- onDone: {
94
- target: 'idle',
95
- },
96
- onError: {
97
- target: 'idle',
98
- },
99
- },
100
- },
101
- },
102
- },
103
- timer: {
104
- initial: 'fetchingGameSHA',
105
- states: {
106
- fetchingGameSHA: {
107
- invoke: {
108
- src: 'fetchGameSHA',
109
- onDone: {
110
- target: 'checking',
111
- actions: 'setGameSHA',
112
- },
113
- onError: {
114
- target: 'pending',
115
- },
116
- },
117
- },
118
- checking: {
119
- always: [
120
- { target: 'updatingStatus', cond: 'isStatusChanged' },
121
- { target: 'updatingCategory', cond: 'isCategoryChanged' },
122
- { target: 'pending' },
123
- ],
124
- },
125
- updatingStatus: {
126
- invoke: {
127
- src: 'fetchStatus',
128
- onDone: {
129
- target: 'updatingOption',
130
- actions: ['setStatus'],
131
- },
132
- onError: {
133
- target: 'pending',
134
- },
135
- },
136
- },
137
- updatingOption: {
138
- invoke: {
139
- src: 'fetchOption',
140
- onDone: {
141
- target: 'updatingCategory',
142
- actions: 'mergeOption',
143
- },
144
- onError: {
145
- target: 'pending',
146
- },
147
- },
148
- },
149
- updatingCategory: {
150
- invoke: {
151
- src: 'getRoomItems',
152
- onDone: {
153
- target: 'pending',
154
- actions: 'setList',
155
- },
156
- onError: {
157
- target: 'pending',
158
- },
159
- },
160
- },
161
- pending: {
162
- after: {
163
- 20000: {
164
- target: 'fetchingGameSHA',
165
- },
166
- },
167
- },
168
- },
169
- },
170
- },
171
- },
172
- {
173
- actions: {
174
- setRoomId: assign((context, event) => {
175
- return { roomId: event.roomId }
176
- }),
177
- setRoom: assign((context, event) => {
178
- return {
179
- room: event.data,
180
- roomId: event.data.id,
181
- }
182
- }),
183
- setList: assign((context, event) => {
184
- const { statusMap, optionMap } = context
185
- const { list = [] } = event.data
186
- const gameList = list
187
- .map((item) => {
188
- if (item.id) {
189
- item.room = true
190
- return item
191
- }
192
-
193
- const code = item.g
194
- if (!code || !optionMap[code]) {
195
- return
196
- }
197
-
198
- return {
199
- ...optionMap[code],
200
- code,
201
- system_enable: statusMap[code][0],
202
- }
203
- })
204
- .filter((item) => item && !item.header)
205
- .sort((a, b) => a.system_enable - b.system_enable)
206
- return { list, gameList }
207
- }),
208
- setGameURL: assign({
209
- gameURL: (context, event) => {
210
- return event.data.gameURL
211
- },
212
- }),
213
- clearGameInfo: assign((context, event) => {
214
- return { game: { provider: null, game_id: null, game_type: null, mapping_id: null } }
215
- }),
216
- setGameInfo: assign((context, event) => {
217
- const { provider, game_id, game_type, mapping_id, portrait } = event.data.game
218
- return { game: { provider, game_id, game_type, mapping_id, portrait } }
219
- }),
220
- setLang: assign((context, event) => {
221
- const lang = event.data.locale.replace('-', '_')
222
- return { lang }
223
- }),
224
- setGameSHA: assign((context, event) => {
225
- const { sha } = context
226
- const newSha = event.data
227
- return {
228
- sha: newSha,
229
- isCategoryChanged: !sha.category || sha.category !== newSha.category,
230
- isStatusChanged: !sha.status || sha.status !== newSha.status,
231
- }
232
- }),
233
- setStatus: assign((context, event) => {
234
- return {
235
- statusMap: event.data,
236
- }
237
- }),
238
- mergeOption: assign((context, event) => {
239
- const { optionMap } = context
240
- return {
241
- optionMap: { ...optionMap, ...event.data },
242
- }
243
- }),
244
- },
245
- guards: {
246
- isCategoryChanged: (context, event) => context.isCategoryChanged,
247
- isStatusChanged: (context, event) => context.isStatusChanged,
248
- },
249
- services: {
250
- getRoomItems: async (context, event) => {
251
- return await request.send(api.getGameCategory({ id: context.roomId }))
252
- },
253
- connectGame: async (context, event) => {
254
- const { lang, isMobile } = context
255
- const { provider, game_id, game_type, mapping_id } = context.game
256
- const params = {
257
- provider_id: provider,
258
- game_id: game_id,
259
- gametype_id: game_type,
260
- mapping_id: mapping_id,
261
- is_demo: false,
262
- is_mobile: isMobile,
263
- lang,
264
- return_url: window.location.href,
265
- }
266
- const { redirect_url } = await request.send(api.playGame(params))
267
- return { gameURL: redirect_url }
268
- },
269
- disconnectGame: async (context, event) => {
270
- const uid_site = event.data
271
- return await request.send(api.logoutGame({ uid_site, provider_id: context.game.provider }))
272
- },
273
- fetchOption: async (context, event) => {
274
- return await request.send(api.getOptionMap())
275
- },
276
- fetchGameSHA: async (context, event) => {
277
- return await request.send(api.getGameSHA())
278
- },
279
- fetchStatus: async (context, event) => {
280
- return await request.send(api.getGameStatus())
281
- },
282
- },
283
- }
284
- )
285
- }