@jetthai/cuora 1.1.77-cash-2 → 1.1.77-cash-3
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/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
### [1.1.77-cash-3](https://github.com/jetthai/cuora-module/compare/v1.1.77-cash-2...v1.1.77-cash-3) (2023-04-19)
|
|
6
|
+
|
|
5
7
|
### [1.1.77-cash-2](https://github.com/jetthai/cuora-module/compare/v1.1.77-cash-1...v1.1.77-cash-2) (2023-04-18)
|
|
6
8
|
|
|
7
9
|
### [1.1.77-cash-1](https://github.com/jetthai/cuora-module/compare/v1.1.77-cash...v1.1.77-cash-1) (2023-04-16)
|
package/package.json
CHANGED
|
@@ -0,0 +1,215 @@
|
|
|
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.exchange({
|
|
203
|
+
exchangeType: 1,
|
|
204
|
+
activityNo,
|
|
205
|
+
exchangeAward: event.data,
|
|
206
|
+
})
|
|
207
|
+
)
|
|
208
|
+
},
|
|
209
|
+
collect: async (context, event) => {
|
|
210
|
+
return await request.send(api.collect({ appSecret }))
|
|
211
|
+
},
|
|
212
|
+
},
|
|
213
|
+
}
|
|
214
|
+
)
|
|
215
|
+
}
|
|
@@ -31,7 +31,13 @@ export default function (request) {
|
|
|
31
31
|
},
|
|
32
32
|
},
|
|
33
33
|
},
|
|
34
|
-
idle: {
|
|
34
|
+
idle: {
|
|
35
|
+
on: {
|
|
36
|
+
SET_ACTIVITY_NO: {
|
|
37
|
+
// todo - deprecated
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
},
|
|
35
41
|
checking: {
|
|
36
42
|
always: [{ target: 'loading', cond: 'hasActivityNo' }],
|
|
37
43
|
},
|
|
@@ -52,9 +58,6 @@ export default function (request) {
|
|
|
52
58
|
EXCHANGE: {
|
|
53
59
|
target: 'exchanging',
|
|
54
60
|
},
|
|
55
|
-
SELECT: {
|
|
56
|
-
actions: ['selectProduct', 'count'],
|
|
57
|
-
},
|
|
58
61
|
ADD_TO_CART: {
|
|
59
62
|
actions: ['addProduct', 'count'],
|
|
60
63
|
},
|
|
@@ -142,11 +145,6 @@ export default function (request) {
|
|
|
142
145
|
unclaimedRewardList: [],
|
|
143
146
|
}
|
|
144
147
|
}),
|
|
145
|
-
selectProduct: assign((context, event) => {
|
|
146
|
-
return {
|
|
147
|
-
exchangeList: [event.data],
|
|
148
|
-
}
|
|
149
|
-
}),
|
|
150
148
|
addProduct: assign((context, event) => {
|
|
151
149
|
return {
|
|
152
150
|
exchangeList: [...context.exchangeList, event.data],
|
|
@@ -2,6 +2,7 @@ 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
8
|
import affiliate_invite_friends_activity from './affiliate_invite_friends_activity.js'
|
|
@@ -20,6 +21,7 @@ export default {
|
|
|
20
21
|
deposit_activity,
|
|
21
22
|
diamond_shop_activity_fc,
|
|
22
23
|
diamond_shop_activity_vn,
|
|
24
|
+
diamond_shop_activity_cash,
|
|
23
25
|
fafafa_activity,
|
|
24
26
|
invite_friends_activity,
|
|
25
27
|
affiliate_invite_friends_activity,
|