@jetthai/cuora 1.0.65 → 1.0.66

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.0.66](https://github.com/jetthai/cuora-module/compare/v1.0.65...v1.0.66) (2021-12-24)
6
+
5
7
  ### [1.0.65](https://github.com/jetthai/cuora-module/compare/v1.0.64...v1.0.65) (2021-12-22)
6
8
 
7
9
  ### [1.0.64](https://github.com/jetthai/cuora-module/compare/v1.0.63...v1.0.64) (2021-12-22)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jetthai/cuora",
3
- "version": "1.0.65",
3
+ "version": "1.0.66",
4
4
  "description": "",
5
5
  "main": "./src/index.js",
6
6
  "scripts": {
package/src/api/index.js CHANGED
@@ -1,10 +1,10 @@
1
1
  import activity from './activity'
2
2
  import auth from './auth'
3
- import core from './common'
3
+ import common from './common'
4
4
  import game from './game'
5
5
  import mailbox from './mailbox'
6
6
  import payment from './payment'
7
7
  import user from './user'
8
8
  import form from './form'
9
9
 
10
- export default { activity, auth, core, game, mailbox, payment, user, form }
10
+ export default { activity, auth, common, game, mailbox, payment, user, form }
@@ -4,10 +4,10 @@ export default {
4
4
  getSpotMarket: () => ({ url: 'payment/spotmarket', method: 'get' }),
5
5
  // getPaymentInfo: () => ({ url: `payment/paymentInfo`, method: 'get' }),
6
6
  getPaymentInfo: () => ({ url: `payment/v2/paymentInfo`, method: 'get' }),
7
- updatePaymentInfo: ({ bankCode, bankAccount, firstNameTh, lastNameTh, firstNameEn, lastNameEn, bonus, paymentProvider }) => ({
7
+ updatePaymentInfo: ({ bankCode, branch, holderName, bankAccount, firstNameTh, lastNameTh, firstNameEn, lastNameEn, bonus, paymentProvider }) => ({
8
8
  url: 'payment/v2/updatePaymentInfo',
9
9
  method: 'post',
10
- params: { bankCode, bankAccount, firstNameTh, lastNameTh, firstNameEn, lastNameEn, bonus, paymentProvider },
10
+ params: { bankCode, branch, holderName, bankAccount, firstNameTh, lastNameTh, firstNameEn, lastNameEn, bonus, paymentProvider },
11
11
  }),
12
12
  getBankList: (paymentMethod) => ({ url: `payment/v2/${paymentMethod}/getBankList`, method: 'get' }),
13
13
  makeTransaction: ({ type, payload, paymentMethod }) => ({
@@ -52,4 +52,9 @@ export default {
52
52
  method: 'post',
53
53
  params: { transferType: 'WITHDRAW', amount, cryptoCurrency, cryptoNetwork, targetAddress },
54
54
  }),
55
+ submitWithdrawTransactionVN: ({ method, amount, applyerBankCode, applyerAccountNumber, branch, holderName }) => ({
56
+ url: `payment/v2/${method}/transaction`,
57
+ method: 'post',
58
+ params: { transferType: 'WITHDRAW', amount, applyerBankCode, applyerAccountNumber, branch, holderName },
59
+ }),
55
60
  }
@@ -0,0 +1,119 @@
1
+ import { assign, createMachine } from 'xstate'
2
+ import payment from '../api/payment'
3
+
4
+ export default function (request) {
5
+ return createMachine(
6
+ {
7
+ id: 'bank_binding',
8
+ initial: 'fetching',
9
+ context: {
10
+ bankList: [],
11
+ bank: null,
12
+ branch: null,
13
+ accountNumber: null,
14
+ holderName: null,
15
+ },
16
+ states: {
17
+ fetching: {
18
+ invoke: {
19
+ src: 'fetchBanks',
20
+ onDone: {
21
+ target: 'idle',
22
+ actions: ['setBanks', 'setDefaultBank'],
23
+ },
24
+ onError: {
25
+ target: 'idle',
26
+ },
27
+ },
28
+ },
29
+ idle: {
30
+ on: {
31
+ SET_BANK_CODE: {
32
+ actions: assign((context, event) => {
33
+ return {
34
+ bank: event.data,
35
+ }
36
+ }),
37
+ },
38
+ SET_BRANCH: {
39
+ actions: assign((context, event) => {
40
+ return {
41
+ branch: event.data,
42
+ }
43
+ }),
44
+ },
45
+ SET_ACCOUNT_NUMBER: {
46
+ actions: assign((context, event) => {
47
+ return {
48
+ accountNumber: event.data,
49
+ }
50
+ }),
51
+ },
52
+ SET_HOLDER_NAME: {
53
+ actions: assign((context, event) => {
54
+ return {
55
+ holderName: event.data,
56
+ }
57
+ }),
58
+ },
59
+ BIND_BANK: {
60
+ target: 'binding',
61
+ cond: 'isBindable',
62
+ },
63
+ },
64
+ },
65
+ binding: {
66
+ invoke: {
67
+ src: 'updatePaymentInfo',
68
+ onDone: {
69
+ target: 'bound',
70
+ },
71
+ onError: {
72
+ target: 'idle',
73
+ },
74
+ },
75
+ },
76
+ bound: {},
77
+ },
78
+ },
79
+ {
80
+ actions: {
81
+ setBanks: assign((context, event) => {
82
+ return {
83
+ bankList: event.data,
84
+ bank: event.data[0],
85
+ }
86
+ }),
87
+ setDefaultBank: assign((context, event) => {
88
+ return {
89
+ bank: event.data[0],
90
+ }
91
+ }),
92
+ },
93
+ guards: {
94
+ isBindable: (context, event) => {
95
+ const { bank, accountNumber, branch, holderName } = context
96
+ return bank.bankCode && accountNumber && branch && holderName
97
+ },
98
+ },
99
+ services: {
100
+ fetchBanks: async (context, event) => {
101
+ const paymentDetail = await request.send(payment.getPaymentDetail({ transferType: 'WITHDRAW' }))
102
+ const method = paymentDetail.find((payment) => payment.methodType === 'manual').method
103
+ return await request.send(payment.getBankList(method))
104
+ },
105
+ updatePaymentInfo: async (context, event) => {
106
+ const { bank, branch, accountNumber, holderName } = context
107
+ return await request.send(
108
+ payment.updatePaymentInfo({
109
+ bankCode: bank.bankCode,
110
+ branch,
111
+ bankAccount: accountNumber,
112
+ holderName,
113
+ })
114
+ )
115
+ },
116
+ },
117
+ }
118
+ )
119
+ }
@@ -19,6 +19,8 @@ import withdraw from './withdraw'
19
19
  import user_info from './user_info'
20
20
  import user_sign_up from './user_sign_up'
21
21
  import user_reset_password from './user_reset_password'
22
+ import bank_binding from './bank_binding'
23
+ import withdraw_vn from './withdraw_vn'
22
24
 
23
25
  export default {
24
26
  ...activity,
@@ -42,4 +44,6 @@ export default {
42
44
  user_info,
43
45
  user_sign_up,
44
46
  user_reset_password,
47
+ bank_binding,
48
+ withdraw_vn,
45
49
  }
@@ -0,0 +1,318 @@
1
+ import { assign, createMachine } from 'xstate'
2
+ import findLastIndex from 'lodash/findLastIndex'
3
+ import payment from '../api/payment'
4
+ import common from '../api/common'
5
+ import user from '../api/user'
6
+
7
+ // todo - noBind -> unbound
8
+ // todo - withdrawLimit, targetWithdrawLimit 轉為正數
9
+ // todo - mod -> mode
10
+ // todo - adjust updateWithdrawCondition
11
+
12
+ export default function (request) {
13
+ const { appSecret } = request.config
14
+ return createMachine(
15
+ {
16
+ id: 'withdraw_vn',
17
+ initial: 'loading',
18
+ context: {
19
+ siteConfig: null,
20
+ userInfo: null,
21
+ balance: null,
22
+ charge: null,
23
+ realAmount: null,
24
+ applyId: null,
25
+ methods: [],
26
+ paymentDetail: [],
27
+ bankInfo: [],
28
+ bankList: [],
29
+ withdrawLimit: null,
30
+ targetWithdrawLimit: null,
31
+
32
+ bank: null,
33
+ branch: null,
34
+ accountNumber: null,
35
+ holderName: null,
36
+
37
+ withdrawDistance: null,
38
+ withdrawAmount: null,
39
+ },
40
+ states: {
41
+ loading: {
42
+ invoke: {
43
+ src: 'fetchInitData',
44
+ onDone: {
45
+ target: 'mode',
46
+ actions: ['setSiteConfig', 'setUserInfo', 'setData', 'preset'],
47
+ },
48
+ onError: {
49
+ target: 'fail',
50
+ },
51
+ },
52
+ },
53
+ mode: {
54
+ always: [{ target: 'free', cond: 'isFree' }, { target: 'cash' }],
55
+ },
56
+ free: {
57
+ initial: 'loading',
58
+ states: {
59
+ loading: {
60
+ invoke: {
61
+ src: 'fetchWithdrawRules',
62
+ onDone: {
63
+ target: 'checking',
64
+ actions: 'updateWithdrawCondition',
65
+ },
66
+ onError: {
67
+ target: 'notConvertible',
68
+ },
69
+ },
70
+ },
71
+ checking: {
72
+ always: [{ target: 'convertible', cond: 'isConvertible' }, { target: 'notConvertible' }],
73
+ },
74
+ notConvertible: {},
75
+ convertible: {
76
+ on: {
77
+ SUBMIT: {
78
+ target: 'converting',
79
+ },
80
+ },
81
+ },
82
+ converting: {
83
+ invoke: {
84
+ src: 'submitWithdrawFree',
85
+ onDone: {
86
+ target: 'converted',
87
+ },
88
+ onError: {
89
+ target: 'convertible',
90
+ },
91
+ },
92
+ },
93
+ converted: {},
94
+ },
95
+ },
96
+ cash: {
97
+ initial: 'checking',
98
+ states: {
99
+ checking: {
100
+ always: [
101
+ { target: 'inProcessing', cond: 'haveProcessing' },
102
+ { target: 'notWithdrawable', cond: 'isNotWithdrawable' },
103
+ { target: 'unbound', cond: 'isBankNotBound' },
104
+ { target: 'withdrawable' },
105
+ ],
106
+ },
107
+ notWithdrawable: {},
108
+ unbound: {
109
+ // to bank_binding.js
110
+ },
111
+ inProcessing: {},
112
+ withdrawable: {
113
+ on: {
114
+ SUBMIT: {
115
+ target: 'submitting',
116
+ cond: 'isSubmittable',
117
+ },
118
+ },
119
+ },
120
+ submitting: {
121
+ invoke: {
122
+ src: 'submitWithdraw',
123
+ onDone: {
124
+ target: 'submitted',
125
+ },
126
+ onError: {
127
+ target: 'withdrawable',
128
+ },
129
+ },
130
+ },
131
+ submitted: {
132
+ entry: assign((context, event) => {
133
+ const { applyId, balance, realAmount, charge } = event.data
134
+ return { applyId, balance, realAmount, charge }
135
+ }),
136
+ invoke: {
137
+ src: 'fetchPaymentData',
138
+ onDone: {
139
+ actions: 'setPaymentData',
140
+ },
141
+ onError: {
142
+ target: '#withdraw_vn.fail',
143
+ },
144
+ },
145
+ },
146
+ },
147
+ },
148
+ fail: {},
149
+ },
150
+ on: {
151
+ REFRESH: {
152
+ target: 'loading',
153
+ },
154
+ SET_CURRENT_BANK: {
155
+ actions: assign((context, event) => {
156
+ return {
157
+ bank: event.data,
158
+ }
159
+ }),
160
+ },
161
+ SET_AMOUNT: {
162
+ actions: assign((context, event) => {
163
+ return {
164
+ amount: event.data,
165
+ }
166
+ }),
167
+ },
168
+ },
169
+ },
170
+ {
171
+ actions: {
172
+ setData: assign((context, event) => {
173
+ return {
174
+ paymentDetail: event.data.paymentDetail,
175
+ bankInfo: event.data.bankInfo,
176
+ bonus: event.data.bonus,
177
+ bankList: event.data.bankList,
178
+ }
179
+ }),
180
+ setPaymentData: assign((context, event) => {
181
+ return {
182
+ bankInfo: event.data.bankInfo,
183
+ bonus: event.data.bonus,
184
+ paymentDetail: event.data.paymentDetail,
185
+ }
186
+ }),
187
+ setUserInfo: assign((context, event) => {
188
+ return {
189
+ userInfo: event.data.userInfo,
190
+ }
191
+ }),
192
+ setSiteConfig: assign((context, event) => {
193
+ return {
194
+ siteConfig: event.data.siteConfig,
195
+ }
196
+ }),
197
+ preset: assign((context, event) => {
198
+ const { userInfo, siteConfig } = event.data
199
+ const { withdraw_limit, target_withdraw_limit } = userInfo || {}
200
+ const balance = parseFloat(userInfo?.balance)
201
+ const methods = siteConfig?.paymentMethods?.withdraw || []
202
+ return {
203
+ withdrawLimit: Math.abs(withdraw_limit),
204
+ targetWithdrawLimit: Math.abs(target_withdraw_limit),
205
+ methods,
206
+ balance,
207
+ }
208
+ }),
209
+ updateWithdrawCondition: assign((context, event) => {
210
+ const rules = event.data.rules.filter((rule) => rule.maxWithdrawAmount > 0)
211
+
212
+ const { balance, withdrawLimit } = context
213
+ const lastMatchedIndex = findLastIndex(rules, (rule) => balance >= rule.greaterEqualThen)
214
+
215
+ let maxWithdrawAmount = 0,
216
+ availableWithdrawAmount = 0
217
+
218
+ if (lastMatchedIndex > -1) {
219
+ rules[lastMatchedIndex].match = true
220
+ maxWithdrawAmount = rules[lastMatchedIndex].maxWithdrawAmount
221
+
222
+ if (withdrawLimit === 0) {
223
+ availableWithdrawAmount = Math.min(balance, maxWithdrawAmount)
224
+ }
225
+ } else if (rules.length > 0) {
226
+ maxWithdrawAmount = rules[0].maxWithdrawAmount
227
+ } else {
228
+ maxWithdrawAmount = balance
229
+ }
230
+
231
+ return {
232
+ maxWithdrawAmount,
233
+ availableWithdrawAmount,
234
+ }
235
+ }),
236
+ },
237
+ guards: {
238
+ isFree: (context, event) => {
239
+ return context.userInfo?.withdraw_rule !== 'DEFAULT'
240
+ },
241
+ haveProcessing: (context, event) => {
242
+ return context.paymentDetail[0] && context.paymentDetail[0].processing.length > 0
243
+ },
244
+ otherPlace: (context, event) => {
245
+ return context.otherPlace
246
+ },
247
+ isWithdrawDisable: (context, event) => {
248
+ const { siteConfig } = context
249
+ const methods = siteConfig?.paymentMethods?.withdraw || []
250
+ return methods.length === 0
251
+ },
252
+ isBankNotBound: (context, event) => {
253
+ return !context.bankInfo?.length
254
+ },
255
+ isBindable: (context, event) => {
256
+ const { bank, accountNumber, branch, holderName } = context
257
+ return bank.bankCode && accountNumber && branch && holderName
258
+ },
259
+ isSubmittable: (context, event) => {
260
+ const { applyerBankCode, applyerAccountNumber, branch, holderName, amount } = event.data
261
+ return applyerBankCode, applyerAccountNumber, branch, holderName, amount
262
+ },
263
+ isConvertible: (context, event) => {
264
+ const { balance, withdrawLimit } = context
265
+ return balance > 0 && withdrawLimit === 0
266
+ },
267
+ isNotWithdrawable: (context, event) => {
268
+ const { balance, withdrawLimit, paymentDetail } = context
269
+ const minWithdrawAmount = paymentDetail[0]?.minimum || 0
270
+ return withdrawLimit !== 0 || balance < minWithdrawAmount
271
+ },
272
+ },
273
+ services: {
274
+ fetchInitData: async (context, event) => {
275
+ const [{ config }, userInfo, paymentDetail = [], { bonus, bankInfo }] = await Promise.all([
276
+ request.send(common.getConfig({ appSecret })),
277
+ request.send(user.getUserInfo()),
278
+ request.send(payment.getPaymentDetail({ transferType: 'WITHDRAW' })),
279
+ request.send(payment.getPaymentInfo()),
280
+ ])
281
+ const siteConfig = JSON.parse(window.atob(config))
282
+ const method = paymentDetail.find((payment) => payment.methodType === 'manual').method
283
+ const bankList = await request.send(payment.getBankList(method))
284
+ return { siteConfig, userInfo, paymentDetail, bonus, bankInfo, bankList }
285
+ },
286
+ fetchPaymentData: async (context, event) => {
287
+ const paymentDetail = await request.send(payment.getPaymentDetail({ transferType: 'WITHDRAW' }))
288
+ const { bonus, bankInfo } = await request.send(payment.getPaymentInfo())
289
+ return { bonus, bankInfo, paymentDetail }
290
+ },
291
+ updatePaymentInfo: async (context, event) => {
292
+ const { bank, branch, accountNumber, holderName } = context
293
+ return await request.send(
294
+ payment.updatePaymentInfo({
295
+ bankCode: bank.bankCode,
296
+ branch,
297
+ bankAccount: accountNumber,
298
+ holderName,
299
+ })
300
+ )
301
+ },
302
+ fetchWithdrawRules: async (context, event) => {
303
+ return await request.send(payment.getCurrentWithdrawRule())
304
+ },
305
+ submitWithdraw: async (context, event) => {
306
+ const { amount, applyerBankCode, applyerAccountNumber, branch, holderName } = event.data
307
+ const { method } = context.paymentDetail[0]
308
+ return await request.send(
309
+ payment.submitWithdrawTransactionVN({ method, amount, applyerBankCode, applyerAccountNumber, branch, holderName })
310
+ )
311
+ },
312
+ submitWithdrawFree: async (context, event) => {
313
+ return await request.send(payment.convertFreeCredit({ exchangeType: 1 }))
314
+ },
315
+ },
316
+ }
317
+ )
318
+ }