@jetthai/cuora 1.0.168-2 → 1.0.169
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/CHANGELOG.md +1 -3
- package/package.json +1 -1
- package/src/api/game.js +31 -1
- package/src/index.js +3 -2
- package/src/machine/auth.js +27 -33
- package/src/machine/game_v2.js +327 -0
- package/src/machine/index.js +4 -0
- package/src/machine/side_v2.js +192 -0
- package/src/util/constant.js +1 -0
- package/src/util/index.js +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,9 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
-
### [1.0.
|
|
6
|
-
|
|
7
|
-
### [1.0.168-1](https://github.com/jetthai/cuora-module/compare/v1.0.168...v1.0.168-1) (2022-09-23)
|
|
5
|
+
### [1.0.169](https://github.com/jetthai/cuora-module/compare/v1.0.168...v1.0.169) (2022-09-19)
|
|
8
6
|
|
|
9
7
|
### [1.0.168](https://github.com/jetthai/cuora-module/compare/v1.0.167...v1.0.168) (2022-09-12)
|
|
10
8
|
|
package/package.json
CHANGED
package/src/api/game.js
CHANGED
|
@@ -2,7 +2,7 @@ export default {
|
|
|
2
2
|
getGameSHA: () => ({ method: 'get', url: 'game/list/v2/sha' }),
|
|
3
3
|
getOptionMap: (code) => ({ method: 'get', url: 'game/list/v2/options', params: { code } }),
|
|
4
4
|
getGameStatus: () => ({ method: 'get', url: 'game/list/v2/status' }),
|
|
5
|
-
getGameCategory: ({ id, first }) => ({ method: 'get', url: 'game/list/v2/category', params: { id, first } }),
|
|
5
|
+
getGameCategory: ({ id, first } = {}) => ({ method: 'get', url: 'game/list/v2/category', params: { id, first } }),
|
|
6
6
|
addFavoriteGame: (code) => ({ method: 'post', url: 'game/myfavorite/add', params: { games: [code] } }),
|
|
7
7
|
removeFavoriteGame: (code) => ({ method: 'post', url: 'game/myfavorite/remove', params: { games: [code] } }),
|
|
8
8
|
getStatements: () => ({ url: 'game/statements', method: 'get' }),
|
|
@@ -43,4 +43,34 @@ export default {
|
|
|
43
43
|
url: 'game/history/options',
|
|
44
44
|
method: 'get',
|
|
45
45
|
}),
|
|
46
|
+
getListRoot: ({ timestamp } = {}) => ({
|
|
47
|
+
url: 'game/list/v3/root',
|
|
48
|
+
method: 'get',
|
|
49
|
+
params: { timestamp },
|
|
50
|
+
}),
|
|
51
|
+
getListCategory: ({ categoryId, timestamp, index }) => ({
|
|
52
|
+
url: 'game/list/v3/category',
|
|
53
|
+
method: 'get',
|
|
54
|
+
params: { categoryId, timestamp, index },
|
|
55
|
+
}),
|
|
56
|
+
getListAddition: ({ categoryId, timestamp, index }) => ({
|
|
57
|
+
url: 'game/list/v3/addition',
|
|
58
|
+
method: 'get',
|
|
59
|
+
params: { categoryId, timestamp, index },
|
|
60
|
+
}),
|
|
61
|
+
getListCategoryByRange: ({ categoryId, timestamp, end }) => ({
|
|
62
|
+
url: 'game/list/v3/categoryByRange',
|
|
63
|
+
method: 'get',
|
|
64
|
+
params: { categoryId, timestamp, end },
|
|
65
|
+
}),
|
|
66
|
+
getListAdditionByRange: ({ categoryId, timestamp, end }) => ({
|
|
67
|
+
url: 'game/list/v3/additionByRange',
|
|
68
|
+
method: 'get',
|
|
69
|
+
params: { categoryId, timestamp, end },
|
|
70
|
+
}),
|
|
71
|
+
getListMyFavorite: ({ timestamp } = {}) => ({
|
|
72
|
+
url: 'game/list/v3/myFavorite',
|
|
73
|
+
method: 'get',
|
|
74
|
+
params: { timestamp },
|
|
75
|
+
}),
|
|
46
76
|
}
|
package/src/index.js
CHANGED
|
@@ -2,5 +2,6 @@ import api from './api/index.js'
|
|
|
2
2
|
import machine from './machine/index.js'
|
|
3
3
|
import Request from './request/request.js'
|
|
4
4
|
import Config from './request/config.js'
|
|
5
|
-
import util from './util/index.js'
|
|
6
|
-
|
|
5
|
+
import util, { constant } from './util/index.js'
|
|
6
|
+
|
|
7
|
+
export { api, machine, Request, Config, util, constant }
|
package/src/machine/auth.js
CHANGED
|
@@ -11,7 +11,6 @@ export default function (request) {
|
|
|
11
11
|
const { clientId, fpToken, sentry, defaultChannel, defaultSubchannel } = request.config
|
|
12
12
|
const tokenKey = `cuora_${clientId}`
|
|
13
13
|
const userKey = `cuora_tempuser`
|
|
14
|
-
const phoneCountryCode = 'phone_countrycode'
|
|
15
14
|
const accountPhoneKey = 'account_phone'
|
|
16
15
|
const accountEmailKey = 'account_email'
|
|
17
16
|
const cookies = new Cookies()
|
|
@@ -32,7 +31,6 @@ export default function (request) {
|
|
|
32
31
|
username: null,
|
|
33
32
|
password: null,
|
|
34
33
|
},
|
|
35
|
-
countryAbbr: null,
|
|
36
34
|
userInfo: {},
|
|
37
35
|
redirectURL: null,
|
|
38
36
|
reCaptchaToken: null,
|
|
@@ -41,6 +39,23 @@ export default function (request) {
|
|
|
41
39
|
idle: {
|
|
42
40
|
entry: 'fetchToken',
|
|
43
41
|
always: [{ target: 'authenticated', cond: 'hasToken' }],
|
|
42
|
+
on: {
|
|
43
|
+
LOGIN_GUEST: {
|
|
44
|
+
target: 'authenticationGuest',
|
|
45
|
+
},
|
|
46
|
+
LOGIN_PHONE: {
|
|
47
|
+
target: 'authentication',
|
|
48
|
+
actions: ['setReCaptchaToken', 'setLoginPhone'],
|
|
49
|
+
},
|
|
50
|
+
LOGIN_EMAIL: {
|
|
51
|
+
target: 'authentication',
|
|
52
|
+
actions: ['setReCaptchaToken', 'setLoginEmail'],
|
|
53
|
+
},
|
|
54
|
+
LOGIN_LOCAL: {
|
|
55
|
+
target: 'authentication',
|
|
56
|
+
actions: 'setLoginLocal',
|
|
57
|
+
},
|
|
58
|
+
},
|
|
44
59
|
},
|
|
45
60
|
authentication: {
|
|
46
61
|
invoke: {
|
|
@@ -162,21 +177,6 @@ export default function (request) {
|
|
|
162
177
|
CLEAR: {
|
|
163
178
|
target: '.logout',
|
|
164
179
|
},
|
|
165
|
-
LOGIN_GUEST: {
|
|
166
|
-
target: '.authenticationGuest',
|
|
167
|
-
},
|
|
168
|
-
LOGIN_PHONE: {
|
|
169
|
-
target: '.authentication',
|
|
170
|
-
actions: ['setReCaptchaToken', 'setLoginPhone'],
|
|
171
|
-
},
|
|
172
|
-
LOGIN_EMAIL: {
|
|
173
|
-
target: '.authentication',
|
|
174
|
-
actions: ['setReCaptchaToken', 'setLoginEmail'],
|
|
175
|
-
},
|
|
176
|
-
LOGIN_LOCAL: {
|
|
177
|
-
target: '.authentication',
|
|
178
|
-
actions: 'setLoginLocal',
|
|
179
|
-
},
|
|
180
180
|
LOGIN_3PARTY: {
|
|
181
181
|
actions: 'redirectTo3Party',
|
|
182
182
|
},
|
|
@@ -211,7 +211,7 @@ export default function (request) {
|
|
|
211
211
|
}
|
|
212
212
|
}),
|
|
213
213
|
setLoginPhone: assign((context, event) => {
|
|
214
|
-
const { countryCode,
|
|
214
|
+
const { countryCode, phone, password } = event.data
|
|
215
215
|
return {
|
|
216
216
|
loginData: {
|
|
217
217
|
provider: 'phone',
|
|
@@ -219,7 +219,6 @@ export default function (request) {
|
|
|
219
219
|
phone,
|
|
220
220
|
password,
|
|
221
221
|
},
|
|
222
|
-
countryAbbr,
|
|
223
222
|
}
|
|
224
223
|
}),
|
|
225
224
|
setLoginEmail: assign((context, event) => {
|
|
@@ -264,17 +263,12 @@ export default function (request) {
|
|
|
264
263
|
setAccount: assign((context, event) => {
|
|
265
264
|
if (context.loginData.phone) {
|
|
266
265
|
cookies.remove(accountEmailKey)
|
|
267
|
-
cookies.set(accountPhoneKey,
|
|
268
|
-
path: '/',
|
|
269
|
-
maxAge: 60 * 60 * 24 * 7,
|
|
270
|
-
})
|
|
271
|
-
cookies.set(phoneCountryCode, `${context.countryAbbr}_${context.loginData.countryCode}`, {
|
|
266
|
+
cookies.set(accountPhoneKey, `0${context.loginData.phone}`, {
|
|
272
267
|
path: '/',
|
|
273
268
|
maxAge: 60 * 60 * 24 * 7,
|
|
274
269
|
})
|
|
275
270
|
} else if (context.loginData.email) {
|
|
276
271
|
cookies.remove(accountPhoneKey)
|
|
277
|
-
cookies.remove(phoneCountryCode)
|
|
278
272
|
cookies.set(accountEmailKey, context.loginData.email, {
|
|
279
273
|
path: '/',
|
|
280
274
|
maxAge: 60 * 60 * 24 * 7,
|
|
@@ -314,14 +308,14 @@ export default function (request) {
|
|
|
314
308
|
const redirectURL = urljoin(
|
|
315
309
|
request.config.fullURL,
|
|
316
310
|
'login?' +
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
311
|
+
new URLSearchParams({
|
|
312
|
+
provider,
|
|
313
|
+
redirectURI: `${window.location.protocol}//${window.location.host}`,
|
|
314
|
+
channel: cookies.get('channel') || channel || defaultChannel || 'official',
|
|
315
|
+
subchannel: cookies.get('subchannel') || subchannel || defaultSubchannel || 'pwa',
|
|
316
|
+
// dt,
|
|
317
|
+
platform: 'pwa',
|
|
318
|
+
}).toString()
|
|
325
319
|
)
|
|
326
320
|
window.location.href = redirectURL
|
|
327
321
|
},
|
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
import { assign, createMachine } from 'xstate'
|
|
2
|
+
import api from '../api/game.js'
|
|
3
|
+
import UAParser from 'ua-parser-js'
|
|
4
|
+
import { MY_FAVORITE } from '../util/constant.js'
|
|
5
|
+
|
|
6
|
+
export default function (request) {
|
|
7
|
+
return createMachine(
|
|
8
|
+
{
|
|
9
|
+
id: 'game',
|
|
10
|
+
type: 'parallel',
|
|
11
|
+
context: {
|
|
12
|
+
room: null,
|
|
13
|
+
index: 0,
|
|
14
|
+
content: {
|
|
15
|
+
data: [],
|
|
16
|
+
timestamp: null,
|
|
17
|
+
parentCategoryId: null,
|
|
18
|
+
totalPage: 1,
|
|
19
|
+
},
|
|
20
|
+
favoriteList: [],
|
|
21
|
+
// play params
|
|
22
|
+
game: {
|
|
23
|
+
providerId: null,
|
|
24
|
+
gameId: null,
|
|
25
|
+
gameTypeId: null,
|
|
26
|
+
mappingId: null,
|
|
27
|
+
portrait: null,
|
|
28
|
+
},
|
|
29
|
+
lang: 'en_US',
|
|
30
|
+
isMobile: new UAParser().getResult().device.type,
|
|
31
|
+
gameURL: null,
|
|
32
|
+
},
|
|
33
|
+
states: {
|
|
34
|
+
flow: {
|
|
35
|
+
initial: 'idle',
|
|
36
|
+
states: {
|
|
37
|
+
idle: {
|
|
38
|
+
enter: 'clearGameInfo',
|
|
39
|
+
on: {
|
|
40
|
+
ENTER_ROOM: {
|
|
41
|
+
target: 'loading',
|
|
42
|
+
cond: 'isDifferentRoom',
|
|
43
|
+
actions: ['setRoom', 'resetContent'],
|
|
44
|
+
},
|
|
45
|
+
NEXT_PAGE: {
|
|
46
|
+
target: 'loading',
|
|
47
|
+
cond: 'hasNext',
|
|
48
|
+
actions: 'increaseIndex',
|
|
49
|
+
},
|
|
50
|
+
ENTER_GAME: {
|
|
51
|
+
target: 'connecting',
|
|
52
|
+
actions: ['setGameInfo', 'setLang'],
|
|
53
|
+
},
|
|
54
|
+
ADD_FAVORITE: {
|
|
55
|
+
target: 'adding',
|
|
56
|
+
cond: 'isNotFavorite',
|
|
57
|
+
actions: 'addToFavoriteList',
|
|
58
|
+
},
|
|
59
|
+
REMOVE_FAVORITE: {
|
|
60
|
+
target: 'removing',
|
|
61
|
+
cond: 'isFavorite',
|
|
62
|
+
actions: 'removeFromFavoriteList',
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
loading: {
|
|
67
|
+
invoke: {
|
|
68
|
+
src: 'getPageContent',
|
|
69
|
+
onDone: {
|
|
70
|
+
target: 'idle',
|
|
71
|
+
actions: 'appendContent',
|
|
72
|
+
},
|
|
73
|
+
onError: {
|
|
74
|
+
target: 'idle',
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
connecting: {
|
|
79
|
+
invoke: {
|
|
80
|
+
src: 'connectGame',
|
|
81
|
+
onDone: {
|
|
82
|
+
target: 'playing',
|
|
83
|
+
actions: 'setGameURL',
|
|
84
|
+
},
|
|
85
|
+
onError: {
|
|
86
|
+
target: 'idle',
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
playing: {
|
|
91
|
+
on: {
|
|
92
|
+
EXIT_GAME: {
|
|
93
|
+
target: 'disconnect',
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
disconnect: {
|
|
98
|
+
invoke: {
|
|
99
|
+
src: 'disconnectGame',
|
|
100
|
+
onDone: {
|
|
101
|
+
target: 'idle',
|
|
102
|
+
},
|
|
103
|
+
onError: {
|
|
104
|
+
target: 'idle',
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
adding: {
|
|
109
|
+
invoke: {
|
|
110
|
+
src: 'addFavorite',
|
|
111
|
+
onDone: {
|
|
112
|
+
target: 'idle',
|
|
113
|
+
},
|
|
114
|
+
onError: {
|
|
115
|
+
target: 'idle',
|
|
116
|
+
actions: 'removeFromFavoriteList',
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
removing: {
|
|
121
|
+
invoke: {
|
|
122
|
+
src: 'removeFavorite',
|
|
123
|
+
onDone: {
|
|
124
|
+
target: 'idle',
|
|
125
|
+
},
|
|
126
|
+
onError: {
|
|
127
|
+
target: 'idle',
|
|
128
|
+
actions: 'addToFavoriteList',
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
timer: {
|
|
135
|
+
initial: 'favorite',
|
|
136
|
+
states: {
|
|
137
|
+
favorite: {
|
|
138
|
+
invoke: {
|
|
139
|
+
src: 'getFavorite',
|
|
140
|
+
onDone: {
|
|
141
|
+
target: 'pending',
|
|
142
|
+
actions: 'setFavoriteList',
|
|
143
|
+
},
|
|
144
|
+
onError: {
|
|
145
|
+
target: 'pending',
|
|
146
|
+
},
|
|
147
|
+
},
|
|
148
|
+
},
|
|
149
|
+
pending: {
|
|
150
|
+
after: {
|
|
151
|
+
20000: [
|
|
152
|
+
{
|
|
153
|
+
target: 'updating',
|
|
154
|
+
cond: 'hasRoom',
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
target: 'pending',
|
|
158
|
+
},
|
|
159
|
+
],
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
updating: {
|
|
163
|
+
invoke: {
|
|
164
|
+
src: 'updatePageContent',
|
|
165
|
+
onDone: {
|
|
166
|
+
target: 'pending',
|
|
167
|
+
actions: 'swapContent',
|
|
168
|
+
},
|
|
169
|
+
onError: {
|
|
170
|
+
target: 'pending',
|
|
171
|
+
},
|
|
172
|
+
},
|
|
173
|
+
},
|
|
174
|
+
},
|
|
175
|
+
},
|
|
176
|
+
},
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
actions: {
|
|
180
|
+
setFavoriteList: assign((context, event) => {
|
|
181
|
+
return {
|
|
182
|
+
favoriteList: event.data.data || [],
|
|
183
|
+
}
|
|
184
|
+
}),
|
|
185
|
+
setRoom: assign((context, event) => {
|
|
186
|
+
return {
|
|
187
|
+
room: event.data,
|
|
188
|
+
}
|
|
189
|
+
}),
|
|
190
|
+
resetContent: assign((context, event) => {
|
|
191
|
+
return {
|
|
192
|
+
index: 0,
|
|
193
|
+
content: {
|
|
194
|
+
data: [],
|
|
195
|
+
timestamp: null,
|
|
196
|
+
parentCategoryId: null,
|
|
197
|
+
totalPage: 1,
|
|
198
|
+
},
|
|
199
|
+
}
|
|
200
|
+
}),
|
|
201
|
+
appendContent: assign((context, event) => {
|
|
202
|
+
const { room, favoriteList } = context
|
|
203
|
+
const { data, ...rest } = event.data
|
|
204
|
+
return {
|
|
205
|
+
favoriteList: room.categoryId === MY_FAVORITE ? data : favoriteList,
|
|
206
|
+
content: {
|
|
207
|
+
...context.content,
|
|
208
|
+
...rest,
|
|
209
|
+
data: context.content.data.concat(data),
|
|
210
|
+
},
|
|
211
|
+
}
|
|
212
|
+
}),
|
|
213
|
+
swapContent: assign((context, event) => {
|
|
214
|
+
const { room, favoriteList } = context
|
|
215
|
+
if (event.data.data.length) {
|
|
216
|
+
return {
|
|
217
|
+
favoriteList: room.categoryId === MY_FAVORITE ? event.data.data : favoriteList,
|
|
218
|
+
content: event.data,
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}),
|
|
222
|
+
increaseIndex: assign((context, event) => {
|
|
223
|
+
return {
|
|
224
|
+
index: context.index + 1,
|
|
225
|
+
}
|
|
226
|
+
}),
|
|
227
|
+
setGameURL: assign({
|
|
228
|
+
gameURL: (context, event) => {
|
|
229
|
+
return event.data.gameURL
|
|
230
|
+
},
|
|
231
|
+
}),
|
|
232
|
+
clearGameInfo: assign((context, event) => {
|
|
233
|
+
return { game: { providerId: null, gameId: null, gameTypeId: null, mappingId: null } }
|
|
234
|
+
}),
|
|
235
|
+
setGameInfo: assign((context, event) => {
|
|
236
|
+
const { providerId, gameId, gameTypeId, mappingId, portrait } = event.data.game
|
|
237
|
+
return { game: { providerId, gameId, gameTypeId, mappingId, portrait: portrait ? 1 : 0 } }
|
|
238
|
+
}),
|
|
239
|
+
setLang: assign((context, event) => {
|
|
240
|
+
const lang = event.data.locale.replace('-', '_')
|
|
241
|
+
return { lang }
|
|
242
|
+
}),
|
|
243
|
+
addToFavoriteList: assign((context, event) => {
|
|
244
|
+
return {
|
|
245
|
+
favoriteList: [...context.favoriteList, event.data],
|
|
246
|
+
}
|
|
247
|
+
}),
|
|
248
|
+
removeFromFavoriteList: assign((context, event) => {
|
|
249
|
+
return {
|
|
250
|
+
favoriteList: context.favoriteList.filter((item) => item.gameCode !== event.data.gameCode),
|
|
251
|
+
}
|
|
252
|
+
}),
|
|
253
|
+
},
|
|
254
|
+
guards: {
|
|
255
|
+
isDifferentRoom: (context, event) => context.room?.categoryId !== event.data?.categoryId,
|
|
256
|
+
hasNext: (context, event) => context.index < context?.content?.totalPage - 1,
|
|
257
|
+
hasRoom: (context, event) => context.room?.categoryId,
|
|
258
|
+
isFavorite: (context, event) => context.favoriteList.some((item) => item.gameCode === event.data.gameCode),
|
|
259
|
+
isNotFavorite: (context, event) => !context.favoriteList.some((item) => item.gameCode === event.data.gameCode),
|
|
260
|
+
},
|
|
261
|
+
services: {
|
|
262
|
+
getFavorite: async (context, event) => {
|
|
263
|
+
return await request.send(api.getListMyFavorite())
|
|
264
|
+
},
|
|
265
|
+
getPageContent: async (context, event) => {
|
|
266
|
+
const { room, index } = context
|
|
267
|
+
if (room.categoryId === MY_FAVORITE) {
|
|
268
|
+
return await request.send(api.getListMyFavorite())
|
|
269
|
+
} else {
|
|
270
|
+
return await request.send(api.getListCategory({ categoryId: room.categoryId, index }))
|
|
271
|
+
}
|
|
272
|
+
},
|
|
273
|
+
updatePageContent: async (context, event) => {
|
|
274
|
+
const { room, content, index } = context
|
|
275
|
+
if (room.categoryId === MY_FAVORITE) {
|
|
276
|
+
// return await request.send(api.getListMyFavorite({ timestamp: content.timestamp }))
|
|
277
|
+
} else {
|
|
278
|
+
return await request.send(
|
|
279
|
+
api.getListCategoryByRange({
|
|
280
|
+
categoryId: room.categoryId,
|
|
281
|
+
end: index,
|
|
282
|
+
timestamp: content.timestamp,
|
|
283
|
+
})
|
|
284
|
+
)
|
|
285
|
+
}
|
|
286
|
+
},
|
|
287
|
+
connectGame: async (context, event) => {
|
|
288
|
+
const { lang, isMobile } = context
|
|
289
|
+
const { providerId, gameId, gameTypeId, mappingId } = context.game
|
|
290
|
+
const params = {
|
|
291
|
+
provider_id: providerId,
|
|
292
|
+
game_id: gameId,
|
|
293
|
+
gametype_id: gameTypeId,
|
|
294
|
+
mapping_id: mappingId,
|
|
295
|
+
is_demo: false,
|
|
296
|
+
is_mobile: isMobile,
|
|
297
|
+
lang,
|
|
298
|
+
return_url: window.location.href,
|
|
299
|
+
}
|
|
300
|
+
const { redirect_url } = await request.send(api.playGame(params))
|
|
301
|
+
return { gameURL: redirect_url }
|
|
302
|
+
},
|
|
303
|
+
disconnectGame: async (context, event) => {
|
|
304
|
+
const uid_site = event.data
|
|
305
|
+
const provider_id = context.game.providerId
|
|
306
|
+
return await request.send(api.logoutGame({ uid_site, provider_id }))
|
|
307
|
+
},
|
|
308
|
+
addFavorite: async (context, event) => {
|
|
309
|
+
try {
|
|
310
|
+
await request.send(api.addFavoriteGame(event.data.gameCode))
|
|
311
|
+
return event.data
|
|
312
|
+
} catch (error) {
|
|
313
|
+
throw event.data
|
|
314
|
+
}
|
|
315
|
+
},
|
|
316
|
+
removeFavorite: async (context, event) => {
|
|
317
|
+
try {
|
|
318
|
+
await request.send(api.removeFavoriteGame(event.data.gameCode))
|
|
319
|
+
return event.data
|
|
320
|
+
} catch (error) {
|
|
321
|
+
throw event.data
|
|
322
|
+
}
|
|
323
|
+
},
|
|
324
|
+
},
|
|
325
|
+
}
|
|
326
|
+
)
|
|
327
|
+
}
|
package/src/machine/index.js
CHANGED
|
@@ -5,6 +5,7 @@ import welcome from './welcome.js'
|
|
|
5
5
|
import common from './common.js'
|
|
6
6
|
import error from './error.js'
|
|
7
7
|
import game from './game.js'
|
|
8
|
+
import game_v2 from './game_v2.js'
|
|
8
9
|
import game_favorite from './game_favorite.js'
|
|
9
10
|
import game_search from './game_search.js'
|
|
10
11
|
import game_hot_new from './game_hot_new.js'
|
|
@@ -15,6 +16,7 @@ import reward_fc from './reward_fc.js'
|
|
|
15
16
|
import reward from './reward.js'
|
|
16
17
|
import setting from './setting.js'
|
|
17
18
|
import side from './side.js'
|
|
19
|
+
import side_v2 from './side_v2.js'
|
|
18
20
|
import user_info from './user_info.js'
|
|
19
21
|
import user_sign_up from './user_sign_up.js'
|
|
20
22
|
import user_reset_password from './user_reset_password.js'
|
|
@@ -38,6 +40,7 @@ export default {
|
|
|
38
40
|
deposit,
|
|
39
41
|
error,
|
|
40
42
|
game,
|
|
43
|
+
game_v2,
|
|
41
44
|
game_favorite,
|
|
42
45
|
game_search,
|
|
43
46
|
game_hot_new,
|
|
@@ -48,6 +51,7 @@ export default {
|
|
|
48
51
|
reward_fc,
|
|
49
52
|
setting,
|
|
50
53
|
side,
|
|
54
|
+
side_v2,
|
|
51
55
|
user_info,
|
|
52
56
|
user_sign_up,
|
|
53
57
|
user_reset_password,
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { assign, createMachine } from 'xstate'
|
|
2
|
+
import game from '../api/game.js'
|
|
3
|
+
|
|
4
|
+
export default function (request) {
|
|
5
|
+
return createMachine(
|
|
6
|
+
{
|
|
7
|
+
id: 'side',
|
|
8
|
+
initial: 'loading',
|
|
9
|
+
context: {
|
|
10
|
+
menu: null,
|
|
11
|
+
menuItemStack: [],
|
|
12
|
+
previousMenuItemStack: [],
|
|
13
|
+
historyStack: [],
|
|
14
|
+
},
|
|
15
|
+
states: {
|
|
16
|
+
loading: {
|
|
17
|
+
invoke: {
|
|
18
|
+
src: 'getMenu',
|
|
19
|
+
onDone: {
|
|
20
|
+
target: 'idle',
|
|
21
|
+
actions: ['setMenu', 'setDefaultMenuItemStack'],
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
idle: {
|
|
26
|
+
initial: 'pending',
|
|
27
|
+
states: {
|
|
28
|
+
pending: {
|
|
29
|
+
after: {
|
|
30
|
+
20000: [
|
|
31
|
+
{
|
|
32
|
+
target: 'updating',
|
|
33
|
+
cond: 'isInMenu'
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
target: 'pending',
|
|
37
|
+
},
|
|
38
|
+
]
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
updating: {
|
|
42
|
+
invoke: {
|
|
43
|
+
src: 'fetchUpdateMenu',
|
|
44
|
+
onDone: {
|
|
45
|
+
target: 'pending',
|
|
46
|
+
actions: 'updateMenu',
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
on: {
|
|
52
|
+
SELECT: {
|
|
53
|
+
actions: 'setMenuItemStack',
|
|
54
|
+
},
|
|
55
|
+
CANCEL: {
|
|
56
|
+
actions: 'restoreMenuItemStack',
|
|
57
|
+
},
|
|
58
|
+
PUSH: {
|
|
59
|
+
actions: 'pushHistoryStack'
|
|
60
|
+
},
|
|
61
|
+
POP: {
|
|
62
|
+
actions: 'popHistoryStack'
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
actions: {
|
|
70
|
+
setMenu: assign((context, event) => {
|
|
71
|
+
const menu = event.data
|
|
72
|
+
addLevelProperty(menu.data, 0)
|
|
73
|
+
return { menu }
|
|
74
|
+
}),
|
|
75
|
+
setDefaultMenuItemStack: assign((context, event) => {
|
|
76
|
+
const menuItemStack = getDefaultItem(event.data.data[0])
|
|
77
|
+
return { menuItemStack }
|
|
78
|
+
}),
|
|
79
|
+
setMenuItemStack: assign((context, event) => {
|
|
80
|
+
const { menuItemStack } = context
|
|
81
|
+
const inputItem = event.data
|
|
82
|
+
const isTopItem = inputItem.level === 0
|
|
83
|
+
const hasSubMenu = inputItem.sub.length
|
|
84
|
+
|
|
85
|
+
if (isTopItem) {
|
|
86
|
+
if (hasSubMenu) {
|
|
87
|
+
const isSameBranch = menuItemStack[0].categoryId === inputItem.categoryId
|
|
88
|
+
if (isSameBranch) {
|
|
89
|
+
return {
|
|
90
|
+
previousMenuItemStack: menuItemStack,
|
|
91
|
+
historyStack: []
|
|
92
|
+
}
|
|
93
|
+
} else {
|
|
94
|
+
return {
|
|
95
|
+
previousMenuItemStack: menuItemStack,
|
|
96
|
+
menuItemStack: [event.data],
|
|
97
|
+
historyStack: []
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
} else {
|
|
101
|
+
return {
|
|
102
|
+
previousMenuItemStack: [],
|
|
103
|
+
menuItemStack: [event.data],
|
|
104
|
+
historyStack: []
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
} else {
|
|
108
|
+
const slicedStack = menuItemStack.slice(0, inputItem.level)
|
|
109
|
+
return {
|
|
110
|
+
menuItemStack: [...slicedStack, event.data],
|
|
111
|
+
historyStack: []
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}),
|
|
115
|
+
restoreMenuItemStack: assign((context, event) => {
|
|
116
|
+
const { previousMenuItemStack } = context
|
|
117
|
+
return {
|
|
118
|
+
previousMenuItemStack: [],
|
|
119
|
+
menuItemStack: previousMenuItemStack,
|
|
120
|
+
}
|
|
121
|
+
}),
|
|
122
|
+
updateMenu: assign((context, event) => {
|
|
123
|
+
const menu = event.data
|
|
124
|
+
if (menu.data.length) {
|
|
125
|
+
addLevelProperty(menu.data, 0)
|
|
126
|
+
return { menu }
|
|
127
|
+
}
|
|
128
|
+
}),
|
|
129
|
+
pushHistoryStack: assign((context, event) => {
|
|
130
|
+
const { menuItemStack, historyStack } = context
|
|
131
|
+
return {
|
|
132
|
+
historyStack: historyStack.concat(menuItemStack.slice(-1)),
|
|
133
|
+
}
|
|
134
|
+
}),
|
|
135
|
+
popHistoryStack: assign((context, event) => {
|
|
136
|
+
const { historyStack } = context
|
|
137
|
+
return {
|
|
138
|
+
historyStack: historyStack.slice(0, -1),
|
|
139
|
+
}
|
|
140
|
+
}),
|
|
141
|
+
},
|
|
142
|
+
guards: {
|
|
143
|
+
isInMenu: ((context, event) => {
|
|
144
|
+
const {menuItemStack, menu} = context
|
|
145
|
+
const menuItem = menuItemStack.slice(-1)[0]
|
|
146
|
+
return isItemInMenu(menuItem, menu.data)
|
|
147
|
+
})
|
|
148
|
+
},
|
|
149
|
+
services: {
|
|
150
|
+
getMenu: async (context, event) => {
|
|
151
|
+
return await request.send(game.getListRoot())
|
|
152
|
+
},
|
|
153
|
+
fetchUpdateMenu: async (context, event) => {
|
|
154
|
+
return await request.send(game.getListRoot({ timestamp: context.menu.timestamp }))
|
|
155
|
+
},
|
|
156
|
+
},
|
|
157
|
+
}
|
|
158
|
+
)
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function isItemInMenu(targetItem, menuList) {
|
|
162
|
+
return menuList.reduce((result, currentItem) => {
|
|
163
|
+
if (result) {
|
|
164
|
+
return true
|
|
165
|
+
} else {
|
|
166
|
+
if (currentItem.categoryId === targetItem.categoryId) {
|
|
167
|
+
return true
|
|
168
|
+
} else if (currentItem.sub.length) {
|
|
169
|
+
return isItemInMenu(targetItem, currentItem.sub)
|
|
170
|
+
} else {
|
|
171
|
+
return false
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}, false)
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function getDefaultItem(node) {
|
|
178
|
+
if (node.sub.length > 0) {
|
|
179
|
+
const stack = getDefaultItem(node.sub[0])
|
|
180
|
+
return [node, ...stack]
|
|
181
|
+
} else {
|
|
182
|
+
return [node]
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function addLevelProperty(list, level) {
|
|
187
|
+
const nextLevel = level + 1
|
|
188
|
+
for (let i = 0; i < list.length; i++) {
|
|
189
|
+
list[i].level = level
|
|
190
|
+
addLevelProperty(list[i].sub, nextLevel)
|
|
191
|
+
}
|
|
192
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const MY_FAVORITE = 'MyFavorite'
|
package/src/util/index.js
CHANGED