@jetthai/cuora 2.0.0-beta.1 → 2.0.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 (201) hide show
  1. package/.claude/commands/sync-ai-prompts.md +93 -0
  2. package/.claude/settings.local.json +23 -0
  3. package/.github/copilot-instructions.md +405 -0
  4. package/.husky/post-checkout +32 -0
  5. package/.husky/pre-commit +1 -3
  6. package/.husky/pre-push +36 -0
  7. package/AGENTS.md +405 -0
  8. package/AI_PROMPT_SOURCE.md +403 -0
  9. package/CHANGELOG.md +274 -3
  10. package/CLAUDE.md +405 -0
  11. package/GEMINI.md +405 -0
  12. package/README.md +299 -15
  13. package/docs/kibana/crypto-way-deposit-amount-bug-analysis.md +1003 -0
  14. package/docs/kibana/play-providerId-error.md +202 -0
  15. package/docs/kibana/play-selectedWalletType.md +1 -0
  16. package/docs/kibana/play-selectedWalletType_2.md +1 -0
  17. package/docs/kibana/play-selectedWalletType_analysis.md +565 -0
  18. package/package.json +3 -3
  19. package/scripts/auto-version.js +68 -0
  20. package/scripts/auto-version.sh +33 -0
  21. package/scripts/branch-auto-npm-publish.js +29 -0
  22. package/scripts/check-version.sh +36 -0
  23. package/scripts/clean-tags.sh +84 -0
  24. package/src/api/account.js +0 -1
  25. package/src/api/activity.js +22 -37
  26. package/src/api/auth.js +5 -36
  27. package/src/api/common.js +5 -3
  28. package/src/api/game.js +0 -10
  29. package/src/api/payment.js +17 -55
  30. package/src/api/user.js +10 -16
  31. package/src/index.js +2 -2
  32. package/src/machine/activity/activity_cash.js +84 -36
  33. package/src/machine/activity/cash_rain_activity.js +0 -1
  34. package/src/machine/activity/continue_deposit_activity.js +0 -1
  35. package/src/machine/activity/deposit_activity.js +0 -1
  36. package/src/machine/activity/diamond_shop_activity_cash.js +0 -8
  37. package/src/machine/activity/fafafa_activity.js +0 -11
  38. package/src/machine/activity/friend_invite_friends_activity.js +8 -7
  39. package/src/machine/activity/index.js +0 -12
  40. package/src/machine/activity/instant_rebate_activity.js +0 -1
  41. package/src/machine/activity/jackpot.js +0 -1
  42. package/src/machine/activity/otp_verified_activity.js +0 -1
  43. package/src/machine/activity/ranking_activity.js +0 -1
  44. package/src/machine/activity/roulette_activity_v2.js +0 -1
  45. package/src/machine/activity/sign_in_activity.js +0 -1
  46. package/src/machine/activity/sign_in_monthly_activity.js +1 -2
  47. package/src/machine/activity/specify_bets_activity.js +0 -1
  48. package/src/machine/activity/specify_turnover_activity.js +0 -1
  49. package/src/machine/activity/time_bomb_activity.js +0 -1
  50. package/src/machine/activity/vip_card_activity.js +0 -1
  51. package/src/machine/auth.js +112 -113
  52. package/src/machine/auth_otp_v3.js +11 -8
  53. package/src/machine/bank_binding.js +2 -3
  54. package/src/machine/common.js +14 -112
  55. package/src/machine/deposit/crypto_bank_cash.js +20 -35
  56. package/src/machine/deposit/crypto_qrcode_cash.js +26 -64
  57. package/src/machine/deposit/crypto_way_cash.js +48 -37
  58. package/src/machine/deposit/direct_cash.js +8 -10
  59. package/src/machine/deposit/index.js +0 -28
  60. package/src/machine/deposit/loadcard_cash.js +14 -32
  61. package/src/machine/deposit/manual_cash.js +18 -28
  62. package/src/machine/deposit/qrcode_cash.js +15 -32
  63. package/src/machine/deposit/usdt_cash.js +1 -15
  64. package/src/machine/deposit/virtual_bank_cash.js +13 -12
  65. package/src/machine/error.js +7 -1
  66. package/src/machine/game_betslip.js +0 -1
  67. package/src/machine/game_favorite_v2.js +0 -1
  68. package/src/machine/game_info.js +1 -13
  69. package/src/machine/game_search_cash.js +2 -13
  70. package/src/machine/game_v2_1.js +42 -166
  71. package/src/machine/honor_board_cash.js +8 -11
  72. package/src/machine/inbox.js +43 -105
  73. package/src/machine/index.js +0 -32
  74. package/src/machine/leaderboard.js +8 -12
  75. package/src/machine/navbar.js +1 -3
  76. package/src/machine/ranking.js +45 -30
  77. package/src/machine/reward_cash.js +0 -40
  78. package/src/machine/roulette_v2.js +14 -11
  79. package/src/machine/setting.js +0 -1
  80. package/src/machine/side_cash.js +3 -3
  81. package/src/machine/user_info.js +0 -1
  82. package/src/machine/user_photo.js +0 -1
  83. package/src/machine/user_reset_password.js +0 -14
  84. package/src/machine/user_sign_up.js +46 -61
  85. package/src/machine/websocket.js +18 -62
  86. package/src/machine/withdraw/index.js +0 -6
  87. package/src/machine/withdraw/withdraw_manual_cash.js +59 -39
  88. package/src/request/config.js +2 -0
  89. package/src/request/request.js +49 -60
  90. package/src/util/amount.js +8 -0
  91. package/src/util/constant.js +0 -1
  92. package/src/util/err998SentryExtra.js +26 -0
  93. package/src/util/index.js +2 -4
  94. package/src/util/paramStore.js +139 -0
  95. package/src/util/storage.js +3 -4
  96. package/BREAKING_CHANGES.md +0 -9
  97. package/resetGitBranch.sh +0 -101
  98. package/src/lib/fingerprint_v3_11_12.js +0 -11433
  99. package/src/machine/activity/activity.js +0 -213
  100. package/src/machine/activity/diamond_shop_activity_fc.js +0 -197
  101. package/src/machine/activity/diamond_shop_activity_vn.js +0 -179
  102. package/src/machine/activity/invite_friends_activity.js +0 -115
  103. package/src/machine/activity/mini_game_activity.js +0 -69
  104. package/src/machine/activity/return_bonus_activity.js +0 -155
  105. package/src/machine/auth_otp_v2.js +0 -178
  106. package/src/machine/bank_binding_amb.js +0 -146
  107. package/src/machine/bonus.js +0 -76
  108. package/src/machine/deposit/amb.js +0 -93
  109. package/src/machine/deposit/crypto_bank.js +0 -340
  110. package/src/machine/deposit/crypto_qrcode.js +0 -158
  111. package/src/machine/deposit/crypto_way.js +0 -253
  112. package/src/machine/deposit/deposit_fc.js +0 -272
  113. package/src/machine/deposit/direct.js +0 -311
  114. package/src/machine/deposit/float.js +0 -375
  115. package/src/machine/deposit/krway.js +0 -152
  116. package/src/machine/deposit/loadcard_vn.js +0 -352
  117. package/src/machine/deposit/manual_vn.js +0 -463
  118. package/src/machine/deposit/qrcode_v2.js +0 -339
  119. package/src/machine/deposit/usdt.js +0 -163
  120. package/src/machine/deposit/virtual_bank_vn.js +0 -270
  121. package/src/machine/deposit/vpay.js +0 -374
  122. package/src/machine/game_hot_new.js +0 -91
  123. package/src/machine/game_replay.js +0 -47
  124. package/src/machine/game_search_v2.js +0 -402
  125. package/src/machine/honor_board.js +0 -144
  126. package/src/machine/merge.js +0 -58
  127. package/src/machine/payment_data.js +0 -87
  128. package/src/machine/promotions.js +0 -163
  129. package/src/machine/reward.js +0 -256
  130. package/src/machine/reward_fc.js +0 -99
  131. package/src/machine/side.js +0 -160
  132. package/src/machine/side_v2.js +0 -223
  133. package/src/machine/vip_table.js +0 -58
  134. package/src/machine/welcome.js +0 -111
  135. package/src/machine/withdraw/withdraw_crypto_cash.js +0 -328
  136. package/src/machine/withdraw/withdraw_krway.js +0 -223
  137. package/src/machine/withdraw/withdraw_manual.js +0 -541
  138. package/src/util/deviceToken.js +0 -60
  139. package/src/util/math.js +0 -4
  140. package/test/api.behavior.test.js +0 -69
  141. package/test/api.contract.test.js +0 -18
  142. package/test/config.test.js +0 -27
  143. package/test/deviceToken.test.js +0 -139
  144. package/test/helpers.coverage.test.js +0 -11
  145. package/test/helpers.js +0 -91
  146. package/test/index.exports.test.js +0 -14
  147. package/test/machine.activity.core.coverage.test.js +0 -337
  148. package/test/machine.activity.gap.coverage.test.js +0 -252
  149. package/test/machine.activity.more.coverage.test.js +0 -180
  150. package/test/machine.activity_plus_and_binding_amb.coverage.test.js +0 -201
  151. package/test/machine.activity_timer_bonus.coverage.test.js +0 -136
  152. package/test/machine.activity_welcome.low.coverage.test.js +0 -211
  153. package/test/machine.amb_rewardfc_websocket.more.coverage.test.js +0 -201
  154. package/test/machine.auth.coverage.test.js +0 -215
  155. package/test/machine.bank_binding.test.js +0 -143
  156. package/test/machine.binding_otp_krway.coverage.test.js +0 -223
  157. package/test/machine.contract.test.js +0 -50
  158. package/test/machine.crypto_bank.coverage.test.js +0 -270
  159. package/test/machine.crypto_way.coverage.test.js +0 -108
  160. package/test/machine.crypto_way_cash.coverage.test.js +0 -114
  161. package/test/machine.definition.test.js +0 -137
  162. package/test/machine.deposit.manual.coverage.test.js +0 -365
  163. package/test/machine.deposit_fc.coverage.test.js +0 -126
  164. package/test/machine.direct.coverage.test.js +0 -96
  165. package/test/machine.direct_cash.coverage.test.js +0 -108
  166. package/test/machine.error.coverage.test.js +0 -37
  167. package/test/machine.events.test.js +0 -126
  168. package/test/machine.favorite_jackpot.coverage.test.js +0 -82
  169. package/test/machine.float.coverage.test.js +0 -136
  170. package/test/machine.flow.test.js +0 -226
  171. package/test/machine.game_hot_new_vip_table.coverage.test.js +0 -105
  172. package/test/machine.game_search_cash.coverage.test.js +0 -195
  173. package/test/machine.game_search_v2.test.js +0 -199
  174. package/test/machine.game_user_profile.coverage.test.js +0 -100
  175. package/test/machine.honor_board.test.js +0 -148
  176. package/test/machine.inbox.common.coverage.test.js +0 -304
  177. package/test/machine.loadcard_cash.coverage.test.js +0 -101
  178. package/test/machine.loadcard_vn.coverage.test.js +0 -122
  179. package/test/machine.misc.coverage.test.js +0 -361
  180. package/test/machine.more2.coverage.test.js +0 -261
  181. package/test/machine.options.execution.test.js +0 -272
  182. package/test/machine.priority.coverage.test.js +0 -629
  183. package/test/machine.qrcode_cash.coverage.test.js +0 -107
  184. package/test/machine.qrcode_v2.coverage.test.js +0 -121
  185. package/test/machine.regression.test.js +0 -82
  186. package/test/machine.roulette_v2.test.js +0 -142
  187. package/test/machine.side_reward_reset.coverage.test.js +0 -220
  188. package/test/machine.targeted.coverage.test.js +0 -313
  189. package/test/machine.usdt.coverage.test.js +0 -95
  190. package/test/machine.usdt_cash.coverage.test.js +0 -73
  191. package/test/machine.vip_card_activity.test.js +0 -114
  192. package/test/machine.virtual_bank_cash.coverage.test.js +0 -105
  193. package/test/machine.virtual_bank_vn.coverage.test.js +0 -105
  194. package/test/machine.vpay.coverage.test.js +0 -142
  195. package/test/machine.withdraw_crypto_cash.coverage.test.js +0 -166
  196. package/test/machine.withdraw_krway.coverage.test.js +0 -123
  197. package/test/machine.withdraw_manual.coverage.test.js +0 -185
  198. package/test/machine.withdraw_manual_cash.coverage.test.js +0 -123
  199. package/test/request.test.js +0 -325
  200. package/test/util.storage.errors.test.js +0 -47
  201. package/test/util.test.js +0 -41
