@jetthai/cuora 1.1.479 → 1.1.481-api.0
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/.github/copilot-instructions.md +64 -57
- package/AGENTS.md +65 -58
- package/AI_PROMPT_SOURCE.md +65 -58
- package/CHANGELOG.md +35 -0
- package/CLAUDE.md +65 -58
- package/GEMINI.md +65 -58
- package/README.md +11 -12
- package/package.json +1 -1
- package/src/api/account.js +0 -1
- package/src/api/activity.js +0 -37
- package/src/api/auth.js +0 -31
- package/src/api/game.js +0 -10
- package/src/api/payment.js +0 -51
- package/src/api/user.js +0 -16
- package/src/index.js +2 -2
- package/src/machine/activity/diamond_shop_activity_cash.js +0 -1
- package/src/machine/activity/fafafa_activity.js +0 -10
- package/src/machine/activity/index.js +0 -12
- package/src/machine/auth.js +38 -60
- package/src/machine/auth_otp_v3.js +0 -3
- package/src/machine/common.js +0 -55
- package/src/machine/deposit/index.js +0 -28
- package/src/machine/deposit/manual_cash.js +0 -8
- package/src/machine/game_info.js +1 -12
- package/src/machine/game_v2_1.js +1 -89
- package/src/machine/inbox.js +0 -12
- package/src/machine/index.js +0 -32
- package/src/machine/reward_cash.js +0 -39
- package/src/machine/user_reset_password.js +0 -13
- package/src/machine/websocket.js +0 -4
- package/src/machine/withdraw/index.js +0 -6
- package/src/request/request.js +68 -29
- package/src/util/constant.js +0 -1
- package/src/util/index.js +1 -4
- package/src/machine/activity/activity.js +0 -209
- package/src/machine/activity/diamond_shop_activity_fc.js +0 -196
- package/src/machine/activity/diamond_shop_activity_vn.js +0 -178
- package/src/machine/activity/invite_friends_activity.js +0 -114
- package/src/machine/activity/mini_game_activity.js +0 -68
- package/src/machine/activity/return_bonus_activity.js +0 -153
- package/src/machine/auth_otp_v2.js +0 -177
- package/src/machine/bank_binding_amb.js +0 -146
- package/src/machine/bonus.js +0 -76
- package/src/machine/deposit/amb.js +0 -93
- package/src/machine/deposit/crypto_bank.js +0 -330
- package/src/machine/deposit/crypto_qrcode.js +0 -148
- package/src/machine/deposit/crypto_way.js +0 -252
- package/src/machine/deposit/deposit_fc.js +0 -272
- package/src/machine/deposit/direct.js +0 -310
- package/src/machine/deposit/float.js +0 -375
- package/src/machine/deposit/krway.js +0 -151
- package/src/machine/deposit/loadcard_vn.js +0 -351
- package/src/machine/deposit/manual_vn.js +0 -458
- package/src/machine/deposit/qrcode_v2.js +0 -338
- package/src/machine/deposit/usdt.js +0 -144
- package/src/machine/deposit/virtual_bank_vn.js +0 -269
- package/src/machine/deposit/vpay.js +0 -368
- package/src/machine/game_hot_new.js +0 -79
- package/src/machine/game_replay.js +0 -46
- package/src/machine/game_search_v2.js +0 -401
- package/src/machine/honor_board.js +0 -132
- package/src/machine/merge.js +0 -57
- package/src/machine/payment_data.js +0 -86
- package/src/machine/promotions.js +0 -170
- package/src/machine/reward.js +0 -255
- package/src/machine/reward_fc.js +0 -98
- package/src/machine/side.js +0 -154
- package/src/machine/side_v2.js +0 -211
- package/src/machine/vip_table.js +0 -57
- package/src/machine/welcome.js +0 -110
- package/src/machine/withdraw/withdraw_crypto_cash.js +0 -327
- package/src/machine/withdraw/withdraw_krway.js +0 -223
- package/src/machine/withdraw/withdraw_manual.js +0 -536
- package/src/util/math.js +0 -4
|
@@ -63,10 +63,6 @@ export default function (request, context) {
|
|
|
63
63
|
states: {
|
|
64
64
|
idle: {
|
|
65
65
|
on: {
|
|
66
|
-
FETCH_WITHDRAW_RULE: {
|
|
67
|
-
target: 'fetching',
|
|
68
|
-
actions: 'setRewardData',
|
|
69
|
-
},
|
|
70
66
|
FETCH_OTHER_REWARD: {
|
|
71
67
|
target: 'fetchingOtherReward',
|
|
72
68
|
actions: 'setOrderColumn',
|
|
@@ -84,18 +80,6 @@ export default function (request, context) {
|
|
|
84
80
|
},
|
|
85
81
|
},
|
|
86
82
|
},
|
|
87
|
-
fetching: {
|
|
88
|
-
invoke: {
|
|
89
|
-
src: 'fetchWithdrawRulePreview',
|
|
90
|
-
onDone: {
|
|
91
|
-
target: 'pending',
|
|
92
|
-
actions: 'setWithdrawRulePreview',
|
|
93
|
-
},
|
|
94
|
-
onError: {
|
|
95
|
-
target: 'idle',
|
|
96
|
-
},
|
|
97
|
-
},
|
|
98
|
-
},
|
|
99
83
|
fetchingOtherReward: {
|
|
100
84
|
invoke: {
|
|
101
85
|
src: 'fetchOtherRewardList',
|
|
@@ -180,13 +164,6 @@ export default function (request, context) {
|
|
|
180
164
|
otherRewardList: event.data[0]?.data,
|
|
181
165
|
}
|
|
182
166
|
}),
|
|
183
|
-
setRewardData: assign((context, event) => {
|
|
184
|
-
const { activityNo, receiveNo } = event.data
|
|
185
|
-
return {
|
|
186
|
-
activityNo,
|
|
187
|
-
receiveNo,
|
|
188
|
-
}
|
|
189
|
-
}),
|
|
190
167
|
setCallback: assign((context, event) => {
|
|
191
168
|
return {
|
|
192
169
|
callback: event.data?.callback || (() => {}),
|
|
@@ -200,11 +177,6 @@ export default function (request, context) {
|
|
|
200
177
|
doCallback: (context, event) => {
|
|
201
178
|
context.callback()
|
|
202
179
|
},
|
|
203
|
-
setWithdrawRulePreview: assign((context, event) => {
|
|
204
|
-
return {
|
|
205
|
-
withdrawRule: event.data,
|
|
206
|
-
}
|
|
207
|
-
}),
|
|
208
180
|
setLang: assign((context, event) => {
|
|
209
181
|
const lang = event.data.locale || context.lang || 'en-US'
|
|
210
182
|
return { lang }
|
|
@@ -250,17 +222,6 @@ export default function (request, context) {
|
|
|
250
222
|
const [otherRewardList] = await Promise.all([getOtherRewardAPI])
|
|
251
223
|
return [otherRewardList]
|
|
252
224
|
},
|
|
253
|
-
fetchWithdrawRulePreview: async (context, event) => {
|
|
254
|
-
const { receiveNo } = context
|
|
255
|
-
const data = await request.send(
|
|
256
|
-
payment.getWithdrawRulePreview({
|
|
257
|
-
applyType: 'activity',
|
|
258
|
-
applyNo: receiveNo,
|
|
259
|
-
amount: null,
|
|
260
|
-
})
|
|
261
|
-
)
|
|
262
|
-
return data
|
|
263
|
-
},
|
|
264
225
|
receiveReward: async (context, event) => {
|
|
265
226
|
const { activityNo, receiveNo, attended } = event.data
|
|
266
227
|
// Number("")-> 0 / Number(" ") -> 0 需要收到實際的數字才傳給後端
|
|
@@ -28,10 +28,6 @@ export default function (request) {
|
|
|
28
28
|
target: 'otpFetching',
|
|
29
29
|
actions: 'setOtpParamsEmail',
|
|
30
30
|
},
|
|
31
|
-
SEND_OTP_LOCAL: {
|
|
32
|
-
target: 'otpFetching',
|
|
33
|
-
actions: 'setOtpParamsLocal',
|
|
34
|
-
},
|
|
35
31
|
SEND_OTP_PHONE: {
|
|
36
32
|
target: 'otpFetching',
|
|
37
33
|
actions: 'setOtpParamsPhone',
|
|
@@ -157,15 +153,6 @@ export default function (request) {
|
|
|
157
153
|
},
|
|
158
154
|
}
|
|
159
155
|
}),
|
|
160
|
-
setOtpParamsLocal: assign((context, event) => {
|
|
161
|
-
const { username } = event.data
|
|
162
|
-
return {
|
|
163
|
-
otpParams: {
|
|
164
|
-
provider: 'local',
|
|
165
|
-
username,
|
|
166
|
-
},
|
|
167
|
-
}
|
|
168
|
-
}),
|
|
169
156
|
setOtpParamsEmail: assign((context, event) => {
|
|
170
157
|
const { email } = event.data
|
|
171
158
|
return {
|
package/src/machine/websocket.js
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
import withdraw_manual from './withdraw_manual.js'
|
|
2
|
-
import withdraw_krway from './withdraw_krway.js'
|
|
3
|
-
import withdraw_crypto_cash from './withdraw_crypto_cash.js'
|
|
4
1
|
import withdraw_manual_cash from './withdraw_manual_cash.js'
|
|
5
2
|
|
|
6
3
|
export default {
|
|
7
|
-
withdraw_manual,
|
|
8
|
-
withdraw_krway,
|
|
9
|
-
withdraw_crypto_cash,
|
|
10
4
|
withdraw_manual_cash,
|
|
11
5
|
}
|
package/src/request/request.js
CHANGED
|
@@ -5,11 +5,12 @@ import { getErr998SentryExtra } from '../util/err998SentryExtra.js'
|
|
|
5
5
|
// 暫停 ERR_998 上報:在組裝 Sentry 資料之前就中止,不建立事件;仍照常 reject ERR_998 給呼叫端。恢復時改回 false 即可
|
|
6
6
|
const IS_ERR_998_REPORT_PAUSED = true
|
|
7
7
|
|
|
8
|
+
const CANCELLED_MESSAGE = 'Requests Cancelled'
|
|
9
|
+
|
|
8
10
|
// const pickBy = require('lodash/pickBy')
|
|
9
11
|
const supportVersion2List = [
|
|
10
12
|
// 04-09 Update
|
|
11
13
|
'game/play',
|
|
12
|
-
'game/gameReplay',
|
|
13
14
|
'game/logout',
|
|
14
15
|
'game/list/v3/root',
|
|
15
16
|
'game/list/v3/category',
|
|
@@ -21,8 +22,6 @@ const supportVersion2List = [
|
|
|
21
22
|
'game/list/v3/removeMyFavorite',
|
|
22
23
|
'login',
|
|
23
24
|
'callback/:strategy',
|
|
24
|
-
'guestLogin',
|
|
25
|
-
'appLogin',
|
|
26
25
|
'logout',
|
|
27
26
|
'self',
|
|
28
27
|
'register',
|
|
@@ -30,7 +29,6 @@ const supportVersion2List = [
|
|
|
30
29
|
'verify',
|
|
31
30
|
'reset',
|
|
32
31
|
'acknowledge',
|
|
33
|
-
'recovery',
|
|
34
32
|
'recovery/abandon',
|
|
35
33
|
'recovery/acknowledge',
|
|
36
34
|
'checkDt',
|
|
@@ -59,7 +57,6 @@ const supportVersion2List = [
|
|
|
59
57
|
'account-binding/status',
|
|
60
58
|
'account-binding/bind',
|
|
61
59
|
'account-binding/acknowledge',
|
|
62
|
-
'account-binding/bind-third-party',
|
|
63
60
|
'feeds',
|
|
64
61
|
'broadcast',
|
|
65
62
|
'upload',
|
|
@@ -78,18 +75,13 @@ const supportVersion2List = [
|
|
|
78
75
|
'payment/v2/convertFreeCredit',
|
|
79
76
|
'payment/v2/getBindingBankList',
|
|
80
77
|
'payment/v2/getBindingPaymentList',
|
|
81
|
-
'payment/v2/getWithdrawBankList',
|
|
82
|
-
'payment/v2/getCurrentWithdrawRule',
|
|
83
78
|
'payment/v2/withdrawCheck',
|
|
84
|
-
'payment/v2/history',
|
|
85
|
-
'payment/v2/mergeWallet',
|
|
86
79
|
'payment/v2/paymentDetail',
|
|
87
80
|
'payment/v2/category/options',
|
|
88
81
|
'payment/v2/paymentInfo',
|
|
89
82
|
'payment/v2/getBindingPaymentInfo',
|
|
90
83
|
'payment/v2/pendingOrder',
|
|
91
84
|
'payment/v2/promotions',
|
|
92
|
-
'payment/v2/spotmarket',
|
|
93
85
|
'payment/v2/transactionHistory',
|
|
94
86
|
'payment/v2/updateUtr',
|
|
95
87
|
'payment/v2/setting',
|
|
@@ -99,7 +91,6 @@ const supportVersion2List = [
|
|
|
99
91
|
'payment/v2/withdrawRule',
|
|
100
92
|
'payment/v2/:paymentType/getBankList',
|
|
101
93
|
'payment/v2/:paymentType/transaction',
|
|
102
|
-
'payment/v2/:paymentType/checkTransaction',
|
|
103
94
|
'payment/v2/:paymentType/bonus/preview',
|
|
104
95
|
'payment/v2/:paymentType/expected/result',
|
|
105
96
|
'payment/v2/:paymentType/crypto/expected/result',
|
|
@@ -114,7 +105,6 @@ const supportVersion2List = [
|
|
|
114
105
|
'activities',
|
|
115
106
|
'activities/types',
|
|
116
107
|
'activities/promo',
|
|
117
|
-
'activities/viptable',
|
|
118
108
|
'activities/level-bonus/info',
|
|
119
109
|
'activities/numbers',
|
|
120
110
|
'activities/honorBroadcast',
|
|
@@ -136,7 +126,6 @@ const supportVersion2List = [
|
|
|
136
126
|
'friends/dashboard',
|
|
137
127
|
'friends/dashboard/list',
|
|
138
128
|
'activities/ranking',
|
|
139
|
-
'activities/activity/ranking',
|
|
140
129
|
'activities/cashRain',
|
|
141
130
|
'activities/jackpot/list',
|
|
142
131
|
// 09/09
|
|
@@ -150,7 +139,6 @@ const supportVersion2List = [
|
|
|
150
139
|
'account-binding/status',
|
|
151
140
|
'account-binding/bind',
|
|
152
141
|
'account-binding/acknowledge',
|
|
153
|
-
'account-binding/bind-third-party',
|
|
154
142
|
'account-binding/bind-password',
|
|
155
143
|
'account-binding/reset-otp',
|
|
156
144
|
// 11/10
|
|
@@ -168,13 +156,15 @@ function isValid(value) {
|
|
|
168
156
|
export default class Request {
|
|
169
157
|
constructor(axios, config) {
|
|
170
158
|
this.axios = axios
|
|
171
|
-
this.source = axios.CancelToken.source()
|
|
172
159
|
this.config = config
|
|
173
160
|
this.sentry = config.sentry
|
|
174
161
|
this.key = `cuora_${config.clientId}`
|
|
175
162
|
this.errorHandler = null
|
|
176
163
|
this.hosts = []
|
|
177
164
|
this.isBlocked = false
|
|
165
|
+
this.activeRequests = new Set() // { source, token }:僅追蹤非 public 且帶 token 的在途請求,供 revokeToken 取消
|
|
166
|
+
this.revokedToken = null
|
|
167
|
+
this.tokenGate = null
|
|
178
168
|
this.clientIp = '' // 由外部 plugin(如 clientIp.client.js)非同步寫入,用於 ERR_998 Sentry 回報
|
|
179
169
|
this.hostTester = null // 由外部 plugin(如 host.client.js)寫入,需提供 lastResults 陣列供 ERR_998 Sentry 回報使用
|
|
180
170
|
this.initialize()
|
|
@@ -252,15 +242,70 @@ export default class Request {
|
|
|
252
242
|
this.errorHandler = handler
|
|
253
243
|
}
|
|
254
244
|
|
|
245
|
+
// 作廢指定 token:取消同 token 的在途請求,並讓之後仍帶此 token 的 send() 直接 reject。
|
|
246
|
+
// 只在 token 仍是目前身分時作用,舊身分遲到的錯誤不得影響新身分;重新登入後 token 改變即自然恢復
|
|
247
|
+
revokeToken(token) {
|
|
248
|
+
if (!token || token !== this.getToken()) return
|
|
249
|
+
this.revokedToken = token
|
|
250
|
+
this.activeRequests.forEach((item) => {
|
|
251
|
+
if (item.token === token) item.source.cancel(CANCELLED_MESSAGE)
|
|
252
|
+
})
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// 回前景時先確認 token 仍有效:promise 結算(成功或失敗)或逾時即放行,之後的 send() 才會送出
|
|
256
|
+
beginTokenGate(promise, timeoutMs = 3000) {
|
|
257
|
+
let timer
|
|
258
|
+
const timeout = new Promise((resolve) => {
|
|
259
|
+
timer = setTimeout(resolve, timeoutMs)
|
|
260
|
+
})
|
|
261
|
+
const gate = Promise.race([Promise.resolve(promise).catch(() => {}), timeout]).then(() => {
|
|
262
|
+
clearTimeout(timer)
|
|
263
|
+
if (this.tokenGate === gate) this.tokenGate = null
|
|
264
|
+
})
|
|
265
|
+
this.tokenGate = gate
|
|
266
|
+
return gate
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
_throwIfRevoked() {
|
|
270
|
+
if (this.revokedToken && this.getToken() === this.revokedToken) {
|
|
271
|
+
throw new Error(CANCELLED_MESSAGE)
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
_isCancelled(error) {
|
|
276
|
+
return !!this.axios.isCancel?.(error) || error?.message === CANCELLED_MESSAGE
|
|
277
|
+
}
|
|
278
|
+
|
|
255
279
|
async send(req, customToken) {
|
|
280
|
+
let tracked = null
|
|
281
|
+
let requestToken = null
|
|
256
282
|
try {
|
|
257
283
|
// 非 public 請求缺 token 直接 reject:reject → onError → leaving → 乾淨登出,且不送網路 → 洪水照止
|
|
258
284
|
if (!req.isPublic && !this.getToken()) return Promise.reject({ code: 'ERR_A103' })
|
|
259
285
|
|
|
286
|
+
// 公開請求不帶 token,作廢期間 token 仍留在 storage 也不可誤拒(如 autoLogin 前後的 getConfig)
|
|
287
|
+
if (!req.isPublic) this._throwIfRevoked()
|
|
288
|
+
|
|
289
|
+
// /self 是 gate 自己的探測請求,不可等待 gate,否則死鎖
|
|
290
|
+
if (this.tokenGate && !req.isPublic && req.url.split('?')[0] !== 'self') {
|
|
291
|
+
await this.tokenGate
|
|
292
|
+
this._throwIfRevoked()
|
|
293
|
+
if (!this.getToken()) return Promise.reject({ code: 'ERR_A103' })
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
requestToken = req.isPublic ? null : this.getToken()
|
|
297
|
+
|
|
260
298
|
// axios <0.22 對 cancelToken.promise 註冊的取消 handler 永不退訂(xhr.js 無 unsubscribe),
|
|
261
299
|
// 預設掛長壽命共用 token 會使 handler 隨請求數線性累積(掛機過夜 OOM,TI-15555)。
|
|
262
|
-
//
|
|
263
|
-
|
|
300
|
+
// 故不掛共用 token:呼叫端傳入 customToken 時自行管理其生命週期;否則帶 token 的請求用一次性 source,
|
|
301
|
+
// 結束即移出 activeRequests 隨請求回收
|
|
302
|
+
let cancelToken = customToken
|
|
303
|
+
if (!customToken && requestToken && this.axios.CancelToken) {
|
|
304
|
+
const source = this.axios.CancelToken.source()
|
|
305
|
+
tracked = { source, token: requestToken }
|
|
306
|
+
this.activeRequests.add(tracked)
|
|
307
|
+
cancelToken = source.token
|
|
308
|
+
}
|
|
264
309
|
|
|
265
310
|
const requestConfig = this._createConfig(req, cancelToken)
|
|
266
311
|
const configUrls = ['getConfig', 'get-config']
|
|
@@ -271,6 +316,10 @@ export default class Request {
|
|
|
271
316
|
return data
|
|
272
317
|
}
|
|
273
318
|
} catch (error) {
|
|
319
|
+
if (this._isCancelled(error)) throw error
|
|
320
|
+
if (requestToken && error && typeof error === 'object') {
|
|
321
|
+
error.requestToken = requestToken
|
|
322
|
+
}
|
|
274
323
|
if (error.code === 'ERR_F108') {
|
|
275
324
|
this.isBlocked = true
|
|
276
325
|
this.errorHandler && this.errorHandler(error)
|
|
@@ -285,20 +334,11 @@ export default class Request {
|
|
|
285
334
|
}
|
|
286
335
|
throw error
|
|
287
336
|
}
|
|
337
|
+
} finally {
|
|
338
|
+
if (tracked) this.activeRequests.delete(tracked)
|
|
288
339
|
}
|
|
289
340
|
}
|
|
290
341
|
|
|
291
|
-
// 注意:send() 已不再預設附加 this.source.token(見 send 內註解),
|
|
292
|
-
// sourceUpdate 僅對「呼叫端明確以 this.source.token 為 customToken」的請求有效;保留以維持 API 相容。
|
|
293
|
-
sourceUpdate() {
|
|
294
|
-
this.source.cancel('Requests Cancelled')
|
|
295
|
-
this.source = this.axios.CancelToken.source()
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
sourceGenerate() {
|
|
299
|
-
return this.axios.CancelToken.source()
|
|
300
|
-
}
|
|
301
|
-
|
|
302
342
|
_createConfig(req, cancelToken) {
|
|
303
343
|
const { method, url, params, isPublic, isFormData, headers } = req
|
|
304
344
|
let fullURL = this.config.fullURL
|
|
@@ -357,7 +397,6 @@ export default class Request {
|
|
|
357
397
|
'activities/getFreeGameRewardList': 'activities/free-game/get-free-game-reward-list',
|
|
358
398
|
'activities/lose-rebate/history': 'activities/rebate/lose-rebate/history',
|
|
359
399
|
'activities/ranking': 'activities/ranking/promotion-ranking',
|
|
360
|
-
'activities/activity/ranking': 'activities/ranking/basic-ranking',
|
|
361
400
|
'activities/cashRain': 'activities/cash-rain/exchange',
|
|
362
401
|
'tournament/detail': 'activities/tournament/detail',
|
|
363
402
|
'ranking/detail': 'activities/tournament/ranking/detail',
|
package/src/util/constant.js
CHANGED
package/src/util/index.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import storage from './storage.js'
|
|
2
2
|
import paramStore from './paramStore.js'
|
|
3
3
|
import * as constant from './constant.js'
|
|
4
|
-
import { max } from './math.js'
|
|
5
|
-
import { isAmountInRange } from './amount.js'
|
|
6
4
|
|
|
7
|
-
export
|
|
8
|
-
export { constant, storage, paramStore, max, isAmountInRange }
|
|
5
|
+
export { constant, storage, paramStore }
|
|
@@ -1,209 +0,0 @@
|
|
|
1
|
-
import { createMachine, assign } from 'xstate'
|
|
2
|
-
import activity from '../../api/activity.js'
|
|
3
|
-
import payment from '../../api/payment.js'
|
|
4
|
-
|
|
5
|
-
export default function (request) {
|
|
6
|
-
const { appSecret } = request.config
|
|
7
|
-
return createMachine(
|
|
8
|
-
{
|
|
9
|
-
id: 'activity',
|
|
10
|
-
initial: 'init',
|
|
11
|
-
context: {
|
|
12
|
-
tick: 2000,
|
|
13
|
-
specifyActivities: [4, 29, 34],
|
|
14
|
-
activitiesDetailList: [],
|
|
15
|
-
activityList: [],
|
|
16
|
-
promotionList: [],
|
|
17
|
-
activityMap: {},
|
|
18
|
-
tournamentList: [],
|
|
19
|
-
refs: {},
|
|
20
|
-
uidSite: '',
|
|
21
|
-
siteConfig: {},
|
|
22
|
-
isPlaying: false,
|
|
23
|
-
},
|
|
24
|
-
states: {
|
|
25
|
-
init: {
|
|
26
|
-
on: {
|
|
27
|
-
SET_CONFIG: {
|
|
28
|
-
target: 'fetchingList',
|
|
29
|
-
actions: 'setSiteConifg',
|
|
30
|
-
},
|
|
31
|
-
},
|
|
32
|
-
},
|
|
33
|
-
fetchingList: {
|
|
34
|
-
invoke: {
|
|
35
|
-
src: 'fetchList',
|
|
36
|
-
onDone: {
|
|
37
|
-
target: 'idle',
|
|
38
|
-
actions: ['setActivityList', 'setTournamentList', 'setPromotionList'],
|
|
39
|
-
},
|
|
40
|
-
onError: {
|
|
41
|
-
target: 'idle',
|
|
42
|
-
},
|
|
43
|
-
},
|
|
44
|
-
},
|
|
45
|
-
idle: {
|
|
46
|
-
type: 'parallel',
|
|
47
|
-
states: {
|
|
48
|
-
activitiesDetail: {
|
|
49
|
-
initial: 'checking',
|
|
50
|
-
states: {
|
|
51
|
-
checking: {
|
|
52
|
-
always: [{ target: 'fetchActivityDetail', cond: 'hasSpecifyActivities' }, { target: 'end' }],
|
|
53
|
-
},
|
|
54
|
-
fetchActivityDetail: {
|
|
55
|
-
invoke: {
|
|
56
|
-
src: 'fetchActivitiesDetail',
|
|
57
|
-
onDone: {
|
|
58
|
-
target: 'end',
|
|
59
|
-
actions: 'setActivitiesDetailList',
|
|
60
|
-
},
|
|
61
|
-
onError: {
|
|
62
|
-
target: 'end',
|
|
63
|
-
},
|
|
64
|
-
},
|
|
65
|
-
},
|
|
66
|
-
end: {},
|
|
67
|
-
},
|
|
68
|
-
},
|
|
69
|
-
pending: {
|
|
70
|
-
after: {
|
|
71
|
-
TIMEOUT: [
|
|
72
|
-
{ target: '#activity.fetchingList', cond: 'isNotInGame' },
|
|
73
|
-
{ target: '#activity.idle', cond: 'isInGame' },
|
|
74
|
-
],
|
|
75
|
-
},
|
|
76
|
-
on: {
|
|
77
|
-
SET_UNREAD: {
|
|
78
|
-
actions: 'setUnread',
|
|
79
|
-
},
|
|
80
|
-
RESET_ACTIVITIES: {
|
|
81
|
-
actions: 'resetActivities',
|
|
82
|
-
},
|
|
83
|
-
},
|
|
84
|
-
},
|
|
85
|
-
},
|
|
86
|
-
},
|
|
87
|
-
},
|
|
88
|
-
on: {
|
|
89
|
-
REFRESH: {
|
|
90
|
-
target: '#activity.fetchingList',
|
|
91
|
-
actions: 'leaveGame',
|
|
92
|
-
},
|
|
93
|
-
},
|
|
94
|
-
},
|
|
95
|
-
{
|
|
96
|
-
actions: {
|
|
97
|
-
setSiteConifg: assign((context, event) => {
|
|
98
|
-
return {
|
|
99
|
-
siteConfig: event.data,
|
|
100
|
-
}
|
|
101
|
-
}),
|
|
102
|
-
setTournamentList: assign((context, event) => {
|
|
103
|
-
const { activityList } = event.data
|
|
104
|
-
const tournamentList = activityList.filter((item) => item.tournament === 1)
|
|
105
|
-
return {
|
|
106
|
-
tournamentList,
|
|
107
|
-
}
|
|
108
|
-
}),
|
|
109
|
-
setActivityList: assign((context, event) => {
|
|
110
|
-
const noRedActivity = [2, 4, 13, 20, 90, 91, 92]
|
|
111
|
-
const { uidSite } = context
|
|
112
|
-
const { activityList } = event.data
|
|
113
|
-
let list = JSON.parse(JSON.stringify(activityList))
|
|
114
|
-
list.forEach((activity) => {
|
|
115
|
-
const storageUnread = localStorage.getItem(`unread_${activity.activityNo}_${uidSite}`)
|
|
116
|
-
if (noRedActivity.includes(activity.activityType)) {
|
|
117
|
-
activity.unread = false
|
|
118
|
-
} else if (storageUnread) {
|
|
119
|
-
activity.unread = JSON.parse(storageUnread)
|
|
120
|
-
} else {
|
|
121
|
-
activity.unread = true
|
|
122
|
-
}
|
|
123
|
-
})
|
|
124
|
-
return {
|
|
125
|
-
activityList: list,
|
|
126
|
-
}
|
|
127
|
-
}),
|
|
128
|
-
setPromotionList: assign((context, event) => {
|
|
129
|
-
const { promotionList } = event.data
|
|
130
|
-
return {
|
|
131
|
-
promotionList,
|
|
132
|
-
}
|
|
133
|
-
}),
|
|
134
|
-
setActivitiesDetailList: assign((context, event) => {
|
|
135
|
-
return {
|
|
136
|
-
activitiesDetailList: event.data.map((item) => item.data),
|
|
137
|
-
}
|
|
138
|
-
}),
|
|
139
|
-
setUnread: assign((context, event) => {
|
|
140
|
-
const { uidSite, activityNo, unread } = event.data
|
|
141
|
-
const list = JSON.parse(JSON.stringify(context.activityList))
|
|
142
|
-
localStorage.setItem(`unread_${activityNo}_${uidSite}`, `${unread}`)
|
|
143
|
-
list.map((item) => {
|
|
144
|
-
if (item.activityNo === activityNo) {
|
|
145
|
-
item.unread = JSON.parse(`${unread}`)
|
|
146
|
-
}
|
|
147
|
-
return item
|
|
148
|
-
})
|
|
149
|
-
return {
|
|
150
|
-
activityList: list,
|
|
151
|
-
uidSite,
|
|
152
|
-
}
|
|
153
|
-
}),
|
|
154
|
-
resetActivities: assign((context, event) => {
|
|
155
|
-
return {
|
|
156
|
-
isPlaying: true,
|
|
157
|
-
}
|
|
158
|
-
}),
|
|
159
|
-
leaveGame: assign((context, event) => {
|
|
160
|
-
return {
|
|
161
|
-
isPlaying: false,
|
|
162
|
-
}
|
|
163
|
-
}),
|
|
164
|
-
},
|
|
165
|
-
guards: {
|
|
166
|
-
hasSpecifyActivities: (context, event) => {
|
|
167
|
-
const { activityList = [], specifyActivities = [] } = context
|
|
168
|
-
const filterActivityList = activityList.filter((activity) => specifyActivities.includes(activity.activityType))
|
|
169
|
-
return filterActivityList.length > 0
|
|
170
|
-
},
|
|
171
|
-
isInGame: (context, event) => {
|
|
172
|
-
return context.isPlaying
|
|
173
|
-
},
|
|
174
|
-
isNotInGame: (context, event) => {
|
|
175
|
-
return !context.isPlaying
|
|
176
|
-
},
|
|
177
|
-
},
|
|
178
|
-
delays: {
|
|
179
|
-
TIMEOUT: (context, event) => {
|
|
180
|
-
const { tick } = context
|
|
181
|
-
return tick * 10
|
|
182
|
-
},
|
|
183
|
-
},
|
|
184
|
-
services: {
|
|
185
|
-
fetchList: async (context, event) => {
|
|
186
|
-
const hasToken = request.getToken()
|
|
187
|
-
const apiCallable = hasToken
|
|
188
|
-
const [{ data }, promotionList] = await Promise.all([
|
|
189
|
-
hasToken ? request.send(activity.getActivityList({ appSecret })) : request.send(activity.getAllActivityList({ appSecret })),
|
|
190
|
-
apiCallable && !context.isPlaying ? request.send(payment.getPromotionsList()) : [],
|
|
191
|
-
])
|
|
192
|
-
|
|
193
|
-
return { activityList: data, promotionList }
|
|
194
|
-
},
|
|
195
|
-
fetchActivitiesDetail: async (context, event) => {
|
|
196
|
-
await new Promise((resolve) => setTimeout(resolve, 1000)) // delay 1 second
|
|
197
|
-
|
|
198
|
-
const { activityList = [], specifyActivities = [] } = context
|
|
199
|
-
const filterActivityList = activityList.filter((activity) => specifyActivities.includes(activity.activityType))
|
|
200
|
-
const promiseArray = filterActivityList.map((item) => {
|
|
201
|
-
return request.send(activity.getActivityDetail({ activityNo: item.activityNo, appSecret }))
|
|
202
|
-
})
|
|
203
|
-
const activitiesDetail = await Promise.all(promiseArray)
|
|
204
|
-
return activitiesDetail
|
|
205
|
-
},
|
|
206
|
-
},
|
|
207
|
-
}
|
|
208
|
-
)
|
|
209
|
-
}
|