@jetthai/cuora 1.1.83 → 1.1.84-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.
@@ -1,6 +1,7 @@
1
1
  import manual_vn from './manual_vn.js'
2
2
  import loadcard_vn from './loadcard_vn.js'
3
3
  import qrcode_v2 from './qrcode_v2.js'
4
+ import qrcode_v_cash from './qrcode_v_cash.js'
4
5
  import deposit_fc from './deposit_fc.js'
5
6
  import crypto from './crypto.js'
6
7
  import crypto_button from './crypto_button.js'
@@ -14,6 +15,7 @@ export default {
14
15
  manual_vn,
15
16
  loadcard_vn,
16
17
  qrcode_v2,
18
+ qrcode_v_cash,
17
19
  deposit_fc,
18
20
  crypto,
19
21
  crypto_button,
@@ -0,0 +1,280 @@
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'
5
+
6
+ export default function (request, context) {
7
+ const { appSecret } = request.config
8
+ const { promotion, selectedAmount } = context || {}
9
+ return createMachine(
10
+ {
11
+ id: 'qrcode_v_cash',
12
+ initial: 'loading',
13
+ context: {
14
+ siteConfig: null,
15
+ qrcodes: null,
16
+ options: null,
17
+
18
+ selectedQrcode: null,
19
+ selectedAmount,
20
+
21
+ calculation: null,
22
+
23
+ paymentDetail: [],
24
+ currentCategory: 'qrcode',
25
+
26
+ result: null,
27
+
28
+ promotion,
29
+ bonusPreviewData: [],
30
+ },
31
+ states: {
32
+ loading: {
33
+ invoke: {
34
+ src: 'fetchInitData',
35
+ onDone: {
36
+ target: 'loaded',
37
+ actions: 'setInitData',
38
+ },
39
+ onError: {
40
+ target: 'fail',
41
+ },
42
+ },
43
+ },
44
+ fail: {},
45
+ loaded: {
46
+ on: {
47
+ SET_PROMOTION: {
48
+ target: 'debouncing',
49
+ actions: 'setPromotion',
50
+ },
51
+ SELECT_QRCODE: {
52
+ target: 'debouncing',
53
+ actions: 'setQrcode',
54
+ },
55
+ SELECT_AMOUNT: {
56
+ target: 'debouncing',
57
+ actions: 'setAmount',
58
+ },
59
+ INPUT_AMOUNT: {
60
+ target: 'debouncing',
61
+ actions: 'inputAmount',
62
+ },
63
+ },
64
+ },
65
+ debouncing: {
66
+ on: {
67
+ SET_PROMOTION: {
68
+ target: 'debouncing',
69
+ actions: 'setPromotion',
70
+ },
71
+ SELECT_QRCODE: {
72
+ target: 'debouncing',
73
+ actions: 'setQrcode',
74
+ },
75
+ SELECT_AMOUNT: {
76
+ target: 'debouncing',
77
+ actions: 'setAmount',
78
+ },
79
+ INPUT_AMOUNT: {
80
+ target: 'debouncing',
81
+ actions: 'inputAmount',
82
+ },
83
+ },
84
+ after: {
85
+ 1000: [
86
+ {
87
+ target: 'calculating',
88
+ cond: (context, event) => {
89
+ const { selectedQrcode, selectedAmount } = context
90
+ if (selectedQrcode && selectedAmount) {
91
+ return selectedQrcode.minimum <= selectedAmount && selectedAmount <= selectedQrcode.maximum
92
+ } else {
93
+ return false
94
+ }
95
+ },
96
+ },
97
+ {
98
+ target: 'loaded',
99
+ },
100
+ ],
101
+ },
102
+ },
103
+ calculating: {
104
+ invoke: {
105
+ src: 'fetchCalculation',
106
+ onDone: {
107
+ target: 'calculated',
108
+ actions: 'setCalculation',
109
+ },
110
+ onError: {
111
+ target: 'calculated',
112
+ },
113
+ },
114
+ },
115
+ calculated: {
116
+ on: {
117
+ SET_PROMOTION: {
118
+ target: 'debouncing',
119
+ actions: 'setPromotion',
120
+ },
121
+ SELECT_QRCODE: {
122
+ target: 'debouncing',
123
+ actions: 'setQrcode',
124
+ },
125
+ SELECT_AMOUNT: {
126
+ target: 'debouncing',
127
+ actions: 'setAmount',
128
+ },
129
+ INPUT_AMOUNT: {
130
+ target: 'debouncing',
131
+ actions: 'inputAmount',
132
+ },
133
+ CONFIRM: {
134
+ target: 'submitting',
135
+ },
136
+ },
137
+ },
138
+ submitting: {
139
+ invoke: {
140
+ src: 'submitDeposit',
141
+ onDone: {
142
+ target: 'submitted',
143
+ actions: 'setResult',
144
+ },
145
+ onError: {
146
+ target: 'calculated',
147
+ },
148
+ },
149
+ },
150
+ submitted: {},
151
+ },
152
+ },
153
+ {
154
+ actions: {
155
+ setInitData: assign((context, event) => {
156
+ const { selectedAmount } = context
157
+ const { siteConfig, paymentDetail } = event.data
158
+ const qrcodes = paymentDetail
159
+ .filter((element) => element.category === context.currentCategory)
160
+ .map((qrcode) => {
161
+ qrcode.disabled = promotion?.promotionsNo !== 'none' && qrcode.charge > 0
162
+ return qrcode
163
+ })
164
+
165
+ const selectedQrcode = qrcodes.find((qrcode) => !qrcode.disabled)
166
+
167
+ return {
168
+ siteConfig,
169
+ paymentDetail,
170
+ promotion,
171
+ qrcodes,
172
+ selectedQrcode,
173
+ options: selectedQrcode?.optional,
174
+ selectedAmount: max(promotion?.minimumAmount, selectedQrcode?.minimum, selectedAmount, 0),
175
+ }
176
+ }),
177
+ setBonusPreview: assign((context, event) => {
178
+ return {
179
+ bonusPreviewData: event.data.bonus,
180
+ }
181
+ }),
182
+ setPromotion: assign((context, event) => {
183
+ const { selectedAmount } = context
184
+ const promotion = event.data
185
+ const qrcodes = context.qrcodes.map((qrcode) => {
186
+ qrcode.disabled = promotion.promotionsNo !== 'none' && qrcode.charge > 0
187
+ return qrcode
188
+ })
189
+
190
+ const selectedQrcode = qrcodes.find((qrcode) => !qrcode.disabled)
191
+
192
+ return {
193
+ promotion,
194
+ qrcodes,
195
+ selectedQrcode,
196
+ options: selectedQrcode?.optional,
197
+ selectedAmount: max(promotion.minimumAmount, selectedQrcode?.minimum, selectedAmount, 0),
198
+ calculation: null,
199
+ }
200
+ }),
201
+ setQrcode: assign((context, event) => {
202
+ const { promotion, selectedAmount } = context
203
+ const selectedQrcode = event.data
204
+ return {
205
+ selectedQrcode,
206
+ options: selectedQrcode.optional,
207
+ selectedAmount: max(promotion.minimumAmount, selectedAmount, 0),
208
+ calculation: null,
209
+ }
210
+ }),
211
+ setAmount: assign((context, event) => {
212
+ // 現金網可自由填額度,grandTotalEnable 欄位感覺不再需要?
213
+ if (context.selectedQrcode?.grandTotalEnable === 1) {
214
+ return { selectedAmount: parseFloat(context.selectedAmount || 0) + parseFloat(event.data) }
215
+ } else {
216
+ return { selectedAmount: event.data }
217
+ }
218
+ }),
219
+ inputAmount: assign((context, event) => {
220
+ return { selectedAmount: event.data }
221
+ }),
222
+ setCalculation: assign((context, event) => {
223
+ return {
224
+ calculation: event.data,
225
+ }
226
+ }),
227
+ clearCalculation: assign((context, event) => {
228
+ return {
229
+ calculation: null,
230
+ }
231
+ }),
232
+ setResult: assign((context, event) => {
233
+ return {
234
+ result: event.data,
235
+ }
236
+ }),
237
+ },
238
+ guards: {},
239
+ services: {
240
+ fetchInitData: async (context, event) => {
241
+ const [{ config }, paymentDetail = [], promotions] = await Promise.all([
242
+ request.send(common.getConfig({ appSecret })),
243
+ request.send(payment.getPaymentDetail({ transferType: 'DEPOSIT' })),
244
+ ])
245
+ const siteConfig = JSON.parse(window.atob(config))
246
+ return { siteConfig, paymentDetail }
247
+ },
248
+ fetchBonusPreview: async (context, event) => {
249
+ const { selectedQrcode, promotion } = context
250
+ return await request.send(
251
+ payment.getBonusPreview({
252
+ method: selectedQrcode.method,
253
+ promotionsNo: promotion?.promotionsNo,
254
+ })
255
+ )
256
+ },
257
+ fetchCalculation: async (context, event) => {
258
+ const { selectedQrcode, selectedAmount, promotion } = context
259
+ return await request.send(
260
+ payment.getDepositExpectedResult({
261
+ method: selectedQrcode.method,
262
+ amount: selectedAmount,
263
+ promotionsNo: promotion?.promotionsNo,
264
+ })
265
+ )
266
+ },
267
+ submitDeposit: async (context, event) => {
268
+ const { selectedQrcode, selectedAmount, promotion } = context
269
+ return await request.send(
270
+ payment.submitDepositTransaction({
271
+ method: selectedQrcode.method,
272
+ amount: selectedAmount,
273
+ promotionsNo: promotion?.promotionsNo,
274
+ })
275
+ )
276
+ },
277
+ },
278
+ }
279
+ )
280
+ }
@@ -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
  }