@@ -1,213 +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
- predictableActionArguments: true,
11
- initial: 'init',
12
- context: {
13
- tick: 2000,
14
- specifyActivities: [4, 29, 34],
15
- activitiesDetailList: [],
16
- activityList: [],
17
- promotionList: [],
18
- activityMap: {},
19
- tournamentList: [],
20
- refs: {},
21
- uidSite: '',
22
- siteConfig: {},
23
- isPlaying: false,
24
- },
25
- states: {
26
- init: {
27
- on: {
28
- SET_CONFIG: {
29
- target: 'fetchingList',
30
- actions: 'setSiteConifg',
31
- },
32
- },
33
- },
34
- fetchingList: {
35
- invoke: {
36
- src: 'fetchList',
37
- onDone: {
38
- target: 'idle',
39
- actions: ['setActivityList', 'setTournamentList', 'setPromotionList'],
40
- },
41
- onError: {
42
- target: 'idle',
43
- },
44
- },
45
- },
46
- idle: {
47
- type: 'parallel',
48
- states: {
49
- activitiesDetail: {
50
- initial: 'checking',
51
- states: {
52
- checking: {
53
- always: [{ target: 'fetchActivityDetail', cond: 'hasSpecifyActivities' }, { target: 'end' }],
54
- },
55
- fetchActivityDetail: {
56
- invoke: {
57
- src: 'fetchActivitiesDetail',
58
- onDone: {
59
- target: 'end',
60
- actions: 'setActivitiesDetailList',
61
- },
62
- onError: {
63
- target: 'end',
64
- },
65
- },
66
- },
67
- end: {},
68
- },
69
- },
70
- pending: {
71
- after: {
72
- TIMEOUT: [
73
- { target: '#activity.fetchingList', cond: 'isNotInGame' },
74
- { target: '#activity.idle', cond: 'isInGame' },
75
- ],
76
- },
77
- on: {
78
- SET_UNREAD: {
79
- actions: 'setUnread',
80
- },
81
- RESET_ACTIVITIES: {
82
- actions: 'resetActivities',
83
- },
84
- },
85
- },
86
- },
87
- },
88
- },
89
- on: {
90
- REFRESH: {
91
- target: '#activity.fetchingList',
92
- actions: 'leaveGame',
93
- },
94
- },
95
- },
96
- {
97
- actions: {
98
- setSiteConifg: assign((context, event) => {
99
- return {
100
- siteConfig: event.data,
101
- }
102
- }),
103
- setTournamentList: assign((context, event) => {
104
- const { activityList } = event.data
105
- const tournamentList = activityList.filter((item) => item.tournament === 1)
106
- return {
107
- tournamentList,
108
- }
109
- }),
110
- setActivityList: assign((context, event) => {
111
- const noRedActivity = [2, 4, 13, 20, 90, 91, 92]
112
- const noReadSet = new Set(noRedActivity)
113
- const { uidSite } = context
114
- const { activityList } = event.data
115
- const list = (activityList || []).map((activity) => {
116
- const storageUnread = localStorage.getItem(`unread_${activity.activityNo}_${uidSite}`)
117
- if (noReadSet.has(activity.activityType)) {
118
- return { ...activity, unread: false }
119
- } else if (storageUnread) {
120
- return { ...activity, unread: JSON.parse(storageUnread) }
121
- } else {
122
- return { ...activity, unread: true }
123
- }
124
- })
125
- return {
126
- activityList: list,
127
- }
128
- }),
129
- setPromotionList: assign((context, event) => {
130
- const { promotionList } = event.data
131
- return {
132
- promotionList,
133
- }
134
- }),
135
- setActivitiesDetailList: assign((context, event) => {
136
- return {
137
- activitiesDetailList: event.data.map((item) => item.data),
138
- }
139
- }),
140
- setUnread: assign((context, event) => {
141
- const { uidSite, activityNo, unread } = event.data
142
- localStorage.setItem(`unread_${activityNo}_${uidSite}`, `${unread}`)
143
- const list = (context.activityList || []).map((item) =>
144
- item.activityNo === activityNo
145
- ? {
146
- ...item,
147
- unread: JSON.parse(`${unread}`),
148
- }
149
- : item
150
- )
151
- return {
152
- activityList: list,
153
- uidSite,
154
- }
155
- }),
156
- resetActivities: assign((context, event) => {
157
- return {
158
- isPlaying: true,
159
- }
160
- }),
161
- leaveGame: assign((context, event) => {
162
- return {
163
- isPlaying: false,
164
- }
165
- }),
166
- },
167
- guards: {
168
- hasSpecifyActivities: (context, event) => {
169
- const { activityList = [], specifyActivities = [] } = context
170
- return activityList.some((activity) => specifyActivities.includes(activity.activityType))
171
- },
172
- isInGame: (context, event) => {
173
- return context.isPlaying
174
- },
175
- isNotInGame: (context, event) => {
176
- return !context.isPlaying
177
- },
178
- },
179
- delays: {
180
- TIMEOUT: (context, event) => {
181
- const { tick } = context
182
- return tick * 10
183
- },
184
- },
185
- services: {
186
- fetchList: async (context, event) => {
187
- const hasToken = request.getToken()
188
- const apiCallable = hasToken
189
- const [{ data }, promotionList] = await Promise.all([
190
- hasToken ? request.send(activity.getActivityList({ appSecret })) : request.send(activity.getAllActivityList({ appSecret })),
191
- apiCallable && !context.isPlaying ? request.send(payment.getPromotionsList()) : [],
192
- ])
193
-
194
- return { activityList: data, promotionList }
195
- },
196
- fetchActivitiesDetail: async (context, event) => {
197
- await new Promise((resolve) => setTimeout(resolve, 1000)) // delay 1 second
198
-
199
- const { activityList = [], specifyActivities = [] } = context
200
- const promiseArray = []
201
- for (let i = 0; i < activityList.length; i++) {
202
- const item = activityList[i]
203
- if (specifyActivities.includes(item.activityType)) {
204
- promiseArray.push(request.send(activity.getActivityDetail({ activityNo: item.activityNo, appSecret })))
205
- }
206
- }
207
- const activitiesDetail = await Promise.all(promiseArray)
208
- return activitiesDetail
209
- },
210
- },
211
- }
212
- )
213
- }
@@ -1,197 +0,0 @@
1
- import { assign, createMachine } from 'xstate'
2
- import api from '../../api/activity.js'
3
-
4
- export default function (request) {
5
- const { appSecret } = request.config
6
- return createMachine(
7
- {
8
- id: 'diamond_shop_activity',
9
- predictableActionArguments: true,
10
- context: {
11
- activityNo: null,
12
- activityDetail: null,
13
- awards: [],
14
- exchangeList: [],
15
- exchangeAward: 0,
16
- exchangePoint: 0,
17
- },
18
- initial: 'fetching',
19
- states: {
20
- fetching: {
21
- invoke: {
22
- src: 'fetchActivityList',
23
- onDone: {
24
- target: 'checking',
25
- actions: 'setDiamondShopActivities',
26
- },
27
- onError: {
28
- target: 'idle',
29
- },
30
- },
31
- },
32
- idle: {
33
- on: {
34
- SET_ACTIVITY_NO: {
35
- // todo - deprecated
36
- },
37
- },
38
- },
39
- checking: {
40
- always: [{ target: 'loading', cond: 'hasActivityNo' }],
41
- },
42
- loading: {
43
- invoke: {
44
- src: 'fetchActivityDetail',
45
- onDone: {
46
- target: 'loaded',
47
- actions: ['setActivityDetail', 'setAwardList'],
48
- },
49
- onError: {
50
- target: 'idle',
51
- },
52
- },
53
- },
54
- loaded: {
55
- on: {
56
- EXCHANGE: {
57
- target: 'exchanging',
58
- cond: 'isExchangeable',
59
- },
60
- ADD_TO_CART: {
61
- actions: ['addProduct', 'count'],
62
- },
63
- CLEAR_CART: {
64
- actions: ['clearCart', 'count'],
65
- },
66
- COLLECT: {
67
- target: 'collecting',
68
- cond: 'hasUnclaimedReward',
69
- },
70
- },
71
- },
72
- exchanging: {
73
- invoke: {
74
- src: 'exchange',
75
- onDone: {
76
- target: 'collecting',
77
- actions: ['clearCart', 'count'],
78
- },
79
- onError: {
80
- target: 'loaded',
81
- },
82
- },
83
- },
84
- collecting: {
85
- invoke: {
86
- src: 'collect',
87
- onDone: {
88
- target: 'collected',
89
- },
90
- onError: {
91
- target: 'collected',
92
- },
93
- },
94
- },
95
- collected: {
96
- after: {
97
- 0: {
98
- target: 'loaded',
99
- },
100
- },
101
- },
102
- },
103
- },
104
- {
105
- actions: {
106
- setActivityNo: assign((context, event) => {
107
- return {
108
- activityNo: event.data,
109
- }
110
- }),
111
- setDiamondShopActivities: assign((context, event) => {
112
- const rankActivities = event.data.filter((item) => item.activityType === 91)
113
- return {
114
- rankActivities,
115
- activityNo: rankActivities?.[0]?.activityNo,
116
- }
117
- }),
118
- setActivityDetail: assign((context, event) => {
119
- return {
120
- activityDetail: event.data,
121
- }
122
- }),
123
- setAwardList: assign((context, event) => {
124
- return {
125
- awardList: event.data?.awards || [],
126
- }
127
- }),
128
- addProduct: assign((context, event) => {
129
- return {
130
- exchangeList: [...context.exchangeList, event.data],
131
- }
132
- }),
133
- clearCart: assign((context, event) => {
134
- return {
135
- exchangeList: [],
136
- }
137
- }),
138
- count: assign((context, event) => {
139
- const { exchangeList } = context
140
- const { exchangeAward, exchangePoint } = exchangeList.reduce(
141
- ({ exchangeAward, exchangePoint }, item) => {
142
- return {
143
- exchangeAward: exchangeAward + item.award,
144
- exchangePoint: exchangePoint + item.points,
145
- }
146
- },
147
- { exchangeAward: 0, exchangePoint: 0 }
148
- )
149
- return {
150
- exchangeAward,
151
- exchangePoint,
152
- }
153
- }),
154
- },
155
- guards: {
156
- hasUnclaimedReward: (context, event) => {
157
- return context.activityDetail?.unclaimedReward?.length > 0
158
- },
159
- isExchangeable: (context, event) => {
160
- const { exchangeList } = context
161
- return exchangeList.length > 0
162
- },
163
- hasActivityNo: (context, event) => {
164
- return !!context.activityNo
165
- },
166
- },
167
- services: {
168
- fetchActivityList: async (context, event) => {
169
- const { data } = await request.send(api.getActivityList({ appSecret }))
170
- return data
171
- },
172
- fetchActivityDetail: async (context, event) => {
173
- const { activityNo } = context
174
- const { data } = await request.send(api.getActivityDetail({ activityNo, appSecret }))
175
- return data
176
- },
177
- exchange: async (context, event) => {
178
- const { activityNo, exchangeList } = context
179
- return await Promise.all(
180
- exchangeList.map((item) =>
181
- request.send(
182
- api.exchange({
183
- exchangeType: 1,
184
- activityNo,
185
- exchangeAward: item.award,
186
- })
187
- )
188
- )
189
- )
190
- },
191
- collect: async (context, event) => {
192
- return await request.send(api.collect({ appSecret }))
193
- },
194
- },
195
- }
196
- )
197
- }
@@ -1,179 +0,0 @@
1
- import { assign, createMachine } from 'xstate'
2
- import api from '../../api/activity.js'
3
-
4
- export default function (request) {
5
- const { appSecret } = request.config
6
- return createMachine(
7
- {
8
- id: 'diamond_shop_activity',
9
- predictableActionArguments: true,
10
- context: {
11
- activityNo: null,
12
- activityDetail: null,
13
- totalPoints: 0,
14
- awardList: [],
15
- totalAmount: 0,
16
- subtractPoints: 0,
17
- callback: () => {},
18
- },
19
- initial: 'fetching',
20
- states: {
21
- fetching: {
22
- invoke: {
23
- src: 'fetchActivityList',
24
- onDone: {
25
- target: 'checking',
26
- actions: 'setDiamondShopActivities',
27
- },
28
- onError: {
29
- target: 'idle',
30
- },
31
- },
32
- },
33
- idle: {},
34
- checking: {
35
- always: [{ target: 'loading', cond: 'hasActivityNo' }],
36
- },
37
- loading: {
38
- invoke: {
39
- src: 'fetchActivityDetail',
40
- onDone: {
41
- target: 'loaded',
42
- actions: ['setActivityDetail', 'setAwardList'],
43
- },
44
- onError: {
45
- target: 'idle',
46
- },
47
- },
48
- },
49
- loaded: {
50
- on: {
51
- SELECT_EXCHANGE_AMOUNT: {
52
- actions: 'selectExchangeAmount',
53
- },
54
- SET_MAX_EXCHANGE_AMOUNT: {
55
- target: 'fetchingMaxAmount',
56
- },
57
- RESET_EXCHANGE_AMOUNT: {
58
- actions: 'resetExchangeAmount',
59
- },
60
- SETTLE_AMOUNT: {
61
- target: 'settling',
62
- actions: 'setCallback',
63
- cond: 'settlable',
64
- },
65
- },
66
- },
67
- fetchingMaxAmount: {
68
- invoke: {
69
- src: 'fetchMaxExchangeAmount',
70
- onDone: {
71
- target: 'loaded',
72
- actions: 'setMaxExchangeAmount',
73
- },
74
- onError: {
75
- target: 'loaded',
76
- },
77
- },
78
- },
79
- settling: {
80
- invoke: {
81
- src: 'settleAmount',
82
- onDone: {
83
- target: 'settled',
84
- actions: ['resetExchangeAmount', 'doCallback'],
85
- },
86
- onError: {
87
- target: 'settled',
88
- },
89
- },
90
- },
91
- settled: {
92
- after: {
93
- 0: {
94
- target: 'loaded',
95
- },
96
- },
97
- },
98
- },
99
- },
100
- {
101
- actions: {
102
- setDiamondShopActivities: assign((context, event) => {
103
- const activity = event.data.filter((item) => item.activityType === 91)
104
- return {
105
- activityNo: activity?.[0]?.activityNo,
106
- }
107
- }),
108
- setActivityDetail: assign((context, event) => {
109
- return {
110
- activityDetail: event.data,
111
- }
112
- }),
113
- setAwardList: assign((context, event) => {
114
- return {
115
- awardList: event.data?.awards || [],
116
- }
117
- }),
118
- selectExchangeAmount: assign((context, event) => {
119
- const { totalAmount = 0, subtractPoints = 0 } = context
120
- const { award = 0, points = 0 } = event.data
121
- return {
122
- totalAmount: parseFloat(`${totalAmount}`) + parseFloat(`${award}`),
123
- subtractPoints: parseFloat(`${subtractPoints}`) + parseFloat(`${points}`),
124
- }
125
- }),
126
- setMaxExchangeAmount: assign((context, event) => {
127
- const { addCash = 0, subtractDiamond = 0 } = event.data
128
- return {
129
- totalAmount: parseFloat(`${addCash}`),
130
- subtractPoints: parseFloat(`${subtractDiamond}`),
131
- }
132
- }),
133
- resetExchangeAmount: assign((context, event) => {
134
- return {
135
- totalAmount: 0,
136
- subtractPoints: 0,
137
- }
138
- }),
139
- setCallback: assign((context, event) => {
140
- return {
141
- callback: event.data?.callback || (() => {}),
142
- }
143
- }),
144
- doCallback: (context, event) => {
145
- context.callback()
146
- },
147
- },
148
- guards: {
149
- settlable: (context, event) => {
150
- const { totalPoints, totalAmount, subtractPoints } = context
151
- return totalAmount > 0 && subtractPoints <= totalPoints
152
- },
153
- hasActivityNo: (context, event) => {
154
- return !!context.activityNo
155
- },
156
- },
157
- services: {
158
- fetchActivityList: async (context, event) => {
159
- const { data } = await request.send(api.getActivityList({ appSecret }))
160
- return data
161
- },
162
- fetchActivityDetail: async (context, event) => {
163
- const { activityNo } = context
164
- const { data } = await request.send(api.getActivityDetail({ activityNo, appSecret }))
165
- return data
166
- },
167
- fetchMaxExchangeAmount: async (context, event) => {
168
- const { activityNo } = context
169
- const { data } = await request.send(api.getMaxExchangeAmount({ activityNo, appSecret }))
170
- return data
171
- },
172
- settleAmount: async (context, event) => {
173
- const { activityNo, totalAmount } = context
174
- return await request.send(api.settleAmount({ activityNo, totalCash: totalAmount, appSecret }))
175
- },
176
- },
177
- }
178
- )
179
- }
@@ -1,115 +0,0 @@
1
- import { assign, createMachine } from 'xstate'
2
- import user from '../../api/user.js'
3
- import api from '../../api/activity.js'
4
-
5
- export default function (request) {
6
- const { appSecret } = request.config
7
- return createMachine(
8
- {
9
- id: 'invite_friends_activity',
10
- predictableActionArguments: true,
11
- context: {
12
- activityNo: null,
13
- bindingCode: null,
14
- uidSite: null,
15
- receiveNo: null,
16
- friendCode: null,
17
- downlineCount: 0,
18
- },
19
- initial: 'idle',
20
- states: {
21
- idle: {
22
- on: {
23
- FETCH_FRIEND_CODE: {
24
- target: 'fetching',
25
- },
26
- BIND_FRIEND_CODE: {
27
- target: 'binding',
28
- actions: ['setActivityNo', 'setBindingCode', 'setUidSite'],
29
- },
30
- },
31
- },
32
- fetching: {
33
- invoke: {
34
- src: 'fetchFriends',
35
- onDone: {
36
- target: 'idle',
37
- actions: 'setFriendCode',
38
- },
39
- onError: {
40
- target: 'idle',
41
- },
42
- },
43
- },
44
- binding: {
45
- invoke: {
46
- src: 'postFriends',
47
- onDone: {
48
- target: 'awarding',
49
- },
50
- onError: {
51
- target: 'idle',
52
- },
53
- },
54
- },
55
- awarding: {
56
- invoke: {
57
- src: 'awardPrize',
58
- onDone: {
59
- target: 'bound',
60
- },
61
- onError: {
62
- target: 'idle',
63
- },
64
- },
65
- },
66
- bound: {
67
- after: {
68
- 0: {
69
- target: 'idle',
70
- },
71
- },
72
- },
73
- },
74
- },
75
- {
76
- actions: {
77
- setFriendCode: assign((context, event) => {
78
- const { friendCode, downlineCount } = event.data
79
- return {
80
- friendCode,
81
- downlineCount,
82
- }
83
- }),
84
- setBindingCode: assign((context, event) => {
85
- return {
86
- bindingCode: event.data.bindingCode,
87
- }
88
- }),
89
- setActivityNo: assign((context, event) => {
90
- return {
91
- activityNo: event.data.activityNo,
92
- }
93
- }),
94
- setUidSite: assign((context, event) => {
95
- return {
96
- uidSite: event.data.uidSite,
97
- }
98
- }),
99
- },
100
- services: {
101
- postFriends: async (context, event) => {
102
- return await request.send(user.postFriends({ friendCode: context.bindingCode }))
103
- },
104
- fetchFriends: async (context, event) => {
105
- return await request.send(user.getFriends())
106
- },
107
- awardPrize: async (context, event) => {
108
- const { activityNo, uidSite, bindingCode } = context
109
- const { data } = await request.send(api.sentAward({ activityNo, uidSite, affiliateCode: bindingCode, appSecret }))
110
- return data
111
- },
112
- },
113
- }
114
- )
115
- }