@jetthai/cuora 1.1.5 → 1.1.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jetthai/cuora",
3
- "version": "1.1.5",
3
+ "version": "1.1.7",
4
4
  "description": "",
5
5
  "main": "./src/index.js",
6
6
  "type": "module",
@@ -119,7 +119,7 @@ export default function (request) {
119
119
  states: {
120
120
  idle: {
121
121
  on: {
122
- SEND_OTP: {
122
+ ACKNOWLEDGE: {
123
123
  target: 'acknowledging',
124
124
  },
125
125
  RESET_OTP: {
@@ -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
- target: 'converted',
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
- actions: 'setResult',
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
  )
@@ -4,8 +4,6 @@ import payment from '../api/payment.js'
4
4
  import common from '../api/common.js'
5
5
  import user from '../api/user.js'
6
6
 
7
- // const findLastIndex = require('lodash/findLastIndex')
8
-
9
7
  export default function (request) {
10
8
  const { appSecret } = request.config
11
9
  return createMachine(
@@ -34,6 +32,12 @@ export default function (request) {
34
32
 
35
33
  withdrawDistance: null,
36
34
  withdrawAmount: 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,14 @@ export default function (request) {
80
84
  converting: {
81
85
  invoke: {
82
86
  src: 'submitWithdrawFree',
83
- onDone: {
84
- target: 'converted',
85
- },
87
+ onDone: [
88
+ {
89
+ target: '#withdraw_vn.otp',
90
+ actions: 'setOtp',
91
+ cond: 'isOtpRequired',
92
+ },
93
+ { target: 'converted' },
94
+ ],
86
95
  onError: {
87
96
  target: 'convertible',
88
97
  },
@@ -132,9 +141,16 @@ export default function (request) {
132
141
  submitting: {
133
142
  invoke: {
134
143
  src: 'submitWithdraw',
135
- onDone: {
136
- target: 'submitted',
137
- },
144
+ onDone: [
145
+ {
146
+ target: '#withdraw_vn.otp',
147
+ actions: 'setOtp',
148
+ cond: 'isOtpRequired',
149
+ },
150
+ {
151
+ target: 'submitted',
152
+ },
153
+ ],
138
154
  onError: {
139
155
  target: 'withdrawable',
140
156
  },
@@ -148,6 +164,7 @@ export default function (request) {
148
164
  invoke: {
149
165
  src: 'fetchPaymentData',
150
166
  onDone: {
167
+ target: 'inProcessing',
151
168
  actions: 'setPaymentData',
152
169
  },
153
170
  onError: {
@@ -157,6 +174,71 @@ export default function (request) {
157
174
  },
158
175
  },
159
176
  },
177
+ otp: {
178
+ type: 'parallel',
179
+ states: {
180
+ countdown: {
181
+ after: {
182
+ 1000: {
183
+ target: 'countdown',
184
+ actions: 'decreaseTtl',
185
+ cond: (context) => context.ttl > 0,
186
+ },
187
+ },
188
+ },
189
+ verification: {
190
+ initial: 'idle',
191
+ states: {
192
+ idle: {
193
+ on: {
194
+ ACKNOWLEDGE: {
195
+ target: 'acknowledging',
196
+ },
197
+ RESET_OTP: {
198
+ target: 'reset',
199
+ },
200
+ BACK: [
201
+ {
202
+ target: '#withdraw_vn.free.convertible',
203
+ cond: 'isFree',
204
+ },
205
+ {
206
+ target: '#withdraw_vn.cash.withdrawable',
207
+ },
208
+ ],
209
+ },
210
+ },
211
+ acknowledging: {
212
+ invoke: {
213
+ src: 'acknowledge',
214
+ onDone: [
215
+ {
216
+ target: '#withdraw_vn.free.converted',
217
+ cond: 'isFree',
218
+ },
219
+ {
220
+ target: '#withdraw_vn.cash.submitted',
221
+ },
222
+ ],
223
+ onError: {
224
+ target: 'idle',
225
+ },
226
+ },
227
+ },
228
+ reset: {
229
+ invoke: {
230
+ src: 'resetOtp',
231
+ onDone: {
232
+ target: 'idle',
233
+ actions: 'setVerificationData',
234
+ },
235
+ onError: { target: 'idle' },
236
+ },
237
+ },
238
+ },
239
+ },
240
+ },
241
+ },
160
242
  fail: {},
161
243
  },
162
244
  on: {
@@ -223,6 +305,29 @@ export default function (request) {
223
305
  availableWithdrawAmount,
224
306
  }
225
307
  }),
308
+ setOtp: assign((context, event) => {
309
+ const { requestId, status, target, ttl } = event.data
310
+ return {
311
+ requestId,
312
+ status,
313
+ target,
314
+ ttl,
315
+ }
316
+ }),
317
+ decreaseTtl: assign((context, evnet) => {
318
+ const second = context.ttl
319
+ return {
320
+ ttl: Math.max(second - 1, 0),
321
+ }
322
+ }),
323
+ setVerificationData: assign((context, event) => {
324
+ const { requestId, ttl, target } = event.data
325
+ return {
326
+ requestId,
327
+ ttl,
328
+ target,
329
+ }
330
+ }),
226
331
  },
227
332
  guards: {
228
333
  isFree: (context, event) => {
@@ -252,6 +357,9 @@ export default function (request) {
252
357
  const minWithdrawAmount = paymentDetail[0]?.minimum || 0
253
358
  return withdrawLimit !== 0 || balance < minWithdrawAmount
254
359
  },
360
+ isOtpRequired: (context, event) => {
361
+ return event.data?.status === 'otp-verifying'
362
+ },
255
363
  },
256
364
  services: {
257
365
  fetchInitData: async (context, event) => {
@@ -299,6 +407,15 @@ export default function (request) {
299
407
  submitWithdrawFree: async (context, event) => {
300
408
  return await request.send(payment.convertFreeCredit({ exchangeType: 1 }))
301
409
  },
410
+ resetOtp: async (context, event) => {
411
+ const { requestId, target } = context
412
+ return await request.send(user.otpReset({ requestId, target }))
413
+ },
414
+ acknowledge: async (context, event) => {
415
+ const { requestId, target } = context
416
+ const code = event.data
417
+ return await request.send(user.otpAcknowledge({ requestId, target, code }))
418
+ },
302
419
  },
303
420
  }
304
421
  )
@@ -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
- }