@jetthai/cuora 1.1.476 → 1.1.477-dev.1

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.
Files changed (86) hide show
  1. package/.claude/commands/sync-ai-prompts.md +88 -1
  2. package/.claude/settings.local.json +3 -1
  3. package/.github/copilot-instructions.md +68 -58
  4. package/.husky/post-checkout +3 -3
  5. package/.husky/pre-push +1 -1
  6. package/.prettierignore +2 -1
  7. package/AGENTS.md +69 -59
  8. package/AI_PROMPT_SOURCE.md +69 -59
  9. package/CHANGELOG.md +325 -5
  10. package/CLAUDE.md +69 -59
  11. package/GEMINI.md +69 -59
  12. package/README.md +11 -12
  13. package/package.json +1 -1
  14. package/scripts/auto-version.js +1 -0
  15. package/scripts/branch-auto-npm-publish.js +9 -2
  16. package/src/api/account.js +0 -1
  17. package/src/api/activity.js +0 -37
  18. package/src/api/auth.js +0 -31
  19. package/src/api/game.js +0 -10
  20. package/src/api/payment.js +1 -52
  21. package/src/api/user.js +0 -16
  22. package/src/index.js +2 -2
  23. package/src/machine/activity/activity_cash.js +1 -0
  24. package/src/machine/activity/diamond_shop_activity_cash.js +0 -1
  25. package/src/machine/activity/fafafa_activity.js +0 -10
  26. package/src/machine/activity/index.js +0 -12
  27. package/src/machine/auth.js +37 -59
  28. package/src/machine/auth_otp_v3.js +30 -19
  29. package/src/machine/common.js +0 -55
  30. package/src/machine/deposit/crypto_qrcode_cash.js +2 -2
  31. package/src/machine/deposit/index.js +0 -28
  32. package/src/machine/deposit/manual_cash.js +0 -8
  33. package/src/machine/game_info.js +1 -12
  34. package/src/machine/game_v2_1.js +1 -89
  35. package/src/machine/honor_board_cash.js +15 -18
  36. package/src/machine/inbox.js +0 -12
  37. package/src/machine/index.js +0 -32
  38. package/src/machine/reward_cash.js +0 -39
  39. package/src/machine/user_reset_password.js +0 -13
  40. package/src/machine/user_sign_up.js +3 -0
  41. package/src/machine/websocket.js +0 -4
  42. package/src/machine/withdraw/index.js +0 -6
  43. package/src/request/request.js +4 -29
  44. package/src/util/constant.js +0 -1
  45. package/src/util/index.js +1 -4
  46. package/test/auth_otp_v3.test.js +192 -0
  47. package/src/machine/activity/activity.js +0 -209
  48. package/src/machine/activity/diamond_shop_activity_fc.js +0 -196
  49. package/src/machine/activity/diamond_shop_activity_vn.js +0 -178
  50. package/src/machine/activity/invite_friends_activity.js +0 -114
  51. package/src/machine/activity/mini_game_activity.js +0 -68
  52. package/src/machine/activity/return_bonus_activity.js +0 -153
  53. package/src/machine/auth_otp_v2.js +0 -177
  54. package/src/machine/bank_binding_amb.js +0 -146
  55. package/src/machine/bonus.js +0 -76
  56. package/src/machine/deposit/amb.js +0 -93
  57. package/src/machine/deposit/crypto_bank.js +0 -330
  58. package/src/machine/deposit/crypto_qrcode.js +0 -148
  59. package/src/machine/deposit/crypto_way.js +0 -252
  60. package/src/machine/deposit/deposit_fc.js +0 -272
  61. package/src/machine/deposit/direct.js +0 -310
  62. package/src/machine/deposit/float.js +0 -375
  63. package/src/machine/deposit/krway.js +0 -151
  64. package/src/machine/deposit/loadcard_vn.js +0 -351
  65. package/src/machine/deposit/manual_vn.js +0 -458
  66. package/src/machine/deposit/qrcode_v2.js +0 -338
  67. package/src/machine/deposit/usdt.js +0 -144
  68. package/src/machine/deposit/virtual_bank_vn.js +0 -269
  69. package/src/machine/deposit/vpay.js +0 -368
  70. package/src/machine/game_hot_new.js +0 -79
  71. package/src/machine/game_replay.js +0 -46
  72. package/src/machine/game_search_v2.js +0 -401
  73. package/src/machine/honor_board.js +0 -132
  74. package/src/machine/merge.js +0 -57
  75. package/src/machine/payment_data.js +0 -86
  76. package/src/machine/promotions.js +0 -170
  77. package/src/machine/reward.js +0 -255
  78. package/src/machine/reward_fc.js +0 -98
  79. package/src/machine/side.js +0 -154
  80. package/src/machine/side_v2.js +0 -211
  81. package/src/machine/vip_table.js +0 -57
  82. package/src/machine/welcome.js +0 -110
  83. package/src/machine/withdraw/withdraw_crypto_cash.js +0 -327
  84. package/src/machine/withdraw/withdraw_krway.js +0 -223
  85. package/src/machine/withdraw/withdraw_manual.js +0 -536
  86. package/src/util/math.js +0 -4
