@jetthai/cuora 1.1.90 → 1.1.92-cash

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 (35) hide show
  1. package/.husky/pre-commit +1 -1
  2. package/CHANGELOG.md +12 -0
  3. package/dist/bundle.mjs +583 -1334
  4. package/package.json +1 -1
  5. package/src/api/activity.js +13 -1
  6. package/src/api/auth.js +2 -2
  7. package/src/api/user.js +5 -0
  8. package/src/machine/activity/deposit_activity.js +2 -2
  9. package/src/machine/activity/diamond_shop_activity_cash.js +214 -0
  10. package/src/machine/activity/fafafa_activity.js +35 -11
  11. package/src/machine/activity/{affiliate_invite_friends_activity.js → friend_invite_friends_activity.js} +23 -23
  12. package/src/machine/activity/index.js +4 -2
  13. package/src/machine/activity/invite_friends_activity.js +13 -13
  14. package/src/machine/activity/ranking_activity.js +31 -2
  15. package/src/machine/activity/specify_bets_activity.js +44 -3
  16. package/src/machine/activity/specify_turnover_activity.js +44 -3
  17. package/src/machine/auth.js +7 -7
  18. package/src/machine/common.js +4 -4
  19. package/src/machine/deposit/index.js +4 -0
  20. package/src/machine/deposit/manual_cash.js +321 -0
  21. package/src/machine/deposit/qrcode_cash.js +258 -0
  22. package/src/machine/game_favorite_v2.js +6 -2
  23. package/src/machine/game_v2_1.js +35 -9
  24. package/src/machine/index.js +4 -6
  25. package/src/machine/reward_cash.js +220 -0
  26. package/src/machine/side_cash.js +198 -0
  27. package/src/machine/user_info.js +8 -2
  28. package/src/machine/user_sign_up.js +8 -8
  29. package/src/machine/withdraw/withdraw_activity.js +383 -0
  30. package/src/request/request.js +9 -5
  31. package/src/util/index.js +2 -1
  32. package/src/util/math.js +4 -0
  33. package/src/machine/game.js +0 -285
  34. package/src/machine/game_favorite.js +0 -123
  35. package/src/machine/game_v2.js +0 -381
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jetthai/cuora",
3
- "version": "1.1.90",
3
+ "version": "1.1.92-cash",
4
4
  "description": "",
5
5
  "main": "./src/index.js",
6
6
  "type": "module",
@@ -46,9 +46,21 @@ export default {
46
46
  method: 'get',
47
47
  params: { rewardType },
48
48
  }),
49
- getRewardList: ({ rewardType, count, appSecret }) => ({ url: 'activities/rewards', method: 'get', params: { rewardType, count, appSecret } }),
49
+ getRewardList: ({ rewardType, count, appSecret }) => ({
50
+ url: 'activities/rewards',
51
+ method: 'get',
52
+ params: { rewardType, count, appSecret },
53
+ }),
50
54
  exchange: (data) => ({ url: 'activities/exchange', method: 'post', params: data }),
51
55
  collect: (data) => ({ url: 'activities/collect', method: 'post', params: data }),
52
56
  getVipTable: () => ({ url: 'activities/viptable', method: 'get' }),
53
57
  getRankingList: () => ({ url: 'activities/ranking', method: 'get' }),
58
+ exchangeDiamond: ({ activityNo, exchangeAward = [] }) => ({
59
+ url: 'activities/exchange/diamond',
60
+ method: 'post',
61
+ params: {
62
+ activityNo,
63
+ exchangeAward,
64
+ },
65
+ }),
54
66
  }
package/src/api/auth.js CHANGED
@@ -31,8 +31,8 @@ export default {
31
31
  },
32
32
  isPublic: true,
33
33
  }),
