@jetthai/cuora 1.1.270-fix-8 → 1.1.270-jackpot-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,23 +2,7 @@
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.270-fix-8](https://github.com/jetthai/cuora-module/compare/v1.1.270-fix-7...v1.1.270-fix-8) (2024-06-15)
6
-
7
- ### [1.1.270-fix-7](https://github.com/jetthai/cuora-module/compare/v1.1.270-fix-6...v1.1.270-fix-7) (2024-06-14)
8
-
9
- ### [1.1.270-fix-6](https://github.com/jetthai/cuora-module/compare/v1.1.270-fix-5...v1.1.270-fix-6) (2024-06-05)
10
-
11
- ### [1.1.270-fix-5](https://github.com/jetthai/cuora-module/compare/v1.1.270-fix-4...v1.1.270-fix-5) (2024-06-05)
12
-
13
- ### [1.1.270-fix-4](https://github.com/jetthai/cuora-module/compare/v1.1.270-fix-3...v1.1.270-fix-4) (2024-06-04)
14
-
15
- ### [1.1.270-fix-3](https://github.com/jetthai/cuora-module/compare/v1.1.270-fix-2...v1.1.270-fix-3) (2024-06-04)
16
-
17
- ### [1.1.270-fix-2](https://github.com/jetthai/cuora-module/compare/v1.1.270-fix-1...v1.1.270-fix-2) (2024-06-03)
18
-
19
- ### [1.1.270-fix-1](https://github.com/jetthai/cuora-module/compare/v1.1.270-fix...v1.1.270-fix-1) (2024-06-03)
20
-
21
- ### [1.1.270-fix](https://github.com/jetthai/cuora-module/compare/v1.1.270...v1.1.270-fix) (2024-05-29)
5
+ ### [1.1.270-jackpot-1](https://github.com/jetthai/cuora-module/compare/v1.1.270...v1.1.270-jackpot-1) (2024-05-16)
22
6
 
23
7
  ### [1.1.270](https://github.com/jetthai/cuora-module/compare/v1.1.269...v1.1.270) (2024-05-16)
24
8
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jetthai/cuora",
3
- "version": "1.1.270-fix-8",
3
+ "version": "1.1.270-jackpot-1",
4
4
  "description": "",
5
5
  "main": "./src/index.js",
6
6
  "type": "module",
@@ -6,6 +6,12 @@ export default {
6
6
  params: { appSecret, include },
7
7
  isPublic: true,
8
8
  }),
