@jetthai/cuora 1.1.342 → 1.1.343-dev-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.
@@ -49,7 +49,6 @@ export default function (request) {
49
49
  gameWalletType: null,
50
50
  switchGame: null,
51
51
  isPlaying: false,
52
- ...oldContext,
53
52
  },
54
53
  states: {
55
54
  flow: {
@@ -207,7 +206,6 @@ export default function (request) {
207
206
  actions: ['setIsPlaying', 'resetContent', 'resetSHA'],
208
207
  },
209
208
  LEAVE_GAME_REFRESH: {
210
- target: '#game.oldTimer',
211
209
  actions: 'setIsPlaying',
212
210
  },
213
211
  },
@@ -282,63 +280,6 @@ export default function (request) {
282
280
  },
283
281
  },
284
282
  },
285
- oldTimer: {
286
- initial: 'fetchingGameSHA',
287
- states: {
288
- fetchingGameSHA: {
289
- invoke: {
290
- src: 'fetchGameSHA',
291
- onDone: {
292
- target: 'checking',
293
- actions: 'setGameSHA',
294
- },
295
- onError: {
296
- target: 'pending',
297
- },
298
- },
299
- },
300
- checking: {
301
- always: [{ target: 'updatingStatus', cond: 'isStatusChanged' }, { target: 'pending' }],
302
- },
303
- updatingStatus: {
304
- invoke: {
305
- src: 'fetchStatus',
306
- onDone: {
307
- target: 'updatingOption',
308
- actions: ['setStatus'],
309
- },
310
- onError: {
311
- target: 'pending',
312
- },
313
- },
314
- },
315
- updatingOption: {
316
- invoke: {
317
- src: 'fetchOption',
318
- onDone: {
319
- target: 'pending',
320
- actions: 'mergeOption',
321
- },
322
- onError: {
323
- target: 'pending',
324
- },
325
- },
326
- },
327
- pending: {
328
- after: {
329
- 20000: [
330
- {
331
- target: 'fetchingGameSHA',
332
- cond: 'isNotInGame',
333
- },
334
- {
335
- target: 'pending',
336
- },
337
- ],
338
- },
339
- },
340
- },
341
- },
342
283
  },
343
284
  },
344
285
  {
@@ -455,9 +396,6 @@ export default function (request) {
455
396
  return event.data.gameWalletType
456
397
  },
457
398
  }),
458
- clearGameInfo: assign((context, event) => {
459
- return { game: { providerId: null, gameId: null, gameTypeId: null, mappingId: null } }
460
- }),
461
399
  setGameInfo: assign((context, event) => {
462
400
  const { providerId, gameId, gameTypeId, mappingId, portrait, gameCode, name } = event.data.game
463
401
  return { game: { providerId, gameId, gameTypeId, mappingId, portrait: portrait ? 1 : 0, gameCode, name } }
@@ -491,7 +429,6 @@ export default function (request) {
491
429
  isPlaying: event.data,
492
430
  }
493
431
  }),
494
- ...oldActions,
495
432
  },
496
433
  guards: {
497
434
  isDifferentRoom: (context, event) => context.room?.categoryId !== event.data?.categoryId,
@@ -500,13 +437,9 @@ export default function (request) {
500
437
  // 是否有下一頁
501
438
  return loadable && !isLastPage
502
439
  },
503
- isNotInGame: (context, event) => {
504
- return !context.isPlaying
505
- },
506
440
  hasRoomAndIsNotInGame: (context, event) => {
507
441
  return context.room?.categoryId && !context.isPlaying
508
442
  },
509
- ...oldGuards,
510
443
  },
511
444
  services: {
512
445
  batchFetch: async (context, event) => {
@@ -634,75 +567,7 @@ export default function (request) {
634
567
  const provider_id = context.game.providerId
635
568
  return await request.send(api.logoutGame({ uid_site, provider_id }))
636
569
  },
637
- ...oldServices(request),
638
570
  },
639
571
  }
640
572
  )
641
573
  }
