@jetthai/cuora 1.1.66-sabai-6 → 1.1.67

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,7 +1,9 @@
1
1
  import { assign, createMachine } from 'xstate'
2
2
  import payment from '../../api/payment.js'
3
+ import common from '../../api/common.js'
3
4
 
4
5
  export default function (request) {
6
+ const { appSecret } = request.config
5
7
  return createMachine(
6
8
  {
7
9
  id: 'vpay',
@@ -9,6 +11,7 @@ export default function (request) {
9
11
  context: {
10
12
  method: 'vpay',
11
13
  userAccount: {},
14
+ siteConfig: null,
12
15
  amount: 0,
13
16
 
14
17
  bankList: [],
@@ -23,6 +26,9 @@ export default function (request) {
23
26
  calculatedAmount: 0,
24
27
 
25
28
  grandTotalEnable: 1,
29
+
30
+ promotion: null,
31
+ bonusPreviewData: [],
26
32
  },
27
33
  states: {
28
34
  loading: {
@@ -53,7 +59,7 @@ export default function (request) {
53
59
  actions: ['setInitialization', 'setPreviousOrder'],
54
60
  cond: 'hasPreviousOrder',
55
61
  },
56
- { target: '#vpay.loaded', actions: 'setInitialization' },
62
+ { target: '#vpay.checking', actions: 'setInitialization' },
57
63
  ],
58
64
  onError: {
59
65
  target: '#vpay.unavailable',
@@ -62,6 +68,31 @@ export default function (request) {
62
68
  },
63
69
  },
64
70
  },
71
+ checking: {
72
+ always: [
73
+ {
74
+ target: 'fetching',
75
+ cond: (context, event) => {
76
+ const { siteConfig = {}, promotion = {} } = context
77
+ const { walletMode = '', bonusPreviewEnable = '0' } = siteConfig
78
+ return walletMode === '4' && bonusPreviewEnable === '1' && promotion.activityNo != 'none'
79
+ },
80
+ },
81
+ { target: 'loaded' },
82
+ ],
83
+ },
84
+ fetching: {
85
+ invoke: {
86
+ src: 'fetchBonusPreview',
87
+ onDone: {
88
+ target: 'loaded',
89
+ actions: 'setBonusPreview',
90
+ },
91
+ onError: {
92
+ target: 'loaded',
93
+ },
94
+ },
95
+ },
65
96
  loaded: {
66
97
  entry: 'reset',
67
98
  on: {
@@ -69,7 +100,7 @@ export default function (request) {
69
100
  {
70
101
  target: 'debouncing',
71
102
  actions: 'addAmount',
72
- cond: (context, event) => context.grandTotalEnable === 1,
103
+ cond: 'isGrandTotalEnable',
73
104
  },
74
105
  {
75
106
  target: 'debouncing',
@@ -80,6 +111,10 @@ export default function (request) {
80
111
  target: 'calculating',
81
112
  actions: 'setAmount',
82
113
  },
114
+ CLEAR_CALCULATION: {
115
+ target: 'debouncing',
116
+ actions: 'clearCalculation',
117
+ },
83
118
  },
84
119
  },
85
120
  debouncing: {
@@ -88,7 +123,7 @@ export default function (request) {
88
123
  {
89
124
  target: 'debouncing',
90
125
  actions: 'addAmount',
91
- cond: (context, event) => context.grandTotalEnable === 1,
126
+ cond: 'isGrandTotalEnable',
92
127
  },
93
128
  {
94
129
  target: 'debouncing',
@@ -99,9 +134,6 @@ export default function (request) {
99
134
  target: 'debouncing',
100
135
  actions: 'setAmount',
101
136
  },
102
- BACK: {
103
- target: 'loaded',
104
- },
105
137
  },
106
138
  after: {
107
139
  1000: {
@@ -116,7 +148,7 @@ export default function (request) {
116
148
  {
117
149
  target: 'debouncing',
118
150
  actions: 'addAmount',
119
- cond: (context, event) => context.grandTotalEnable === 1,
151
+ cond: 'isGrandTotalEnable',
120
152
  },
121
153
  {
122
154
  target: 'debouncing',
@@ -127,11 +159,12 @@ export default function (request) {
127
159
  target: 'debouncing',
128
160
  actions: 'setAmount',
129
161
  },
130
- CALCULATE: {
162
+ CLEAR_CALCULATION: {
131
163
  target: 'debouncing',
164
+ actions: 'clearCalculation',
132
165
  },
133
- BACK: {
134
- target: 'loaded',
166
+ CLEAR: {
167
+ actions: 'setAmount',
135
168
  },
136
169
  },
137
170
  },
@@ -153,7 +186,7 @@ export default function (request) {
153
186
  {
154
187
  target: 'debouncing',
155
188
  actions: 'addAmount',
156
- cond: (context, event) => context.grandTotalEnable === 1,
189
+ cond: 'isGrandTotalEnable',
157
190
  },
158
191
  {
159
192
  target: 'debouncing',
@@ -167,19 +200,22 @@ export default function (request) {
167
200
  CONFIRM: {
168
201
  target: 'submitting',
169
202
  },
170
- BACK: {
171
- target: 'loaded',
172
- },
173
203
  CLEAR_CALCULATION: {
174
204
  target: 'debouncing',
175
205
  actions: 'clearCalculation',
176
206
  },
207
+ CLEAR: {
208
+ actions: 'setAmount',
209
+ },
177
210
  },
178
211
  },
179
212
  submitting: {
180
213
  invoke: {
181
214
  src: 'submitDeposit',
182
- onDone: { target: 'submitted', actions: 'setOrder' },
215
+ onDone: {
216
+ target: 'submitted',
217
+ actions: 'setOrder',
218
+ },
183
219
  onError: {
184
220
  target: 'calculated',
185
221
  },
@@ -189,6 +225,11 @@ export default function (request) {
189
225
  accountUnbound: {},
190
226
  unavailable: {},
191
227
  },
228
+ on: {
229
+ SET_PROMOTION: {
230
+ actions: 'setPromotion',
231
+ },
232
+ },
192
233
  },
193
234
  {
194
235
  actions: {
@@ -197,6 +238,11 @@ export default function (request) {
197
238
  userAccount: event.data.bankInfo?.[0],
198
239
  }
199
240
  }),
241
+ setBonusPreview: assign((context, event) => {
242
+ return {
243
+ bonusPreviewData: event.data.bonus,
244
+ }
245
+ }),
200
246
  setOrder: assign((context, event) => {
201
247
  const { amount, qrcode, vpayId } = event.data
202
248
  return {
@@ -214,9 +260,10 @@ export default function (request) {
214
260
  }
215
261
  }),
216
262
  setInitialization: assign((context, event) => {
217
- const { housePayment, bankList } = event.data
263
+ const { siteConfig, housePayment, bankList } = event.data
218
264
  const { optional, minimum, maximum, grandTotalEnable } = housePayment
219
265
  return {
266
+ siteConfig,
220
267
  options: optional,
221
268
  minimum,
222
269
  maximum,
@@ -224,6 +271,12 @@ export default function (request) {
224
271
  grandTotalEnable,
225
272
  }
226
273
  }),
274
+ setPromotion: assign((context, event) => {
275
+ const promotion = event.data
276
+ return {
277
+ promotion,
278
+ }
279
+ }),
227
280
  addAmount: assign((context, event) => {
228
281
  const { amount, maximum } = context
229
282
  return {
@@ -233,11 +286,6 @@ export default function (request) {
233
286
  setAmount: assign((context, event) => {
234
287
  return { amount: event.data }
235
288
  }),
236
- clear: assign((context, event) => {
237
- return {
238
- amount: 0,
239
- }
240
- }),
241
289
  setCalculation: assign((context, event) => {
242
290
  return {
243
291
  calculation: event.data,
@@ -256,33 +304,48 @@ export default function (request) {
256
304
  hasPreviousOrder: (context, event) => {
257
305
  return event.data.order?.qrcode
258
306
  },
307
+ isGrandTotalEnable: (context, event) => {
308
+ return context.grandTotalEnable === 1
309
+ },
259
310
  },
260
311
  services: {
261
312
  fetchPaymentInfo: async (context, event) => {
262
313
  return await request.send(payment.getPaymentInfo())
263
314
  },
264
315
  initialize: async (context, event) => {
265
- const [payments, bankList, order] = await Promise.all([
316
+ const [{ config }, payments, bankList, order] = await Promise.all([
317
+ request.send(common.getConfig({ appSecret })),
266
318
  request.send(payment.getPaymentDetail({ transferType: 'DEPOSIT' })),
267
319
  request.send(payment.getBankList('amb')),
268
320
  request.send(payment.checkTransaction(context.method)),
269
321
  ])
270
- return { housePayment: payments.find((payment) => payment.method === context.method), bankList, order }
322
+ const siteConfig = JSON.parse(window.atob(config))
323
+ return { siteConfig, housePayment: payments.find((payment) => payment.method === context.method), bankList, order }
324
+ },
325
+ fetchBonusPreview: async (context, event) => {
326
+ const { method, promotion } = context
327
+ return await request.send({
328
+ paymentMethod: method,
329
+ promotionsNo: promotion?.activityNo,
330
+ })
271
331
  },
272
332
  submitDeposit: async (context, event) => {
273
- const { method, amount } = context
333
+ const { method, amount, promotion } = context
274
334
  return await request.send(
275
335
  payment.submitDepositTransaction({
276
336
  method,
277
337
  amount,
338
+ promotionsNo: promotion?.activityNo,
278
339
  })
279
340
  )
280
341
  },
281
342
  fetchCalculation: async (context, event) => {
343
+ const { method, amount, promotion } = context
282
344
  return await request.send(
283
345
  payment.getDepositExpectedResult({
284
- method: context.method,
285
- amount: context.amount,
346
+ method,
347
+ amount,
348
+ promotionsNo: promotion?.activityNo,
286
349
  })
287
350
  )
288
351
  },
@@ -10,26 +10,11 @@ export default function (request) {
10
10
  list: [],
11
11
  },
12
12
  states: {
13
- idle: {
14
- on: {
15
- ADD: {
16
- target: 'operation.adding.enable',
17
- actions: 'addToList',
18
- cond: 'isNotExist',
19
- },
20
- REMOVE: {
21
- target: 'operation.removing.enable',
22
- actions: 'removeFromList',
23
- cond: 'isExist',
24
- },
25
- },
26
- },
27
13
  fetching: {
28
14
  invoke: {
29
15
  src: 'fetchList',
30
16
  onDone: {
31
17
  actions: 'setList',
32
- target: '#favorite.idle',
33
18
  },
34
19
  onError: {
35
20
  actions: assign({ list: [] }),
@@ -46,12 +31,9 @@ export default function (request) {
46
31
  enable: {
47
32
  invoke: {
48
33
  src: 'add',
49
- onDone: {
50
- target: '#favorite.idle',
51
- },
34
+ onDone: {},
52
35
  onError: {
53
36
  actions: 'removeFromList',
54
- target: '#favorite.idle',
55
37
  },
56
38
  },
57
39
  },
@@ -64,12 +46,9 @@ export default function (request) {
64
46
  enable: {
65
47
  invoke: {
66
48
  src: 'remove',
67
- onDone: {
68
- target: '#favorite.idle',
69
- },
49
+ onDone: {},
70
50
  onError: {
71
51
  actions: 'addToList',
72
- target: '#favorite.idle',
73
52
  },
74
53
  },
75
54
  },
@@ -78,6 +57,18 @@ export default function (request) {
78
57
  },
79
58
  },
80
59
  },
60
+ on: {
61
+ ADD: {
62
+ target: 'operation.adding.enable',
63
+ actions: 'addToList',
64
+ cond: 'isNotExist',
65
+ },
66
+ REMOVE: {
67
+ target: 'operation.removing.enable',
68
+ actions: 'removeFromList',
69
+ cond: 'isExist',
70
+ },
71
+ },
81
72
  },
82
73
  {
83
74
  actions: {
@@ -37,7 +37,6 @@ export default function (request) {
37
37
  lang: 'en_US',
38
38
  isMobile: new UAParser().getResult().device.type,
39
39
  gameURL: null,
40
- inGaming: false,
41
40
  ...oldContext,
42
41
  },
43
42
  states: {
@@ -126,12 +125,15 @@ export default function (request) {
126
125
  states: {
127
126
  pending: {
128
127
  after: {
129
- 20000: [{ target: 'inGaming', cond: 'isInGaming' }, { target: 'updating', cond: 'hasRoom' }, { target: 'pending' }],
130
- },
131
- },
132
- inGaming: {
133
- after: {
134
- 3000: [{ target: 'inGaming', cond: 'isInGaming' }, { target: 'updating', cond: 'hasRoom' }, { target: 'pending' }],
128
+ 20000: [
129
+ {
130
+ target: 'updating',
131
+ cond: 'hasRoom',
132
+ },
133
+ {
134
+ target: 'pending',
135
+ },
136
+ ],
135
137
  },
136
138
  },
137
139
  updating: {
@@ -171,7 +173,7 @@ export default function (request) {
171
173
  src: 'fetchStatus',
172
174
  onDone: {
173
175
  target: 'updatingOption',
174
- actions: 'setStatus',
176
+ actions: ['setStatus'],
175
177
  },
176
178
  onError: {
177
179
  target: 'pending',
@@ -192,25 +194,14 @@ export default function (request) {
192
194
  },
193
195
  pending: {
194
196
  after: {
195
- 20000: [{ target: 'inGaming', cond: 'isInGaming' }, { target: 'fetchingGameSHA' }],
196
- },
197
- },
198
- inGaming: {
199
- after: {
200
- 3000: [{ target: 'inGaming', cond: 'isInGaming' }, { target: 'fetchingGameSHA' }],
197
+ 20000: {
198
+ target: 'fetchingGameSHA',
199
+ },
201
200
  },
202
201
  },
203
202
  },
204
203
  },
205
204
  },
206
- on: {
207
- SET_IN_GAME: {
208
- actions: 'setInGaming',
209
- },
210
- SET_LEAVE_GAME: {
211
- actions: 'setLeaveGame',
212
- },
213
- },
214
205
  },
215
206
  {
216
207
  actions: {
@@ -227,9 +218,15 @@ export default function (request) {
227
218
  setLastPage: assign((context, event) => {
228
219
  const { index, content } = context
229
220
  return {
221
+ loadable: false,
230
222
  isLastPage: index >= content?.totalPage - 1,
231
223
  }
232
224
  }),
225
+ setFavoriteList: assign((context, event) => {
226
+ return {
227
+ favoriteList: event.data.data || [],
228
+ }
229
+ }),
233
230
  setRoom: assign((context, event) => {
234
231
  return {
235
232
  room: event.data,
@@ -314,12 +311,6 @@ export default function (request) {
314
311
  const lang = event.data.locale.replace('-', '_')
315
312
  return { lang }
316
313
  }),
317
- setInGaming: assign((context, event) => {
318
- return { inGaming: true }
319
- }),
320
- setLeaveGame: assign((context, event) => {
321
- return { inGaming: false }
322
- }),
323
314
  ...oldActions,
324
315
  },
325
316
  guards: {
@@ -328,12 +319,7 @@ export default function (request) {
328
319
  const { loadable, isLastPage } = context
329
320
  return loadable && !isLastPage
330
321
  },
331
- hasRoom: (context, event) => {
332
- return context.room?.categoryId
333
- },
334
- isInGaming: (context, event) => {
335
- return context.inGaming
336
- },
322
+ hasRoom: (context, event) => context.room?.categoryId,
337
323
  ...oldGuards,
338
324
  },
339
325
  services: {
@@ -111,7 +111,7 @@ export default function (request) {
111
111
  }
112
112
  return {
113
113
  promotionsList,
114
- selectedPromo: noBonus,
114
+ selectedPromo: siteConfig?.walletMode === '4' ? promotionsList[0] : noBonus,
115
115
  }
116
116
  }),
117
117
  setSelectedPromo: assign((context, event) => {
@@ -12,7 +12,6 @@ export default function (request) {
12
12
  previousMenuItemStack: [],
13
13
  historyStack: [],
14
14
  defaultMenuItemStack: [],
15
- inGaming: false,
16
15
  },
17
16
  states: {
18
17
  loading: {
@@ -29,12 +28,15 @@ export default function (request) {
29
28
  states: {
30
29
  pending: {
31
30
  after: {
32
- 20000: [{ target: 'inGaming', cond: 'isInGaming' }, { target: 'updating', cond: 'isInMenu' }, { target: 'pending' }],
33
- },
34
- },
35
- inGaming: {
36
- after: {
37
- 3000: [{ target: 'inGaming', cond: 'isInGaming' }, { target: 'updating', cond: 'isInMenu' }, { target: 'pending' }],
31
+ 20000: [
32
+ {
33
+ target: 'updating',
34
+ cond: 'isInMenu',
35
+ },
36
+ {
37
+ target: 'pending',
38
+ },
39
+ ],
38
40
  },
39
41
  },
40
42
  updating: {
@@ -63,12 +65,6 @@ export default function (request) {
63
65
  RESET: {
64
66
  actions: 'resetMenuItemStack',
65
67
  },
66
- SET_IN_GAME: {
67
- actions: 'setInGame',
68
- },
69
- SET_LEAVE_GAME: {
70
- actions: 'setLeaveGame',
71
- },
72
68
  },
73
69
  },
74
70
  },
@@ -90,8 +86,8 @@ export default function (request) {
90
86
  setMenuItemStack: assign((context, event) => {
91
87
  const { menuItemStack } = context
92
88
  const inputItem = event.data
93
- const isTopItem = inputItem.level ? inputItem.level === 0 : true
94
- const hasSubMenu = inputItem.sub?.length || 0
89
+ const isTopItem = inputItem.level === 0
90
+ const hasSubMenu = inputItem.sub.length
95
91
 
96
92
  if (isTopItem) {
97
93
  if (hasSubMenu) {
@@ -144,24 +140,13 @@ export default function (request) {
144
140
  const { defaultMenuItemStack } = context
145
141
  return { menuItemStack: defaultMenuItemStack }
146
142
  }),
147
- setInGame: assign((context, event) => {
148
- return { inGaming: true }
149
- }),
150
- setLeaveGame: assign((context, event) => {
151
- return { inGaming: false }
152
- }),
153
143
  },
154
144
  guards: {
155
145
  isInMenu: (context, event) => {
156
146
  const { menuItemStack, menu } = context
157
- if (!menuItemStack || menuItemStack.length === 0) return false
158
147
  const menuItem = menuItemStack.slice(-1)[0]
159
- if (!menuItem || !menuItem.categoryId) return false
160
148
  return isItemInMenu(menuItem, menu.data)
161
149
  },
162
- isInGaming: (context, event) => {
163
- return context.inGaming
164
- },
165
150
  },
166
151
  services: {
167
152
  getMenu: async (context, event) => {
@@ -1,21 +1,19 @@
1
+ // import FingerprintJS from '@fingerprintjs/fingerprintjs-pro'
1
2
  import uniqBy from 'lodash/uniqBy'
2
- import { load, defaultEndpoint } from '../lib/fingerprint_v3_11_5.js'
3
+ import { load } from '../lib/fingerprint.js'
3
4
 
4
5
  const reg = /fnapi\d*/
6
+ // const reg = /(?<=https:\/\/)\w+(?=(\.\w+\.\w+))/
5
7
 
6
- const getDeviceToken = async ({ fpToken, sentry, hosts, enable = true }) => {
7
- if (!enable) {
8
- return
9
- }
10
-
8
+ const getDeviceToken = async ({ fpToken, sentry, hosts }) => {
11
9
  let dt, endpoints
12
10
  try {
13
11
  endpoints = uniqBy(
14
12
  hosts.map((host) => host.replace(reg, 'fp')),
15
13
  (url) => url
16
14
  )
17
-
18
- const fp = await load({ endpoint: [...endpoints, defaultEndpoint] })
15
+ // const fp = await FingerprintJS.load({ apiKey: fpToken, endpoint: endpoints })
16
+ const fp = await load({ endpoint: endpoints })
19
17
  const result = await fp.get({ timeout: 30000 })
20
18
  dt = result.visitorId
21
19
 
@@ -24,7 +22,6 @@ const getDeviceToken = async ({ fpToken, sentry, hosts, enable = true }) => {
24
22
  }
25
23
 
26
24
  console.log('[Device Token]', `${dt} from ${endpoints}`)
27
- sentry?.setTag('dt', dt)
28
25
  } catch (error) {
29
26
  console.error('[Device Token]', `${dt} from ${endpoints}`, error)
30
27
  sentry?.captureException(error)