@jetthai/cuora 1.0.33 → 1.0.35
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/api/user.js +1 -1
- package/src/machine/auth.js +38 -14
- package/src/machine/auth_otp.js +1 -1
- package/src/machine/check.js +4 -4
- package/src/machine/deposit.js +14 -7
- package/src/machine/index.js +2 -0
- package/src/machine/user_info.js +64 -0
- package/src/machine/withdraw.js +19 -10
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.35](https://github.com/jetthai/cuora-module/compare/v1.0.34...v1.0.35) (2021-10-28)
|
|
6
|
+
|
|
7
|
+
### [1.0.34](https://github.com/jetthai/cuora-module/compare/v1.0.33...v1.0.34) (2021-10-26)
|
|
8
|
+
|
|
5
9
|
### [1.0.33](https://github.com/jetthai/cuora-module/compare/v1.0.32...v1.0.33) (2021-10-22)
|
|
6
10
|
|
|
7
11
|
### [1.0.32](https://github.com/jetthai/cuora-module/compare/v1.0.31...v1.0.32) (2021-10-21)
|
package/package.json
CHANGED
package/src/api/user.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export default {
|
|
2
2
|
getUserInfo: () => ({ url: 'self', method: 'get' }),
|
|
3
|
-
|
|
3
|
+
updateUserInfo: (data) => ({ url: 'self', method: 'post', params: data }),
|
|
4
4
|
changePassword: (data) => ({ url: 'settings/password', method: 'post', params: data }),
|
|
5
5
|
setPreference: ({ defaultCategory }) => ({ url: 'settings/preference', method: 'post', params: { defaultCategory } }),
|
|
6
6
|
resetOtp: ({ requestId, number }) => ({ url: 'reset', method: 'post', params: { requestId, number } }),
|
package/src/machine/auth.js
CHANGED
|
@@ -104,28 +104,48 @@ export default function (request) {
|
|
|
104
104
|
},
|
|
105
105
|
},
|
|
106
106
|
user: {
|
|
107
|
+
id: 'user',
|
|
107
108
|
initial: 'idle',
|
|
108
109
|
states: {
|
|
109
110
|
idle: {
|
|
110
111
|
on: {
|
|
111
|
-
|
|
112
|
-
target: '
|
|
112
|
+
CHECK: {
|
|
113
|
+
target: 'checking',
|
|
113
114
|
},
|
|
114
115
|
},
|
|
115
116
|
},
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
target: '
|
|
121
|
-
actions: send({ type: 'FETCH_USER_INFO' }),
|
|
122
|
-
},
|
|
123
|
-
onError: {
|
|
124
|
-
target: 'idle',
|
|
117
|
+
checking: {
|
|
118
|
+
always: [
|
|
119
|
+
{ target: 'inline', cond: 'isInline' },
|
|
120
|
+
{
|
|
121
|
+
target: 'normal',
|
|
125
122
|
},
|
|
126
|
-
|
|
123
|
+
],
|
|
127
124
|
},
|
|
125
|
+
inline: {},
|
|
126
|
+
normal: {},
|
|
128
127
|
},
|
|
128
|
+
// states: {
|
|
129
|
+
// idle: {
|
|
130
|
+
// on: {
|
|
131
|
+
// UPDATE_USER_INFO: {
|
|
132
|
+
// target: 'updatingUserInfo',
|
|
133
|
+
// },
|
|
134
|
+
// },
|
|
135
|
+
// },
|
|
136
|
+
// updatingUserInfo: {
|
|
137
|
+
// invoke: {
|
|
138
|
+
// src: 'updateUserInfo',
|
|
139
|
+
// onDone: {
|
|
140
|
+
// target: 'idle',
|
|
141
|
+
// actions: send({ type: 'FETCH_USER_INFO' }),
|
|
142
|
+
// },
|
|
143
|
+
// onError: {
|
|
144
|
+
// target: 'idle',
|
|
145
|
+
// },
|
|
146
|
+
// },
|
|
147
|
+
// },
|
|
148
|
+
// },
|
|
129
149
|
},
|
|
130
150
|
},
|
|
131
151
|
on: {
|
|
@@ -164,6 +184,10 @@ export default function (request) {
|
|
|
164
184
|
const { bank_account, bank_setting_status } = context.userInfo || {}
|
|
165
185
|
return !!bank_account || bank_setting_status === 1
|
|
166
186
|
},
|
|
187
|
+
isInline: (context, event) => {
|
|
188
|
+
console.log(context.userInfo?.rank, context.userInfo?.rank >= 0)
|
|
189
|
+
return context.userInfo?.rank >= 0
|
|
190
|
+
},
|
|
167
191
|
},
|
|
168
192
|
actions: {
|
|
169
193
|
fetchToken: assign((context, event) => {
|
|
@@ -236,8 +260,8 @@ export default function (request) {
|
|
|
236
260
|
fetchUserInfo: async (context, event) => {
|
|
237
261
|
return await request.send(user.getUserInfo())
|
|
238
262
|
},
|
|
239
|
-
|
|
240
|
-
return await request.send(user.
|
|
263
|
+
updateUserInfo: async (context, event) => {
|
|
264
|
+
return await request.send(user.updateUserInfo(event.data))
|
|
241
265
|
},
|
|
242
266
|
},
|
|
243
267
|
}
|
package/src/machine/auth_otp.js
CHANGED
|
@@ -174,7 +174,7 @@ export default function (request) {
|
|
|
174
174
|
},
|
|
175
175
|
sendPhone: async (context, event) => {
|
|
176
176
|
const { countryCode, phone } = context
|
|
177
|
-
return await request.send(api.
|
|
177
|
+
return await request.send(api.updateUserInfo({ countryCode, phone }))
|
|
178
178
|
},
|
|
179
179
|
resetOtp: async (context, event) => {
|
|
180
180
|
const { requestId, number } = context
|
package/src/machine/check.js
CHANGED
|
@@ -71,9 +71,9 @@ export default function (request) {
|
|
|
71
71
|
return context.userInfo?.rank >= 0
|
|
72
72
|
},
|
|
73
73
|
isInquiryIncomplete: (context, event) => {
|
|
74
|
-
const { bank_account, bank_setting_status } = context.userInfo || {}
|
|
74
|
+
const { bank_account, bank_setting_status, uid } = context.userInfo || {}
|
|
75
75
|
const hasBankAccount = bank_account || bank_setting_status === 1
|
|
76
|
-
return !hasBankAccount && !cookies.get(
|
|
76
|
+
return !hasBankAccount && !cookies.get(`welcome_${uid}`)
|
|
77
77
|
},
|
|
78
78
|
isInquiryFilled: (context, event) => {
|
|
79
79
|
const { bonus, gender } = context
|
|
@@ -87,7 +87,7 @@ export default function (request) {
|
|
|
87
87
|
}
|
|
88
88
|
}),
|
|
89
89
|
setInfo: (context, event) => {
|
|
90
|
-
cookies.set(
|
|
90
|
+
cookies.set(`welcome_${context.userInfo.uid}`, 'done', {
|
|
91
91
|
path: '/',
|
|
92
92
|
maxAge: 60 * 60 * 24 * 365,
|
|
93
93
|
})
|
|
@@ -104,7 +104,7 @@ export default function (request) {
|
|
|
104
104
|
const { bonus, gender } = context
|
|
105
105
|
await Promise.all([
|
|
106
106
|
request.send(payment.setBonusSetting({ bonus })),
|
|
107
|
-
request.send(user.
|
|
107
|
+
request.send(user.updateUserInfo({ gender })),
|
|
108
108
|
])
|
|
109
109
|
},
|
|
110
110
|
},
|
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/index.js
CHANGED
|
@@ -15,6 +15,7 @@ import reward from './reward'
|
|
|
15
15
|
import setting from './setting'
|
|
16
16
|
import side from './side'
|
|
17
17
|
import withdraw from './withdraw'
|
|
18
|
+
import user_info from './user_info'
|
|
18
19
|
|
|
19
20
|
export default {
|
|
20
21
|
...activity,
|
|
@@ -34,4 +35,5 @@ export default {
|
|
|
34
35
|
setting,
|
|
35
36
|
side,
|
|
36
37
|
withdraw,
|
|
38
|
+
user_info,
|
|
37
39
|
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { assign, createMachine } from 'xstate'
|
|
2
|
+
import user from '../api/user'
|
|
3
|
+
|
|
4
|
+
export default function (request) {
|
|
5
|
+
return createMachine(
|
|
6
|
+
{
|
|
7
|
+
id: 'user_info',
|
|
8
|
+
initial: 'fetching',
|
|
9
|
+
context: {
|
|
10
|
+
userInfo: {},
|
|
11
|
+
},
|
|
12
|
+
states: {
|
|
13
|
+
fetching: {
|
|
14
|
+
invoke: {
|
|
15
|
+
src: 'fetchUserInfo',
|
|
16
|
+
onDone: {
|
|
17
|
+
target: 'idle',
|
|
18
|
+
actions: 'setUserInfo',
|
|
19
|
+
},
|
|
20
|
+
onError: {
|
|
21
|
+
target: 'idle',
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
idle: {
|
|
26
|
+
on: {
|
|
27
|
+
UPDATE_USER_INFO: {
|
|
28
|
+
target: 'updating',
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
updating: {
|
|
33
|
+
invoke: {
|
|
34
|
+
src: 'updateUserInfo',
|
|
35
|
+
onDone: {
|
|
36
|
+
target: 'idle',
|
|
37
|
+
// target: 'fetching', // 因為更新 userInfo 後 get self 還是拿到舊資料
|
|
38
|
+
},
|
|
39
|
+
onError: {
|
|
40
|
+
target: 'idle',
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
actions: {
|
|
48
|
+
setUserInfo: assign((context, event) => {
|
|
49
|
+
return {
|
|
50
|
+
userInfo: event.data,
|
|
51
|
+
}
|
|
52
|
+
}),
|
|
53
|
+
},
|
|
54
|
+
services: {
|
|
55
|
+
fetchUserInfo: async (context, event) => {
|
|
56
|
+
return await request.send(user.getUserInfo())
|
|
57
|
+
},
|
|
58
|
+
updateUserInfo: async (context, event) => {
|
|
59
|
+
return await request.send(user.updateUserInfo(event.data))
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
}
|
|
63
|
+
)
|
|
64
|
+
}
|
package/src/machine/withdraw.js
CHANGED
|
@@ -13,7 +13,7 @@ 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,
|
|
@@ -36,7 +36,7 @@ export default function (request) {
|
|
|
36
36
|
},
|
|
37
37
|
preparing: {
|
|
38
38
|
invoke: {
|
|
39
|
-
src: '
|
|
39
|
+
src: 'fetchPaymentConfig',
|
|
40
40
|
onDone: {
|
|
41
41
|
target: 'mode',
|
|
42
42
|
actions: 'setCrypto',
|
|
@@ -221,7 +221,7 @@ export default function (request) {
|
|
|
221
221
|
const lastMatchedIndex = findLastIndex(rules, (rule) => balance >= rule.greaterEqualThen)
|
|
222
222
|
|
|
223
223
|
let distance = 0,
|
|
224
|
-
limit,
|
|
224
|
+
limit = 0,
|
|
225
225
|
amount = 0
|
|
226
226
|
if (lastMatchedIndex > -1) {
|
|
227
227
|
rules[lastMatchedIndex].match = true
|
|
@@ -235,9 +235,11 @@ export default function (request) {
|
|
|
235
235
|
} else {
|
|
236
236
|
distance = diff
|
|
237
237
|
}
|
|
238
|
-
} else {
|
|
238
|
+
} else if (rules.length > 0) {
|
|
239
239
|
limit = rules[0]?.greaterEqualThen || 0
|
|
240
240
|
distance = Math.max(limit - balance, 0)
|
|
241
|
+
} else {
|
|
242
|
+
amount = balance
|
|
241
243
|
}
|
|
242
244
|
return {
|
|
243
245
|
withdrawDistance: distance,
|
|
@@ -253,9 +255,16 @@ export default function (request) {
|
|
|
253
255
|
}
|
|
254
256
|
}),
|
|
255
257
|
setCrypto: assign((context, event) => {
|
|
258
|
+
const method = event.data?.[0]
|
|
256
259
|
return {
|
|
257
|
-
crypto:
|
|
258
|
-
networks:
|
|
260
|
+
crypto: method,
|
|
261
|
+
networks:
|
|
262
|
+
method?.optional.map((value, i) => {
|
|
263
|
+
return {
|
|
264
|
+
label: method?.originalItem?.[i],
|
|
265
|
+
value,
|
|
266
|
+
}
|
|
267
|
+
}) || [],
|
|
259
268
|
}
|
|
260
269
|
}),
|
|
261
270
|
setNetwork: assign((context, event) => {
|
|
@@ -322,7 +331,7 @@ export default function (request) {
|
|
|
322
331
|
fetchWithdrawRules: async (context, event) => {
|
|
323
332
|
return await request.send(api.getCurrentWithdrawRule())
|
|
324
333
|
},
|
|
325
|
-
|
|
334
|
+
fetchPaymentConfig: async (context, event) => {
|
|
326
335
|
return await request.send(api.getPaymentDetail({ transferType: 'WITHDRAW' }))
|
|
327
336
|
},
|
|
328
337
|
submitWithdraw: async (context, event) => {
|
|
@@ -333,7 +342,7 @@ export default function (request) {
|
|
|
333
342
|
method,
|
|
334
343
|
amount: withdrawAmount,
|
|
335
344
|
cryptoCurrency: crypto.channel,
|
|
336
|
-
cryptoNetwork: currentNetwork,
|
|
345
|
+
cryptoNetwork: currentNetwork.value,
|
|
337
346
|
targetAddress: currentAddress,
|
|
338
347
|
})
|
|
339
348
|
)
|
|
@@ -343,7 +352,7 @@ export default function (request) {
|
|
|
343
352
|
return await request.send(
|
|
344
353
|
api.convertFreeCredit({
|
|
345
354
|
exchangeType: 1,
|
|
346
|
-
cryptoNetwork: currentNetwork,
|
|
355
|
+
cryptoNetwork: currentNetwork.value,
|
|
347
356
|
targetAddress: currentAddress,
|
|
348
357
|
})
|
|
349
358
|
)
|
|
@@ -355,7 +364,7 @@ export default function (request) {
|
|
|
355
364
|
api.getWithdrawExpectedResult({
|
|
356
365
|
method,
|
|
357
366
|
amount: withdrawAmount,
|
|
358
|
-
cryptoNetwork: currentNetwork,
|
|
367
|
+
cryptoNetwork: currentNetwork.value,
|
|
359
368
|
})
|
|
360
369
|
)
|
|
361
370
|
},
|