@jetthai/cuora 1.1.68-cash → 1.1.69

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.68-cash",
3
+ "version": "1.1.69",
4
4
  "description": "",
5
5
  "main": "./src/index.js",
6
6
  "type": "module",
@@ -138,4 +138,5 @@ export default {
138
138
  giveUp: () => ({ url: 'payment/v2/bankWallet/promotion/giveUp', method: 'post' }),
139
139
  restore: ({ amount }) => ({ url: 'payment/v2/bankWallet/restore', method: 'post', params: { amount } }),
140
140
  restore: () => ({ url: 'payment/v2/bankWallet/restore', method: 'post', params: { amount } }),
141
+ getBonusPreview: ({ method, promotionsNo }) => ({ url: `payment/v2/${method}/transaction`, method: 'post', params: { promotionsNo } }),
141
142
  }
@@ -391,10 +391,12 @@ export default function (request) {
391
391
  },
392
392
  fetchBonusPreview: async (context, event) => {
393
393
  const { selectedCrypto, promotion } = context
394
- return await request.send({
395
- paymentMethod: selectedCrypto.method,
396
- promotionsNo: promotion?.activityNo,
397
- })
394
+ return await request.send(
395
+ payment.getBonusPreview({
396
+ method: selectedCrypto.method,
397
+ promotionsNo: promotion?.activityNo,
398
+ })
399
+ )
398
400
  },
