@jetthai/cuora 1.0.131 → 1.0.132
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 +2 -0
- package/package.json +1 -1
- package/src/machine/bank_binding.js +5 -9
- package/src/machine/deposit/{web.js → crypto.js} +81 -48
- package/src/machine/deposit/index.js +2 -2
- package/src/machine/deposit/loadcard_vn.js +4 -4
- package/src/machine/deposit/manual_vn.js +2 -2
- package/src/machine/deposit/qrcode_v2.js +4 -4
- package/src/machine/deposit/qrcode_vn.js +4 -4
- package/src/machine/index.js +2 -0
- package/src/machine/withdraw_crypto.js +342 -0
- package/src/machine/withdraw_vn.js +2 -2
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.0.132](https://github.com/jetthai/cuora-module/compare/v1.0.131...v1.0.132) (2022-06-08)
|
|
6
|
+
|
|
5
7
|
### [1.0.131](https://github.com/jetthai/cuora-module/compare/v1.0.130...v1.0.131) (2022-06-06)
|
|
6
8
|
|
|
7
9
|
### [1.0.130](https://github.com/jetthai/cuora-module/compare/v1.0.129...v1.0.130) (2022-06-01)
|
package/package.json
CHANGED
|
@@ -19,7 +19,7 @@ export default function (request) {
|
|
|
19
19
|
src: 'fetchBanks',
|
|
20
20
|
onDone: {
|
|
21
21
|
target: 'idle',
|
|
22
|
-
actions:
|
|
22
|
+
actions: 'setBanks',
|
|
23
23
|
},
|
|
24
24
|
onError: {
|
|
25
25
|
target: 'idle',
|
|
@@ -79,14 +79,10 @@ export default function (request) {
|
|
|
79
79
|
{
|
|
80
80
|
actions: {
|
|
81
81
|
setBanks: assign((context, event) => {
|
|
82
|
+
const bankList = event.data || []
|
|
82
83
|
return {
|
|
83
|
-
bankList
|
|
84
|
-
bank:
|
|
85
|
-
}
|
|
86
|
-
}),
|
|
87
|
-
setDefaultBank: assign((context, event) => {
|
|
88
|
-
return {
|
|
89
|
-
bank: event.data[0],
|
|
84
|
+
bankList,
|
|
85
|
+
bank: bankList[0],
|
|
90
86
|
}
|
|
91
87
|
}),
|
|
92
88
|
},
|
|
@@ -99,7 +95,7 @@ export default function (request) {
|
|
|
99
95
|
services: {
|
|
100
96
|
fetchBanks: async (context, event) => {
|
|
101
97
|
const paymentDetail = await request.send(payment.getPaymentDetail({ transferType: 'WITHDRAW' }))
|
|
102
|
-
const method = paymentDetail.find((payment) => payment.
|
|
98
|
+
const method = paymentDetail.find((payment) => payment.category === 'manual').method
|
|
103
99
|
return await request.send(payment.getBankList(method))
|
|
104
100
|
},
|
|
105
101
|
updatePaymentInfo: async (context, event) => {
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import { assign, createMachine } from 'xstate'
|
|
2
|
+
import padStart from 'lodash/padStart'
|
|
2
3
|
import payment from '../../api/payment'
|
|
4
|
+
import toNumber from 'lodash/toNumber'
|
|
3
5
|
|
|
4
6
|
export default function (request) {
|
|
5
7
|
return createMachine(
|
|
6
8
|
{
|
|
7
|
-
id: '
|
|
9
|
+
id: 'crypto',
|
|
8
10
|
initial: 'loading',
|
|
9
11
|
context: {
|
|
10
12
|
paymentDetails: [],
|
|
11
13
|
|
|
14
|
+
channels: [],
|
|
12
15
|
cryptos: [],
|
|
13
16
|
networks: [],
|
|
14
17
|
sourceAddress: null,
|
|
@@ -17,11 +20,11 @@ export default function (request) {
|
|
|
17
20
|
selectedCrypto: null,
|
|
18
21
|
selectedNetwork: null,
|
|
19
22
|
|
|
20
|
-
|
|
23
|
+
currentCategory: 'crypto',
|
|
21
24
|
currentPayment: null,
|
|
22
25
|
|
|
23
26
|
calculation: null,
|
|
24
|
-
|
|
27
|
+
result: null,
|
|
25
28
|
},
|
|
26
29
|
states: {
|
|
27
30
|
loading: {
|
|
@@ -32,31 +35,17 @@ export default function (request) {
|
|
|
32
35
|
actions: 'setCryptos',
|
|
33
36
|
},
|
|
34
37
|
onError: {
|
|
35
|
-
target: '#
|
|
38
|
+
target: '#crypto.fail',
|
|
36
39
|
},
|
|
37
40
|
},
|
|
38
41
|
},
|
|
39
42
|
idle: {
|
|
43
|
+
always: [{ target: 'calculable', cond: 'isCalculable' }],
|
|
44
|
+
},
|
|
45
|
+
calculable: {
|
|
40
46
|
on: {
|
|
41
|
-
SET_CRYPTO: {
|
|
42
|
-
actions: 'setCrypto',
|
|
43
|
-
},
|
|
44
|
-
SET_NETWORK: {
|
|
45
|
-
actions: 'setNetwork',
|
|
46
|
-
},
|
|
47
|
-
SET_AMOUNT: {
|
|
48
|
-
actions: ['setAmount', 'clearCalculation'],
|
|
49
|
-
},
|
|
50
47
|
CALCULATE: {
|
|
51
48
|
target: 'calculating',
|
|
52
|
-
cond: 'isCalculable',
|
|
53
|
-
},
|
|
54
|
-
CLEAR_CALCULATION: {
|
|
55
|
-
actions: 'clearCalculation',
|
|
56
|
-
},
|
|
57
|
-
SUBMIT: {
|
|
58
|
-
target: 'submitting',
|
|
59
|
-
cond: 'isSubmittable',
|
|
60
49
|
},
|
|
61
50
|
},
|
|
62
51
|
},
|
|
@@ -64,7 +53,7 @@ export default function (request) {
|
|
|
64
53
|
invoke: {
|
|
65
54
|
src: 'fetchCalculation',
|
|
66
55
|
onDone: {
|
|
67
|
-
target: '
|
|
56
|
+
target: 'submittable',
|
|
68
57
|
actions: 'setCalculation',
|
|
69
58
|
},
|
|
70
59
|
onError: {
|
|
@@ -72,28 +61,60 @@ export default function (request) {
|
|
|
72
61
|
},
|
|
73
62
|
},
|
|
74
63
|
},
|
|
64
|
+
submittable: {
|
|
65
|
+
on: {
|
|
66
|
+
SUBMIT: {
|
|
67
|
+
target: 'submitting',
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
},
|
|
75
71
|
submitting: {
|
|
76
72
|
invoke: {
|
|
77
73
|
src: 'submitDeposit',
|
|
78
74
|
onDone: {
|
|
79
75
|
target: 'submitted',
|
|
80
|
-
actions: '
|
|
76
|
+
actions: 'setResult',
|
|
81
77
|
},
|
|
82
78
|
onError: {
|
|
83
79
|
target: 'idle',
|
|
84
80
|
},
|
|
85
81
|
},
|
|
86
82
|
},
|
|
87
|
-
processing: {},
|
|
88
83
|
submitted: {},
|
|
89
84
|
fail: {},
|
|
90
85
|
},
|
|
86
|
+
on: {
|
|
87
|
+
SET_CHANNEL: {
|
|
88
|
+
target: '.idle',
|
|
89
|
+
actions: 'setChannel',
|
|
90
|
+
},
|
|
91
|
+
SET_CRYPTO: {
|
|
92
|
+
target: '.idle',
|
|
93
|
+
actions: 'setCrypto',
|
|
94
|
+
},
|
|
95
|
+
SET_NETWORK: {
|
|
96
|
+
target: '.idle',
|
|
97
|
+
actions: 'setNetwork',
|
|
98
|
+
},
|
|
99
|
+
SET_ADDRESS: {
|
|
100
|
+
actions: 'setAddress',
|
|
101
|
+
},
|
|
102
|
+
SET_AMOUNT: {
|
|
103
|
+
target: '.idle',
|
|
104
|
+
actions: ['setAmount', 'clearCalculation'],
|
|
105
|
+
},
|
|
106
|
+
CLEAR_CALCULATION: {
|
|
107
|
+
target: '.idle',
|
|
108
|
+
actions: 'clearCalculation',
|
|
109
|
+
},
|
|
110
|
+
},
|
|
91
111
|
},
|
|
92
112
|
{
|
|
93
113
|
actions: {
|
|
94
114
|
setCryptos: assign((context, event) => {
|
|
95
115
|
const cryptos = event.data?.map?.((crypto) => ({ ...crypto, label: crypto.channel, value: crypto.method, icon: crypto.channel })) || []
|
|
96
|
-
const currentPayment = cryptos.find((element) => element.
|
|
116
|
+
const currentPayment = cryptos.find((element) => element.category === context.currentCategory)
|
|
117
|
+
const channels = cryptos.map((item, i) => ({ ...item, label: `Channel ${padStart(String(i + 1), 2, '0')}`, icon: 'channel' }))
|
|
97
118
|
const defaultNetworks =
|
|
98
119
|
cryptos[0].optional.map((value, i) => {
|
|
99
120
|
return {
|
|
@@ -103,12 +124,35 @@ export default function (request) {
|
|
|
103
124
|
}
|
|
104
125
|
}) || []
|
|
105
126
|
return {
|
|
127
|
+
channels,
|
|
106
128
|
cryptos,
|
|
129
|
+
networks: defaultNetworks,
|
|
130
|
+
selectedChannel: channels[0],
|
|
107
131
|
selectedCrypto: cryptos[0],
|
|
108
132
|
selectedNetwork: defaultNetworks[0],
|
|
109
133
|
currentPayment,
|
|
110
134
|
}
|
|
111
135
|
}),
|
|
136
|
+
setChannel: assign((context, event) => {
|
|
137
|
+
const { cryptos } = context
|
|
138
|
+
const selectedCrypto = cryptos.find((crypto) => crypto.method === event.data.value)
|
|
139
|
+
const networks =
|
|
140
|
+
selectedCrypto?.optional.map((value, i) => {
|
|
141
|
+
return {
|
|
142
|
+
label: selectedCrypto?.originalItem?.[i],
|
|
143
|
+
value,
|
|
144
|
+
icon: value,
|
|
145
|
+
}
|
|
146
|
+
}) || []
|
|
147
|
+
return {
|
|
148
|
+
networks,
|
|
149
|
+
selectedChannel: event.data,
|
|
150
|
+
selectedCrypto: selectedCrypto,
|
|
151
|
+
selectedNetwork: networks[0],
|
|
152
|
+
amount: null,
|
|
153
|
+
calculation: null,
|
|
154
|
+
}
|
|
155
|
+
}),
|
|
112
156
|
setCrypto: assign((context, event) => {
|
|
113
157
|
const { cryptos, selectedNetwork } = context
|
|
114
158
|
const method = cryptos.find((crypto) => crypto.method === event.data.value)
|
|
@@ -142,14 +186,14 @@ export default function (request) {
|
|
|
142
186
|
amount: event.data,
|
|
143
187
|
}
|
|
144
188
|
}),
|
|
145
|
-
|
|
189
|
+
setAddress: assign((context, event) => {
|
|
146
190
|
return {
|
|
147
|
-
|
|
191
|
+
sourceAddress: event.data,
|
|
148
192
|
}
|
|
149
193
|
}),
|
|
150
|
-
|
|
194
|
+
setCalculation: assign((context, event) => {
|
|
151
195
|
return {
|
|
152
|
-
|
|
196
|
+
calculation: event.data,
|
|
153
197
|
}
|
|
154
198
|
}),
|
|
155
199
|
clearCalculation: assign((context, event) => {
|
|
@@ -157,25 +201,21 @@ export default function (request) {
|
|
|
157
201
|
calculation: null,
|
|
158
202
|
}
|
|
159
203
|
}),
|
|
204
|
+
setResult: assign((context, event) => {
|
|
205
|
+
return {
|
|
206
|
+
result: event.data,
|
|
207
|
+
}
|
|
208
|
+
}),
|
|
160
209
|
},
|
|
161
210
|
guards: {
|
|
162
211
|
isCalculable: (context, event) => {
|
|
163
212
|
const {
|
|
213
|
+
selectedCrypto,
|
|
214
|
+
selectedNetwork,
|
|
164
215
|
amount,
|
|
165
216
|
currentPayment: { maximum, minimum },
|
|
166
217
|
} = context
|
|
167
|
-
return amount && minimum <= +amount && +amount <= maximum
|
|
168
|
-
},
|
|
169
|
-
isCalculated: (context, event) => {
|
|
170
|
-
return context.calculation
|
|
171
|
-
},
|
|
172
|
-
isSubmittable: (context, event) => {
|
|
173
|
-
console.log(context)
|
|
174
|
-
const { amount } = context
|
|
175
|
-
return amount
|
|
176
|
-
},
|
|
177
|
-
isProcessing: (context, event) => {
|
|
178
|
-
return context.processing
|
|
218
|
+
return selectedCrypto && selectedNetwork && amount && minimum <= +amount && +amount <= maximum
|
|
179
219
|
},
|
|
180
220
|
},
|
|
181
221
|
services: {
|
|
@@ -194,13 +234,6 @@ export default function (request) {
|
|
|
194
234
|
},
|
|
195
235
|
submitDeposit: async (context, event) => {
|
|
196
236
|
const { selectedCrypto, selectedNetwork, calculation, sourceAddress } = context
|
|
197
|
-
console.log({
|
|
198
|
-
method: selectedCrypto.method,
|
|
199
|
-
amount: calculation.actualAmount,
|
|
200
|
-
cryptoCurrency: selectedCrypto.channel,
|
|
201
|
-
cryptoNetwork: selectedNetwork.value,
|
|
202
|
-
sourceAddress: sourceAddress,
|
|
203
|
-
})
|
|
204
237
|
return await request.send(
|
|
205
238
|
payment.submitDepositTransaction({
|
|
206
239
|
method: selectedCrypto.method,
|
|
@@ -3,6 +3,6 @@ import loadcard_vn from './loadcard_vn'
|
|
|
3
3
|
import qrcode_vn from './qrcode_vn'
|
|
4
4
|
import qrcode_v2 from './qrcode_v2'
|
|
5
5
|
import deposit_fc from './deposit_fc'
|
|
6
|
-
import
|
|
6
|
+
import crypto from './crypto'
|
|
7
7
|
|
|
8
|
-
export default { manual_vn, loadcard_vn, qrcode_vn, qrcode_v2, deposit_fc,
|
|
8
|
+
export default { manual_vn, loadcard_vn, qrcode_vn, qrcode_v2, deposit_fc, crypto }
|
|
@@ -26,7 +26,7 @@ export default function (request) {
|
|
|
26
26
|
calculation: null,
|
|
27
27
|
|
|
28
28
|
paymentDetails: [],
|
|
29
|
-
|
|
29
|
+
currentCategory: 'loadcard',
|
|
30
30
|
currentMethod: null,
|
|
31
31
|
currentPayment: null,
|
|
32
32
|
},
|
|
@@ -150,7 +150,7 @@ export default function (request) {
|
|
|
150
150
|
}),
|
|
151
151
|
setInitData: assign((context, event) => {
|
|
152
152
|
const paymentDetails = event.data
|
|
153
|
-
const currentPayment = paymentDetails.find((element) => element.
|
|
153
|
+
const currentPayment = paymentDetails.find((element) => element.category === context.currentCategory)
|
|
154
154
|
return {
|
|
155
155
|
paymentDetails,
|
|
156
156
|
currentPayment,
|
|
@@ -199,8 +199,8 @@ export default function (request) {
|
|
|
199
199
|
return await request.send(payment.getPaymentDetail({ transferType: 'DEPOSIT' }))
|
|
200
200
|
},
|
|
201
201
|
fetchBanksList: async (context, event) => {
|
|
202
|
-
const { paymentDetails,
|
|
203
|
-
const method = paymentDetails.find((item) => item.
|
|
202
|
+
const { paymentDetails, currentCategory } = context
|
|
203
|
+
const method = paymentDetails.find((item) => item.category === currentCategory)?.method
|
|
204
204
|
return await request.send(payment.getBankList(method))
|
|
205
205
|
},
|
|
206
206
|
fetchCalculation: async (context, event) => {
|
|
@@ -21,7 +21,7 @@ export default function (request) {
|
|
|
21
21
|
depositTime: null,
|
|
22
22
|
receipt: null,
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
currentCategory: 'manual',
|
|
25
25
|
method: null,
|
|
26
26
|
currentPayment: null,
|
|
27
27
|
currentApplyerBank: null,
|
|
@@ -178,7 +178,7 @@ export default function (request) {
|
|
|
178
178
|
setInitData: assign((context, event) => {
|
|
179
179
|
const { paymentInfo, paymentDetails } = event.data
|
|
180
180
|
const bankInfoList = paymentInfo?.bankInfo || []
|
|
181
|
-
const currentPayment = paymentDetails.find((element) => element.
|
|
181
|
+
const currentPayment = paymentDetails.find((element) => element.category === context.currentCategory)
|
|
182
182
|
const houseBanks = currentPayment.banks.map((item) => {
|
|
183
183
|
item.bankCode = item.bankName
|
|
184
184
|
return item
|
|
@@ -16,7 +16,7 @@ export default function (request) {
|
|
|
16
16
|
calculation: null,
|
|
17
17
|
|
|
18
18
|
paymentDetails: [],
|
|
19
|
-
|
|
19
|
+
currentCategory: 'qrcode',
|
|
20
20
|
currentMethod: null,
|
|
21
21
|
|
|
22
22
|
result: null,
|
|
@@ -135,7 +135,7 @@ export default function (request) {
|
|
|
135
135
|
}),
|
|
136
136
|
setInitData: assign((context, event) => {
|
|
137
137
|
const paymentDetails = event.data
|
|
138
|
-
const qrcodes = paymentDetails.filter((element) => element.
|
|
138
|
+
const qrcodes = paymentDetails.filter((element) => element.category === context.currentCategory)
|
|
139
139
|
|
|
140
140
|
return {
|
|
141
141
|
paymentDetails,
|
|
@@ -179,8 +179,8 @@ export default function (request) {
|
|
|
179
179
|
return await request.send(payment.getPaymentDetail({ transferType: 'DEPOSIT' }))
|
|
180
180
|
},
|
|
181
181
|
fetchBanksList: async (context, event) => {
|
|
182
|
-
const { paymentDetails,
|
|
183
|
-
const method = paymentDetails.find((item) => item.
|
|
182
|
+
const { paymentDetails, currentCategory } = context
|
|
183
|
+
const method = paymentDetails.find((item) => item.category === currentCategory)?.method
|
|
184
184
|
return await request.send(payment.getBankList(method))
|
|
185
185
|
},
|
|
186
186
|
fetchCalculation: async (context, event) => {
|
|
@@ -16,7 +16,7 @@ export default function (request) {
|
|
|
16
16
|
calculation: null,
|
|
17
17
|
|
|
18
18
|
paymentDetails: [],
|
|
19
|
-
|
|
19
|
+
currentCategory: 'qrcode',
|
|
20
20
|
currentMethod: null,
|
|
21
21
|
|
|
22
22
|
result: null,
|
|
@@ -134,7 +134,7 @@ export default function (request) {
|
|
|
134
134
|
}),
|
|
135
135
|
setInitData: assign((context, event) => {
|
|
136
136
|
const paymentDetails = event.data
|
|
137
|
-
const qrcodes = paymentDetails.filter((element) => element.
|
|
137
|
+
const qrcodes = paymentDetails.filter((element) => element.category === context.currentCategory)
|
|
138
138
|
|
|
139
139
|
return {
|
|
140
140
|
paymentDetails,
|
|
@@ -178,8 +178,8 @@ export default function (request) {
|
|
|
178
178
|
return await request.send(payment.getPaymentDetail({ transferType: 'DEPOSIT' }))
|
|
179
179
|
},
|
|
180
180
|
fetchBanksList: async (context, event) => {
|
|
181
|
-
const { paymentDetails,
|
|
182
|
-
const method = paymentDetails.find((item) => item.
|
|
181
|
+
const { paymentDetails, currentCategory } = context
|
|
182
|
+
const method = paymentDetails.find((item) => item.category === currentCategory)?.method
|
|
183
183
|
return await request.send(payment.getBankList(method))
|
|
184
184
|
},
|
|
185
185
|
fetchCalculation: async (context, event) => {
|
package/src/machine/index.js
CHANGED
|
@@ -22,6 +22,7 @@ import user_reset_password from './user_reset_password'
|
|
|
22
22
|
import bank_binding from './bank_binding'
|
|
23
23
|
import withdraw_fc from './withdraw_fc'
|
|
24
24
|
import withdraw_vn from './withdraw_vn'
|
|
25
|
+
import withdraw_crypto from './withdraw_crypto'
|
|
25
26
|
import deposit from './deposit'
|
|
26
27
|
import bonus from './bonus'
|
|
27
28
|
import leaderboard from './leaderboard'
|
|
@@ -54,6 +55,7 @@ export default {
|
|
|
54
55
|
bank_binding,
|
|
55
56
|
withdraw_fc,
|
|
56
57
|
withdraw_vn,
|
|
58
|
+
withdraw_crypto,
|
|
57
59
|
...deposit,
|
|
58
60
|
bonus,
|
|
59
61
|
leaderboard,
|
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
import { assign, createMachine } from 'xstate'
|
|
2
|
+
import findLastIndex from 'lodash/findLastIndex'
|
|
3
|
+
import payment from '../api/payment'
|
|
4
|
+
import common from '../api/common'
|
|
5
|
+
import user from '../api/user'
|
|
6
|
+
import api from '../api/payment'
|
|
7
|
+
|
|
8
|
+
export default function (request) {
|
|
9
|
+
const { appSecret } = request.config
|
|
10
|
+
return createMachine(
|
|
11
|
+
{
|
|
12
|
+
id: 'withdraw_crypto',
|
|
13
|
+
initial: 'loading',
|
|
14
|
+
context: {
|
|
15
|
+
siteConfig: null,
|
|
16
|
+
userInfo: null,
|
|
17
|
+
balance: null,
|
|
18
|
+
|
|
19
|
+
methods: [],
|
|
20
|
+
paymentDetail: [],
|
|
21
|
+
|
|
22
|
+
withdrawLimit: null,
|
|
23
|
+
targetWithdrawLimit: null,
|
|
24
|
+
|
|
25
|
+
maxWithdrawAmount: null,
|
|
26
|
+
availableWithdrawAmount: null,
|
|
27
|
+
|
|
28
|
+
networks: [],
|
|
29
|
+
selectedNetwork: null,
|
|
30
|
+
address: '',
|
|
31
|
+
amount: null,
|
|
32
|
+
|
|
33
|
+
charge: null,
|
|
34
|
+
realAmount: null,
|
|
35
|
+
},
|
|
36
|
+
states: {
|
|
37
|
+
loading: {
|
|
38
|
+
invoke: {
|
|
39
|
+
src: 'fetchInitData',
|
|
40
|
+
onDone: {
|
|
41
|
+
target: 'mode',
|
|
42
|
+
actions: ['setInitData', 'preset'],
|
|
43
|
+
},
|
|
44
|
+
onError: {
|
|
45
|
+
target: 'fail',
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
mode: {
|
|
50
|
+
always: [{ target: 'free', cond: 'isFree' }, { target: 'cash' }],
|
|
51
|
+
},
|
|
52
|
+
free: {
|
|
53
|
+
initial: 'loading',
|
|
54
|
+
states: {
|
|
55
|
+
loading: {
|
|
56
|
+
invoke: {
|
|
57
|
+
src: 'fetchWithdrawRules',
|
|
58
|
+
onDone: {
|
|
59
|
+
target: 'checking',
|
|
60
|
+
actions: 'updateWithdrawCondition',
|
|
61
|
+
},
|
|
62
|
+
onError: {
|
|
63
|
+
target: 'notConvertible',
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
checking: {
|
|
68
|
+
always: [{ target: 'convertible', cond: 'isConvertible' }, { target: 'notConvertible' }],
|
|
69
|
+
},
|
|
70
|
+
notConvertible: {},
|
|
71
|
+
convertible: {
|
|
72
|
+
on: {
|
|
73
|
+
SUBMIT: {
|
|
74
|
+
target: 'converting',
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
converting: {
|
|
79
|
+
invoke: {
|
|
80
|
+
src: 'submitWithdrawFree',
|
|
81
|
+
onDone: {
|
|
82
|
+
target: 'converted',
|
|
83
|
+
},
|
|
84
|
+
onError: {
|
|
85
|
+
target: 'convertible',
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
converted: {},
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
cash: {
|
|
93
|
+
initial: 'checking',
|
|
94
|
+
states: {
|
|
95
|
+
checking: {
|
|
96
|
+
always: [
|
|
97
|
+
{ target: 'inProcessing', cond: 'haveProcessing' },
|
|
98
|
+
{ target: 'notWithdrawable', cond: 'isNotWithdrawable' },
|
|
99
|
+
{ target: 'withdrawable' },
|
|
100
|
+
],
|
|
101
|
+
},
|
|
102
|
+
notWithdrawable: {},
|
|
103
|
+
inProcessing: {},
|
|
104
|
+
withdrawable: {
|
|
105
|
+
on: {
|
|
106
|
+
SET_NETWORK: {
|
|
107
|
+
actions: ['resetCharge', 'setNetwork'],
|
|
108
|
+
},
|
|
109
|
+
SET_ADDRESS: {
|
|
110
|
+
actions: 'setAddress',
|
|
111
|
+
},
|
|
112
|
+
SET_AMOUNT: {
|
|
113
|
+
actions: ['resetCharge', 'setAmount'],
|
|
114
|
+
},
|
|
115
|
+
CALCULATE: {
|
|
116
|
+
target: 'calculating',
|
|
117
|
+
cond: 'isCalculable',
|
|
118
|
+
},
|
|
119
|
+
PREVIEW: {
|
|
120
|
+
target: 'submittable',
|
|
121
|
+
cond: 'isSubmittable',
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
calculating: {
|
|
126
|
+
entry: 'resetCharge',
|
|
127
|
+
invoke: {
|
|
128
|
+
src: 'fetchCalculation',
|
|
129
|
+
onDone: {
|
|
130
|
+
target: 'withdrawable',
|
|
131
|
+
actions: 'setCalculatedResult',
|
|
132
|
+
},
|
|
133
|
+
onError: {
|
|
134
|
+
target: 'withdrawable',
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
submittable: {
|
|
139
|
+
on: {
|
|
140
|
+
SUBMIT: {
|
|
141
|
+
target: 'submitting',
|
|
142
|
+
},
|
|
143
|
+
BACK: {
|
|
144
|
+
target: 'withdrawable',
|
|
145
|
+
},
|
|
146
|
+
},
|
|
147
|
+
},
|
|
148
|
+
submitting: {
|
|
149
|
+
invoke: {
|
|
150
|
+
src: 'submitWithdraw',
|
|
151
|
+
onDone: {
|
|
152
|
+
target: 'submitted',
|
|
153
|
+
actions: 'setResult',
|
|
154
|
+
},
|
|
155
|
+
onError: {
|
|
156
|
+
target: 'withdrawable',
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
},
|
|
160
|
+
submitted: {},
|
|
161
|
+
},
|
|
162
|
+
},
|
|
163
|
+
fail: {},
|
|
164
|
+
},
|
|
165
|
+
on: {
|
|
166
|
+
REFRESH: {
|
|
167
|
+
target: 'loading',
|
|
168
|
+
},
|
|
169
|
+
},
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
actions: {
|
|
173
|
+
setInitData: assign((context, event) => {
|
|
174
|
+
const method = event.data.paymentDetail?.[0]
|
|
175
|
+
return {
|
|
176
|
+
paymentDetail: event.data.paymentDetail,
|
|
177
|
+
crypto: method,
|
|
178
|
+
networks:
|
|
179
|
+
method?.optional?.map?.((value, i) => {
|
|
180
|
+
return {
|
|
181
|
+
label: method?.originalItem?.[i],
|
|
182
|
+
value,
|
|
183
|
+
icon: value,
|
|
184
|
+
}
|
|
185
|
+
}) || [],
|
|
186
|
+
}
|
|
187
|
+
}),
|
|
188
|
+
setPaymentData: assign((context, event) => {
|
|
189
|
+
return {
|
|
190
|
+
paymentDetail: event.data.paymentDetail,
|
|
191
|
+
}
|
|
192
|
+
}),
|
|
193
|
+
preset: assign((context, event) => {
|
|
194
|
+
const { userInfo, siteConfig } = event.data
|
|
195
|
+
const { withdraw_limit, target_withdraw_limit } = userInfo || {}
|
|
196
|
+
const balance = parseFloat(userInfo?.balance)
|
|
197
|
+
const methods = siteConfig?.paymentMethods?.withdraw || []
|
|
198
|
+
return {
|
|
199
|
+
withdrawLimit: Math.abs(withdraw_limit),
|
|
200
|
+
targetWithdrawLimit: Math.abs(target_withdraw_limit),
|
|
201
|
+
methods,
|
|
202
|
+
balance,
|
|
203
|
+
siteConfig,
|
|
204
|
+
userInfo,
|
|
205
|
+
}
|
|
206
|
+
}),
|
|
207
|
+
updateWithdrawCondition: assign((context, event) => {
|
|
208
|
+
const rules = event.data.rules.filter((rule) => rule.maxWithdrawAmount > 0)
|
|
209
|
+
|
|
210
|
+
const { balance, withdrawLimit } = context
|
|
211
|
+
const lastMatchedIndex = findLastIndex(rules, (rule) => balance >= rule.greaterEqualThen)
|
|
212
|
+
|
|
213
|
+
let maxWithdrawAmount = 0,
|
|
214
|
+
availableWithdrawAmount = 0
|
|
215
|
+
|
|
216
|
+
if (lastMatchedIndex > -1) {
|
|
217
|
+
rules[lastMatchedIndex].match = true
|
|
218
|
+
maxWithdrawAmount = rules[lastMatchedIndex].maxWithdrawAmount
|
|
219
|
+
|
|
220
|
+
if (withdrawLimit === 0) {
|
|
221
|
+
availableWithdrawAmount = Math.min(balance, maxWithdrawAmount)
|
|
222
|
+
}
|
|
223
|
+
} else if (rules.length > 0) {
|
|
224
|
+
maxWithdrawAmount = rules[0].maxWithdrawAmount
|
|
225
|
+
} else {
|
|
226
|
+
maxWithdrawAmount = balance
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
return {
|
|
230
|
+
maxWithdrawAmount,
|
|
231
|
+
availableWithdrawAmount,
|
|
232
|
+
}
|
|
233
|
+
}),
|
|
234
|
+
setNetwork: assign((context, event) => {
|
|
235
|
+
return {
|
|
236
|
+
selectedNetwork: event.data,
|
|
237
|
+
}
|
|
238
|
+
}),
|
|
239
|
+
setAddress: assign((context, event) => {
|
|
240
|
+
return {
|
|
241
|
+
address: event.data,
|
|
242
|
+
}
|
|
243
|
+
}),
|
|
244
|
+
setAmount: assign((context, event) => {
|
|
245
|
+
return {
|
|
246
|
+
amount: event.data,
|
|
247
|
+
}
|
|
248
|
+
}),
|
|
249
|
+
setCalculatedResult: assign((context, event) => {
|
|
250
|
+
return {
|
|
251
|
+
charge: event.data.charge,
|
|
252
|
+
}
|
|
253
|
+
}),
|
|
254
|
+
resetCharge: assign((context, event) => {
|
|
255
|
+
return {
|
|
256
|
+
charge: null,
|
|
257
|
+
}
|
|
258
|
+
}),
|
|
259
|
+
setTransaction: assign((context, event) => {
|
|
260
|
+
const { realAmount } = event.data
|
|
261
|
+
return {
|
|
262
|
+
realAmount,
|
|
263
|
+
}
|
|
264
|
+
}),
|
|
265
|
+
},
|
|
266
|
+
guards: {
|
|
267
|
+
isFree: (context, event) => {
|
|
268
|
+
return context.userInfo?.withdraw_rule !== 'DEFAULT'
|
|
269
|
+
},
|
|
270
|
+
haveProcessing: (context, event) => {
|
|
271
|
+
return (context.paymentDetail?.[0]?.processing || []).length > 0
|
|
272
|
+
},
|
|
273
|
+
isWithdrawDisable: (context, event) => {
|
|
274
|
+
const { siteConfig } = context
|
|
275
|
+
const methods = siteConfig?.paymentMethods?.withdraw || []
|
|
276
|
+
return methods.length === 0
|
|
277
|
+
},
|
|
278
|
+
isSubmittable: (context, event) => {
|
|
279
|
+
const { selectedNetwork, address, amount, charge } = context
|
|
280
|
+
return selectedNetwork && address && amount && charge
|
|
281
|
+
},
|
|
282
|
+
isConvertible: (context, event) => {
|
|
283
|
+
const { balance, withdrawLimit } = context
|
|
284
|
+
return balance > 0 && withdrawLimit === 0
|
|
285
|
+
},
|
|
286
|
+
isNotWithdrawable: (context, event) => {
|
|
287
|
+
const { balance, withdrawLimit, paymentDetail } = context
|
|
288
|
+
const minWithdrawAmount = paymentDetail[0]?.minimum || 0
|
|
289
|
+
return withdrawLimit !== 0 || balance < minWithdrawAmount
|
|
290
|
+
},
|
|
291
|
+
isCalculable: (context, event) => {
|
|
292
|
+
const { selectedNetwork, amount } = context
|
|
293
|
+
return selectedNetwork && amount
|
|
294
|
+
},
|
|
295
|
+
},
|
|
296
|
+
services: {
|
|
297
|
+
fetchInitData: async (context, event) => {
|
|
298
|
+
const [{ config }, userInfo, paymentDetail = []] = await Promise.all([
|
|
299
|
+
request.send(common.getConfig({ appSecret })),
|
|
300
|
+
request.send(user.getUserInfo()),
|
|
301
|
+
request.send(payment.getPaymentDetail({ transferType: 'WITHDRAW' })),
|
|
302
|
+
])
|
|
303
|
+
const siteConfig = JSON.parse(window.atob(config))
|
|
304
|
+
return { siteConfig, userInfo, paymentDetail }
|
|
305
|
+
},
|
|
306
|
+
fetchPaymentData: async (context, event) => {
|
|
307
|
+
const paymentDetail = await request.send(payment.getPaymentDetail({ transferType: 'WITHDRAW' }))
|
|
308
|
+
return { paymentDetail }
|
|
309
|
+
},
|
|
310
|
+
fetchWithdrawRules: async (context, event) => {
|
|
311
|
+
return await request.send(payment.getCurrentWithdrawRule())
|
|
312
|
+
},
|
|
313
|
+
submitWithdraw: async (context, event) => {
|
|
314
|
+
const { crypto, selectedNetwork, address, amount } = context
|
|
315
|
+
return await request.send(
|
|
316
|
+
api.submitWithdrawTransaction({
|
|
317
|
+
method: crypto.method,
|
|
318
|
+
amount,
|
|
319
|
+
cryptoCurrency: crypto.channel,
|
|
320
|
+
cryptoNetwork: selectedNetwork.value,
|
|
321
|
+
targetAddress: address,
|
|
322
|
+
})
|
|
323
|
+
)
|
|
324
|
+
},
|
|
325
|
+
submitWithdrawFree: async (context, event) => {
|
|
326
|
+
return await request.send(payment.convertFreeCredit({ exchangeType: 1 }))
|
|
327
|
+
},
|
|
328
|
+
fetchCalculation: async (context, event) => {
|
|
329
|
+
const { crypto, selectedNetwork, amount } = context
|
|
330
|
+
const method = crypto.method
|
|
331
|
+
return await request.send(
|
|
332
|
+
api.getWithdrawExpectedResult({
|
|
333
|
+
method,
|
|
334
|
+
amount,
|
|
335
|
+
cryptoNetwork: selectedNetwork.value,
|
|
336
|
+
})
|
|
337
|
+
)
|
|
338
|
+
},
|
|
339
|
+
},
|
|
340
|
+
}
|
|
341
|
+
)
|
|
342
|
+
}
|
|
@@ -227,7 +227,7 @@ export default function (request) {
|
|
|
227
227
|
return context.userInfo?.withdraw_rule !== 'DEFAULT'
|
|
228
228
|
},
|
|
229
229
|
haveProcessing: (context, event) => {
|
|
230
|
-
return context.paymentDetail[0]
|
|
230
|
+
return (context.paymentDetail?.[0]?.processing || []).length > 0
|
|
231
231
|
},
|
|
232
232
|
isWithdrawDisable: (context, event) => {
|
|
233
233
|
const { siteConfig } = context
|
|
@@ -260,7 +260,7 @@ export default function (request) {
|
|
|
260
260
|
request.send(payment.getPaymentInfo()),
|
|
261
261
|
])
|
|
262
262
|
const siteConfig = JSON.parse(window.atob(config))
|
|
263
|
-
const method = paymentDetail.find((payment) => payment.
|
|
263
|
+
const method = paymentDetail.find((payment) => payment.category === 'manual').method
|
|
264
264
|
const bankList = await request.send(payment.getBankList(method))
|
|
265
265
|
const newBankInfo = bankInfo.map((item) => {
|
|
266
266
|
return { ...item, ...bankList.find((bank) => bank.bankCode === item.bankCode) }
|