642
-
643
- const oldContext = {
644
- sha: {
645
- status: null,
646
- },
647
- isStatusChanged: false,
648
- statusMap: {},
649
- optionMap: {},
650
- }
651
-
652
- const oldActions = {
653
- setGameSHA: assign((context, event) => {
654
- const { sha } = context
655
- const newSha = event.data
656
- return {
657
- sha: newSha,
658
- isStatusChanged: !sha.status || sha.status !== newSha.status,
659
- }
660
- }),
661
- setStatus: assign((context, event) => {
662
- return {
663
- statusMap: event.data,
664
- }
665
- }),
666
- mergeOption: assign((context, event) => {
667
- const { optionMap } = context
668
- return {
669
- optionMap: { ...optionMap, ...event.data },
670
- }
671
- }),
672
- resetSHA: assign((context, event) => {
673
- return {
674
- sha: {
675
- status: null,
676
- },
677
- isStatusChanged: false,
678
- statusMap: {},
679
- optionMap: {},
680
- }
681
- }),
682
- }
683
-
684
- const oldGuards = {
685
- isStatusChanged: (context, event) => context.isStatusChanged,
686
- }
687
-
688
- const oldServices = (request) => ({
689
- fetchOption: async (context, event) => {
690
- if (request.getToken()) {
691
- return await request.send(api.getOptionMap())
692
- }
693
- },
694
- fetchGameSHA: async (context, event) => {
695
- if (request.getToken()) {
696
- return await request.send(api.getGameSHA())
697
- } else {
698
- return {
699
- status: null,
700
- }
701
- }
702
- },
703
- fetchStatus: async (context, event) => {
704
- if (request.getToken()) {
705
- return await request.send(api.getGameStatus())
706
- }
707
- },
708
- })
@@ -39,6 +39,7 @@ import honor_board from './honor_board.js'
39
39
  import user_photo from './user_photo.js'
40
40
  import navbar from './navbar.js'
41
41
  import websocket from './websocket.js'
42
+ import dragon_tiger_ranking from './dragon_tiger_ranking.js'
42
43
 
