@jetthai/cuora 1.1.488 → 1.2.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.
Files changed (128) hide show
  1. package/.husky/pre-commit +3 -1
  2. package/CHANGELOG.md +0 -349
  3. package/README.md +15 -299
  4. package/package.json +3 -6
  5. package/resetGitBranch.sh +101 -0
  6. package/src/api/activity.js +39 -24
  7. package/src/api/auth.js +35 -4
  8. package/src/api/common.js +1 -8
  9. package/src/api/game.js +10 -0
  10. package/src/api/index.js +1 -3
  11. package/src/api/payment.js +55 -17
  12. package/src/api/user.js +16 -11
  13. package/src/index.js +2 -2
  14. package/src/lib/fingerprint_v3_11_12.js +11433 -0
  15. package/src/machine/activity/activity.js +209 -0
  16. package/src/machine/activity/activity_cash.js +18 -71
  17. package/src/machine/activity/diamond_shop_activity_cash.js +1 -0
  18. package/src/machine/activity/diamond_shop_activity_fc.js +196 -0
  19. package/src/machine/activity/diamond_shop_activity_vn.js +178 -0
  20. package/src/machine/activity/fafafa_activity.js +10 -0
  21. package/src/machine/activity/index.js +12 -0
  22. package/src/machine/activity/invite_friends_activity.js +114 -0
  23. package/src/machine/activity/mini_game_activity.js +68 -0
  24. package/src/machine/activity/return_bonus_activity.js +153 -0
  25. package/src/machine/activity/roulette_activity_v2.js +0 -5
  26. package/src/machine/auth.js +109 -158
  27. package/src/machine/auth_otp_v2.js +177 -0
  28. package/src/machine/auth_otp_v3.js +32 -111
  29. package/src/machine/bank_binding.js +2 -2
  30. package/src/machine/bank_binding_amb.js +145 -0
  31. package/src/machine/bonus.js +75 -0
  32. package/src/machine/common.js +91 -27
  33. package/src/machine/deposit/amb.js +92 -0
  34. package/src/machine/deposit/crypto_bank.js +325 -0
  35. package/src/machine/deposit/crypto_bank_cash.js +8 -19
  36. package/src/machine/deposit/crypto_qrcode.js +148 -0
  37. package/src/machine/deposit/crypto_qrcode_cash.js +41 -26
  38. package/src/machine/deposit/crypto_way.js +247 -0
  39. package/src/machine/deposit/crypto_way_cash.js +32 -52
  40. package/src/machine/deposit/deposit_fc.js +271 -0
  41. package/src/machine/deposit/direct.js +310 -0
  42. package/src/machine/deposit/direct_cash.js +9 -8
  43. package/src/machine/deposit/float.js +374 -0
  44. package/src/machine/deposit/index.js +28 -0
  45. package/src/machine/deposit/krway.js +151 -0
  46. package/src/machine/deposit/loadcard_cash.js +31 -14
  47. package/src/machine/deposit/loadcard_vn.js +351 -0
  48. package/src/machine/deposit/manual_cash.js +10 -8
  49. package/src/machine/deposit/manual_vn.js +458 -0
  50. package/src/machine/deposit/qrcode_cash.js +30 -14
  51. package/src/machine/deposit/qrcode_v2.js +338 -0
  52. package/src/machine/deposit/usdt.js +144 -0
  53. package/src/machine/deposit/virtual_bank_cash.js +2 -5
  54. package/src/machine/deposit/virtual_bank_vn.js +269 -0
  55. package/src/machine/deposit/vpay.js +367 -0
  56. package/src/machine/error.js +0 -7
  57. package/src/machine/game_hot_new.js +79 -0
  58. package/src/machine/game_info.js +12 -5
  59. package/src/machine/game_replay.js +46 -0
  60. package/src/machine/game_search_v2.js +401 -0
  61. package/src/machine/game_v2_1.js +88 -43
  62. package/src/machine/honor_board.js +132 -0
  63. package/src/machine/honor_board_cash.js +18 -15
  64. package/src/machine/inbox.js +12 -0
  65. package/src/machine/index.js +32 -0
  66. package/src/machine/leaderboard.js +11 -8
  67. package/src/machine/merge.js +57 -0
  68. package/src/machine/payment_data.js +86 -0
  69. package/src/machine/promotions.js +170 -0
  70. package/src/machine/ranking.js +25 -43
  71. package/src/machine/reward.js +255 -0
  72. package/src/machine/reward_cash.js +41 -2
  73. package/src/machine/reward_fc.js +98 -0
  74. package/src/machine/roulette_v2.js +25 -20
  75. package/src/machine/side.js +154 -0
  76. package/src/machine/side_cash.js +2 -3
  77. package/src/machine/side_v2.js +209 -0
  78. package/src/machine/user_reset_password.js +15 -4
  79. package/src/machine/user_sign_up.js +60 -46
  80. package/src/machine/vip_table.js +57 -0
  81. package/src/machine/websocket.js +325 -378
  82. package/src/machine/welcome.js +110 -0
  83. package/src/machine/withdraw/index.js +6 -0
  84. package/src/machine/withdraw/withdraw_crypto_cash.js +327 -0
  85. package/src/machine/withdraw/withdraw_krway.js +222 -0
  86. package/src/machine/withdraw/withdraw_manual.js +533 -0
  87. package/src/machine/withdraw/withdraw_manual_cash.js +38 -59
  88. package/src/request/config.js +0 -2
  89. package/src/request/request.js +62 -130
  90. package/src/util/constant.js +2 -6
  91. package/src/util/deviceToken.js +59 -0
  92. package/src/util/index.js +4 -2
  93. package/src/util/math.js +4 -0
  94. package/.claude/commands/sync-ai-prompts.md +0 -93
  95. package/.claude/settings.local.json +0 -23
  96. package/.github/copilot-instructions.md +0 -448
  97. package/.husky/post-checkout +0 -32
  98. package/.husky/pre-push +0 -36
  99. package/AGENTS.md +0 -448
  100. package/AI_PROMPT_SOURCE.md +0 -446
  101. package/CLAUDE.md +0 -448
  102. package/GEMINI.md +0 -448
  103. package/docs/kibana/crypto-way-deposit-amount-bug-analysis.md +0 -1003
  104. package/docs/kibana/play-providerId-error.md +0 -202
  105. package/docs/kibana/play-selectedWalletType.md +0 -1
  106. package/docs/kibana/play-selectedWalletType_2.md +0 -1
  107. package/docs/kibana/play-selectedWalletType_analysis.md +0 -565
  108. package/docs/my-claude/feat-sharon-JT-1790247240-socket/branch-transfer.md +0 -14
  109. package/docs/my-claude/feat-sharon-JT-1790247240-socket/cash-module-preparation.json +0 -40
  110. package/docs/my-claude/feat-sharon-JT-1790247240-socket/cash-module-verification.md +0 -41
  111. package/docs/my-claude/feat-sharon-JT-1790247240-socket/implementation-ledger.md +0 -87
  112. package/docs/my-claude/feat-sharon-JT-1790247240-socket/module-report.md +0 -73
  113. package/docs/my-claude/feat-sharon-JT-1790247240-socket/plan.md +0 -309
  114. package/docs/my-claude/feat-sharon-JT-1790247240-socket/test-cases.md +0 -245
  115. package/docs/my-claude/feat-sharon-JT-1791180540-onesignal/transfer.md +0 -9
  116. package/scripts/auto-version.js +0 -68
  117. package/scripts/auto-version.sh +0 -33
  118. package/scripts/branch-auto-npm-publish.js +0 -29
  119. package/scripts/check-version.sh +0 -36
  120. package/scripts/clean-tags.sh +0 -84
  121. package/src/api/account.js +0 -7
  122. package/src/api/otp.js +0 -5
  123. package/src/util/amount.js +0 -8
  124. package/src/util/err998SentryExtra.js +0 -26
  125. package/src/util/paramStore.js +0 -139
  126. package/src/util/socketPolicy.js +0 -57
  127. package/test/auth_otp_v3.test.js +0 -323
  128. package/tests/websocket.test.mjs +0 -779
