@jetthai/cuora 1.1.182-krw → 1.1.182-krw-1

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,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.182-krw-1](https://github.com/jetthai/cuora-module/compare/v1.1.182-krw...v1.1.182-krw-1) (2023-09-27)
6
+
5
7
  ### [1.1.182-krw](https://github.com/jetthai/cuora-module/compare/v1.1.182...v1.1.182-krw) (2023-09-26)
6
8
 
7
9
  ### [1.1.182](https://github.com/jetthai/cuora-module/compare/v1.1.181...v1.1.182) (2023-09-21)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jetthai/cuora",
3
- "version": "1.1.182-krw",
3
+ "version": "1.1.182-krw-1",
4
4
  "description": "",
5
5
  "main": "./src/index.js",
6
6
  "type": "module",
@@ -210,6 +210,10 @@ export default function (request) {
210
210
  LOGIN_GUEST: {
211
211
  target: '.authenticationGuest',
212
212
  },
213
+ LOGIN_ID: {
214
+ target: '.authentication',
215
+ actions: ['setReCaptchaToken', 'setLoginId'],
216
+ },
213
217
  LOGIN_PHONE: {
214
218
  target: '.authentication',
215
219
  actions: ['setReCaptchaToken', 'setLoginPhone'],
@@ -264,6 +268,16 @@ export default function (request) {
264
268
  reCaptchaToken,
265
269
  }
266
270
  }),
271
+ setLoginId: assign((context, event) => {
272
+ const { username, password } = event.data
273
+ return {
274
+ loginData: {
275
+ provider: 'local',
276
+ username,
277
+ password,
278
+ },
279
+ }
280
+ }),
267
281
  setLoginPhone: assign((context, event) => {
268
282
  const { countryCode, countryAbbr, phone, password } = event.data
269
283
  return {
@@ -8,6 +8,7 @@ import direct from './direct.js'
8
8
  import amb from './amb.js'
9
9
  import float from './float.js'
10
10
  import vpay from './vpay.js'
11
+ import krway from './krway.js'
11
12
  import usdt from './usdt.js'
12
13
  import manual_cash from './manual_cash.js'
13
14
  import qrcode_cash from './qrcode_cash.js'
@@ -34,6 +35,7 @@ export default {
34
35
  float,
35
36
  vpay,
36
37
  usdt,
38
+ krway,
37
39
  manual_cash,
38
40
  qrcode_cash,
39
41
  usdt_cash,
@@ -0,0 +1,124 @@
1
+ import { assign, createMachine } from 'xstate'
2
+ import payment from '@jetthai/cuora/src/api/payment.js'
3
+
4
+ export default function (request) {
5
+ return createMachine(
6
+ {
7
+ id: 'krway',
8
+ initial: 'loading',
9
+ context: {
10
+ currentCategory: 'krway',
11
+ paymentDetail: [],
12
+ currentPayment: null,
13
+ options: null,
14
+ amount: null,
15
+ },
16
+ states: {
17
+ loading: {
18
+ invoke: {
19
+ src: 'fetchPaymentDetail',
20
+ onDone: {
21
+ target: 'idle',
22
+ actions: 'setInitData',
23
+ },
24
+ onError: {
25
+ target: 'fail',
26
+ },
27
+ },
28
+ },
29
+ idle: {},
30
+ searching: {
31
+ invoke: {
32
+ src: 'searchAccount',
33
+ onDone: {
34
+ target: 'searched',
35
+ },
36
+ onError: {
37
+ target: 'fail',
38
+ },
39
+ },
40
+ },
41
+ searched: {
42
+ after: {
43
+ 0: {
44
+ target: 'idle',
45
+ },
46
+ },
47
+ },
48
+ submitting: {
49
+ invoke: {
50
+ src: 'submitDeposit',
51
+ onDone: {
52
+ target: 'idle',
53
+ },
54
+ onError: {
55
+ target: 'fail',
56
+ },
57
+ },
58
+ },
59
+ submitted: {},
60
+ fail: {},
61
+ },
62
+ on: {
63
+ SEARCHING_ACCOUNT: {
64
+ target: 'searching',
65
+ },
66
+ ADD_AMOUNT: {
67
+ actions: 'addAmount',
68
+ },
69
+ SET_AMOUNT: {
70
+ actions: 'setAmount',
71
+ },
72
+ CLEAR_AMOUNT: {
73
+ actions: 'clearAmount',
74
+ },
75
+ SUBMIT: {
76
+ target: 'submitting',
77
+ },
78
+ },
79
+ },
80
+ {
81
+ actions: {
82
+ setInitData: assign((context, event) => {
83
+ const paymentDetail = event.data
84
+ const payments = paymentDetail.filter((item) => item.category === context.currentCategory)
85
+ const currentPayment = payments[0]
86
+ const options = currentPayment.optional
87
+
88
+ return {
89
+ currentPayment,
90
+ options,
91
+ }
92
+ }),
93
+ addAmount: assign((context, event) => {
94
+ return {
95
+ amount: parseFloat(`${context.amount || 0}`) + parseFloat(`${event.data}`),
96
+ }
97
+ }),
98
+ setAmount: assign((context, event) => {
99
+ return { amount: parseFloat(`${event.data}`) }
100
+ }),
101
+ clearAmount: assign((context, event) => {
102
+ return { amount: null }
103
+ }),
104
+ },
105
+ services: {
106
+ fetchPaymentDetail: async (context, event) => {
107
+ return await request.send(payment.getPaymentDetail({ transferType: 'DEPOSIT' }))
108
+ },
109
+ searchAccount: async (context, event) => {
110
+ return await request.send(payment.searchAccount())
111
+ },
112
+ submitDeposit: async (context, event) => {
113
+ const { currentPayment, amount } = context
114
+ return await request.send(
115
+ payment.submitDepositTransaction({
116
+ method: currentPayment.method,
117
+ amount,
118
+ })
119
+ )
120
+ },
121
+ },
122
+ }
123
+ )
124
+ }
@@ -75,11 +75,11 @@ export default function (request) {
75
75
  return { fc }
76
76
  }),
77
77
  setSignUpId: assign((context, event) => {
78
- const { account, password, channel, subchannel, bankCode, bankAccount, holderName, branch, branchCode, affiliateCode } = event.data
78
+ const { username, password, channel, subchannel, bankCode, bankAccount, holderName, branch, branchCode, affiliateCode } = event.data
79
79
  return {
80
80
  signUpData: {
81
81
  provider: 'local',
82
- account,
82
+ username,
83
83
  password,
84
84
  bankCode,
85
85
  bankAccount,
@@ -4,6 +4,7 @@ import withdraw_vn2 from './withdraw_vn2.js'
4
4
  import withdraw_crypto from './withdraw_crypto.js'
5
5
  import withdraw_crypto2 from './withdraw_crypto2.js'
6
6
  import withdraw_amb from './withdraw_amb.js'
7
+ import withdraw_krway from './withdraw_krway.js'
7
8
  import withdraw_crypto_cash from './withdraw_crypto_cash.js'
8
9
  import withdraw_manual_cash from './withdraw_manual_cash.js'
9
10
 
@@ -14,6 +15,7 @@ export default {
14
15
  withdraw_crypto,
15
16
  withdraw_crypto2,
16
17
  withdraw_amb,
18
+ withdraw_krway,
17
19
  withdraw_crypto_cash,
18
20
  withdraw_manual_cash,
19
21
  }
@@ -0,0 +1,515 @@
1
+ import { assign, createMachine } from 'xstate'
2
+ import findLastIndex from 'lodash/findLastIndex.js'
3
+ import payment from '../../api/payment.js'
4
+ import user from '../../api/user.js'
5
+
6
+ export default function (request) {
7
+ const { appSecret } = request.config
8
+ return createMachine(
9
+ {
10
+ id: 'withdraw_vn2',
11
+ initial: 'loading',
12
+ context: {
13
+ mode: null,
14
+ siteConfig: null,
15
+ balance: null,
16
+ charge: null,
17
+ realAmount: null,
18
+ applyId: null,
19
+ methods: [],
20
+ paymentDetail: [],
21
+ bankInfo: [],
22
+ bankList: [],
23
+ currentWithdrawLimit: null,
24
+ targetWithdrawLimit: null,
25
+ attachmentType: null, // null | 'withdraw' | 'pool'
26
+ enableWithdrawAmount: 0,
27
+ enableWithdraw: false,
28
+ withdrawRules: [],
29
+ withdrawRule: {},
30
+
31
+ amount: null,
32
+ bank: null,
33
+ branch: null,
34
+ holderName: null,
35
+
36
+ // otp
37
+ requestId: null,
38
+ status: null,
39
+ target: null,
40
+ ttl: null,
41
+ },
42
+ states: {
43
+ loading: {
44
+ invoke: {
45
+ src: 'fetchInitData',
46
+ onDone: {
47
+ target: 'pending',
48
+ actions: ['setInitData', 'preset'],
49
+ },
50
+ onError: {
51
+ target: 'fail',
52
+ },
53
+ },
54
+ },
55
+ pending: {
56
+ on: {
57
+ SET_MODE: {
58
+ target: 'fetching',
59
+ actions: 'setMode',
60
+ },
61
+ },
62
+ },
63
+ fetching: {
64
+ invoke: {
65
+ src: 'fetchWithdrawRules',
66
+ onDone: {
67
+ target: 'mode',
68
+ actions: 'updateWithdrawCondition',
69
+ },
70
+ onError: {
71
+ target: '#withdraw_vn2.fail',
72
+ },
73
+ },
74
+ },
75
+ mode: {
76
+ always: [{ target: 'activity', cond: 'isActivity' }, { target: 'cash' }],
77
+ },
78
+ activity: {
79
+ initial: 'checking',
80
+ states: {
81
+ checking: {
82
+ always: [{ target: 'convertible', cond: 'isConvertible' }, { target: 'notConvertible' }],
83
+ },
84
+ notConvertible: {
85
+ on: {
86
+ GIVE_UP: {
87
+ target: 'fetchWithdrawRule',
88
+ },
89
+ },
90
+ },
91
+ fetchWithdrawRule: {
92
+ invoke: {
93
+ src: 'fetchWithdrawRulePreview',
94
+ onDone: {
95
+ target: 'giveUp',
96
+ actions: 'setWithdrawRulePreview',
97
+ },
98
+ onError: {
99
+ target: 'notConvertible',
100
+ },
101
+ },
102
+ },
103
+ giveUp: {
104
+ on: {
105
+ CONFIRM: {
106
+ target: 'givingUp',
107
+ },
108
+ BACK: {
109
+ target: 'notConvertible',
110
+ },
111
+ },
112
+ },
113
+ givingUp: {
114
+ invoke: {
115
+ src: 'giveUp',
116
+ onDone: {
117
+ target: 'gaveUp',
118
+ },
119
+ onError: {
120
+ target: 'convertible',
121
+ },
122
+ },
123
+ },
124
+ gaveUp: {},
125
+ convertible: {
126
+ on: {
127
+ SUBMIT: {
128
+ target: 'converting',
129
+ actions: 'setAttachmentType',
130
+ },
131
+ },
132
+ },
133
+ converting: {
134
+ invoke: {
135
+ src: 'convertFreeCredit',
136
+ onDone: [
137
+ {
138
+ target: '#withdraw_vn2.otp',
139
+ actions: 'setOtp',
140
+ cond: 'isOtpRequired',
141
+ },
142
+ { target: 'converted' },
143
+ ],
144
+ onError: {
145
+ target: 'convertible',
146
+ },
147
+ },
148
+ },
149
+ converted: {
150
+ always: [
151
+ { target: '#withdraw_vn2.cash.unbound', cond: 'isBankNotBound' },
152
+ { target: '#withdraw_vn2.cash.withdrawable', cond: 'hasAttachmentType' },
153
+ ],
154
+ },
155
+ },
156
+ },
157
+ cash: {
158
+ initial: 'checking',
159
+ states: {
160
+ checking: {
161
+ always: [
162
+ { target: 'inProcessing', cond: 'haveProcessing' },
163
+ { target: 'notWithdrawable', cond: 'isNotWithdrawable' },
164
+ { target: 'unbound', cond: 'isBankNotBound' },
165
+ { target: 'withdrawable' },
166
+ ],
167
+ },
168
+ notWithdrawable: {},
169
+ unbound: {
170
+ // to bank_binding.js
171
+ },
172
+ inProcessing: {},
173
+ withdrawable: {
174
+ on: {
175
+ SET_CURRENT_BANK: {
176
+ actions: assign((context, event) => {
177
+ return {
178
+ bank: event.data,
179
+ }
180
+ }),
181
+ },
182
+ SET_AMOUNT: {
183
+ actions: assign((context, event) => {
184
+ return {
185
+ amount: event.data,
186
+ }
187
+ }),
188
+ },
189
+ SET_ATTACHMENT_TYPE: {
190
+ actions: 'setAttachmentType',
191
+ },
192
+ SUBMIT: [
193
+ {
194
+ target: 'pooling',
195
+ cond: (context, event) => {
196
+ const { amount, attachmentType } = context
197
+ return attachmentType === 'pool' && amount > 0
198
+ },
199
+ },
200
+ {
201
+ target: 'submitting',
202
+ cond: 'isSubmittable',
203
+ },
204
+ ],
205
+ },
206
+ },
207
+ submitting: {
208
+ invoke: {
209
+ src: 'submitWithdraw',
210
+ onDone: [
211
+ {
212
+ target: '#withdraw_vn2.otp',
213
+ actions: 'setOtp',
214
+ cond: 'isOtpRequired',
215
+ },
216
+ {
217
+ target: 'submitted',
218
+ },
219
+ ],
220
+ onError: {
221
+ target: 'withdrawable',
222
+ },
223
+ },
224
+ },
225
+ submitted: {
226
+ entry: assign((context, event) => {
227
+ const { applyId, balance, realAmount, charge } = event.data
228
+ return { applyId, balance, realAmount, charge }
229
+ }),
230
+ invoke: {
231
+ src: 'fetchPaymentData',
232
+ onDone: {
233
+ target: 'inProcessing',
234
+ actions: 'setPaymentData',
235
+ },
236
+ onError: {
237
+ target: '#withdraw_vn2.fail',
238
+ },
239
+ },
240
+ },
241
+ pooling: {
242
+ invoke: {
243
+ src: 'pool',
244
+ onDone: { target: 'pooled' },
245
+ onError: {
246
+ target: 'withdrawable',
247
+ },
248
+ },
249
+ },
250
+ pooled: {},
251
+ },
252
+ },
253
+ otp: {
254
+ type: 'parallel',
255
+ states: {
256
+ countdown: {
257
+ after: {
258
+ 1000: {
259
+ target: 'countdown',
260
+ actions: 'decreaseTtl',
261
+ cond: (context) => context.ttl > 0,
262
+ },
263
+ },
264
+ },
265
+ verification: {
266
+ initial: 'idle',
267
+ states: {
268
+ idle: {
269
+ on: {
270
+ ACKNOWLEDGE: {
271
+ target: 'acknowledging',
272
+ },
273
+ RESET_OTP: {
274
+ target: 'reset',
275
+ },
276
+ BACK: [
277
+ {
278
+ target: '#withdraw_vn2.activity.convertible',
279
+ cond: 'isActivity',
280
+ },
281
+ {
282
+ target: '#withdraw_vn2.cash.withdrawable',
283
+ },
284
+ ],
285
+ },
286
+ },
287
+ acknowledging: {
288
+ invoke: {
289
+ src: 'acknowledge',
290
+ onDone: [
291
+ {
292
+ target: '#withdraw_vn2.activity.converted',
293
+ cond: 'isActivity',
294
+ },
295
+ {
296
+ target: '#withdraw_vn2.cash.submitted',
297
+ },
298
+ ],
299
+ onError: {
300
+ target: 'idle',
301
+ },
302
+ },
303
+ },
304
+ reset: {
305
+ invoke: {
306
+ src: 'resetOtp',
307
+ onDone: {
308
+ target: 'idle',
309
+ actions: 'setVerificationData',
310
+ },
311
+ onError: { target: 'idle' },
312
+ },
313
+ },
314
+ },
315
+ },
316
+ },
317
+ },
318
+ fail: {},
319
+ },
320
+ on: {
321
+ REFRESH: {
322
+ target: 'loading',
323
+ },
324
+ },
325
+ },
326
+ {
327
+ actions: {
328
+ setInitData: assign((context, event) => {
329
+ const { paymentDetail, bankInfo, bonus, bankList } = event.data
330
+ return {
331
+ paymentDetail,
332
+ bankInfo,
333
+ bank: bankInfo[0],
334
+ bonus,
335
+ bankList,
336
+ }
337
+ }),
338
+ preset: assign((context, event) => {
339
+ const { siteConfig } = context
340
+ const methods = siteConfig?.paymentMethods?.withdraw || []
341
+ return {
342
+ methods,
343
+ attachmentType: siteConfig.walletMode > 0 ? 'withdraw' : null,
344
+ }
345
+ }),
346
+ setMode: assign((context, event) => {
347
+ return {
348
+ mode: event.data,
349
+ }
350
+ }),
351
+ updateWithdrawCondition: assign((context, event) => {
352
+ const { enableWithdraw, enableWithdrawAmount, currentWithdrawLimit, targetWithdrawLimit, balance } = event.data
353
+ const withdrawRules = event.data?.rules || []
354
+ const rules = withdrawRules.filter((rule) => rule.maxWithdrawAmount > 0)
355
+ const lastMatchedIndex = findLastIndex(rules, (rule) => balance >= rule.greaterEqualThen)
356
+
357
+ let maxWithdrawAmount = 0
358
+
359
+ if (lastMatchedIndex > -1) {
360
+ rules[lastMatchedIndex].match = true
361
+ maxWithdrawAmount = rules[lastMatchedIndex].maxWithdrawAmount
362
+ } else if (rules.length > 0) {
363
+ maxWithdrawAmount = rules[0].maxWithdrawAmount
364
+ } else {
365
+ maxWithdrawAmount = balance
366
+ }
367
+
368
+ return {
369
+ balance,
370
+ currentWithdrawLimit,
371
+ targetWithdrawLimit,
372
+ maxWithdrawAmount,
373
+ enableWithdrawAmount: +enableWithdrawAmount,
374
+ enableWithdraw,
375
+ withdrawRules,
376
+ }
377
+ }),
378
+ setWithdrawRulePreview: assign((context, event) => {
379
+ return {
380
+ withdrawRule: event.data,
381
+ }
382
+ }),
383
+ setPaymentData: assign((context, event) => {
384
+ const { bankInfo, bonus, paymentDetail } = event.data
385
+ return {
386
+ bankInfo,
387
+ bonus,
388
+ paymentDetail,
389
+ }
390
+ }),
391
+ setOtp: assign((context, event) => {
392
+ const { requestId, status, target, ttl } = event.data
393
+ return {
394
+ requestId,
395
+ status,
396
+ target,
397
+ ttl,
398
+ }
399
+ }),
400
+ decreaseTtl: assign((context, evnet) => {
401
+ const second = context.ttl
402
+ return {
403
+ ttl: Math.max(second - 1, 0),
404
+ }
405
+ }),
406
+ setVerificationData: assign((context, event) => {
407
+ const { requestId, ttl, target } = event.data
408
+ return {
409
+ requestId,
410
+ ttl,
411
+ target,
412
+ }
413
+ }),
414
+ setAttachmentType: assign((context, event) => {
415
+ return {
416
+ attachmentType: event.data,
417
+ }
418
+ }),
419
+ },
420
+ guards: {
421
+ isActivity: (context, event) => {
422
+ return context.mode === 'ACTIVITY'
423
+ },
424
+ hasAttachmentType: (context, event) => {
425
+ return ['withdraw', 'pool'].includes(context.attachmentType)
426
+ },
427
+ haveProcessing: (context, event) => {
428
+ return (context.paymentDetail?.[0]?.processing || []).length > 0
429
+ },
430
+ isBankNotBound: (context, event) => {
431
+ return !context.bankInfo?.length
432
+ },
433
+ isSubmittable: (context, event) => {
434
+ const { bank, amount } = context
435
+ return bank && amount > 0
436
+ },
437
+ isConvertible: (context, event) => {
438
+ const { balance, enableWithdraw } = context
439
+ return balance > 0 && enableWithdraw
440
+ },
441
+ isNotWithdrawable: (context, event) => {
442
+ const { balance, enableWithdraw, paymentDetail } = context
443
+ const minWithdrawAmount = paymentDetail[0]?.minimum || 0
444
+ return !enableWithdraw || balance < minWithdrawAmount
445
+ },
446
+ isOtpRequired: (context, event) => {
447
+ return event.data?.status === 'otp-verifying'
448
+ },
449
+ },
450
+ services: {
451
+ fetchInitData: async (context, event) => {
452
+ const [paymentDetail = [], { bonus, bankInfo }] = await Promise.all([
453
+ request.send(payment.getPaymentDetail({ transferType: 'WITHDRAW' })),
454
+ request.send(payment.getPaymentInfo()),
455
+ ])
456
+ const bankList = await request.send(payment.getWithdrawBankList())
457
+ const newBankInfo = bankInfo
458
+ .map((item) => {
459
+ const matchedBank = bankList.find((bank) => bank.bankCode === item.bankCode)
460
+ return matchedBank ? { ...item, ...matchedBank } : null
461
+ })
462
+ .filter(Boolean)
463
+ return { paymentDetail, bonus, bankInfo: newBankInfo, bankList }
464
+ },
465
+ fetchPaymentData: async (context, event) => {
466
+ const paymentDetail = await request.send(payment.getPaymentDetail({ transferType: 'WITHDRAW' }))
467
+ const { bonus, bankInfo } = await request.send(payment.getPaymentInfo())
468
+ return { bonus, bankInfo, paymentDetail }
469
+ },
470
+ fetchWithdrawRules: async (context, event) => {
471
+ const { mode } = context
472
+ return await request.send(payment.getDoubleWalletWithdrawRule({ walletType: mode }))
473
+ },
474
+ fetchWithdrawRulePreview: async (context, event) => {
475
+ const data = await request.send(payment.getWithdrawRulePreview({ applyType: 'giveup' }))
476
+ return data
477
+ },
478
+ submitWithdraw: async (context, event) => {
479
+ const { bank, amount } = context
480
+ const { method } = context.paymentDetail[0]
481
+ const branchTemp = ['GCASH', 'PAYM', 'PIX'].includes(bank.bankCode) ? '' : bank.branch
482
+ return await request.send(
483
+ payment.submitWithdrawTransactionVN({
484
+ method,
485
+ amount,
486
+ applyerBankCode: bank.bankCode,
487
+ applyerAccountNumber: bank.accountNumber,
488
+ branch: branchTemp,
489
+ holderName: bank.holderName,
490
+ })
491
+ )
492
+ },
493
+ convertFreeCredit: async (context, event) => {
494
+ return await request.send(payment.convertFreeCredit({ exchangeType: 1 }))
495
+ },
496
+ resetOtp: async (context, event) => {
497
+ const { requestId, target } = context
498
+ return await request.send(user.otpReset({ requestId, target }))
499
+ },
500
+ acknowledge: async (context, event) => {
501
+ const { requestId, target } = context
502
+ const code = event.data
503
+ return await request.send(user.otpAcknowledge({ requestId, target, code }))
504
+ },
505
+ pool: async (context, event) => {
506
+ const { amount } = context
507
+ return await request.send(payment.restore({ amount }))
508
+ },
509
+ giveUp: async (context, event) => {
510
+ return await request.send(payment.giveUp())
511
+ },
512
+ },
513
+ }
514
+ )
515
+ }