@jetthai/cuora 1.1.6 → 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.6",
3
+ "version": "1.1.7",
4
4
  "description": "",
5
5
  "main": "./src/index.js",
6
6
  "type": "module",
@@ -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
  )