@jetthai/cuora 1.1.178 → 1.1.179
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/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
### [1.1.179](https://github.com/jetthai/cuora-module/compare/v1.1.178...v1.1.179) (2023-09-19)
|
|
6
|
+
|
|
5
7
|
### [1.1.178](https://github.com/jetthai/cuora-module/compare/v1.1.177...v1.1.178) (2023-09-19)
|
|
6
8
|
|
|
7
9
|
### [1.1.177](https://github.com/jetthai/cuora-module/compare/v1.1.176...v1.1.177) (2023-09-19)
|
package/package.json
CHANGED
package/src/api/payment.js
CHANGED
|
@@ -74,6 +74,11 @@ export default {
|
|
|
74
74
|
method: 'post',
|
|
75
75
|
params: { transferType: 'DEPOSIT', amount, cryptoCurrency, promotionsNo },
|
|
76
76
|
}),
|
|
77
|
+
getCryptoDepositExpectedResult: ({ method, amount, cryptoCurrency, promotionsNo }) => ({
|
|
78
|
+
url: `payment/v2/${method}/crypto/expected/result`,
|
|
79
|
+
method: 'post',
|
|
80
|
+
params: { transferType: 'DEPOSIT', amount, cryptoCurrency, promotionsNo },
|
|
81
|
+
}),
|
|
77
82
|
getWithdrawExpectedResult: ({ method, amount, cryptoNetwork }) => ({
|
|
78
83
|
url: `payment/v2/${method}/expected/result`,
|
|
79
84
|
method: 'post',
|
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
import { assign, createMachine } from 'xstate'
|
|
2
|
+
import padStart from 'lodash/padStart.js'
|
|
3
|
+
import payment from '@jetthai/cuora/src/api/payment.js'
|
|
4
|
+
|
|
5
|
+
export default function (request) {
|
|
6
|
+
const { appSecret } = request.config
|
|
7
|
+
return createMachine(
|
|
8
|
+
{
|
|
9
|
+
id: 'crypto_bank',
|
|
10
|
+
initial: 'loading',
|
|
11
|
+
context: {
|
|
12
|
+
paymentDetails: [],
|
|
13
|
+
|
|
14
|
+
channels: [],
|
|
15
|
+
cryptos: [],
|
|
16
|
+
networks: [],
|
|
17
|
+
sourceAddress: '',
|
|
18
|
+
|
|
19
|
+
houseBanks: [],
|
|
20
|
+
banks: [],
|
|
21
|
+
|
|
22
|
+
amount: null,
|
|
23
|
+
selectedHouseBank: null,
|
|
24
|
+
selectedChannel: null,
|
|
25
|
+
selectedCrypto: null,
|
|
26
|
+
selectedNetwork: null,
|
|
27
|
+
|
|
28
|
+
currentCategory: 'cryptoBank',
|
|
29
|
+
currentPayment: null,
|
|
30
|
+
|
|
31
|
+
calculation: null,
|
|
32
|
+
processing: null,
|
|
33
|
+
result: null,
|
|
34
|
+
|
|
35
|
+
depositTime: null,
|
|
36
|
+
receipt: null,
|
|
37
|
+
|
|
38
|
+
// use for wallet mode 4
|
|
39
|
+
promotion: null,
|
|
40
|
+
},
|
|
41
|
+
states: {
|
|
42
|
+
loading: {
|
|
43
|
+
initial: 'init1',
|
|
44
|
+
states: {
|
|
45
|
+
init1: {
|
|
46
|
+
invoke: {
|
|
47
|
+
src: 'fetchPayments',
|
|
48
|
+
onDone: {
|
|
49
|
+
target: 'init2',
|
|
50
|
+
actions: 'setPayment',
|
|
51
|
+
},
|
|
52
|
+
onError: {
|
|
53
|
+
target: '#crypto_bank.fail',
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
init2: {
|
|
58
|
+
always: [
|
|
59
|
+
{
|
|
60
|
+
target: '#crypto_bank.processing',
|
|
61
|
+
cond: 'isProcessing',
|
|
62
|
+
},
|
|
63
|
+
{ target: '#crypto_bank.loaded' },
|
|
64
|
+
],
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
loaded: {
|
|
69
|
+
always: [{ target: 'debouncing', cond: 'isCalculable' }],
|
|
70
|
+
},
|
|
71
|
+
debouncing: {
|
|
72
|
+
after: {
|
|
73
|
+
1000: {
|
|
74
|
+
target: 'calculating',
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
calculating: {
|
|
79
|
+
invoke: {
|
|
80
|
+
src: 'fetchCalculation',
|
|
81
|
+
onDone: {
|
|
82
|
+
target: 'calculated',
|
|
83
|
+
actions: 'setCalculation',
|
|
84
|
+
},
|
|
85
|
+
onError: {
|
|
86
|
+
target: 'loaded',
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
calculated: {
|
|
91
|
+
on: {
|
|
92
|
+
SUBMIT: [
|
|
93
|
+
{
|
|
94
|
+
target: 'pending',
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
target: 'submitting',
|
|
98
|
+
cond: 'isSubmittable',
|
|
99
|
+
},
|
|
100
|
+
],
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
pending: {
|
|
104
|
+
on: {
|
|
105
|
+
SUBMIT: {
|
|
106
|
+
target: 'submitting',
|
|
107
|
+
cond: 'isSubmittable',
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
submitting: {
|
|
112
|
+
invoke: {
|
|
113
|
+
src: 'submitDeposit',
|
|
114
|
+
onDone: {
|
|
115
|
+
target: 'submitted',
|
|
116
|
+
actions: 'setResult',
|
|
117
|
+
},
|
|
118
|
+
onError: {
|
|
119
|
+
target: 'loaded',
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
processing: {},
|
|
124
|
+
submitted: {},
|
|
125
|
+
fail: {},
|
|
126
|
+
},
|
|
127
|
+
on: {
|
|
128
|
+
SET_CHANNEL: {
|
|
129
|
+
target: '.loaded',
|
|
130
|
+
actions: 'setChannel',
|
|
131
|
+
},
|
|
132
|
+
SET_CRYPTO: {
|
|
133
|
+
target: '.loaded',
|
|
134
|
+
actions: 'setCrypto',
|
|
135
|
+
},
|
|
136
|
+
SET_NETWORK: {
|
|
137
|
+
target: '.loaded',
|
|
138
|
+
actions: 'setNetwork',
|
|
139
|
+
},
|
|
140
|
+
SET_ADDRESS: {
|
|
141
|
+
actions: 'setAddress',
|
|
142
|
+
},
|
|
143
|
+
SET_AMOUNT: {
|
|
144
|
+
target: '.loaded',
|
|
145
|
+
actions: ['setAmount', 'clearCalculation'],
|
|
146
|
+
},
|
|
147
|
+
CALCULATE: {
|
|
148
|
+
target: '.debouncing',
|
|
149
|
+
actions: 'clearCalculation',
|
|
150
|
+
},
|
|
151
|
+
SET_DEPOSIT_TIME: {
|
|
152
|
+
actions: 'setDepositTime',
|
|
153
|
+
},
|
|
154
|
+
SET_RECEIPT: {
|
|
155
|
+
actions: 'setReceipt',
|
|
156
|
+
},
|
|
157
|
+
SET_PROMOTION: {
|
|
158
|
+
actions: 'setPromotion',
|
|
159
|
+
},
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
actions: {
|
|
164
|
+
setPayment: assign((context, event) => {
|
|
165
|
+
const cryptos =
|
|
166
|
+
event.data
|
|
167
|
+
.filter((element) => element.category === context.currentCategory)
|
|
168
|
+
.map?.((crypto) => ({ ...crypto, label: crypto.channel, value: crypto.method, icon: crypto.channel })) || []
|
|
169
|
+
const currentPayment = cryptos.find((element) => element.category === context.currentCategory)
|
|
170
|
+
const houseBanks = currentPayment.banks?.map((item) => {
|
|
171
|
+
item.bankCode = item.bankName
|
|
172
|
+
return item
|
|
173
|
+
})
|
|
174
|
+
const channels = cryptos.map((item, i) => ({ ...item, label: `Channel ${padStart(String(i + 1), 2, '0')}`, icon: 'channel' }))
|
|
175
|
+
const defaultNetworks =
|
|
176
|
+
cryptos[0].networkName.map((value, i) => {
|
|
177
|
+
return {
|
|
178
|
+
label: cryptos[0].networkOptional?.[i],
|
|
179
|
+
value,
|
|
180
|
+
icon: value,
|
|
181
|
+
}
|
|
182
|
+
}) || []
|
|
183
|
+
const selectedHouseBank = houseBanks.find((element) => element.network === defaultNetworks[0]?.value) || {}
|
|
184
|
+
return {
|
|
185
|
+
channels,
|
|
186
|
+
cryptos,
|
|
187
|
+
networks: defaultNetworks,
|
|
188
|
+
selectedChannel: channels[0],
|
|
189
|
+
selectedCrypto: cryptos[0],
|
|
190
|
+
selectedNetwork: defaultNetworks[0],
|
|
191
|
+
currentPayment,
|
|
192
|
+
houseBanks,
|
|
193
|
+
selectedHouseBank,
|
|
194
|
+
processing: currentPayment.processing?.[0],
|
|
195
|
+
}
|
|
196
|
+
}),
|
|
197
|
+
setChannel: assign((context, event) => {
|
|
198
|
+
const { cryptos } = context
|
|
199
|
+
const selectedCrypto = cryptos.find((crypto) => crypto.method === event.data.value)
|
|
200
|
+
const networks =
|
|
201
|
+
selectedCrypto?.networkName.map((value, i) => {
|
|
202
|
+
return {
|
|
203
|
+
label: selectedCrypto?.networkOptional?.[i],
|
|
204
|
+
value,
|
|
205
|
+
icon: value,
|
|
206
|
+
}
|
|
207
|
+
}) || []
|
|
208
|
+
return {
|
|
209
|
+
networks,
|
|
210
|
+
selectedChannel: event.data,
|
|
211
|
+
selectedCrypto: selectedCrypto,
|
|
212
|
+
selectedNetwork: networks[0],
|
|
213
|
+
amount: null,
|
|
214
|
+
calculation: null,
|
|
215
|
+
}
|
|
216
|
+
}),
|
|
217
|
+
setCrypto: assign((context, event) => {
|
|
218
|
+
const { cryptos, selectedNetwork } = context
|
|
219
|
+
const method = cryptos.find((crypto) => crypto.method === event.data.value)
|
|
220
|
+
const networks =
|
|
221
|
+
method?.networkName.map((value, i) => {
|
|
222
|
+
return {
|
|
223
|
+
label: method?.networkOptional?.[i],
|
|
224
|
+
value,
|
|
225
|
+
icon: value,
|
|
226
|
+
}
|
|
227
|
+
}) || []
|
|
228
|
+
|
|
229
|
+
const properties = {
|
|
230
|
+
selectedCrypto: event.data,
|
|
231
|
+
networks,
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
if (!networks.includes(selectedNetwork)) {
|
|
235
|
+
properties.selectedNetwork = null
|
|
236
|
+
properties.amount = null
|
|
237
|
+
properties.calculation = null
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
return properties
|
|
241
|
+
}),
|
|
242
|
+
setNetwork: assign((context, event) => {
|
|
243
|
+
const { houseBanks } = context
|
|
244
|
+
const currentNetwork = houseBanks.find((element) => element.network === event.data.value) || houseBanks[0]
|
|
245
|
+
|
|
246
|
+
return { selectedNetwork: event.data, selectedHouseBank: currentNetwork }
|
|
247
|
+
}),
|
|
248
|
+
setAmount: assign((context, event) => {
|
|
249
|
+
return {
|
|
250
|
+
amount: event.data,
|
|
251
|
+
}
|
|
252
|
+
}),
|
|
253
|
+
setAddress: assign((context, event) => {
|
|
254
|
+
return {
|
|
255
|
+
sourceAddress: event.data,
|
|
256
|
+
}
|
|
257
|
+
}),
|
|
258
|
+
setCalculation: assign((context, event) => {
|
|
259
|
+
return {
|
|
260
|
+
calculation: event.data,
|
|
261
|
+
}
|
|
262
|
+
}),
|
|
263
|
+
clearCalculation: assign((context, event) => {
|
|
264
|
+
return {
|
|
265
|
+
calculation: null,
|
|
266
|
+
}
|
|
267
|
+
}),
|
|
268
|
+
setResult: assign((context, event) => {
|
|
269
|
+
return {
|
|
270
|
+
result: event.data,
|
|
271
|
+
}
|
|
272
|
+
}),
|
|
273
|
+
setDepositTime: assign((context, event) => {
|
|
274
|
+
return {
|
|
275
|
+
depositTime: event.data,
|
|
276
|
+
}
|
|
277
|
+
}),
|
|
278
|
+
setReceipt: assign((context, event) => {
|
|
279
|
+
return {
|
|
280
|
+
receipt: event.data,
|
|
281
|
+
}
|
|
282
|
+
}),
|
|
283
|
+
setPromotion: assign((context, event) => {
|
|
284
|
+
const promotion = event.data
|
|
285
|
+
return {
|
|
286
|
+
promotion,
|
|
287
|
+
}
|
|
288
|
+
}),
|
|
289
|
+
},
|
|
290
|
+
guards: {
|
|
291
|
+
isCalculable: (context, event) => {
|
|
292
|
+
const {
|
|
293
|
+
selectedCrypto,
|
|
294
|
+
selectedNetwork,
|
|
295
|
+
amount,
|
|
296
|
+
currentPayment: { maximum, minimum },
|
|
297
|
+
} = context
|
|
298
|
+
return selectedCrypto && selectedNetwork && amount && minimum <= +amount && +amount <= maximum
|
|
299
|
+
},
|
|
300
|
+
isSubmittable: (context, event) => {
|
|
301
|
+
const { selectedCrypto, selectedNetwork, amount } = context
|
|
302
|
+
return selectedCrypto && selectedNetwork && amount
|
|
303
|
+
},
|
|
304
|
+
isProcessing: (context, event) => {
|
|
305
|
+
return context.processing
|
|
306
|
+
},
|
|
307
|
+
},
|
|
308
|
+
services: {
|
|
309
|
+
fetchPayments: async (context, event) => {
|
|
310
|
+
return await request.send(payment.getPaymentDetail({ transferType: 'DEPOSIT' }))
|
|
311
|
+
},
|
|
312
|
+
fetchCalculation: async (context, event) => {
|
|
313
|
+
const { selectedCrypto, amount, promotion } = context
|
|
314
|
+
return await request.send(
|
|
315
|
+
payment.getCryptoDepositExpectedResult({
|
|
316
|
+
method: selectedCrypto.method,
|
|
317
|
+
amount,
|
|
318
|
+
cryptoCurrency: selectedCrypto.channel,
|
|
319
|
+
promotionsNo: promotion?.activityNo,
|
|
320
|
+
})
|
|
321
|
+
)
|
|
322
|
+
},
|
|
323
|
+
submitDeposit: async (context, event) => {
|
|
324
|
+
const { selectedCrypto, selectedNetwork, calculation, depositTime, receipt, amount } = context
|
|
325
|
+
return await request.send(
|
|
326
|
+
payment.submitDepositTransactionCrypto({
|
|
327
|
+
method: selectedCrypto.method,
|
|
328
|
+
amount: calculation.actualAmount,
|
|
329
|
+
cryptoCurrency: selectedCrypto.channel,
|
|
330
|
+
cryptoNetwork: selectedNetwork.value,
|
|
331
|
+
depositTime,
|
|
332
|
+
receipt,
|
|
333
|
+
})
|
|
334
|
+
)
|
|
335
|
+
},
|
|
336
|
+
},
|
|
337
|
+
}
|
|
338
|
+
)
|
|
339
|
+
}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { assign, createMachine } from 'xstate'
|
|
2
|
+
import payment from '@jetthai/cuora/src/api/payment.js'
|
|
3
|
+
|
|
4
|
+
export default function (request) {
|
|
5
|
+
return createMachine(
|
|
6
|
+
{
|
|
7
|
+
id: 'crypto_qrcode',
|
|
8
|
+
initial: 'loading',
|
|
9
|
+
context: {
|
|
10
|
+
paymentDetails: [],
|
|
11
|
+
currentCategory: 'cryptoQrcode',
|
|
12
|
+
currentPayment: null,
|
|
13
|
+
networks: [],
|
|
14
|
+
selectedCrypto: null,
|
|
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
|
+
invoke: {
|
|
31
|
+
src: 'fetchPayments',
|
|
32
|
+
onDone: {
|
|
33
|
+
target: 'fetching',
|
|
34
|
+
actions: 'setPayment',
|
|
35
|
+
},
|
|
36
|
+
onError: {
|
|
37
|
+
target: 'fail',
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
finding: {
|
|
42
|
+
always: [
|
|
43
|
+
{
|
|
44
|
+
target: 'idle',
|
|
45
|
+
actions: 'setResultFromLocal',
|
|
46
|
+
cond: 'isFound',
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
target: 'fetching',
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
},
|
|
53
|
+
fetching: {
|
|
54
|
+
invoke: {
|
|
55
|
+
src: 'submitDeposit',
|
|
56
|
+
onDone: {
|
|
57
|
+
target: 'idle',
|
|
58
|
+
actions: 'setResult',
|
|
59
|
+
},
|
|
60
|
+
onError: {
|
|
61
|
+
target: 'idle',
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
idle: {},
|
|
66
|
+
fail: {},
|
|
67
|
+
},
|
|
68
|
+
on: {
|
|
69
|
+
SET_NETWORK: {
|
|
70
|
+
target: '.finding',
|
|
71
|
+
actions: 'setNetwork',
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
actions: {
|
|
77
|
+
setPayment: assign((context, event) => {
|
|
78
|
+
const cryptos =
|
|
79
|
+
event.data
|
|
80
|
+
.filter((element) => element.category === context.currentCategory)
|
|
81
|
+
.map?.((crypto) => ({ ...crypto, label: crypto.channel, value: crypto.method, icon: crypto.channel })) || []
|
|
82
|
+
const currentPayment = event.data.find((element) => element.category === context.currentCategory)
|
|
83
|
+
const defaultNetworks =
|
|
84
|
+
currentPayment.networkName.map((value, i) => {
|
|
85
|
+
return {
|
|
86
|
+
label: currentPayment.networkOptional?.[i],
|
|
87
|
+
value,
|
|
88
|
+
icon: value,
|
|
89
|
+
}
|
|
90
|
+
}) || []
|
|
91
|
+
|
|
92
|
+
return {
|
|
93
|
+
networks: defaultNetworks,
|
|
94
|
+
selectedNetwork: defaultNetworks[0],
|
|
95
|
+
currentPayment,
|
|
96
|
+
selectedCrypto: cryptos[0],
|
|
97
|
+
}
|
|
98
|
+
}),
|
|
99
|
+
setNetwork: assign((context, event) => {
|
|
100
|
+
return { selectedNetwork: event.data }
|
|
101
|
+
}),
|
|
102
|
+
setResultFromLocal: assign((context, event) => {
|
|
103
|
+
const { resultMap, selectedNetwork } = context
|
|
104
|
+
return { result: resultMap[selectedNetwork.value] }
|
|
105
|
+
}),
|
|
106
|
+
setResult: assign((context, event) => {
|
|
107
|
+
const { resultMap, selectedNetwork } = context
|
|
108
|
+
const { action, cdtime, accountNumber, currency, network, name, qrcode } = event.data
|
|
109
|
+
const result = {
|
|
110
|
+
action,
|
|
111
|
+
cdtime,
|
|
112
|
+
accountNumber,
|
|
113
|
+
currency,
|
|
114
|
+
network,
|
|
115
|
+
name,
|
|
116
|
+
qrcode,
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return {
|
|
120
|
+
result,
|
|
121
|
+
resultMap: {
|
|
122
|
+
...resultMap,
|
|
123
|
+
[selectedNetwork.value]: result,
|
|
124
|
+
},
|
|
125
|
+
}
|
|
126
|
+
}),
|
|
127
|
+
},
|
|
128
|
+
guards: {
|
|
129
|
+
isFound: (context, event) => {
|
|
130
|
+
const { resultMap, selectedNetwork } = context
|
|
131
|
+
return resultMap[selectedNetwork.value]
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
services: {
|
|
135
|
+
fetchPayments: async (context, event) => {
|
|
136
|
+
return await request.send(payment.getPaymentDetail({ transferType: 'DEPOSIT' }))
|
|
137
|
+
},
|
|
138
|
+
submitDeposit: async (context, event) => {
|
|
139
|
+
const { currentPayment, selectedNetwork } = context
|
|
140
|
+
return await request.send(
|
|
141
|
+
payment.submitDepositTransactionCrypto({
|
|
142
|
+
method: currentPayment.method,
|
|
143
|
+
cryptoCurrency: currentPayment.channel,
|
|
144
|
+
cryptoNetwork: selectedNetwork.value,
|
|
145
|
+
})
|
|
146
|
+
)
|
|
147
|
+
},
|
|
148
|
+
},
|
|
149
|
+
}
|
|
150
|
+
)
|
|
151
|
+
}
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
import { assign, createMachine } from 'xstate'
|
|
2
|
+
import padStart from 'lodash/padStart.js'
|
|
3
|
+
import payment from '@jetthai/cuora/src/api/payment.js'
|
|
4
|
+
import common from '../../api/common.js'
|
|
5
|
+
|
|
6
|
+
export default function (request) {
|
|
7
|
+
const { appSecret } = request.config
|
|
8
|
+
return createMachine(
|
|
9
|
+
{
|
|
10
|
+
id: 'crypto_way',
|
|
11
|
+
initial: 'loading',
|
|
12
|
+
context: {
|
|
13
|
+
paymentDetails: [],
|
|
14
|
+
|
|
15
|
+
channels: [],
|
|
16
|
+
cryptos: [],
|
|
17
|
+
networks: [],
|
|
18
|
+
sourceAddress: '',
|
|
19
|
+
|
|
20
|
+
amount: null,
|
|
21
|
+
selectedChannel: null,
|
|
22
|
+
selectedCrypto: null,
|
|
23
|
+
selectedNetwork: null,
|
|
24
|
+
|
|
25
|
+
currentCategory: 'cryptoWay',
|
|
26
|
+
currentPayment: null,
|
|
27
|
+
|
|
28
|
+
calculation: null,
|
|
29
|
+
result: null,
|
|
30
|
+
|
|
31
|
+
// use for wallet mode 4
|
|
32
|
+
promotion: null,
|
|
33
|
+
},
|
|
34
|
+
states: {
|
|
35
|
+
loading: {
|
|
36
|
+
invoke: {
|
|
37
|
+
src: 'fetchPayments',
|
|
38
|
+
onDone: {
|
|
39
|
+
target: 'loaded',
|
|
40
|
+
actions: 'setPayment',
|
|
41
|
+
},
|
|
42
|
+
onError: {
|
|
43
|
+
target: '#crypto_way.fail',
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
loaded: {
|
|
48
|
+
always: [{ target: 'debouncing', cond: 'isCalculable' }],
|
|
49
|
+
},
|
|
50
|
+
debouncing: {
|
|
51
|
+
after: {
|
|
52
|
+
1000: {
|
|
53
|
+
target: 'calculating',
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
calculating: {
|
|
58
|
+
invoke: {
|
|
59
|
+
src: 'fetchCalculation',
|
|
60
|
+
onDone: {
|
|
61
|
+
target: 'calculated',
|
|
62
|
+
actions: 'setCalculation',
|
|
63
|
+
},
|
|
64
|
+
onError: {
|
|
65
|
+
target: 'loaded',
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
calculated: {
|
|
70
|
+
on: {
|
|
71
|
+
SUBMIT: [
|
|
72
|
+
{
|
|
73
|
+
target: 'pending',
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
target: 'submitting',
|
|
77
|
+
cond: 'isSubmittable',
|
|
78
|
+
},
|
|
79
|
+
],
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
pending: {
|
|
83
|
+
on: {
|
|
84
|
+
SUBMIT: {
|
|
85
|
+
target: 'submitting',
|
|
86
|
+
cond: 'isSubmittable',
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
submitting: {
|
|
91
|
+
invoke: {
|
|
92
|
+
src: 'submitDeposit',
|
|
93
|
+
onDone: {
|
|
94
|
+
target: 'submitted',
|
|
95
|
+
actions: 'setResult',
|
|
96
|
+
},
|
|
97
|
+
onError: {
|
|
98
|
+
target: 'loaded',
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
submitted: {},
|
|
103
|
+
fail: {},
|
|
104
|
+
},
|
|
105
|
+
on: {
|
|
106
|
+
SET_CHANNEL: {
|
|
107
|
+
target: '.loaded',
|
|
108
|
+
actions: 'setChannel',
|
|
109
|
+
},
|
|
110
|
+
SET_CRYPTO: {
|
|
111
|
+
target: '.loaded',
|
|
112
|
+
actions: 'setCrypto',
|
|
113
|
+
},
|
|
114
|
+
SET_NETWORK: {
|
|
115
|
+
target: '.loaded',
|
|
116
|
+
actions: 'setNetwork',
|
|
117
|
+
},
|
|
118
|
+
SET_ADDRESS: {
|
|
119
|
+
actions: 'setAddress',
|
|
120
|
+
},
|
|
121
|
+
SET_AMOUNT: {
|
|
122
|
+
target: '.loaded',
|
|
123
|
+
actions: ['setAmount', 'clearCalculation'],
|
|
124
|
+
},
|
|
125
|
+
CALCULATE: {
|
|
126
|
+
target: '.debouncing',
|
|
127
|
+
actions: 'clearCalculation',
|
|
128
|
+
},
|
|
129
|
+
SET_PROMOTION: {
|
|
130
|
+
actions: 'setPromotion',
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
actions: {
|
|
136
|
+
setPayment: assign((context, event) => {
|
|
137
|
+
const cryptos =
|
|
138
|
+
event.data
|
|
139
|
+
.filter((element) => element.category === context.currentCategory)
|
|
140
|
+
.map?.((crypto) => ({ ...crypto, label: crypto.channel, value: crypto.method, icon: crypto.channel })) || []
|
|
141
|
+
const currentPayment = cryptos.find((element) => element.category === context.currentCategory)
|
|
142
|
+
const channels = cryptos.map((item, i) => ({ ...item, label: `Channel ${padStart(String(i + 1), 2, '0')}`, icon: 'channel' }))
|
|
143
|
+
const defaultNetworks =
|
|
144
|
+
cryptos[0].networkName.map((value, i) => {
|
|
145
|
+
return {
|
|
146
|
+
label: cryptos[0].networkOptional?.[i],
|
|
147
|
+
value,
|
|
148
|
+
icon: value,
|
|
149
|
+
}
|
|
150
|
+
}) || []
|
|
151
|
+
return {
|
|
152
|
+
channels,
|
|
153
|
+
cryptos,
|
|
154
|
+
networks: defaultNetworks,
|
|
155
|
+
selectedChannel: channels[0],
|
|
156
|
+
selectedCrypto: cryptos[0],
|
|
157
|
+
selectedNetwork: defaultNetworks[0],
|
|
158
|
+
currentPayment,
|
|
159
|
+
}
|
|
160
|
+
}),
|
|
161
|
+
setChannel: assign((context, event) => {
|
|
162
|
+
const { cryptos } = context
|
|
163
|
+
const selectedCrypto = cryptos.find((crypto) => crypto.method === event.data.value)
|
|
164
|
+
const networks =
|
|
165
|
+
selectedCrypto?.networkName.map((value, i) => {
|
|
166
|
+
return {
|
|
167
|
+
label: selectedCrypto?.networkOptional?.[i],
|
|
168
|
+
value,
|
|
169
|
+
icon: value,
|
|
170
|
+
}
|
|
171
|
+
}) || []
|
|
172
|
+
return {
|
|
173
|
+
networks,
|
|
174
|
+
selectedChannel: event.data,
|
|
175
|
+
selectedCrypto: selectedCrypto,
|
|
176
|
+
selectedNetwork: networks[0],
|
|
177
|
+
amount: null,
|
|
178
|
+
calculation: null,
|
|
179
|
+
}
|
|
180
|
+
}),
|
|
181
|
+
setCrypto: assign((context, event) => {
|
|
182
|
+
const { cryptos, selectedNetwork } = context
|
|
183
|
+
const method = cryptos.find((crypto) => crypto.method === event.data.value)
|
|
184
|
+
const networks =
|
|
185
|
+
method?.networkName.map((value, i) => {
|
|
186
|
+
return {
|
|
187
|
+
label: method?.networkOptional?.[i],
|
|
188
|
+
value,
|
|
189
|
+
icon: value,
|
|
190
|
+
}
|
|
191
|
+
}) || []
|
|
192
|
+
|
|
193
|
+
const properties = {
|
|
194
|
+
selectedCrypto: event.data,
|
|
195
|
+
networks,
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
if (!networks.includes(selectedNetwork)) {
|
|
199
|
+
properties.selectedNetwork = null
|
|
200
|
+
properties.amount = null
|
|
201
|
+
properties.calculation = null
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
return properties
|
|
205
|
+
}),
|
|
206
|
+
setNetwork: assign((context, event) => {
|
|
207
|
+
return { selectedNetwork: event.data }
|
|
208
|
+
}),
|
|
209
|
+
setAmount: assign((context, event) => {
|
|
210
|
+
return {
|
|
211
|
+
amount: event.data,
|
|
212
|
+
}
|
|
213
|
+
}),
|
|
214
|
+
setAddress: assign((context, event) => {
|
|
215
|
+
return {
|
|
216
|
+
sourceAddress: event.data,
|
|
217
|
+
}
|
|
218
|
+
}),
|
|
219
|
+
setCalculation: assign((context, event) => {
|
|
220
|
+
return {
|
|
221
|
+
calculation: event.data,
|
|
222
|
+
}
|
|
223
|
+
}),
|
|
224
|
+
clearCalculation: assign((context, event) => {
|
|
225
|
+
return {
|
|
226
|
+
calculation: null,
|
|
227
|
+
}
|
|
228
|
+
}),
|
|
229
|
+
setResult: assign((context, event) => {
|
|
230
|
+
return {
|
|
231
|
+
result: event.data,
|
|
232
|
+
}
|
|
233
|
+
}),
|
|
234
|
+
setPromotion: assign((context, event) => {
|
|
235
|
+
const promotion = event.data
|
|
236
|
+
return {
|
|
237
|
+
promotion,
|
|
238
|
+
}
|
|
239
|
+
}),
|
|
240
|
+
},
|
|
241
|
+
guards: {
|
|
242
|
+
isCalculable: (context, event) => {
|
|
243
|
+
const {
|
|
244
|
+
selectedCrypto,
|
|
245
|
+
selectedNetwork,
|
|
246
|
+
amount,
|
|
247
|
+
currentPayment: { maximum, minimum },
|
|
248
|
+
} = context
|
|
249
|
+
return selectedCrypto && selectedNetwork && amount && minimum <= +amount && +amount <= maximum
|
|
250
|
+
},
|
|
251
|
+
isSubmittable: (context, event) => {
|
|
252
|
+
const { selectedCrypto, selectedNetwork, amount } = context
|
|
253
|
+
return selectedCrypto && selectedNetwork && amount
|
|
254
|
+
},
|
|
255
|
+
},
|
|
256
|
+
services: {
|
|
257
|
+
fetchPayments: async (context, event) => {
|
|
258
|
+
return await request.send(payment.getPaymentDetail({ transferType: 'DEPOSIT' }))
|
|
259
|
+
},
|
|
260
|
+
fetchCalculation: async (context, event) => {
|
|
261
|
+
const { selectedCrypto, amount, promotion } = context
|
|
262
|
+
return await request.send(
|
|
263
|
+
payment.getCryptoDepositExpectedResult({
|
|
264
|
+
method: selectedCrypto.method,
|
|
265
|
+
amount,
|
|
266
|
+
cryptoCurrency: selectedCrypto.channel,
|
|
267
|
+
promotionsNo: promotion?.activityNo,
|
|
268
|
+
})
|
|
269
|
+
)
|
|
270
|
+
},
|
|
271
|
+
submitDeposit: async (context, event) => {
|
|
272
|
+
const { selectedCrypto, selectedNetwork, calculation } = context
|
|
273
|
+
return await request.send(
|
|
274
|
+
payment.submitDepositTransactionCrypto({
|
|
275
|
+
method: selectedCrypto.method,
|
|
276
|
+
amount: calculation.actualAmount,
|
|
277
|
+
cryptoCurrency: selectedCrypto.channel,
|
|
278
|
+
cryptoNetwork: selectedNetwork.value,
|
|
279
|
+
})
|
|
280
|
+
)
|
|
281
|
+
},
|
|
282
|
+
},
|
|
283
|
+
}
|
|
284
|
+
)
|
|
285
|
+
}
|
|
@@ -17,6 +17,9 @@ import usdt_cash from './usdt_cash.js'
|
|
|
17
17
|
import crypto_cash from './crypto_cash.js'
|
|
18
18
|
import direct_cash from './direct_cash.js'
|
|
19
19
|
import loadcard_cash from './loadcard_cash.js'
|
|
20
|
+
import crypto_bank from './crypto_bank.js'
|
|
21
|
+
import crypto_qrcode from './crypto_qrcode.js'
|
|
22
|
+
import crypto_way from './crypto_way.js'
|
|
20
23
|
|
|
21
24
|
export default {
|
|
22
25
|
manual_vn,
|
|
@@ -38,4 +41,7 @@ export default {
|
|
|
38
41
|
crypto_cash,
|
|
39
42
|
direct_cash,
|
|
40
43
|
loadcard_cash,
|
|
44
|
+
crypto_bank,
|
|
45
|
+
crypto_qrcode,
|
|
46
|
+
crypto_way,
|
|
41
47
|
}
|