@jetthai/cuora 1.1.127 → 1.1.128-dev-2

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 (70) hide show
  1. package/CHANGELOG.md +426 -0
  2. package/package.json +1 -1
  3. package/src/api/activity.js +28 -0
  4. package/src/api/auth.js +6 -0
  5. package/src/api/common.js +2 -1
  6. package/src/api/game.js +5 -4
  7. package/src/api/mailbox.js +9 -5
  8. package/src/api/payment.js +103 -8
  9. package/src/api/user.js +2 -0
  10. package/src/machine/activity/activity.js +56 -16
  11. package/src/machine/activity/activity_cash.js +78 -14
  12. package/src/machine/activity/cash_rain_activity.js +153 -0
  13. package/src/machine/activity/diamond_shop_activity_cash.js +57 -92
  14. package/src/machine/activity/diamond_shop_activity_vn.js +54 -89
  15. package/src/machine/activity/fafafa_activity.js +8 -1
  16. package/src/machine/activity/friend_invite_friends_activity.js +3 -1
  17. package/src/machine/activity/index.js +6 -0
  18. package/src/machine/activity/instant_rebate_activity.js +214 -0
  19. package/src/machine/activity/roulette_activity_v2.js +11 -2
  20. package/src/machine/activity/sign_in_activity.js +20 -13
  21. package/src/machine/activity/vip_card_activity.js +140 -0
  22. package/src/machine/auth.js +54 -5
  23. package/src/machine/bank_binding.js +112 -12
  24. package/src/machine/bank_binding_amb.js +6 -1
  25. package/src/machine/common.js +92 -24
  26. package/src/machine/deposit/amb.js +5 -3
  27. package/src/machine/deposit/crypto.js +14 -10
  28. package/src/machine/deposit/crypto_bank.js +317 -0
  29. package/src/machine/deposit/crypto_bank_cash.js +280 -0
  30. package/src/machine/deposit/crypto_button.js +9 -5
  31. package/src/machine/deposit/crypto_cash.js +2 -5
  32. package/src/machine/deposit/crypto_qrcode.js +147 -0
  33. package/src/machine/deposit/crypto_qrcode_cash.js +131 -0
  34. package/src/machine/deposit/crypto_way.js +220 -0
  35. package/src/machine/deposit/crypto_way_cash.js +242 -0
  36. package/src/machine/deposit/direct.js +2 -11
  37. package/src/machine/deposit/direct_cash.js +6 -26
  38. package/src/machine/deposit/float.js +5 -3
  39. package/src/machine/deposit/index.js +14 -0
  40. package/src/machine/deposit/krway.js +151 -0
  41. package/src/machine/deposit/loadcard_cash.js +6 -27
  42. package/src/machine/deposit/loadcard_vn.js +2 -10
  43. package/src/machine/deposit/manual_cash.js +89 -38
  44. package/src/machine/deposit/manual_vn.js +104 -48
  45. package/src/machine/deposit/qrcode_cash.js +12 -23
  46. package/src/machine/deposit/qrcode_v2.js +3 -8
  47. package/src/machine/deposit/usdt_cash.js +0 -2
  48. package/src/machine/deposit/vpay.js +5 -3
  49. package/src/machine/game_info.js +57 -0
  50. package/src/machine/game_search_cash.js +137 -12
  51. package/src/machine/game_search_v2.js +4 -4
  52. package/src/machine/game_v2_1.js +131 -7
  53. package/src/machine/honor_board_cash.js +63 -0
  54. package/src/machine/inbox.js +259 -34
  55. package/src/machine/index.js +6 -0
  56. package/src/machine/leaderboard.js +31 -8
  57. package/src/machine/reward_cash.js +1 -1
  58. package/src/machine/side_v2.js +1 -1
  59. package/src/machine/user_photo.js +65 -0
  60. package/src/machine/user_sign_up.js +71 -7
  61. package/src/machine/withdraw/index.js +6 -0
  62. package/src/machine/withdraw/withdraw_crypto.js +1 -66
  63. package/src/machine/withdraw/withdraw_crypto2.js +540 -0
  64. package/src/machine/withdraw/withdraw_krway.js +207 -0
  65. package/src/machine/withdraw/withdraw_manual.js +595 -0
  66. package/src/machine/withdraw/withdraw_manual_cash.js +44 -14
  67. package/src/machine/withdraw/withdraw_vn.js +42 -7
  68. package/src/machine/withdraw/withdraw_vn2.js +64 -37
  69. package/src/util/constant.js +18 -0
  70. package/src/util/deviceToken.js +2 -2
