@jetthai/cuora 1.1.343-depositEvent-1 → 1.1.343-dev-2

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.
@@ -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
  )
@@ -176,22 +176,19 @@ export default function (request) {
176
176
  }),
177
177
  pushEvent: assign((context, value) => {
178
178
  const { analytics } = context
179
- const { data, event, isTracking } = value.data
180
- if (isTracking) {
181
- analytics?.push(
182
- {
183
- event: event,
184
- paymentMethod: data.paymentMethod,
185
- transaction_id: data.transactionId,
186
- currency: data.currency,
187
- value: data.value,
188
- app_value: data.value,
189
- },
190
- { eventID: data.transactionId }
191
- )
192
- }
193
-
194
- if (event === 'purchase' && data?.isFirst === true && isTracking) {
179
+ const { data, event } = value.data
180
+ analytics?.push(
181
+ {
182
+ event: event,
183
+ paymentMethod: data.paymentMethod,
184
+ transaction_id: data.transactionId,
185
+ currency: data.currency,
186
+ value: data.value,
187
+ app_value: data.value,
188
+ },
189
+ { eventID: data.transactionId }
190
+ )
191
+ if (event === 'purchase' && data?.isFirst === true) {
195
192
  analytics?.push(
196
193
  {
197
194
  event: 'first_deposit',
@@ -274,12 +271,23 @@ export default function (request) {
274
271
  clientSocket.on('activity-info', (data) => {
275
272
  console.log('[socket][activity-info]:', data)
276
273
  callback({ type: 'ACTIVITY_INFO', data })
277
- callback({ type: 'PUSH_ANALYTICS', data })
274
+ })
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 })
278
286
  })
279
287
 
280
288
  // 監聽 payment-info 事件
281
289
  clientSocket.on('payment-info', (data) => {
282
- console.log('[socket][payment-info]:', data)
290
+ console.log('[socket][payment-info]:', data, data.windowType)
283
291
  if (data.windowType === 'toast') {
284
292
  callback({ type: 'ACTIVITY_INFO', data })
285
293
  }
@@ -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
- }