@jetthai/cuora 1.0.84 → 1.0.86

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,10 @@
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.0.86](https://github.com/jetthai/cuora-module/compare/v1.0.85...v1.0.86) (2022-02-07)
6
+
7
+ ### [1.0.85](https://github.com/jetthai/cuora-module/compare/v1.0.84...v1.0.85) (2022-01-25)
8
+
5
9
  ### [1.0.84](https://github.com/jetthai/cuora-module/compare/v1.0.83...v1.0.84) (2022-01-20)
6
10
 
7
11
  ### [1.0.83](https://github.com/jetthai/cuora-module/compare/v1.0.82...v1.0.83) (2022-01-18)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jetthai/cuora",
3
- "version": "1.0.84",
3
+ "version": "1.0.86",
4
4
  "description": "",
5
5
  "main": "./src/index.js",
6
6
  "scripts": {
@@ -1,6 +1,6 @@
1
1
  export default {
2
2
  getActivityTypes: ({ appSecret }) => ({ url: 'activities/types', method: 'get', params: { appSecret } }),
3
- getActivityList: ({ appSecret, include }) => ({
3
+ getActivityList: ({ appSecret, include = 'cl' }) => ({
4
4
  url: 'activities/list',
5
5
  method: 'get',
6
6
  params: { appSecret, include },
package/src/api/auth.js CHANGED
@@ -1,8 +1,8 @@
1
1
  export default {
2
- login: ({ username, password, provider, countryCode, phone, email }) => ({
2
+ login: ({ username, password, provider, countryCode, phone, email, dt }) => ({
3
3
  url: 'login',
4
4
  method: 'post',
5
- params: { username, password, provider, countryCode, phone, email },
5
+ params: { username, password, provider, countryCode, phone, email, dt },
6
6
  isPublic: true,
7
7
  }),
8
8
  register: ({ channel = 'official', subchannel = 'pwa', ...rest }) => ({
@@ -58,7 +58,7 @@ export default function (request) {
58
58
  },
59
59
  services: {
60
60
  fetchActivityList: async (context, event) => {
61
- const { data } = await request.send(api.getActivityList({ appSecret, include: 'cl' }))
61
+ const { data } = await request.send(api.getActivityList({ appSecret }))
62
62
  return data
63
63
  },
64
64
  },
@@ -14,16 +14,30 @@ export default function (request) {
14
14
  exchangeAward: 0,
15
15
  exchangePoint: 0,
16
16
  },
17
- initial: 'idle',
17
+ initial: 'fetching',
18
18
  states: {
19
+ fetching: {
20
+ invoke: {
21
+ src: 'fetchActivityList',
22
+ onDone: {
23
+ target: 'checking',
24
+ actions: 'setDiamondShopActivities',
25
+ },
26
+ onError: {
27
+ target: 'idle',
28
+ },
29
+ },
30
+ },
19
31
  idle: {
20
32
  on: {
21
33
  SET_ACTIVITY_NO: {
22
- target: 'loading',
23
- actions: 'setActivityNo',
34
+ // todo - deprecated
24
35
  },
25
36
  },
26
37
  },
38
+ checking: {
39
+ always: [{ target: 'loading', cond: 'hasActivityNo' }],
40
+ },
27
41
  loading: {
28
42
  invoke: {
29
43
  src: 'fetchActivityDetail',
@@ -93,6 +107,13 @@ export default function (request) {
93
107
  activityNo: event.data,
94
108
  }
95
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
+ }),
96
117
  setActivityDetail: assign((context, event) => {
97
118
  return {
98
119
  activityDetail: event.data,
@@ -138,8 +159,15 @@ export default function (request) {
138
159
  const { exchangeList } = context
139
160
  return exchangeList.length > 0
140
161
  },
162
+ hasActivityNo: (context, event) => {
163
+ return !!context.activityNo
164
+ },
141
165
  },
142
166
  services: {
167
+ fetchActivityList: async (context, event) => {
168
+ const { data } = await request.send(api.getActivityList({ appSecret }))
169
+ return data
170
+ },
143
171
  fetchActivityDetail: async (context, event) => {
144
172
  const { activityNo } = context
145
173
  const { data } = await request.send(api.getActivityDetail({ activityNo, appSecret }))
@@ -0,0 +1,214 @@
1
+ import { createMachine, assign } from 'xstate'
2
+ import { api } from '@jetthai/cuora'
3
+
4
+ export default function (request) {
5
+ const { appSecret } = request.config
6
+ const apiActivity = api.activity
7
+ return createMachine(
8
+ {
9
+ id: 'diamond_shop_activity',
10
+ context: {
11
+ activityNo: null,
12
+ activityDetail: null,
13
+ awards: [],
14
+ exchangeList: [],
15
+ exchangeAward: 0,
16
+ exchangePoint: 0,
17
+ remainingPoints: 0,
18
+ receiveRewards: [],
19
+ unclaimedRewardList: [],
20
+ },
21
+ initial: 'fetching',
22
+ states: {
23
+ fetching: {
24
+ invoke: {
25
+ src: 'fetchActivityList',
26
+ onDone: {
27
+ target: 'checking',
28
+ actions: 'setDiamondShopActivities',
29
+ },
30
+ onError: {
31
+ target: 'idle',
32
+ },
33
+ },
34
+ },
35
+ idle: {
36
+ on: {
37
+ SET_ACTIVITY_NO: {
38
+ // todo - deprecated
39
+ },
40
+ },
41
+ },
42
+ checking: {
43
+ always: [{ target: 'loading', cond: 'hasActivityNo' }],
44
+ },
45
+ loading: {
46
+ invoke: {
47
+ src: 'fetchActivityDetail',
48
+ onDone: {
49
+ target: 'loaded',
50
+ actions: ['setActivityDetail', 'setAwardList', 'setUnclaimedReward'],
51
+ },
52
+ onError: {
53
+ target: 'idle',
54
+ },
55
+ },
56
+ },
57
+ loaded: {
58
+ on: {
59
+ EXCHANGE: {
60
+ target: 'exchanging',
61
+ },
62
+ ADD_TO_CART: {
63
+ actions: ['addProduct', 'count'],
64
+ },
65
+ CLEAR_CART: {
66
+ actions: ['clearCart', 'count'],
67
+ },
68
+ COLLECT: {
69
+ target: 'collecting',
70
+ cond: 'hasUnclaimedReward',
71
+ },
72
+ },
73
+ },
74
+ exchanging: {
75
+ invoke: {
76
+ src: 'exchange',
77
+ onDone: {
78
+ target: 'loaded',
79
+ actions: ['setExchangedData', 'setUnclaimedReward'],
80
+ },
81
+ onError: {
82
+ target: 'loaded',
83
+ },
84
+ },
85
+ },
86
+ collecting: {
87
+ invoke: {
88
+ src: 'collect',
89
+ onDone: {
90
+ target: 'collected',
91
+ actions: 'clearExchangedData',
92
+ },
93
+ onError: {
94
+ target: 'collected',
95
+ },
96
+ },
97
+ },
98
+ collected: {
99
+ after: {
100
+ 0: {
101
+ target: 'loaded',
102
+ },
103
+ },
104
+ },
105
+ },
106
+ },
107
+ {
108
+ actions: {
109
+ setActivityNo: assign((context, event) => {
110
+ return {
111
+ activityNo: event.data,
112
+ }
113
+ }),
114
+ setDiamondShopActivities: assign((context, event) => {
115
+ const rankActivities = event.data.filter((item) => item.activityType === 91)
116
+ return {
117
+ rankActivities,
118
+ activityNo: rankActivities?.[0]?.activityNo,
119
+ }
120
+ }),
121
+ setActivityDetail: assign((context, event) => {
122
+ return {
123
+ activityDetail: event.data,
124
+ }
125
+ }),
126
+ setAwardList: assign((context, event) => {
127
+ return {
128
+ awardList: event.data?.awards || [],
129
+ }
130
+ }),
131
+ setExchangedData: assign((context, event) => {
132
+ return {
133
+ remainingPoints: event.data?.data?.points,
134
+ receiveRewards: event.data?.date?.receiveRewards,
135
+ }
136
+ }),
137
+ setUnclaimedReward: assign((context, event) => {
138
+ return {
139
+ unclaimedRewardList: event.data?.unclaimedReward || event.data?.data?.unclaimedReward || [],
140
+ }
141
+ }),
142
+ clearExchangedData: assign((context, event) => {
143
+ return {
144
+ remainingPoints: null,
145
+ receiveRewards: [],
146
+ unclaimedRewardList: [],
147
+ }
148
+ }),
149
+ addProduct: assign((context, event) => {
150
+ return {
151
+ exchangeList: [...context.exchangeList, event.data],
152
+ }
153
+ }),
154
+ clearCart: assign((context, event) => {
155
+ return {
156
+ exchangeList: [],
157
+ }
158
+ }),
159
+ count: assign((context, event) => {
160
+ const { exchangeList } = context
161
+ const { exchangeAward, exchangePoint } = exchangeList.reduce(
162
+ ({ exchangeAward, exchangePoint }, item) => {
163
+ return {
164
+ exchangeAward: exchangeAward + item.award,
165
+ exchangePoint: exchangePoint + item.points,
166
+ }
167
+ },
168
+ { exchangeAward: 0, exchangePoint: 0 }
169
+ )
170
+ return {
171
+ exchangeAward,
172
+ exchangePoint,
173
+ }
174
+ }),
175
+ },
176
+ guards: {
177
+ hasUnclaimedReward: (context, event) => {
178
+ return context.unclaimedRewardList.length > 0
179
+ },
180
+ isExchangeable: (context, event) => {
181
+ const { exchangeList } = context
182
+ return exchangeList.length > 0
183
+ },
184
+ hasActivityNo: (context, event) => {
185
+ return !!context.activityNo
186
+ },
187
+ },
188
+ services: {
189
+ fetchActivityList: async (context, event) => {
190
+ const { data } = await request.send(apiActivity.getActivityList({ appSecret }))
191
+ return data
192
+ },
193
+ fetchActivityDetail: async (context, event) => {
194
+ const { activityNo } = context
195
+ const { data } = await request.send(apiActivity.getActivityDetail({ activityNo, appSecret }))
196
+ return data
197
+ },
198
+ exchange: async (context, event) => {
199
+ const { activityNo } = context
200
+ return await request.send(
201
+ apiActivity.exchange({
202
+ exchangeType: 1,
203
+ activityNo,
204
+ exchangeAward: event.data,
205
+ })
206
+ )
207
+ },
208
+ collect: async (context, event) => {
209
+ return await request.send(apiActivity.collect({ appSecret }))
210
+ },
211
+ },
212
+ }
213
+ )
214
+ }
@@ -1,6 +1,7 @@
1
1
  import continue_deposit_activity from './continue_deposit_activity'
2
2
  import deposit_activity from './deposit_activity'
3
- import diamond_shop_activity from './diamond_shop_activity'
3
+ import diamond_shop_activity_fc from './diamond_shop_activity_fc'
4
+ import diamond_shop_activity_vn from './diamond_shop_activity_vn'
4
5
  import fafafa_activity from './fafafa_activity'
5
6
  import invite_friends_activity from './invite_friends_activity'
6
7
  import ranking_activity from './ranking_activity'
@@ -13,7 +14,8 @@ import activity from './activity'
13
14
  export default {
14
15
  continue_deposit_activity,
15
16
  deposit_activity,
16
- diamond_shop_activity,
17
+ diamond_shop_activity_fc,
18
+ diamond_shop_activity_vn,
17
19
  fafafa_activity,
18
20
  invite_friends_activity,
19
21
  ranking_activity,
@@ -35,7 +35,10 @@ export default function (request) {
35
35
  },
36
36
  },
37
37
  checking: {
38
- always: [{ target: 'idle', actions: 'setActivityDetail', cond: 'isExist' }, { target: 'loading' }],
38
+ always: [
39
+ { target: 'idle', actions: 'setActivityDetail', cond: 'isExist' },
40
+ { target: 'loading', cond: 'hasActivityNo' },
41
+ ],
39
42
  },
40
43
  loading: {
41
44
  invoke: {
@@ -85,10 +88,13 @@ export default function (request) {
85
88
  const { activityMap, activityNo } = context
86
89
  return activityMap[activityNo]
87
90
  },
91
+ hasActivityNo: (context, event) => {
92
+ return !!context.activityNo
93
+ },
88
94
  },
89
95
  services: {
90
96
  fetchActivityList: async (context, event) => {
91
- const { data } = await request.send(api.getActivityList({ appSecret, include: 'cl' }))
97
+ const { data } = await request.send(api.getActivityList({ appSecret }))
92
98
  return data
93
99
  },
94
100
  fetchActivityDetail: async (context, event) => {
@@ -276,7 +276,9 @@ export default function (request) {
276
276
  },
277
277
  services: {
278
278
  authenticate: async (context, event) => {
279
- const { token } = await request.send(auth.login(context.loginData))
279
+ const dt = await getDeviceToken(fpToken)
280
+ const data = { ...context.loginData, dt }
281
+ const { token } = await request.send(auth.login(data))
280
282
  return token
281
283
  },
282
284
  logout: async (context, event) => {