@jetthai/cuora 1.1.84 → 1.1.85-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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jetthai/cuora",
3
- "version": "1.1.84",
3
+ "version": "1.1.85-cash",
4
4
  "description": "",
5
5
  "main": "./src/index.js",
6
6
  "type": "module",
@@ -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,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
+ }
@@ -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
@@ -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 friend_invite_friends_activity from './friend_invite_friends_activity.js'
@@ -21,6 +22,7 @@ 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
28
  friend_invite_friends_activity,
@@ -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
  },
@@ -1,19 +1,29 @@
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: 'specify_bets_activity',
9
10
  context: {
10
- activityNo: null,
11
+ isLogin,
12
+ activityNo,
11
13
  activityDetail: null,
12
14
  callback: () => {},
15
+ duration: 0,
13
16
  },
14
17
  initial: 'idle',
15
18
  states: {
16
19
  idle: {
20
+ entry: 'reset',
21
+ always: [
22
+ {
23
+ target: 'loading',
24
+ cond: 'isLoadable',
25
+ },
26
+ ],
17
27
  on: {
18
28
  SET_ACTIVITY_NO: {
19
29
  target: 'loading',
@@ -40,7 +50,14 @@ export default function (request) {
40
50
  { target: 'receivable', cond: 'isReceivable' },
41
51
  ],
42
52
  },
43
- ongoing: {},
53
+ ongoing: {
54
+ entry: 'setDuration',
55
+ after: {
56
+ 1000: {
57
+ target: 'ongoing',
58
+ },
59
+ },
60
+ },
44
61
  received: {},
45
62
  receivable: {
46
63
  on: {
@@ -63,6 +80,16 @@ export default function (request) {
63
80
  },
64
81
  },
65
82
  },
83
+ on: {
84
+ START: {
85
+ target: '.idle',
86
+ actions: assign((context, event) => ({ isLogin: true })),
87
+ },
88
+ STOP: {
89
+ target: '.idle',
90
+ actions: assign((context, event) => ({ isLogin: false })),
91
+ },
92
+ },
66
93
  },
67
94
  {
68
95
  actions: {
@@ -84,8 +111,22 @@ export default function (request) {
84
111
  doCallback: (context, event) => {
85
112
  context.callback(event.data.type)
86
113
  },
114
+ setDuration: assign((context, event) => {
115
+ return {
116
+ duration: Math.max(context?.activityDetail?.activityEndTime - new Date().getTime() / 1000, 0),
117
+ }
118
+ }),
119
+ reset: assign((context, event) => {
120
+ return {
121
+ activityDetail: null,
122
+ duration: 0,
123
+ }
124
+ }),
87
125
  },
88
126
  guards: {
127
+ isLoadable: (context, event) => {
128
+ return context.isLogin && context.activityNo
129
+ },
89
130
  isReceivable: (context, event) => {
90
131
  return context.activityDetail?.receiveStatus === 2
91
132
  },
@@ -1,19 +1,29 @@
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: 'specify_turnover_activity',
9
10
  context: {
10
- activityNo: null,
11
+ isLogin,
12
+ activityNo,
11
13
  activityDetail: null,
12
14
  callback: () => {},
15
+ duration: 0,
13
16
  },
14
17
  initial: 'idle',
15
18
  states: {
16
19
  idle: {
20
+ entry: 'reset',
21
+ always: [
22
+ {
23
+ target: 'loading',
24
+ cond: 'isLoadable',
25
+ },
26
+ ],
17
27
  on: {
18
28
  SET_ACTIVITY_NO: {
19
29
  target: 'loading',
@@ -40,7 +50,14 @@ export default function (request) {
40
50
  { target: 'receivable', cond: 'isReceivable' },
41
51
  ],
42
52
  },
43
- ongoing: {},
53
+ ongoing: {
54
+ entry: 'setDuration',
55
+ after: {
56
+ 1000: {
57
+ target: 'ongoing',
58
+ },
59
+ },
60
+ },
44
61
  received: {},
45
62
  receivable: {
46
63
  on: {
@@ -63,6 +80,16 @@ export default function (request) {
63
80
  },
64
81
  },
65
82
  },
83
+ on: {
84
+ START: {
85
+ target: '.idle',
86
+ actions: assign((context, event) => ({ isLogin: true })),
87
+ },
88
+ STOP: {
89
+ target: '.idle',
90
+ actions: assign((context, event) => ({ isLogin: false })),
91
+ },
92
+ },
66
93
  },
67
94
  {
68
95
  actions: {
@@ -84,8 +111,22 @@ export default function (request) {
84
111
  doCallback: (context, event) => {
85
112
  context.callback(event.data.type)
86
113
  },
114
+ setDuration: assign((context, event) => {
115
+ return {
116
+ duration: Math.max(context?.activityDetail?.activityEndTime - new Date().getTime() / 1000, 0),
117
+ }
118
+ }),
119
+ reset: assign((context, event) => {
120
+ return {
121
+ activityDetail: null,
122
+ duration: 0,
123
+ }
124
+ }),
87
125
  },
88
126
  guards: {
127
+ isLoadable: (context, event) => {
128
+ return context.isLogin && context.activityNo
129
+ },
89
130
  isReceivable: (context, event) => {
90
131
  return context.activityDetail?.receiveStatus === 2
91
132
  },
@@ -330,7 +330,7 @@ export default function (request) {
330
330
  })
331
331
  sentry.setTag('dt', dt)
332
332
 
333
- const ac = storage.get('ac')
333
+ const affiliateCode = storage.get('ac')
334
334
  const messages = {
335
335
  url: window.location.href,
336
336
  channelOrders: [
@@ -338,13 +338,13 @@ export default function (request) {
338
338
  { channel: defaultChannel, subchannel: defaultSubchannel },
339
339
  { channel: channel, subchannel: subchannel },
340
340
  ],
341
- ac,
341
+ affiliateCode,
342
342
  }
343
343
  sentry.captureMessage(JSON.stringify(messages))
344
344
 
345
345
  const referralObj = {}
346
- if (![undefined, 'undefined', null, 'null'].includes(ac)) {
347
- referralObj.ac = ac
346
+ if (![undefined, 'undefined', null, 'null'].includes(affiliateCode)) {
347
+ referralObj.ac = affiliateCode
348
348
  } else {
349
349
  ;(referralObj.channel = storage.get('channel') || defaultChannel || channel),
350
350
  (referralObj.subchannel = storage.get('subchannel') || defaultSubchannel || subchannel)
@@ -7,13 +7,15 @@ import storage from '../util/storage.js'
7
7
  // const pickBy = require('lodash/pickBy')
8
8
  // const UAParser = require('ua-parser-js')
9
9
 
10
- export default function (request) {
10
+ export default function (request, context) {
11
+ const { site } = context || {}
11
12
  const { appSecret, defaultChannel, defaultSubchannel } = request.config
12
13
  return createMachine(
13
14
  {
14
15
  id: 'common',
15
16
  type: 'parallel',
16
17
  context: {
18
+ site,
17
19
  tick: 2000,
18
20
  siteConfig: {
19
21
  cs: {
@@ -42,6 +44,7 @@ export default function (request) {
42
44
  channel: null,
43
45
  subchannel: null,
44
46
  affiliateCode: null,
47
+ friendCode: null,
45
48
  },
46
49
  states: {
47
50
  config: {
@@ -157,7 +160,8 @@ export default function (request) {
157
160
  let urlParams = new URLSearchParams(window.location.search)
158
161
  const channel = urlParams.get('channel') || storage.get('channel') || defaultChannel || 'official'
159
162
  const subchannel = urlParams.get('subchannel') || storage.get('subchannel') || defaultSubchannel || 'pwa'
160
- const ac = urlParams.get('ac') || urlParams.get('referralCode') || storage.get('ac') || storage.get('referralCode')
163
+ const affiliateCode = urlParams.get('ac') || urlParams.get('referralCode') || storage.get('ac') || storage.get('referralCode')
164
+ const friendCode = urlParams.get('fc') || urlParams.get('affiliate') || storage.get('fc') || storage.get(`${context.site}_affiliate`)
161
165
 
162
166
  storage.set('channel', channel, {
163
167
  path: '/',
@@ -167,7 +171,11 @@ export default function (request) {
167
171
  path: '/',
168
172
  maxAge: 60 * 60 * 24 * 7,
169
173
  })
170
- storage.set('ac', ac, {
174
+ storage.set('ac', affiliateCode, {
175
+ path: '/',
176
+ maxAge: 60 * 60 * 24 * 7,
177
+ })
178
+ storage.set('fc', friendCode, {
171
179
  path: '/',
172
180
  maxAge: 60 * 60 * 24 * 7,
173
181
  })
@@ -175,7 +183,8 @@ export default function (request) {
175
183
  return {
176
184
  channel,
177
185
  subchannel,
178
- ac,
186
+ affiliateCode,
187
+ friendCode,
179
188
  }
180
189
  }
181
190
  }),