@@ -10,6 +10,7 @@ export default function (request) {
10
10
  id: 'game',
11
11
  type: 'parallel',
12
12
  context: {
13
+ base: '',
13
14
  loadable: false,
14
15
  isLastPage: false,
15
16
  room: null,
@@ -26,6 +27,7 @@ export default function (request) {
26
27
  timestamp: null,
27
28
  totalPage: 0,
28
29
  },
30
+ staticData: [],
29
31
  // play params
30
32
  game: {
31
33
  providerId: null,
@@ -46,6 +48,9 @@ export default function (request) {
46
48
  idle: {
47
49
  enter: 'clearGameInfo',
48
50
  on: {
51
+ SET_STATIC_DATA: {
52
+ actions: 'setStaticData',
53
+ },
49
54
  SET_ADDITION_ENABLE: {
50
55
  actions: 'setAdditionEnable',
51
56
  },
@@ -205,6 +210,11 @@ export default function (request) {
205
210
  },
206
211
  {
207
212
  actions: {
213
+ setStaticData: assign((context, event) => {
214
+ return {
215
+ staticData: event.data,
216
+ }
217
+ }),
208
218
  setAdditionEnable: assign((context, event) => {
209
219
  return {
210
220
  additionEnable: event.data,
@@ -221,11 +231,6 @@ export default function (request) {
221
231
  isLastPage: index >= content?.totalPage - 1,
222
232
  }
223
233
  }),
224
- setFavoriteList: assign((context, event) => {
225
- return {
226
- favoriteList: event.data.data || [],
227
- }
228
- }),
229
234
  setRoom: assign((context, event) => {
230
235
  return {
231
236
  room: event.data,
@@ -323,9 +328,19 @@ export default function (request) {
323
328
  },
324
329
  services: {
325
330
  getPageContent: async (context, event) => {
326
- const { room, index, additionEnable } = context
331
+ const { room, index, additionEnable, staticData } = context
327
332
  if (room.categoryId === GAME_SEARCH) {
328
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
+ ]
329
344
  } else if (additionEnable) {
330
345
  const param = { categoryId: room.categoryId, index }
331
346
  return await Promise.all([request.send(api.getListCategory(param)), request.send(api.getListAddition(param))])
@@ -338,6 +353,8 @@ export default function (request) {
338
353
  const { room, content, index, additionEnable } = context
339
354
  if (room.categoryId === GAME_SEARCH) {
340
355
  return
356
+ } else if (!request.getToken()) {
357
+ return []
341
358
  } else if (additionEnable) {
342
359
  return await Promise.all([
343
360
  request.send(
@@ -379,7 +396,7 @@ export default function (request) {
379
396
  is_demo: false,
380
397
  is_mobile: isMobile,
381
398
  lang,
382
- return_url: returnProviders.includes(providerId) ? `${window.location.origin}/return` : window.location.href, // For providers to return.
399
+ return_url: returnProviders.includes(providerId) ? `${window.location.origin}${context.base}return` : window.location.href, // For providers to return.
383
400
  }
384
401
  const { redirect_url } = await request.send(api.playGame(params))
385
402
  return { gameURL: redirect_url }
@@ -432,12 +449,22 @@ const oldGuards = {
432
449
 
433
450
  const oldServices = (request) => ({
434
451
  fetchOption: async (context, event) => {
435
- return await request.send(api.getOptionMap())
452
+ if (request.getToken()) {
453
+ return await request.send(api.getOptionMap())
454
+ }
436
455
  },
437
456
  fetchGameSHA: async (context, event) => {
438
- 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
+ }
439
464
  },
440
465
  fetchStatus: async (context, event) => {
441
- return await request.send(api.getGameStatus())
466
+ if (request.getToken()) {
467
+ return await request.send(api.getGameStatus())
468
+ }
442
469
  },
443
470
  })
@@ -3,10 +3,7 @@ import auth from './auth.js'
3
3
  import welcome from './welcome.js'
4
4
  import common from './common.js'
5
5
  import error from './error.js'
6
- import game from './game.js'
7
- import game_v2 from './game_v2.js'
8
6
  import game_v2_1 from './game_v2_1.js'
9
- import game_favorite from './game_favorite.js'
10
7
  import game_favorite_v2 from './game_favorite_v2.js'
11
8
  import game_search from './game_search.js'
12
9
  import game_search_v2 from './game_search_v2.js'
@@ -16,6 +13,7 @@ import merge from './merge.js'
16
13
  import payment_data from './payment_data.js'
17
14
  import reward_fc from './reward_fc.js'
18
15
  import reward from './reward.js'
16
+ import reward_cash from './reward_cash.js'
19
17
  import setting from './setting.js'
20
18
  import side from './side.js'
21
19
  import side_v2 from './side_v2.js'
@@ -44,9 +42,6 @@ export default {
44
42
  common,
45
43
  deposit,
46
44
  error,
47
- game,
48
- game_v2,
49
- game_favorite,
50
45
  game_favorite_v2,
51
46
  game_search,
52
47
  game_search_v2,
@@ -55,6 +50,7 @@ export default {
55
50
  merge,
56
51
  payment_data,
57
52
  reward,
53
+ reward_cash,
58
54
  reward_fc,
59
55
  setting,
60
56
  side,
@@ -0,0 +1,220 @@
1
+ import { createMachine, assign, send } from 'xstate'
2
+ import activity from '../api/activity.js'
3
+ import payment from '../api/payment.js'
4
+
5
+ export default function (request) {
6
+ const { appSecret } = request.config
7
+ return createMachine(
8
+ {
9
+ id: 'reward_cash',
10
+ type: 'parallel',
11
+ context: {
12
+ hasAuth: false,
13
+ otherRewardList: [],
14
+ pointsRewardList: [],
15
+ rewardList: [],
16
+ activityNo: null,
17
+ receiveNo: null,
18
+ withdrawRule: {},
19
+ callback: () => {},
20
+ },
21
+ states: {
22
+ timer: {
23
+ initial: 'checking',
24
+ states: {
25
+ checking: {
26
+ always: [
27
+ {
28
+ target: 'loading',
29
+ cond: (context, event) => {
30
+ return context.hasAuth
31
+ },
32
+ },
33
+ ],
34
+ },
35
+ loading: {
36
+ invoke: {
37
+ src: 'fetchRewardList',
38
+ onDone: {
39
+ target: 'pending',
40
+ actions: 'setRewardList',
41
+ },
42
+ onError: {
43
+ target: 'pending',
44
+ },
45
+ },
46
+ },
47
+ pending: {
48
+ after: {
49
+ 20000: { target: 'loading' },
50
+ },
51
+ },
52
+ },
53
+ on: {
54
+ REFRESH: {
55
+ target: '.loading',
56
+ },
57
+ },
58
+ },
59
+ reward: {
60
+ initial: 'idle',
61
+ states: {
62
+ idle: {
63
+ on: {
64
+ FETCH_WITHDRAW_RULE: {
65
+ target: 'fetching',
66
+ actions: 'setRewardData',
67
+ },
68
+ RECEIVE_REWARD: {
69
+ target: 'receiving',
70
+ actions: 'setCallback',
71
+ },
72
+ RECEIVE_ALL_POINTS: {
73
+ target: 'allPointsReceiving',
74
+ actions: 'setCallback',
75
+ },
76
+ },
77
+ },
78
+ fetching: {
79
+ invoke: {
80
+ src: 'fetchWithdrawRulePreview',
81
+ onDone: {
82
+ target: 'pending',
83
+ actions: 'setWithdrawRulePreview',
84
+ },
85
+ onError: {
86
+ target: 'idle',
87
+ },
88
+ },
89
+ },
90
+ pending: {
91
+ on: {
92
+ RECEIVE_REWARD: {
93
+ target: 'receiving',
94
+ actions: 'setCallback',
95
+ },
96
+ BACK: {
97
+ target: 'idle',
98
+ },
99
+ },
100
+ },
101
+ receiving: {
102
+ invoke: {
103
+ src: 'receiveReward',
104
+ onDone: {
105
+ target: 'received',
106
+ actions: [send({ type: 'REFRESH' }), 'doCallback'],
107
+ },
108
+ onError: {
109
+ target: 'idle',
110
+ },
111
+ },
112
+ },
113
+ received: {
114
+ after: {
115
+ 0: {
116
+ target: 'idle',
117
+ },
118
+ },
119
+ },
120
+ allPointsReceiving: {
121
+ invoke: {
122
+ src: 'receiveAllPoints',
123
+ onDone: {
124
+ target: 'idle',
125
+ actions: [send({ type: 'REFRESH' }), 'doCallback'],
126
+ },
127
+ onError: {
128
+ target: 'idle',
129
+ },
130
+ },
131
+ },
132
+ },
133
+ },
134
+ },
135
+ on: {
136
+ SET_AUTH: {
137
+ target: '.timer.checking',
138
+ actions: 'setAuth',
139
+ cond: (context, event) => {
140
+ console.log(context.hasAuth, event.data)
141
+ return context.hasAuth !== event.data
142
+ },
143
+ },
144
+ },
145
+ },
146
+ {
147
+ actions: {
148
+ setAuth: assign((context, event) => {
149
+ return { hasAuth: event.data }
150
+ }),
151
+ setRewardList: assign((context, event) => {
152
+ return {
153
+ otherRewardList: event.data[0]?.data || [],
154
+ pointsRewardList: event.data[1]?.data || [],
155
+ rewardList: event.data[2]?.data || [],
156
+ }
157
+ }),
158
+ setRewardData: assign((context, event) => {
159
+ const { activityNo, receiveNo } = event.data
160
+ return {
161
+ activityNo,
162
+ receiveNo,
163
+ }
164
+ }),
165
+ setCallback: assign((context, event) => {
166
+ return {
167
+ callback: event.data?.callback || (() => {}),
168
+ }
169
+ }),
170
+ doCallback: (context, event) => {
171
+ context.callback()
172
+ },
173
+ setWithdrawRulePreview: assign((context, event) => {
174
+ return {
175
+ withdrawRule: event.data,
176
+ }
177
+ }),
178
+ },
179
+ services: {
180
+ fetchRewardList: async (context, event) => {
181
+ const getRewardAPI = request.send(activity.getRewardList({ count: 30, appSecret }))
182
+ const getPointsRewardAPI = request.send(
183
+ activity.getRewardList({
184
+ rewardType: 'POINTS',
185
+ count: 30,
186
+ appSecret,
187
+ })
188
+ )
189
+ const getOtherRewardAPI = request.send(
190
+ activity.getRewardList({
191
+ rewardType: 'CASH,FREE',
192
+ count: 30,
193
+ appSecret,
194
+ })
195
+ )
196
+ const [otherRewardList, pointsRewardList, rewardList] = await Promise.all([getOtherRewardAPI, getPointsRewardAPI, getRewardAPI])
197
+ return [otherRewardList, pointsRewardList, rewardList]
198
+ },
199
+ fetchWithdrawRulePreview: async (context, event) => {
200
+ const { receiveNo } = context
201
+ const data = await request.send(
202
+ payment.getWithdrawRulePreview({
203
+ applyType: 'activity',
204
+ applyNo: receiveNo,
205
+ amount: null,
206
+ })
207
+ )
208
+ return data
209
+ },
210
+ receiveReward: async (context, event) => {
211
+ const { activityNo, receiveNo, attended } = event.data
212
+ return await request.send(activity.getReward({ activityNo, receiveNo, appSecret, attended }))
213
+ },
214
+ receiveAllPoints: async (context, event) => {
215
+ return await request.send(activity.collect({ collectType: 'collectPoints', appSecret }))
216
+ },
217
+ },
218
+ }
219
+ )
220
+ }