@@ -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 {
@@ -107,6 +107,7 @@ export default function (request) {
107
107
  return {
108
108
  signUpData: {
109
109
  provider: 'local',
110
+ birthday,
110
111
  ...pickBindData(event.data),
111
112
  birthday,
112
113
  email,
@@ -130,6 +131,7 @@ export default function (request) {
130
131
  return {
131
132
  signUpData: {
132
133
  provider: 'phone',
134
+ birthday,
133
135
  ...pickBindData(event.data),
134
136
  birthday,
135
137
  email,
@@ -152,6 +154,7 @@ export default function (request) {
152
154
  return {
153
155
  signUpData: {
154
156
  provider: 'email',
157
+ birthday,
155
158
  ...pickBindData(event.data),
156
159
  birthday,
157
160
  email,
@@ -73,10 +73,6 @@ export default function (request) {
73
73
  },
74
74
  },
75
75
  on: {
76
- CONNECT: {
77
- target: 'fetchSocket',
78
- cond: 'isNeedConnect',
79
- },
80
76
  SET_CONNECTED: {
81
77
  actions: 'setSocket',
82
78
  },
@@ -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
  }
@@ -2,11 +2,13 @@ import pickBy from 'lodash/pickBy.js'
2
2
  import storage from '../util/storage.js'
3
3
  import { getErr998SentryExtra } from '../util/err998SentryExtra.js'
4
4
 
5
+ // 暫停 ERR_998 上報:在組裝 Sentry 資料之前就中止,不建立事件;仍照常 reject ERR_998 給呼叫端。恢復時改回 false 即可
6
+ const IS_ERR_998_REPORT_PAUSED = true
7
+
5
8
  // const pickBy = require('lodash/pickBy')
6
9
  const supportVersion2List = [
7
10
  // 04-09 Update
8
11
  'game/play',
9
- 'game/gameReplay',
10
12
  'game/logout',
11
13
  'game/list/v3/root',
12
14
  'game/list/v3/category',
@@ -18,8 +20,6 @@ const supportVersion2List = [
18
20
  'game/list/v3/removeMyFavorite',
19
21
  'login',
20
22
  'callback/:strategy',
21
- 'guestLogin',
22
- 'appLogin',
23
23
  'logout',
24
24
  'self',
25
25
  'register',
@@ -27,7 +27,6 @@ const supportVersion2List = [
27
27
  'verify',
28
28
  'reset',
29
29
  'acknowledge',
30
- 'recovery',
31
30
  'recovery/abandon',
32
31
  'recovery/acknowledge',
33
32
  'checkDt',
@@ -56,7 +55,6 @@ const supportVersion2List = [
56
55
  'account-binding/status',
57
56
  'account-binding/bind',
58
57
  'account-binding/acknowledge',
59
- 'account-binding/bind-third-party',
60
58
  'feeds',
61
59
  'broadcast',
62
60
  'upload',
@@ -75,28 +73,21 @@ const supportVersion2List = [
75
73
  'payment/v2/convertFreeCredit',
76
74
  'payment/v2/getBindingBankList',
77
75
  'payment/v2/getBindingPaymentList',
78
- 'payment/v2/getWithdrawBankList',
79
- 'payment/v2/getCurrentWithdrawRule',
80
76
  'payment/v2/withdrawCheck',
81
- 'payment/v2/history',
82
- 'payment/v2/mergeWallet',
83
77
  'payment/v2/paymentDetail',
84
78
  'payment/v2/category/options',
85
79
  'payment/v2/paymentInfo',
86
80
  'payment/v2/getBindingPaymentInfo',
87
81
  'payment/v2/pendingOrder',
88
82
  'payment/v2/promotions',
89
- 'payment/v2/spotmarket',
90
83
  'payment/v2/transactionHistory',
91
84
  'payment/v2/updateUtr',
92
- 'payment/v2/setting',
93
85
  'payment/v2/amb/setting',
94
86
  'payment/v2/updatePaymentInfo',
95
87
  'payment/v2/uploadSlip',
96
88
  'payment/v2/withdrawRule',
97
89
  'payment/v2/:paymentType/getBankList',
98
90
  'payment/v2/:paymentType/transaction',
99
- 'payment/v2/:paymentType/checkTransaction',
100
91
  'payment/v2/:paymentType/bonus/preview',
101
92
  'payment/v2/:paymentType/expected/result',
102
93
  'payment/v2/:paymentType/crypto/expected/result',
@@ -111,7 +102,6 @@ const supportVersion2List = [
111
102
  'activities',
112
103
  'activities/types',
113
104
  'activities/promo',
114
- 'activities/viptable',
115
105
  'activities/level-bonus/info',
116
106
  'activities/numbers',
117
107
  'activities/honorBroadcast',
@@ -133,7 +123,6 @@ const supportVersion2List = [
133
123
  'friends/dashboard',
134
124
  'friends/dashboard/list',
135
125
  'activities/ranking',
136
- 'activities/activity/ranking',
137
126
  'activities/cashRain',
138
127
  'activities/jackpot/list',
139
128
  // 09/09
@@ -147,7 +136,6 @@ const supportVersion2List = [
147
136
  'account-binding/status',
148
137
  'account-binding/bind',
149
138
  'account-binding/acknowledge',
150
- 'account-binding/bind-third-party',
151
139
  'account-binding/bind-password',
152
140
  'account-binding/reset-otp',
153
141
  // 11/10
@@ -165,7 +153,6 @@ function isValid(value) {
165
153
  export default class Request {
166
154
  constructor(axios, config) {
167
155
  this.axios = axios
168
- this.source = axios.CancelToken.source()
169
156
  this.config = config
170
157
  this.sentry = config.sentry
171
158
  this.key = `cuora_${config.clientId}`
@@ -224,7 +211,7 @@ export default class Request {
224
211
  const endpoint = error.config?.url || ''
225
212
  // 確實在線才以 warning 等級回報(連線不穩定多為使用者端網路問題,非應用程式錯誤)
226
213
  const isOnline = typeof navigator !== 'undefined' ? navigator.onLine : true
227
- if (isOnline) {
214
+ if (!IS_ERR_998_REPORT_PAUSED && isOnline) {
228
215
  const errData998 = getErr998SentryExtra(this, error.config)
229
216
  const sentryError = new Error(`ERR_998:${error.message}`)
230
217
  sentryError.name = 'ERR_998'
@@ -285,17 +272,6 @@ export default class Request {
285
272
  }
286
273
  }
287
274
 
288
- // 注意:send() 已不再預設附加 this.source.token(見 send 內註解),
289
- // sourceUpdate 僅對「呼叫端明確以 this.source.token 為 customToken」的請求有效;保留以維持 API 相容。
290
- sourceUpdate() {
291
- this.source.cancel('Requests Cancelled')
292
- this.source = this.axios.CancelToken.source()
293
- }
294
-
295
- sourceGenerate() {
296
- return this.axios.CancelToken.source()
297
- }
298
-
299
275
  _createConfig(req, cancelToken) {
300
276
  const { method, url, params, isPublic, isFormData, headers } = req
301
277
  let fullURL = this.config.fullURL
@@ -354,7 +330,6 @@ export default class Request {
354
330
  'activities/getFreeGameRewardList': 'activities/free-game/get-free-game-reward-list',
355
331
  'activities/lose-rebate/history': 'activities/rebate/lose-rebate/history',
356
332
  'activities/ranking': 'activities/ranking/promotion-ranking',
357
- 'activities/activity/ranking': 'activities/ranking/basic-ranking',
358
333
  'activities/cashRain': 'activities/cash-rain/exchange',
359
334
  'tournament/detail': 'activities/tournament/detail',
360
335
  'ranking/detail': 'activities/tournament/ranking/detail',
@@ -1,4 +1,3 @@
1
- export const MY_FAVORITE = 'MyFavorite'
2
1
  export const GAME_SEARCH = 'GameSearch'
3
2
  export const GAME_TYPE_LIST = [
4
3
  { typeId: 'SLOT', name: 'Slots', gameTypeMappingId: 1 },
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 default {}
8
- export { constant, storage, paramStore, max, isAmountInRange }
5
+ export { constant, storage, paramStore }
@@ -0,0 +1,192 @@
1
+ import test from 'node:test'
2
+ import assert from 'node:assert/strict'
3
+ import { interpret } from 'xstate'
4
+ import authOtpV3 from '../src/machine/auth_otp_v3.js'
5
+
6
+ function waitForState(service, matches) {
7
+ if (service.state.matches(matches)) return Promise.resolve(service.state)
8
+ return new Promise((resolve, reject) => {
9
+ const timeout = setTimeout(() => reject(new Error(`Timed out waiting for ${matches}`)), 1000)
10
+ service.onTransition((state) => {
11
+ if (!state.matches(matches)) return
12
+ clearTimeout(timeout)
13
+ resolve(state)
14
+ })
15
+ })
16
+ }
17
+
18
+ test('phone entry skips OTP only after /self confirms phone verification', async () => {
19
+ let selfReads = 0
20
+ const requests = []
21
+ const request = {
22
+ async send(descriptor) {
23
+ requests.push(descriptor.url)
24
+ if (descriptor.url === 'self') {
25
+ selfReads++
26
+ return {
27
+ phone: selfReads === 1 ? null : '123456789',
28
+ phone_verification_status: selfReads > 1,
29
+ email: null,
30
+ email_verification_status: false,
31
+ }
32
+ }
33
+ if (descriptor.url === 'otp-verification-point/verify') return { needAcknowledge: false }
34
+ throw new Error(`Unexpected request: ${descriptor.url}`)
35
+ },
36
+ }
37
+ const service = interpret(authOtpV3(request)).start()
38
+ try {
39
+ service.send({ type: 'SET_STRATEGY', data: 'phone' })
40
+ await waitForState(service, 'notVerified.phone')
41
+ service.send({ type: 'SEND_PHONE', data: { countryCode: '886', phone: '123456789' } })
42
+ await waitForState(service, 'verified')
43
+ assert.equal(selfReads, 2)
44
+ assert.deepEqual(requests, ['self', 'otp-verification-point/verify', 'self'])
45
+ } finally {
46
+ service.stop()
47
+ }
48
+ })
49
+
50
+ test('email entry skips OTP only after /self confirms email verification', async () => {
51
+ let selfReads = 0
52
+ const request = {
53
+ async send(descriptor) {
54
+ if (descriptor.url === 'self') {
55
+ selfReads++
56
+ return {
57
+ phone: null,
58
+ phone_verification_status: false,
59
+ email: selfReads === 1 ? null : 'test@example.com',
60
+ email_verification_status: selfReads > 1,
61
+ }
62
+ }
63
+ if (descriptor.url === 'otp-verification-point/verify') return { needAcknowledge: false }
64
+ throw new Error(`Unexpected request: ${descriptor.url}`)
65
+ },
66
+ }
67
+ const service = interpret(authOtpV3(request)).start()
68
+ try {
69
+ service.send({ type: 'SET_STRATEGY', data: 'email' })
70
+ await waitForState(service, 'notVerified.email')
71
+ service.send({ type: 'SEND_EMAIL', data: { email: 'test@example.com' } })
72
+ await waitForState(service, 'verified')
73
+ assert.equal(selfReads, 2)
74
+ } finally {
75
+ service.stop()
76
+ }
77
+ })
78
+
79
+ test('existing phone auto verification checks /self before finishing', async () => {
80
+ let selfReads = 0
81
+ const request = {
82
+ async send(descriptor) {
83
+ if (descriptor.url === 'self') {
84
+ selfReads++
85
+ return {
86
+ phone: '123456789',
87
+ phone_verification_status: selfReads > 1,
88
+ email: null,
89
+ email_verification_status: false,
90
+ }
91
+ }
92
+ if (descriptor.url === 'otp-verification-point/verify') return { needAcknowledge: false }
93
+ throw new Error(`Unexpected request: ${descriptor.url}`)
94
+ },
95
+ }
96
+ const service = interpret(authOtpV3(request)).start()
97
+ try {
98
+ service.send({ type: 'SET_STRATEGY', data: 'phone' })
99
+ await waitForState(service, 'verified')
100
+ assert.equal(selfReads, 2)
101
+ } finally {
102
+ service.stop()
103
+ }
104
+ })
105
+
106
+ test('needAcknowledge false never grants verification when /self is still unverified', async () => {
107
+ let verifyCalls = 0
108
+ const request = {
109
+ async send(descriptor) {
110
+ if (descriptor.url === 'self') {
111
+ return { phone: null, phone_verification_status: false, email: null, email_verification_status: false }
112
+ }
113
+ if (descriptor.url === 'otp-verification-point/verify') {
114
+ verifyCalls++
115
+ return { needAcknowledge: false }
116
+ }
117
+ throw new Error(`Unexpected request: ${descriptor.url}`)
118
+ },
119
+ }
120
+ const service = interpret(authOtpV3(request)).start()
121
+ try {
122
+ service.send({ type: 'SET_STRATEGY', data: 'phone' })
123
+ await waitForState(service, 'notVerified.phone')
124
+ service.send({ type: 'SEND_PHONE', data: { countryCode: '886', phone: '123456789' } })
125
+ await waitForState(service, 'fail')
126
+ assert.equal(verifyCalls, 1)
127
+ } finally {
128
+ service.stop()
129
+ }
130
+ })
131
+
132
+ test('needAcknowledge true keeps the existing OTP input route', async () => {
133
+ const request = {
134
+ async send(descriptor) {
135
+ if (descriptor.url === 'self') {
136
+ return { phone: null, phone_verification_status: false, email: null, email_verification_status: false }
137
+ }
138
+ if (descriptor.url === 'otp-verification-point/verify') {
139
+ return { needAcknowledge: true, request_id: 'test-request', ttl: 60000, countryCode: '886', phone: '123456789' }
140
+ }
141
+ throw new Error(`Unexpected request: ${descriptor.url}`)
142
+ },
143
+ }
144
+ const service = interpret(authOtpV3(request)).start()
145
+ try {
146
+ service.send({ type: 'SET_STRATEGY', data: 'phone' })
147
+ await waitForState(service, 'notVerified.phone')
148
+ service.send({ type: 'SEND_PHONE', data: { countryCode: '886', phone: '123456789' } })
149
+ await waitForState(service, 'notVerified.otp')
150
+ assert.equal(service.state.context.requestId, 'test-request')
151
+ } finally {
152
+ service.stop()
153
+ }
154
+ })
155
+
156
+ test('email without an address still requires input even if its verification flag is true', async () => {
157
+ const request = {
158
+ async send(descriptor) {
159
+ if (descriptor.url === 'self') {
160
+ return { phone: '123456789', phone_verification_status: true, email: null, email_verification_status: true }
161
+ }
162
+ throw new Error(`Unexpected request: ${descriptor.url}`)
163
+ },
164
+ }
165
+ const service = interpret(authOtpV3(request)).start()
166
+ try {
167
+ service.send({ type: 'SET_STRATEGY', data: 'email' })
168
+ await waitForState(service, 'notVerified.email')
169
+ assert.equal(service.state.matches('verified'), false)
170
+ } finally {
171
+ service.stop()
172
+ }
173
+ })
174
+
175
+ test('phone without a number still requires input even if its verification flag is true', async () => {
176
+ const request = {
177
+ async send(descriptor) {
178
+ if (descriptor.url === 'self') {
179
+ return { phone: null, phone_verification_status: true, email: 'test@example.com', email_verification_status: true }
180
+ }
181
+ throw new Error(`Unexpected request: ${descriptor.url}`)
182
+ },
183
+ }
184
+ const service = interpret(authOtpV3(request)).start()
185
+ try {
186
+ service.send({ type: 'SET_STRATEGY', data: 'phone' })
187
+ await waitForState(service, 'notVerified.phone')
188
+ assert.equal(service.state.matches('verified'), false)
189
+ } finally {
190
+ service.stop()
191
+ }
192
+ })
@@ -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
- }