34
- register: ({ channel, subchannel, referralCode, affiliate = null, reCaptchaToken, dt, ...rest }) => {
35
- const params = pickBy({ channel, subchannel, referralCode, affiliate }, (value) => {
34
+ register: ({ channel, subchannel, ac, fc = null, reCaptchaToken, dt, ...rest }) => {
35
+ const params = pickBy({ channel, subchannel, ac, fc }, (value) => {
36
36
  return value !== undefined && value !== null
37
37
  })
38
38
  const qs = Object.keys(params)
package/src/api/user.js CHANGED
@@ -14,6 +14,11 @@ export default {
14
14
  getAffiliateDashboard: () => ({ url: 'affiliate/dashboard', method: 'get' }),
15
15
  getAffiliateDashboardList: ({ level, page, row }) => ({ url: 'affiliate/dashboard/list', method: 'post', params: { level, page, row } }),
16
16
  postAffiliate: ({ affiliateCode }) => ({ url: 'affiliate', method: 'post', params: { affiliateCode } }),
17
+ getFriends: () => ({ url: 'friends', method: 'get' }),
18
+ getFriendsHome: () => ({ url: 'friends/home', method: 'get' }),
19
+ getFriendsDashboard: () => ({ url: 'friends/dashboard', method: 'get' }),
20
+ getFriendsDashboardList: ({ level, page, row }) => ({ url: 'friends/dashboard/list', method: 'post', params: { level, page, row } }),
21
+ postFriends: ({ friendCode }) => ({ url: 'friends', method: 'post', params: { friendCode } }),
17
22
  passwordRecovery: (recoveryData) => ({ url: 'recovery', method: 'post', params: recoveryData, isPublic: true }),
18
23
  passwordAbandon: ({ number }) => ({ url: 'recovery/abandon', method: 'post', params: { number }, isPublic: true }),
19
24
  passwordAcknowledge: (acknowledgeData) => ({ url: 'recovery/acknowledge', method: 'post', params: acknowledgeData, isPublic: true }),
@@ -9,7 +9,7 @@ export default function (request) {
9
9
  context: {
10
10
  activityNo: null,
11
11
  activityDetail: null,
12
- duration: null,
12
+ duration: 0,
13
13
  },
14
14
  initial: 'idle',
15
15
  states: {
@@ -62,7 +62,7 @@ export default function (request) {
62
62
  }),
63
63
  setDuration: assign((context, event) => {
64
64
  return {
65
- duration: context?.activityDetail?.deadline - new Date().getTime() / 1000,
65
+ duration: Math.max(context?.activityDetail?.deadline - new Date().getTime() / 1000, 0),
66
66
  }
67
67
  }),
68
68
  },
@@ -0,0 +1,214 @@
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
+ context: {
10
+ activityNo: null,
11
+ activityDetail: null,
12
+ awards: [],
13
+ exchangeList: [],
14
+ exchangeAward: 0,
15
+ exchangePoint: 0,
16
+ remainingPoints: 0,
17
+ receiveRewards: [],
18
+ unclaimedRewardList: [],
19
+ },
20
+ initial: 'fetching',
21
+ states: {
22
+ fetching: {
23
+ invoke: {
24
+ src: 'fetchActivityList',
25
+ onDone: {
26
+ target: 'checking',
27
+ actions: 'setDiamondShopActivities',
28
+ },
29
+ onError: {
30
+ target: 'idle',
31
+ },
32
+ },
33
+ },
34
+ idle: {},
35
+ checking: {
36
+ always: [{ target: 'loading', cond: 'hasActivityNo' }],
37
+ },
38
+ loading: {
39
+ invoke: {
40
+ src: 'fetchActivityDetail',
41
+ onDone: {
42
+ target: 'loaded',
43
+ actions: ['setActivityDetail', 'setAwardList', 'setUnclaimedReward'],
44
+ },
45
+ onError: {
46
+ target: 'idle',
47
+ },
48
+ },
49
+ },
50
+ loaded: {
51
+ on: {
52
+ EXCHANGE: {
53
+ target: 'exchanging',
54
+ },
55
+ SELECT: {
56
+ actions: ['selectProduct', 'count'],
57
+ },
58
+ // ADD_TO_CART: {
59
+ // actions: ['addProduct', 'count'],
60
+ // },
61
+ // CLEAR_CART: {
62
+ // actions: ['clearCart', 'count'],
63
+ // },
64
+ // COLLECT: {
65
+ // target: 'collecting',
66
+ // cond: 'hasUnclaimedReward',
67
+ // },
68
+ },
69
+ },
70
+ exchanging: {
71
+ invoke: {
72
+ src: 'exchange',
73
+ onDone: {
74
+ target: 'collecting',
75
+ actions: ['setExchangedData', 'setUnclaimedReward'],
76
+ },
77
+ onError: {
78
+ target: 'loaded',
79
+ },
80
+ },
81
+ },
82
+ collecting: {
83
+ invoke: {
84
+ src: 'collect',
85
+ onDone: {
86
+ target: 'collected',
87
+ actions: 'clearExchangedData',
88
+ },
89
+ onError: {
90
+ target: 'collected',
91
+ },
92
+ },
93
+ },
94
+ collected: {
95
+ after: {
96
+ 0: {
97
+ target: 'loaded',
98
+ },
99
+ },
100
+ },
101
+ },
102
+ },
103
+ {
104
+ actions: {
105
+ setActivityNo: assign((context, event) => {
106
+ return {
107
+ activityNo: event.data,
108
+ }
109
+ }),
110
+ setDiamondShopActivities: assign((context, event) => {
111
+ const rankActivities = event.data.filter((item) => item.activityType === 91)
112
+ return {
113
+ rankActivities,
114
+ activityNo: rankActivities?.[0]?.activityNo,
115
+ }
116
+ }),
117
+ setActivityDetail: assign((context, event) => {
118
+ return {
119
+ activityDetail: event.data,
120
+ }
121
+ }),
122
+ setAwardList: assign((context, event) => {
123
+ return {
124
+ awardList: event.data?.awards || [],
125
+ }
126
+ }),
127
+ setExchangedData: assign((context, event) => {
128
+ return {
129
+ remainingPoints: event.data?.data?.points,
130
+ receiveRewards: event.data?.date?.receiveRewards,
131
+ }
132
+ }),
133
+ setUnclaimedReward: assign((context, event) => {
134
+ return {
135
+ unclaimedRewardList: event.data?.unclaimedReward || event.data?.data?.unclaimedReward || [],
136
+ }
137
+ }),
138
+ clearExchangedData: assign((context, event) => {
139
+ return {
140
+ remainingPoints: null,
141
+ receiveRewards: [],
142
+ unclaimedRewardList: [],
143
+ }
144
+ }),
145
+ selectProduct: assign((context, event) => {
146
+ return {
147
+ exchangeList: [event.data],
148
+ }
149
+ }),
150
+ addProduct: assign((context, event) => {
151
+ return {
152
+ exchangeList: [...context.exchangeList, event.data],
153
+ }
154
+ }),
155
+ clearCart: assign((context, event) => {
156
+ return {
157
+ exchangeList: [],
158
+ }
159
+ }),
160
+ count: assign((context, event) => {
161
+ const { exchangeList } = context
162
+ const { exchangeAward, exchangePoint } = exchangeList.reduce(
163
+ ({ exchangeAward, exchangePoint }, item) => {
164
+ return {
165
+ exchangeAward: exchangeAward + item.award,
166
+ exchangePoint: exchangePoint + item.points,
167
+ }
168
+ },
169
+ { exchangeAward: 0, exchangePoint: 0 }
170
+ )
171
+ return {
172
+ exchangeAward,
173
+ exchangePoint,
174
+ }
175
+ }),
176
+ },
177
+ guards: {
178
+ hasUnclaimedReward: (context, event) => {
179
+ return context.unclaimedRewardList.length > 0
180
+ },
181
+ isExchangeable: (context, event) => {
182
+ const { exchangeList } = context
183
+ return exchangeList.length > 0
184
+ },
185
+ hasActivityNo: (context, event) => {
186
+ return !!context.activityNo
187
+ },
188
+ },
189
+ services: {
190
+ fetchActivityList: async (context, event) => {
191
+ const { data } = await request.send(api.getActivityList({ appSecret }))
192
+ return data
193
+ },
194
+ fetchActivityDetail: async (context, event) => {
195
+ const { activityNo } = context
196
+ const { data } = await request.send(api.getActivityDetail({ activityNo, appSecret }))
197
+ return data
198
+ },
199
+ exchange: async (context, event) => {
200
+ const { activityNo } = context
201
+ return await request.send(
202
+ api.exchangeDiamond({
203
+ activityNo,
204
+ exchangeAward: [event.data],
205
+ })
206
+ )
207
+ },
208
+ collect: async (context, event) => {
209
+ return await request.send(api.collect({ appSecret }))
210
+ },
211
+ },
212
+ }
213
+ )
214
+ }
@@ -2,17 +2,18 @@ import { assign, createMachine } from 'xstate'
2
2
  import isEqual from 'lodash/isEqual.js'
3
3
  import api from '../../api/activity.js'
4
4
 
5
- // const isEqual = require('lodash/isEqual')
6
-
7
- export default function (request) {
5
+ export default function (request, context) {
8
6
  const { appSecret } = request.config
7
+ const { activityNo, isAutoReceiving = true, isLogin = true } = context || {}
9
8
  return createMachine(
10
9
  {
11
10
  id: 'fafafa_activity',
12
11
  context: {
13
- isAutoReceiving: true,
14
- activityNo: null,
12
+ isLogin,
13
+ isAutoReceiving,
14
+ activityNo,
15
15
  activityDetail: null,
16
+ duration: 0,
16
17
 
17
18
  // 領獎後得到的資訊
18
19
  awards: [],
@@ -26,7 +27,8 @@ export default function (request) {
26
27
  initial: 'idle',
27
28
  states: {
28
29
  idle: {
29
- always: [{ target: 'loading', cond: 'hasActivityNo' }],
30
+ entry: 'reset',
31
+ always: [{ target: 'loading', cond: 'isLoadable' }],
30
32
  },
31
33
  loading: {
32
34
  invoke: {
@@ -35,21 +37,24 @@ export default function (request) {
35
37
  target: 'loaded',
36
38
  actions: 'setActivityDetail',
37
39
  },
38
- onError: {
39
- target: 'idle',
40
- },
41
40
  },
42
41
  },
43
42
  loaded: {
44
43
  always: [{ target: 'awardable', cond: 'isAwardable' }, { target: 'awarded' }],
45
44
  },
46
45
  awardable: {
46
+ entry: 'setDuration',
47
47
  on: {
48
48
  AWARD_PRIZE: {
49
49
  target: 'awarding',
50
50
  actions: 'setCallback',
51
51
  },
52
52
  },
53
+ after: {
54
+ 1000: {
55
+ target: 'awardable',
56
+ },
57
+ },
53
58
  },
54
59
  awarded: {
55
60
  on: {
@@ -90,6 +95,14 @@ export default function (request) {
90
95
  actions: 'setActivityNo',
91
96
  cond: 'isActivityChanged',
92
97
  },
98
+ START: {
99
+ target: '.idle',
100
+ actions: assign((context, event) => ({ isLogin: true })),
101
+ },
102
+ STOP: {
103
+ target: '.idle',
104
+ actions: assign((context, event) => ({ isLogin: false })),
105
+ },
93
106
  },
94
107
  },
95
108
  {
@@ -122,13 +135,24 @@ export default function (request) {
122
135
  doCallback: (context, event) => {
123
136
  context.callback()
124
137
  },
138
+ setDuration: assign((context, event) => {
139
+ return {
140
+ duration: Math.max(context?.activityDetail?.periodEndTime - new Date().getTime() / 1000, 0),
141
+ }
142
+ }),
143
+ reset: assign((context, event) => {
144
+ return {
145
+ activityDetail: null,
146
+ duration: 0,
147
+ }
148
+ }),
125
149
  },
126
150
  guards: {
127
151
  isActivityChanged: (context, event) => {
128
152
  return !isEqual(context.activityNo, event.data)
129
153
  },
130
- hasActivityNo: (context, event) => {
131
- return context.activityNo
154
+ isLoadable: (context, event) => {
155
+ return context.isLogin && context.activityNo
132
156
  },
133
157
  isAwardable: (context, event) => {
134
158
  return context.activityDetail?.receiveStatus === 2
@@ -6,14 +6,14 @@ export default function (request) {
6
6
  const { appSecret } = request.config
7
7
  return createMachine(
8
8
  {
9
- id: 'affiliate_invite_friends_activity',
9
+ id: 'friend_invite_friends_activity',
10
10
  context: {
11
- affiliateEnable: false,
11
+ friendsEnable: false,
12
12
  activityNo: null,
13
13
  bindingCode: null,
14
14
  uidSite: null,
15
15
  receiveNo: null,
16
- affiliateCode: '',
16
+ friendCode: '',
17
17
  commission: 0,
18
18
  downLine: 0,
19
19
  activeDownLine: 0,
@@ -27,10 +27,10 @@ export default function (request) {
27
27
  states: {
28
28
  fetching1: {
29
29
  invoke: {
30
- src: 'fetchAffiliateCode',
30
+ src: 'fetchFriendCode',
31
31
  onDone: {
32
32
  target: 'checking',
33
- actions: 'setAffiliateCode',
33
+ actions: 'setFriendsCode',
34
34
  },
35
35
  onError: {
36
36
  target: 'fetching2',
@@ -38,11 +38,11 @@ export default function (request) {
38
38
  },
39
39
  },
40
40
  checking: {
41
- always: [{ target: 'fetching2', cond: 'isAffiliateEnable' }, { target: 'idle' }],
41
+ always: [{ target: 'fetching2', cond: 'isFriendsEnable' }, { target: 'idle' }],
42
42
  },
43
43
  fetching2: {
44
44
  invoke: {
45
- src: 'fetchAffiliateData',
45
+ src: 'fetchFriendsData',
46
46
  onDone: {
47
47
  target: 'idle',
48
48
  actions: 'setInitialData',
@@ -54,7 +54,7 @@ export default function (request) {
54
54
  },
55
55
  idle: {
56
56
  on: {
57
- BIND_AFFILIATE_CODE: {
57
+ BIND_FRIEND_CODE: {
58
58
  target: 'binding',
59
59
  actions: ['setBindingCode', 'setUidSite', 'setActivityNo'],
60
60
  },
@@ -71,7 +71,7 @@ export default function (request) {
71
71
  },
72
72
  binding: {
73
73
  invoke: {
74
- src: 'postAffiliate',
74
+ src: 'postFriends',
75
75
  onDone: {
76
76
  target: 'awarding',
77
77
  },
@@ -115,10 +115,10 @@ export default function (request) {
115
115
  },
116
116
  {
117
117
  actions: {
118
- setAffiliateCode: assign((context, event) => {
119
- const { affiliateCode = '' } = event.data || {}
118
+ setFriendsCode: assign((context, event) => {
119
+ const { friendCode = '' } = event.data || {}
120
120
  return {
121
- affiliateCode,
121
+ friendCode,
122
122
  }
123
123
  }),
124
124
  setInitialData: assign((context, event) => {
@@ -175,20 +175,20 @@ export default function (request) {
175
175
  const { page } = context.levelDownLine
176
176
  return page.current < page.total
177
177
  },
178
- isAffiliateEnable: (context, event) => context.affiliateEnable,
178
+ isFriendsEnable: (context, event) => context.friendsEnable,
179
179
  },
180
180
  services: {
181
- fetchAffiliateCode: async () => {
182
- return await request.send(user.getAffiliate())
181
+ fetchFriendCode: async () => {
182
+ return await request.send(user.getFriends())
183
183
  },
184
- fetchAffiliateData: async (context, event) => {
185
- const affiliateHomeAPI = request.send(user.getAffiliateHome())
186
- const affiliateDashboard = request.send(user.getAffiliateDashboard())
187
- const [affiliateHomeData, affiliateDashboardData] = await Promise.all([affiliateHomeAPI, affiliateDashboard])
188
- return [affiliateHomeData, affiliateDashboardData]
184
+ fetchFriendsData: async (context, event) => {
185
+ const friendsHomeAPI = request.send(user.getFriendsHome())
186
+ const friendsDashboard = request.send(user.getFriendsDashboard())
187
+ const [friendsHomeData, friendsDashboardData] = await Promise.all([friendsHomeAPI, friendsDashboard])
188
+ return [friendsHomeData, friendsDashboardData]
189
189
  },
190
- postAffiliate: async (context, event) => {
191
- return await request.send(user.postAffiliate({ affiliateCode: context.bindingCode }))
190
+ postFriends: async (context, event) => {
191
+ return await request.send(user.postFriends({ friendCode: context.bindingCode }))
192
192
  },
193
193
  awardPrize: async (context, event) => {
194
194
  const { activityNo, uidSite, bindingCode } = context
@@ -199,7 +199,7 @@ export default function (request) {
199
199
  const { currentLevel, page, levelDownLine } = context
200
200
  const copiedObj = JSON.parse(JSON.stringify(levelDownLine))
201
201
  const copiedList = copiedObj.data
202
- const resopnseData = await request.send(user.getAffiliateDashboardList({ level: currentLevel, page, row: 10 }))
202
+ const resopnseData = await request.send(user.getFriendsDashboardList({ level: currentLevel, page, row: 10 }))
203
203
  if (!!copiedList && !!resopnseData?.data) {
204
204
  const combindData = {
205
205
  ...resopnseData,
@@ -2,9 +2,10 @@ import continue_deposit_activity from './continue_deposit_activity.js'
2
2
  import deposit_activity from './deposit_activity.js'
3
3
  import diamond_shop_activity_fc from './diamond_shop_activity_fc.js'
4
4
  import diamond_shop_activity_vn from './diamond_shop_activity_vn.js'
5
+ import diamond_shop_activity_cash from './diamond_shop_activity_cash.js'
5
6
  import fafafa_activity from './fafafa_activity.js'
6
7
  import invite_friends_activity from './invite_friends_activity.js'
7
- import affiliate_invite_friends_activity from './affiliate_invite_friends_activity.js'
8
+ import friend_invite_friends_activity from './friend_invite_friends_activity.js'
8
9
  import ranking_activity from './ranking_activity.js'
9
10
  import return_bonus_activity from './return_bonus_activity.js'
10
11
  import specify_bets_activity from './specify_bets_activity.js'
@@ -21,9 +22,10 @@ export default {
21
22
  deposit_activity,
22
23
  diamond_shop_activity_fc,
23
24
  diamond_shop_activity_vn,
25
+ diamond_shop_activity_cash,
24
26
  fafafa_activity,
25
27
  invite_friends_activity,
26
- affiliate_invite_friends_activity,
28
+ friend_invite_friends_activity,
27
29
  ranking_activity,
28
30
  return_bonus_activity,
29
31
  specify_bets_activity,
@@ -12,17 +12,17 @@ export default function (request) {
12
12
  bindingCode: null,
13
13
  uidSite: null,
14
14
  receiveNo: null,
15
- affiliateCode: null,
15
+ friendCode: null,
16
16
  downlineCount: 0,
17
17
  },
18
18
  initial: 'idle',
19
19
  states: {
20
20
  idle: {
21
21
  on: {
22
- FETCH_AFFILIATE_CODE: {
22
+ FETCH_FRIEND_CODE: {
23
23
  target: 'fetching',
24
24
  },
25
- BIND_AFFILIATE_CODE: {
25
+ BIND_FRIEND_CODE: {
26
26
  target: 'binding',
27
27
  actions: ['setActivityNo', 'setBindingCode', 'setUidSite'],
28
28
  },
@@ -30,10 +30,10 @@ export default function (request) {
30
30
  },
31
31
  fetching: {
32
32
  invoke: {
33
- src: 'fetchAffiliate',
33
+ src: 'fetchFriends',
34
34
  onDone: {
35
35
  target: 'idle',
36
- actions: 'setAffiliateCode',
36
+ actions: 'setFriendCode',
37
37
  },
38
38
  onError: {
39
39
  target: 'idle',
@@ -42,7 +42,7 @@ export default function (request) {
42
42
  },
43
43
  binding: {
44
44
  invoke: {
45
- src: 'postAffiliate',
45
+ src: 'postFriends',
46
46
  onDone: {
47
47
  target: 'awarding',
48
48
  },
@@ -73,10 +73,10 @@ export default function (request) {
73
73
  },
74
74
  {
75
75
  actions: {
76
- setAffiliateCode: assign((context, event) => {
77
- const { affiliateCode, downlineCount } = event.data
76
+ setFriendCode: assign((context, event) => {
77
+ const { friendCode, downlineCount } = event.data
78
78
  return {
79
- affiliateCode,
79
+ friendCode,
80
80
  downlineCount,
81
81
  }
82
82
  }),
@@ -97,11 +97,11 @@ export default function (request) {
97
97
  }),
98
98
  },
99
99
  services: {
100
- postAffiliate: async (context, event) => {
101
- return await request.send(user.postAffiliate({ affiliateCode: context.bindingCode }))
100
+ postFriends: async (context, event) => {
101
+ return await request.send(user.postFriends({ friendCode: context.bindingCode }))
102
102
  },
103
- fetchAffiliate: async (context, event) => {
104
- return await request.send(user.getAffiliate())
103
+ fetchFriends: async (context, event) => {
104
+ return await request.send(user.getFriends())
105
105
  },
106
106
  awardPrize: async (context, event) => {
107
107
  const { activityNo, uidSite, bindingCode } = context
@@ -1,13 +1,15 @@
1
1
  import { assign, createMachine } from 'xstate'
2
2
  import api from '../../api/activity.js'
3
3
 
4
- export default function (request) {
4
+ export default function (request, context) {
5
5
  const { appSecret } = request.config
6
+ const { activityNo, isLogin = true } = context || {}
6
7
  return createMachine(
7
8
  {
8
9
  id: 'ranking_activity',
9
10
  context: {
10
- activityNo: null,
11
+ isLogin,
12
+ activityNo,
11
13
  activityDetail: null,
12
14
  duration: null,
13
15
  status: 'not-started', // "not-started" | "started" | "finished"
@@ -15,6 +17,13 @@ export default function (request) {
15
17
  initial: 'idle',
16
18
  states: {
17
19
  idle: {
20
+ entry: 'reset',
21
+ always: [
22
+ {
23
+ target: 'loading',
24
+ cond: 'isLoadable',
25
+ },
26
+ ],
18
27
  on: {
19
28
  SET_ACTIVITY_NO: {
20
29
  target: 'loading',
@@ -45,6 +54,16 @@ export default function (request) {
45
54
  },
46
55
  expired: {},
47
56
  },
57
+ on: {
58
+ START: {
59
+ target: '.idle',
60
+ actions: assign((context, event) => ({ isLogin: true })),
61
+ },
62
+ STOP: {
63
+ target: '.idle',
64
+ actions: assign((context, event) => ({ isLogin: false })),
65
+ },
66
+ },
48
67
  },
49
68
  {
50
69
  actions: {
@@ -78,8 +97,18 @@ export default function (request) {
78
97
  }
79
98
  }
80
99
  }),
100
+ reset: assign((context, event) => {
101
+ return {
102
+ activityDetail: null,
103
+ duration: 0,
104
+ status: 'not-started',
105
+ }
106
+ }),
81
107
  },
82
108
  guards: {
109
+ isLoadable: (context, event) => {
110
+ return context.isLogin && context.activityNo
111
+ },
83
112
  isExpired: (context, event) => {
84
113
  return context.duration <= 0
85
114
  },