@jetthai/cuora 1.0.307-dev-2 → 1.1.1
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 -853
- package/README.md +0 -6
- package/dist/bundle.mjs +18461 -0
- package/package.json +9 -6
- package/rollup.config.js +16 -0
- package/src/api/activity.js +2 -43
- package/src/api/auth.js +7 -22
- package/src/api/common.js +1 -3
- package/src/api/game.js +7 -20
- package/src/api/mailbox.js +5 -9
- package/src/api/payment.js +19 -167
- package/src/api/user.js +0 -7
- package/src/machine/activity/activity.js +26 -111
- package/src/machine/activity/{friend_invite_friends_activity.js → affiliate_invite_friends_activity.js} +41 -70
- package/src/machine/activity/continue_deposit_activity.js +2 -11
- package/src/machine/activity/deposit_activity.js +4 -13
- package/src/machine/activity/diamond_shop_activity_vn.js +89 -54
- package/src/machine/activity/fafafa_activity.js +19 -34
- package/src/machine/activity/index.js +4 -22
- package/src/machine/activity/invite_friends_activity.js +14 -14
- package/src/machine/activity/ranking_activity.js +2 -11
- package/src/machine/activity/sign_in_activity.js +14 -21
- package/src/machine/activity/specify_bets_activity.js +3 -25
- package/src/machine/activity/specify_turnover_activity.js +3 -25
- package/src/machine/activity/time_bomb_activity.js +2 -11
- package/src/machine/auth.js +25 -141
- package/src/machine/auth_otp.js +201 -0
- package/src/machine/auth_otp_v2.js +4 -10
- package/src/machine/auth_otp_v3.js +3 -11
- package/src/machine/bank_binding.js +12 -112
- package/src/machine/common.js +30 -110
- package/src/machine/deposit/crypto.js +29 -50
- package/src/machine/deposit/crypto_button.js +39 -174
- package/src/machine/deposit/deposit_fc.js +5 -8
- package/src/machine/deposit/direct.js +16 -111
- package/src/machine/deposit/index.js +2 -43
- package/src/machine/deposit/loadcard_vn.js +43 -191
- package/src/machine/deposit/manual_vn.js +60 -182
- package/src/machine/deposit/qrcode_v2.js +52 -285
- package/src/machine/deposit/qrcode_vn.js +206 -0
- package/src/machine/game.js +285 -0
- package/src/machine/game_favorite.js +123 -0
- package/src/machine/game_favorite_v2.js +28 -74
- package/src/machine/game_search.js +244 -0
- package/src/machine/game_search_v2.js +24 -64
- package/src/machine/game_v2.js +356 -0
- package/src/machine/inbox.js +34 -259
- package/src/machine/index.js +17 -26
- package/src/machine/leaderboard.js +8 -31
- package/src/machine/reward.js +7 -74
- package/src/machine/setting.js +2 -5
- package/src/machine/side_v2.js +28 -33
- package/src/machine/user_sign_up.js +21 -112
- package/src/machine/{withdraw/withdraw_crypto.js → withdraw_crypto.js} +69 -220
- package/src/machine/{withdraw/withdraw_fc.js → withdraw_fc.js} +2 -2
- package/src/machine/{withdraw/withdraw_amb.js → withdraw_vn.js} +78 -146
- package/src/request/request.js +5 -10
- package/src/util/constant.js +1 -19
- package/src/util/deviceToken.js +8 -18
- package/src/util/index.js +1 -2
- package/src/util/storage.js +22 -22
- package/.husky/pre-commit +0 -4
- package/.prettierignore +0 -1
- package/src/lib/fingerprint.js +0 -9779
- package/src/machine/activity/activity_cash.js +0 -159
- package/src/machine/activity/cash_rain_activity.js +0 -153
- package/src/machine/activity/diamond_shop_activity_cash.js +0 -179
- package/src/machine/activity/instant_rebate_activity.js +0 -195
- package/src/machine/activity/jackpot.js +0 -74
- package/src/machine/activity/otp_verified_activity.js +0 -74
- package/src/machine/activity/roulette_activity_v2.js +0 -90
- package/src/machine/activity/sign_in_monthly_activity.js +0 -65
- package/src/machine/activity/vip_card_activity.js +0 -140
- package/src/machine/bank_binding_amb.js +0 -145
- package/src/machine/deposit/amb.js +0 -92
- package/src/machine/deposit/crypto_bank.js +0 -317
- package/src/machine/deposit/crypto_bank_cash.js +0 -287
- package/src/machine/deposit/crypto_cash.js +0 -255
- package/src/machine/deposit/crypto_qrcode.js +0 -148
- package/src/machine/deposit/crypto_qrcode_cash.js +0 -131
- package/src/machine/deposit/crypto_way.js +0 -239
- package/src/machine/deposit/crypto_way_cash.js +0 -256
- package/src/machine/deposit/direct_cash.js +0 -217
- package/src/machine/deposit/float.js +0 -366
- package/src/machine/deposit/krway.js +0 -151
- package/src/machine/deposit/loadcard_cash.js +0 -207
- package/src/machine/deposit/manual_cash.js +0 -356
- package/src/machine/deposit/qrcode_cash.js +0 -217
- package/src/machine/deposit/usdt.js +0 -144
- package/src/machine/deposit/usdt_cash.js +0 -138
- package/src/machine/deposit/vpay.js +0 -359
- package/src/machine/game_info.js +0 -57
- package/src/machine/game_search_cash.js +0 -390
- package/src/machine/game_v2_1.js +0 -662
- package/src/machine/honor_board.js +0 -118
- package/src/machine/honor_board_cash.js +0 -89
- package/src/machine/navbar.js +0 -57
- package/src/machine/promotions.js +0 -171
- package/src/machine/reward_cash.js +0 -219
- package/src/machine/roulette_v2.js +0 -276
- package/src/machine/side_cash.js +0 -110
- package/src/machine/user_photo.js +0 -65
- package/src/machine/withdraw/index.js +0 -23
- package/src/machine/withdraw/withdraw_crypto2.js +0 -540
- package/src/machine/withdraw/withdraw_crypto_cash.js +0 -319
- package/src/machine/withdraw/withdraw_krway.js +0 -220
- package/src/machine/withdraw/withdraw_manual.js +0 -610
- package/src/machine/withdraw/withdraw_manual_cash.js +0 -303
- package/src/machine/withdraw/withdraw_vn.js +0 -546
- package/src/machine/withdraw/withdraw_vn2.js +0 -561
- package/src/util/math.js +0 -4
|
@@ -1,239 +0,0 @@
|
|
|
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
|
-
cryptos: [],
|
|
16
|
-
sourceAddress: '',
|
|
17
|
-
|
|
18
|
-
amount: null,
|
|
19
|
-
selectedCrypto: null,
|
|
20
|
-
|
|
21
|
-
currentCategory: 'cryptoWay',
|
|
22
|
-
currentPayment: null,
|
|
23
|
-
|
|
24
|
-
calculation: null,
|
|
25
|
-
result: null,
|
|
26
|
-
|
|
27
|
-
// use for wallet mode 4
|
|
28
|
-
promotion: null,
|
|
29
|
-
},
|
|
30
|
-
states: {
|
|
31
|
-
loading: {
|
|
32
|
-
invoke: {
|
|
33
|
-
src: 'fetchPayments',
|
|
34
|
-
onDone: {
|
|
35
|
-
target: 'loaded',
|
|
36
|
-
actions: 'setPayment',
|
|
37
|
-
},
|
|
38
|
-
onError: {
|
|
39
|
-
target: '#crypto_way.fail',
|
|
40
|
-
},
|
|
41
|
-
},
|
|
42
|
-
},
|
|
43
|
-
loaded: {
|
|
44
|
-
always: [{ target: 'debouncing', cond: 'isCalculable' }],
|
|
45
|
-
},
|
|
46
|
-
debouncing: {
|
|
47
|
-
after: {
|
|
48
|
-
1000: {
|
|
49
|
-
target: 'calculating',
|
|
50
|
-
},
|
|
51
|
-
},
|
|
52
|
-
},
|
|
53
|
-
calculating: {
|
|
54
|
-
invoke: {
|
|
55
|
-
src: 'fetchCalculation',
|
|
56
|
-
onDone: {
|
|
57
|
-
target: 'calculated',
|
|
58
|
-
actions: 'setCalculation',
|
|
59
|
-
},
|
|
60
|
-
onError: {
|
|
61
|
-
target: 'loaded',
|
|
62
|
-
},
|
|
63
|
-
},
|
|
64
|
-
},
|
|
65
|
-
calculated: {
|
|
66
|
-
on: {
|
|
67
|
-
SUBMIT: [
|
|
68
|
-
{
|
|
69
|
-
target: 'pending',
|
|
70
|
-
},
|
|
71
|
-
{
|
|
72
|
-
target: 'submitting',
|
|
73
|
-
cond: 'isSubmittable',
|
|
74
|
-
},
|
|
75
|
-
],
|
|
76
|
-
},
|
|
77
|
-
},
|
|
78
|
-
pending: {
|
|
79
|
-
on: {
|
|
80
|
-
SUBMIT: {
|
|
81
|
-
target: 'submitting',
|
|
82
|
-
cond: 'isSubmittable',
|
|
83
|
-
},
|
|
84
|
-
},
|
|
85
|
-
},
|
|
86
|
-
submitting: {
|
|
87
|
-
invoke: {
|
|
88
|
-
src: 'submitDeposit',
|
|
89
|
-
onDone: {
|
|
90
|
-
target: 'submitted',
|
|
91
|
-
actions: 'setResult',
|
|
92
|
-
},
|
|
93
|
-
onError: {
|
|
94
|
-
target: 'loaded',
|
|
95
|
-
},
|
|
96
|
-
},
|
|
97
|
-
},
|
|
98
|
-
submitted: {},
|
|
99
|
-
fail: {},
|
|
100
|
-
},
|
|
101
|
-
on: {
|
|
102
|
-
SET_CRYPTO: {
|
|
103
|
-
target: '.loaded',
|
|
104
|
-
actions: 'setCrypto',
|
|
105
|
-
},
|
|
106
|
-
SET_ADDRESS: {
|
|
107
|
-
actions: 'setAddress',
|
|
108
|
-
},
|
|
109
|
-
SET_AMOUNT: {
|
|
110
|
-
target: '.loaded',
|
|
111
|
-
actions: ['setAmount', 'clearCalculation'],
|
|
112
|
-
},
|
|
113
|
-
INPUT_AMOUNT: {
|
|
114
|
-
target: '.loaded',
|
|
115
|
-
actions: ['inputAmount', 'clearCalculation'],
|
|
116
|
-
},
|
|
117
|
-
CALCULATE: {
|
|
118
|
-
target: '.debouncing',
|
|
119
|
-
actions: 'clearCalculation',
|
|
120
|
-
},
|
|
121
|
-
SET_PROMOTION: {
|
|
122
|
-
actions: 'setPromotion',
|
|
123
|
-
},
|
|
124
|
-
},
|
|
125
|
-
},
|
|
126
|
-
{
|
|
127
|
-
actions: {
|
|
128
|
-
setPayment: assign((context, event) => {
|
|
129
|
-
const payments = event.data.filter((item) => item.category === context.currentCategory)
|
|
130
|
-
const cryptos = payments?.map((value, i) => {
|
|
131
|
-
return {
|
|
132
|
-
...value,
|
|
133
|
-
label: value?.cryptoOptional[0],
|
|
134
|
-
network: value?.networkName[0],
|
|
135
|
-
icon: value?.channel,
|
|
136
|
-
}
|
|
137
|
-
})
|
|
138
|
-
return {
|
|
139
|
-
cryptos,
|
|
140
|
-
selectedCrypto: cryptos[0],
|
|
141
|
-
currentPayment: cryptos[0],
|
|
142
|
-
}
|
|
143
|
-
}),
|
|
144
|
-
setCrypto: assign((context, event) => {
|
|
145
|
-
const { cryptos } = context
|
|
146
|
-
const selectedCrypto = cryptos.find((crypto) => crypto.label === event.data.label)
|
|
147
|
-
return {
|
|
148
|
-
selectedCrypto: selectedCrypto,
|
|
149
|
-
amount: null,
|
|
150
|
-
calculation: null,
|
|
151
|
-
}
|
|
152
|
-
}),
|
|
153
|
-
setAmount: assign((context, event) => {
|
|
154
|
-
return {
|
|
155
|
-
amount: event.data,
|
|
156
|
-
}
|
|
157
|
-
}),
|
|
158
|
-
inputAmount: assign((context, event) => {
|
|
159
|
-
return { amount: preciseAdd(`${parseFloat(context.amount || 0)}`, `${parseFloat(event.data)}`) }
|
|
160
|
-
}),
|
|
161
|
-
setAddress: assign((context, event) => {
|
|
162
|
-
return {
|
|
163
|
-
sourceAddress: event.data,
|
|
164
|
-
}
|
|
165
|
-
}),
|
|
166
|
-
setCalculation: assign((context, event) => {
|
|
167
|
-
return {
|
|
168
|
-
calculation: event.data,
|
|
169
|
-
}
|
|
170
|
-
}),
|
|
171
|
-
clearCalculation: assign((context, event) => {
|
|
172
|
-
return {
|
|
173
|
-
calculation: null,
|
|
174
|
-
}
|
|
175
|
-
}),
|
|
176
|
-
setResult: assign((context, event) => {
|
|
177
|
-
return {
|
|
178
|
-
result: event.data,
|
|
179
|
-
}
|
|
180
|
-
}),
|
|
181
|
-
setPromotion: assign((context, event) => {
|
|
182
|
-
const promotion = event.data
|
|
183
|
-
return {
|
|
184
|
-
promotion,
|
|
185
|
-
}
|
|
186
|
-
}),
|
|
187
|
-
},
|
|
188
|
-
guards: {
|
|
189
|
-
isCalculable: (context, event) => {
|
|
190
|
-
const { selectedCrypto, amount } = context
|
|
191
|
-
return selectedCrypto && amount && selectedCrypto?.minimum <= +amount && +amount <= selectedCrypto?.maximum
|
|
192
|
-
},
|
|
193
|
-
isSubmittable: (context, event) => {
|
|
194
|
-
const { selectedCrypto, amount } = context
|
|
195
|
-
return selectedCrypto && amount
|
|
196
|
-
},
|
|
197
|
-
},
|
|
198
|
-
services: {
|
|
199
|
-
fetchPayments: async (context, event) => {
|
|
200
|
-
return await request.send(payment.getPaymentDetail({ transferType: 'DEPOSIT' }))
|
|
201
|
-
},
|
|
202
|
-
fetchCalculation: async (context, event) => {
|
|
203
|
-
const { selectedCrypto, amount, promotion } = context
|
|
204
|
-
return await request.send(
|
|
205
|
-
payment.getCryptoDepositExpectedResult({
|
|
206
|
-
method: selectedCrypto.method,
|
|
207
|
-
amount,
|
|
208
|
-
cryptoCurrency: selectedCrypto.channel,
|
|
209
|
-
promotionsNo: promotion?.activityNo,
|
|
210
|
-
})
|
|
211
|
-
)
|
|
212
|
-
},
|
|
213
|
-
submitDeposit: async (context, event) => {
|
|
214
|
-
const { selectedCrypto, amount } = context
|
|
215
|
-
return await request.send(
|
|
216
|
-
payment.submitDepositTransactionCrypto({
|
|
217
|
-
method: selectedCrypto.method,
|
|
218
|
-
amount: amount,
|
|
219
|
-
cryptoCurrency: selectedCrypto.channel,
|
|
220
|
-
cryptoNetwork: selectedCrypto.network,
|
|
221
|
-
})
|
|
222
|
-
)
|
|
223
|
-
},
|
|
224
|
-
},
|
|
225
|
-
}
|
|
226
|
-
)
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
function preciseAdd(a, b) {
|
|
230
|
-
let aStr = a.toString()
|
|
231
|
-
let bStr = b.toString()
|
|
232
|
-
|
|
233
|
-
let aDecimalPlaces = aStr.split('.')[1] ? aStr.split('.')[1].length : 0
|
|
234
|
-
let bDecimalPlaces = bStr.split('.')[1] ? bStr.split('.')[1].length : 0
|
|
235
|
-
|
|
236
|
-
let factor = Math.pow(10, Math.max(aDecimalPlaces, bDecimalPlaces))
|
|
237
|
-
|
|
238
|
-
return (Math.round(a * factor) + Math.round(b * factor)) / factor
|
|
239
|
-
}
|
|
@@ -1,256 +0,0 @@
|
|
|
1
|
-
import { assign, createMachine } from 'xstate'
|
|
2
|
-
import payment from '@jetthai/cuora/src/api/payment.js'
|
|
3
|
-
import { max } from '../../util/index.js'
|
|
4
|
-
|
|
5
|
-
export default function (request, context) {
|
|
6
|
-
const { paymentDetail = [], promotion, selectedAmount } = context || {}
|
|
7
|
-
return createMachine(
|
|
8
|
-
{
|
|
9
|
-
id: 'crypto_way_cash',
|
|
10
|
-
initial: 'loading',
|
|
11
|
-
context: {
|
|
12
|
-
paymentDetail,
|
|
13
|
-
promotion,
|
|
14
|
-
selectedAmount,
|
|
15
|
-
|
|
16
|
-
cryptos: [],
|
|
17
|
-
sourceAddress: '',
|
|
18
|
-
options: [],
|
|
19
|
-
|
|
20
|
-
selectedCrypto: null,
|
|
21
|
-
|
|
22
|
-
currentCategory: 'cryptoWay',
|
|
23
|
-
|
|
24
|
-
calculation: null,
|
|
25
|
-
result: null,
|
|
26
|
-
ttl: 0,
|
|
27
|
-
},
|
|
28
|
-
states: {
|
|
29
|
-
loading: {
|
|
30
|
-
always: [
|
|
31
|
-
{
|
|
32
|
-
target: 'debouncing',
|
|
33
|
-
actions: 'setInitData',
|
|
34
|
-
},
|
|
35
|
-
],
|
|
36
|
-
},
|
|
37
|
-
loaded: {},
|
|
38
|
-
debouncing: {
|
|
39
|
-
entry: 'clearCalculation',
|
|
40
|
-
after: {
|
|
41
|
-
1000: [
|
|
42
|
-
{
|
|
43
|
-
target: 'calculating',
|
|
44
|
-
cond: 'isCalculable',
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
target: 'loaded',
|
|
48
|
-
},
|
|
49
|
-
],
|
|
50
|
-
},
|
|
51
|
-
},
|
|
52
|
-
calculating: {
|
|
53
|
-
invoke: {
|
|
54
|
-
src: 'fetchCalculation',
|
|
55
|
-
onDone: {
|
|
56
|
-
target: 'calculated',
|
|
57
|
-
actions: 'setCalculation',
|
|
58
|
-
},
|
|
59
|
-
onError: {
|
|
60
|
-
target: 'calculated',
|
|
61
|
-
},
|
|
62
|
-
},
|
|
63
|
-
},
|
|
64
|
-
calculated: {
|
|
65
|
-
on: {
|
|
66
|
-
SUBMIT: [
|
|
67
|
-
{
|
|
68
|
-
target: 'submitting',
|
|
69
|
-
cond: 'isSubmittable',
|
|
70
|
-
},
|
|
71
|
-
],
|
|
72
|
-
},
|
|
73
|
-
},
|
|
74
|
-
submitting: {
|
|
75
|
-
invoke: {
|
|
76
|
-
src: 'submitDeposit',
|
|
77
|
-
onDone: {
|
|
78
|
-
target: 'submitted',
|
|
79
|
-
actions: ['setResult', 'setTtl'],
|
|
80
|
-
},
|
|
81
|
-
onError: {
|
|
82
|
-
target: 'calculated',
|
|
83
|
-
},
|
|
84
|
-
},
|
|
85
|
-
},
|
|
86
|
-
submitted: {
|
|
87
|
-
after: {
|
|
88
|
-
1000: {
|
|
89
|
-
target: 'submitted',
|
|
90
|
-
actions: 'decreaseTtl',
|
|
91
|
-
cond: (context) => context.ttl > 0,
|
|
92
|
-
},
|
|
93
|
-
},
|
|
94
|
-
},
|
|
95
|
-
},
|
|
96
|
-
on: {
|
|
97
|
-
SET_PROMOTION: {
|
|
98
|
-
target: '.debouncing',
|
|
99
|
-
actions: 'setPromotion',
|
|
100
|
-
internal: false,
|
|
101
|
-
},
|
|
102
|
-
SET_CRYPTO: {
|
|
103
|
-
target: '.debouncing',
|
|
104
|
-
actions: 'setCrypto',
|
|
105
|
-
internal: false,
|
|
106
|
-
},
|
|
107
|
-
SET_ADDRESS: {
|
|
108
|
-
actions: 'setAddress',
|
|
109
|
-
internal: false,
|
|
110
|
-
},
|
|
111
|
-
SET_AMOUNT: {
|
|
112
|
-
target: '.debouncing',
|
|
113
|
-
actions: 'setAmount',
|
|
114
|
-
internal: false,
|
|
115
|
-
},
|
|
116
|
-
INPUT_AMOUNT: {
|
|
117
|
-
target: '.debouncing',
|
|
118
|
-
actions: 'inputAmount',
|
|
119
|
-
internal: false,
|
|
120
|
-
},
|
|
121
|
-
},
|
|
122
|
-
},
|
|
123
|
-
{
|
|
124
|
-
actions: {
|
|
125
|
-
setInitData: assign((context, event) => {
|
|
126
|
-
const { paymentDetail } = context
|
|
127
|
-
const payments = paymentDetail.filter((item) => item.category === context.currentCategory)
|
|
128
|
-
const cryptos = payments.map((payment) => ({
|
|
129
|
-
...payment,
|
|
130
|
-
label: payment.cryptoOptional?.[0],
|
|
131
|
-
network: payment.networkName?.[0],
|
|
132
|
-
value: payment.method,
|
|
133
|
-
icon: payment.channel,
|
|
134
|
-
}))
|
|
135
|
-
|
|
136
|
-
return {
|
|
137
|
-
cryptos,
|
|
138
|
-
selectedCrypto: cryptos[0],
|
|
139
|
-
options: cryptos[0].optional,
|
|
140
|
-
}
|
|
141
|
-
}),
|
|
142
|
-
setCrypto: assign((context, event) => {
|
|
143
|
-
const { cryptos } = context
|
|
144
|
-
const selectedCrypto = cryptos.find((crypto) => crypto.label === event.data.label)
|
|
145
|
-
return {
|
|
146
|
-
selectedCrypto: selectedCrypto,
|
|
147
|
-
selectedAmount: null,
|
|
148
|
-
calculation: null,
|
|
149
|
-
options: selectedCrypto.optional,
|
|
150
|
-
}
|
|
151
|
-
}),
|
|
152
|
-
setAmount: assign((context, event) => {
|
|
153
|
-
// 現金網可自由填額度,grandTotalEnable 欄位感覺不再需要?
|
|
154
|
-
if (context.selectedCrypto?.grandTotalEnable === 1) {
|
|
155
|
-
return {
|
|
156
|
-
selectedAmount: preciseAdd(`${parseFloat(context.selectedAmount || 0)}`, `${parseFloat(event.data)}`),
|
|
157
|
-
}
|
|
158
|
-
} else {
|
|
159
|
-
return { selectedAmount: event.data }
|
|
160
|
-
}
|
|
161
|
-
}),
|
|
162
|
-
inputAmount: assign((context, event) => {
|
|
163
|
-
return { selectedAmount: event.data }
|
|
164
|
-
}),
|
|
165
|
-
setAddress: assign((context, event) => {
|
|
166
|
-
return {
|
|
167
|
-
sourceAddress: event.data,
|
|
168
|
-
}
|
|
169
|
-
}),
|
|
170
|
-
setCalculation: assign((context, event) => {
|
|
171
|
-
return {
|
|
172
|
-
calculation: event.data,
|
|
173
|
-
}
|
|
174
|
-
}),
|
|
175
|
-
clearCalculation: assign((context, event) => {
|
|
176
|
-
return {
|
|
177
|
-
calculation: null,
|
|
178
|
-
}
|
|
179
|
-
}),
|
|
180
|
-
setResult: assign((context, event) => {
|
|
181
|
-
return {
|
|
182
|
-
result: event.data,
|
|
183
|
-
}
|
|
184
|
-
}),
|
|
185
|
-
setPromotion: assign((context, event) => {
|
|
186
|
-
const { selectedCrypto, selectedAmount } = context
|
|
187
|
-
const promotion = event.data
|
|
188
|
-
return {
|
|
189
|
-
promotion,
|
|
190
|
-
selectedAmount: max(promotion.minimumAmount, selectedCrypto.minimum, selectedAmount, 0),
|
|
191
|
-
calculation: null,
|
|
192
|
-
}
|
|
193
|
-
}),
|
|
194
|
-
setTtl: assign((context, event) => {
|
|
195
|
-
const { cdtime } = event.data
|
|
196
|
-
return {
|
|
197
|
-
ttl: cdtime,
|
|
198
|
-
}
|
|
199
|
-
}),
|
|
200
|
-
decreaseTtl: assign((context, evnet) => {
|
|
201
|
-
return {
|
|
202
|
-
ttl: Math.max(context.ttl - 1000, 0),
|
|
203
|
-
}
|
|
204
|
-
}),
|
|
205
|
-
},
|
|
206
|
-
guards: {
|
|
207
|
-
isCalculable: (context, event) => {
|
|
208
|
-
const { selectedCrypto, selectedAmount } = context
|
|
209
|
-
return selectedCrypto && selectedAmount && selectedCrypto.minimum <= +selectedAmount && +selectedAmount <= selectedCrypto.maximum
|
|
210
|
-
},
|
|
211
|
-
isSubmittable: (context, event) => {
|
|
212
|
-
const { selectedCrypto, selectedAmount, calculation } = context
|
|
213
|
-
return selectedCrypto && selectedAmount && calculation
|
|
214
|
-
},
|
|
215
|
-
},
|
|
216
|
-
services: {
|
|
217
|
-
fetchCalculation: async (context, event) => {
|
|
218
|
-
const { selectedCrypto, selectedAmount, promotion } = context
|
|
219
|
-
return await request.send(
|
|
220
|
-
payment.getCryptoDepositExpectedResult({
|
|
221
|
-
method: selectedCrypto.method,
|
|
222
|
-
amount: selectedAmount,
|
|
223
|
-
cryptoCurrency: selectedCrypto.channel,
|
|
224
|
-
promotionsNo: promotion?.promotionsNo,
|
|
225
|
-
})
|
|
226
|
-
)
|
|
227
|
-
},
|
|
228
|
-
submitDeposit: async (context, event) => {
|
|
229
|
-
const { selectedCrypto, selectedAmount, sourceAddress, promotion } = context
|
|
230
|
-
return await request.send(
|
|
231
|
-
payment.submitDepositTransactionCrypto({
|
|
232
|
-
method: selectedCrypto.method,
|
|
233
|
-
amount: selectedAmount,
|
|
234
|
-
cryptoCurrency: selectedCrypto.channel,
|
|
235
|
-
cryptoNetwork: selectedCrypto.network,
|
|
236
|
-
sourceAddress: sourceAddress,
|
|
237
|
-
promotionsNo: promotion?.promotionsNo,
|
|
238
|
-
})
|
|
239
|
-
)
|
|
240
|
-
},
|
|
241
|
-
},
|
|
242
|
-
}
|
|
243
|
-
)
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
function preciseAdd(a, b) {
|
|
247
|
-
let aStr = a.toString()
|
|
248
|
-
let bStr = b.toString()
|
|
249
|
-
|
|
250
|
-
let aDecimalPlaces = aStr.split('.')[1] ? aStr.split('.')[1].length : 0
|
|
251
|
-
let bDecimalPlaces = bStr.split('.')[1] ? bStr.split('.')[1].length : 0
|
|
252
|
-
|
|
253
|
-
let factor = Math.pow(10, Math.max(aDecimalPlaces, bDecimalPlaces))
|
|
254
|
-
|
|
255
|
-
return (Math.round(a * factor) + Math.round(b * factor)) / factor
|
|
256
|
-
}
|
|
@@ -1,217 +0,0 @@
|
|
|
1
|
-
import { assign, createMachine } from 'xstate'
|
|
2
|
-
import payment from '../../api/payment.js'
|
|
3
|
-
import { max } from '../../util/index.js'
|
|
4
|
-
|
|
5
|
-
export default function (request, context) {
|
|
6
|
-
const { paymentDetail = [], promotion, selectedAmount } = context || {}
|
|
7
|
-
|
|
8
|
-
return createMachine(
|
|
9
|
-
{
|
|
10
|
-
id: 'direct_cash',
|
|
11
|
-
initial: 'loading',
|
|
12
|
-
context: {
|
|
13
|
-
paymentDetail,
|
|
14
|
-
promotion,
|
|
15
|
-
selectedAmount,
|
|
16
|
-
|
|
17
|
-
directs: [],
|
|
18
|
-
selectedDirect: null,
|
|
19
|
-
bankMap: {},
|
|
20
|
-
userBanks: [],
|
|
21
|
-
selectedUserBank: null,
|
|
22
|
-
calculation: null,
|
|
23
|
-
currentCategory: 'direct',
|
|
24
|
-
result: null,
|
|
25
|
-
},
|
|
26
|
-
states: {
|
|
27
|
-
loading: {
|
|
28
|
-
always: [
|
|
29
|
-
{
|
|
30
|
-
target: 'checking',
|
|
31
|
-
actions: 'setInitData',
|
|
32
|
-
},
|
|
33
|
-
],
|
|
34
|
-
},
|
|
35
|
-
checking: {
|
|
36
|
-
invoke: {
|
|
37
|
-
src: 'fetchBanksList',
|
|
38
|
-
onDone: {
|
|
39
|
-
target: 'debouncing',
|
|
40
|
-
actions: 'setBanks',
|
|
41
|
-
},
|
|
42
|
-
},
|
|
43
|
-
},
|
|
44
|
-
loaded: {},
|
|
45
|
-
debouncing: {
|
|
46
|
-
entry: 'clearCalculation',
|
|
47
|
-
after: {
|
|
48
|
-
1000: [{ target: 'calculating', cond: 'isCalculable' }, { target: 'loaded' }],
|
|
49
|
-
},
|
|
50
|
-
},
|
|
51
|
-
calculating: {
|
|
52
|
-
invoke: {
|
|
53
|
-
src: 'fetchCalculation',
|
|
54
|
-
onDone: {
|
|
55
|
-
target: 'calculated',
|
|
56
|
-
actions: 'setCalculation',
|
|
57
|
-
},
|
|
58
|
-
onError: {
|
|
59
|
-
target: 'loaded',
|
|
60
|
-
},
|
|
61
|
-
},
|
|
62
|
-
},
|
|
63
|
-
calculated: {
|
|
64
|
-
on: {
|
|
65
|
-
SUBMIT: {
|
|
66
|
-
target: 'submitting',
|
|
67
|
-
cond: 'isSubmittable',
|
|
68
|
-
},
|
|
69
|
-
},
|
|
70
|
-
},
|
|
71
|
-
submitting: {
|
|
72
|
-
invoke: {
|
|
73
|
-
src: 'submitDeposit',
|
|
74
|
-
onDone: {
|
|
75
|
-
target: 'submitted',
|
|
76
|
-
actions: 'setResult',
|
|
77
|
-
},
|
|
78
|
-
onError: {
|
|
79
|
-
target: 'loaded',
|
|
80
|
-
},
|
|
81
|
-
},
|
|
82
|
-
},
|
|
83
|
-
submitted: {},
|
|
84
|
-
fail: {},
|
|
85
|
-
},
|
|
86
|
-
on: {
|
|
87
|
-
SET_PROMOTION: {
|
|
88
|
-
target: '.loading',
|
|
89
|
-
actions: 'setPromotion',
|
|
90
|
-
internal: false,
|
|
91
|
-
},
|
|
92
|
-
SELECT_DIRECT: {
|
|
93
|
-
target: '.loading',
|
|
94
|
-
actions: 'setDirect',
|
|
95
|
-
internal: false,
|
|
96
|
-
},
|
|
97
|
-
SELECT_USER_BANK: {
|
|
98
|
-
actions: 'setUserBank',
|
|
99
|
-
internal: false,
|
|
100
|
-
},
|
|
101
|
-
SET_AMOUNT: {
|
|
102
|
-
target: '.debouncing',
|
|
103
|
-
actions: 'setAmount',
|
|
104
|
-
internal: false,
|
|
105
|
-
},
|
|
106
|
-
},
|
|
107
|
-
},
|
|
108
|
-
{
|
|
109
|
-
actions: {
|
|
110
|
-
setInitData: assign((context, event) => {
|
|
111
|
-
const { paymentDetail, selectedAmount, promotion } = context
|
|
112
|
-
const directs = paymentDetail.filter((element) => element.category === context.currentCategory && element.transferType === 'deposit')
|
|
113
|
-
const selectedDirect = context.selectedDirect || directs[0]
|
|
114
|
-
return {
|
|
115
|
-
directs,
|
|
116
|
-
selectedDirect,
|
|
117
|
-
selectedAmount: max(promotion?.minimumAmount, selectedDirect?.minimum, selectedAmount, 0),
|
|
118
|
-
}
|
|
119
|
-
}),
|
|
120
|
-
setBanks: assign((context, event) => {
|
|
121
|
-
const { selectedDirect, bankMap } = context
|
|
122
|
-
const userBanks = event.data
|
|
123
|
-
|
|
124
|
-
if (selectedDirect)
|
|
125
|
-
return {
|
|
126
|
-
bankMap: { ...bankMap, [selectedDirect.method]: userBanks },
|
|
127
|
-
userBanks,
|
|
128
|
-
selectedUserBank: userBanks[0],
|
|
129
|
-
}
|
|
130
|
-
}),
|
|
131
|
-
setDirect: assign((context, event) => {
|
|
132
|
-
return {
|
|
133
|
-
selectedDirect: event.data,
|
|
134
|
-
}
|
|
135
|
-
}),
|
|
136
|
-
setUserBank: assign((context, event) => {
|
|
137
|
-
return {
|
|
138
|
-
selectedUserBank: event.data,
|
|
139
|
-
}
|
|
140
|
-
}),
|
|
141
|
-
setAmount: assign((context, event) => {
|
|
142
|
-
return {
|
|
143
|
-
selectedAmount: event.data,
|
|
144
|
-
}
|
|
145
|
-
}),
|
|
146
|
-
setCalculation: assign((context, event) => {
|
|
147
|
-
return {
|
|
148
|
-
calculation: event.data,
|
|
149
|
-
}
|
|
150
|
-
}),
|
|
151
|
-
clearCalculation: assign((context, event) => {
|
|
152
|
-
return {
|
|
153
|
-
calculation: null,
|
|
154
|
-
}
|
|
155
|
-
}),
|
|
156
|
-
setResult: assign((context, event) => {
|
|
157
|
-
return {
|
|
158
|
-
result: event.data,
|
|
159
|
-
}
|
|
160
|
-
}),
|
|
161
|
-
setPromotion: assign((context, event) => {
|
|
162
|
-
return {
|
|
163
|
-
promotion: event.data,
|
|
164
|
-
}
|
|
165
|
-
}),
|
|
166
|
-
},
|
|
167
|
-
guards: {
|
|
168
|
-
isCalculable: (context, event) => {
|
|
169
|
-
const {
|
|
170
|
-
selectedAmount,
|
|
171
|
-
selectedDirect: { maximum, minimum },
|
|
172
|
-
} = context
|
|
173
|
-
return selectedAmount && minimum <= +selectedAmount && +selectedAmount <= maximum
|
|
174
|
-
},
|
|
175
|
-
isSubmittable: (context, event) => {
|
|
176
|
-
const { selectedAmount, selectedDirect, selectedUserBank } = context
|
|
177
|
-
return selectedAmount && selectedDirect && selectedUserBank
|
|
178
|
-
},
|
|
179
|
-
},
|
|
180
|
-
services: {
|
|
181
|
-
fetchBanksList: async (context, event) => {
|
|
182
|
-
const { selectedDirect, bankMap } = context
|
|
183
|
-
const method = selectedDirect?.method
|
|
184
|
-
|
|
185
|
-
if (!selectedDirect) {
|
|
186
|
-
return []
|
|
187
|
-
} else if (bankMap[method]) {
|
|
188
|
-
return bankMap[method]
|
|
189
|
-
} else {
|
|
190
|
-
return await request.send(payment.getBankList(method))
|
|
191
|
-
}
|
|
192
|
-
},
|
|
193
|
-
fetchCalculation: async (context, event) => {
|
|
194
|
-
const { selectedDirect, selectedAmount, promotion } = context
|
|
195
|
-
return await request.send(
|
|
196
|
-
payment.getDepositExpectedResult({
|
|
197
|
-
method: selectedDirect.method,
|
|
198
|
-
amount: selectedAmount,
|
|
199
|
-
promotionsNo: promotion?.promotionsNo,
|
|
200
|
-
})
|
|
201
|
-
)
|
|
202
|
-
},
|
|
203
|
-
submitDeposit: async (context, event) => {
|
|
204
|
-
const { selectedDirect, selectedAmount, selectedUserBank, promotion } = context
|
|
205
|
-
return await request.send(
|
|
206
|
-
payment.submitDepositTransactionBank({
|
|
207
|
-
method: selectedDirect.method,
|
|
208
|
-
amount: selectedAmount,
|
|
209
|
-
applyerBankCode: selectedUserBank.bankCode,
|
|
210
|
-
promotionsNo: promotion?.promotionsNo,
|
|
211
|
-
})
|
|
212
|
-
)
|
|
213
|
-
},
|
|
214
|
-
},
|
|
215
|
-
}
|
|
216
|
-
)
|
|
217
|
-
}
|