@jetthai/cuora 1.0.179 → 1.0.181
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 +4 -0
- package/dist/bundle.mjs +709 -898
- package/package.json +1 -1
- package/src/index.js +2 -2
- package/src/machine/auth.js +16 -17
- package/src/machine/common.js +5 -6
- package/src/machine/game_favorite_v2.js +114 -0
- package/src/machine/game_v2.js +2 -87
- package/src/machine/index.js +2 -0
- package/src/machine/user_sign_up.js +4 -5
- package/src/machine/welcome.js +3 -5
- package/src/request/request.js +5 -5
- package/src/util/index.js +3 -1
- package/src/util/storage.js +37 -0
- package/src/request/cookie.js +0 -52
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -2,6 +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, { constant } from './util/index.js'
|
|
5
|
+
import util, { constant, storage } from './util/index.js'
|
|
6
6
|
|
|
7
|
-
export { api, machine, Request, Config, util, constant }
|
|
7
|
+
export { api, machine, Request, Config, util, constant, storage }
|
package/src/machine/auth.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import urljoin from 'url-join'
|
|
2
|
-
import Cookies from 'universal-cookie'
|
|
3
2
|
import { assign, createMachine } from 'xstate'
|
|
4
3
|
import auth from '../api/auth.js'
|
|
5
4
|
import user from '../api/user.js'
|
|
5
|
+
import storage from '../util/storage.js'
|
|
6
6
|
import { getDeviceToken } from '../util/deviceToken.js'
|
|
7
7
|
|
|
8
8
|
// const urljoin = require('url-join')
|
|
@@ -14,7 +14,6 @@ export default function (request) {
|
|
|
14
14
|
const phoneCountryCode = 'phone_countrycode'
|
|
15
15
|
const accountPhoneKey = 'account_phone'
|
|
16
16
|
const accountEmailKey = 'account_email'
|
|
17
|
-
const cookies = new Cookies()
|
|
18
17
|
|
|
19
18
|
return createMachine(
|
|
20
19
|
{
|
|
@@ -234,7 +233,7 @@ export default function (request) {
|
|
|
234
233
|
}),
|
|
235
234
|
setLoginLocal: assign((context, event) => {
|
|
236
235
|
const { username, password } = event.data
|
|
237
|
-
|
|
236
|
+
storage.set(userKey, username, {
|
|
238
237
|
path: '/',
|
|
239
238
|
maxAge: 60 * 60 * 24,
|
|
240
239
|
})
|
|
@@ -247,13 +246,13 @@ export default function (request) {
|
|
|
247
246
|
}
|
|
248
247
|
}),
|
|
249
248
|
fetchToken: assign((context, event) => {
|
|
250
|
-
const token =
|
|
249
|
+
const token = storage.get(tokenKey)
|
|
251
250
|
return {
|
|
252
251
|
token,
|
|
253
252
|
}
|
|
254
253
|
}),
|
|
255
254
|
setToken: assign((context, event) => {
|
|
256
|
-
|
|
255
|
+
storage.set(tokenKey, event.data, {
|
|
257
256
|
path: '/',
|
|
258
257
|
maxAge: 300,
|
|
259
258
|
})
|
|
@@ -263,34 +262,34 @@ export default function (request) {
|
|
|
263
262
|
}),
|
|
264
263
|
setAccount: assign((context, event) => {
|
|
265
264
|
if (context.loginData.phone) {
|
|
266
|
-
|
|
267
|
-
|
|
265
|
+
storage.remove(accountEmailKey)
|
|
266
|
+
storage.set(accountPhoneKey, `${context.loginData.phone}`, {
|
|
268
267
|
path: '/',
|
|
269
268
|
maxAge: 60 * 60 * 24 * 7,
|
|
270
269
|
})
|
|
271
|
-
|
|
270
|
+
storage.set(phoneCountryCode, `${context.countryAbbr}_${context.loginData.countryCode}`, {
|
|
272
271
|
path: '/',
|
|
273
272
|
maxAge: 60 * 60 * 24 * 7,
|
|
274
273
|
})
|
|
275
274
|
} else if (context.loginData.email) {
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
275
|
+
storage.remove(accountPhoneKey)
|
|
276
|
+
storage.remove(phoneCountryCode)
|
|
277
|
+
storage.set(accountEmailKey, context.loginData.email, {
|
|
279
278
|
path: '/',
|
|
280
279
|
maxAge: 60 * 60 * 24 * 7,
|
|
281
280
|
})
|
|
282
281
|
}
|
|
283
282
|
}),
|
|
284
283
|
removeToken: assign((context, event) => {
|
|
285
|
-
|
|
284
|
+
storage.remove(tokenKey, {
|
|
286
285
|
path: '/',
|
|
287
286
|
maxAge: 300,
|
|
288
287
|
})
|
|
289
288
|
return { token: null }
|
|
290
289
|
}),
|
|
291
290
|
extendToken: assign((context, event) => {
|
|
292
|
-
const token =
|
|
293
|
-
|
|
291
|
+
const token = storage.get(tokenKey)
|
|
292
|
+
storage.set(tokenKey, token, {
|
|
294
293
|
path: '/',
|
|
295
294
|
maxAge: 300,
|
|
296
295
|
})
|
|
@@ -304,7 +303,7 @@ export default function (request) {
|
|
|
304
303
|
const messages = {
|
|
305
304
|
url: window.location.href,
|
|
306
305
|
list: [
|
|
307
|
-
{ channel:
|
|
306
|
+
{ channel: storage.get('channel'), subchannel: storage.get('subchannel') },
|
|
308
307
|
{ channel: defaultChannel, subchannel: defaultSubchannel },
|
|
309
308
|
{ channel: channel, subchannel: subchannel },
|
|
310
309
|
],
|
|
@@ -317,8 +316,8 @@ export default function (request) {
|
|
|
317
316
|
new URLSearchParams({
|
|
318
317
|
provider,
|
|
319
318
|
redirectURI: `${window.location.protocol}//${window.location.host}`,
|
|
320
|
-
channel:
|
|
321
|
-
subchannel:
|
|
319
|
+
channel: storage.get('channel') || channel || defaultChannel || 'official',
|
|
320
|
+
subchannel: storage.get('subchannel') || subchannel || defaultSubchannel || 'pwa',
|
|
322
321
|
// dt,
|
|
323
322
|
platform: 'pwa',
|
|
324
323
|
}).toString()
|
package/src/machine/common.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import UAParser from 'ua-parser-js'
|
|
2
|
-
import Cookies from 'universal-cookie'
|
|
3
2
|
import { assign, createMachine } from 'xstate'
|
|
4
3
|
import pickBy from 'lodash/pickBy.js'
|
|
5
4
|
import api from '../api/common.js'
|
|
5
|
+
import storage from '../util/storage.js'
|
|
6
6
|
|
|
7
7
|
// const pickBy = require('lodash/pickBy')
|
|
8
8
|
// const UAParser = require('ua-parser-js')
|
|
9
|
-
const cookies = new Cookies()
|
|
10
9
|
|
|
11
10
|
export default function (request) {
|
|
12
11
|
const { appSecret, defaultChannel, defaultSubchannel } = request.config
|
|
@@ -155,14 +154,14 @@ export default function (request) {
|
|
|
155
154
|
return
|
|
156
155
|
} else {
|
|
157
156
|
let urlParams = new URLSearchParams(window.location.search)
|
|
158
|
-
const channel = urlParams.get('channel') ||
|
|
159
|
-
const subchannel = urlParams.get('subchannel') ||
|
|
157
|
+
const channel = urlParams.get('channel') || storage.get('channel') || defaultChannel || 'official'
|
|
158
|
+
const subchannel = urlParams.get('subchannel') || storage.get('subchannel') || defaultSubchannel || 'pwa'
|
|
160
159
|
|
|
161
|
-
|
|
160
|
+
storage.set('channel', channel, {
|
|
162
161
|
path: '/',
|
|
163
162
|
maxAge: 60 * 60 * 24 * 7,
|
|
164
163
|
})
|
|
165
|
-
|
|
164
|
+
storage.set('subchannel', subchannel, {
|
|
166
165
|
path: '/',
|
|
167
166
|
maxAge: 60 * 60 * 24 * 7,
|
|
168
167
|
})
|
|
@@ -0,0 +1,114 @@
|
|
|
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
|
+
invoke: {
|
|
15
|
+
src: 'fetchList',
|
|
16
|
+
onDone: {
|
|
17
|
+
actions: 'setList',
|
|
18
|
+
},
|
|
19
|
+
onError: {
|
|
20
|
+
actions: assign({ list: [] }),
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
adding: {
|
|
25
|
+
initial: 'disable',
|
|
26
|
+
states: {
|
|
27
|
+
disable: {},
|
|
28
|
+
enable: {
|
|
29
|
+
invoke: {
|
|
30
|
+
src: 'add',
|
|
31
|
+
onDone: {},
|
|
32
|
+
onError: {
|
|
33
|
+
actions: 'removeFromList',
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
removing: {
|
|
40
|
+
initial: 'disable',
|
|
41
|
+
states: {
|
|
42
|
+
disable: {},
|
|
43
|
+
enable: {
|
|
44
|
+
invoke: {
|
|
45
|
+
src: 'remove',
|
|
46
|
+
onDone: {},
|
|
47
|
+
onError: {
|
|
48
|
+
actions: 'addToList',
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
on: {
|
|
56
|
+
ADD: {
|
|
57
|
+
target: 'adding.enable',
|
|
58
|
+
actions: 'addToList',
|
|
59
|
+
cond: 'isNotExist',
|
|
60
|
+
},
|
|
61
|
+
REMOVE: {
|
|
62
|
+
target: 'removing.enable',
|
|
63
|
+
actions: 'removeFromList',
|
|
64
|
+
cond: 'isExist',
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
actions: {
|
|
70
|
+
setList: assign((context, event) => {
|
|
71
|
+
return {
|
|
72
|
+
list: event.data,
|
|
73
|
+
}
|
|
74
|
+
}),
|
|
75
|
+
addToList: assign((context, event) => {
|
|
76
|
+
return {
|
|
77
|
+
list: [...context.list, event.data],
|
|
78
|
+
}
|
|
79
|
+
}),
|
|
80
|
+
removeFromList: assign((context, event) => {
|
|
81
|
+
return {
|
|
82
|
+
list: context.list.filter((item) => item.gameCode !== event.data.gameCode),
|
|
83
|
+
}
|
|
84
|
+
}),
|
|
85
|
+
},
|
|
86
|
+
guards: {
|
|
87
|
+
isExist: (context, event) => context.list.some((item) => item.gameCode === event.data.gameCode),
|
|
88
|
+
isNotExist: (context, event) => !context.list.some((item) => item.gameCode === event.data.gameCode)
|
|
89
|
+
},
|
|
90
|
+
services: {
|
|
91
|
+
add: async (context, event) => {
|
|
92
|
+
try {
|
|
93
|
+
await request.send(api.addListFavorite(event.data.gameCode))
|
|
94
|
+
return event.data
|
|
95
|
+
} catch (error) {
|
|
96
|
+
throw event.data
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
remove: async (context, event) => {
|
|
100
|
+
try {
|
|
101
|
+
await request.send(api.removeListFavorite(event.data.gameCode))
|
|
102
|
+
return event.data
|
|
103
|
+
} catch (error) {
|
|
104
|
+
throw event.data
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
fetchList: async (context, event) => {
|
|
108
|
+
const { data } = await request.send(api.getListMyFavorite())
|
|
109
|
+
return data
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
}
|
|
113
|
+
)
|
|
114
|
+
}
|
package/src/machine/game_v2.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { assign, createMachine } from 'xstate'
|
|
2
2
|
import api from '../api/game.js'
|
|
3
3
|
import UAParser from 'ua-parser-js'
|
|
4
|
-
import {
|
|
4
|
+
import { GAME_SEARCH } from '../util/constant.js'
|
|
5
5
|
|
|
6
6
|
export default function (request) {
|
|
7
7
|
return createMachine(
|
|
@@ -17,7 +17,6 @@ export default function (request) {
|
|
|
17
17
|
parentCategoryId: null,
|
|
18
18
|
totalPage: 1,
|
|
19
19
|
},
|
|
20
|
-
favoriteList: [],
|
|
21
20
|
// play params
|
|
22
21
|
game: {
|
|
23
22
|
providerId: null,
|
|
@@ -52,16 +51,6 @@ export default function (request) {
|
|
|
52
51
|
target: 'connecting',
|
|
53
52
|
actions: ['setGameInfo', 'setLang'],
|
|
54
53
|
},
|
|
55
|
-
ADD_FAVORITE: {
|
|
56
|
-
target: 'adding',
|
|
57
|
-
cond: 'isNotFavorite',
|
|
58
|
-
actions: 'addToFavoriteList',
|
|
59
|
-
},
|
|
60
|
-
REMOVE_FAVORITE: {
|
|
61
|
-
target: 'removing',
|
|
62
|
-
cond: 'isFavorite',
|
|
63
|
-
actions: 'removeFromFavoriteList',
|
|
64
|
-
},
|
|
65
54
|
},
|
|
66
55
|
},
|
|
67
56
|
loading: {
|
|
@@ -106,47 +95,11 @@ export default function (request) {
|
|
|
106
95
|
},
|
|
107
96
|
},
|
|
108
97
|
},
|
|
109
|
-
adding: {
|
|
110
|
-
invoke: {
|
|
111
|
-
src: 'addFavorite',
|
|
112
|
-
onDone: {
|
|
113
|
-
target: 'idle',
|
|
114
|
-
},
|
|
115
|
-
onError: {
|
|
116
|
-
target: 'idle',
|
|
117
|
-
actions: 'removeFromFavoriteList',
|
|
118
|
-
},
|
|
119
|
-
},
|
|
120
|
-
},
|
|
121
|
-
removing: {
|
|
122
|
-
invoke: {
|
|
123
|
-
src: 'removeFavorite',
|
|
124
|
-
onDone: {
|
|
125
|
-
target: 'idle',
|
|
126
|
-
},
|
|
127
|
-
onError: {
|
|
128
|
-
target: 'idle',
|
|
129
|
-
actions: 'addToFavoriteList',
|
|
130
|
-
},
|
|
131
|
-
},
|
|
132
|
-
},
|
|
133
98
|
},
|
|
134
99
|
},
|
|
135
100
|
timer: {
|
|
136
|
-
initial: '
|
|
101
|
+
initial: 'pending',
|
|
137
102
|
states: {
|
|
138
|
-
favorite: {
|
|
139
|
-
invoke: {
|
|
140
|
-
src: 'getFavorite',
|
|
141
|
-
onDone: {
|
|
142
|
-
target: 'pending',
|
|
143
|
-
actions: 'setFavoriteList',
|
|
144
|
-
},
|
|
145
|
-
onError: {
|
|
146
|
-
target: 'pending',
|
|
147
|
-
},
|
|
148
|
-
},
|
|
149
|
-
},
|
|
150
103
|
pending: {
|
|
151
104
|
after: {
|
|
152
105
|
20000: [
|
|
@@ -260,7 +213,6 @@ export default function (request) {
|
|
|
260
213
|
} else {
|
|
261
214
|
const { data, ...rest } = event.data
|
|
262
215
|
return {
|
|
263
|
-
favoriteList: room.categoryId === MY_FAVORITE ? data : favoriteList,
|
|
264
216
|
content: {
|
|
265
217
|
...context.content,
|
|
266
218
|
...rest,
|
|
@@ -270,11 +222,9 @@ export default function (request) {
|
|
|
270
222
|
}
|
|
271
223
|
}),
|
|
272
224
|
swapContent: assign((context, event) => {
|
|
273
|
-
const { room, favoriteList } = context
|
|
274
225
|
const item = event.data
|
|
275
226
|
if (item.data?.length) {
|
|
276
227
|
return {
|
|
277
|
-
favoriteList: room.categoryId === MY_FAVORITE ? event.data.data : favoriteList,
|
|
278
228
|
content: event.data,
|
|
279
229
|
}
|
|
280
230
|
}
|
|
@@ -300,36 +250,19 @@ export default function (request) {
|
|
|
300
250
|
const lang = event.data.locale.replace('-', '_')
|
|
301
251
|
return { lang }
|
|
302
252
|
}),
|
|
303
|
-
addToFavoriteList: assign((context, event) => {
|
|
304
|
-
return {
|
|
305
|
-
favoriteList: [...context.favoriteList, event.data],
|
|
306
|
-
}
|
|
307
|
-
}),
|
|
308
|
-
removeFromFavoriteList: assign((context, event) => {
|
|
309
|
-
return {
|
|
310
|
-
favoriteList: context.favoriteList.filter((item) => item.gameCode !== event.data.gameCode),
|
|
311
|
-
}
|
|
312
|
-
}),
|
|
313
253
|
...oldActions
|
|
314
254
|
},
|
|
315
255
|
guards: {
|
|
316
256
|
isDifferentRoom: (context, event) => context.room?.categoryId !== event.data?.categoryId,
|
|
317
257
|
hasNext: (context, event) => context.index < context?.content?.totalPage - 1,
|
|
318
258
|
hasRoom: (context, event) => context.room?.categoryId,
|
|
319
|
-
isFavorite: (context, event) => context.favoriteList.some((item) => item.gameCode === event.data.gameCode),
|
|
320
|
-
isNotFavorite: (context, event) => !context.favoriteList.some((item) => item.gameCode === event.data.gameCode),
|
|
321
259
|
...oldGuards
|
|
322
260
|
},
|
|
323
261
|
services: {
|
|
324
|
-
getFavorite: async (context, event) => {
|
|
325
|
-
return await request.send(api.getListMyFavorite())
|
|
326
|
-
},
|
|
327
262
|
getPageContent: async (context, event) => {
|
|
328
263
|
const { room, index } = context
|
|
329
264
|
if (room.categoryId === GAME_SEARCH) {
|
|
330
265
|
return
|
|
331
|
-
} else if (room.categoryId === MY_FAVORITE) {
|
|
332
|
-
return await request.send(api.getListMyFavorite())
|
|
333
266
|
} else {
|
|
334
267
|
return await request.send(api.getListCategory({ categoryId: room.categoryId, index }))
|
|
335
268
|
}
|
|
@@ -338,8 +271,6 @@ export default function (request) {
|
|
|
338
271
|
const { room, content, index } = context
|
|
339
272
|
if (room.categoryId === GAME_SEARCH) {
|
|
340
273
|
return
|
|
341
|
-
} else if (room.categoryId === MY_FAVORITE) {
|
|
342
|
-
// return await request.send(api.getListMyFavorite({ timestamp: content.timestamp }))
|
|
343
274
|
} else {
|
|
344
275
|
return await request.send(
|
|
345
276
|
api.getListCategoryByRange({
|
|
@@ -371,22 +302,6 @@ export default function (request) {
|
|
|
371
302
|
const provider_id = context.game.providerId
|
|
372
303
|
return await request.send(api.logoutGame({ uid_site, provider_id }))
|
|
373
304
|
},
|
|
374
|
-
addFavorite: async (context, event) => {
|
|
375
|
-
try {
|
|
376
|
-
await request.send(api.addListFavorite(event.data.gameCode))
|
|
377
|
-
return event.data
|
|
378
|
-
} catch (error) {
|
|
379
|
-
throw event.data
|
|
380
|
-
}
|
|
381
|
-
},
|
|
382
|
-
removeFavorite: async (context, event) => {
|
|
383
|
-
try {
|
|
384
|
-
await request.send(api.removeListFavorite(event.data.gameCode))
|
|
385
|
-
return event.data
|
|
386
|
-
} catch (error) {
|
|
387
|
-
throw event.data
|
|
388
|
-
}
|
|
389
|
-
},
|
|
390
305
|
...oldServices(request)
|
|
391
306
|
},
|
|
392
307
|
}
|
package/src/machine/index.js
CHANGED
|
@@ -7,6 +7,7 @@ import error from './error.js'
|
|
|
7
7
|
import game from './game.js'
|
|
8
8
|
import game_v2 from './game_v2.js'
|
|
9
9
|
import game_favorite from './game_favorite.js'
|
|
10
|
+
import game_favorite_v2 from './game_favorite_v2.js'
|
|
10
11
|
import game_search from './game_search.js'
|
|
11
12
|
import game_hot_new from './game_hot_new.js'
|
|
12
13
|
import inbox from './inbox.js'
|
|
@@ -42,6 +43,7 @@ export default {
|
|
|
42
43
|
game,
|
|
43
44
|
game_v2,
|
|
44
45
|
game_favorite,
|
|
46
|
+
game_favorite_v2,
|
|
45
47
|
game_search,
|
|
46
48
|
game_hot_new,
|
|
47
49
|
inbox,
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { assign, createMachine } from 'xstate'
|
|
2
|
-
import Cookies from 'universal-cookie'
|
|
3
2
|
import auth from '../api/auth.js'
|
|
4
3
|
import { getDeviceToken } from '../util/deviceToken.js'
|
|
4
|
+
import storage from '../util/storage.js'
|
|
5
5
|
|
|
6
|
-
const cookies = new Cookies()
|
|
7
6
|
|
|
8
7
|
export default function (request) {
|
|
9
8
|
const { fpToken, sentry, defaultChannel, defaultSubchannel } = request.config
|
|
@@ -108,7 +107,7 @@ export default function (request) {
|
|
|
108
107
|
const messages = {
|
|
109
108
|
url: window.location.href,
|
|
110
109
|
list: [
|
|
111
|
-
{ channel:
|
|
110
|
+
{ channel: storage.get('channel'), subchannel: storage.get('subchannel') },
|
|
112
111
|
{ channel: defaultChannel, subchannel: defaultSubchannel },
|
|
113
112
|
{ channel: channel, subchannel: subchannel },
|
|
114
113
|
],
|
|
@@ -118,8 +117,8 @@ export default function (request) {
|
|
|
118
117
|
return await request.send(
|
|
119
118
|
auth.register({
|
|
120
119
|
...signUpData,
|
|
121
|
-
channel:
|
|
122
|
-
subchannel:
|
|
120
|
+
channel: storage.get('channel') || defaultChannel || channel,
|
|
121
|
+
subchannel: storage.get('subchannel') || defaultSubchannel || subchannel,
|
|
123
122
|
dt,
|
|
124
123
|
reCaptchaToken: context.reCaptchaToken,
|
|
125
124
|
})
|
package/src/machine/welcome.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { assign, createMachine } from 'xstate'
|
|
2
|
-
import Cookies from 'universal-cookie'
|
|
3
2
|
import payment from '../api/payment.js'
|
|
4
3
|
import user from '../api/user.js'
|
|
5
|
-
|
|
6
|
-
const cookies = new Cookies()
|
|
4
|
+
import storage from '../util/storage.js'
|
|
7
5
|
|
|
8
6
|
export default function (request) {
|
|
9
7
|
return createMachine(
|
|
@@ -71,7 +69,7 @@ export default function (request) {
|
|
|
71
69
|
const { bank_account, bank_setting_status, topup, verification_status, uid } = context.userInfo || {}
|
|
72
70
|
// const hasBankAccount = bank_account || bank_setting_status === 1 // sabai
|
|
73
71
|
const isComplete = topup === 1 || verification_status === 1
|
|
74
|
-
const isSent =
|
|
72
|
+
const isSent = storage.get(`welcome_${uid}`)
|
|
75
73
|
return !(isSent || isComplete)
|
|
76
74
|
},
|
|
77
75
|
isFilled: (context, event) => {
|
|
@@ -86,7 +84,7 @@ export default function (request) {
|
|
|
86
84
|
}
|
|
87
85
|
}),
|
|
88
86
|
setInfo: (context, event) => {
|
|
89
|
-
|
|
87
|
+
storage.set(`welcome_${context.userInfo.uid}`, 'done', {
|
|
90
88
|
path: '/',
|
|
91
89
|
maxAge: 60 * 60 * 24 * 365,
|
|
92
90
|
})
|
package/src/request/request.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import pickBy from 'lodash/pickBy.js'
|
|
2
|
-
import
|
|
2
|
+
import storage from '../util/storage.js'
|
|
3
3
|
|
|
4
4
|
// const pickBy = require('lodash/pickBy')
|
|
5
5
|
|
|
@@ -12,7 +12,7 @@ export default class Request {
|
|
|
12
12
|
this.axios = axios
|
|
13
13
|
this.source = axios.CancelToken.source()
|
|
14
14
|
this.config = config
|
|
15
|
-
this.
|
|
15
|
+
this.key = `cuora_${config.clientId}`
|
|
16
16
|
this.errorHandler = null
|
|
17
17
|
this.initialize()
|
|
18
18
|
}
|
|
@@ -21,8 +21,8 @@ export default class Request {
|
|
|
21
21
|
this.axios.interceptors.request.use((axiosConfig) => {
|
|
22
22
|
axiosConfig.headers['X-TH1GAMES-VERSION'] = this.config.version
|
|
23
23
|
axiosConfig.headers['X-TH1GAMES-PLATFORM'] = this.config.platform
|
|
24
|
-
if (this.
|
|
25
|
-
axiosConfig.headers.Authorization = this.
|
|
24
|
+
if (storage.get(this.key)) {
|
|
25
|
+
axiosConfig.headers.Authorization = storage.get(this.key)
|
|
26
26
|
}
|
|
27
27
|
return axiosConfig
|
|
28
28
|
})
|
|
@@ -50,7 +50,7 @@ export default class Request {
|
|
|
50
50
|
async send(req, customToken) {
|
|
51
51
|
try {
|
|
52
52
|
const cancelToken = customToken || this.source.token
|
|
53
|
-
this._checkToken(req, this.
|
|
53
|
+
this._checkToken(req, storage.get(this.key))
|
|
54
54
|
const requestConfig = this._createConfig(req, cancelToken)
|
|
55
55
|
const { data } = await this.axios.request(requestConfig)
|
|
56
56
|
return data
|
package/src/util/index.js
CHANGED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// import Cookies from 'universal-cookie'
|
|
2
|
+
|
|
3
|
+
// const cookies = new Cookies()
|
|
4
|
+
|
|
5
|
+
export default {
|
|
6
|
+
get(name, options) {
|
|
7
|
+
//return cookies.get(name, options)
|
|
8
|
+
|
|
9
|
+
const itemStr = localStorage.getItem(name)
|
|
10
|
+
|
|
11
|
+
if (!itemStr) {
|
|
12
|
+
return null
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const item = JSON.parse(itemStr)
|
|
16
|
+
if (new Date().getTime() > item.expiry) {
|
|
17
|
+
localStorage.removeItem(name)
|
|
18
|
+
return null
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return item.value
|
|
22
|
+
},
|
|
23
|
+
set(name, value, options) {
|
|
24
|
+
// cookies.set(name, value, options)
|
|
25
|
+
|
|
26
|
+
const item = {
|
|
27
|
+
value,
|
|
28
|
+
expiry: new Date().getTime() + (options.maxAge || 0)*1000
|
|
29
|
+
}
|
|
30
|
+
localStorage.setItem(name, JSON.stringify(item))
|
|
31
|
+
},
|
|
32
|
+
remove(name, options) {
|
|
33
|
+
// cookies.remove(name, options)
|
|
34
|
+
|
|
35
|
+
localStorage.removeItem(name)
|
|
36
|
+
}
|
|
37
|
+
}
|
package/src/request/cookie.js
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import Cookies from 'universal-cookie'
|
|
2
|
-
|
|
3
|
-
export default class Cookie {
|
|
4
|
-
constructor(tokenKey) {
|
|
5
|
-
this.cookies = new Cookies()
|
|
6
|
-
this.tokenKey = tokenKey
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
setToken(token) {
|
|
10
|
-
this.cookies.set(this.tokenKey, token, {
|
|
11
|
-
path: '/',
|
|
12
|
-
maxAge: 300,
|
|
13
|
-
})
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
prolongToken() {
|
|
17
|
-
const token = this.getToken()
|
|
18
|
-
if (token) {
|
|
19
|
-
this.setToken(token)
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
getToken() {
|
|
24
|
-
return this.cookies.get(this.tokenKey)
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
removeToken() {
|
|
28
|
-
this.cookies.remove(this.tokenKey, {
|
|
29
|
-
path: '/',
|
|
30
|
-
maxAge: 300,
|
|
31
|
-
})
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
setUser(user) {
|
|
35
|
-
this.cookies.set('cuora_tempuser', user, {
|
|
36
|
-
path: '/',
|
|
37
|
-
maxAge: 60 * 60 * 24,
|
|
38
|
-
})
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
getUser() {
|
|
42
|
-
return this.cookies.get('cuora_tempuser')
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
set(name, value, options) {
|
|
46
|
-
this.cookies.set(name, value, options)
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
get(name, options) {
|
|
50
|
-
return this.cookies.get(name, options)
|
|
51
|
-
}
|
|
52
|
-
}
|