@jetthai/cuora 1.0.204 → 1.0.302-dev-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/.husky/pre-commit +4 -0
- package/.prettierignore +1 -0
- package/CHANGELOG.md +848 -0
- package/README.md +6 -0
- package/package.json +6 -9
- package/src/api/activity.js +43 -2
- package/src/api/auth.js +22 -7
- package/src/api/common.js +3 -1
- package/src/api/game.js +20 -7
- package/src/api/mailbox.js +9 -5
- package/src/api/payment.js +167 -19
- package/src/api/user.js +7 -0
- package/src/lib/fingerprint.js +9779 -0
- package/src/machine/activity/activity.js +111 -26
- package/src/machine/activity/activity_cash.js +159 -0
- package/src/machine/activity/cash_rain_activity.js +153 -0
- package/src/machine/activity/continue_deposit_activity.js +11 -2
- package/src/machine/activity/deposit_activity.js +13 -4
- package/src/machine/activity/diamond_shop_activity_cash.js +179 -0
- package/src/machine/activity/diamond_shop_activity_vn.js +54 -89
- package/src/machine/activity/fafafa_activity.js +34 -19
- package/src/machine/activity/{affiliate_invite_friends_activity.js → friend_invite_friends_activity.js} +72 -45
- package/src/machine/activity/index.js +22 -4
- package/src/machine/activity/instant_rebate_activity.js +217 -0
- package/src/machine/activity/invite_friends_activity.js +14 -14
- package/src/machine/activity/jackpot.js +74 -0
- package/src/machine/activity/otp_verified_activity.js +74 -0
- package/src/machine/activity/ranking_activity.js +11 -2
- package/src/machine/activity/roulette_activity_v2.js +90 -0
- package/src/machine/activity/sign_in_activity.js +21 -14
- package/src/machine/activity/sign_in_monthly_activity.js +65 -0
- package/src/machine/activity/specify_bets_activity.js +25 -3
- package/src/machine/activity/specify_turnover_activity.js +25 -3
- package/src/machine/activity/time_bomb_activity.js +11 -2
- package/src/machine/activity/vip_card_activity.js +140 -0
- package/src/machine/auth.js +141 -27
- package/src/machine/auth_otp_v2.js +10 -4
- package/src/machine/auth_otp_v3.js +11 -3
- package/src/machine/bank_binding.js +112 -12
- package/src/machine/bank_binding_amb.js +145 -0
- package/src/machine/common.js +113 -25
- package/src/machine/deposit/amb.js +92 -0
- package/src/machine/deposit/crypto.js +50 -29
- package/src/machine/deposit/crypto_bank.js +317 -0
- package/src/machine/deposit/crypto_bank_cash.js +287 -0
- package/src/machine/deposit/crypto_button.js +174 -39
- package/src/machine/deposit/crypto_cash.js +255 -0
- package/src/machine/deposit/crypto_qrcode.js +148 -0
- package/src/machine/deposit/crypto_qrcode_cash.js +131 -0
- package/src/machine/deposit/crypto_way.js +239 -0
- package/src/machine/deposit/crypto_way_cash.js +256 -0
- package/src/machine/deposit/deposit_fc.js +8 -5
- package/src/machine/deposit/direct.js +111 -16
- package/src/machine/deposit/direct_cash.js +217 -0
- package/src/machine/deposit/float.js +366 -0
- package/src/machine/deposit/index.js +43 -2
- package/src/machine/deposit/krway.js +151 -0
- package/src/machine/deposit/loadcard_cash.js +207 -0
- package/src/machine/deposit/loadcard_vn.js +191 -43
- package/src/machine/deposit/manual_cash.js +356 -0
- package/src/machine/deposit/manual_vn.js +182 -60
- package/src/machine/deposit/qrcode_cash.js +217 -0
- package/src/machine/deposit/qrcode_v2.js +285 -52
- package/src/machine/deposit/usdt.js +144 -0
- package/src/machine/deposit/usdt_cash.js +138 -0
- package/src/machine/deposit/vpay.js +359 -0
- package/src/machine/game_favorite_v2.js +70 -28
- package/src/machine/game_info.js +57 -0
- package/src/machine/game_search_cash.js +390 -0
- package/src/machine/game_search_v2.js +64 -24
- package/src/machine/game_v2_1.js +662 -0
- package/src/machine/honor_board_cash.js +63 -0
- package/src/machine/inbox.js +259 -34
- package/src/machine/index.js +24 -17
- package/src/machine/leaderboard.js +31 -8
- package/src/machine/navbar.js +57 -0
- package/src/machine/promotions.js +171 -0
- package/src/machine/reward.js +74 -7
- package/src/machine/reward_cash.js +219 -0
- package/src/machine/roulette_v2.js +276 -0
- package/src/machine/setting.js +5 -2
- package/src/machine/side_cash.js +110 -0
- package/src/machine/side_v2.js +33 -28
- package/src/machine/user_photo.js +65 -0
- package/src/machine/user_sign_up.js +117 -17
- package/src/machine/withdraw/index.js +23 -0
- package/src/machine/{withdraw_vn.js → withdraw/withdraw_amb.js} +146 -78
- package/src/machine/{withdraw_crypto.js → withdraw/withdraw_crypto.js} +220 -69
- package/src/machine/withdraw/withdraw_crypto2.js +540 -0
- package/src/machine/withdraw/withdraw_crypto_cash.js +319 -0
- package/src/machine/{withdraw_fc.js → withdraw/withdraw_fc.js} +2 -2
- package/src/machine/withdraw/withdraw_krway.js +207 -0
- package/src/machine/withdraw/withdraw_manual.js +595 -0
- package/src/machine/withdraw/withdraw_manual_cash.js +303 -0
- package/src/machine/withdraw/withdraw_vn.js +533 -0
- package/src/machine/withdraw/withdraw_vn2.js +548 -0
- package/src/request/request.js +10 -5
- package/src/util/constant.js +19 -1
- package/src/util/deviceToken.js +18 -8
- package/src/util/index.js +2 -1
- package/src/util/math.js +4 -0
- package/src/util/storage.js +22 -22
- package/dist/bundle.mjs +0 -18462
- package/rollup.config.js +0 -16
- package/src/machine/auth_otp.js +0 -201
- package/src/machine/deposit/qrcode_vn.js +0 -206
- package/src/machine/game.js +0 -285
- package/src/machine/game_favorite.js +0 -123
- package/src/machine/game_search.js +0 -244
- package/src/machine/game_v2.js +0 -356
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import { assign, createMachine } from 'xstate'
|
|
2
2
|
import padStart from 'lodash/padStart.js'
|
|
3
3
|
import payment from '../../api/payment.js'
|
|
4
|
+
import common from '../../api/common.js'
|
|
4
5
|
|
|
5
6
|
export default function (request) {
|
|
7
|
+
const { appSecret } = request.config
|
|
6
8
|
return createMachine(
|
|
7
9
|
{
|
|
8
10
|
id: 'crypro_button',
|
|
9
11
|
initial: 'loading',
|
|
10
12
|
context: {
|
|
13
|
+
siteConfig: null,
|
|
11
14
|
paymentDetails: [],
|
|
12
15
|
|
|
13
16
|
channels: [],
|
|
@@ -16,6 +19,7 @@ export default function (request) {
|
|
|
16
19
|
options: [],
|
|
17
20
|
sourceAddress: '',
|
|
18
21
|
|
|
22
|
+
selectedChannel: null,
|
|
19
23
|
selectedAmount: null,
|
|
20
24
|
selectedCrypto: null,
|
|
21
25
|
selectedNetwork: null,
|
|
@@ -25,20 +29,51 @@ export default function (request) {
|
|
|
25
29
|
|
|
26
30
|
calculation: null,
|
|
27
31
|
result: null,
|
|
32
|
+
|
|
33
|
+
grandTotalEnable: 1,
|
|
34
|
+
|
|
35
|
+
// use for wallet mode 4
|
|
36
|
+
promotion: null,
|
|
37
|
+
bonusPreviewData: [],
|
|
28
38
|
},
|
|
29
39
|
states: {
|
|
30
40
|
loading: {
|
|
31
41
|
invoke: {
|
|
32
|
-
src: '
|
|
42
|
+
src: 'fetchInitData',
|
|
33
43
|
onDone: {
|
|
34
44
|
target: 'loaded',
|
|
35
|
-
actions: '
|
|
45
|
+
actions: 'setInitData',
|
|
36
46
|
},
|
|
37
47
|
onError: {
|
|
38
48
|
target: 'fail',
|
|
39
49
|
},
|
|
40
50
|
},
|
|
41
51
|
},
|
|
52
|
+
checking: {
|
|
53
|
+
always: [
|
|
54
|
+
{
|
|
55
|
+
target: 'fetching',
|
|
56
|
+
cond: (context, event) => {
|
|
57
|
+
const { siteConfig = {}, promotion = {}, selectedCrypto } = context
|
|
58
|
+
const { walletMode = '', bonusPreviewEnable = '0' } = siteConfig
|
|
59
|
+
return !!selectedCrypto && walletMode === '4' && bonusPreviewEnable === '1' && promotion.activityNo != 'none'
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
{ target: 'loaded' },
|
|
63
|
+
],
|
|
64
|
+
},
|
|
65
|
+
fetching: {
|
|
66
|
+
invoke: {
|
|
67
|
+
src: 'fetchBonusPreview',
|
|
68
|
+
onDone: {
|
|
69
|
+
target: 'loaded',
|
|
70
|
+
actions: 'setBonusPreview',
|
|
71
|
+
},
|
|
72
|
+
onError: {
|
|
73
|
+
target: 'loaded',
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
},
|
|
42
77
|
loaded: {
|
|
43
78
|
on: {
|
|
44
79
|
SET_CHANNEL: {
|
|
@@ -55,7 +90,7 @@ export default function (request) {
|
|
|
55
90
|
},
|
|
56
91
|
CONFIRM: {
|
|
57
92
|
target: 'selecting',
|
|
58
|
-
cond: 'isConfirmable'
|
|
93
|
+
cond: 'isConfirmable',
|
|
59
94
|
},
|
|
60
95
|
},
|
|
61
96
|
},
|
|
@@ -63,25 +98,64 @@ export default function (request) {
|
|
|
63
98
|
selecting: {
|
|
64
99
|
entry: 'reset',
|
|
65
100
|
on: {
|
|
66
|
-
SELECT_AMOUNT:
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
101
|
+
SELECT_AMOUNT: [
|
|
102
|
+
{
|
|
103
|
+
target: 'debouncing',
|
|
104
|
+
actions: 'setAmount',
|
|
105
|
+
cond: 'isDoubleWalletMode',
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
actions: 'addAmount',
|
|
109
|
+
cond: (context, event) => context.siteConfig?.walletMode === '2' && context.grandTotalEnable === 1,
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
actions: 'setAmount',
|
|
113
|
+
cond: 'isFreeWalletMode',
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
target: 'debouncing',
|
|
117
|
+
actions: 'addAmount',
|
|
118
|
+
cond: 'isGrandTotalEnable',
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
target: 'debouncing',
|
|
122
|
+
actions: 'setAmount',
|
|
123
|
+
},
|
|
124
|
+
],
|
|
125
|
+
KEY_IN: [
|
|
126
|
+
{
|
|
127
|
+
actions: 'setAmount',
|
|
128
|
+
cond: 'isFreeWalletMode',
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
target: 'debouncing',
|
|
132
|
+
actions: 'setAmount',
|
|
133
|
+
},
|
|
134
|
+
],
|
|
135
|
+
SUBMIT: {
|
|
71
136
|
target: 'debouncing',
|
|
72
|
-
actions: 'setAmount'
|
|
73
137
|
},
|
|
74
138
|
BACK: {
|
|
75
|
-
target: 'loaded'
|
|
76
|
-
}
|
|
77
|
-
|
|
139
|
+
target: 'loaded',
|
|
140
|
+
},
|
|
141
|
+
CLEAR_ALL: {
|
|
142
|
+
actions: 'reset',
|
|
143
|
+
},
|
|
144
|
+
},
|
|
78
145
|
},
|
|
79
146
|
debouncing: {
|
|
80
147
|
on: {
|
|
81
|
-
SELECT_AMOUNT:
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
148
|
+
SELECT_AMOUNT: [
|
|
149
|
+
{
|
|
150
|
+
target: 'debouncing',
|
|
151
|
+
actions: 'addAmount',
|
|
152
|
+
cond: 'isGrandTotalEnable',
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
target: 'debouncing',
|
|
156
|
+
actions: 'setAmount',
|
|
157
|
+
},
|
|
158
|
+
],
|
|
85
159
|
KEY_IN: {
|
|
86
160
|
target: 'debouncing',
|
|
87
161
|
actions: 'setAmount',
|
|
@@ -96,29 +170,43 @@ export default function (request) {
|
|
|
96
170
|
calculating: {
|
|
97
171
|
invoke: {
|
|
98
172
|
src: 'fetchCalculation',
|
|
99
|
-
onDone:
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
173
|
+
onDone: [
|
|
174
|
+
{
|
|
175
|
+
target: 'submitting',
|
|
176
|
+
actions: 'setCalculation',
|
|
177
|
+
cond: 'isFreeWalletMode',
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
target: 'calculated',
|
|
181
|
+
actions: 'setCalculation',
|
|
182
|
+
},
|
|
183
|
+
],
|
|
103
184
|
onError: {
|
|
104
185
|
target: 'selecting',
|
|
105
|
-
actions: 'reset'
|
|
186
|
+
actions: 'reset',
|
|
106
187
|
},
|
|
107
188
|
},
|
|
108
189
|
},
|
|
109
190
|
calculated: {
|
|
110
191
|
on: {
|
|
111
|
-
SELECT_AMOUNT:
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
192
|
+
SELECT_AMOUNT: [
|
|
193
|
+
{
|
|
194
|
+
target: 'debouncing',
|
|
195
|
+
actions: 'addAmount',
|
|
196
|
+
cond: 'isGrandTotalEnable',
|
|
197
|
+
},
|
|
198
|
+
{
|
|
199
|
+
target: 'debouncing',
|
|
200
|
+
actions: 'setAmount',
|
|
201
|
+
},
|
|
202
|
+
],
|
|
115
203
|
KEY_IN: {
|
|
116
204
|
target: 'debouncing',
|
|
117
205
|
actions: 'setAmount',
|
|
118
206
|
},
|
|
119
207
|
SUBMIT: {
|
|
120
208
|
target: 'submitting',
|
|
121
|
-
cond: 'isSubmittable'
|
|
209
|
+
cond: 'isSubmittable',
|
|
122
210
|
},
|
|
123
211
|
CLEAR_CALCULATION: {
|
|
124
212
|
target: 'debouncing',
|
|
@@ -138,11 +226,15 @@ export default function (request) {
|
|
|
138
226
|
actions: 'setResult',
|
|
139
227
|
},
|
|
140
228
|
onError: {
|
|
141
|
-
target: '
|
|
229
|
+
target: 'loaded',
|
|
142
230
|
},
|
|
143
231
|
},
|
|
144
232
|
},
|
|
145
|
-
submitted: {
|
|
233
|
+
submitted: {},
|
|
234
|
+
},
|
|
235
|
+
on: {
|
|
236
|
+
SET_PROMOTION: {
|
|
237
|
+
actions: 'setPromotion',
|
|
146
238
|
},
|
|
147
239
|
},
|
|
148
240
|
},
|
|
@@ -152,11 +244,16 @@ export default function (request) {
|
|
|
152
244
|
return {
|
|
153
245
|
selectedAmount: null,
|
|
154
246
|
calculation: null,
|
|
247
|
+
result: null,
|
|
155
248
|
}
|
|
156
249
|
}),
|
|
157
|
-
|
|
158
|
-
const
|
|
159
|
-
const
|
|
250
|
+
setInitData: assign((context, event) => {
|
|
251
|
+
const { siteConfig, paymentDetail } = event.data
|
|
252
|
+
const cryptos =
|
|
253
|
+
paymentDetail
|
|
254
|
+
?.filter((element) => element.category === context.currentCategory)
|
|
255
|
+
?.map((crypto) => ({ ...crypto, label: crypto.channel, value: crypto.method, icon: crypto.channel })) || []
|
|
256
|
+
const currentPayment = cryptos[0]
|
|
160
257
|
const channels = cryptos.map((item, i) => ({ ...item, label: `Channel ${padStart(String(i + 1), 2, '0')}`, icon: 'channel' }))
|
|
161
258
|
const defaultNetworks =
|
|
162
259
|
cryptos[0].networkName.map((value, i) => {
|
|
@@ -168,14 +265,16 @@ export default function (request) {
|
|
|
168
265
|
}) || []
|
|
169
266
|
const options = cryptos[0].optional
|
|
170
267
|
return {
|
|
268
|
+
siteConfig,
|
|
171
269
|
channels,
|
|
172
270
|
cryptos,
|
|
173
271
|
networks: defaultNetworks,
|
|
174
272
|
selectedChannel: channels[0],
|
|
175
273
|
selectedCrypto: cryptos[0],
|
|
176
274
|
selectedNetwork: defaultNetworks[0],
|
|
275
|
+
grandTotalEnable: cryptos[0].grandTotalEnable,
|
|
177
276
|
currentPayment,
|
|
178
|
-
options
|
|
277
|
+
options,
|
|
179
278
|
}
|
|
180
279
|
}),
|
|
181
280
|
setChannel: assign((context, event) => {
|
|
@@ -197,7 +296,8 @@ export default function (request) {
|
|
|
197
296
|
selectedNetwork: networks[0],
|
|
198
297
|
selectedAmount: null,
|
|
199
298
|
calculation: null,
|
|
200
|
-
|
|
299
|
+
grandTotalEnable: selectedCrypto.grandTotalEnable,
|
|
300
|
+
options,
|
|
201
301
|
}
|
|
202
302
|
}),
|
|
203
303
|
setCrypto: assign((context, event) => {
|
|
@@ -211,7 +311,6 @@ export default function (request) {
|
|
|
211
311
|
icon: value,
|
|
212
312
|
}
|
|
213
313
|
}) || []
|
|
214
|
-
|
|
215
314
|
const properties = {
|
|
216
315
|
selectedCrypto: event.data,
|
|
217
316
|
networks,
|
|
@@ -228,6 +327,11 @@ export default function (request) {
|
|
|
228
327
|
setNetwork: assign((context, event) => {
|
|
229
328
|
return { selectedNetwork: event.data }
|
|
230
329
|
}),
|
|
330
|
+
setBonusPreview: assign((context, event) => {
|
|
331
|
+
return {
|
|
332
|
+
bonusPreviewData: event.data.bonus,
|
|
333
|
+
}
|
|
334
|
+
}),
|
|
231
335
|
addAmount: assign((context, event) => {
|
|
232
336
|
return { selectedAmount: (context.selectedAmount || 0) + event.data }
|
|
233
337
|
}),
|
|
@@ -254,8 +358,23 @@ export default function (request) {
|
|
|
254
358
|
result: event.data,
|
|
255
359
|
}
|
|
256
360
|
}),
|
|
361
|
+
setPromotion: assign((context, event) => {
|
|
362
|
+
const promotion = event.data
|
|
363
|
+
return {
|
|
364
|
+
promotion,
|
|
365
|
+
}
|
|
366
|
+
}),
|
|
257
367
|
},
|
|
258
368
|
guards: {
|
|
369
|
+
isFreeWalletMode: (context, event) => {
|
|
370
|
+
return context.siteConfig?.walletMode === '2'
|
|
371
|
+
},
|
|
372
|
+
isDoubleWalletMode: (context, event) => {
|
|
373
|
+
return context.siteConfig?.walletMode === '4'
|
|
374
|
+
},
|
|
375
|
+
isGrandTotalEnable: (context, event) => {
|
|
376
|
+
return context.grandTotalEnable === 1
|
|
377
|
+
},
|
|
259
378
|
isConfirmable: (context, event) => {
|
|
260
379
|
const { selectedCrypto, selectedNetwork } = context
|
|
261
380
|
return selectedCrypto && selectedNetwork
|
|
@@ -266,28 +385,44 @@ export default function (request) {
|
|
|
266
385
|
},
|
|
267
386
|
},
|
|
268
387
|
services: {
|
|
269
|
-
|
|
270
|
-
|
|
388
|
+
fetchInitData: async (context, event) => {
|
|
389
|
+
const [{ config }, paymentDetail = []] = await Promise.all([
|
|
390
|
+
request.send(common.getConfig({ appSecret })),
|
|
391
|
+
request.send(payment.getPaymentDetail({ transferType: 'DEPOSIT' })),
|
|
392
|
+
])
|
|
393
|
+
const siteConfig = JSON.parse(window.atob(config))
|
|
394
|
+
return { siteConfig, paymentDetail }
|
|
395
|
+
},
|
|
396
|
+
fetchBonusPreview: async (context, event) => {
|
|
397
|
+
const { selectedCrypto, promotion } = context
|
|
398
|
+
return await request.send(
|
|
399
|
+
payment.getBonusPreview({
|
|
400
|
+
method: selectedCrypto.method,
|
|
401
|
+
promotionsNo: promotion?.activityNo,
|
|
402
|
+
})
|
|
403
|
+
)
|
|
271
404
|
},
|
|
272
405
|
fetchCalculation: async (context, event) => {
|
|
273
|
-
const { selectedCrypto, selectedAmount } = context
|
|
406
|
+
const { selectedCrypto, selectedAmount, promotion } = context
|
|
274
407
|
return await request.send(
|
|
275
408
|
payment.getDepositExpectedResult({
|
|
276
409
|
method: selectedCrypto.method,
|
|
277
410
|
amount: selectedAmount,
|
|
278
411
|
cryptoCurrency: selectedCrypto.channel,
|
|
412
|
+
promotionsNo: promotion?.activityNo,
|
|
279
413
|
})
|
|
280
414
|
)
|
|
281
415
|
},
|
|
282
416
|
submitDeposit: async (context, event) => {
|
|
283
|
-
const { selectedCrypto, selectedNetwork, calculation, sourceAddress } = context
|
|
417
|
+
const { selectedCrypto, selectedNetwork, calculation, sourceAddress, promotion } = context
|
|
284
418
|
return await request.send(
|
|
285
|
-
payment.
|
|
419
|
+
payment.submitDepositTransactionCrypto({
|
|
286
420
|
method: selectedCrypto.method,
|
|
287
421
|
amount: calculation.actualAmount,
|
|
288
422
|
cryptoCurrency: selectedCrypto.channel,
|
|
289
423
|
cryptoNetwork: selectedNetwork.value,
|
|
290
424
|
sourceAddress: sourceAddress,
|
|
425
|
+
promotionsNo: promotion?.activityNo,
|
|
291
426
|
})
|
|
292
427
|
)
|
|
293
428
|
},
|
|
@@ -0,0 +1,255 @@
|
|
|
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_cash',
|
|
10
|
+
initial: 'loading',
|
|
11
|
+
context: {
|
|
12
|
+
paymentDetail,
|
|
13
|
+
promotion,
|
|
14
|
+
selectedAmount,
|
|
15
|
+
|
|
16
|
+
cryptos: [],
|
|
17
|
+
networks: [],
|
|
18
|
+
sourceAddress: '',
|
|
19
|
+
options: [],
|
|
20
|
+
|
|
21
|
+
selectedCrypto: null,
|
|
22
|
+
selectedNetwork: null,
|
|
23
|
+
|
|
24
|
+
currentCategory: 'crypto',
|
|
25
|
+
|
|
26
|
+
calculation: null,
|
|
27
|
+
result: null,
|
|
28
|
+
},
|
|
29
|
+
states: {
|
|
30
|
+
loading: {
|
|
31
|
+
always: [
|
|
32
|
+
{
|
|
33
|
+
target: 'debouncing',
|
|
34
|
+
actions: 'setInitData',
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
|
+
},
|
|
38
|
+
loaded: {},
|
|
39
|
+
debouncing: {
|
|
40
|
+
entry: 'clearCalculation',
|
|
41
|
+
after: {
|
|
42
|
+
1000: [
|
|
43
|
+
{
|
|
44
|
+
target: 'calculating',
|
|
45
|
+
cond: 'isCalculable',
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
target: 'loaded',
|
|
49
|
+
},
|
|
50
|
+
],
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
calculating: {
|
|
54
|
+
invoke: {
|
|
55
|
+
src: 'fetchCalculation',
|
|
56
|
+
onDone: {
|
|
57
|
+
target: 'calculated',
|
|
58
|
+
actions: 'setCalculation',
|
|
59
|
+
},
|
|
60
|
+
onError: {
|
|
61
|
+
target: 'calculated',
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
calculated: {
|
|
66
|
+
on: {
|
|
67
|
+
SUBMIT: [
|
|
68
|
+
{
|
|
69
|
+
target: 'submitting',
|
|
70
|
+
cond: 'isSubmittable',
|
|
71
|
+
},
|
|
72
|
+
],
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
submitting: {
|
|
76
|
+
invoke: {
|
|
77
|
+
src: 'submitDeposit',
|
|
78
|
+
onDone: {
|
|
79
|
+
target: 'submitted',
|
|
80
|
+
actions: 'setResult',
|
|
81
|
+
},
|
|
82
|
+
onError: {
|
|
83
|
+
target: 'loaded',
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
submitted: {},
|
|
88
|
+
},
|
|
89
|
+
on: {
|
|
90
|
+
SET_PROMOTION: {
|
|
91
|
+
target: '.debouncing',
|
|
92
|
+
actions: 'setPromotion',
|
|
93
|
+
internal: false,
|
|
94
|
+
},
|
|
95
|
+
SET_CRYPTO: {
|
|
96
|
+
target: '.debouncing',
|
|
97
|
+
actions: 'setCrypto',
|
|
98
|
+
internal: false,
|
|
99
|
+
},
|
|
100
|
+
SET_NETWORK: {
|
|
101
|
+
target: '.debouncing',
|
|
102
|
+
actions: 'setNetwork',
|
|
103
|
+
internal: false,
|
|
104
|
+
},
|
|
105
|
+
SET_ADDRESS: {
|
|
106
|
+
actions: 'setAddress',
|
|
107
|
+
internal: false,
|
|
108
|
+
},
|
|
109
|
+
SET_AMOUNT: {
|
|
110
|
+
target: '.debouncing',
|
|
111
|
+
actions: 'setAmount',
|
|
112
|
+
internal: false,
|
|
113
|
+
},
|
|
114
|
+
INPUT_AMOUNT: {
|
|
115
|
+
target: '.debouncing',
|
|
116
|
+
actions: 'inputAmount',
|
|
117
|
+
internal: false,
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
actions: {
|
|
123
|
+
setInitData: assign((context, event) => {
|
|
124
|
+
const { paymentDetail } = context
|
|
125
|
+
const cryptos = paymentDetail
|
|
126
|
+
.filter((element) => element.transferType === 'deposit' && element.category === context.currentCategory)
|
|
127
|
+
.map((crypto) => ({
|
|
128
|
+
...crypto,
|
|
129
|
+
label: crypto.channel,
|
|
130
|
+
value: crypto.method,
|
|
131
|
+
icon: crypto.channel,
|
|
132
|
+
}))
|
|
133
|
+
const defaultNetworks = cryptos[0].networkName.map((value, i) => {
|
|
134
|
+
return {
|
|
135
|
+
label: cryptos[0].networkOptional?.[i],
|
|
136
|
+
value,
|
|
137
|
+
icon: value,
|
|
138
|
+
}
|
|
139
|
+
})
|
|
140
|
+
return {
|
|
141
|
+
cryptos,
|
|
142
|
+
networks: defaultNetworks,
|
|
143
|
+
selectedCrypto: cryptos[0],
|
|
144
|
+
selectedNetwork: defaultNetworks[0],
|
|
145
|
+
options: cryptos[0].optional,
|
|
146
|
+
}
|
|
147
|
+
}),
|
|
148
|
+
setCrypto: assign((context, event) => {
|
|
149
|
+
const { cryptos } = context
|
|
150
|
+
const selectedCrypto = cryptos.find((crypto) => crypto.method === event.data.value)
|
|
151
|
+
const networks = selectedCrypto?.networkName.map((value, i) => {
|
|
152
|
+
return {
|
|
153
|
+
label: selectedCrypto?.networkOptional?.[i],
|
|
154
|
+
value,
|
|
155
|
+
icon: value,
|
|
156
|
+
}
|
|
157
|
+
})
|
|
158
|
+
return {
|
|
159
|
+
networks,
|
|
160
|
+
selectedCrypto: selectedCrypto,
|
|
161
|
+
selectedNetwork: networks[0],
|
|
162
|
+
selectedAmount: null,
|
|
163
|
+
calculation: null,
|
|
164
|
+
options: selectedCrypto.optional,
|
|
165
|
+
}
|
|
166
|
+
}),
|
|
167
|
+
setNetwork: assign((context, event) => {
|
|
168
|
+
return { selectedNetwork: event.data }
|
|
169
|
+
}),
|
|
170
|
+
setAmount: assign((context, event) => {
|
|
171
|
+
// 現金網可自由填額度,grandTotalEnable 欄位感覺不再需要?
|
|
172
|
+
if (context.selectedCrypto?.grandTotalEnable === 1) {
|
|
173
|
+
return { selectedAmount: parseFloat(context.selectedAmount || 0) + parseFloat(event.data) }
|
|
174
|
+
} else {
|
|
175
|
+
return { selectedAmount: event.data }
|
|
176
|
+
}
|
|
177
|
+
}),
|
|
178
|
+
inputAmount: assign((context, event) => {
|
|
179
|
+
return { selectedAmount: event.data }
|
|
180
|
+
}),
|
|
181
|
+
setAddress: assign((context, event) => {
|
|
182
|
+
return {
|
|
183
|
+
sourceAddress: event.data,
|
|
184
|
+
}
|
|
185
|
+
}),
|
|
186
|
+
setCalculation: assign((context, event) => {
|
|
187
|
+
return {
|
|
188
|
+
calculation: event.data,
|
|
189
|
+
}
|
|
190
|
+
}),
|
|
191
|
+
clearCalculation: assign((context, event) => {
|
|
192
|
+
return {
|
|
193
|
+
calculation: null,
|
|
194
|
+
}
|
|
195
|
+
}),
|
|
196
|
+
setResult: assign((context, event) => {
|
|
197
|
+
return {
|
|
198
|
+
result: event.data,
|
|
199
|
+
}
|
|
200
|
+
}),
|
|
201
|
+
setPromotion: assign((context, event) => {
|
|
202
|
+
const { selectedCrypto, selectedAmount } = context
|
|
203
|
+
const promotion = event.data
|
|
204
|
+
return {
|
|
205
|
+
promotion,
|
|
206
|
+
selectedAmount: max(promotion.minimumAmount, selectedCrypto.minimum, selectedAmount, 0),
|
|
207
|
+
calculation: null,
|
|
208
|
+
}
|
|
209
|
+
}),
|
|
210
|
+
},
|
|
211
|
+
guards: {
|
|
212
|
+
isCalculable: (context, event) => {
|
|
213
|
+
const { selectedCrypto, selectedNetwork, selectedAmount } = context
|
|
214
|
+
return (
|
|
215
|
+
selectedCrypto &&
|
|
216
|
+
selectedNetwork &&
|
|
217
|
+
selectedAmount &&
|
|
218
|
+
selectedCrypto.minimum <= +selectedAmount &&
|
|
219
|
+
+selectedAmount <= selectedCrypto.maximum
|
|
220
|
+
)
|
|
221
|
+
},
|
|
222
|
+
isSubmittable: (context, event) => {
|
|
223
|
+
const { selectedCrypto, selectedNetwork, selectedAmount } = context
|
|
224
|
+
return selectedCrypto && selectedNetwork && selectedAmount
|
|
225
|
+
},
|
|
226
|
+
},
|
|
227
|
+
services: {
|
|
228
|
+
fetchCalculation: async (context, event) => {
|
|
229
|
+
const { selectedCrypto, selectedAmount, promotion } = context
|
|
230
|
+
return await request.send(
|
|
231
|
+
payment.getDepositExpectedResult({
|
|
232
|
+
method: selectedCrypto.method,
|
|
233
|
+
amount: selectedAmount,
|
|
234
|
+
cryptoCurrency: selectedCrypto.channel,
|
|
235
|
+
promotionsNo: promotion?.promotionsNo,
|
|
236
|
+
})
|
|
237
|
+
)
|
|
238
|
+
},
|
|
239
|
+
submitDeposit: async (context, event) => {
|
|
240
|
+
const { selectedCrypto, selectedNetwork, calculation, sourceAddress, promotion } = context
|
|
241
|
+
return await request.send(
|
|
242
|
+
payment.submitDepositTransactionCrypto({
|
|
243
|
+
method: selectedCrypto.method,
|
|
244
|
+
amount: calculation.actualAmount,
|
|
245
|
+
cryptoCurrency: selectedCrypto.channel,
|
|
246
|
+
cryptoNetwork: selectedNetwork.value,
|
|
247
|
+
sourceAddress: sourceAddress,
|
|
248
|
+
promotionsNo: promotion?.promotionsNo,
|
|
249
|
+
})
|
|
250
|
+
)
|
|
251
|
+
},
|
|
252
|
+
},
|
|
253
|
+
}
|
|
254
|
+
)
|
|
255
|
+
}
|