@@ -1,5 +1,4 @@
1
1
  export default {
2
- // getPaymentHistory: () => ({ url: 'payment/history', method: 'post' }),
3
2
  getPaymentHistory: (returnDays) => ({ url: 'payment/v2/history', method: 'post', params: { returnDays } }),
4
3
  getSpotMarket: () => ({ url: 'payment/spotmarket', method: 'get' }),
5
4
  getTransactionHistory: (payload) => ({
@@ -8,14 +7,34 @@ export default {
8
7
  params: { ...payload },
9
8
  }),
10
9
  getTransactionHistoryOptions: () => ({ url: 'payment/v2/category/options', method: 'get' }),
11
- // getPaymentInfo: () => ({ url: `payment/paymentInfo`, method: 'get' }),
12
10
  getPaymentInfo: () => ({ url: `payment/v2/paymentInfo`, method: 'get' }),
13
- updatePaymentInfo: ({ bankCode, branch, holderName, bankAccount, firstNameTh, lastNameTh, firstNameEn, lastNameEn, bonus, paymentProvider }) => ({
11
+ getBindingPaymentInfo: () => ({ url: `payment/getBindingPaymentInfo`, method: 'get' }),
12
+ updatePaymentInfo: ({
13
+ bankCode,
14
+ branch,
15
+ branchCode,
16
+ holderName,
17
+ bankAccount,
18
+ firstNameTh,
19
+ lastNameTh,
20
+ firstNameEn,
21
+ lastNameEn,
22
+ bonus,
23
+ paymentProvider,
24
+ pixType,
25
+ bindingType,
26
+ cryptoCurrency,
27
+ cryptoNetwork,
28
+ cryptoAddress,
29
+ walletCode,
30
+ ifscCode,
31
+ }) => ({
14
32
  url: 'payment/v2/updatePaymentInfo',
15
33
  method: 'post',
16
34
  params: {
17
35
  bankCode,
18
36
  branch,
37
+ branchCode,
19
38
  holderName,
20
39
  bankAccount,
21
40
  firstNameTh,
@@ -24,9 +43,19 @@ export default {
24
43
  lastNameEn,
25
44
  bonus,
26
45
  paymentProvider,
46
+ pixType,
47
+ bindingType,
48
+ cryptoCurrency,
49
+ cryptoNetwork,
50
+ cryptoAddress,
51
+ walletCode,
52
+ ifscCode,
27
53
  },
28
54
  }),
29
55
  getBankList: (paymentMethod) => ({ url: `payment/v2/${paymentMethod}/getBankList`, method: 'get' }),
56
+ getBindingBankList: ({ appSecret }) => ({ url: 'payment/v2/getBindingBankList', method: 'get', params: { appSecret }, isPublic: true }),
57
+ getBindingPaymentList: ({ appSecret }) => ({ url: 'payment/getBindingPaymentList', method: 'get', params: { appSecret }, isPublic: true }),
58
+ getWithdrawBankList: () => ({ url: 'payment/v2/getWithdrawBankList', method: 'get' }),
30
59
  makeTransaction: ({ type, payload, paymentMethod }) => ({
31
60
  url: `payment/v2/${paymentMethod}/transaction`,
32
61
  method: 'post',
@@ -59,15 +88,39 @@ export default {
59
88
  method: 'post',
60
89
  params: { transferType: 'DEPOSIT', amount, cryptoCurrency, promotionsNo },
61
90
  }),
91
+ getCryptoDepositExpectedResult: ({ method, amount, cryptoCurrency, promotionsNo }) => ({
92
+ url: `payment/v2/${method}/crypto/expected/result`,
93
+ method: 'post',
94
+ params: { transferType: 'DEPOSIT', amount, cryptoCurrency, promotionsNo },
95
+ }),
96
+ getCryptoWithdrawExpectedResult: ({ method, amount, cryptoCurrency, promotionsNo }) => ({
97
+ url: `payment/v2/${method}/crypto/expected/result`,
98
+ method: 'post',
99
+ params: { transferType: 'WITHDRAW', amount, cryptoCurrency, promotionsNo },
100
+ }),
62
101
  getWithdrawExpectedResult: ({ method, amount, cryptoNetwork }) => ({
63
102
  url: `payment/v2/${method}/expected/result`,
64
103
  method: 'post',
65
104
  params: { transferType: 'WITHDRAW', amount, cryptoNetwork },
66
105
  }),
67
- submitDepositTransactionCrypto: ({ method, amount, cryptoCurrency, cryptoNetwork, sourceAddress, promotionsNo }) => ({
106
+ submitDepositTransactionCrypto: ({ method, amount, cryptoCurrency, cryptoNetwork, sourceAddress, promotionsNo, receipt }) => ({
107
+ url: `payment/v2/${method}/transaction`,
108
+ method: 'post',
109
+ params: { transferType: 'DEPOSIT', amount, cryptoCurrency, cryptoNetwork, sourceAddress, promotionsNo, receipt },
110
+ }),
111
+ submitDepositTransactionCryptoBank: ({ method, amount, cryptoCurrency, cryptoNetwork, sourceAddress, promotionsNo, depositTime, receipt }) => ({
68
112
  url: `payment/v2/${method}/transaction`,
69
113
  method: 'post',
70
- params: { transferType: 'DEPOSIT', amount, cryptoCurrency, cryptoNetwork, sourceAddress, promotionsNo },
114
+ params: {
115
+ transferType: 'DEPOSIT',
116
+ amount,
117
+ cryptoCurrency,
118
+ cryptoNetwork,
119
+ sourceAddress,
120
+ promotionsNo,
121
+ depositTime,
122
+ receipt,
123
+ },
71
124
  }),
72
125
  submitDepositTransactionLoadcard: ({ method, amount, card_type, card_code, card_seri, promotionsNo }) => ({
73
126
  url: `payment/v2/${method}/transaction`,
@@ -79,9 +132,15 @@ export default {
79
132
  amount,
80
133
  applyerBankCode,
81
134
  applyerAccountNumber,
135
+ applyerIfscCode,
82
136
  applyerHolderName,
137
+ applyerBranch,
138
+ applyerBranchCode,
83
139
  targetBankCode,
84
140
  targetAccountNumber,
141
+ targetIfscCode,
142
+ targetUpi,
143
+ transactionId,
85
144
  depositTime,
86
145
  receipt,
87
146
  promotionsNo,
@@ -93,9 +152,15 @@ export default {
93
152
  amount,
94
153
  applyerBankCode,
95
154
  applyerAccountNumber,
155
+ applyerIfscCode,
96
156
  applyerHolderName,
157
+ applyerBranch,
158
+ applyerBranchCode,
97
159
  targetBankCode,
98
160
  targetAccountNumber,
161
+ targetIfscCode,
162
+ targetUpi,
163
+ transactionId,
99
164
  depositTime,
100
165
  receipt,
101
166
  promotionsNo,
@@ -106,12 +171,36 @@ export default {
106
171
  method: 'post',
107
172
  params: { transferType: 'DEPOSIT', amount, promotionsNo },
108
173
  }),
109
- submitWithdrawTransactionCrypto: ({ method, amount, cryptoCurrency, cryptoNetwork, targetAddress }) => ({
174
+ submitWithdrawTransactionCrypto: ({ method, amount, cryptoCurrency, cryptoNetwork, targetAddress, applyerHolderName }) => ({
110
175
  url: `payment/v2/${method}/transaction`,
111
176
  method: 'post',
112
- params: { transferType: 'WITHDRAW', amount, cryptoCurrency, cryptoNetwork, targetAddress },
177
+ params: { transferType: 'WITHDRAW', amount, cryptoCurrency, cryptoNetwork, targetAddress, applyerHolderName },
113
178
  }),
114
- submitWithdrawTransactionVN: ({ method, amount, applyerBankCode, applyerAccountNumber, branch, holderName }) => ({
179
+ submitWithdrawTransactionVN: ({ method, amount, applyerBankCode, applyerAccountNumber, applyerIfscCode, branch, applyerHolderName }) => ({
180
+ url: `payment/v2/${method}/transaction`,
181
+ method: 'post',
182
+ params: {
183
+ transferType: 'WITHDRAW',
184
+ amount,
185
+ applyerBankCode,
186
+ applyerAccountNumber,
187
+ applyerIfscCode,
188
+ branch,
189
+ applyerHolderName,
190
+ },
191
+ }),
192
+ submitWithdrawTransactionManual: ({
193
+ method,
194
+ amount,
195
+ applyerBankCode,
196
+ applyerAccountNumber,
197
+ applyerIfscCode,
198
+ branch,
199
+ holderName,
200
+ cryptoCurrency,
201
+ cryptoNetwork,
202
+ targetAddress,
203
+ }) => ({
115
204
  url: `payment/v2/${method}/transaction`,
116
205
  method: 'post',
117
206
  params: {
@@ -119,8 +208,12 @@ export default {
119
208
  amount,
120
209
  applyerBankCode,
121
210
  applyerAccountNumber,
211
+ applyerIfscCode,
122
212
  branch,
123
213
  holderName,
214
+ cryptoCurrency,
215
+ cryptoNetwork,
216
+ targetAddress,
124
217
  },
125
218
  }),
126
219
  submitWithdrawTransactionAmb: ({ method, amount }) => ({
@@ -147,4 +240,6 @@ export default {
147
240
  params: { promotionsNo },
148
241
  }),
149
242
  getPendingOrder: ({ transferType }) => ({ url: 'payment/v2/pendingOrder', method: 'post', params: { transferType } }),
243
+ withdrawCheck: () => ({ url: `payment/v2/withdrawCheck`, method: 'post' }),
244
+ updateUtr: ({ applyId, utr }) => ({ url: 'payment/v2/updateUtr', method: 'post', params: { applyId, utr } }),
150
245
  }
package/src/api/user.js CHANGED
@@ -57,4 +57,6 @@ export default {
57
57
  isPublic: true,
58
58
  }),
59
59
  otpReset: ({ requestId, target }) => ({ url: '/otpsso/reset', method: 'post', params: { requestId, target }, isPublic: true }),
60
+ getUserPhotoList: () => ({ url: 'getAllAvatar', method: 'get' }),
61
+ updateUserPhoto: (data) => ({ url: 'updateUserAvatar', method: 'post', params: data }),
60
62
  }
@@ -1,30 +1,41 @@
1
1
  import { createMachine, assign } from 'xstate'
2
- import api from '../../api/activity.js'
3
- import activity from './index.js'
2
+ import activity from '../../api/activity.js'
3
+ import payment from '../../api/payment.js'
4
4
 
5
5
  export default function (request) {
6
6
  const { appSecret } = request.config
7
7
  return createMachine(
8
8
  {
9
9
  id: 'activity',
10
- initial: 'fetchingActivityList',
10
+ initial: 'init',
11
11
  context: {
12
12
  tick: 2000,
13
- specifyActivities: [29],
13
+ specifyActivities: [4, 29, 34],
14
14
  activitiesDetailList: [],
15
15
  activityList: [],
16
+ promotionList: [],
17
+ jackpotList: [],
16
18
  activityMap: {},
17
19
  tournamentList: [],
18
20
  refs: {},
19
21
  uidSite: '',
22
+ siteConfig: {},
20
23
  },
21
24
  states: {
22
- fetchingActivityList: {
25
+ init: {
26
+ on: {
27
+ SET_CONFIG: {
28
+ target: 'fetchingList',
29
+ actions: 'setSiteConifg',
30
+ },
31
+ },
32
+ },
33
+ fetchingList: {
23
34
  invoke: {
24
- src: 'fetchActivityList',
35
+ src: 'fetchList',
25
36
  onDone: {
26
37
  target: 'idle',
27
- actions: ['setActivityList', 'setTournamentList'],
38
+ actions: ['setActivityList', 'setTournamentList', 'setPromotionList', 'setJackpotList'],
28
39
  },
29
40
  onError: {
30
41
  target: 'idle',
@@ -58,7 +69,7 @@ export default function (request) {
58
69
  pending: {
59
70
  after: {
60
71
  TIMEOUT: {
61
- target: '#activity.fetchingActivityList',
72
+ target: '#activity.fetchingList',
62
73
  },
63
74
  },
64
75
  on: {
@@ -66,7 +77,7 @@ export default function (request) {
66
77
  actions: 'setUnread',
67
78
  },
68
79
  REFRESH: {
69
- target: '#activity.fetchingActivityList',
80
+ target: '#activity.fetchingList',
70
81
  },
71
82
  },
72
83
  },
@@ -76,8 +87,14 @@ export default function (request) {
76
87
  },
77
88
  {
78
89
  actions: {
90
+ setSiteConifg: assign((context, event) => {
91
+ return {
92
+ siteConfig: event.data,
93
+ }
94
+ }),
79
95
  setTournamentList: assign((context, event) => {
80
- const tournamentList = event.data.filter((item) => item.tournament === 1)
96
+ const { activityList } = event.data
97
+ const tournamentList = activityList.filter((item) => item.tournament === 1)
81
98
  return {
82
99
  tournamentList,
83
100
  }
@@ -85,7 +102,8 @@ export default function (request) {
85
102
  setActivityList: assign((context, event) => {
86
103
  const noRedActivity = [2, 4, 13, 20, 90, 91, 92]
87
104
  const { uidSite } = context
88
- let list = JSON.parse(JSON.stringify(event.data))
105
+ const { activityList } = event.data
106
+ let list = JSON.parse(JSON.stringify(activityList))
89
107
  list.forEach((activity) => {
90
108
  const storageUnread = localStorage.getItem(`unread_${activity.activityNo}_${uidSite}`)
91
109
  if (noRedActivity.includes(activity.activityType)) {
@@ -100,6 +118,18 @@ export default function (request) {
100
118
  activityList: list,
101
119
  }
102
120
  }),
121
+ setPromotionList: assign((context, event) => {
122
+ const { promotionList } = event.data
123
+ return {
124
+ promotionList,
125
+ }
126
+ }),
127
+ setJackpotList: assign((context, event) => {
128
+ const { jackpotList } = event.data
129
+ return {
130
+ jackpotList,
131
+ }
132
+ }),
103
133
  setActivitiesDetailList: assign((context, event) => {
104
134
  return {
105
135
  activitiesDetailList: event.data.map((item) => item.data),
@@ -135,15 +165,25 @@ export default function (request) {
135
165
  },
136
166
  },
137
167
  services: {
138
- fetchActivityList: async (context, event) => {
139
- const { data } = await request.send(api.getActivityList({ appSecret }))
140
- return data
168
+ fetchList: async (context, event) => {
169
+ const hasToken = request.getToken()
170
+ const isDoubleWallet = context.siteConfig?.walletMode === '4'
171
+ const apiCallable = hasToken && isDoubleWallet
172
+ const [{ data }, promotionList, jackpotList] = await Promise.all([
173
+ request.send(activity.getActivityList({ appSecret })),
174
+ apiCallable ? request.send(payment.getPromotionsList()) : [],
175
+ request.send(activity.getJackpotList({ appSecret })),
176
+ ])
177
+
178
+ return { activityList: data, promotionList, jackpotList: jackpotList.data }
141
179
  },
142
180
  fetchActivitiesDetail: async (context, event) => {
181
+ await new Promise((resolve) => setTimeout(resolve, 1000)) // delay 1 second
182
+
143
183
  const { activityList = [], specifyActivities = [] } = context
144
184
  const filterActivityList = activityList.filter((activity) => specifyActivities.includes(activity.activityType))
145
- const promiseArray = filterActivityList.map((activity) => {
146
- return request.send(api.getActivityDetail({ activityNo: activity.activityNo, appSecret }))
185
+ const promiseArray = filterActivityList.map((item) => {
186
+ return request.send(activity.getActivityDetail({ activityNo: item.activityNo, appSecret }))
147
187
  })
148
188
  const activitiesDetail = await Promise.all(promiseArray)
149
189
  return activitiesDetail
@@ -1,26 +1,45 @@
1
1
  import { createMachine, assign } from 'xstate'
2
- import api from '../../api/activity.js'
2
+ import activity from '../../api/activity.js'
3
+ import payment from '../../api/payment.js'
3
4
 
4
5
  export default function (request) {
5
6
  const { appSecret } = request.config
6
7
  return createMachine(
7
8
  {
8
9
  id: 'activity',
9
- initial: 'fetchingActivityList',
10
+ initial: 'fetchingList',
10
11
  context: {
11
12
  tick: 2000,
12
13
  activityList: [],
13
- activityMap: {},
14
14
  tournamentList: [],
15
- refs: {},
15
+ promotionList: [],
16
+ jackpotList: [],
17
+ uidSite: '',
18
+ detailNeededActivityTypes: [29, 34],
19
+ activityDetailList: [],
16
20
  },
17
21
  states: {
18
- fetchingActivityList: {
22
+ fetchingList: {
19
23
  invoke: {
20
- src: 'fetchActivityList',
24
+ src: 'fetchList',
25
+ onDone: {
26
+ target: 'checking',
27
+ actions: ['setActivityList', 'setTournamentList', 'setPromotionList', 'setJackpotList'],
28
+ },
29
+ onError: {
30
+ target: 'pending',
31
+ },
32
+ },
33
+ },
34
+ checking: {
35
+ always: [{ target: 'fetchingDetailList', cond: 'needFetchingDetail' }, { target: 'pending' }],
36
+ },
37
+ fetchingDetailList: {
38
+ invoke: {
39
+ src: 'fetchActivityDetailList',
21
40
  onDone: {
22
41
  target: 'pending',
23
- actions: ['setActivityList', 'setTournamentList'],
42
+ actions: 'setActivityDetailList',
24
43
  },
25
44
  onError: {
26
45
  target: 'pending',
@@ -30,7 +49,7 @@ export default function (request) {
30
49
  pending: {
31
50
  after: {
32
51
  TIMEOUT: {
33
- target: 'fetchingActivityList',
52
+ target: 'fetchingList',
34
53
  },
35
54
  },
36
55
  on: {
@@ -38,7 +57,7 @@ export default function (request) {
38
57
  actions: 'setUnread',
39
58
  },
40
59
  REFRESH: {
41
- target: '#activity.fetchingActivityList',
60
+ target: '#activity.fetchingList',
42
61
  },
43
62
  },
44
63
  },
@@ -47,7 +66,8 @@ export default function (request) {
47
66
  {
48
67
  actions: {
49
68
  setTournamentList: assign((context, event) => {
50
- const tournamentList = event.data.filter((item) => item.tournament === 1)
69
+ const { activityList } = event.data
70
+ const tournamentList = activityList.filter((item) => item.tournament === 1)
51
71
  return {
52
72
  tournamentList,
53
73
  }
@@ -55,7 +75,8 @@ export default function (request) {
55
75
  setActivityList: assign((context, event) => {
56
76
  const noReadActivity = [2, 4, 13, 20, 90, 91, 92]
57
77
  const { uidSite } = context
58
- let list = JSON.parse(JSON.stringify(event.data))
78
+ const { activityList } = event.data
79
+ let list = JSON.parse(JSON.stringify(activityList))
59
80
  list.forEach((activity) => {
60
81
  const storageUnread = localStorage.getItem(`unread_${activity.activityNo}_${uidSite}`)
61
82
  if (noReadActivity.includes(activity.activityType)) {
@@ -70,6 +91,18 @@ export default function (request) {
70
91
  activityList: list,
71
92
  }
72
93
  }),
94
+ setPromotionList: assign((context, event) => {
95
+ const { promotionList } = event.data
96
+ return {
97
+ promotionList,
98
+ }
99
+ }),
100
+ setJackpotList: assign((context, event) => {
101
+ const { jackpotList } = event.data
102
+ return {
103
+ jackpotList,
104
+ }
105
+ }),
73
106
  setUnread: assign((context, event) => {
74
107
  const { uidSite, activityNo, unread } = event.data
75
108
  const list = JSON.parse(JSON.stringify(context.activityList))
@@ -85,6 +118,17 @@ export default function (request) {
85
118
  uidSite,
86
119
  }
87
120
  }),
121
+ setActivityDetailList: assign((context, event) => {
122
+ return {
123
+ activityDetailList: event.data.map((item) => item.data),
124
+ }
125
+ }),
126
+ },
127
+ guards: {
128
+ needFetchingDetail: (context, event) => {
129
+ const { activityList = [], detailNeededActivityTypes } = context
130
+ return activityList.filter((activity) => detailNeededActivityTypes.includes(activity.activityType)).length > 0
131
+ },
88
132
  },
89
133
  delays: {
90
134
  TIMEOUT: (context, event) => {
@@ -93,9 +137,29 @@ export default function (request) {
93
137
  },
94
138
  },
95
139
  services: {
96
- fetchActivityList: async (context, event) => {
97
- const { data } = await request.send(api.getActivityList({ appSecret }))
98
- return data
140
+ fetchList: async (context, event) => {
141
+ const hasToken = request.getToken()
142
+ const [{ data }, promotionList, jackpotList] = await Promise.all([
143
+ request.send(activity.getActivityList({ appSecret })),
144
+ hasToken ? request.send(payment.getPromotionsList()) : [],
145
+ request.send(activity.getJackpotList({ appSecret })),
146
+ ])
147
+
148
+ return { activityList: data, promotionList, jackpotList: jackpotList.data }
149
+ },
150
+ fetchActivityDetailList: async (context, event) => {
151
+ await new Promise((resolve) => setTimeout(resolve, 1000)) // delay 1 second
152
+ const hasToken = request.getToken()
153
+
154
+ const { activityList = [], detailNeededActivityTypes } = context
155
+ const filteredActivityList = activityList.filter((activity) => detailNeededActivityTypes.includes(activity.activityType))
156
+ return hasToken
157
+ ? await Promise.all(
158
+ filteredActivityList.map((item) => {
159
+ return request.send(activity.getActivityDetail({ activityNo: item.activityNo, appSecret }))
160
+ })
161
+ )
162
+ : []
99
163
  },
100
164
  },
101
165
  }
@@ -0,0 +1,153 @@
1
+ import { assign, createMachine } from 'xstate'
2
+ import api from '../../api/activity.js'
3
+
4
+ export default function (request, context) {
5
+ const { activityNo } = context || {}
6
+ const { appSecret } = request.config
7
+ return createMachine(
8
+ {
9
+ id: 'cash_rain_activity',
10
+ context: {
11
+ activityNo,
12
+ activityDetail: null,
13
+ duration: null,
14
+
15
+ // 領獎後得到的資訊
16
+ amount: null,
17
+ rewardType: null,
18
+ message: null,
19
+ canReceiveQuantity: null,
20
+ receivedQuantity: null,
21
+ },
22
+ initial: 'idle',
23
+ states: {
24
+ idle: {
25
+ on: {
26
+ SET_ACTIVITY_NO: {
27
+ target: 'loading',
28
+ actions: 'setActivityNo',
29
+ },
30
+ RESET_AWARD: {
31
+ target: 'loaded',
32
+ actions: 'resetAward',
33
+ },
34
+ },
35
+ },
36
+ loading: {
37
+ invoke: {
38
+ src: 'fetchActivityDetail',
39
+ onDone: {
40
+ target: 'loaded',
41
+ actions: 'setActivityDetail',
42
+ },
43
+ onError: {
44
+ target: 'idle',
45
+ },
46
+ },
47
+ },
48
+ loaded: {
49
+ entry: 'setDuration',
50
+ always: [{ target: 'expired', cond: 'isExpired' }],
51
+ after: {
52
+ 1000: {
53
+ target: 'loaded',
54
+ },
55
+ },
56
+ on: {
57
+ AWARD_PRIZE: {
58
+ target: 'awarding',
59
+ actions: 'setCallback',
60
+ },
61
+ REFRESH: {
62
+ target: 'loading',
63
+ },
64
+ },
65
+ },
66
+ awarding: {
67
+ invoke: {
68
+ src: 'awardPrize',
69
+ onDone: [{ target: 'receivable', actions: 'setAward' }],
70
+ onError: {
71
+ target: 'loaded',
72
+ },
73
+ },
74
+ },
75
+ receivable: {
76
+ after: {
77
+ 0: {
78
+ target: 'loaded',
79
+ },
80
+ },
81
+ },
82
+ expired: {},
83
+ },
84
+ on: {
85
+ START: {
86
+ target: '.loading',
87
+ },
88
+ STOP: {
89
+ target: '.idle',
90
+ },
91
+ },
92
+ },
93
+ {
94
+ actions: {
95
+ setActivityNo: assign((context, event) => {
96
+ return {
97
+ activityNo: event.data,
98
+ }
99
+ }),
100
+ setActivityDetail: assign((context, event) => {
101
+ return {
102
+ activityDetail: event.data,
103
+ }
104
+ }),
105
+ setDuration: assign((context, event) => {
106
+ const { activityDetail = {} } = context
107
+ return {
108
+ duration: activityDetail.periodEndTime - new Date().getTime() / 1000,
109
+ }
110
+ }),
111
+ setAward: assign((context, event) => {
112
+ const { amount, rewardType, message, canReceiveQuantity, receivedQuantity } = event.data
113
+ return {
114
+ amount,
115
+ rewardType,
116
+ message,
117
+ canReceiveQuantity,
118
+ receivedQuantity,
119
+ }
120
+ }),
121
+ setCallback: assign((context, event) => {
122
+ return {
123
+ callback: event.data?.callback || (() => {}),
124
+ }
125
+ }),
126
+ resetAward: assign((context, event) => {
127
+ return {
128
+ amount: null,
129
+ rewardType: null,
130
+ message: null,
131
+ }
132
+ }),
133
+ },
134
+ guards: {
135
+ isExpired: (context, event) => {
136
+ return context.duration <= 0
137
+ },
138
+ },
139
+ services: {
140
+ fetchActivityDetail: async (context, event) => {
141
+ const { activityNo } = context
142
+ const { data } = await request.send(api.getActivityDetail({ activityNo, appSecret }))
143
+ return data
144
+ },
145
+ awardPrize: async (context, event) => {
146
+ const { activityNo } = context
147
+ const { data } = await request.send(api.getCashRainReward({ activityNo, appSecret }))
148
+ return data
149
+ },
150
+ },
151
+ }
152
+ )
153
+ }