@@ -0,0 +1,86 @@
1
+ import { assign, createMachine } from 'xstate'
2
+ import payment from '../api/payment.js'
3
+
4
+ export default function (request) {
5
+ return createMachine(
6
+ {
7
+ id: 'payment_data',
8
+ initial: 'idle',
9
+ context: {
10
+ transactionList: [],
11
+ spotMarketTime: null,
12
+ spotMarketList: [],
13
+ },
14
+ states: {
15
+ idle: {},
16
+ fetchingTransactionList: {
17
+ invoke: {
18
+ src: 'fetchTransactionList',
19
+ onDone: {
20
+ target: 'idle',
21
+ actions: 'setTransactionList',
22
+ },
23
+ onError: {
24
+ target: 'idle',
25
+ },
26
+ },
27
+ },
28
+ fetchingSpotMarket: {
29
+ invoke: {
30
+ src: 'fetchSpotMarket',
31
+ onDone: {
32
+ target: 'idle',
33
+ actions: 'setSpotMarket',
34
+ },
35
+ onError: {
36
+ target: 'idle',
37
+ },
38
+ },
39
+ },
40
+ },
41
+ on: {
42
+ GET_TRANSACTION_LIST: {
43
+ target: 'fetchingTransactionList',
44
+ },
45
+ GET_SPOT_MARKET: {
46
+ target: 'fetchingSpotMarket',
47
+ },
48
+ },
49
+ },
50
+ {
51
+ actions: {
52
+ setTransactionList: assign((context, event) => {
53
+ const statusMap = {
54
+ 2: 'pending',
55
+ 3: 'success',
56
+ 4: 'reject',
57
+ 8: 'expired',
58
+ }
59
+ const transactionList = event.data.map((item) => {
60
+ item.statusName = statusMap[item.status]
61
+ return item
62
+ })
63
+ return {
64
+ transactionList,
65
+ }
66
+ }),
67
+ setSpotMarket: assign((context, event) => {
68
+ const { timestamp, data } = event.data
69
+ return {
70
+ spotMarketTime: timestamp,
71
+ spotMarketList: data.slice(0, 100),
72
+ }
73
+ }),
74
+ },
75
+ services: {
76
+ fetchTransactionList: async (context, event) => {
77
+ const returnDays = event.data
78
+ return await request.send(payment.getPaymentHistory(returnDays))
79
+ },
80
+ fetchSpotMarket: async (context, event) => {
81
+ return await request.send(payment.getSpotMarket())
82
+ },
83
+ },
84
+ }
85
+ )
86
+ }
@@ -0,0 +1,170 @@
1
+ import { assign, createMachine } from 'xstate'
2
+ import payment from '../api/payment.js'
3
+
4
+ export default function (request) {
5
+ return createMachine(
6
+ {
7
+ id: 'promotions',
8
+ initial: 'loading',
9
+ context: {
10
+ userInfo: {},
11
+ siteConfig: {},
12
+ withdrawRule: {},
13
+ promotionsList: [],
14
+ selectedPromo: {},
15
+ amount: null,
16
+ callback: () => {},
17
+ },
18
+ states: {
19
+ loading: {
20
+ invoke: {
21
+ src: 'fetchPromotionsList',
22
+ onDone: {
23
+ target: 'loaded',
24
+ actions: 'setPromotionsList',
25
+ },
26
+ onError: {
27
+ target: 'fail',
28
+ },
29
+ },
30
+ },
31
+ loaded: {
32
+ on: {
33
+ SELECT_PROMO: {
34
+ actions: ['reset', 'setSelectedPromo'],
35
+ },
36
+ SET_AMOUNT: {
37
+ actions: 'setAmount',
38
+ },
39
+ JOIN: {
40
+ target: 'fetching',
41
+ cond: 'isValidAmount',
42
+ },
43
+ },
44
+ },
45
+ fetching: {
46
+ invoke: {
47
+ src: 'fetchWithdrawRulePreview',
48
+ onDone: {
49
+ target: 'pending',
50
+ actions: 'setWithdrawRulePreview',
51
+ },
52
+ onError: {
53
+ target: 'loaded',
54
+ },
55
+ },
56
+ },
57
+ pending: {
58
+ on: {
59
+ CONFIRM: {
60
+ target: 'applying',
61
+ actions: 'setCallback',
62
+ },
63
+ BACK: {
64
+ target: 'loaded',
65
+ },
66
+ },
67
+ },
68
+ applying: {
69
+ invoke: {
70
+ src: 'applyPromotion',
71
+ onDone: {
72
+ target: 'applied',
73
+ },
74
+ onError: {
75
+ target: 'loaded',
76
+ },
77
+ },
78
+ },
79
+ applied: {
80
+ entry: 'doCallback',
81
+ },
82
+ fail: {},
83
+ },
84
+ },
85
+ {
86
+ actions: {
87
+ setPromotionsList: assign((context, event) => {
88
+ const promotionsList = JSON.parse(JSON.stringify(event.data))
89
+ const { userInfo, siteConfig } = context
90
+ const { withdraw_rule, balance, bank_amount } = userInfo
91
+ const { currencyConversionLimit } = siteConfig
92
+ const balanceAvailable = parseFloat(bank_amount) < parseFloat(`${currencyConversionLimit}`)
93
+ const isFreeLimitRule = withdraw_rule.includes('FREE_LIMIT')
94
+ const includesDefaultRule = withdraw_rule === 'DEFAULT' || withdraw_rule.includes('FREE_DEFAULT')
95
+
96
+ if (!balanceAvailable && includesDefaultRule) {
97
+ promotionsList.map((item) => {
98
+ item.attendEnable = !item.withdrawRule.includes('FREE_LIMIT')
99
+ return item
100
+ })
101
+ } else if (!balanceAvailable && isFreeLimitRule) {
102
+ promotionsList.map((item) => {
103
+ item.attendEnable = false
104
+ return item
105
+ })
106
+ } else {
107
+ promotionsList.map((item) => {
108
+ item.attendEnable = true
109
+ return item
110
+ })
111
+ }
112
+ return {
113
+ promotionsList,
114
+ selectedPromo: promotionsList[0],
115
+ }
116
+ }),
117
+ setSelectedPromo: assign((context, event) => {
118
+ return {
119
+ selectedPromo: event.data,
120
+ }
121
+ }),
122
+ setAmount: assign((context, event) => {
123
+ return {
124
+ amount: event.data,
125
+ }
126
+ }),
127
+ setWithdrawRulePreview: assign((context, event) => {
128
+ return {
129
+ withdrawRule: event.data,
130
+ }
131
+ }),
132
+ setCallback: assign((context, event) => {
133
+ return {
134
+ callback: event.data?.callback || (() => {}),
135
+ }
136
+ }),
137
+ doCallback: (context, event) => {
138
+ context.callback()
139
+ },
140
+ reset: assign((context, event) => {
141
+ return {
142
+ amount: null,
143
+ }
144
+ }),
145
+ },
146
+ guards: {
147
+ isValidAmount: (context, event) => {
148
+ const { selectedPromo, amount } = context
149
+ return selectedPromo.minimumAmount <= amount
150
+ },
151
+ },
152
+ services: {
153
+ fetchPromotionsList: async (context, event) => {
154
+ return await request.send(payment.getPromotionsList())
155
+ },
156
+ fetchWithdrawRulePreview: async (context, event) => {
157
+ const { selectedPromo, amount } = context
158
+ const data = await request.send(
159
+ payment.getWithdrawRulePreview({ applyType: 'promotions', applyNo: selectedPromo.promotionsNo, amount: parseFloat(amount) })
160
+ )
161
+ return data
162
+ },
163
+ applyPromotion: async (context, event) => {
164
+ const { selectedPromo, amount } = context
165
+ return await request.send(payment.applyPromotions({ promotionsNo: selectedPromo.promotionsNo, amount: parseFloat(amount) }))
166
+ },
167
+ },
168
+ }
169
+ )
170
+ }
@@ -1,28 +1,19 @@
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 {}
@@ -39,6 +30,7 @@ export default function (request) {
39
30
  site: '',
40
31
  activityNo: '',
41
32
  // api options 回傳的資料
33
+ currentRound: [],
42
34
  cycle: '',
43
35
  round: 0,
44
36
  rule: '',
@@ -50,7 +42,7 @@ export default function (request) {
50
42
  gameRanking: [],
51
43
  topRanking: [],
52
44
  settleStatus: false,
53
- // 前端這邊用的選單資料 { cycle: [string], round: { [cycle]: [{ round, beginDate, endDate }] } }
45
+ // 前端這邊用的選單資料 { cycle, round }
54
46
  options: {},
55
47
  },
56
48
  states: {
@@ -164,41 +156,31 @@ export default function (request) {
164
156
  setRankingOptions: assign((context, event) => {
165
157
  const isChampion = event.data?.rule === 'CHAMPION'
166
158
  const cycle = event.data?.cycle
167
- const periodOptions = event.data?.periodOptions || []
168
- // 每個 cycle 對應一筆「當前回合」
169
- const optionByCycle = periodOptions.reduce((acc, option) => {
170
- acc[option.cycle] = option
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
- }, {})
159
+ const currentRound = event.data?.currentRound || []
160
+ // 取得結算週期選單列表
161
+ const cycleOptions = isChampion ? cycleMapping.slice(0, currentRound.length) : [cycle]
162
+ const roundOptions = roundProcess(currentRound, cycleOptions)
180
163
  // 如果是冠軍龍虎月結算,則加入全部選項
181
164
  if (cycle === 'MONTHLY' && isChampion) {
182
165
  cycleOptions.push('ALL')
183
- roundOptions.ALL = expandPeriodOption(optionByCycle.MONTHLY, 'ALL')
166
+ roundOptions.ALL = roundOptions.MONTHLY
184
167
  }
185
- // 初始 cycle 與 round
186
- const initialCycle = isChampion ? 'DAILY' : cycle
187
- const initialRound = roundOptions[initialCycle]?.[0]?.round
188
168
  return {
189
169
  ...event.data,
190
170
  options: { cycle: cycleOptions, round: roundOptions },
191
- cycle: initialCycle,
192
- round: initialRound,
171
+ // 初始固定顯示 DAILY
172
+ cycle: isChampion ? 'DAILY' : cycle,
173
+ round: currentRound[0],
193
174
  }
194
175
  }),
195
176
  setOptions: assign((context, event) => {
196
- const { cycle, round, options } = context
177
+ const { cycle, round } = context
197
178
  // 處理變更 cycle,如果沒有輸入或沒有變更就不更新
198
179
  if (event.data?.cycle && cycle !== event.data?.cycle) {
199
- const newCycle = event.data?.cycle
200
- const newRound = options?.round?.[newCycle]?.[0]?.round
201
- return { cycle: newCycle, round: newRound }
180
+ const { currentRound } = context
181
+ const cycleForRound = event.data?.cycle === 'ALL' ? 'MONTHLY' : event.data?.cycle
182
+ const cycleIndex = cycleMapping.indexOf(cycleForRound)
183
+ return { cycle: event.data?.cycle, round: currentRound[cycleIndex] }
202
184
  }
203
185
  if (event.data?.round && round !== event.data?.round) {
204
186
  return { round: event.data?.round }
@@ -0,0 +1,255 @@
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
+ type: 'parallel',
11
+ context: {
12
+ otherRewardList: [],
13
+ pointsRewardList: [],
14
+ rewardList: [],
15
+ activityNo: null,
16
+ receiveNo: null,
17
+ withdrawRule: {},
18
+ rewardType: null,
19
+ isPlaying: false,
20
+ callback: () => {},
21
+ orderColumn: 'createTime',
22
+ lang: context?.locale,
23
+ },
24
+ states: {
25
+ timer: {
26
+ initial: 'loading',
27
+ states: {
28
+ loading: {
29
+ invoke: {
30
+ src: 'fetchRewardList',
31
+ onDone: {
32
+ target: 'pending',
33
+ actions: 'setRewardList',
34
+ },
35
+ onError: {
36
+ target: 'pending',
37
+ },
38
+ },
39
+ },
40
+ pending: {
41
+ after: {
42
+ 20000: [{ target: 'loading', cond: 'isNotInGame' }, { target: 'pending' }],
43
+ },
44
+ },
45
+ },
46
+ on: {
47
+ REFRESH: {
48
+ target: '.loading',
49
+ },
50
+ },
51
+ },
52
+ reward: {
53
+ initial: 'idle',
54
+ states: {
55
+ idle: {
56
+ on: {
57
+ FETCH_WITHDRAW_RULE: {
58
+ target: 'fetching',
59
+ actions: 'setRewardData',
60
+ },
61
+ FETCH_OTHER_REWARD: {
62
+ target: 'fetchingOtherReward',
63
+ actions: 'setOrderColumn',
64
+ },
65
+ RECEIVE_REWARD: {
66
+ target: 'receiving',
67
+ actions: ['setCallback', 'setRewardType'],
68
+ },
69
+ RECEIVE_ALL_POINTS: {
70
+ target: 'allPointsReceiving',
71
+ actions: 'setCallback',
72
+ },
73
+ SET_IS_PLAYING: {
74
+ actions: 'setIsPlaying',
75
+ },
76
+ SET_LANG: {
77
+ actions: 'setLang',
78
+ },
79
+ },
80
+ },
81
+ fetching: {
82
+ invoke: {
83
+ src: 'fetchWithdrawRulePreview',
84
+ onDone: {
85
+ target: 'pending',
86
+ actions: 'setWithdrawRulePreview',
87
+ },
88
+ onError: {
89
+ target: 'idle',
90
+ },
91
+ },
92
+ },
93
+ fetchingOtherReward: {
94
+ invoke: {
95
+ src: 'fetchOtherRewardList',
96
+ onDone: {
97
+ target: 'idle',
98
+ actions: 'setOtherRewardList',
99
+ },
100
+ onError: {
101
+ target: 'idle',
102
+ },
103
+ },
104
+ },
105
+ pending: {
106
+ on: {
107
+ RECEIVE_REWARD: {
108
+ target: 'receiving',
109
+ actions: 'setCallback',
110
+ },
111
+ BACK: {
112
+ target: 'idle',
113
+ },
114
+ },
115
+ },
116
+ receiving: {
117
+ invoke: {
118
+ src: 'receiveReward',
119
+ onDone: [
120
+ { target: 'received', cond: 'isPrize', actions: send({ type: 'REFRESH' }) },
121
+ { target: 'received', actions: [send({ type: 'REFRESH' }), 'doCallback'] },
122
+ ],
123
+ onError: {
124
+ target: 'idle',
125
+ },
126
+ },
127
+ },
128
+ received: {
129
+ after: {
130
+ 0: {
131
+ target: 'idle',
132
+ },
133
+ },
134
+ },
135
+ allPointsReceiving: {
136
+ invoke: {
137
+ src: 'receiveAllPoints',
138
+ onDone: {
139
+ target: 'idle',
140
+ actions: [send({ type: 'REFRESH' }), 'doCallback'],
141
+ },
142
+ onError: {
143
+ target: 'idle',
144
+ },
145
+ },
146
+ },
147
+ },
148
+ },
149
+ },
150
+ },
151
+ {
152
+ actions: {
153
+ setRewardList: assign((context, event) => {
154
+ return {
155
+ otherRewardList: event.data[0]?.data || [],
156
+ pointsRewardList: event.data[1]?.data || [],
157
+ rewardList: event.data[2]?.data || [],
158
+ }
159
+ }),
160
+ setOtherRewardList: assign((context, event) => {
161
+ return {
162
+ otherRewardList: event.data[0]?.data,
163
+ }
164
+ }),
165
+ setRewardData: assign((context, event) => {
166
+ const { activityNo, receiveNo } = event.data
167
+ return {
168
+ activityNo,
169
+ receiveNo,
170
+ }
171
+ }),
172
+ setCallback: assign((context, event) => {
173
+ return {
174
+ callback: event.data?.callback || (() => {}),
175
+ }
176
+ }),
177
+ setOrderColumn: assign((context, event) => {
178
+ return {
179
+ orderColumn: event.data?.orderColumn || 'createTime',
180
+ }
181
+ }),
182
+ setRewardType: assign((context, event) => {
183
+ return {
184
+ rewardType: event.data?.rewardType,
185
+ }
186
+ }),
187
+ doCallback: (context, event) => {
188
+ context.callback()
189
+ },
190
+ setWithdrawRulePreview: assign((context, event) => {
191
+ return {
192
+ withdrawRule: event.data,
193
+ }
194
+ }),
195
+ setIsPlaying: assign((context, event) => {
196
+ return {
197
+ isPlaying: event.data,
198
+ }
199
+ }),
200
+ setLang: assign((context, event) => {
201
+ const lang = event.data.locale || context.lang || 'en-US'
202
+ return { lang }
203
+ }),
204
+ },
205
+ guards: {
206
+ isPrize: (context, event) => {
207
+ const { rewardType } = context
208
+ return rewardType === 'PRIZE'
209
+ },
210
+ isNotInGame: (context, event) => {
211
+ return !context.isPlaying
212
+ },
213
+ },
214
+ services: {
215
+ fetchRewardList: async (context, event) => {
216
+ const lang = context.lang
217
+ const orderColumn = context.orderColumn
218
+ const getRewardAPI = request.send(activity.getRewardList({ count: 30, appSecret, lang }))
219
+ const getPointsRewardAPI = request.send(activity.getRewardList({ rewardType: 'POINTS', count: 30, appSecret, lang }))
220
+ const getOtherRewardAPI = request.send(activity.getRewardList({ rewardType: 'CASH,FREE,PRIZE', count: 30, appSecret, orderColumn, lang }))
221
+ const [otherRewardList, pointsRewardList, rewardList] = await Promise.all([getOtherRewardAPI, getPointsRewardAPI, getRewardAPI])
222
+ return [otherRewardList, pointsRewardList, rewardList]
223
+ },
224
+ fetchOtherRewardList: async (context, event) => {
225
+ const orderColumn = context.orderColumn
226
+ const lang = context.lang
227
+ const getOtherRewardAPI = request.send(
228
+ activity.getRewardList({
229
+ rewardType: 'CASH,FREE,PRIZE',
230
+ count: 30,
231
+ appSecret,
232
+ orderColumn,
233
+ lang,
234
+ })
235
+ )
236
+ const [otherRewardList] = await Promise.all([getOtherRewardAPI])
237
+ return [otherRewardList]
238
+ },
239
+ fetchWithdrawRulePreview: async (context, event) => {
240
+ const { receiveNo } = context
241
+ const data = await request.send(payment.getWithdrawRulePreview({ applyType: 'activity', applyNo: receiveNo, amount: null }))
242
+ return data
243
+ },
244
+ receiveReward: async (context, event) => {
245
+ const { activityNo, receiveNo, attended } = event.data
246
+ const validateReceiveNo = Number(receiveNo) > 0 ? Number(receiveNo) : undefined
247
+ return await request.send(activity.getReward({ activityNo, receiveNo: validateReceiveNo, appSecret, attended }))
248
+ },
249
+ receiveAllPoints: async (context, event) => {
250
+ return await request.send(activity.collect({ collectType: 'collectPoints', appSecret }))
251
+ },
252
+ },
253
+ }
254
+ )
255
+ }