@jetthai/cuora 1.1.82 → 1.1.83-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.82",
3
+ "version": "1.1.83-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'
@@ -14,12 +15,14 @@ import time_bomb_activity from './time_bomb_activity.js'
14
15
  import mini_game_activity from './mini_game_activity.js'
15
16
  import roulette_activity_v2 from './roulette_activity_v2.js'
16
17
  import activity from './activity.js'
18
+ import otp_verified_activity from './otp_verified_activity.js'
17
19
 
18
20
  export default {
19
21
  continue_deposit_activity,
20
22
  deposit_activity,
21
23
  diamond_shop_activity_fc,
22
24
  diamond_shop_activity_vn,
25
+ diamond_shop_activity_cash,
23
26
  fafafa_activity,
24
27
  invite_friends_activity,
25
28
  friend_invite_friends_activity,
@@ -32,4 +35,5 @@ export default {
32
35
  mini_game_activity,
33
36
  roulette_activity_v2,
34
37
  activity,
38
+ otp_verified_activity,
35
39
  }
@@ -0,0 +1,74 @@
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: 'otp_verified_activity',
9
+ context: {
10
+ activityNo: null,
11
+ activityDetail: null,
12
+ stages: [],
13
+ currentStage: {},
14
+ receiveNo: null,
15
+ rewardType: '',
16
+ callback: () => {},
17
+ },
18
+ initial: 'idle',
19
+ states: {
20
+ idle: {
21
+ on: {
22
+ SET_ACTIVITY_NO: {
23
+ target: 'loading',
24
+ actions: 'setActivityNo',
25
+ },
26
+ },
27
+ },
28
+ loading: {
29
+ invoke: {
30
+ src: 'fetchActivityDetail',
31
+ onDone: {
32
+ target: 'loaded',
33
+ actions: 'setActivityDetail',
34
+ },
35
+ onError: {
36
+ target: 'idle',
37
+ },
38
+ },
39
+ },
40
+ loaded: {
41
+ always: [{ target: 'received', cond: 'isReceived' }],
42
+ },
43
+ received: {},
44
+ },
45
+ },
46
+ {
47
+ actions: {
48
+ setActivityNo: assign((context, event) => {
49
+ return {
50
+ activityNo: event.data,
51
+ }
52
+ }),
53
+ setActivityDetail: assign((context, event) => {
54
+ return {
55
+ activityDetail: event.data,
56
+ }
57
+ }),
58
+ },
59
+ guards: {
60
+ isReceived: (context, event) => {
61
+ const { receiveStatus } = context.activityDetail
62
+ return receiveStatus === 1
63
+ },
64
+ },
65
+ services: {
66
+ fetchActivityDetail: async (context, event) => {
67
+ const { activityNo } = context
68
+ const { data } = await request.send(api.getActivityDetail({ activityNo, appSecret }))
69
+ return data
70
+ },
71
+ },
72
+ }
73
+ )
74
+ }
@@ -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
  },
@@ -1,6 +1,7 @@
1
1
  import manual_vn from './manual_vn.js'
2
2
  import loadcard_vn from './loadcard_vn.js'
3
3
  import qrcode_v2 from './qrcode_v2.js'
4
+ import qrcode_v_cash from './qrcode_v_cash.js'
4
5
  import deposit_fc from './deposit_fc.js'
5
6
  import crypto from './crypto.js'
6
7
  import crypto_button from './crypto_button.js'
@@ -14,6 +15,7 @@ export default {
14
15
  manual_vn,
15
16
  loadcard_vn,
16
17
  qrcode_v2,
18
+ qrcode_v_cash,
17
19
  deposit_fc,
18
20
  crypto,
19
21
  crypto_button,