@jetthai/cuora 1.1.5 → 1.1.6
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 +2 -0
- package/package.json +1 -1
- package/src/machine/auth_otp_v3.js +1 -1
- package/src/machine/index.js +0 -2
- package/src/machine/withdraw_crypto.js +113 -8
- package/src/machine/auth_otp.js +0 -201
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
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.6](https://github.com/jetthai/cuora-module/compare/v1.1.5...v1.1.6) (2022-12-06)
|
|
6
|
+
|
|
5
7
|
### [1.1.5](https://github.com/jetthai/cuora-module/compare/v1.1.4...v1.1.5) (2022-12-02)
|
|
6
8
|
|
|
7
9
|
### [1.1.4](https://github.com/jetthai/cuora-module/compare/v1.1.3...v1.1.4) (2022-12-01)
|
package/package.json
CHANGED
package/src/machine/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import activity from './activity/index.js'
|
|
2
2
|
import auth from './auth.js'
|
|
3
|
-
import auth_otp from './auth_otp.js'
|
|
4
3
|
import welcome from './welcome.js'
|
|
5
4
|
import common from './common.js'
|
|
6
5
|
import error from './error.js'
|
|
@@ -36,7 +35,6 @@ import vip_table from './vip_table.js'
|
|
|
36
35
|
export default {
|
|
37
36
|
...activity,
|
|
38
37
|
auth,
|
|
39
|
-
auth_otp,
|
|
40
38
|
welcome,
|
|
41
39
|
common,
|
|
42
40
|
deposit,
|
|
@@ -5,8 +5,6 @@ import common from '../api/common.js'
|
|
|
5
5
|
import user from '../api/user.js'
|
|
6
6
|
import api from '../api/payment.js'
|
|
7
7
|
|
|
8
|
-
// const findLastIndex = require('lodash/findLastIndex')
|
|
9
|
-
|
|
10
8
|
export default function (request) {
|
|
11
9
|
const { appSecret } = request.config
|
|
12
10
|
return createMachine(
|
|
@@ -34,6 +32,12 @@ export default function (request) {
|
|
|
34
32
|
|
|
35
33
|
charge: null,
|
|
36
34
|
realAmount: null,
|
|
35
|
+
|
|
36
|
+
// otp
|
|
37
|
+
requestId: null,
|
|
38
|
+
status: null,
|
|
39
|
+
target: null,
|
|
40
|
+
ttl: null,
|
|
37
41
|
},
|
|
38
42
|
states: {
|
|
39
43
|
loading: {
|
|
@@ -80,9 +84,13 @@ export default function (request) {
|
|
|
80
84
|
converting: {
|
|
81
85
|
invoke: {
|
|
82
86
|
src: 'submitWithdrawFree',
|
|
83
|
-
onDone: {
|
|
84
|
-
|
|
85
|
-
|
|
87
|
+
onDone: [{
|
|
88
|
+
target: '#withdraw_crypto.otp',
|
|
89
|
+
actions: 'setOtp',
|
|
90
|
+
cond: 'isOtpRequired'
|
|
91
|
+
}, {
|
|
92
|
+
target: 'converted',
|
|
93
|
+
}],
|
|
86
94
|
onError: {
|
|
87
95
|
target: 'convertible',
|
|
88
96
|
},
|
|
@@ -150,10 +158,13 @@ export default function (request) {
|
|
|
150
158
|
submitting: {
|
|
151
159
|
invoke: {
|
|
152
160
|
src: 'submitWithdraw',
|
|
153
|
-
onDone: {
|
|
161
|
+
onDone: [{
|
|
162
|
+
target: '#withdraw_crypto.otp',
|
|
163
|
+
actions: 'setOtp',
|
|
164
|
+
cond: 'isOtpRequired'
|
|
165
|
+
}, {
|
|
154
166
|
target: 'submitted',
|
|
155
|
-
|
|
156
|
-
},
|
|
167
|
+
}],
|
|
157
168
|
onError: {
|
|
158
169
|
target: 'withdrawable',
|
|
159
170
|
},
|
|
@@ -162,6 +173,65 @@ export default function (request) {
|
|
|
162
173
|
submitted: {},
|
|
163
174
|
},
|
|
164
175
|
},
|
|
176
|
+
otp: {
|
|
177
|
+
type: 'parallel',
|
|
178
|
+
states: {
|
|
179
|
+
countdown: {
|
|
180
|
+
after: {
|
|
181
|
+
1000: {
|
|
182
|
+
target: 'countdown',
|
|
183
|
+
actions: 'decreaseTtl',
|
|
184
|
+
cond: (context) => context.ttl > 0,
|
|
185
|
+
},
|
|
186
|
+
},
|
|
187
|
+
},
|
|
188
|
+
verification: {
|
|
189
|
+
initial: 'idle',
|
|
190
|
+
states: {
|
|
191
|
+
idle: {
|
|
192
|
+
on: {
|
|
193
|
+
ACKNOWLEDGE: {
|
|
194
|
+
target: 'acknowledging',
|
|
195
|
+
},
|
|
196
|
+
RESET_OTP: {
|
|
197
|
+
target: 'reset',
|
|
198
|
+
},
|
|
199
|
+
BACK: [{
|
|
200
|
+
target: '#withdraw_crypto.free.convertible',
|
|
201
|
+
cond: 'isFree'
|
|
202
|
+
}, {
|
|
203
|
+
target: '#withdraw_crypto.cash.submittable',
|
|
204
|
+
}],
|
|
205
|
+
},
|
|
206
|
+
},
|
|
207
|
+
acknowledging: {
|
|
208
|
+
invoke: {
|
|
209
|
+
src: 'acknowledge',
|
|
210
|
+
onDone: [{
|
|
211
|
+
target: '#withdraw_crypto.free.converted',
|
|
212
|
+
cond: 'isFree'
|
|
213
|
+
}, {
|
|
214
|
+
target: '#withdraw_crypto.cash.submitted',
|
|
215
|
+
}],
|
|
216
|
+
onError: {
|
|
217
|
+
target: 'idle',
|
|
218
|
+
},
|
|
219
|
+
},
|
|
220
|
+
},
|
|
221
|
+
reset: {
|
|
222
|
+
invoke: {
|
|
223
|
+
src: 'resetOtp',
|
|
224
|
+
onDone: {
|
|
225
|
+
target: 'idle',
|
|
226
|
+
actions: 'setVerificationData',
|
|
227
|
+
},
|
|
228
|
+
onError: { target: 'idle' },
|
|
229
|
+
},
|
|
230
|
+
},
|
|
231
|
+
},
|
|
232
|
+
},
|
|
233
|
+
},
|
|
234
|
+
},
|
|
165
235
|
fail: {},
|
|
166
236
|
},
|
|
167
237
|
on: {
|
|
@@ -264,6 +334,29 @@ export default function (request) {
|
|
|
264
334
|
realAmount,
|
|
265
335
|
}
|
|
266
336
|
}),
|
|
337
|
+
setOtp: assign((context, event) => {
|
|
338
|
+
const { requestId, status, target, ttl } = event.data
|
|
339
|
+
return {
|
|
340
|
+
requestId,
|
|
341
|
+
status,
|
|
342
|
+
target,
|
|
343
|
+
ttl,
|
|
344
|
+
}
|
|
345
|
+
}),
|
|
346
|
+
decreaseTtl: assign((context, evnet) => {
|
|
347
|
+
const second = context.ttl
|
|
348
|
+
return {
|
|
349
|
+
ttl: Math.max(second - 1, 0),
|
|
350
|
+
}
|
|
351
|
+
}),
|
|
352
|
+
setVerificationData: assign((context, event) => {
|
|
353
|
+
const { requestId, ttl, target } = event.data
|
|
354
|
+
return {
|
|
355
|
+
requestId,
|
|
356
|
+
ttl,
|
|
357
|
+
target,
|
|
358
|
+
}
|
|
359
|
+
}),
|
|
267
360
|
},
|
|
268
361
|
guards: {
|
|
269
362
|
isFree: (context, event) => {
|
|
@@ -294,6 +387,9 @@ export default function (request) {
|
|
|
294
387
|
const { selectedNetwork, amount } = context
|
|
295
388
|
return selectedNetwork && amount
|
|
296
389
|
},
|
|
390
|
+
isOtpRequired: (context, event) => {
|
|
391
|
+
return event.data?.status === 'otp-verifying'
|
|
392
|
+
}
|
|
297
393
|
},
|
|
298
394
|
services: {
|
|
299
395
|
fetchInitData: async (context, event) => {
|
|
@@ -338,6 +434,15 @@ export default function (request) {
|
|
|
338
434
|
})
|
|
339
435
|
)
|
|
340
436
|
},
|
|
437
|
+
resetOtp: async (context, event) => {
|
|
438
|
+
const { requestId, target } = context
|
|
439
|
+
return await request.send(user.otpReset({ requestId, target }))
|
|
440
|
+
},
|
|
441
|
+
acknowledge: async (context, event) => {
|
|
442
|
+
const { requestId, target } = context
|
|
443
|
+
const code = event.data
|
|
444
|
+
return await request.send(user.otpAcknowledge({ requestId, target, code }))
|
|
445
|
+
},
|
|
341
446
|
},
|
|
342
447
|
}
|
|
343
448
|
)
|
package/src/machine/auth_otp.js
DELETED
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
import { assign, createMachine } from 'xstate'
|
|
2
|
-
import api from '../api/user.js'
|
|
3
|
-
|
|
4
|
-
export default function (request) {
|
|
5
|
-
return createMachine(
|
|
6
|
-
{
|
|
7
|
-
id: 'auth_otp',
|
|
8
|
-
initial: 'fetching',
|
|
9
|
-
context: {
|
|
10
|
-
userInfo: null,
|
|
11
|
-
error: null,
|
|
12
|
-
countryCode: null,
|
|
13
|
-
phone: null,
|
|
14
|
-
number: null,
|
|
15
|
-
requestId: null,
|
|
16
|
-
ttl: 0,
|
|
17
|
-
},
|
|
18
|
-
states: {
|
|
19
|
-
fetching: {
|
|
20
|
-
invoke: {
|
|
21
|
-
src: 'fetchUserInfo',
|
|
22
|
-
onDone: {
|
|
23
|
-
target: 'checking',
|
|
24
|
-
actions: 'setUserInfo',
|
|
25
|
-
},
|
|
26
|
-
onError: {
|
|
27
|
-
target: 'fail',
|
|
28
|
-
},
|
|
29
|
-
},
|
|
30
|
-
},
|
|
31
|
-
checking: {
|
|
32
|
-
always: [
|
|
33
|
-
{ target: 'verified', cond: 'isVerified' },
|
|
34
|
-
{ target: 'notVerified', cond: 'isNotVerified' },
|
|
35
|
-
],
|
|
36
|
-
},
|
|
37
|
-
notVerified: {
|
|
38
|
-
initial: 'checkingStatus',
|
|
39
|
-
states: {
|
|
40
|
-
checkingStatus: {
|
|
41
|
-
invoke: {
|
|
42
|
-
src: 'verify',
|
|
43
|
-
onDone: {
|
|
44
|
-
target: 'otp',
|
|
45
|
-
actions: 'setVerificationData',
|
|
46
|
-
},
|
|
47
|
-
onError: {
|
|
48
|
-
target: 'errorChecking',
|
|
49
|
-
actions: 'setError',
|
|
50
|
-
},
|
|
51
|
-
},
|
|
52
|
-
},
|
|
53
|
-
errorChecking: {
|
|
54
|
-
always: [{ target: 'phone', cond: 'hasNoPhone' }, { target: '#auth_otp.fail' }],
|
|
55
|
-
},
|
|
56
|
-
phone: {
|
|
57
|
-
on: {
|
|
58
|
-
SEND_PHONE: {
|
|
59
|
-
target: 'sendingPhone',
|
|
60
|
-
actions: 'setPhone',
|
|
61
|
-
},
|
|
62
|
-
},
|
|
63
|
-
},
|
|
64
|
-
sendingPhone: {
|
|
65
|
-
invoke: {
|
|
66
|
-
src: 'sendPhone',
|
|
67
|
-
onDone: {
|
|
68
|
-
target: 'checkingStatus',
|
|
69
|
-
},
|
|
70
|
-
onError: { target: 'phone' },
|
|
71
|
-
},
|
|
72
|
-
},
|
|
73
|
-
otp: {
|
|
74
|
-
type: 'parallel',
|
|
75
|
-
states: {
|
|
76
|
-
countdown: {
|
|
77
|
-
after: {
|
|
78
|
-
1000: {
|
|
79
|
-
target: 'countdown',
|
|
80
|
-
actions: 'decreaseTtl',
|
|
81
|
-
cond: (context) => context.ttl > 0,
|
|
82
|
-
},
|
|
83
|
-
},
|
|
84
|
-
},
|
|
85
|
-
verification: {
|
|
86
|
-
initial: 'idle',
|
|
87
|
-
states: {
|
|
88
|
-
idle: {
|
|
89
|
-
on: {
|
|
90
|
-
SEND_OTP: {
|
|
91
|
-
target: 'acknowledging',
|
|
92
|
-
},
|
|
93
|
-
RESET_OTP: {
|
|
94
|
-
target: 'reset',
|
|
95
|
-
},
|
|
96
|
-
RESEND_PHONE: {
|
|
97
|
-
target: '#auth_otp.notVerified.phone',
|
|
98
|
-
},
|
|
99
|
-
},
|
|
100
|
-
},
|
|
101
|
-
acknowledging: {
|
|
102
|
-
invoke: {
|
|
103
|
-
src: 'acknowledge',
|
|
104
|
-
onDone: {
|
|
105
|
-
target: '#auth_otp.verified',
|
|
106
|
-
},
|
|
107
|
-
onError: {
|
|
108
|
-
target: 'idle',
|
|
109
|
-
},
|
|
110
|
-
},
|
|
111
|
-
},
|
|
112
|
-
reset: {
|
|
113
|
-
invoke: {
|
|
114
|
-
src: 'resetOtp',
|
|
115
|
-
onDone: {
|
|
116
|
-
target: 'idle',
|
|
117
|
-
actions: 'setVerificationData',
|
|
118
|
-
},
|
|
119
|
-
onError: { target: 'idle' },
|
|
120
|
-
},
|
|
121
|
-
},
|
|
122
|
-
},
|
|
123
|
-
},
|
|
124
|
-
},
|
|
125
|
-
},
|
|
126
|
-
},
|
|
127
|
-
},
|
|
128
|
-
verified: {},
|
|
129
|
-
fail: {},
|
|
130
|
-
},
|
|
131
|
-
},
|
|
132
|
-
{
|
|
133
|
-
actions: {
|
|
134
|
-
setUserInfo: assign((context, event) => {
|
|
135
|
-
return {
|
|
136
|
-
userInfo: event.data,
|
|
137
|
-
}
|
|
138
|
-
}),
|
|
139
|
-
setVerificationData: assign((context, event) => {
|
|
140
|
-
const { number, requestId, ttl } = event.data
|
|
141
|
-
return {
|
|
142
|
-
number,
|
|
143
|
-
requestId,
|
|
144
|
-
ttl,
|
|
145
|
-
}
|
|
146
|
-
}),
|
|
147
|
-
decreaseTtl: assign((context, evnet) => {
|
|
148
|
-
const ms = context.ttl
|
|
149
|
-
return {
|
|
150
|
-
ttl: Math.max(ms - 1000, 0),
|
|
151
|
-
}
|
|
152
|
-
}),
|
|
153
|
-
setError: assign((context, event) => {
|
|
154
|
-
return {
|
|
155
|
-
error: event.data,
|
|
156
|
-
}
|
|
157
|
-
}),
|
|
158
|
-
setPhone: assign((context, event) => {
|
|
159
|
-
const { countryCode, phone } = event.data
|
|
160
|
-
return {
|
|
161
|
-
countryCode,
|
|
162
|
-
phone,
|
|
163
|
-
}
|
|
164
|
-
}),
|
|
165
|
-
},
|
|
166
|
-
guards: {
|
|
167
|
-
isVerified: (context, event) => {
|
|
168
|
-
return context.userInfo?.verification_status === 1
|
|
169
|
-
},
|
|
170
|
-
isNotVerified: (context, event) => {
|
|
171
|
-
return context.userInfo && context.userInfo.verification_status !== 1
|
|
172
|
-
},
|
|
173
|
-
hasNoPhone: (context, event) => {
|
|
174
|
-
const { error } = context
|
|
175
|
-
return error.code === 'ERR_F106'
|
|
176
|
-
},
|
|
177
|
-
},
|
|
178
|
-
services: {
|
|
179
|
-
fetchUserInfo: async (context, event) => {
|
|
180
|
-
return await request.send(api.getUserInfo())
|
|
181
|
-
},
|
|
182
|
-
verify: async (context, event) => {
|
|
183
|
-
return await request.send(api.verify())
|
|
184
|
-
},
|
|
185
|
-
sendPhone: async (context, event) => {
|
|
186
|
-
const { countryCode, phone } = context
|
|
187
|
-
return await request.send(api.updateUserInfo({ countryCode, phone }))
|
|
188
|
-
},
|
|
189
|
-
resetOtp: async (context, event) => {
|
|
190
|
-
const { requestId, number } = context
|
|
191
|
-
return await request.send(api.resetOtp({ requestId, number }))
|
|
192
|
-
},
|
|
193
|
-
acknowledge: async (context, event) => {
|
|
194
|
-
const { requestId } = context
|
|
195
|
-
const code = event.data
|
|
196
|
-
return await request.send(api.acknowledge({ requestId, code }))
|
|
197
|
-
},
|
|
198
|
-
},
|
|
199
|
-
}
|
|
200
|
-
)
|
|
201
|
-
}
|