@jetthai/cuora 1.1.91 → 1.1.92-cash

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.
@@ -9,6 +9,8 @@ import amb from './amb.js'
9
9
  import float from './float.js'
10
10
  import vpay from './vpay.js'
11
11
  import usdt from './usdt.js'
12
+ import manual_cash from './manual_cash.js'
13
+ import qrcode_cash from './qrcode_cash.js'
12
14
 
13
15
  export default {
14
16
  manual_vn,
@@ -22,4 +24,6 @@ export default {
22
24
  float,
23
25
  vpay,
24
26
  usdt,
27
+ manual_cash,
28
+ qrcode_cash,
25
29
  }
@@ -0,0 +1,321 @@
1
+ import { assign, createMachine } from 'xstate'
2
+ import payment from '../../api/payment.js'
3
+ import common from '../../api/common.js'
4
+ import { max } from '../../util/index.js'
5
+
6
+ export default function (request, context) {
7
+ const { paymentDetail = [], promotion, selectedAmount } = context || {}
8
+
9
+ return createMachine(
10
+ {
11
+ id: 'manual_cash',
12
+ initial: 'loading',
13
+ context: {
14
+ paymentDetail,
15
+ promotion,
16
+ selectedAmount,
17
+
18
+ houseBanks: [],
19
+ userBanks: [],
20
+ banks: [],
21
+
22
+ selectedHouseBank: null,
23
+ selectedUserBank: null,
24
+ userAccountNumber: null,
25
+ userAccountName: null,
26
+ depositTime: null,
27
+ receipt: null,
28
+
29
+ currentCategory: 'manual',
30
+ method: null,
31
+ currentPayment: null,
32
+ currentApplyerBank: null,
33
+
34
+ calculation: null,
35
+ processing: null,
36
+ },
37
+ states: {
38
+ loading: {
39
+ invoke: {
40
+ src: 'fetchInitData',
41
+ onDone: {
42
+ target: 'checking',
43
+ actions: 'setInitData',
44
+ },
45
+ },
46
+ },
47
+ checking: {
48
+ always: [
49
+ {
50
+ target: 'submitted',
51
+ cond: 'isProcessing',
52
+ },
53
+ {
54
+ target: 'loaded',
55
+ },
56
+ ],
57
+ },
58
+ loaded: {
59
+ on: {
60
+ SET_PROMOTION: {
61
+ target: 'debouncing',
62
+ actions: 'setPromotion',
63
+ },
64
+ SELECT_HOUSE_BANK: {
65
+ actions: 'setHouseBank',
66
+ },
67
+ INPUT_AMOUNT: {
68
+ target: 'debouncing',
69
+ actions: 'inputAmount',
70
+ },
71
+ },
72
+ },
73
+ debouncing: {
74
+ after: {
75
+ 1000: [{ target: 'calculating', cond: 'isCalculable' }, { target: 'loaded' }],
76
+ },
77
+ on: {
78
+ SET_PROMOTION: {
79
+ target: 'debouncing',
80
+ actions: 'setPromotion',
81
+ },
82
+ SELECT_HOUSE_BANK: {
83
+ actions: 'setHouseBank',
84
+ },
85
+ INPUT_AMOUNT: {
86
+ target: 'debouncing',
87
+ actions: 'inputAmount',
88
+ },
89
+ },
90
+ },
91
+ calculating: {
92
+ invoke: {
93
+ src: 'fetchCalculation',
94
+ onDone: {
95
+ target: 'calculated',
96
+ actions: 'setCalculation',
97
+ },
98
+ onError: {
99
+ target: 'loaded',
100
+ },
101
+ },
102
+ },
103
+ calculated: {
104
+ on: {
105
+ SET_PROMOTION: {
106
+ target: 'debouncing',
107
+ actions: 'setPromotion',
108
+ },
109
+ SELECT_HOUSE_BANK: {
110
+ actions: 'setHouseBank',
111
+ },
112
+ INPUT_AMOUNT: {
113
+ target: 'debouncing',
114
+ actions: 'inputAmount',
115
+ },
116
+ SELECT_USER_BANK: {
117
+ actions: 'setUserBank',
118
+ },
119
+ INPUT_USER_ACCOUNT_NUMBER: {
120
+ actions: 'setUserAccountNumber',
121
+ },
122
+ INPUT_USER_ACCOUNT_NAME: {
123
+ actions: 'setUserAccountName',
124
+ },
125
+ SET_RECEIPT: {
126
+ actions: 'setReceipt',
127
+ },
128
+ SET_DEPOSIT_TIME: {
129
+ actions: 'setDepositTime',
130
+ },
131
+ SUBMIT: {
132
+ target: 'submitting',
133
+ cond: 'isSubmittable',
134
+ },
135
+ },
136
+ },
137
+ submitting: {
138
+ invoke: {
139
+ src: 'submitDeposit',
140
+ onDone: {
141
+ target: 'submitted',
142
+ actions: 'setProcessing',
143
+ },
144
+ onError: {
145
+ target: 'loaded',
146
+ },
147
+ },
148
+ },
149
+ submitted: {},
150
+ },
151
+ on: {
152
+ SET_PROMOTION: {
153
+ actions: 'setPromotion',
154
+ },
155
+ },
156
+ },
157
+ {
158
+ actions: {
159
+ setInitData: assign((context, event) => {
160
+ const { currentPayment, banks, paymentInfo } = event.data
161
+ const playerBanks = paymentInfo?.bankInfo || []
162
+
163
+ const houseBanks = currentPayment.banks.map((bank) => {
164
+ bank.bankCode = bank.bankName // because api has no bankCode field
165
+ bank.imageUrl = banks.find((item) => item.bankCode === bank.bankName)?.imageUrl
166
+ return bank
167
+ })
168
+
169
+ const formattedPlayerBanks = playerBanks.map((bank) => {
170
+ bank.displayText = `${bank.bankCode} ${bank.accountNumber.slice(-5)}`
171
+ bank.imageUrl = banks.find((item) => item.bankCode === bank.bankCode)?.imageUrl
172
+ return bank
173
+ })
174
+
175
+ const userBanks = [...formattedPlayerBanks, ...banks]
176
+
177
+ return {
178
+ currentPayment,
179
+ method: currentPayment.method,
180
+ processing: currentPayment.processing?.[0],
181
+ houseBanks,
182
+ selectedHouseBank: houseBanks[0],
183
+ userBanks,
184
+ selectedUserBank: userBanks[0],
185
+ userAccountNumber: userBanks[0].accountNumber,
186
+ userAccountName: userBanks[0].holderName,
187
+ }
188
+ }),
189
+ setHouseBank: assign((context, event) => {
190
+ return {
191
+ selectedHouseBank: event.data,
192
+ }
193
+ }),
194
+ inputAmount: assign((context, event) => {
195
+ return { selectedAmount: event.data }
196
+ }),
197
+ setCalculation: assign((context, event) => {
198
+ return {
199
+ calculation: event.data,
200
+ }
201
+ }),
202
+ setProcessing: assign((context, event) => {
203
+ return {
204
+ processing: event.data,
205
+ }
206
+ }),
207
+ clearCalculation: assign((context, event) => {
208
+ return {
209
+ calculation: null,
210
+ }
211
+ }),
212
+ setUserBank: assign((context, event) => {
213
+ const { accountNumber, holderName } = event.data
214
+ return {
215
+ selectedUserBank: event.data,
216
+ userAccountNumber: accountNumber,
217
+ userAccountName: holderName,
218
+ }
219
+ }),
220
+ setUserAccountNumber: assign((context, event) => {
221
+ console.log('userAccountNumber', event.data)
222
+ return {
223
+ userAccountNumber: event.data,
224
+ }
225
+ }),
226
+ setUserAccountName: assign((context, event) => {
227
+ console.log('userAccountName', event.data)
228
+ return {
229
+ userAccountName: event.data,
230
+ }
231
+ }),
232
+ setDepositTime: assign((context, event) => {
233
+ return {
234
+ depositTime: event.data,
235
+ }
236
+ }),
237
+ setReceipt: assign((context, event) => {
238
+ return {
239
+ receipt: event.data,
240
+ }
241
+ }),
242
+ setPromotion: assign((context, event) => {
243
+ return {
244
+ promotion: event.data,
245
+ }
246
+ }),
247
+ setPromotionDefaultAmount: assign((context, event) => {
248
+ return {
249
+ selectedAmount: context.promotion.minimumAmount,
250
+ }
251
+ }),
252
+ },
253
+ guards: {
254
+ isCalculable: (context, event) => {
255
+ const {
256
+ selectedAmount,
257
+ currentPayment: { maximum, minimum },
258
+ } = context
259
+ return selectedAmount && minimum <= +selectedAmount && +selectedAmount <= maximum
260
+ },
261
+ isCalculated: (context, event) => {
262
+ return context.calculation
263
+ },
264
+ isSubmittable: (context, event) => {
265
+ const { selectedAmount, userAccountNumber, userAccountName, depositTime, receipt } = context
266
+ return selectedAmount && userAccountNumber && userAccountName && depositTime && receipt
267
+ },
268
+ isProcessing: (context, event) => {
269
+ return context.processing
270
+ },
271
+ hasMinPromotionDeposit: (context, event) => {
272
+ return context.promotion?.minimumAmount
273
+ },
274
+ },
275
+ services: {
276
+ fetchInitData: async (context, event) => {
277
+ const currentPayment = context.paymentDetail.find((element) => element.category === context.currentCategory)
278
+
279
+ const [banks, paymentInfo] = await Promise.all([
280
+ request.send(payment.getBankList(currentPayment.method)),
281
+ request.send(payment.getPaymentInfo()),
282
+ ])
283
+
284
+ return {
285
+ currentPayment,
286
+ banks,
287
+ paymentInfo,
288
+ }
289
+ },
290
+ fetchCalculation: async (context, event) => {
291
+ const { method, selectedAmount, promotion } = context
292
+ return await request.send(
293
+ payment.getDepositExpectedResult({
294
+ method,
295
+ amount: selectedAmount,
296
+ promotionsNo: promotion?.activityNo,
297
+ })
298
+ )
299
+ },
300
+ submitDeposit: async (context, event) => {
301
+ const { method, selectedAmount, selectedHouseBank, selectedUserBank, userAccountNumber, userAccountName, depositTime, receipt, promotion } =
302
+ context
303
+ return await request.send(
304
+ payment.submitDepositTransactionBank({
305
+ method,
306
+ amount: selectedAmount,
307
+ targetBankCode: selectedHouseBank.bankName,
308
+ targetAccountNumber: selectedHouseBank.accountNumber,
309
+ applyerBankCode: selectedUserBank.bankCode,
310
+ applyerAccountNumber: userAccountNumber,
311
+ applyerHolderName: userAccountName,
312
+ depositTime,
313
+ receipt,
314
+ promotionsNo: promotion?.activityNo,
315
+ })
316
+ )
317
+ },
318
+ },
319
+ }
320
+ )
321
+ }
@@ -0,0 +1,258 @@
1
+ import { assign, createMachine } from 'xstate'
2
+ import payment from '../../api/payment.js'
3
+ import { max } from '../../util'
4
+
5
+ export default function (request, context) {
6
+ const { paymentDetail = [], promotion, selectedAmount } = context || {}
7
+ return createMachine(
8
+ {
9
+ id: 'qrcode_cash',
10
+ initial: 'loading',
11
+ context: {
12
+ paymentDetail,
13
+ promotion,
14
+ selectedAmount,
15
+
16
+ qrcodes: null,
17
+ options: null,
18
+
19
+ selectedQrcode: null,
20
+
21
+ calculation: null,
22
+
23
+ currentCategory: 'qrcode',
24
+
25
+ result: null,
26
+
27
+ bonusPreviewData: [],
28
+ },
29
+ states: {
30
+ loading: {
31
+ always: [
32
+ {
33
+ target: 'loaded',
34
+ actions: 'setInitData',
35
+ cond: 'hasQrcodeMethods',
36
+ },
37
+ ],
38
+ },
39
+ loaded: {
40
+ on: {
41
+ SET_PROMOTION: {
42
+ target: 'debouncing',
43
+ actions: 'setPromotion',
44
+ },
45
+ SELECT_QRCODE: {
46
+ target: 'debouncing',
47
+ actions: 'setQrcode',
48
+ },
49
+ SELECT_AMOUNT: {
50
+ target: 'debouncing',
51
+ actions: 'setAmount',
52
+ },
53
+ INPUT_AMOUNT: {
54
+ target: 'debouncing',
55
+ actions: 'inputAmount',
56
+ },
57
+ },
58
+ },
59
+ debouncing: {
60
+ after: {
61
+ 1000: [
62
+ {
63
+ target: 'calculating',
64
+ cond: (context, event) => {
65
+ const { selectedQrcode, selectedAmount } = context
66
+ if (selectedQrcode && selectedAmount) {
67
+ return selectedQrcode.minimum <= selectedAmount && selectedAmount <= selectedQrcode.maximum
68
+ } else {
69
+ return false
70
+ }
71
+ },
72
+ },
73
+ {
74
+ target: 'loaded',
75
+ },
76
+ ],
77
+ },
78
+ on: {
79
+ SET_PROMOTION: {
80
+ target: 'debouncing',
81
+ actions: 'setPromotion',
82
+ },
83
+ SELECT_QRCODE: {
84
+ target: 'debouncing',
85
+ actions: 'setQrcode',
86
+ },
87
+ SELECT_AMOUNT: {
88
+ target: 'debouncing',
89
+ actions: 'setAmount',
90
+ },
91
+ INPUT_AMOUNT: {
92
+ target: 'debouncing',
93
+ actions: 'inputAmount',
94
+ },
95
+ },
96
+ },
97
+ calculating: {
98
+ invoke: {
99
+ src: 'fetchCalculation',
100
+ onDone: {
101
+ target: 'calculated',
102
+ actions: 'setCalculation',
103
+ },
104
+ onError: {
105
+ target: 'calculated',
106
+ },
107
+ },
108
+ },
109
+ calculated: {
110
+ on: {
111
+ SET_PROMOTION: {
112
+ target: 'debouncing',
113
+ actions: 'setPromotion',
114
+ },
115
+ SELECT_QRCODE: {
116
+ target: 'debouncing',
117
+ actions: 'setQrcode',
118
+ },
119
+ SELECT_AMOUNT: {
120
+ target: 'debouncing',
121
+ actions: 'setAmount',
122
+ },
123
+ INPUT_AMOUNT: {
124
+ target: 'debouncing',
125
+ actions: 'inputAmount',
126
+ },
127
+ SUBMIT: {
128
+ target: 'submitting',
129
+ },
130
+ },
131
+ },
132
+ submitting: {
133
+ invoke: {
134
+ src: 'submitDeposit',
135
+ onDone: {
136
+ target: 'submitted',
137
+ actions: 'setResult',
138
+ },
139
+ onError: {
140
+ target: 'calculated',
141
+ },
142
+ },
143
+ },
144
+ submitted: {},
145
+ },
146
+ },
147
+ {
148
+ actions: {
149
+ setInitData: assign((context, event) => {
150
+ const { paymentDetail, selectedAmount, promotion } = context
151
+ const qrcodes = paymentDetail
152
+ .filter((element) => element.category === context.currentCategory)
153
+ .map((qrcode) => {
154
+ qrcode.disabled = promotion?.promotionsNo !== 'none' && qrcode.charge > 0
155
+ return qrcode
156
+ })
157
+
158
+ const selectedQrcode = qrcodes.find((qrcode) => !qrcode.disabled)
159
+
160
+ return {
161
+ paymentDetail,
162
+ qrcodes,
163
+ selectedQrcode,
164
+ options: selectedQrcode?.optional,
165
+ selectedAmount: max(promotion?.minimumAmount, selectedQrcode?.minimum, selectedAmount, 0),
166
+ }
167
+ }),
168
+ setBonusPreview: assign((context, event) => {
169
+ return {
170
+ bonusPreviewData: event.data.bonus,
171
+ }
172
+ }),
173
+ setPromotion: assign((context, event) => {
174
+ const { selectedAmount } = context
175
+ const promotion = event.data
176
+ const qrcodes = context.qrcodes.map((qrcode) => {
177
+ qrcode.disabled = promotion.promotionsNo !== 'none' && qrcode.charge > 0
178
+ return qrcode
179
+ })
180
+
181
+ const selectedQrcode = qrcodes.find((qrcode) => !qrcode.disabled)
182
+
183
+ return {
184
+ promotion,
185
+ qrcodes,
186
+ selectedQrcode,
187
+ options: selectedQrcode?.optional,
188
+ selectedAmount: max(promotion.minimumAmount, selectedQrcode?.minimum, selectedAmount, 0),
189
+ calculation: null,
190
+ }
191
+ }),
192
+ setQrcode: assign((context, event) => {
193
+ const { promotion, selectedAmount } = context
194
+ const selectedQrcode = event.data
195
+ return {
196
+ selectedQrcode,
197
+ options: selectedQrcode.optional,
198
+ selectedAmount: max(promotion.minimumAmount, selectedAmount, 0),
199
+ calculation: null,
200
+ }
201
+ }),
202
+ setAmount: assign((context, event) => {
203
+ // 現金網可自由填額度,grandTotalEnable 欄位感覺不再需要?
204
+ if (context.selectedQrcode?.grandTotalEnable === 1) {
205
+ return { selectedAmount: parseFloat(context.selectedAmount || 0) + parseFloat(event.data) }
206
+ } else {
207
+ return { selectedAmount: event.data }
208
+ }
209
+ }),
210
+ inputAmount: assign((context, event) => {
211
+ return { selectedAmount: event.data }
212
+ }),
213
+ setCalculation: assign((context, event) => {
214
+ return {
215
+ calculation: event.data,
216
+ }
217
+ }),
218
+ clearCalculation: assign((context, event) => {
219
+ return {
220
+ calculation: null,
221
+ }
222
+ }),
223
+ setResult: assign((context, event) => {
224
+ return {
225
+ result: event.data,
226
+ }
227
+ }),
228
+ },
229
+ guards: {
230
+ hasQrcodeMethods: (context, event) => {
231
+ return context.paymentDetail?.filter((element) => element.category === context.currentCategory).length > 0
232
+ },
233
+ },
234
+ services: {
235
+ fetchCalculation: async (context, event) => {
236
+ const { selectedQrcode, selectedAmount, promotion } = context
237
+ return await request.send(
238
+ payment.getDepositExpectedResult({
239
+ method: selectedQrcode.method,
240
+ amount: selectedAmount,
241
+ promotionsNo: promotion?.promotionsNo,
242
+ })
243
+ )
244
+ },
245
+ submitDeposit: async (context, event) => {
246
+ const { selectedQrcode, selectedAmount, promotion } = context
247
+ return await request.send(
248
+ payment.submitDepositTransaction({
249
+ method: selectedQrcode.method,
250
+ amount: selectedAmount,
251
+ promotionsNo: promotion?.promotionsNo,
252
+ })
253
+ )
254
+ },
255
+ },
256
+ }
257
+ )
258
+ }
@@ -110,8 +110,12 @@ export default function (request) {
110
110
  }
111
111
  },