399
401
  fetchCalculation: async (context, event) => {
400
402
  const { selectedCrypto, selectedAmount, promotion } = context
@@ -331,10 +331,12 @@ export default function (request) {
331
331
  },
332
332
  fetchBonusPreview: async (context, event) => {
333
333
  const { method, promotion } = context
334
- return await request.send({
335
- paymentMethod: method,
336
- promotionsNo: promotion?.activityNo,
337
- })
334
+ return await request.send(
335
+ payment.getBonusPreview({
336
+ method,
337
+ promotionsNo: promotion?.activityNo,
338
+ })
339
+ )
338
340
  },
339
341
  submitDeposit: async (context, event) => {
340
342
  const { method, amount, promotion } = context
@@ -331,10 +331,12 @@ export default function (request) {
331
331
  },
332
332
  fetchBonusPreview: async (context, event) => {
333
333
  const { currentMethod, promotion } = context
334
- return await request.send({
335
- paymentMethod: currentMethod,
336
- promotionsNo: promotion?.activityNo,
337
- })
334
+ return await request.send(
335
+ payment.getBonusPreview({
336
+ method: currentMethod,
337
+ promotionsNo: promotion?.activityNo,
338
+ })
339
+ )
338
340
  },
339
341
  fetchCalculation: async (context, event) => {
340
342
  const { currentMethod, selectedAmount, promotion } = context
@@ -410,10 +410,12 @@ export default function (request) {
410
410
  },
411
411
  fetchBonusPreview: async (context, event) => {
412
412
  const { currentMethod, promotion } = context
413
- return await request.send({
414
- paymentMethod: currentMethod,
415
- promotionsNo: promotion?.activityNo,
416
- })
413
+ return await request.send(
414
+ payment.getBonusPreview({
415
+ method: currentMethod,
416
+ promotionsNo: promotion?.activityNo,
417
+ })
418
+ )
417
419
  },
418
420
  fetchCalculation: async (context, event) => {
419
421
  const { currentMethod, selectedAmount, promotion } = context
@@ -324,10 +324,12 @@ export default function (request) {
324
324
  },
325
325
  fetchBonusPreview: async (context, event) => {
326
326
  const { method, promotion } = context
327
- return await request.send({
328
- paymentMethod: method,
329
- promotionsNo: promotion?.activityNo,
330
- })
327
+ return await request.send(
328
+ payment.getBonusPreview({
329
+ method,
330
+ promotionsNo: promotion?.activityNo,
331
+ })
332
+ )
331
333
  },
332
334
  submitDeposit: async (context, event) => {
333
335
  const { method, amount, promotion } = context
@@ -0,0 +1,285 @@
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
+ }
@@ -0,0 +1,123 @@
1
+ import { assign, createMachine } from 'xstate'
2
+ import api from '../api/game.js'
3
+
4
+ export default function (request) {
5
+ return createMachine(
6
+ {
7
+ id: 'favorite',
8
+ type: 'parallel',
9
+ context: {
10
+ list: [],
11
+ },
12
+ states: {
13
+ fetching: {
14
+ initial: 'disable',
15
+ states: {
16
+ disable: {},
17
+ enable: {
18
+ invoke: {
19
+ src: 'fetchList',
20
+ onDone: {
21
+ actions: 'setList',
22
+ },
23
+ onError: {
24
+ actions: assign({ list: [] }),
25
+ },
26
+ },
27
+ },
28
+ },
29
+ },
30
+ adding: {
31
+ initial: 'disable',
32
+ states: {
33
+ disable: {},
34
+ enable: {
35
+ invoke: {
36
+ src: 'add',
37
+ onDone: {},
38
+ onError: {
39
+ actions: 'removeFromList',
40
+ },
41
+ },
42
+ },
43
+ },
44
+ },
45
+ removing: {
46
+ initial: 'disable',
47
+ states: {
48
+ disable: {},
49
+ enable: {
50
+ invoke: {
51
+ src: 'remove',
52
+ onDone: {},
53
+ onError: {
54
+ actions: 'addToList',
55
+ },
56
+ },
57
+ },
58
+ },
59
+ },
60
+ },
61
+ on: {
62
+ FETCH_LIST: {
63
+ target: 'fetching.enable',
64
+ },
65
+ ADD: {
66
+ target: 'adding.enable',
67
+ actions: 'addToList',
68
+ cond: 'isNotExist',
69
+ },
70
+ REMOVE: {
71
+ target: 'removing.enable',
72
+ actions: 'removeFromList',
73
+ cond: 'isExist',
74
+ },
75
+ },
76
+ },
77
+ {
78
+ actions: {
79
+ setList: assign((context, event) => {
80
+ return {
81
+ list: event.data,
82
+ }
83
+ }),
84
+ addToList: assign((context, event) => {
85
+ return {
86
+ list: [...context.list, event.data],
87
+ }
88
+ }),
89
+ removeFromList: assign((context, event) => {
90
+ return {
91
+ list: context.list.filter((item) => item !== event.data),
92
+ }
93
+ }),
94
+ },
95
+ guards: {
96
+ isExist: (context, event) => context.list.includes(event.data),
97
+ isNotExist: (context, event) => !context.list.includes(event.data),
98
+ },
99
+ services: {
100
+ add: async (context, event) => {
101
+ try {
102
+ return await request.send(api.addFavoriteGame(event.data))
103
+ } catch (error) {
104
+ throw event.data
105
+ }
106
+ },
107
+ remove: async (context, event) => {
108
+ try {
109
+ return await request.send(api.removeFavoriteGame(event.data))
110
+ } catch (error) {
111
+ throw event.data
112
+ }
113
+ },
114
+ fetchList: async (context, event) => {
115
+ const main = await request.send(api.getGameCategory({}))
116
+ const room = main.list.find((item) => item.category === 'SYSTEM_MY_FAVORITE')
117
+ const favorite = await request.send(api.getGameCategory({ id: room.id }))
118
+ return favorite.list.map((item) => item.g)
119
+ },
120
+ },
121
+ }
122
+ )
123
+ }
@@ -110,12 +110,8 @@ export default function (request) {
110
110
  }
111
111
  },
112
112
  fetchList: async (context, event) => {
113
- if (request.getToken()) {
114
- const { data } = await request.send(api.getListMyFavorite())
115
- return data
116
- } else {
117
- return []
118
- }
113
+ const { data } = await request.send(api.getListMyFavorite())
114
+ return data
119
115
  },
120
116
  },
121
117
  }