@jetthai/cuora 1.1.93-cash → 1.1.93

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,258 +0,0 @@
1
- import { assign, createMachine } from 'xstate'
2
- import payment from '../../api/payment.js'
3
- import { max } from '../../util'
4
-
5
- export default function (request, context) {
6
- const { paymentDetail = [], promotion, selectedAmount } = context || {}
7
- return createMachine(
8
- {
9
- id: 'qrcode_cash',
10
- initial: 'loading',
11
- context: {
12
- paymentDetail,
13
- promotion,
14
- selectedAmount,
15
-
16
- qrcodes: null,
17
- options: null,
18
-
19
- selectedQrcode: null,
20
-
21
- calculation: null,
22
-
23
- currentCategory: 'qrcode',
24
-
25
- result: null,
26
-
27
- bonusPreviewData: [],
28
- },
29
- states: {
30
- loading: {
31
- always: [
32
- {
33
- target: 'loaded',
34
- actions: 'setInitData',
35
- cond: 'hasQrcodeMethods',
36
- },
37
- ],
38
- },
39
- loaded: {
40
- on: {
41
- SET_PROMOTION: {
42
- target: 'debouncing',
43
- actions: 'setPromotion',
44
- },
45
- SELECT_QRCODE: {
46
- target: 'debouncing',
47
- actions: 'setQrcode',
48
- },
49
- SELECT_AMOUNT: {
50
- target: 'debouncing',
51
- actions: 'setAmount',
52
- },
53
- INPUT_AMOUNT: {
54
- target: 'debouncing',
55
- actions: 'inputAmount',
56
- },
57
- },
58
- },
59
- debouncing: {
60
- after: {
61
- 1000: [
62
- {
63
- target: 'calculating',
64
- cond: (context, event) => {
65
- const { selectedQrcode, selectedAmount } = context
66
- if (selectedQrcode && selectedAmount) {
67
- return selectedQrcode.minimum <= selectedAmount && selectedAmount <= selectedQrcode.maximum
68
- } else {
69
- return false
70
- }
71
- },
72
- },
73
- {
74
- target: 'loaded',
75
- },
76
- ],
77
- },
78
- on: {
79
- SET_PROMOTION: {
80
- target: 'debouncing',
81
- actions: 'setPromotion',
82
- },
83
- SELECT_QRCODE: {
84
- target: 'debouncing',
85
- actions: 'setQrcode',
86
- },
87
- SELECT_AMOUNT: {
88
- target: 'debouncing',
89
- actions: 'setAmount',
90
- },
91
- INPUT_AMOUNT: {
92
- target: 'debouncing',
93
- actions: 'inputAmount',
94
- },
95
- },
96
- },
97
- calculating: {
98
- invoke: {
99
- src: 'fetchCalculation',
100
- onDone: {
101
- target: 'calculated',
102
- actions: 'setCalculation',
103
- },
104
- onError: {
105
- target: 'calculated',
106
- },
107
- },
108
- },
109
- calculated: {
110
- on: {
111
- SET_PROMOTION: {
112
- target: 'debouncing',
113
- actions: 'setPromotion',
114
- },
115
- SELECT_QRCODE: {
116
- target: 'debouncing',
117
- actions: 'setQrcode',
118
- },
119
- SELECT_AMOUNT: {
120
- target: 'debouncing',
121
- actions: 'setAmount',
122
- },
123
- INPUT_AMOUNT: {
124
- target: 'debouncing',
125
- actions: 'inputAmount',
126
- },
127
- SUBMIT: {
128
- target: 'submitting',
129
- },
130
- },
131
- },
132
- submitting: {
133
- invoke: {
134
- src: 'submitDeposit',
135
- onDone: {
136
- target: 'submitted',
137
- actions: 'setResult',
138
- },
139
- onError: {
140
- target: 'calculated',
141
- },
142
- },
143
- },
144
- submitted: {},
145
- },
146
- },
147
- {
148
- actions: {
149
- setInitData: assign((context, event) => {
150
- const { paymentDetail, selectedAmount, promotion } = context
151
- const qrcodes = paymentDetail
152
- .filter((element) => element.category === context.currentCategory)
153
- .map((qrcode) => {
154
- qrcode.disabled = promotion?.promotionsNo !== 'none' && qrcode.charge > 0
155
- return qrcode
156
- })
157
-
158
- const selectedQrcode = qrcodes.find((qrcode) => !qrcode.disabled)
159
-
160
- return {
161
- paymentDetail,
162
- qrcodes,
163
- selectedQrcode,
164
- options: selectedQrcode?.optional,
165
- selectedAmount: max(promotion?.minimumAmount, selectedQrcode?.minimum, selectedAmount, 0),
166
- }
167
- }),
168
- setBonusPreview: assign((context, event) => {
169
- return {
170
- bonusPreviewData: event.data.bonus,
171
- }
172
- }),
173
- setPromotion: assign((context, event) => {
174
- const { selectedAmount } = context
175
- const promotion = event.data
176
- const qrcodes = context.qrcodes.map((qrcode) => {
177
- qrcode.disabled = promotion.promotionsNo !== 'none' && qrcode.charge > 0
178
- return qrcode
179
- })
180
-
181
- const selectedQrcode = qrcodes.find((qrcode) => !qrcode.disabled)
182
-
183
- return {
184
- promotion,
185
- qrcodes,
186
- selectedQrcode,
187
- options: selectedQrcode?.optional,
188
- selectedAmount: max(promotion.minimumAmount, selectedQrcode?.minimum, selectedAmount, 0),
189
- calculation: null,
190
- }
191
- }),
192
- setQrcode: assign((context, event) => {
193
- const { promotion, selectedAmount } = context
194
- const selectedQrcode = event.data
195
- return {
196
- selectedQrcode,
197
- options: selectedQrcode.optional,
198
- selectedAmount: max(promotion.minimumAmount, selectedAmount, 0),
199
- calculation: null,
200
- }
201
- }),
202
- setAmount: assign((context, event) => {
203
- // 現金網可自由填額度,grandTotalEnable 欄位感覺不再需要?
204
- if (context.selectedQrcode?.grandTotalEnable === 1) {
205
- return { selectedAmount: parseFloat(context.selectedAmount || 0) + parseFloat(event.data) }
206
- } else {
207
- return { selectedAmount: event.data }
208
- }
209
- }),
210
- inputAmount: assign((context, event) => {
211
- return { selectedAmount: event.data }
212
- }),
213
- setCalculation: assign((context, event) => {
214
- return {
215
- calculation: event.data,
216
- }
217
- }),
218
- clearCalculation: assign((context, event) => {
219
- return {
220
- calculation: null,
221
- }
222
- }),
223
- setResult: assign((context, event) => {
224
- return {
225
- result: event.data,
226
- }
227
- }),
228
- },
229
- guards: {
230
- hasQrcodeMethods: (context, event) => {
231
- return context.paymentDetail?.filter((element) => element.category === context.currentCategory).length > 0
232
- },
233
- },
234
- services: {
235
- fetchCalculation: async (context, event) => {
236
- const { selectedQrcode, selectedAmount, promotion } = context
237
- return await request.send(
238
- payment.getDepositExpectedResult({
239
- method: selectedQrcode.method,
240
- amount: selectedAmount,
241
- promotionsNo: promotion?.promotionsNo,
242
- })
243
- )
244
- },
245
- submitDeposit: async (context, event) => {
246
- const { selectedQrcode, selectedAmount, promotion } = context
247
- return await request.send(
248
- payment.submitDepositTransaction({
249
- method: selectedQrcode.method,
250
- amount: selectedAmount,
251
- promotionsNo: promotion?.promotionsNo,
252
- })
253
- )
254
- },
255
- },
256
- }
257
- )
258
- }
@@ -1,138 +0,0 @@
1
- import { assign, createMachine } from 'xstate'
2
- import payment from '@jetthai/cuora/src/api/payment.js'
3
-
4
- export default function (request, context) {
5
- const { paymentDetail = [] } = context || {}
6
- return createMachine(
7
- {
8
- id: 'usdt',
9
- initial: 'loading',
10
- context: {
11
- paymentDetail,
12
- currentCategory: 'usdt',
13
- currentPayment: null,
14
- networks: [],
15
- selectedNetwork: null,
16
-
17
- resultMap: {},
18
- result: {
19
- action: '',
20
- cdtime: null,
21
- accountNumber: '', // crypto address
22
- currency: '',
23
- network: '',
24
- name: '',
25
- qrcode: '',
26
- },
27
- },
28
- states: {
29
- loading: {
30
- always: [
31
- {
32
- target: 'checking',
33
- actions: 'setPayment',
34
- },
35
- ],
36
- },
37
- checking: {
38
- always: [
39
- {
40
- target: 'calculated',
41
- actions: 'setResultFromLocal',
42
- cond: 'isFound',
43
- },
44
- {
45
- target: 'calculating',
46
- },
47
- ],
48
- },
49
- calculating: {
50
- invoke: {
51
- src: 'submitDeposit',
52
- onDone: {
53
- target: 'calculated',
54
- actions: 'setResult',
55
- },
56
- onError: {
57
- target: 'calculated',
58
- },
59
- },
60
- },
61
- calculated: {
62
- on: {
63
- SET_NETWORK: {
64
- target: 'checking',
65
- actions: 'setNetwork',
66
- },
67
- },
68
- },
69
- },
70
- },
71
- {
72
- actions: {
73
- setPayment: assign((context, event) => {
74
- const currentPayment = context.paymentDetail.find((element) => element.category === context.currentCategory)
75
- const defaultNetworks = currentPayment.networkName.map((value, i) => {
76
- return {
77
- label: currentPayment.networkOptional?.[i],
78
- value,
79
- icon: value,
80
- }
81
- })
82
-
83
- return {
84
- networks: defaultNetworks,
85
- selectedNetwork: defaultNetworks[0],
86
- currentPayment,
87
- }
88
- }),
89
- setNetwork: assign((context, event) => {
90
- return { selectedNetwork: event.data }
91
- }),
92
- setResultFromLocal: assign((context, event) => {
93
- const { resultMap, selectedNetwork } = context
94
- return { result: resultMap[selectedNetwork.value] }
95
- }),
96
- setResult: assign((context, event) => {
97
- const { resultMap, selectedNetwork } = context
98
- const { action, cdtime, accountNumber, currency, network, name, qrcode } = event.data
99
- const result = {
100
- action,
101
- cdtime,
102
- accountNumber,
103
- currency,
104
- network,
105
- name,
106
- qrcode,
107
- }
108
-
109
- return {
110
- result,
111
- resultMap: {
112
- ...resultMap,
113
- [selectedNetwork.value]: result,
114
- },
115
- }
116
- }),
117
- },
118
- guards: {
119
- isFound: (context, event) => {
120
- const { resultMap, selectedNetwork } = context
121
- return resultMap[selectedNetwork.value]
122
- },
123
- },
124
- services: {
125
- submitDeposit: async (context, event) => {
126
- const { currentPayment, selectedNetwork } = context
127
- return await request.send(
128
- payment.submitDepositTransactionCrypto({
129
- method: currentPayment.method,
130
- cryptoCurrency: currentPayment.channel,
131
- cryptoNetwork: selectedNetwork.value,
132
- })
133
- )
134
- },
135
- },
136
- }
137
- )
138
- }
@@ -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
- }