@jetthai/cuora 1.1.173 → 1.1.175
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,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.1.175](https://github.com/jetthai/cuora-module/compare/v1.1.174...v1.1.175) (2023-09-18)
|
|
6
|
+
|
|
7
|
+
### [1.1.174](https://github.com/jetthai/cuora-module/compare/v1.1.173...v1.1.174) (2023-09-08)
|
|
8
|
+
|
|
5
9
|
### [1.1.173](https://github.com/jetthai/cuora-module/compare/v1.1.172...v1.1.173) (2023-09-07)
|
|
6
10
|
|
|
7
11
|
### [1.1.172](https://github.com/jetthai/cuora-module/compare/v1.1.171...v1.1.172) (2023-09-07)
|
package/package.json
CHANGED
package/src/api/payment.js
CHANGED
|
@@ -10,12 +10,25 @@ export default {
|
|
|
10
10
|
getTransactionHistoryOptions: () => ({ url: 'payment/v2/category/options', method: 'get' }),
|
|
11
11
|
// getPaymentInfo: () => ({ url: `payment/paymentInfo`, method: 'get' }),
|
|
12
12
|
getPaymentInfo: () => ({ url: `payment/v2/paymentInfo`, method: 'get' }),
|
|
13
|
-
updatePaymentInfo: ({
|
|
13
|
+
updatePaymentInfo: ({
|
|
14
|
+
bankCode,
|
|
15
|
+
branch,
|
|
16
|
+
branchCode,
|
|
17
|
+
holderName,
|
|
18
|
+
bankAccount,
|
|
19
|
+
firstNameTh,
|
|
20
|
+
lastNameTh,
|
|
21
|
+
firstNameEn,
|
|
22
|
+
lastNameEn,
|
|
23
|
+
bonus,
|
|
24
|
+
paymentProvider,
|
|
25
|
+
}) => ({
|
|
14
26
|
url: 'payment/v2/updatePaymentInfo',
|
|
15
27
|
method: 'post',
|
|
16
28
|
params: {
|
|
17
29
|
bankCode,
|
|
18
30
|
branch,
|
|
31
|
+
branchCode,
|
|
19
32
|
holderName,
|
|
20
33
|
bankAccount,
|
|
21
34
|
firstNameTh,
|
|
@@ -0,0 +1,275 @@
|
|
|
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
|
+
networks: [],
|
|
18
|
+
sourceAddress: '',
|
|
19
|
+
options: [],
|
|
20
|
+
|
|
21
|
+
selectedCrypto: null,
|
|
22
|
+
selectedNetwork: null,
|
|
23
|
+
|
|
24
|
+
currentCategory: 'cryptoWay',
|
|
25
|
+
|
|
26
|
+
calculation: null,
|
|
27
|
+
result: null,
|
|
28
|
+
ttl: 0,
|
|
29
|
+
},
|
|
30
|
+
states: {
|
|
31
|
+
loading: {
|
|
32
|
+
always: [
|
|
33
|
+
{
|
|
34
|
+
target: 'debouncing',
|
|
35
|
+
actions: 'setInitData',
|
|
36
|
+
},
|
|
37
|
+
],
|
|
38
|
+
},
|
|
39
|
+
loaded: {},
|
|
40
|
+
debouncing: {
|
|
41
|
+
entry: 'clearCalculation',
|
|
42
|
+
after: {
|
|
43
|
+
1000: [
|
|
44
|
+
{
|
|
45
|
+
target: 'calculating',
|
|
46
|
+
cond: 'isCalculable',
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
target: 'loaded',
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
calculating: {
|
|
55
|
+
invoke: {
|
|
56
|
+
src: 'fetchCalculation',
|
|
57
|
+
onDone: {
|
|
58
|
+
target: 'calculated',
|
|
59
|
+
actions: 'setCalculation',
|
|
60
|
+
},
|
|
61
|
+
onError: {
|
|
62
|
+
target: 'calculated',
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
calculated: {
|
|
67
|
+
on: {
|
|
68
|
+
SUBMIT: [
|
|
69
|
+
{
|
|
70
|
+
target: 'submitting',
|
|
71
|
+
cond: 'isSubmittable',
|
|
72
|
+
},
|
|
73
|
+
],
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
submitting: {
|
|
77
|
+
invoke: {
|
|
78
|
+
src: 'submitDeposit',
|
|
79
|
+
onDone: {
|
|
80
|
+
target: 'submitted',
|
|
81
|
+
actions: ['setResult', 'setTtl'],
|
|
82
|
+
},
|
|
83
|
+
onError: {
|
|
84
|
+
target: 'loaded',
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
submitted: {
|
|
89
|
+
after: {
|
|
90
|
+
1000: {
|
|
91
|
+
target: 'submitted',
|
|
92
|
+
actions: 'decreaseTtl',
|
|
93
|
+
cond: (context) => context.ttl > 0,
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
on: {
|
|
99
|
+
SET_PROMOTION: {
|
|
100
|
+
target: '.debouncing',
|
|
101
|
+
actions: 'setPromotion',
|
|
102
|
+
internal: false,
|
|
103
|
+
},
|
|
104
|
+
SET_CRYPTO: {
|
|
105
|
+
target: '.debouncing',
|
|
106
|
+
actions: 'setCrypto',
|
|
107
|
+
internal: false,
|
|
108
|
+
},
|
|
109
|
+
SET_NETWORK: {
|
|
110
|
+
target: '.debouncing',
|
|
111
|
+
actions: 'setNetwork',
|
|
112
|
+
internal: false,
|
|
113
|
+
},
|
|
114
|
+
SET_ADDRESS: {
|
|
115
|
+
actions: 'setAddress',
|
|
116
|
+
internal: false,
|
|
117
|
+
},
|
|
118
|
+
SET_AMOUNT: {
|
|
119
|
+
target: '.debouncing',
|
|
120
|
+
actions: 'setAmount',
|
|
121
|
+
internal: false,
|
|
122
|
+
},
|
|
123
|
+
INPUT_AMOUNT: {
|
|
124
|
+
target: '.debouncing',
|
|
125
|
+
actions: 'inputAmount',
|
|
126
|
+
internal: false,
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
actions: {
|
|
132
|
+
setInitData: assign((context, event) => {
|
|
133
|
+
const { paymentDetail } = context
|
|
134
|
+
const cryptos = paymentDetail
|
|
135
|
+
.filter((element) => element.transferType === 'deposit' && element.category === context.currentCategory)
|
|
136
|
+
.map((crypto) => ({
|
|
137
|
+
...crypto,
|
|
138
|
+
label: crypto.channel,
|
|
139
|
+
value: crypto.method,
|
|
140
|
+
icon: crypto.channel,
|
|
141
|
+
}))
|
|
142
|
+
const defaultNetworks = cryptos[0].networkName.map((value, i) => {
|
|
143
|
+
return {
|
|
144
|
+
label: cryptos[0].networkOptional?.[i],
|
|
145
|
+
value,
|
|
146
|
+
icon: value,
|
|
147
|
+
}
|
|
148
|
+
})
|
|
149
|
+
return {
|
|
150
|
+
cryptos,
|
|
151
|
+
networks: defaultNetworks,
|
|
152
|
+
selectedCrypto: cryptos[0],
|
|
153
|
+
selectedNetwork: defaultNetworks[0],
|
|
154
|
+
options: cryptos[0].optional,
|
|
155
|
+
}
|
|
156
|
+
}),
|
|
157
|
+
setCrypto: assign((context, event) => {
|
|
158
|
+
const { cryptos } = context
|
|
159
|
+
const selectedCrypto = cryptos.find((crypto) => crypto.method === event.data.value)
|
|
160
|
+
const networks = selectedCrypto?.networkName.map((value, i) => {
|
|
161
|
+
return {
|
|
162
|
+
label: selectedCrypto?.networkOptional?.[i],
|
|
163
|
+
value,
|
|
164
|
+
icon: value,
|
|
165
|
+
}
|
|
166
|
+
})
|
|
167
|
+
return {
|
|
168
|
+
networks,
|
|
169
|
+
selectedCrypto: selectedCrypto,
|
|
170
|
+
selectedNetwork: networks[0],
|
|
171
|
+
selectedAmount: null,
|
|
172
|
+
calculation: null,
|
|
173
|
+
options: selectedCrypto.optional,
|
|
174
|
+
}
|
|
175
|
+
}),
|
|
176
|
+
setNetwork: assign((context, event) => {
|
|
177
|
+
return { selectedNetwork: event.data }
|
|
178
|
+
}),
|
|
179
|
+
setAmount: assign((context, event) => {
|
|
180
|
+
// 現金網可自由填額度,grandTotalEnable 欄位感覺不再需要?
|
|
181
|
+
if (context.selectedCrypto?.grandTotalEnable === 1) {
|
|
182
|
+
return { selectedAmount: parseFloat(context.selectedAmount || 0) + parseFloat(event.data) }
|
|
183
|
+
} else {
|
|
184
|
+
return { selectedAmount: event.data }
|
|
185
|
+
}
|
|
186
|
+
}),
|
|
187
|
+
inputAmount: assign((context, event) => {
|
|
188
|
+
return { selectedAmount: event.data }
|
|
189
|
+
}),
|
|
190
|
+
setAddress: assign((context, event) => {
|
|
191
|
+
return {
|
|
192
|
+
sourceAddress: event.data,
|
|
193
|
+
}
|
|
194
|
+
}),
|
|
195
|
+
setCalculation: assign((context, event) => {
|
|
196
|
+
return {
|
|
197
|
+
calculation: event.data,
|
|
198
|
+
}
|
|
199
|
+
}),
|
|
200
|
+
clearCalculation: assign((context, event) => {
|
|
201
|
+
return {
|
|
202
|
+
calculation: null,
|
|
203
|
+
}
|
|
204
|
+
}),
|
|
205
|
+
setResult: assign((context, event) => {
|
|
206
|
+
return {
|
|
207
|
+
result: event.data,
|
|
208
|
+
}
|
|
209
|
+
}),
|
|
210
|
+
setPromotion: assign((context, event) => {
|
|
211
|
+
const { selectedCrypto, selectedAmount } = context
|
|
212
|
+
const promotion = event.data
|
|
213
|
+
return {
|
|
214
|
+
promotion,
|
|
215
|
+
selectedAmount: max(promotion.minimumAmount, selectedCrypto.minimum, selectedAmount, 0),
|
|
216
|
+
calculation: null,
|
|
217
|
+
}
|
|
218
|
+
}),
|
|
219
|
+
setTtl: assign((context, event) => {
|
|
220
|
+
const { cdtime } = event.data
|
|
221
|
+
return {
|
|
222
|
+
ttl: cdtime,
|
|
223
|
+
}
|
|
224
|
+
}),
|
|
225
|
+
decreaseTtl: assign((context, evnet) => {
|
|
226
|
+
return {
|
|
227
|
+
ttl: Math.max(context.ttl - 1000, 0),
|
|
228
|
+
}
|
|
229
|
+
}),
|
|
230
|
+
},
|
|
231
|
+
guards: {
|
|
232
|
+
isCalculable: (context, event) => {
|
|
233
|
+
const { selectedCrypto, selectedNetwork, selectedAmount } = context
|
|
234
|
+
return (
|
|
235
|
+
selectedCrypto &&
|
|
236
|
+
selectedNetwork &&
|
|
237
|
+
selectedAmount &&
|
|
238
|
+
selectedCrypto.minimum <= +selectedAmount &&
|
|
239
|
+
+selectedAmount <= selectedCrypto.maximum
|
|
240
|
+
)
|
|
241
|
+
},
|
|
242
|
+
isSubmittable: (context, event) => {
|
|
243
|
+
const { selectedCrypto, selectedNetwork, selectedAmount } = context
|
|
244
|
+
return selectedCrypto && selectedNetwork && selectedAmount
|
|
245
|
+
},
|
|
246
|
+
},
|
|
247
|
+
services: {
|
|
248
|
+
fetchCalculation: async (context, event) => {
|
|
249
|
+
const { selectedCrypto, selectedAmount, promotion } = context
|
|
250
|
+
return await request.send(
|
|
251
|
+
payment.getDepositExpectedResult({
|
|
252
|
+
method: selectedCrypto.method,
|
|
253
|
+
amount: selectedAmount,
|
|
254
|
+
cryptoCurrency: selectedCrypto.channel,
|
|
255
|
+
promotionsNo: promotion?.promotionsNo,
|
|
256
|
+
})
|
|
257
|
+
)
|
|
258
|
+
},
|
|
259
|
+
submitDeposit: async (context, event) => {
|
|
260
|
+
const { selectedCrypto, selectedNetwork, calculation, sourceAddress, promotion } = context
|
|
261
|
+
return await request.send(
|
|
262
|
+
payment.submitDepositTransactionCrypto({
|
|
263
|
+
method: selectedCrypto.method,
|
|
264
|
+
amount: calculation.actualAmount,
|
|
265
|
+
cryptoCurrency: selectedCrypto.channel,
|
|
266
|
+
cryptoNetwork: selectedNetwork.value,
|
|
267
|
+
sourceAddress: sourceAddress,
|
|
268
|
+
promotionsNo: promotion?.promotionsNo,
|
|
269
|
+
})
|
|
270
|
+
)
|
|
271
|
+
},
|
|
272
|
+
},
|
|
273
|
+
}
|
|
274
|
+
)
|
|
275
|
+
}
|
|
@@ -15,6 +15,7 @@ import usdt_cash from './usdt_cash.js'
|
|
|
15
15
|
import crypto_cash from './crypto_cash.js'
|
|
16
16
|
import direct_cash from './direct_cash.js'
|
|
17
17
|
import loadcard_cash from './loadcard_cash.js'
|
|
18
|
+
import crypto_way_cash from './crypto_way_cash.js'
|
|
18
19
|
|
|
19
20
|
export default {
|
|
20
21
|
manual_vn,
|
|
@@ -34,4 +35,5 @@ export default {
|
|
|
34
35
|
crypto_cash,
|
|
35
36
|
direct_cash,
|
|
36
37
|
loadcard_cash,
|
|
38
|
+
crypto_way_cash,
|
|
37
39
|
}
|
package/src/machine/side_v2.js
CHANGED
|
@@ -127,7 +127,7 @@ export default function (request) {
|
|
|
127
127
|
pushHistoryStack: assign((context, event) => {
|
|
128
128
|
const { menuItemStack, historyStack } = context
|
|
129
129
|
return {
|
|
130
|
-
historyStack: historyStack.
|
|
130
|
+
historyStack: [...historyStack, event.data],
|
|
131
131
|
}
|
|
132
132
|
}),
|
|
133
133
|
popHistoryStack: assign((context, event) => {
|