43
44
  export default {
44
45
  ...activity,
@@ -82,4 +83,5 @@ export default {
82
83
  navbar,
83
84
  ...withdraw,
84
85
  websocket,
86
+ dragon_tiger_ranking,
85
87
  }
@@ -1,5 +1,6 @@
1
1
  import { assign, createMachine } from 'xstate'
2
2
  import common from '../api/common.js'
3
+ import game from '../api/game.js'
3
4
 
4
5
  export default function (request) {
5
6
  const { appSecret } = request.config
@@ -8,15 +9,35 @@ export default function (request) {
8
9
  id: 'navbar',
9
10
  initial: 'fetching',
10
11
  context: {
11
- navbar: null,
12
+ navbar: [],
13
+ gameCodes: [],
12
14
  },
13
15
  states: {
14
16
  fetching: {
15
17
  invoke: {
16
18
  src: 'fetchNavbar',
19
+ onDone: [
20
+ {
21
+ target: 'checking',
22
+ actions: ['setNavbar', 'filterGameCodes'],
23
+ cond: 'haveGames',
24
+ },
25
+ { target: 'idle' },
26
+ ],
27
+ onError: {
28
+ target: 'idle',
29
+ },
30
+ },
31
+ },
32
+ checking: {
33
+ always: [{ target: 'combinning', cond: (context, event) => context.gameCodes?.length > 0 }, { target: 'idle' }],
34
+ },
35
+ combinning: {
36
+ invoke: {
37
+ src: 'getGameInfo',
17
38
  onDone: {
18
39
  target: 'idle',
19
- actions: 'setNavbar',
40
+ actions: 'combindGames',
20
41
  },
21
42
  onError: {
22
43
  target: 'idle',
@@ -34,6 +55,47 @@ export default function (request) {
34
55
  navbar: navbarConfig.settings,
35
56
  }
36
57
  }),
58
+ filterGameCodes: assign((context, event) => {
59
+ const { navbar = [] } = context
60
+ const gameCodes = navbar.reduce((acc, item) => {
61
+ if (item.type.toLowerCase() === 'game' && item.gameCode) {
62
+ acc.push(item.gameCode)
63
+ }
64
+ return acc
65
+ }, [])
66
+
67
+ return { gameCodes }
68
+ }),
69
+ combindGames: assign((context, event) => {
70
+ const gameInfo = event.data?.data || []
71
+ const { navbar = [] } = context
72
+ const combindNavBar = navbar.map((item) => {
73
+ if (item.type.toLowerCase() === 'game') {
74
+ const currentGame = gameInfo.find((game) => game.gameCode === item.gameCode)
75
+ return {
76
+ ...item,
77
+ ...currentGame,
78
+ }
79
+ } else {
80
+ return item
81
+ }
82
+ })
83
+
84
+ return {
85
+ navbar: combindNavBar,
86
+ }
87
+ }),
88
+ },
89
+ guards: {
90
+ haveGames: (context, event) => {
91
+ const { navbarConfig = {} } = event.data
92
+ const { settings = [] } = navbarConfig
93
+ if (settings?.length) {
94
+ return settings.some((item) => item.type.toLowerCase() === 'game')
95
+ } else {
96
+ return false
97
+ }
98
+ },
37
99
  },
38
100
  services: {
39
101
  fetchNavbar: async (context, event) => {
@@ -51,6 +113,10 @@ export default function (request) {
51
113
  )
52
114
  return { navbarConfig: JSON.parse(decodeResult) }
53
115
  },
116
+ getGameInfo: async (context, event) => {
117
+ const { gameCodes } = context
118
+ return await request.send(game.getV3GameInfo({ appSecret, gameCodes }))
119
+ },
54
120
  },
55
121
  }
56
122
  )
@@ -273,6 +273,18 @@ export default function (request) {
273
273
  callback({ type: 'ACTIVITY_INFO', data })
274
274
  })
275
275
 
276
+ // 監聽 activity-reward-info 事件
277
+ clientSocket.on('activity-reward-info', (data) => {
278
+ console.log('[socket][activity-reward-info]:', data)
279
+ callback({ type: 'ACTIVITY_INFO', data })
280
+ })
281
+
282
+ // 監聽 message-notice-info 事件
283
+ clientSocket.on('message-notice-info', (data) => {
284
+ console.log('[socket][message-notice-info]:', data)
285
+ callback({ type: 'ACTIVITY_INFO', data })
286
+ })
287
+
276
288
  // 監聽 payment-info 事件
277
289
  clientSocket.on('payment-info', (data) => {
278
290
  console.log('[socket][payment-info]:', data, data.windowType)
@@ -1,288 +0,0 @@
1
- import { assign, createMachine } from 'xstate'
2
- import padStart from 'lodash/padStart.js'
3
- import payment from '@jetthai/cuora/src/api/payment.js'
4
- import common from '../../api/common.js'
5
-
6
- export default function (request) {
7
- const { appSecret } = request.config
8
- return createMachine(
9
- {
10
- id: 'crypto',
11
- initial: 'loading',
12
- context: {
13
- siteConfig: null,
14
- paymentDetails: [],
15
-
16
- channels: [],
17
- cryptos: [],
18
- networks: [],
19
- sourceAddress: '',
20
-
21
- amount: null,
22
- selectedChannel: null,
23
- selectedCrypto: null,
24
- selectedNetwork: null,
25
-
26
- currentCategory: 'crypto',
27
- currentPayment: null,
28
-
29
- calculation: null,
30
- result: null,
31
-
32
- // use for wallet mode 4
33
- promotion: null,
34
- },
35
- states: {
36
- loading: {
37
- invoke: {
38
- src: 'fetchInitData',
39
- onDone: {
40
- target: 'loaded',
41
- actions: 'setInitData',
42
- },
43
- onError: {
44
- target: '#crypto.fail',
45
- },
46
- },
47
- },
48
- loaded: {
49
- always: [{ target: 'debouncing', cond: 'isCalculable' }],
50
- },
51
- debouncing: {
52
- after: {
53
- 1000: {
54
- target: 'calculating',
55
- },
56
- },
57
- },
58
- calculating: {
59
- invoke: {
60
- src: 'fetchCalculation',
61
- onDone: {
62
- target: 'calculated',
63
- actions: 'setCalculation',
64
- },
65
- onError: {
66
- target: 'loaded',
67
- },
68
- },
69
- },
70
- calculated: {
71
- on: {
72
- SUBMIT: [
73
- {
74
- target: 'pending',
75
- cond: 'isDoubleWalletMode',
76
- },
77
- {
78
- target: 'submitting',
79
- cond: 'isSubmittable',
80
- },
81
- ],
82
- },
83
- },
84
- pending: {
85
- on: {
86
- SUBMIT: {
87
- target: 'submitting',
88
- cond: 'isSubmittable',
89
- },
90
- },
91
- },
92
- submitting: {
93
- invoke: {
94
- src: 'submitDeposit',
95
- onDone: {
96
- target: 'submitted',
97
- actions: 'setResult',
98
- },
99
- onError: {
100
- target: 'loaded',
101
- },
102
- },
103
- },
104
- submitted: {},
105
- fail: {},
106
- },
107
- on: {
108
- SET_CHANNEL: {
109
- target: '.loaded',
110
- actions: 'setChannel',
111
- },
112
- SET_CRYPTO: {
113
- target: '.loaded',
114
- actions: 'setCrypto',
115
- },
116
- SET_NETWORK: {
117
- target: '.loaded',
118
- actions: 'setNetwork',
119
- },
120
- SET_ADDRESS: {
121
- actions: 'setAddress',
122
- },
123
- SET_AMOUNT: {
124
- target: '.loaded',
125
- actions: ['setAmount', 'clearCalculation'],
126
- },
127
- CALCULATE: {
128
- target: '.debouncing',
129
- actions: 'clearCalculation',
130
- },
131
- },
132
- },
133
- {
134
- actions: {
135
- setInitData: assign((context, event) => {
136
- const { siteConfig, paymentDetail } = event.data
137
- const cryptos =
138
- paymentDetail
139
- .filter((element) => element.category === context.currentCategory)
140
- .map?.((crypto) => ({ ...crypto, label: crypto.channel, value: crypto.method, icon: crypto.channel })) || []
141
- const currentPayment = cryptos[0]
142
- const channels = cryptos.map((item, i) => ({ ...item, label: `Channel ${padStart(String(i + 1), 2, '0')}`, icon: 'channel' }))
143
- const defaultNetworks =
144
- cryptos[0].networkName.map((value, i) => {
145
- return {
146
- label: cryptos[0].networkOptional?.[i],
147
- value,
148
- icon: value,
149
- }
150
- }) || []
151
- return {
152
- siteConfig,
153
- channels,
154
- cryptos,
155
- networks: defaultNetworks,
156
- selectedChannel: channels[0],
157
- selectedCrypto: cryptos[0],
158
- selectedNetwork: defaultNetworks[0],
159
- currentPayment,
160
- }
161
- }),
162
- setChannel: assign((context, event) => {
163
- const { cryptos } = context
164
- const selectedCrypto = cryptos.find((crypto) => crypto.method === event.data.value)
165
- const networks =
166
- selectedCrypto?.networkName.map((value, i) => {
167
- return {
168
- label: selectedCrypto?.networkOptional?.[i],
169
- value,
170
- icon: value,
171
- }
172
- }) || []
173
- return {
174
- networks,
175
- selectedChannel: event.data,
176
- selectedCrypto: selectedCrypto,
177
- selectedNetwork: networks[0],
178
- amount: null,
179
- calculation: null,
180
- }
181
- }),
182
- setCrypto: assign((context, event) => {
183
- const { cryptos, selectedNetwork } = context
184
- const method = cryptos.find((crypto) => crypto.method === event.data.value)
185
- const networks =
186
- method?.networkName.map((value, i) => {
187
- return {
188
- label: method?.networkOptional?.[i],
189
- value,
190
- icon: value,
191
- }
192
- }) || []
193
-
194
- const properties = {
195
- selectedCrypto: event.data,
196
- networks,
197
- }
198
-
199
- if (!networks.includes(selectedNetwork)) {
200
- properties.selectedNetwork = null
201
- properties.amount = null
202
- properties.calculation = null
203
- }
204
-
205
- return properties
206
- }),
207
- setNetwork: assign((context, event) => {
208
- return { selectedNetwork: event.data }
209
- }),
210
- setAmount: assign((context, event) => {
211
- return {
212
- amount: event.data,
213
- }
214
- }),
215
- setAddress: assign((context, event) => {
216
- return {
217
- sourceAddress: event.data,
218
- }
219
- }),
220
- setCalculation: assign((context, event) => {
221
- return {
222
- calculation: event.data,
223
- }
224
- }),
225
- clearCalculation: assign((context, event) => {
226
- return {
227
- calculation: null,
228
- }
229
- }),
230
- setResult: assign((context, event) => {
231
- return {
232
- result: event.data,
233
- }
234
- }),
235
- },
236
- guards: {
237
- isDoubleWalletMode: (context, event) => {
238
- return context.siteConfig?.walletMode === '4'
239
- },
240
- isCalculable: (context, event) => {
241
- const {
242
- selectedCrypto,
243
- selectedNetwork,
244
- amount,
245
- currentPayment: { maximum, minimum },
246
- } = context
247
- return selectedCrypto && selectedNetwork && amount && minimum <= +amount && +amount <= maximum
248
- },
249
- isSubmittable: (context, event) => {
250
- const { selectedCrypto, selectedNetwork, amount } = context
251
- return selectedCrypto && selectedNetwork && amount
252
- },
253
- },
254
- services: {
255
- fetchInitData: async (context, event) => {
256
- const [{ config }, paymentDetail = []] = await Promise.all([
257
- request.send(common.getConfig({ appSecret })),
258
- request.send(payment.getPaymentDetail({ transferType: 'DEPOSIT' })),
259
- ])
260
- const siteConfig = JSON.parse(window.atob(config))
261
- return { siteConfig, paymentDetail }
262
- },
263
- fetchCalculation: async (context, event) => {
264
- const { selectedCrypto, amount } = context
265
- return await request.send(
266
- payment.getDepositExpectedResult({
267
- method: selectedCrypto.method,
268
- amount,
269
- cryptoCurrency: selectedCrypto.channel,
270
- })
271
- )
272
- },
273
- submitDeposit: async (context, event) => {
274
- const { selectedCrypto, selectedNetwork, calculation, sourceAddress } = context
275
- return await request.send(
276
- payment.submitDepositTransactionCrypto({
277
- method: selectedCrypto.method,
278
- amount: calculation.actualAmount,
279
- cryptoCurrency: selectedCrypto.channel,
280
- cryptoNetwork: selectedNetwork.value,
281
- sourceAddress: sourceAddress,
282
- })
283
- )
284
- },
285
- },
286
- }
287
- )
288
- }