@jetthai/cuora 1.1.488 → 2.0.0-beta.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/.husky/pre-commit +3 -1
- package/BREAKING_CHANGES.md +9 -0
- package/CHANGELOG.md +3 -316
- package/README.md +15 -299
- package/package.json +5 -5
- package/resetGitBranch.sh +101 -0
- package/src/api/account.js +1 -0
- package/src/api/activity.js +39 -24
- package/src/api/auth.js +36 -5
- package/src/api/common.js +3 -5
- package/src/api/game.js +10 -0
- package/src/api/payment.js +55 -17
- package/src/api/user.js +16 -10
- package/src/index.js +2 -2
- package/src/lib/fingerprint_v3_11_12.js +11433 -0
- package/src/machine/activity/activity.js +213 -0
- package/src/machine/activity/activity_cash.js +36 -84
- package/src/machine/activity/cash_rain_activity.js +1 -0
- package/src/machine/activity/continue_deposit_activity.js +1 -0
- package/src/machine/activity/deposit_activity.js +1 -0
- package/src/machine/activity/diamond_shop_activity_cash.js +8 -0
- package/src/machine/activity/diamond_shop_activity_fc.js +197 -0
- package/src/machine/activity/diamond_shop_activity_vn.js +179 -0
- package/src/machine/activity/fafafa_activity.js +11 -0
- package/src/machine/activity/friend_invite_friends_activity.js +7 -8
- package/src/machine/activity/index.js +12 -0
- package/src/machine/activity/instant_rebate_activity.js +1 -0
- package/src/machine/activity/invite_friends_activity.js +115 -0
- package/src/machine/activity/jackpot.js +1 -0
- package/src/machine/activity/mini_game_activity.js +69 -0
- package/src/machine/activity/otp_verified_activity.js +1 -0
- package/src/machine/activity/ranking_activity.js +1 -0
- package/src/machine/activity/return_bonus_activity.js +155 -0
- package/src/machine/activity/roulette_activity_v2.js +1 -0
- package/src/machine/activity/sign_in_activity.js +1 -0
- package/src/machine/activity/sign_in_monthly_activity.js +2 -1
- package/src/machine/activity/specify_bets_activity.js +1 -0
- package/src/machine/activity/specify_turnover_activity.js +1 -0
- package/src/machine/activity/time_bomb_activity.js +1 -0
- package/src/machine/activity/vip_card_activity.js +1 -0
- package/src/machine/auth.js +112 -149
- package/src/machine/auth_otp_v2.js +178 -0
- package/src/machine/auth_otp_v3.js +22 -64
- package/src/machine/bank_binding.js +3 -2
- package/src/machine/bank_binding_amb.js +146 -0
- package/src/machine/bonus.js +76 -0
- package/src/machine/common.js +98 -14
- package/src/machine/deposit/amb.js +93 -0
- package/src/machine/deposit/crypto_bank.js +340 -0
- package/src/machine/deposit/crypto_bank_cash.js +35 -20
- package/src/machine/deposit/crypto_qrcode.js +158 -0
- package/src/machine/deposit/crypto_qrcode_cash.js +64 -26
- package/src/machine/deposit/crypto_way.js +253 -0
- package/src/machine/deposit/crypto_way_cash.js +37 -48
- package/src/machine/deposit/deposit_fc.js +272 -0
- package/src/machine/deposit/direct.js +311 -0
- package/src/machine/deposit/direct_cash.js +10 -8
- package/src/machine/deposit/float.js +375 -0
- package/src/machine/deposit/index.js +28 -0
- package/src/machine/deposit/krway.js +152 -0
- package/src/machine/deposit/loadcard_cash.js +32 -14
- package/src/machine/deposit/loadcard_vn.js +352 -0
- package/src/machine/deposit/manual_cash.js +11 -8
- package/src/machine/deposit/manual_vn.js +459 -0
- package/src/machine/deposit/qrcode_cash.js +32 -15
- package/src/machine/deposit/qrcode_v2.js +339 -0
- package/src/machine/deposit/usdt.js +163 -0
- package/src/machine/deposit/usdt_cash.js +15 -1
- package/src/machine/deposit/virtual_bank_cash.js +12 -13
- package/src/machine/deposit/virtual_bank_vn.js +270 -0
- package/src/machine/deposit/vpay.js +374 -0
- package/src/machine/error.js +1 -7
- package/src/machine/game_betslip.js +1 -0
- package/src/machine/game_favorite_v2.js +1 -0
- package/src/machine/game_hot_new.js +80 -0
- package/src/machine/game_info.js +13 -1
- package/src/machine/game_replay.js +47 -0
- package/src/machine/game_search_cash.js +1 -0
- package/src/machine/game_search_v2.js +402 -0
- package/src/machine/game_v2_1.js +126 -39
- package/src/machine/honor_board.js +133 -0
- package/src/machine/honor_board_cash.js +28 -22
- package/src/machine/inbox.js +105 -43
- package/src/machine/index.js +32 -0
- package/src/machine/leaderboard.js +12 -8
- package/src/machine/merge.js +58 -0
- package/src/machine/navbar.js +3 -1
- package/src/machine/payment_data.js +87 -0
- package/src/machine/promotions.js +163 -0
- package/src/machine/ranking.js +30 -45
- package/src/machine/reward.js +256 -0
- package/src/machine/reward_cash.js +42 -2
- package/src/machine/reward_fc.js +99 -0
- package/src/machine/roulette_v2.js +11 -14
- package/src/machine/setting.js +1 -0
- package/src/machine/side.js +160 -0
- package/src/machine/side_cash.js +3 -3
- package/src/machine/side_v2.js +223 -0
- package/src/machine/user_info.js +1 -0
- package/src/machine/user_photo.js +1 -0
- package/src/machine/user_reset_password.js +14 -0
- package/src/machine/user_sign_up.js +61 -46
- package/src/machine/vip_table.js +58 -0
- package/src/machine/websocket.js +349 -374
- package/src/machine/welcome.js +111 -0
- package/src/machine/withdraw/index.js +6 -0
- package/src/machine/withdraw/withdraw_crypto_cash.js +328 -0
- package/src/machine/withdraw/withdraw_krway.js +223 -0
- package/src/machine/withdraw/withdraw_manual.js +541 -0
- package/src/machine/withdraw/withdraw_manual_cash.js +39 -59
- package/src/request/config.js +0 -2
- package/src/request/request.js +60 -124
- package/src/util/constant.js +2 -6
- package/src/util/deviceToken.js +60 -0
- package/src/util/index.js +4 -2
- package/src/util/math.js +4 -0
- package/src/util/storage.js +4 -3
- package/test/api.behavior.test.js +69 -0
- package/test/api.contract.test.js +18 -0
- package/test/config.test.js +27 -0
- package/test/deviceToken.test.js +139 -0
- package/test/helpers.coverage.test.js +11 -0
- package/test/helpers.js +91 -0
- package/test/index.exports.test.js +14 -0
- package/test/machine.activity.core.coverage.test.js +337 -0
- package/test/machine.activity.gap.coverage.test.js +252 -0
- package/test/machine.activity.more.coverage.test.js +180 -0
- package/test/machine.activity_plus_and_binding_amb.coverage.test.js +201 -0
- package/test/machine.activity_timer_bonus.coverage.test.js +136 -0
- package/test/machine.activity_welcome.low.coverage.test.js +211 -0
- package/test/machine.amb_rewardfc_websocket.more.coverage.test.js +201 -0
- package/test/machine.auth.coverage.test.js +215 -0
- package/test/machine.bank_binding.test.js +143 -0
- package/test/machine.binding_otp_krway.coverage.test.js +223 -0
- package/test/machine.contract.test.js +50 -0
- package/test/machine.crypto_bank.coverage.test.js +270 -0
- package/test/machine.crypto_way.coverage.test.js +108 -0
- package/test/machine.crypto_way_cash.coverage.test.js +114 -0
- package/test/machine.definition.test.js +137 -0
- package/test/machine.deposit.manual.coverage.test.js +365 -0
- package/test/machine.deposit_fc.coverage.test.js +126 -0
- package/test/machine.direct.coverage.test.js +96 -0
- package/test/machine.direct_cash.coverage.test.js +108 -0
- package/test/machine.error.coverage.test.js +37 -0
- package/test/machine.events.test.js +126 -0
- package/test/machine.favorite_jackpot.coverage.test.js +82 -0
- package/test/machine.float.coverage.test.js +136 -0
- package/test/machine.flow.test.js +226 -0
- package/test/machine.game_hot_new_vip_table.coverage.test.js +105 -0
- package/test/machine.game_search_cash.coverage.test.js +155 -0
- package/test/machine.game_search_v2.test.js +199 -0
- package/test/machine.game_user_profile.coverage.test.js +100 -0
- package/test/machine.honor_board.test.js +133 -0
- package/test/machine.inbox.common.coverage.test.js +304 -0
- package/test/machine.loadcard_cash.coverage.test.js +101 -0
- package/test/machine.loadcard_vn.coverage.test.js +122 -0
- package/test/machine.misc.coverage.test.js +361 -0
- package/test/machine.more2.coverage.test.js +261 -0
- package/test/machine.options.execution.test.js +272 -0
- package/test/machine.priority.coverage.test.js +603 -0
- package/test/machine.qrcode_cash.coverage.test.js +107 -0
- package/test/machine.qrcode_v2.coverage.test.js +121 -0
- package/test/machine.regression.test.js +82 -0
- package/test/machine.roulette_v2.test.js +142 -0
- package/test/machine.side_reward_reset.coverage.test.js +220 -0
- package/test/machine.targeted.coverage.test.js +313 -0
- package/test/machine.usdt.coverage.test.js +95 -0
- package/test/machine.usdt_cash.coverage.test.js +73 -0
- package/test/machine.vip_card_activity.test.js +114 -0
- package/test/machine.virtual_bank_cash.coverage.test.js +105 -0
- package/test/machine.virtual_bank_vn.coverage.test.js +105 -0
- package/test/machine.vpay.coverage.test.js +142 -0
- package/test/machine.withdraw_crypto_cash.coverage.test.js +166 -0
- package/test/machine.withdraw_krway.coverage.test.js +123 -0
- package/test/machine.withdraw_manual.coverage.test.js +185 -0
- package/test/machine.withdraw_manual_cash.coverage.test.js +123 -0
- package/test/request.test.js +325 -0
- package/test/util.storage.errors.test.js +47 -0
- package/test/util.test.js +41 -0
- package/.claude/commands/sync-ai-prompts.md +0 -93
- package/.claude/settings.local.json +0 -23
- package/.github/copilot-instructions.md +0 -448
- package/.husky/post-checkout +0 -32
- package/.husky/pre-push +0 -36
- package/AGENTS.md +0 -448
- package/AI_PROMPT_SOURCE.md +0 -446
- package/CLAUDE.md +0 -448
- package/GEMINI.md +0 -448
- package/docs/kibana/crypto-way-deposit-amount-bug-analysis.md +0 -1003
- package/docs/kibana/play-providerId-error.md +0 -202
- package/docs/kibana/play-selectedWalletType.md +0 -1
- package/docs/kibana/play-selectedWalletType_2.md +0 -1
- package/docs/kibana/play-selectedWalletType_analysis.md +0 -565
- package/docs/my-claude/feat-sharon-JT-1790247240-socket/branch-transfer.md +0 -14
- package/docs/my-claude/feat-sharon-JT-1790247240-socket/cash-module-preparation.json +0 -40
- package/docs/my-claude/feat-sharon-JT-1790247240-socket/cash-module-verification.md +0 -41
- package/docs/my-claude/feat-sharon-JT-1790247240-socket/implementation-ledger.md +0 -87
- package/docs/my-claude/feat-sharon-JT-1790247240-socket/module-report.md +0 -73
- package/docs/my-claude/feat-sharon-JT-1790247240-socket/plan.md +0 -309
- package/docs/my-claude/feat-sharon-JT-1790247240-socket/test-cases.md +0 -245
- package/docs/my-claude/feat-sharon-JT-1791180540-onesignal/transfer.md +0 -9
- package/scripts/auto-version.js +0 -68
- package/scripts/auto-version.sh +0 -33
- package/scripts/branch-auto-npm-publish.js +0 -29
- package/scripts/check-version.sh +0 -36
- package/scripts/clean-tags.sh +0 -84
- package/src/util/amount.js +0 -8
- package/src/util/err998SentryExtra.js +0 -26
- package/src/util/paramStore.js +0 -139
- package/src/util/socketPolicy.js +0 -57
- package/test/auth_otp_v3.test.js +0 -323
- package/tests/websocket.test.mjs +0 -779
package/src/machine/ranking.js
CHANGED
|
@@ -1,44 +1,39 @@
|
|
|
1
1
|
import { createMachine, assign } from 'xstate'
|
|
2
2
|
import ranking from '../api/ranking.js'
|
|
3
3
|
|
|
4
|
-
const ROUND_LIMIT = { DAILY: 56, WEEKLY: 8, MONTHLY: 2, ALL: 2 }
|
|
5
|
-
const ONE_DAY_MS = 24 * 60 * 60 * 1000
|
|
6
|
-
|
|
7
|
-
// 後端每個 cycle 只回傳「當前回合」一筆,前台依當前回合往前回填歷史回合
|
|
8
|
-
// 回合長度 = 當期長度(endDate - beginDate)+ 1 天,回合之間連續無間隔
|
|
9
|
-
function expandPeriodOption(option, cycle) {
|
|
10
|
-
if (!option) return []
|
|
11
|
-
const { round, beginDate, endDate } = option
|
|
12
|
-
// 回合長度取整到整數天,避免後端 endDate 帶當日 23:59:59 等時間造成歷史回合逐期偏移
|
|
13
|
-
const step = Math.floor((endDate - beginDate) / ONE_DAY_MS + 1) * ONE_DAY_MS
|
|
14
|
-
const count = Math.min(ROUND_LIMIT[cycle] || round, round)
|
|
15
|
-
// 降冪排列,當前回合在最前
|
|
16
|
-
return Array.from({ length: count }, (_, i) => ({
|
|
17
|
-
round: round - i,
|
|
18
|
-
beginDate: beginDate - i * step,
|
|
19
|
-
endDate: endDate - i * step,
|
|
20
|
-
}))
|
|
21
|
-
}
|
|
22
|
-
|
|
23
4
|
export default function (request) {
|
|
24
5
|
const { appSecret } = request.config
|
|
25
6
|
const cycleMapping = ['DAILY', 'WEEKLY', 'MONTHLY']
|
|
7
|
+
const limit = { DAILY: 56, WEEKLY: 8, MONTHLY: 2, ALL: 2 }
|
|
8
|
+
|
|
9
|
+
function roundProcess(rounds, cycles) {
|
|
10
|
+
const roundArrays = rounds.map((round) => Array.from({ length: round }, (_, i) => i + 1))
|
|
11
|
+
return roundArrays.reduce((acc, roundArray, index) => {
|
|
12
|
+
const max = limit[cycles[index]] || rounds[index] // 若沒限制則取全部
|
|
13
|
+
acc[cycles[index]] = roundArray.reverse().slice(0, max)
|
|
14
|
+
return acc
|
|
15
|
+
}, {})
|
|
16
|
+
}
|
|
26
17
|
|
|
27
18
|
function transGameData(item) {
|
|
28
19
|
if (!item) return {}
|
|
29
|
-
|
|
30
|
-
|
|
20
|
+
return {
|
|
21
|
+
...item,
|
|
22
|
+
providerId: item.provider,
|
|
23
|
+
}
|
|
31
24
|
}
|
|
32
25
|
|
|
33
26
|
return createMachine(
|
|
34
27
|
{
|
|
35
28
|
id: 'ranking',
|
|
29
|
+
predictableActionArguments: true,
|
|
36
30
|
initial: 'idle',
|
|
37
31
|
context: {
|
|
38
32
|
auth: false,
|
|
39
33
|
site: '',
|
|
40
34
|
activityNo: '',
|
|
41
35
|
// api options 回傳的資料
|
|
36
|
+
currentRound: [],
|
|
42
37
|
cycle: '',
|
|
43
38
|
round: 0,
|
|
44
39
|
rule: '',
|
|
@@ -50,7 +45,7 @@ export default function (request) {
|
|
|
50
45
|
gameRanking: [],
|
|
51
46
|
topRanking: [],
|
|
52
47
|
settleStatus: false,
|
|
53
|
-
// 前端這邊用的選單資料 { cycle
|
|
48
|
+
// 前端這邊用的選單資料 { cycle, round }
|
|
54
49
|
options: {},
|
|
55
50
|
},
|
|
56
51
|
states: {
|
|
@@ -164,41 +159,31 @@ export default function (request) {
|
|
|
164
159
|
setRankingOptions: assign((context, event) => {
|
|
165
160
|
const isChampion = event.data?.rule === 'CHAMPION'
|
|
166
161
|
const cycle = event.data?.cycle
|
|
167
|
-
const
|
|
168
|
-
//
|
|
169
|
-
const
|
|
170
|
-
|
|
171
|
-
return acc
|
|
172
|
-
}, {})
|
|
173
|
-
// 依照 cycleMapping 順序取出有資料的 cycle
|
|
174
|
-
const cycleOptions = isChampion ? cycleMapping.filter((c) => optionByCycle[c]) : [cycle]
|
|
175
|
-
// 將每個 cycle 的當前回合往前回填為完整回合列表 { [cycle]: [{ round, beginDate, endDate }] }
|
|
176
|
-
const roundOptions = cycleOptions.reduce((acc, c) => {
|
|
177
|
-
acc[c] = expandPeriodOption(optionByCycle[c], c)
|
|
178
|
-
return acc
|
|
179
|
-
}, {})
|
|
162
|
+
const currentRound = event.data?.currentRound || []
|
|
163
|
+
// 取得結算週期選單列表
|
|
164
|
+
const cycleOptions = isChampion ? cycleMapping.slice(0, currentRound.length) : [cycle]
|
|
165
|
+
const roundOptions = roundProcess(currentRound, cycleOptions)
|
|
180
166
|
// 如果是冠軍龍虎月結算,則加入全部選項
|
|
181
167
|
if (cycle === 'MONTHLY' && isChampion) {
|
|
182
168
|
cycleOptions.push('ALL')
|
|
183
|
-
roundOptions.ALL =
|
|
169
|
+
roundOptions.ALL = roundOptions.MONTHLY
|
|
184
170
|
}
|
|
185
|
-
// 初始 cycle 與 round
|
|
186
|
-
const initialCycle = isChampion ? 'DAILY' : cycle
|
|
187
|
-
const initialRound = roundOptions[initialCycle]?.[0]?.round
|
|
188
171
|
return {
|
|
189
172
|
...event.data,
|
|
190
173
|
options: { cycle: cycleOptions, round: roundOptions },
|
|
191
|
-
|
|
192
|
-
|
|
174
|
+
// 初始固定顯示 DAILY
|
|
175
|
+
cycle: isChampion ? 'DAILY' : cycle,
|
|
176
|
+
round: currentRound[0],
|
|
193
177
|
}
|
|
194
178
|
}),
|
|
195
179
|
setOptions: assign((context, event) => {
|
|
196
|
-
const { cycle, round
|
|
180
|
+
const { cycle, round } = context
|
|
197
181
|
// 處理變更 cycle,如果沒有輸入或沒有變更就不更新
|
|
198
182
|
if (event.data?.cycle && cycle !== event.data?.cycle) {
|
|
199
|
-
const
|
|
200
|
-
const
|
|
201
|
-
|
|
183
|
+
const { currentRound } = context
|
|
184
|
+
const cycleForRound = event.data?.cycle === 'ALL' ? 'MONTHLY' : event.data?.cycle
|
|
185
|
+
const cycleIndex = cycleMapping.indexOf(cycleForRound)
|
|
186
|
+
return { cycle: event.data?.cycle, round: currentRound[cycleIndex] }
|
|
202
187
|
}
|
|
203
188
|
if (event.data?.round && round !== event.data?.round) {
|
|
204
189
|
return { round: event.data?.round }
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
import { createMachine, assign, send } from 'xstate'
|
|
2
|
+
import activity from '../api/activity.js'
|
|
3
|
+
import payment from '../api/payment.js'
|
|
4
|
+
|
|
5
|
+
export default function (request, context) {
|
|
6
|
+
const { appSecret } = request.config
|
|
7
|
+
return createMachine(
|
|
8
|
+
{
|
|
9
|
+
id: 'reward',
|
|
10
|
+
predictableActionArguments: true,
|
|
11
|
+
type: 'parallel',
|
|
12
|
+
context: {
|
|
13
|
+
otherRewardList: [],
|
|
14
|
+
pointsRewardList: [],
|
|
15
|
+
rewardList: [],
|
|
16
|
+
activityNo: null,
|
|
17
|
+
receiveNo: null,
|
|
18
|
+
withdrawRule: {},
|
|
19
|
+
rewardType: null,
|
|
20
|
+
isPlaying: false,
|
|
21
|
+
callback: () => {},
|
|
22
|
+
orderColumn: 'createTime',
|
|
23
|
+
lang: context?.locale,
|
|
24
|
+
},
|
|
25
|
+
states: {
|
|
26
|
+
timer: {
|
|
27
|
+
initial: 'loading',
|
|
28
|
+
states: {
|
|
29
|
+
loading: {
|
|
30
|
+
invoke: {
|
|
31
|
+
src: 'fetchRewardList',
|
|
32
|
+
onDone: {
|
|
33
|
+
target: 'pending',
|
|
34
|
+
actions: 'setRewardList',
|
|
35
|
+
},
|
|
36
|
+
onError: {
|
|
37
|
+
target: 'pending',
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
pending: {
|
|
42
|
+
after: {
|
|
43
|
+
20000: [{ target: 'loading', cond: 'isNotInGame' }, { target: 'pending' }],
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
on: {
|
|
48
|
+
REFRESH: {
|
|
49
|
+
target: '.loading',
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
reward: {
|
|
54
|
+
initial: 'idle',
|
|
55
|
+
states: {
|
|
56
|
+
idle: {
|
|
57
|
+
on: {
|
|
58
|
+
FETCH_WITHDRAW_RULE: {
|
|
59
|
+
target: 'fetching',
|
|
60
|
+
actions: 'setRewardData',
|
|
61
|
+
},
|
|
62
|
+
FETCH_OTHER_REWARD: {
|
|
63
|
+
target: 'fetchingOtherReward',
|
|
64
|
+
actions: 'setOrderColumn',
|
|
65
|
+
},
|
|
66
|
+
RECEIVE_REWARD: {
|
|
67
|
+
target: 'receiving',
|
|
68
|
+
actions: ['setCallback', 'setRewardType'],
|
|
69
|
+
},
|
|
70
|
+
RECEIVE_ALL_POINTS: {
|
|
71
|
+
target: 'allPointsReceiving',
|
|
72
|
+
actions: 'setCallback',
|
|
73
|
+
},
|
|
74
|
+
SET_IS_PLAYING: {
|
|
75
|
+
actions: 'setIsPlaying',
|
|
76
|
+
},
|
|
77
|
+
SET_LANG: {
|
|
78
|
+
actions: 'setLang',
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
fetching: {
|
|
83
|
+
invoke: {
|
|
84
|
+
src: 'fetchWithdrawRulePreview',
|
|
85
|
+
onDone: {
|
|
86
|
+
target: 'pending',
|
|
87
|
+
actions: 'setWithdrawRulePreview',
|
|
88
|
+
},
|
|
89
|
+
onError: {
|
|
90
|
+
target: 'idle',
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
fetchingOtherReward: {
|
|
95
|
+
invoke: {
|
|
96
|
+
src: 'fetchOtherRewardList',
|
|
97
|
+
onDone: {
|
|
98
|
+
target: 'idle',
|
|
99
|
+
actions: 'setOtherRewardList',
|
|
100
|
+
},
|
|
101
|
+
onError: {
|
|
102
|
+
target: 'idle',
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
pending: {
|
|
107
|
+
on: {
|
|
108
|
+
RECEIVE_REWARD: {
|
|
109
|
+
target: 'receiving',
|
|
110
|
+
actions: 'setCallback',
|
|
111
|
+
},
|
|
112
|
+
BACK: {
|
|
113
|
+
target: 'idle',
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
receiving: {
|
|
118
|
+
invoke: {
|
|
119
|
+
src: 'receiveReward',
|
|
120
|
+
onDone: [
|
|
121
|
+
{ target: 'received', cond: 'isPrize', actions: send({ type: 'REFRESH' }) },
|
|
122
|
+
{ target: 'received', actions: [send({ type: 'REFRESH' }), 'doCallback'] },
|
|
123
|
+
],
|
|
124
|
+
onError: {
|
|
125
|
+
target: 'idle',
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
received: {
|
|
130
|
+
after: {
|
|
131
|
+
0: {
|
|
132
|
+
target: 'idle',
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
allPointsReceiving: {
|
|
137
|
+
invoke: {
|
|
138
|
+
src: 'receiveAllPoints',
|
|
139
|
+
onDone: {
|
|
140
|
+
target: 'idle',
|
|
141
|
+
actions: [send({ type: 'REFRESH' }), 'doCallback'],
|
|
142
|
+
},
|
|
143
|
+
onError: {
|
|
144
|
+
target: 'idle',
|
|
145
|
+
},
|
|
146
|
+
},
|
|
147
|
+
},
|
|
148
|
+
},
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
actions: {
|
|
154
|
+
setRewardList: assign((context, event) => {
|
|
155
|
+
return {
|
|
156
|
+
otherRewardList: event.data[0]?.data || [],
|
|
157
|
+
pointsRewardList: event.data[1]?.data || [],
|
|
158
|
+
rewardList: event.data[2]?.data || [],
|
|
159
|
+
}
|
|
160
|
+
}),
|
|
161
|
+
setOtherRewardList: assign((context, event) => {
|
|
162
|
+
return {
|
|
163
|
+
otherRewardList: event.data[0]?.data,
|
|
164
|
+
}
|
|
165
|
+
}),
|
|
166
|
+
setRewardData: assign((context, event) => {
|
|
167
|
+
const { activityNo, receiveNo } = event.data
|
|
168
|
+
return {
|
|
169
|
+
activityNo,
|
|
170
|
+
receiveNo,
|
|
171
|
+
}
|
|
172
|
+
}),
|
|
173
|
+
setCallback: assign((context, event) => {
|
|
174
|
+
return {
|
|
175
|
+
callback: event.data?.callback || (() => {}),
|
|
176
|
+
}
|
|
177
|
+
}),
|
|
178
|
+
setOrderColumn: assign((context, event) => {
|
|
179
|
+
return {
|
|
180
|
+
orderColumn: event.data?.orderColumn || 'createTime',
|
|
181
|
+
}
|
|
182
|
+
}),
|
|
183
|
+
setRewardType: assign((context, event) => {
|
|
184
|
+
return {
|
|
185
|
+
rewardType: event.data?.rewardType,
|
|
186
|
+
}
|
|
187
|
+
}),
|
|
188
|
+
doCallback: (context, event) => {
|
|
189
|
+
context.callback()
|
|
190
|
+
},
|
|
191
|
+
setWithdrawRulePreview: assign((context, event) => {
|
|
192
|
+
return {
|
|
193
|
+
withdrawRule: event.data,
|
|
194
|
+
}
|
|
195
|
+
}),
|
|
196
|
+
setIsPlaying: assign((context, event) => {
|
|
197
|
+
return {
|
|
198
|
+
isPlaying: event.data,
|
|
199
|
+
}
|
|
200
|
+
}),
|
|
201
|
+
setLang: assign((context, event) => {
|
|
202
|
+
const lang = event.data.locale || context.lang || 'en-US'
|
|
203
|
+
return { lang }
|
|
204
|
+
}),
|
|
205
|
+
},
|
|
206
|
+
guards: {
|
|
207
|
+
isPrize: (context, event) => {
|
|
208
|
+
const { rewardType } = context
|
|
209
|
+
return rewardType === 'PRIZE'
|
|
210
|
+
},
|
|
211
|
+
isNotInGame: (context, event) => {
|
|
212
|
+
return !context.isPlaying
|
|
213
|
+
},
|
|
214
|
+
},
|
|
215
|
+
services: {
|
|
216
|
+
fetchRewardList: async (context, event) => {
|
|
217
|
+
const lang = context.lang
|
|
218
|
+
const orderColumn = context.orderColumn
|
|
219
|
+
const getRewardAPI = request.send(activity.getRewardList({ count: 30, appSecret, lang }))
|
|
220
|
+
const getPointsRewardAPI = request.send(activity.getRewardList({ rewardType: 'POINTS', count: 30, appSecret, lang }))
|
|
221
|
+
const getOtherRewardAPI = request.send(activity.getRewardList({ rewardType: 'CASH,FREE,PRIZE', count: 30, appSecret, orderColumn, lang }))
|
|
222
|
+
const [otherRewardList, pointsRewardList, rewardList] = await Promise.all([getOtherRewardAPI, getPointsRewardAPI, getRewardAPI])
|
|
223
|
+
return [otherRewardList, pointsRewardList, rewardList]
|
|
224
|
+
},
|
|
225
|
+
fetchOtherRewardList: async (context, event) => {
|
|
226
|
+
const orderColumn = context.orderColumn
|
|
227
|
+
const lang = context.lang
|
|
228
|
+
const getOtherRewardAPI = request.send(
|
|
229
|
+
activity.getRewardList({
|
|
230
|
+
rewardType: 'CASH,FREE,PRIZE',
|
|
231
|
+
count: 30,
|
|
232
|
+
appSecret,
|
|
233
|
+
orderColumn,
|
|
234
|
+
lang,
|
|
235
|
+
})
|
|
236
|
+
)
|
|
237
|
+
const [otherRewardList] = await Promise.all([getOtherRewardAPI])
|
|
238
|
+
return [otherRewardList]
|
|
239
|
+
},
|
|
240
|
+
fetchWithdrawRulePreview: async (context, event) => {
|
|
241
|
+
const { receiveNo } = context
|
|
242
|
+
const data = await request.send(payment.getWithdrawRulePreview({ applyType: 'activity', applyNo: receiveNo, amount: null }))
|
|
243
|
+
return data
|
|
244
|
+
},
|
|
245
|
+
receiveReward: async (context, event) => {
|
|
246
|
+
const { activityNo, receiveNo, attended } = event.data
|
|
247
|
+
const validateReceiveNo = Number(receiveNo) > 0 ? Number(receiveNo) : undefined
|
|
248
|
+
return await request.send(activity.getReward({ activityNo, receiveNo: validateReceiveNo, appSecret, attended }))
|
|
249
|
+
},
|
|
250
|
+
receiveAllPoints: async (context, event) => {
|
|
251
|
+
return await request.send(activity.collect({ collectType: 'collectPoints', appSecret }))
|
|
252
|
+
},
|
|
253
|
+
},
|
|
254
|
+
}
|
|
255
|
+
)
|
|
256
|
+
}
|
|
@@ -7,6 +7,7 @@ export default function (request, context) {
|
|
|
7
7
|
return createMachine(
|
|
8
8
|
{
|
|
9
9
|
id: 'reward_cash',
|
|
10
|
+
predictableActionArguments: true,
|
|
10
11
|
type: 'parallel',
|
|
11
12
|
context: {
|
|
12
13
|
auth: false,
|
|
@@ -63,6 +64,10 @@ export default function (request, context) {
|
|
|
63
64
|
states: {
|
|
64
65
|
idle: {
|
|
65
66
|
on: {
|
|
67
|
+
FETCH_WITHDRAW_RULE: {
|
|
68
|
+
target: 'fetching',
|
|
69
|
+
actions: 'setRewardData',
|
|
70
|
+
},
|
|
66
71
|
FETCH_OTHER_REWARD: {
|
|
67
72
|
target: 'fetchingOtherReward',
|
|
68
73
|
actions: 'setOrderColumn',
|
|
@@ -80,6 +85,18 @@ export default function (request, context) {
|
|
|
80
85
|
},
|
|
81
86
|
},
|
|
82
87
|
},
|
|
88
|
+
fetching: {
|
|
89
|
+
invoke: {
|
|
90
|
+
src: 'fetchWithdrawRulePreview',
|
|
91
|
+
onDone: {
|
|
92
|
+
target: 'pending',
|
|
93
|
+
actions: 'setWithdrawRulePreview',
|
|
94
|
+
},
|
|
95
|
+
onError: {
|
|
96
|
+
target: 'idle',
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
},
|
|
83
100
|
fetchingOtherReward: {
|
|
84
101
|
invoke: {
|
|
85
102
|
src: 'fetchOtherRewardList',
|
|
@@ -164,6 +181,13 @@ export default function (request, context) {
|
|
|
164
181
|
otherRewardList: event.data[0]?.data,
|
|
165
182
|
}
|
|
166
183
|
}),
|
|
184
|
+
setRewardData: assign((context, event) => {
|
|
185
|
+
const { activityNo, receiveNo } = event.data
|
|
186
|
+
return {
|
|
187
|
+
activityNo,
|
|
188
|
+
receiveNo,
|
|
189
|
+
}
|
|
190
|
+
}),
|
|
167
191
|
setCallback: assign((context, event) => {
|
|
168
192
|
return {
|
|
169
193
|
callback: event.data?.callback || (() => {}),
|
|
@@ -177,6 +201,11 @@ export default function (request, context) {
|
|
|
177
201
|
doCallback: (context, event) => {
|
|
178
202
|
context.callback()
|
|
179
203
|
},
|
|
204
|
+
setWithdrawRulePreview: assign((context, event) => {
|
|
205
|
+
return {
|
|
206
|
+
withdrawRule: event.data,
|
|
207
|
+
}
|
|
208
|
+
}),
|
|
180
209
|
setLang: assign((context, event) => {
|
|
181
210
|
const lang = event.data.locale || context.lang || 'en-US'
|
|
182
211
|
return { lang }
|
|
@@ -197,7 +226,7 @@ export default function (request, context) {
|
|
|
197
226
|
)
|
|
198
227
|
const getOtherRewardAPI = request.send(
|
|
199
228
|
activity.getRewardList({
|
|
200
|
-
rewardType: 'CASH,FREE,PRIZE
|
|
229
|
+
rewardType: 'CASH,FREE,PRIZE',
|
|
201
230
|
count: 30,
|
|
202
231
|
appSecret,
|
|
203
232
|
orderColumn,
|
|
@@ -212,7 +241,7 @@ export default function (request, context) {
|
|
|
212
241
|
const lang = context.lang
|
|
213
242
|
const getOtherRewardAPI = request.send(
|
|
214
243
|
activity.getRewardList({
|
|
215
|
-
rewardType: 'CASH,FREE,PRIZE
|
|
244
|
+
rewardType: 'CASH,FREE,PRIZE',
|
|
216
245
|
count: 30,
|
|
217
246
|
appSecret,
|
|
218
247
|
orderColumn,
|
|
@@ -222,6 +251,17 @@ export default function (request, context) {
|
|
|
222
251
|
const [otherRewardList] = await Promise.all([getOtherRewardAPI])
|
|
223
252
|
return [otherRewardList]
|
|
224
253
|
},
|
|
254
|
+
fetchWithdrawRulePreview: async (context, event) => {
|
|
255
|
+
const { receiveNo } = context
|
|
256
|
+
const data = await request.send(
|
|
257
|
+
payment.getWithdrawRulePreview({
|
|
258
|
+
applyType: 'activity',
|
|
259
|
+
applyNo: receiveNo,
|
|
260
|
+
amount: null,
|
|
261
|
+
})
|
|
262
|
+
)
|
|
263
|
+
return data
|
|
264
|
+
},
|
|
225
265
|
receiveReward: async (context, event) => {
|
|
226
266
|
const { activityNo, receiveNo, attended } = event.data
|
|
227
267
|
// Number("")-> 0 / Number(" ") -> 0 需要收到實際的數字才傳給後端
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { createMachine, assign, send } from 'xstate'
|
|
2
|
+
import activity from '../api/activity.js'
|
|
3
|
+
|
|
4
|
+
export default function (request) {
|
|
5
|
+
const { appSecret } = request.config
|
|
6
|
+
return createMachine(
|
|
7
|
+
{
|
|
8
|
+
id: 'reward',
|
|
9
|
+
predictableActionArguments: true,
|
|
10
|
+
type: 'parallel',
|
|
11
|
+
context: {
|
|
12
|
+
rewardList: [],
|
|
13
|
+
callback: () => {},
|
|
14
|
+
},
|
|
15
|
+
states: {
|
|
16
|
+
timer: {
|
|
17
|
+
initial: 'loading',
|
|
18
|
+
states: {
|
|
19
|
+
loading: {
|
|
20
|
+
invoke: {
|
|
21
|
+
src: 'fetchRewardList',
|
|
22
|
+
onDone: {
|
|
23
|
+
target: 'pending',
|
|
24
|
+
actions: 'setRewardList',
|
|
25
|
+
},
|
|
26
|
+
onError: {
|
|
27
|
+
target: 'pending',
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
pending: {
|
|
32
|
+
after: {
|
|
33
|
+
20000: { target: 'loading' },
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
on: {
|
|
38
|
+
REFRESH: {
|
|
39
|
+
target: '.loading',
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
reward: {
|
|
44
|
+
initial: 'idle',
|
|
45
|
+
states: {
|
|
46
|
+
idle: {
|
|
47
|
+
on: {
|
|
48
|
+
RECEIVE_REWARD: {
|
|
49
|
+
target: 'receiving',
|
|
50
|
+
actions: 'setCallback',
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
receiving: {
|
|
55
|
+
invoke: {
|
|
56
|
+
src: 'receiveReward',
|
|
57
|
+
onDone: {
|
|
58
|
+
target: 'idle',
|
|
59
|
+
actions: [send({ type: 'REFRESH' }), 'doCallback'],
|
|
60
|
+
},
|
|
61
|
+
onError: {
|
|
62
|
+
target: 'idle',
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
actions: {
|
|
72
|
+
setRewardList: assign((context, event) => {
|
|
73
|
+
return {
|
|
74
|
+
rewardList: event.data || [],
|
|
75
|
+
}
|
|
76
|
+
}),
|
|
77
|
+
setCallback: assign((context, event) => {
|
|
78
|
+
return {
|
|
79
|
+
callback: event.data?.callback || (() => {}),
|
|
80
|
+
}
|
|
81
|
+
}),
|
|
82
|
+
doCallback: (context, event) => {
|
|
83
|
+
context.callback()
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
services: {
|
|
87
|
+
fetchRewardList: async (context, event) => {
|
|
88
|
+
const { data } = await request.send(activity.getRewardList({ count: 30, appSecret }))
|
|
89
|
+
return data
|
|
90
|
+
},
|
|
91
|
+
receiveReward: async (context, event) => {
|
|
92
|
+
const { activityNo, receiveNo, attended } = event.data
|
|
93
|
+
const validateReceiveNo = Number(receiveNo) > 0 ? Number(receiveNo) : undefined
|
|
94
|
+
return await request.send(activity.getReward({ activityNo, receiveNo: validateReceiveNo, appSecret, attended }))
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
}
|
|
98
|
+
)
|
|
99
|
+
}
|
|
@@ -6,6 +6,7 @@ export default function (request) {
|
|
|
6
6
|
return createMachine(
|
|
7
7
|
{
|
|
8
8
|
id: 'roulette_v2',
|
|
9
|
+
predictableActionArguments: true,
|
|
9
10
|
context: {
|
|
10
11
|
tick: 2000,
|
|
11
12
|
activityNo: null,
|
|
@@ -24,7 +25,6 @@ export default function (request) {
|
|
|
24
25
|
spinResult: {},
|
|
25
26
|
rouletteV2ExchangeAward: [],
|
|
26
27
|
calculatedNewSpinRewards: [],
|
|
27
|
-
isSpinOutOfStock: false,
|
|
28
28
|
awardedCashAmount: 0,
|
|
29
29
|
awardedFreeAmount: 0,
|
|
30
30
|
awardedPointsAmount: 0,
|
|
@@ -209,27 +209,24 @@ export default function (request) {
|
|
|
209
209
|
}
|
|
210
210
|
}),
|
|
211
211
|
setSpinResult: assign((context, event) => {
|
|
212
|
-
const { unCollectRewards = [], newSpinRewards = [], spinLeft = 0 } =
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
const existing = arr.find((item) => item.rewardType === spin.rewardType && item.reward === spin.reward)
|
|
212
|
+
const { unCollectRewards = [], newSpinRewards = [], spinLeft = 0 } = event.data || {}
|
|
213
|
+
const rewardCountMap = new Map()
|
|
214
|
+
for (let i = 0; i < newSpinRewards.length; i++) {
|
|
215
|
+
const spin = newSpinRewards[i]
|
|
216
|
+
const key = `${spin.rewardType}:${spin.reward}`
|
|
217
|
+
const existing = rewardCountMap.get(key)
|
|
219
218
|
if (existing) {
|
|
220
|
-
existing.count
|
|
219
|
+
existing.count += 1
|
|
221
220
|
} else {
|
|
222
|
-
|
|
221
|
+
rewardCountMap.set(key, { ...spin, count: 1 })
|
|
223
222
|
}
|
|
224
|
-
|
|
225
|
-
|
|
223
|
+
}
|
|
224
|
+
const calculatedNewSpinRewards = [...rewardCountMap.values()]
|
|
226
225
|
|
|
227
226
|
return {
|
|
228
227
|
spinResult: event.data,
|
|
229
228
|
unCollectRewards,
|
|
230
229
|
calculatedNewSpinRewards,
|
|
231
|
-
// 本次抽獎含缺貨項目(單次 Spin 缺貨或 Spin All 部分/全部缺貨),前台以此決定是否改顯示通用缺貨提示
|
|
232
|
-
isSpinOutOfStock: newSpinRewards.some(isOutOfStock),
|
|
233
230
|
spinLeft,
|
|
234
231
|
}
|
|
235
232
|
}),
|