112
112
  fetchList: async (context, event) => {
113
- const { data } = await request.send(api.getListMyFavorite())
114
- return data
113
+ if (request.getToken()) {
114
+ const { data } = await request.send(api.getListMyFavorite())
115
+ return data
116
+ } else {
117
+ return []
118
+ }
115
119
  },
116
120
  },
117
121
  }
@@ -27,6 +27,7 @@ export default function (request) {
27
27
  timestamp: null,
28
28
  totalPage: 0,
29
29
  },
30
+ staticData: [],
30
31
  // play params
31
32
  game: {
32
33
  providerId: null,
@@ -47,6 +48,9 @@ export default function (request) {
47
48
  idle: {
48
49
  enter: 'clearGameInfo',
49
50
  on: {
51
+ SET_STATIC_DATA: {
52
+ actions: 'setStaticData',
53
+ },
50
54
  SET_ADDITION_ENABLE: {
51
55
  actions: 'setAdditionEnable',
52
56
  },
@@ -206,6 +210,11 @@ export default function (request) {
206
210
  },
207
211
  {
208
212
  actions: {
213
+ setStaticData: assign((context, event) => {
214
+ return {
215
+ staticData: event.data,
216
+ }
217
+ }),
209
218
  setAdditionEnable: assign((context, event) => {
210
219
  return {
211
220
  additionEnable: event.data,
@@ -222,11 +231,6 @@ export default function (request) {
222
231
  isLastPage: index >= content?.totalPage - 1,
223
232
  }
224
233
  }),
225
- setFavoriteList: assign((context, event) => {
226
- return {
227
- favoriteList: event.data.data || [],
228
- }
229
- }),
230
234
  setRoom: assign((context, event) => {
231
235
  return {
232
236
  room: event.data,
@@ -324,9 +328,19 @@ export default function (request) {
324
328
  },
325
329
  services: {
326
330
  getPageContent: async (context, event) => {
327
- const { room, index, additionEnable } = context
331
+ const { room, index, additionEnable, staticData } = context
328
332
  if (room.categoryId === GAME_SEARCH) {
329
333
  return
334
+ } else if (!request.getToken()) {
335
+ const list = staticData.find((data) => data.category == room.categoryId)?.info || []
336
+
337
+ return [
338
+ {
339
+ data: list.slice(index * 20, (index + 1) * 20),
340
+ totalPage: Math.ceil(list.length / 20),
341
+ timestamp: Math.floor(Date.now() / 1000),
342
+ },
343
+ ]
330
344
  } else if (additionEnable) {
331
345
  const param = { categoryId: room.categoryId, index }
332
346
  return await Promise.all([request.send(api.getListCategory(param)), request.send(api.getListAddition(param))])
@@ -339,6 +353,8 @@ export default function (request) {
339
353
  const { room, content, index, additionEnable } = context
340
354
  if (room.categoryId === GAME_SEARCH) {
341
355
  return
356
+ } else if (!request.getToken()) {
357
+ return []
342
358
  } else if (additionEnable) {
343
359
  return await Promise.all([
344
360
  request.send(
@@ -433,12 +449,22 @@ const oldGuards = {
433
449
 
434
450
  const oldServices = (request) => ({
435
451
  fetchOption: async (context, event) => {
436
- return await request.send(api.getOptionMap())
452
+ if (request.getToken()) {
453
+ return await request.send(api.getOptionMap())
454
+ }
437
455
  },
438
456
  fetchGameSHA: async (context, event) => {
439
- return await request.send(api.getGameSHA())
457
+ if (request.getToken()) {
458
+ return await request.send(api.getGameSHA())
459
+ } else {
460
+ return {
461
+ status: null,
462
+ }
463
+ }
440
464
  },
441
465
  fetchStatus: async (context, event) => {
442
- return await request.send(api.getGameStatus())
466
+ if (request.getToken()) {
467
+ return await request.send(api.getGameStatus())
468
+ }
443
469
  },
444
470
  })