9
+ getJackpotList: ({ appSecret }) => ({
10
+ url: 'activities/jackpot/list',
11
+ method: 'get',
12
+ params: { appSecret },
13
+ isPublic: true,
14
+ }),
9
15
  getTournamentDetail: ({ activityNo, appSecret }) => ({
10
16
  url: 'tournament/detail',
11
17
  method: 'get',
@@ -1,4 +1,5 @@
1
1
  export default {
2
+ // getPaymentHistory: () => ({ url: 'payment/history', method: 'post' }),
2
3
  getPaymentHistory: (returnDays) => ({ url: 'payment/v2/history', method: 'post', params: { returnDays } }),
3
4
  getSpotMarket: () => ({ url: 'payment/spotmarket', method: 'get' }),
4
5
  getTransactionHistory: (payload) => ({
@@ -7,6 +8,7 @@ export default {
7
8
  params: { ...payload },
8
9
  }),
9
10
  getTransactionHistoryOptions: () => ({ url: 'payment/v2/category/options', method: 'get' }),
11
+ // getPaymentInfo: () => ({ url: `payment/paymentInfo`, method: 'get' }),
10
12
  getPaymentInfo: () => ({ url: `payment/v2/paymentInfo`, method: 'get' }),
11
13
  getBindingPaymentInfo: () => ({ url: `payment/getBindingPaymentInfo`, method: 'get' }),
12
14
  updatePaymentInfo: ({
@@ -91,11 +93,6 @@ export default {
91
93
  method: 'post',
92
94
  params: { transferType: 'DEPOSIT', amount, cryptoCurrency, promotionsNo },
93
95
  }),
94
- getCryptoWithdrawExpectedResult: ({ method, amount, cryptoCurrency, promotionsNo }) => ({
95
- url: `payment/v2/${method}/crypto/expected/result`,
96
- method: 'post',
97
- params: { transferType: 'WITHDRAW', amount, cryptoCurrency, promotionsNo },
98
- }),
99
96
  getWithdrawExpectedResult: ({ method, amount, cryptoNetwork }) => ({
100
97
  url: `payment/v2/${method}/expected/result`,
101
98
  method: 'post',
@@ -161,34 +158,12 @@ export default {
161
158
  method: 'post',
162
159
  params: { transferType: 'DEPOSIT', amount, promotionsNo },
163
160
  }),
164
- submitWithdrawTransactionCrypto: ({ method, amount, cryptoCurrency, cryptoNetwork, targetAddress, applyerHolderName }) => ({
161
+ submitWithdrawTransactionCrypto: ({ method, amount, cryptoCurrency, cryptoNetwork, targetAddress }) => ({
165
162
  url: `payment/v2/${method}/transaction`,
166
163
  method: 'post',
167
- params: { transferType: 'WITHDRAW', amount, cryptoCurrency, cryptoNetwork, targetAddress, applyerHolderName },
164
+ params: { transferType: 'WITHDRAW', amount, cryptoCurrency, cryptoNetwork, targetAddress },
168
165
  }),
169
- submitWithdrawTransactionVN: ({ method, amount, applyerBankCode, applyerAccountNumber, branch, applyerHolderName }) => ({
170
- url: `payment/v2/${method}/transaction`,
171
- method: 'post',
172
- params: {
173
- transferType: 'WITHDRAW',
174
- amount,
175
- applyerBankCode,
176
- applyerAccountNumber,
177
- branch,
178
- applyerHolderName,
179
- },
180
- }),
181
- submitWithdrawTransactionManual: ({
182
- method,
183
- amount,
184
- applyerBankCode,
185
- applyerAccountNumber,
186
- branch,
187
- holderName,
188
- cryptoCurrency,
189
- cryptoNetwork,
190
- targetAddress,
191
- }) => ({
166
+ submitWithdrawTransactionVN: ({ method, amount, applyerBankCode, applyerAccountNumber, branch, holderName }) => ({
192
167
  url: `payment/v2/${method}/transaction`,
193
168
  method: 'post',
194
169
  params: {
@@ -198,9 +173,6 @@ export default {
198
173
  applyerAccountNumber,
199
174
  branch,
200
175
  holderName,
201
- cryptoCurrency,
202
- cryptoNetwork,
203
- targetAddress,
204
176
  },
205
177
  }),
206
178
  submitWithdrawTransactionAmb: ({ method, amount }) => ({
@@ -10,7 +10,7 @@ export default function (request) {
10
10
  initial: 'init',
11
11
  context: {
12
12
  tick: 2000,
13
- specifyActivities: [4, 29, 34],
13
+ specifyActivities: [29, 34],
14
14
  activitiesDetailList: [],
15
15
  activityList: [],
16
16
  promotionList: [],
@@ -13,6 +13,7 @@ export default function (request) {
13
13
  activityList: [],
14
14
  tournamentList: [],
15
15
  promotionList: [],
16
+ jackpotList: [],
16
17
  uidSite: '',
17
18
  detailNeededActivityTypes: [29, 34],
18
19
  activityDetailList: [],
@@ -23,7 +24,7 @@ export default function (request) {
23
24
  src: 'fetchList',
24
25
  onDone: {
25
26
  target: 'checking',
26
- actions: ['setActivityList', 'setTournamentList', 'setPromotionList'],
27
+ actions: ['setActivityList', 'setTournamentList', 'setPromotionList', 'setJackpotList'],
27
28
  },
28
29
  onError: {
29
30
  target: 'pending',
@@ -96,6 +97,12 @@ export default function (request) {
96
97
  promotionList,
97
98
  }
98
99
  }),
100
+ setJackpotList: assign((context, event) => {
101
+ const { jackpotList } = event.data
102
+ return {
103
+ jackpotList,
104
+ }
105
+ }),
99
106
  setUnread: assign((context, event) => {
100
107
  const { uidSite, activityNo, unread } = event.data
101
108
  const list = JSON.parse(JSON.stringify(context.activityList))
@@ -132,12 +139,13 @@ export default function (request) {
132
139
  services: {
133
140
  fetchList: async (context, event) => {
134
141
  const hasToken = request.getToken()
135
- const [{ data }, promotionList] = await Promise.all([
142
+ const [{ data }, promotionList, jackpotList] = await Promise.all([
136
143
  request.send(activity.getActivityList({ appSecret })),
137
144
  hasToken ? request.send(payment.getPromotionsList()) : [],
145
+ request.send(activity.getJackpotList({ appSecret })),
138
146
  ])
139
147
 
140
- return { activityList: data, promotionList }
148
+ return { activityList: data, promotionList, jackpotList: jackpotList.data }
141
149
  },
142
150
  fetchActivityDetailList: async (context, event) => {
143
151
  await new Promise((resolve) => setTimeout(resolve, 1000)) // delay 1 second
@@ -14,7 +14,6 @@ export default function (request, context) {
14
14
 
15
15
  // 領獎後得到的資訊
16
16
  amount: null,
17
- rewardType: null,
18
17
  message: null,
19
18
  canReceiveQuantity: null,
20
19
  receivedQuantity: null,
@@ -109,10 +108,9 @@ export default function (request, context) {
109
108
  }
110
109
  }),
111
110
  setAward: assign((context, event) => {
112
- const { amount, rewardType, message, canReceiveQuantity, receivedQuantity } = event.data
111
+ const { amount, message, canReceiveQuantity, receivedQuantity } = event.data
113
112
  return {
114
113
  amount,
115
- rewardType,
116
114
  message,
117
115
  canReceiveQuantity,
118
116
  receivedQuantity,
@@ -126,7 +124,6 @@ export default function (request, context) {
126
124
  resetAward: assign((context, event) => {
127
125
  return {
128
126
  amount: null,
129
- rewardType: null,
130
127
  message: null,
131
128
  }
132
129
  }),
@@ -13,7 +13,6 @@ export default function (request) {
13
13
  settlementTime: null,
14
14
  validTurnover: null,
15
15
  rebateAmount: null,
16
- rewardType: null,
17
16
  singleMinimumAmountReceive: null,
18
17
  remainingCount: 0,
19
18
  dailyRedemptionLimit: 0,
@@ -130,7 +129,6 @@ export default function (request) {
130
129
  settlementTime = 0,
131
130
  validTurnover = '0',
132
131
  rebateAmount = '0',
133
- rewardType = null,
134
132
  singleMinimumAmountReceive = 0,
135
133
  remainingCount = 0,
136
134
  dailyRedemptionLimit = 0,
@@ -142,7 +140,6 @@ export default function (request) {
142
140
  settlementTime,
143
141
  validTurnover,
144
142
  rebateAmount,
145
- rewardType,
146
143
  singleMinimumAmountReceive,
147
144
  remainingCount,
148
145
  dailyRedemptionLimit,
@@ -54,7 +54,7 @@ export default function (request) {
54
54
  actions: {
55
55
  setUserAccount: assign((context, event) => {
56
56
  return {
57
- userAccount: event.data?.[0],
57
+ userAccount: event.data.bankInfo?.[0],
58
58
  }
59
59
  }),
60
60
  setInitialization: assign((context, event) => {
@@ -69,14 +69,12 @@ export default function (request) {
69
69
  },
70
70
  guards: {
71
71
  hasUserAccount: (context, event) => {
72
- return event.data?.[0]
72
+ return event.data.bankInfo?.[0]
73
73
  },
74
74
  },
75
75
  services: {
76
76
  fetchPaymentInfo: async (context, event) => {
77
- const { bankInfo } = await request.send(payment.getPaymentInfo())
78
- const filterArray = bankInfo?.filter((item) => item.bindingType !== 'CRYPTO' && item.bindingType !== 'EWALLET')
79
- return filterArray || []
77
+ return await request.send(payment.getPaymentInfo())
80
78
  },
81
79
  initialize: async (context, event) => {
82
80
  const { method } = context
@@ -152,9 +152,7 @@ export default function (request, context) {
152
152
  setAmount: assign((context, event) => {
153
153
  // 現金網可自由填額度,grandTotalEnable 欄位感覺不再需要?
154
154
  if (context.selectedCrypto?.grandTotalEnable === 1) {
155
- return {
156
- selectedAmount: preciseAdd(`${parseFloat(context.selectedAmount || 0)}`, `${parseFloat(event.data)}`),
157
- }
155
+ return { selectedAmount: parseFloat(context.selectedAmount || 0) + parseFloat(event.data) }
158
156
  } else {
159
157
  return { selectedAmount: event.data }
160
158
  }
@@ -242,15 +240,3 @@ export default function (request, context) {
242
240
  }
243
241
  )
244
242
  }
245
-
246
- function preciseAdd(a, b) {
247
- let aStr = a.toString()
248
- let bStr = b.toString()
249
-
250
- let aDecimalPlaces = aStr.split('.')[1] ? aStr.split('.')[1].length : 0
251
- let bDecimalPlaces = bStr.split('.')[1] ? bStr.split('.')[1].length : 0
252
-
253
- let factor = Math.pow(10, Math.max(aDecimalPlaces, bDecimalPlaces))
254
-
255
- return (Math.round(a * factor) + Math.round(b * factor)) / factor
256
- }
@@ -245,7 +245,7 @@ export default function (request) {
245
245
  actions: {
246
246
  setUserAccount: assign((context, event) => {
247
247
  return {
248
- userAccount: event.data?.[0],
248
+ userAccount: event.data.bankInfo?.[0],
249
249
  }
250
250
  }),
251
251
  setPromotion: assign((context, event) => {
@@ -310,7 +310,7 @@ export default function (request) {
310
310
  },
311
311
  guards: {
312
312
  hasUserAccount: (context, event) => {
313
- return event.data?.[0]
313
+ return event.data.bankInfo?.[0]
314
314
  },
315
315
  isGrandTotalEnable: (context, event) => {
316
316
  return context.grandTotalEnable === 1
@@ -318,9 +318,7 @@ export default function (request) {
318
318
  },
319
319
  services: {
320
320
  fetchPaymentInfo: async (context, event) => {
321
- const { bankInfo } = await request.send(payment.getPaymentInfo())
322
- const filterArray = bankInfo?.filter((item) => item.bindingType !== 'CRYPTO' && item.bindingType !== 'EWALLET')
323
- return filterArray || []
321
+ return await request.send(payment.getPaymentInfo())
324
322
  },
325
323
  initialize: async (context, event) => {
326
324
  const [{ config }, payments, bankList] = await Promise.all([
@@ -151,14 +151,12 @@ export default function (request, context) {
151
151
  return bank
152
152
  })
153
153
 
154
- const formattedPlayerBanks = playerBanks
155
- .filter((item) => item.bindingType !== 'CRYPTO' && item.bindingType !== 'EWALLET')
156
- .map((bank) => {
157
- const foundBank = banks.find((item) => item.bankCode === bank.bankCode)
158
- bank.displayText = `${foundBank?.shortName} ${bank.accountNumber.slice(-5)}`
159
- bank.imageUrl = foundBank?.imageUrl
160
- return bank
161
- })
154
+ const formattedPlayerBanks = playerBanks.map((bank) => {
155
+ const foundBank = banks.find((item) => item.bankCode === bank.bankCode)
156
+ bank.displayText = `${foundBank?.shortName} ${bank.accountNumber.slice(-5)}`
157
+ bank.imageUrl = foundBank?.imageUrl
158
+ return bank
159
+ })
162
160
 
163
161
  const userBanks = [
164
162
  ...formattedPlayerBanks,
@@ -265,13 +265,11 @@ export default function (request) {
265
265
  const banks = event.data
266
266
  const { playerBanks, houseBanks, selectedHouseBank } = context
267
267
 
268
- const formattedPlayerBanks = playerBanks
269
- .filter((item) => item.bindingType !== 'CRYPTO' && item.bindingType !== 'EWALLET')
270
- .map((bank) => {
271
- bank.shortName = `${bank.bankCode} ${bank.accountNumber.slice(-5)}`
272
- bank.imageUrl = event.data.find((item) => item.bankCode === bank.bankCode)?.imageUrl
273
- return bank
274
- })
268
+ const formattedPlayerBanks = playerBanks.map((bank) => {
269
+ bank.shortName = `${bank.bankCode} ${bank.accountNumber.slice(-5)}`
270
+ bank.imageUrl = event.data.find((item) => item.bankCode === bank.bankCode)?.imageUrl
271
+ return bank
272
+ })
275
273
 
276
274
  const userBanks = [...formattedPlayerBanks, ...banks]
277
275
 
@@ -235,7 +235,7 @@ export default function (request) {
235
235
  actions: {
236
236
  setUserAccount: assign((context, event) => {
237
237
  return {
238
- userAccount: event.data?.[0],
238
+ userAccount: event.data.bankInfo?.[0],
239
239
  }
240
240
  }),
241
241
  setBonusPreview: assign((context, event) => {
@@ -299,7 +299,7 @@ export default function (request) {
299
299
  },
300
300
  guards: {
301
301
  hasUserAccount: (context, event) => {
302
- return event.data?.[0]
302
+ return event.data.bankInfo?.[0]
303
303
  },
304
304
  hasPreviousOrder: (context, event) => {
305
305
  return event.data.order?.qrcode
@@ -310,9 +310,7 @@ export default function (request) {
310
310
  },
311
311
  services: {
312
312
  fetchPaymentInfo: async (context, event) => {
313
- const { bankInfo } = await request.send(payment.getPaymentInfo())
314
- const filterArray = bankInfo?.filter((item) => item.bindingType !== 'CRYPTO' && item.bindingType !== 'EWALLET')
315
- return filterArray || []
313
+ return await request.send(payment.getPaymentInfo())
316
314
  },
317
315
  initialize: async (context, event) => {
318
316
  const [{ config }, payments, bankList, order] = await Promise.all([
@@ -136,29 +136,6 @@ export default function (request) {
136
136
  EXIT_GAME: {
137
137
  target: 'disconnect',
138
138
  },
139
- REFRESH: {
140
- target: 'refreshing',
141
- },
142
- },
143
- },
144
- refreshing: {
145
- invoke: {
146
- src: 'disconnectGame',
147
- onDone: {
148
- target: 'refreshPending',
149
- actions: 'setGameURL',
150
- },
151
- onError: {
152
- target: 'idle',
153
- actions: 'setGameURL',
154
- },
155
- },
156
- },
157
- refreshPending: {
158
- after: {
159
- 500: {
160
- target: 'connecting',
161
- },
162
139
  },
163
140
  },
164
141
  disconnect: {
@@ -1,7 +1,6 @@
1
1
  import withdraw_fc from './withdraw_fc.js'
2
2
  import withdraw_vn from './withdraw_vn.js'
3
3
  import withdraw_vn2 from './withdraw_vn2.js'
4
- import withdraw_manual from './withdraw_manual.js'
5
4
  import withdraw_crypto from './withdraw_crypto.js'
6
5
  import withdraw_crypto2 from './withdraw_crypto2.js'
7
6
  import withdraw_amb from './withdraw_amb.js'
@@ -13,7 +12,6 @@ export default {
13
12
  withdraw_fc,
14
13
  withdraw_vn,
15
14
  withdraw_vn2,
16
- withdraw_manual,
17
15
  withdraw_crypto,
18
16
  withdraw_crypto2,
19
17
  withdraw_amb,
@@ -50,9 +50,6 @@ export default function (request, context) {
50
50
  SUBMIT: {
51
51
  target: 'submitting',
52
52
  },
53
- SUBMIT_CRYPTO: {
54
- target: 'submitting_crypto',
55
- },
56
53
  },
57
54
  },
58
55
  submitting: {
@@ -74,25 +71,6 @@ export default function (request, context) {
74
71
  },
75
72
  },
76
73
  },
77
- submitting_crypto: {
78
- invoke: {
79
- src: 'submitWithdrawCrypto',
80
- onDone: [
81
- {
82
- target: 'otp',
83
- actions: 'setOtp',
84
- cond: 'isOtpRequired',
85
- },
86
- {
87
- target: 'submitted',
88
- actions: 'setProcessing',
89
- },
90
- ],
91
- onError: {
92
- target: 'calculated',
93
- },
94
- },
95
- },
96
74
  submitted: {},
97
75
  otp: {
98
76
  type: 'parallel',
@@ -177,20 +155,18 @@ export default function (request, context) {
177
155
  setInitData: assign((context, event) => {
178
156
  const { currentPayment, banks, paymentInfo, withdrawRule, processing } = event.data
179
157
 
180
- // const withdrawBanks = (paymentInfo?.bankInfo || [])
181
- // .map((item) => {
182
- // const matchedBank = banks.find((bank) => bank.bankCode === item.bankCode)
183
- // return matchedBank ? { ...item, ...matchedBank } : null
184
- // })
185
- // .filter(Boolean)
186
-
187
- // const userBanks = (paymentInfo.bankList || []).map((bank) => {
188
- // bank.displayText = `${bank.bankCode} - ${bank.accountNumber}`
189
- // bank.imageUrl = banks.find((item) => item.bankCode === bank.bankCode)?.imageUrl
190
- // return bank
191
- // })
158
+ const withdrawBanks = (paymentInfo?.bankInfo || [])
159
+ .map((item) => {
160
+ const matchedBank = banks.find((bank) => bank.bankCode === item.bankCode)
161
+ return matchedBank ? { ...item, ...matchedBank } : null
162
+ })
163
+ .filter(Boolean)
192
164
 
193
- const userBanks = [...paymentInfo.bankList, ...paymentInfo.cryptoList, ...paymentInfo.ewalletList]
165
+ const userBanks = (withdrawBanks || []).map((bank) => {
166
+ bank.displayText = `${bank.bankCode} - ${bank.accountNumber}`
167
+ bank.imageUrl = banks.find((item) => item.bankCode === bank.bankCode)?.imageUrl
168
+ return bank
169
+ })
194
170
 
195
171
  return {
196
172
  currentPayment,
@@ -262,8 +238,7 @@ export default function (request, context) {
262
238
 
263
239
  const [banks, paymentInfo, withdrawRule, orders] = await Promise.all([
264
240
  request.send(payment.getWithdrawBankList()),
265
- // request.send(payment.getPaymentInfo()),
266
- request.send(payment.getBindingPaymentInfo()),
241
+ request.send(payment.getPaymentInfo()),
267
242
  request.send(payment.getDoubleWalletWithdrawRule({ walletType: 'CASH' })),
268
243
  request.send(payment.getPendingOrder({ transferType: 'WITHDRAW' })),
269
244
  ])
@@ -286,21 +261,7 @@ export default function (request, context) {
286
261
  applyerBankCode: selectedUserBank.bankCode,
287
262
  applyerAccountNumber: selectedUserBank.accountNumber,
288
263
  branch: branchTemp,
289
- applyerHolderName: selectedUserBank.holderName,
290
- })
291
- )
292
- },
293
- submitWithdrawCrypto: async (context, event) => {
294
- const { currentPayment, selectedUserBank, selectedAmount } = context
295
- const branchTemp = ['GCASH', 'PAYM', 'PIX'].includes(selectedUserBank.bankCode) ? '' : selectedUserBank.branch
296
- return await request.send(
297
- payment.submitWithdrawTransactionCrypto({
298
- method: currentPayment.method,
299
- amount: selectedAmount,
300
- cryptoCurrency: selectedUserBank.cryptoCurrency,
301
- cryptoNetwork: selectedUserBank.cryptoNetwork,
302
- targetAddress: selectedUserBank.cryptoAddress,
303
- applyerHolderName: selectedUserBank.holderName,
264
+ holderName: selectedUserBank.holderName,
304
265
  })
305
266
  )
306
267
  },
@@ -1,594 +0,0 @@
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_manual',
11
- initial: 'loading',
12
- context: {
13
- mode: null,
14
- siteConfig: null,
15
- userInfo: null,
16
- paymentDetail: [],
17
- bindingPaymentInfo: {},
18
- bindingPaymentList: {},
19
- boundBanks: [],
20
- balance: null,
21
- charge: null,
22
- realAmount: null,
23
- applyId: null,
24
- currentBank: null,
25
- currentWithdrawLimit: null,
26
- targetWithdrawLimit: null,
27
- attachmentType: null, // null | 'withdraw' | 'pool'
28
- enableWithdrawAmount: 0,
29
- enableWithdraw: false,
30
- withdrawRules: [],
31
- withdrawRule: {},
32
- withdrawCheck: {},
33
- amount: null,
34
- calculation: 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_manual.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_manual.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_manual.cash.unbound', cond: 'isBankNotBound' },
152
- { target: '#withdraw_manual.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: 'unbound', cond: 'isBankNotBound' },
164
- { target: 'withdrawCheck' },
165
- ],
166
- },
167
- withdrawCheck: {
168
- invoke: {
169
- src: 'withdrawCheck',
170
- onDone: [
171
- {
172
- target: 'notWithdrawMinDepositAmount',
173
- cond: 'isNotWithdrawMinDepositAmount',
174
- actions: assign((context, event) => {
175
- return {
176
- withdrawCheck: event.data,
177
- }
178
- }),
179
- },
180
- {
181
- target: 'notWithdrawable',
182
- cond: 'isNotWithdrawable',
183
- },
184
- {
185
- target: 'withdrawable',
186
- },
187
- ],
188
- onError: {
189
- target: '#withdraw_manual.fail',
190
- },
191
- },
192
- },
193
- notWithdrawMinDepositAmount: {},
194
- notWithdrawable: {},
195
- unbound: {
196
- // to bank_binding.js
197
- },
198
- inProcessing: {},
199
- withdrawable: {
200
- on: {
201
- SET_CURRENT_BANK: {
202
- actions: assign((context, event) => {
203
- return {
204
- currentBank: event.data,
205
- }
206
- }),
207
- },
208
- SET_ATTACHMENT_TYPE: {
209
- actions: 'setAttachmentType',
210
- },
211
- SUBMIT: [
212
- {
213
- target: 'pooling',
214
- cond: (context, event) => {
215
- const { amount, attachmentType } = context
216
- return attachmentType === 'pool' && amount > 0
217
- },
218
- },
219
- {
220
- target: 'submitting',
221
- cond: 'isAvailableAmount',
222
- },
223
- ],
224
- },
225
- },
226
- debouncing: {
227
- after: {
228
- 1000: [
229
- {
230
- target: 'calculating',
231
- cond: 'isAvailableAmount',
232
- },
233
- {
234
- target: 'withdrawable',
235
- },
236
- ],
237
- },
238
- },
239
- calculating: {
240
- invoke: {
241
- src: 'fetchCalculation',
242
- onDone: {
243
- target: 'withdrawable',
244
- actions: 'setCalculation',
245
- },
246
- onError: {
247
- target: 'withdrawable',
248
- },
249
- },
250
- },
251
- submitting: {
252
- invoke: {
253
- src: 'submitWithdraw',
254
- onDone: [
255
- {
256
- target: '#withdraw_manual.otp',
257
- actions: 'setOtp',
258
- cond: 'isOtpRequired',
259
- },
260
- {
261
- target: 'submitted',
262
- },
263
- ],
264
- onError: {
265
- target: 'withdrawable',
266
- },
267
- },
268
- },
269
- submitted: {
270
- entry: assign((context, event) => {
271
- const { applyId, balance, realAmount, charge } = event.data
272
- return { applyId, balance, realAmount, charge }
273
- }),
274
- invoke: {
275
- src: 'fetchPaymentData',
276
- onDone: {
277
- target: 'inProcessing',
278
- actions: 'setPaymentData',
279
- },
280
- onError: {
281
- target: '#withdraw_manual.fail',
282
- },
283
- },
284
- },
285
- pooling: {
286
- invoke: {
287
- src: 'pool',
288
- onDone: { target: 'pooled' },
289
- onError: {
290
- target: 'withdrawable',
291
- },
292
- },
293
- },
294
- pooled: {},
295
- },
296
- on: {
297
- SET_AMOUNT: {
298
- actions: ['setAmount', 'clearCalculation'],
299
- },
300
- CALCULATE: {
301
- target: '.debouncing',
302
- },
303
- },
304
- },
305
- otp: {
306
- type: 'parallel',
307
- states: {
308
- countdown: {
309
- after: {
310
- 1000: {
311
- target: 'countdown',
312
- actions: 'decreaseTtl',
313
- cond: (context) => context.ttl > 0,
314
- },
315
- },
316
- },
317
- verification: {
318
- initial: 'idle',
319
- states: {
320
- idle: {
321
- on: {
322
- ACKNOWLEDGE: {
323
- target: 'acknowledging',
324
- },
325
- RESET_OTP: {
326
- target: 'reset',
327
- },
328
- BACK: [
329
- {
330
- target: '#withdraw_manual.activity.convertible',
331
- cond: 'isActivity',
332
- },
333
- {
334
- target: '#withdraw_manual.cash.withdrawable',
335
- },
336
- ],
337
- },
338
- },
339
- acknowledging: {
340
- invoke: {
341
- src: 'acknowledge',
342
- onDone: [
343
- {
344
- target: '#withdraw_manual.activity.converted',
345
- cond: 'isActivity',
346
- },
347
- {
348
- target: '#withdraw_manual.cash.submitted',
349
- },
350
- ],
351
- onError: {
352
- target: 'idle',
353
- },
354
- },
355
- },
356
- reset: {
357
- invoke: {
358
- src: 'resetOtp',
359
- onDone: {
360
- target: 'idle',
361
- actions: 'setVerificationData',
362
- },
363
- onError: { target: 'idle' },
364
- },
365
- },
366
- },
367
- },
368
- },
369
- },
370
- fail: {},
371
- },
372
- on: {
373
- REFRESH: {
374
- target: 'loading',
375
- },
376
- },
377
- },
378
- {
379
- actions: {
380
- setInitData: assign((context, event) => {
381
- const { bindingPaymentList = {}, bindingPaymentInfo = {} } = event.data
382
- const toBeUsed = ['bankList', 'cryptoList', 'ewalletList']
383
- const copiedBindingPaymentInfo = JSON.parse(JSON.stringify(bindingPaymentInfo))
384
- const filterTypes = Object.keys(copiedBindingPaymentInfo).filter((type) => toBeUsed.includes(type))
385
-
386
- let combinedData = []
387
- filterTypes.forEach((type) => {
388
- combinedData = combinedData.concat(copiedBindingPaymentInfo[type])
389
- })
390
- return { bindingPaymentList, bindingPaymentInfo, boundBanks: combinedData, currentBank: combinedData[0] }
391
- }),
392
- preset: assign((context, event) => {
393
- const { siteConfig } = context
394
- return {
395
- attachmentType: siteConfig.walletMode > 0 ? 'withdraw' : null,
396
- }
397
- }),
398
- setMode: assign((context, event) => {
399
- return {
400
- mode: event.data,
401
- }
402
- }),
403
- updateWithdrawCondition: assign((context, event) => {
404
- const { enableWithdraw, enableWithdrawAmount, currentWithdrawLimit, targetWithdrawLimit, balance } = event.data
405
- const withdrawRules = event.data?.rules || []
406
- const rules = withdrawRules.filter((rule) => rule.maxWithdrawAmount > 0)
407
- const lastMatchedIndex = findLastIndex(rules, (rule) => balance >= rule.greaterEqualThen)
408
-
409
- let maxWithdrawAmount = 0
410
-
411
- if (lastMatchedIndex > -1) {
412
- rules[lastMatchedIndex].match = true
413
- maxWithdrawAmount = rules[lastMatchedIndex].maxWithdrawAmount
414
- } else if (rules.length > 0) {
415
- maxWithdrawAmount = rules[0].maxWithdrawAmount
416
- } else {
417
- maxWithdrawAmount = balance
418
- }
419
-
420
- return {
421
- balance,
422
- currentWithdrawLimit,
423
- targetWithdrawLimit,
424
- maxWithdrawAmount,
425
- enableWithdrawAmount: +enableWithdrawAmount,
426
- enableWithdraw,
427
- withdrawRules,
428
- }
429
- }),
430
- setWithdrawRulePreview: assign((context, event) => {
431
- return {
432
- withdrawRule: event.data,
433
- }
434
- }),
435
- setPaymentData: assign((context, event) => {
436
- const { paymentDetail } = event.data
437
- return { paymentDetail }
438
- }),
439
- setOtp: assign((context, event) => {
440
- const { requestId, status, target, ttl } = event.data
441
- return {
442
- requestId,
443
- status,
444
- target,
445
- ttl,
446
- }
447
- }),
448
- decreaseTtl: assign((context, evnet) => {
449
- const second = context.ttl
450
- return {
451
- ttl: Math.max(second - 1, 0),
452
- }
453
- }),
454
- setVerificationData: assign((context, event) => {
455
- const { requestId, ttl, target } = event.data
456
- return {
457
- requestId,
458
- ttl,
459
- target,
460
- }
461
- }),
462
- setAttachmentType: assign((context, event) => {
463
- return {
464
- attachmentType: event.data,
465
- }
466
- }),
467
- setCalculation: assign((context, event) => {
468
- return {
469
- calculation: event.data,
470
- }
471
- }),
472
- clearCalculation: assign((context, event) => {
473
- return {
474
- calculation: null,
475
- }
476
- }),
477
- setAmount: assign((context, event) => {
478
- return {
479
- amount: event.data,
480
- }
481
- }),
482
- },
483
- guards: {
484
- isAvailableAmount: (context, event) => {
485
- const { paymentDetail, currentBank, amount, userInfo } = context
486
- const { minimum = 0, maximum = 0 } = paymentDetail?.[0] || {}
487
- const { balance = 0 } = userInfo || {}
488
- const lastMax = Math.min(parseFloat(balance), maximum)
489
- return !!currentBank && amount > 0 && minimum <= amount && amount <= lastMax
490
- },
491
- isActivity: (context, event) => {
492
- return context.mode === 'ACTIVITY'
493
- },
494
- hasAttachmentType: (context, event) => {
495
- return ['withdraw', 'pool'].includes(context.attachmentType)
496
- },
497
- haveProcessing: (context, event) => {
498
- return (context.paymentDetail?.[0]?.processing || []).length > 0
499
- },
500
- isBankNotBound: (context, event) => {
501
- return !context.boundBanks?.length
502
- },
503
- isConvertible: (context, event) => {
504
- const { balance, enableWithdraw } = context
505
- return balance > 0 && enableWithdraw
506
- },
507
- isNotWithdrawable: (context, event) => {
508
- const { balance, enableWithdraw, paymentDetail } = context
509
- const minWithdrawAmount = paymentDetail[0]?.minimum || 0
510
- return !enableWithdraw || balance < minWithdrawAmount
511
- },
512
- isOtpRequired: (context, event) => {
513
- return event.data?.status === 'otp-verifying'
514
- },
515
- isNotWithdrawMinDepositAmount: (context, event) => {
516
- return !event.data?.enableWithdraw
517
- },
518
- },
519
- services: {
520
- fetchInitData: async (context, event) => {
521
- const [bindingPaymentList = {}, bindingPaymentInfo = {}] = await Promise.all([
522
- request.send(payment.getBindingPaymentList({ appSecret })),
523
- request.send(payment.getBindingPaymentInfo({ appSecret })),
524
- ])
525
- return { bindingPaymentList, bindingPaymentInfo }
526
- },
527
- fetchPaymentData: async (context, event) => {
528
- const paymentDetail = await request.send(payment.getPaymentDetail({ transferType: 'WITHDRAW' }))
529
- return { paymentDetail }
530
- },
531
- fetchWithdrawRules: async (context, event) => {
532
- const { mode } = context
533
- return await request.send(payment.getDoubleWalletWithdrawRule({ walletType: mode }))
534
- },
535
- fetchWithdrawRulePreview: async (context, event) => {
536
- const data = await request.send(payment.getWithdrawRulePreview({ applyType: 'giveup' }))
537
- return data
538
- },
539
- fetchCalculation: async (context, event) => {
540
- const { paymentDetail, currentBank, amount } = context
541
- const { method } = paymentDetail?.[0] || {}
542
- const { cryptoCurrency } = currentBank || {}
543
- return await request.send(payment.getCryptoWithdrawExpectedResult({ method, amount, cryptoCurrency }))
544
- },
545
- submitWithdraw: async (context, event) => {
546
- const { currentBank, amount } = context
547
- const { method } = context.paymentDetail[0]
548
- const { bindingType } = currentBank || {}
549
-
550
- let branchTemp = ''
551
- if (bindingType === 'BANK' && !['GCASH', 'PAYM', 'PIX'].includes(currentBank.bankCode)) {
552
- branchTemp = currentBank.branch
553
- }
554
-
555
- return await request.send(
556
- payment.submitWithdrawTransactionManual({
557
- method,
558
- amount,
559
- applyerBankCode: currentBank.bankCode,
560
- applyerAccountNumber: currentBank.accountNumber,
561
- branch: branchTemp,
562
- holderName: currentBank.holderName,
563
- cryptoCurrency: currentBank.cryptoCurrency,
564
- cryptoNetwork: currentBank.cryptoNetwork,
565
- targetAddress: currentBank.cryptoAddress,
566
- })
567
- )
568
- },
569
- convertFreeCredit: async (context, event) => {
570
- return await request.send(payment.convertFreeCredit({ exchangeType: 1 }))
571
- },
572
- resetOtp: async (context, event) => {
573
- const { requestId, target } = context
574
- return await request.send(user.otpReset({ requestId, target }))
575
- },
576
- acknowledge: async (context, event) => {
577
- const { requestId, target } = context
578
- const code = event.data
579
- return await request.send(user.otpAcknowledge({ requestId, target, code }))
580
- },
581
- pool: async (context, event) => {
582
- const { amount } = context
583
- return await request.send(payment.restore({ amount }))
584
- },
585
- giveUp: async (context, event) => {
586
- return await request.send(payment.giveUp())
587
- },
588
- withdrawCheck: async (context, event) => {
589
- return await request.send(payment.withdrawCheck())
590
- },
591
- },
592
- }
593
- )
594
- }