@jetthai/cuora 1.1.92 → 1.1.93-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.
@@ -0,0 +1,321 @@
1
+ import { assign, createMachine } from 'xstate'
2
+ import payment from '../../api/payment.js'
3
+ import common from '../../api/common.js'
4
+ import { max } from '../../util/index.js'
5
+
6
+ export default function (request, context) {
7
+ const { paymentDetail = [], promotion, selectedAmount } = context || {}
8
+
9
+ return createMachine(
10
+ {
11
+ id: 'manual_cash',
12
+ initial: 'loading',
13
+ context: {
14
+ paymentDetail,
15
+ promotion,
16
+ selectedAmount,
17
+
18
+ houseBanks: [],
19
+ userBanks: [],
20
+ banks: [],
21
+
22
+ selectedHouseBank: null,
23
+ selectedUserBank: null,
24
+ userAccountNumber: null,
25
+ userAccountName: null,
26
+ depositTime: null,
27
+ receipt: null,
28
+
29
+ currentCategory: 'manual',
30
+ method: null,
31
+ currentPayment: null,
32
+ currentApplyerBank: null,
33
+
34
+ calculation: null,
35
+ processing: null,
36
+ },
37
+ states: {
38
+ loading: {
39
+ invoke: {
40
+ src: 'fetchInitData',
41
+ onDone: {
42
+ target: 'checking',
43
+ actions: 'setInitData',
44
+ },
45
+ },
46
+ },
47
+ checking: {
48
+ always: [
49
+ {
50
+ target: 'submitted',
51
+ cond: 'isProcessing',
52
+ },
53
+ {
54
+ target: 'loaded',
55
+ },
56
+ ],
57
+ },
58
+ loaded: {
59
+ on: {
60
+ SET_PROMOTION: {
61
+ target: 'debouncing',
62
+ actions: 'setPromotion',
63
+ },
64
+ SELECT_HOUSE_BANK: {
65
+ actions: 'setHouseBank',
66
+ },
67
+ INPUT_AMOUNT: {
68
+ target: 'debouncing',
69
+ actions: 'inputAmount',
70
+ },
71
+ },
72
+ },
73
+ debouncing: {
74
+ after: {
75
+ 1000: [{ target: 'calculating', cond: 'isCalculable' }, { target: 'loaded' }],
76
+ },
77
+ on: {
78
+ SET_PROMOTION: {
79
+ target: 'debouncing',
80
+ actions: 'setPromotion',
81
+ },
82
+ SELECT_HOUSE_BANK: {
83
+ actions: 'setHouseBank',
84
+ },
85
+ INPUT_AMOUNT: {
86
+ target: 'debouncing',
87
+ actions: 'inputAmount',
88
+ },
89
+ },
90
+ },
91
+ calculating: {
92
+ invoke: {
93
+ src: 'fetchCalculation',
94
+ onDone: {
95
+ target: 'calculated',
96
+ actions: 'setCalculation',
97
+ },
98
+ onError: {
99
+ target: 'loaded',
100
+ },
101
+ },
102
+ },
103
+ calculated: {
104
+ on: {
105
+ SET_PROMOTION: {
106
+ target: 'debouncing',
107
+ actions: 'setPromotion',
108
+ },
109
+ SELECT_HOUSE_BANK: {
110
+ actions: 'setHouseBank',
111
+ },
112
+ INPUT_AMOUNT: {
113
+ target: 'debouncing',
114
+ actions: 'inputAmount',
115
+ },
116
+ SELECT_USER_BANK: {
117
+ actions: 'setUserBank',
118
+ },
119
+ INPUT_USER_ACCOUNT_NUMBER: {
120
+ actions: 'setUserAccountNumber',
121
+ },
122
+ INPUT_USER_ACCOUNT_NAME: {
123
+ actions: 'setUserAccountName',
124
+ },
125
+ SET_RECEIPT: {
126
+ actions: 'setReceipt',
127
+ },
128
+ SET_DEPOSIT_TIME: {
129
+ actions: 'setDepositTime',
130
+ },
131
+ SUBMIT: {
132
+ target: 'submitting',
133
+ cond: 'isSubmittable',
134
+ },
135
+ },
136
+ },
137
+ submitting: {
138
+ invoke: {
139
+ src: 'submitDeposit',
140
+ onDone: {
141
+ target: 'submitted',
142
+ actions: 'setProcessing',
143
+ },
144
+ onError: {
145
+ target: 'loaded',
146
+ },
147
+ },
148
+ },
149
+ submitted: {},
150
+ },
151
+ on: {
152
+ SET_PROMOTION: {
153
+ actions: 'setPromotion',
154
+ },
155
+ },
156
+ },
157
+ {
158
+ actions: {
159
+ setInitData: assign((context, event) => {
160
+ const { currentPayment, banks, paymentInfo } = event.data
161
+ const playerBanks = paymentInfo?.bankInfo || []
162
+
163
+ const houseBanks = currentPayment.banks.map((bank) => {
164
+ bank.bankCode = bank.bankName // because api has no bankCode field
165
+ bank.imageUrl = banks.find((item) => item.bankCode === bank.bankName)?.imageUrl
166
+ return bank
167
+ })
168
+
169
+ const formattedPlayerBanks = playerBanks.map((bank) => {
170
+ bank.displayText = `${bank.bankCode} ${bank.accountNumber.slice(-5)}`
171
+ bank.imageUrl = banks.find((item) => item.bankCode === bank.bankCode)?.imageUrl
172
+ return bank
173
+ })
174
+
175
+ const userBanks = [...formattedPlayerBanks, ...banks]
176
+
177
+ return {
178
+ currentPayment,
179
+ method: currentPayment.method,
180
+ processing: currentPayment.processing?.[0],
181
+ houseBanks,
182
+ selectedHouseBank: houseBanks[0],
183
+ userBanks,
184
+ selectedUserBank: userBanks[0],
185
+ userAccountNumber: userBanks[0].accountNumber,
186
+ userAccountName: userBanks[0].holderName,
187
+ }
188
+ }),
189
+ setHouseBank: assign((context, event) => {
190
+ return {
191
+ selectedHouseBank: event.data,
192
+ }
193
+ }),
194
+ inputAmount: assign((context, event) => {
195
+ return { selectedAmount: event.data }
196
+ }),
197
+ setCalculation: assign((context, event) => {
198
+ return {
199
+ calculation: event.data,
200
+ }
201
+ }),
202
+ setProcessing: assign((context, event) => {
203
+ return {
204
+ processing: event.data,
205
+ }
206
+ }),
207
+ clearCalculation: assign((context, event) => {
208
+ return {
209
+ calculation: null,
210
+ }
211
+ }),
212
+ setUserBank: assign((context, event) => {
213
+ const { accountNumber, holderName } = event.data
214
+ return {
215
+ selectedUserBank: event.data,
216
+ userAccountNumber: accountNumber,
217
+ userAccountName: holderName,
218
+ }
219
+ }),
220
+ setUserAccountNumber: assign((context, event) => {
221
+ console.log('userAccountNumber', event.data)
222
+ return {
223
+ userAccountNumber: event.data,
224
+ }
225
+ }),
226
+ setUserAccountName: assign((context, event) => {
227
+ console.log('userAccountName', event.data)
228
+ return {
229
+ userAccountName: event.data,
230
+ }
231
+ }),
232
+ setDepositTime: assign((context, event) => {
233
+ return {
234
+ depositTime: event.data,
235
+ }
236
+ }),
237
+ setReceipt: assign((context, event) => {
238
+ return {
239
+ receipt: event.data,
240
+ }
241
+ }),
242
+ setPromotion: assign((context, event) => {
243
+ return {
244
+ promotion: event.data,
245
+ }
246
+ }),
247
+ setPromotionDefaultAmount: assign((context, event) => {
248
+ return {
249
+ selectedAmount: context.promotion.minimumAmount,
250
+ }
251
+ }),
252
+ },
253
+ guards: {
254
+ isCalculable: (context, event) => {
255
+ const {
256
+ selectedAmount,
257
+ currentPayment: { maximum, minimum },
258
+ } = context
259
+ return selectedAmount && minimum <= +selectedAmount && +selectedAmount <= maximum
260
+ },
261
+ isCalculated: (context, event) => {
262
+ return context.calculation
263
+ },
264
+ isSubmittable: (context, event) => {
265
+ const { selectedAmount, userAccountNumber, userAccountName, depositTime, receipt } = context
266
+ return selectedAmount && userAccountNumber && userAccountName && depositTime && receipt
267
+ },
268
+ isProcessing: (context, event) => {
269
+ return context.processing
270
+ },
271
+ hasMinPromotionDeposit: (context, event) => {
272
+ return context.promotion?.minimumAmount
273
+ },
274
+ },
275
+ services: {
276
+ fetchInitData: async (context, event) => {
277
+ const currentPayment = context.paymentDetail.find((element) => element.category === context.currentCategory)
278
+
279
+ const [banks, paymentInfo] = await Promise.all([
280
+ request.send(payment.getBankList(currentPayment.method)),
281
+ request.send(payment.getPaymentInfo()),
282
+ ])
283
+
284
+ return {
285
+ currentPayment,
286
+ banks,
287
+ paymentInfo,
288
+ }
289
+ },
290
+ fetchCalculation: async (context, event) => {
291
+ const { method, selectedAmount, promotion } = context
292
+ return await request.send(
293
+ payment.getDepositExpectedResult({
294
+ method,
295
+ amount: selectedAmount,
296
+ promotionsNo: promotion?.activityNo,
297
+ })
298
+ )
299
+ },
300
+ submitDeposit: async (context, event) => {
301
+ const { method, selectedAmount, selectedHouseBank, selectedUserBank, userAccountNumber, userAccountName, depositTime, receipt, promotion } =
302
+ context
303
+ return await request.send(
304
+ payment.submitDepositTransactionBank({
305
+ method,
306
+ amount: selectedAmount,
307
+ targetBankCode: selectedHouseBank.bankName,
308
+ targetAccountNumber: selectedHouseBank.accountNumber,
309
+ applyerBankCode: selectedUserBank.bankCode,
310
+ applyerAccountNumber: userAccountNumber,
311
+ applyerHolderName: userAccountName,
312
+ depositTime,
313
+ receipt,
314
+ promotionsNo: promotion?.activityNo,
315
+ })
316
+ )
317
+ },
318
+ },
319
+ }
320
+ )
321
+ }
@@ -0,0 +1,258 @@
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
+ }
@@ -0,0 +1,138 @@
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
+ }