@jetthai/cuora 1.1.77-cash-5 → 1.1.77-doubleWallet-fix

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.
@@ -1,215 +0,0 @@
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
- }
@@ -1,274 +0,0 @@
1
- import { assign, createMachine } from 'xstate'
2
- import payment from '../../api/payment.js'
3
- import common from '../../api/common.js'
4
- import { api } from '../../index.js'
5
-
6
- const noBonus = {
7
- promotionsNo: 'none',
8
- activityTypeName: 'promotion',
9
- minimumAmount: 0,
10
- maximumAmount: -1,
11
- turnoverLimitMultiple: 1,
12
- template: 'Template_no_bonus',
13
- promotionDetail: [],
14
- attendEnable: true,
15
- withdrawLimitDetail: [
16
- {
17
- greaterEqualThen: 0,
18
- lessEqualThen: -1,
19
- maxWithdrawAmount: -1,
20
- turnoverLimitMultiple: 1,
21
- },
22
- ],
23
- limitGameDetail: [],
24
- }
25
-
26
- export default function (request) {
27
- const { appSecret } = request.config
28
- return createMachine(
29
- {
30
- id: 'qrcode_v_cash',
31
- initial: 'loading',
32
- context: {
33
- siteConfig: null,
34
- qrcodes: null,
35
- options: null,
36
-
37
- selectedQrcode: null,
38
- selectedAmount: null,
39
-
40
- calculation: null,
41
-
42
- paymentDetail: [],
43
- currentCategory: 'qrcode',
44
-
45
- result: null,
46
-
47
- promotion: undefined,
48
- bonusPreviewData: [],
49
- promotions: [noBonus],
50
- },
51
- states: {
52
- loading: {
53
- invoke: {
54
- src: 'fetchInitData',
55
- onDone: {
56
- target: 'debouncing',
57
- actions: 'setInitData',
58
- },
59
- onError: {
60
- target: 'fail',
61
- },
62
- },
63
- },
64
- fail: {},
65
- debouncing: {
66
- on: {
67
- SET_PROMOTION: {
68
- target: 'debouncing',
69
- actions: 'setPromotion',
70
- },
71
- SELECT_QRCODE: {
72
- target: 'debouncing',
73
- actions: 'setQrcode',
74
- },
75
- SELECT_AMOUNT: {
76
- target: 'debouncing',
77
- actions: 'setAmount',
78
- },
79
- INPUT_AMOUNT: {
80
- target: 'debouncing',
81
- actions: 'inputAmount',
82
- },
83
- },
84
- after: {
85
- 1000: {
86
- target: 'calculating',
87
- cond: (context, event) => {
88
- const { selectedQrcode, selectedAmount } = context
89
- if (selectedQrcode && selectedAmount) {
90
- return selectedQrcode.minimum <= selectedAmount && selectedAmount <= selectedQrcode.maximum
91
- } else {
92
- return false
93
- }
94
- },
95
- },
96
- },
97
- },
98
- calculating: {
99
- invoke: {
100
- src: 'fetchCalculation',
101
- onDone: {
102
- target: 'calculated',
103
- actions: 'setCalculation',
104
- },
105
- onError: {
106
- target: 'calculated',
107
- },
108
- },
109
- },
110
- calculated: {
111
- on: {
112
- SET_PROMOTION: {
113
- target: 'debouncing',
114
- actions: 'setPromotion',
115
- },
116
- SELECT_QRCODE: {
117
- target: 'debouncing',
118
- actions: 'setQrcode',
119
- },
120
- SELECT_AMOUNT: {
121
- target: 'debouncing',
122
- actions: 'setAmount',
123
- },
124
- INPUT_AMOUNT: {
125
- target: 'debouncing',
126
- actions: 'inputAmount',
127
- },
128
- CONFIRM: {
129
- target: 'submitting',
130
- },
131
- },
132
- },
133
- submitting: {
134
- invoke: {
135
- src: 'submitDeposit',
136
- onDone: {
137
- target: 'submitted',
138
- actions: 'setResult',
139
- },
140
- onError: {
141
- target: 'calculated',
142
- },
143
- },
144
- },
145
- submitted: {},
146
- },
147
- },
148
- {
149
- actions: {
150
- setInitData: assign((context, event) => {
151
- const { siteConfig, paymentDetail, promotions } = event.data
152
- const promotion = promotions[0]
153
- const qrcodes = paymentDetail
154
- .filter((element) => element.category === context.currentCategory)
155
- .map((qrcode) => {
156
- qrcode.disabled = promotion.promotionsNo !== 'none' && qrcode.charge > 0
157
- return qrcode
158
- })
159
-
160
- const selectedQrcode = qrcodes.find((qrcode) => !qrcode.disabled)
161
-
162
- return {
163
- siteConfig,
164
- paymentDetail,
165
- promotions,
166
- promotion,
167
- qrcodes,
168
- selectedQrcode,
169
- options: selectedQrcode?.optional,
170
- selectedAmount: Math.max(promotion.minimumAmount, selectedQrcode?.minimum, 0),
171
- }
172
- }),
173
- setBonusPreview: assign((context, event) => {
174
- return {
175
- bonusPreviewData: event.data.bonus,
176
- }
177
- }),
178
- setPromotion: assign((context, event) => {
179
- const promotion = event.data
180
- const qrcodes = context.qrcodes.map((qrcode) => {
181
- qrcode.disabled = promotion.promotionsNo !== 'none' && qrcode.charge > 0
182
- return qrcode
183
- })
184
-
185
- const selectedQrcode = qrcodes.find((qrcode) => !qrcode.disabled)
186
-
187
- return {
188
- promotion,
189
- qrcodes,
190
- selectedQrcode,
191
- options: selectedQrcode?.optional,
192
- selectedAmount: Math.max(promotion.minimumAmount, selectedQrcode?.minimum, 0),
193
- calculation: null,
194
- }
195
- }),
196
- setQrcode: assign((context, event) => {
197
- const selectedQrcode = event.data
198
- return {
199
- selectedQrcode,
200
- options: selectedQrcode.optional,
201
- selectedAmount: context.promotion.minimumAmount || 0,
202
- calculation: null,
203
- }
204
- }),
205
- setAmount: assign((context, event) => {
206
- if (context.selectedQrcode?.grandTotalEnable === 1) {
207
- return { selectedAmount: parseFloat(context.selectedAmount || 0) + parseFloat(event.data) }
208
- } else {
209
- return { selectedAmount: event.data }
210
- }
211
- }),
212
- inputAmount: assign((context, event) => {
213
- return { selectedAmount: event.data }
214
- }),
215
- setCalculation: assign((context, event) => {
216
- return {
217
- calculation: event.data,
218
- }
219
- }),
220
- clearCalculation: assign((context, event) => {
221
- return {
222
- calculation: null,
223
- }
224
- }),
225
- setResult: assign((context, event) => {
226
- return {
227
- result: event.data,
228
- }
229
- }),
230
- },
231
- guards: {},
232
- services: {
233
- fetchInitData: async (context, event) => {
234
- const [{ config }, paymentDetail = [], promotions] = await Promise.all([
235
- request.send(common.getConfig({ appSecret })),
236
- request.send(payment.getPaymentDetail({ transferType: 'DEPOSIT' })),
237
- request.send(api.payment.getPromotionsList()),
238
- ])
239
- const siteConfig = JSON.parse(window.atob(config))
240
- return { siteConfig, paymentDetail, promotions: [noBonus, ...promotions] }
241
- },
242
- fetchBonusPreview: async (context, event) => {
243
- const { selectedQrcode, promotion } = context
244
- return await request.send(
245
- payment.getBonusPreview({
246
- method: selectedQrcode.method,
247
- promotionsNo: promotion?.activityNo,
248
- })
249
- )
250
- },
251
- fetchCalculation: async (context, event) => {
252
- const { selectedQrcode, selectedAmount, promotion } = context
253
- return await request.send(
254
- payment.getDepositExpectedResult({
255
- method: selectedQrcode.method,
256
- amount: selectedAmount,
257
- promotionsNo: promotion?.activityNo,
258
- })
259
- )
260
- },
261
- submitDeposit: async (context, event) => {
262
- const { selectedQrcode, selectedAmount, promotion } = context
263
- return await request.send(
264
- payment.submitDepositTransaction({
265
- method: selectedQrcode.method,
266
- amount: selectedAmount,
267
- promotionsNo: promotion?.activityNo,
268
- })
269
- )
270
- },
271
- },
272
- }
273
- )
274
- }
@@ -1,220 +0,0 @@
1
- import { createMachine, assign, send } from 'xstate'
2
- import activity from '../api/activity.js'
3
- import payment from '../api/payment.js'
4
-
5
- export default function (request) {
6
- const { appSecret } = request.config
7
- return createMachine(
8
- {
9
- id: 'reward_cash',
10
- type: 'parallel',
11
- context: {
12
- hasAuth: false,
13
- otherRewardList: [],
14
- pointsRewardList: [],
15
- rewardList: [],
16
- activityNo: null,
17
- receiveNo: null,
18
- withdrawRule: {},
19
- callback: () => {},
20
- },
21
- states: {
22
- timer: {
23
- initial: 'checking',
24
- states: {
25
- checking: {
26
- always: [
27
- {
28
- target: 'loading',
29
- cond: (context, event) => {
30
- return context.hasAuth
31
- },
32
- },
33
- ],
34
- },
35
- loading: {
36
- invoke: {
37
- src: 'fetchRewardList',
38
- onDone: {
39
- target: 'pending',
40
- actions: 'setRewardList',
41
- },
42
- onError: {
43
- target: 'pending',
44
- },
45
- },
46
- },
47
- pending: {
48
- after: {
49
- 20000: { target: 'loading' },
50
- },
51
- },
52
- },
53
- on: {
54
- REFRESH: {
55
- target: '.loading',
56
- },
57
- },
58
- },
59
- reward: {
60
- initial: 'idle',
61
- states: {
62
- idle: {
63
- on: {
64
- FETCH_WITHDRAW_RULE: {
65
- target: 'fetching',
66
- actions: 'setRewardData',
67
- },
68
- RECEIVE_REWARD: {
69
- target: 'receiving',
70
- actions: 'setCallback',
71
- },
72
- RECEIVE_ALL_POINTS: {
73
- target: 'allPointsReceiving',
74
- actions: 'setCallback',
75
- },
76
- },
77
- },
78
- fetching: {
79
- invoke: {
80
- src: 'fetchWithdrawRulePreview',
81
- onDone: {
82
- target: 'pending',
83
- actions: 'setWithdrawRulePreview',
84
- },
85
- onError: {
86
- target: 'idle',
87
- },
88
- },
89
- },
90
- pending: {
91
- on: {
92
- RECEIVE_REWARD: {
93
- target: 'receiving',
94
- actions: 'setCallback',
95
- },
96
- BACK: {
97
- target: 'idle',
98
- },
99
- },
100
- },
101
- receiving: {
102
- invoke: {
103
- src: 'receiveReward',
104
- onDone: {
105
- target: 'received',
106
- actions: [send({ type: 'REFRESH' }), 'doCallback'],
107
- },
108
- onError: {
109
- target: 'idle',
110
- },
111
- },
112
- },
113
- received: {
114
- after: {
115
- 0: {
116
- target: 'idle',
117
- },
118
- },
119
- },
120
- allPointsReceiving: {
121
- invoke: {
122
- src: 'receiveAllPoints',
123
- onDone: {
124
- target: 'idle',
125
- actions: [send({ type: 'REFRESH' }), 'doCallback'],
126
- },
127
- onError: {
128
- target: 'idle',
129
- },
130
- },
131
- },
132
- },
133
- },
134
- },
135
- on: {
136
- SET_AUTH: {
137
- target: '.timer.checking',
138
- actions: 'setAuth',
139
- cond: (context, event) => {
140
- console.log(context.hasAuth, event.data)
141
- return context.hasAuth !== event.data
142
- },
143
- },
144
- },
145
- },
146
- {
147
- actions: {
148
- setAuth: assign((context, event) => {
149
- return { hasAuth: event.data }
150
- }),
151
- setRewardList: assign((context, event) => {
152
- return {
153
- otherRewardList: event.data[0]?.data || [],
154
- pointsRewardList: event.data[1]?.data || [],
155
- rewardList: event.data[2]?.data || [],
156
- }
157
- }),
158
- setRewardData: assign((context, event) => {
159
- const { activityNo, receiveNo } = event.data
160
- return {
161
- activityNo,
162
- receiveNo,
163
- }
164
- }),
165
- setCallback: assign((context, event) => {
166
- return {
167
- callback: event.data?.callback || (() => {}),
168
- }
169
- }),
170
- doCallback: (context, event) => {
171
- context.callback()
172
- },
173
- setWithdrawRulePreview: assign((context, event) => {
174
- return {
175
- withdrawRule: event.data,
176
- }
177
- }),
178
- },
179
- services: {
180
- fetchRewardList: async (context, event) => {
181
- const getRewardAPI = request.send(activity.getRewardList({ count: 30, appSecret }))
182
- const getPointsRewardAPI = request.send(
183
- activity.getRewardList({
184
- rewardType: 'POINTS',
185
- count: 30,
186
- appSecret,
187
- })
188
- )
189
- const getOtherRewardAPI = request.send(
190
- activity.getRewardList({
191
- rewardType: 'CASH,FREE',
192
- count: 30,
193
- appSecret,
194
- })
195
- )
196
- const [otherRewardList, pointsRewardList, rewardList] = await Promise.all([getOtherRewardAPI, getPointsRewardAPI, getRewardAPI])
197
- return [otherRewardList, pointsRewardList, rewardList]
198
- },
199
- fetchWithdrawRulePreview: async (context, event) => {
200
- const { receiveNo } = context
201
- const data = await request.send(
202
- payment.getWithdrawRulePreview({
203
- applyType: 'activity',
204
- applyNo: receiveNo,
205
- amount: null,
206
- })
207
- )
208
- return data
209
- },
210
- receiveReward: async (context, event) => {
211
- const { activityNo, receiveNo, attended } = event.data
212
- return await request.send(activity.getReward({ activityNo, receiveNo, appSecret, attended }))
213
- },
214
- receiveAllPoints: async (context, event) => {
215
- return await request.send(activity.collect({ collectType: 'collectPoints', appSecret }))
216
- },
217
- },
218
- }
219
- )
220
- }