@jetthai/cuora 1.0.32 → 1.0.34
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 +4 -0
- package/package.json +1 -1
- package/src/machine/deposit.js +14 -7
- package/src/machine/withdraw.js +59 -52
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
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.34](https://github.com/jetthai/cuora-module/compare/v1.0.33...v1.0.34) (2021-10-26)
|
|
6
|
+
|
|
7
|
+
### [1.0.33](https://github.com/jetthai/cuora-module/compare/v1.0.32...v1.0.33) (2021-10-22)
|
|
8
|
+
|
|
5
9
|
### [1.0.32](https://github.com/jetthai/cuora-module/compare/v1.0.31...v1.0.32) (2021-10-21)
|
|
6
10
|
|
|
7
11
|
### [1.0.31](https://github.com/jetthai/cuora-module/compare/v1.0.30...v1.0.31) (2021-10-21)
|
package/package.json
CHANGED
package/src/machine/deposit.js
CHANGED
|
@@ -127,12 +127,19 @@ export default function (request) {
|
|
|
127
127
|
actions: {
|
|
128
128
|
setCryptos: assign((context, event) => {
|
|
129
129
|
return {
|
|
130
|
-
cryptos: event.data,
|
|
130
|
+
cryptos: event.data.map((crypto) => ({ ...crypto, label: crypto.channel, value: crypto.channel })),
|
|
131
131
|
}
|
|
132
132
|
}),
|
|
133
133
|
setCrypto: assign((context, event) => {
|
|
134
134
|
const { cryptos, currentNetwork } = context
|
|
135
|
-
const
|
|
135
|
+
const method = cryptos.find((crypto) => crypto.channel === event.data.value)
|
|
136
|
+
const networks =
|
|
137
|
+
method?.optional.map((value, i) => {
|
|
138
|
+
return {
|
|
139
|
+
label: method?.originalItem?.[i],
|
|
140
|
+
value,
|
|
141
|
+
}
|
|
142
|
+
}) || []
|
|
136
143
|
|
|
137
144
|
const properties = {
|
|
138
145
|
currentCrypto: event.data,
|
|
@@ -209,24 +216,24 @@ export default function (request) {
|
|
|
209
216
|
},
|
|
210
217
|
fetchCalculation: async (context, event) => {
|
|
211
218
|
const { cryptos, currentCrypto, currentAmount } = context
|
|
212
|
-
const method = cryptos.find((crypto) => crypto.channel === currentCrypto)?.method
|
|
219
|
+
const method = cryptos.find((crypto) => crypto.channel === currentCrypto.value)?.method
|
|
213
220
|
return await request.send(
|
|
214
221
|
payment.getDepositExpectedResult({
|
|
215
222
|
method,
|
|
216
223
|
amount: currentAmount,
|
|
217
|
-
cryptoCurrency: currentCrypto,
|
|
224
|
+
cryptoCurrency: currentCrypto.value,
|
|
218
225
|
})
|
|
219
226
|
)
|
|
220
227
|
},
|
|
221
228
|
submitDeposit: async (context, event) => {
|
|
222
229
|
const { cryptos, currentCrypto, currentNetwork, calculatedResult } = context
|
|
223
|
-
const method = cryptos.find((crypto) => crypto.channel === currentCrypto)?.method
|
|
230
|
+
const method = cryptos.find((crypto) => crypto.channel === currentCrypto.value)?.method
|
|
224
231
|
return await request.send(
|
|
225
232
|
payment.submitDepositTransaction({
|
|
226
233
|
method,
|
|
227
234
|
amount: calculatedResult.actualAmount,
|
|
228
|
-
cryptoCurrency: currentCrypto,
|
|
229
|
-
cryptoNetwork: currentNetwork,
|
|
235
|
+
cryptoCurrency: currentCrypto.value,
|
|
236
|
+
cryptoNetwork: currentNetwork.value,
|
|
230
237
|
})
|
|
231
238
|
)
|
|
232
239
|
},
|
package/src/machine/withdraw.js
CHANGED
|
@@ -13,14 +13,14 @@ export default function (request) {
|
|
|
13
13
|
userInfo: null,
|
|
14
14
|
crypto: null,
|
|
15
15
|
networks: [],
|
|
16
|
-
currentNetwork:
|
|
16
|
+
currentNetwork: null,
|
|
17
17
|
currentAddress: '',
|
|
18
18
|
withdrawMethods: [],
|
|
19
19
|
withdrawRuleName: null,
|
|
20
20
|
withdrawRules: [],
|
|
21
21
|
withdrawLimit: null,
|
|
22
22
|
withdrawAmount: null,
|
|
23
|
-
|
|
23
|
+
withdrawDistance: null,
|
|
24
24
|
tutorialUrls: [],
|
|
25
25
|
balance: null,
|
|
26
26
|
charge: null,
|
|
@@ -29,11 +29,24 @@ export default function (request) {
|
|
|
29
29
|
idle: {
|
|
30
30
|
on: {
|
|
31
31
|
PRESET: {
|
|
32
|
-
target: '
|
|
32
|
+
target: 'preparing',
|
|
33
33
|
actions: ['setSiteConfig', 'setUserInfo', 'preset'],
|
|
34
34
|
},
|
|
35
35
|
},
|
|
36
36
|
},
|
|
37
|
+
preparing: {
|
|
38
|
+
invoke: {
|
|
39
|
+
src: 'fetchPaymentConfig',
|
|
40
|
+
onDone: {
|
|
41
|
+
target: 'mode',
|
|
42
|
+
actions: 'setCrypto',
|
|
43
|
+
},
|
|
44
|
+
onError: {
|
|
45
|
+
target: 'fail',
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
fail: {},
|
|
37
50
|
mode: {
|
|
38
51
|
always: [{ target: 'free', cond: 'isFree' }, { target: 'cash' }],
|
|
39
52
|
},
|
|
@@ -44,7 +57,7 @@ export default function (request) {
|
|
|
44
57
|
invoke: {
|
|
45
58
|
src: 'fetchWithdrawRules',
|
|
46
59
|
onDone: {
|
|
47
|
-
target: '
|
|
60
|
+
target: 'checking',
|
|
48
61
|
actions: 'updateWithdrawCondition',
|
|
49
62
|
},
|
|
50
63
|
onError: {
|
|
@@ -52,22 +65,14 @@ export default function (request) {
|
|
|
52
65
|
},
|
|
53
66
|
},
|
|
54
67
|
},
|
|
68
|
+
checking: {
|
|
69
|
+
entry: 'recalculateDistance',
|
|
70
|
+
always: [{ target: 'convertible', cond: 'isConvertible' }, { target: 'notConvertible' }],
|
|
71
|
+
},
|
|
55
72
|
notConvertible: {},
|
|
56
73
|
convertible: {
|
|
57
|
-
initial: '
|
|
74
|
+
initial: 'operation',
|
|
58
75
|
states: {
|
|
59
|
-
preparing: {
|
|
60
|
-
invoke: {
|
|
61
|
-
src: 'fetchPayments',
|
|
62
|
-
onDone: {
|
|
63
|
-
target: 'operation',
|
|
64
|
-
actions: 'setCrypto',
|
|
65
|
-
},
|
|
66
|
-
onError: {
|
|
67
|
-
target: '#withdraw.free.notConvertible',
|
|
68
|
-
},
|
|
69
|
-
},
|
|
70
|
-
},
|
|
71
76
|
operation: {
|
|
72
77
|
on: {
|
|
73
78
|
SET_NETWORK: {
|
|
@@ -118,7 +123,7 @@ export default function (request) {
|
|
|
118
123
|
initial: 'checking',
|
|
119
124
|
states: {
|
|
120
125
|
checking: {
|
|
121
|
-
entry: '
|
|
126
|
+
entry: 'recalculateDistance',
|
|
122
127
|
always: [
|
|
123
128
|
{ target: 'disable', cond: 'isWithdrawDisable' },
|
|
124
129
|
{ target: 'transferable', cond: 'isTransferable' },
|
|
@@ -129,20 +134,8 @@ export default function (request) {
|
|
|
129
134
|
notTransferable: {},
|
|
130
135
|
transferable: {
|
|
131
136
|
entry: 'setBalanceToWithdrawAmount',
|
|
132
|
-
initial: '
|
|
137
|
+
initial: 'operation',
|
|
133
138
|
states: {
|
|
134
|
-
preparing: {
|
|
135
|
-
invoke: {
|
|
136
|
-
src: 'fetchPayments',
|
|
137
|
-
onDone: {
|
|
138
|
-
target: 'operation',
|
|
139
|
-
actions: 'setCrypto',
|
|
140
|
-
},
|
|
141
|
-
onError: {
|
|
142
|
-
target: '#withdraw.cash.checking',
|
|
143
|
-
},
|
|
144
|
-
},
|
|
145
|
-
},
|
|
146
139
|
operation: {
|
|
147
140
|
on: {
|
|
148
141
|
SET_NETWORK: {
|
|
@@ -227,8 +220,8 @@ export default function (request) {
|
|
|
227
220
|
const { balance, withdrawLimit } = context
|
|
228
221
|
const lastMatchedIndex = findLastIndex(rules, (rule) => balance >= rule.greaterEqualThen)
|
|
229
222
|
|
|
230
|
-
let
|
|
231
|
-
limit,
|
|
223
|
+
let distance = 0,
|
|
224
|
+
limit = 0,
|
|
232
225
|
amount = 0
|
|
233
226
|
if (lastMatchedIndex > -1) {
|
|
234
227
|
rules[lastMatchedIndex].match = true
|
|
@@ -237,18 +230,19 @@ export default function (request) {
|
|
|
237
230
|
} else if (withdrawLimit) {
|
|
238
231
|
const diff = withdrawLimit - balance
|
|
239
232
|
limit = withdrawLimit
|
|
240
|
-
if (diff
|
|
233
|
+
if (diff <= 0) {
|
|
241
234
|
amount = balance
|
|
242
235
|
} else {
|
|
243
|
-
|
|
236
|
+
distance = diff
|
|
244
237
|
}
|
|
238
|
+
} else if (rules.length > 0) {
|
|
239
|
+
limit = rules[0]?.greaterEqualThen || 0
|
|
240
|
+
distance = Math.max(limit - balance, 0)
|
|
245
241
|
} else {
|
|
246
|
-
|
|
247
|
-
limit = rules[0]?.greaterEqualThen
|
|
242
|
+
amount = balance
|
|
248
243
|
}
|
|
249
|
-
|
|
250
244
|
return {
|
|
251
|
-
|
|
245
|
+
withdrawDistance: distance,
|
|
252
246
|
withdrawAmount: amount,
|
|
253
247
|
withdrawLimit: limit,
|
|
254
248
|
withdrawRules: rules,
|
|
@@ -261,9 +255,16 @@ export default function (request) {
|
|
|
261
255
|
}
|
|
262
256
|
}),
|
|
263
257
|
setCrypto: assign((context, event) => {
|
|
258
|
+
const method = event.data?.[0]
|
|
264
259
|
return {
|
|
265
|
-
crypto:
|
|
266
|
-
networks:
|
|
260
|
+
crypto: method,
|
|
261
|
+
networks:
|
|
262
|
+
method?.optional.map((value, i) => {
|
|
263
|
+
return {
|
|
264
|
+
label: method?.originalItem?.[i],
|
|
265
|
+
value,
|
|
266
|
+
}
|
|
267
|
+
}) || [],
|
|
267
268
|
}
|
|
268
269
|
}),
|
|
269
270
|
setNetwork: assign((context, event) => {
|
|
@@ -286,12 +287,13 @@ export default function (request) {
|
|
|
286
287
|
charge: null,
|
|
287
288
|
}
|
|
288
289
|
}),
|
|
289
|
-
|
|
290
|
-
const { balance, withdrawLimit } = context
|
|
291
|
-
const
|
|
292
|
-
const
|
|
290
|
+
recalculateDistance: assign((context, event) => {
|
|
291
|
+
const { balance, withdrawLimit, crypto } = context
|
|
292
|
+
const limit = Math.max(withdrawLimit, crypto?.minimum)
|
|
293
|
+
const distance = Math.max(limit - balance, 0)
|
|
293
294
|
return {
|
|
294
|
-
|
|
295
|
+
withdrawDistance: distance,
|
|
296
|
+
withdrawLimit: limit,
|
|
295
297
|
}
|
|
296
298
|
}),
|
|
297
299
|
},
|
|
@@ -304,15 +306,20 @@ export default function (request) {
|
|
|
304
306
|
const methods = siteConfig?.paymentMethods?.withdraw || []
|
|
305
307
|
return methods.length === 0
|
|
306
308
|
},
|
|
309
|
+
isConvertible: (context, event) => {
|
|
310
|
+
const { balance, withdrawDistance } = context
|
|
311
|
+
return balance > 0 && withdrawDistance === 0
|
|
312
|
+
},
|
|
307
313
|
isTransferable: (context, event) => {
|
|
308
|
-
const { balance, withdrawLimit, isTurnoverMode } = context
|
|
314
|
+
const { balance, withdrawLimit, withdrawDistance, isTurnoverMode } = context
|
|
309
315
|
if (balance === 0) {
|
|
310
316
|
return false
|
|
311
317
|
}
|
|
312
318
|
if (isTurnoverMode) {
|
|
319
|
+
// not used in funnycash
|
|
313
320
|
return withdrawLimit === 0
|
|
314
321
|
} else {
|
|
315
|
-
return
|
|
322
|
+
return withdrawDistance === 0
|
|
316
323
|
}
|
|
317
324
|
},
|
|
318
325
|
isCalculable: (context, event) => {
|
|
@@ -324,7 +331,7 @@ export default function (request) {
|
|
|
324
331
|
fetchWithdrawRules: async (context, event) => {
|
|
325
332
|
return await request.send(api.getCurrentWithdrawRule())
|
|
326
333
|
},
|
|
327
|
-
|
|
334
|
+
fetchPaymentConfig: async (context, event) => {
|
|
328
335
|
return await request.send(api.getPaymentDetail({ transferType: 'WITHDRAW' }))
|
|
329
336
|
},
|
|
330
337
|
submitWithdraw: async (context, event) => {
|
|
@@ -335,7 +342,7 @@ export default function (request) {
|
|
|
335
342
|
method,
|
|
336
343
|
amount: withdrawAmount,
|
|
337
344
|
cryptoCurrency: crypto.channel,
|
|
338
|
-
cryptoNetwork: currentNetwork,
|
|
345
|
+
cryptoNetwork: currentNetwork.value,
|
|
339
346
|
targetAddress: currentAddress,
|
|
340
347
|
})
|
|
341
348
|
)
|
|
@@ -345,7 +352,7 @@ export default function (request) {
|
|
|
345
352
|
return await request.send(
|
|
346
353
|
api.convertFreeCredit({
|
|
347
354
|
exchangeType: 1,
|
|
348
|
-
cryptoNetwork: currentNetwork,
|
|
355
|
+
cryptoNetwork: currentNetwork.value,
|
|
349
356
|
targetAddress: currentAddress,
|
|
350
357
|
})
|
|
351
358
|
)
|
|
@@ -357,7 +364,7 @@ export default function (request) {
|
|
|
357
364
|
api.getWithdrawExpectedResult({
|
|
358
365
|
method,
|
|
359
366
|
amount: withdrawAmount,
|
|
360
|
-
cryptoNetwork: currentNetwork,
|
|
367
|
+
cryptoNetwork: currentNetwork.value,
|
|
361
368
|
})
|
|
362
369
|
)
|
|
363
370
|
},
|