@jetthai/cuora 1.0.24 → 1.0.26

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.
Files changed (51) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/api/activity.js +46 -0
  3. package/api/auth.js +15 -0
  4. package/api/common.js +4 -0
  5. package/api/game.js +32 -0
  6. package/api/index.js +9 -0
  7. package/api/mailbox.js +20 -0
  8. package/api/payment.js +63 -0
  9. package/api/user.js +19 -0
  10. package/index.js +3 -58
  11. package/machine/activity/activity.js +73 -0
  12. package/machine/activity/continue_deposit_activity.js +132 -0
  13. package/machine/activity/deposit_activity.js +86 -0
  14. package/machine/activity/diamond_shop_activity.js +163 -0
  15. package/machine/activity/fafafa_activity.js +131 -0
  16. package/machine/activity/index.js +21 -0
  17. package/machine/activity/invite_friends_activity.js +121 -0
  18. package/machine/activity/ranking_activity.js +76 -0
  19. package/machine/activity/return_bonus_activity.js +150 -0
  20. package/machine/activity/specify_bets_activity.js +116 -0
  21. package/machine/auth.js +245 -0
  22. package/machine/auth_otp.js +191 -0
  23. package/machine/check.js +113 -0
  24. package/machine/common.js +163 -0
  25. package/machine/deposit.js +236 -0
  26. package/machine/error.js +72 -0
  27. package/machine/game.js +265 -0
  28. package/machine/game_favorite.js +123 -0
  29. package/machine/game_search.js +248 -0
  30. package/machine/inbox.js +246 -0
  31. package/machine/index.js +37 -0
  32. package/machine/merge.js +57 -0
  33. package/machine/payment_data.js +81 -0
  34. package/machine/reward.js +73 -0
  35. package/machine/setting.js +37 -0
  36. package/machine/side.js +147 -0
  37. package/machine/withdraw.js +367 -0
  38. package/package.json +3 -2
  39. package/request/config.js +18 -0
  40. package/request/cookie.js +52 -0
  41. package/request/request.js +97 -0
  42. package/plugin/activity.js +0 -289
  43. package/plugin/core.js +0 -518
  44. package/plugin/game.js +0 -474
  45. package/plugin/inbox.js +0 -216
  46. package/plugin/information.js +0 -57
  47. package/plugin/job/network.js +0 -61
  48. package/plugin/payment.js +0 -257
  49. package/plugin/request.js +0 -225
  50. package/plugin/search.js +0 -277
  51. package/plugin/user.js +0 -198
@@ -0,0 +1,163 @@
1
+ import UAParser from 'ua-parser-js'
2
+ import { assign, createMachine } from 'xstate'
3
+ import api from '../api/common'
4
+
5
+ export default function (request) {
6
+ const { appSecret } = request.config
7
+ return createMachine(
8
+ {
9
+ id: 'common',
10
+ type: 'parallel',
11
+ context: {
12
+ tick: 2000,
13
+ siteConfig: {
14
+ cs: {
15
+ lineat: null,
16
+ },
17
+ loginMethods: {},
18
+ forceValidation: '0',
19
+ urls: {
20
+ widget: null,
21
+ },
22
+ competitionLab: {
23
+ achievements: false,
24
+ },
25
+ paymentMethods: {},
26
+ },
27
+ ua: '',
28
+ isMobile: false,
29
+ announcementList: null,
30
+ broadcastList: null,
31
+ mailBoxInfo: null,
32
+ promotions: [],
33
+ currentBroadcast: null,
34
+ sentBroadcastList: [],
35
+ },
36
+ states: {
37
+ config: {
38
+ initial: 'fetching',
39
+ states: {
40
+ idle: {
41
+ on: {
42
+ FETCH_SITE_CONFIG: {
43
+ target: 'fetching',
44
+ },
45
+ },
46
+ },
47
+ fetching: {
48
+ entry: 'setUA',
49
+ invoke: {
50
+ src: 'fetchSiteConfig',
51
+ onDone: {
52
+ target: 'idle',
53
+ actions: 'setSiteConfig',
54
+ },
55
+ onError: {
56
+ target: 'idle',
57
+ },
58
+ },
59
+ },
60
+ },
61
+ },
62
+ feed: {
63
+ initial: 'updating',
64
+ states: {
65
+ updating: {
66
+ invoke: {
67
+ src: 'fetchFeeds',
68
+ onDone: {
69
+ target: 'waiting',
70
+ actions: 'setFeeds',
71
+ },
72
+ onError: {
73
+ target: 'waiting',
74
+ },
75
+ },
76
+ },
77
+ waiting: {
78
+ after: {
79
+ TIMEOUT: {
80
+ target: 'updating',
81
+ },
82
+ },
83
+ },
84
+ },
85
+ },
86
+ broadcast: {
87
+ initial: 'idle',
88
+ states: {
89
+ idle: {
90
+ on: {
91
+ START_BROADCAST: {
92
+ target: 'picking',
93
+ },
94
+ },
95
+ },
96
+ picking: {
97
+ after: {
98
+ 5000: {
99
+ target: 'display',
100
+ actions: 'setBroadcast',
101
+ },
102
+ },
103
+ },
104
+ display: {
105
+ after: {
106
+ 5000: {
107
+ target: 'picking',
108
+ },
109
+ },
110
+ },
111
+ },
112
+ },
113
+ },
114
+ },
115
+ {
116
+ delays: {
117
+ TIMEOUT: (context, event) => {
118
+ return context.tick * 10
119
+ },
120
+ },
121
+ actions: {
122
+ setSiteConfig: assign((context, event) => {
123
+ return {
124
+ siteConfig: event.data,
125
+ }
126
+ }),
127
+ setUA: assign((context, event) => {
128
+ const parser = new UAParser()
129
+ const ua = parser.getResult()
130
+ return {
131
+ ua,
132
+ isMobile: ua?.device?.type,
133
+ }
134
+ }),
135
+ setFeeds: assign((context, event) => {
136
+ const { announcementList, broadcastList, mailBoxInfo } = event.data
137
+ const promotions = announcementList?.announcements?.filter?.((item) => item.category === 3) || []
138
+ return { announcementList, broadcastList, mailBoxInfo, promotions }
139
+ }),
140
+ setBroadcast: assign((context, event) => {
141
+ const { broadcastList, sentBroadcastList, currentBroadcast } = context
142
+ let sentList = sentBroadcastList
143
+ if (currentBroadcast) {
144
+ sentList = [...sentBroadcastList, currentBroadcast]
145
+ }
146
+ const nextBroadcast = broadcastList?.broadcasts?.find((broadcast) => {
147
+ return broadcast.type === '1' && !sentList.some((item) => item.broadcast_id === broadcast.broadcast_id)
148
+ })
149
+ return { currentBroadcast: nextBroadcast, sentBroadcastList: sentList }
150
+ }),
151
+ },
152
+ services: {
153
+ fetchSiteConfig: async (context, event) => {
154
+ const { config } = await request.send(api.getConfig({ appSecret }))
155
+ return JSON.parse(window.atob(config))
156
+ },
157
+ fetchFeeds: async (context, event) => {
158
+ return await request.send(api.feeds({ appSecret }))
159
+ },
160
+ },
161
+ }
162
+ )
163
+ }
@@ -0,0 +1,236 @@
1
+ import { assign, createMachine } from 'xstate'
2
+ import toNumber from 'lodash/toNumber'
3
+ import payment from '../api/payment'
4
+
5
+ export default function (request) {
6
+ return createMachine(
7
+ {
8
+ id: 'deposit',
9
+ initial: 'loading',
10
+ context: {
11
+ cryptos: [],
12
+ networks: [],
13
+ currentCrypto: null,
14
+ currentNetwork: null,
15
+ currentAmount: null,
16
+ calculatedResult: null,
17
+ submittedResult: null,
18
+ bonus: null,
19
+ },
20
+ states: {
21
+ loading: {
22
+ initial: 'bonusStatus',
23
+ states: {
24
+ bonusStatus: {
25
+ invoke: {
26
+ src: 'getPaymentInfo',
27
+ onDone: {
28
+ target: 'fetchingPayments',
29
+ actions: 'setBonus',
30
+ },
31
+ onError: {
32
+ target: '#deposit.loaded',
33
+ },
34
+ },
35
+ },
36
+ fetchingPayments: {
37
+ invoke: {
38
+ src: 'fetchPayments',
39
+ onDone: {
40
+ target: '#deposit.loaded',
41
+ actions: 'setCryptos',
42
+ },
43
+ onError: {
44
+ target: '#deposit.loaded',
45
+ },
46
+ },
47
+ },
48
+ },
49
+ },
50
+ loaded: {
51
+ on: {
52
+ SUBMIT: {
53
+ target: 'submitting',
54
+ cond: 'isSubmittable',
55
+ },
56
+ },
57
+ },
58
+ checking: {
59
+ always: [{ target: 'debouncing', cond: 'isCalculable' }, { target: 'loaded' }],
60
+ },
61
+ debouncing: {
62
+ after: {
63
+ 1000: {
64
+ target: 'calculating',
65
+ },
66
+ },
67
+ },
68
+ calculating: {
69
+ invoke: {
70
+ src: 'fetchCalculation',
71
+ onDone: {
72
+ target: 'loaded',
73
+ actions: 'setCalculatedResult',
74
+ },
75
+ onError: {
76
+ target: 'loaded',
77
+ },
78
+ },
79
+ },
80
+ submitting: {
81
+ invoke: {
82
+ src: 'submitDeposit',
83
+ onDone: {
84
+ target: '#deposit.submitted',
85
+ actions: 'setSubmittedResult',
86
+ },
87
+ onError: {
88
+ target: 'loaded',
89
+ },
90
+ },
91
+ },
92
+ switchingBonus: {
93
+ invoke: {
94
+ src: 'setBonusSetting',
95
+ onDone: {
96
+ target: 'checking',
97
+ },
98
+ onError: {
99
+ target: 'loaded',
100
+ },
101
+ },
102
+ },
103
+ submitted: {},
104
+ },
105
+ on: {
106
+ SET_CRYPTO: {
107
+ target: 'checking',
108
+ actions: 'setCrypto',
109
+ cond: 'hasCryptoOptions',
110
+ },
111
+ SET_NETWORK: {
112
+ target: 'checking',
113
+ actions: 'setNetwork',
114
+ cond: 'hasNetworkOptions',
115
+ },
116
+ SET_AMOUNT: {
117
+ target: 'checking',
118
+ actions: 'setAmount',
119
+ },
120
+ TOGGLE_BONUS: {
121
+ target: 'switchingBonus',
122
+ actions: 'toggleBonus',
123
+ },
124
+ },
125
+ },
126
+ {
127
+ actions: {
128
+ setCryptos: assign((context, event) => {
129
+ return {
130
+ cryptos: event.data,
131
+ }
132
+ }),
133
+ setCrypto: assign((context, event) => {
134
+ const { cryptos, currentNetwork } = context
135
+ const networks = cryptos.find((method) => method.channel === event.data)?.optional || []
136
+
137
+ const properties = {
138
+ currentCrypto: event.data,
139
+ networks,
140
+ }
141
+
142
+ if (!networks.includes(currentNetwork)) {
143
+ properties.currentNetwork = null
144
+ properties.currentAmount = null
145
+ properties.calculatedResult = null
146
+ }
147
+
148
+ return properties
149
+ }),
150
+ setNetwork: assign((context, event) => {
151
+ return { currentNetwork: event.data }
152
+ }),
153
+ setAmount: assign((context, event) => {
154
+ return {
155
+ currentAmount: event.data,
156
+ }
157
+ }),
158
+ setCalculatedResult: assign((context, event) => {
159
+ return {
160
+ calculatedResult: event.data,
161
+ }
162
+ }),
163
+ setSubmittedResult: assign((context, event) => {
164
+ return {
165
+ submittedResult: event.data,
166
+ }
167
+ }),
168
+ toggleBonus: assign((context, event) => {
169
+ const { bonus } = context
170
+ return {
171
+ bonus: bonus === 1 ? 0 : 1,
172
+ }
173
+ }),
174
+ setBonus: assign((context, event) => {
175
+ return {
176
+ bonus: event.data,
177
+ }
178
+ }),
179
+ },
180
+ guards: {
181
+ hasCryptoOptions: (context, evnet) => {
182
+ return context.cryptos.length > 0
183
+ },
184
+ hasNetworkOptions: (context, evnet) => {
185
+ return context.networks.length > 0
186
+ },
187
+ isCalculable: (context, event) => {
188
+ const { currentCrypto, currentNetwork, currentAmount } = context
189
+ return currentCrypto && currentNetwork && toNumber(currentAmount)
190
+ },
191
+ isSubmittable: (context, event) => {
192
+ return context.calculatedResult
193
+ },
194
+ isBonusOff: (context, event) => {
195
+ return context.bonus !== 1
196
+ },
197
+ },
198
+ services: {
199
+ fetchPayments: async (context, event) => {
200
+ return await request.send(payment.getPaymentDetail({ transferType: 'DEPOSIT' }))
201
+ },
202
+ fetchCalculation: async (context, event) => {
203
+ const { cryptos, currentCrypto, currentAmount } = context
204
+ const method = cryptos.find((crypto) => crypto.channel === currentCrypto)?.method
205
+ return await request.send(
206
+ payment.getDepositExpectedResult({
207
+ method,
208
+ amount: currentAmount,
209
+ cryptoCurrency: currentCrypto,
210
+ })
211
+ )
212
+ },
213
+ submitDeposit: async (context, event) => {
214
+ const { cryptos, currentCrypto, currentNetwork, calculatedResult } = context
215
+ const method = cryptos.find((crypto) => crypto.channel === currentCrypto)?.method
216
+ return await request.send(
217
+ payment.submitDepositTransaction({
218
+ method,
219
+ amount: calculatedResult.actualAmount,
220
+ cryptoCurrency: currentCrypto,
221
+ cryptoNetwork: currentNetwork,
222
+ })
223
+ )
224
+ },
225
+ setBonusSetting: async (context, event) => {
226
+ const { bonus } = context
227
+ return await request.send(payment.setBonusSetting({ bonus }))
228
+ },
229
+ getPaymentInfo: async (context, event) => {
230
+ const { bonus } = await request.send(payment.getPaymentInfo())
231
+ return bonus
232
+ },
233
+ },
234
+ }
235
+ )
236
+ }
@@ -0,0 +1,72 @@
1
+ import { assign, createMachine } from 'xstate'
2
+
3
+ export default function () {
4
+ return createMachine(
5
+ {
6
+ id: 'error',
7
+ initial: 'normal',
8
+ context: {
9
+ error: null,
10
+ gameCode: null,
11
+ },
12
+ states: {
13
+ normal: {
14
+ on: {
15
+ SET_ERROR: {
16
+ target: 'error',
17
+ actions: 'setError',
18
+ },
19
+ },
20
+ },
21
+ error: {
22
+ initial: 'unknown',
23
+ states: {
24
+ unknown: {
25
+ always: [
26
+ { target: 'logout', cond: 'isLogout' },
27
+ { target: 'deposit', cond: 'isNoBalance' },
28
+ { target: 'unfinishedGame', cond: 'isUnfinishedGame', actions: 'setUnfinishedGame' },
29
+ { target: 'hall' },
30
+ ],
31
+ },
32
+ logout: {},
33
+ deposit: {},
34
+ unfinishedGame: {},
35
+ hall: {},
36
+ },
37
+ },
38
+ },
39
+ on: {
40
+ SOLVE: {
41
+ target: 'normal',
42
+ actions: 'solveError',
43
+ },
44
+ },
45
+ },
46
+ {
47
+ actions: {
48
+ setError: assign((context, event) => {
49
+ return { error: event.data }
50
+ }),
51
+ solveError: assign({ error: null }),
52
+ setUnfinishedGame: assign((context, event) => {
53
+ return {
54
+ gameCode: context.error.extend.split(/_(.+)/)[1],
55
+ }
56
+ }),
57
+ },
58
+ guards: {
59
+ isLogout: (context, event) => {
60
+ return ['ERR_A201', 'ERR_A204', 'ERR_A103', 'ERR_A104', 'ERR_A108', 'ERR_F108'].includes(context.error.code)
61
+ },
62
+ isNoBalance: (context, event) => {
63
+ return context.error.code === 'ERR_G106'
64
+ },
65
+ isUnfinishedGame: (context, event) => {
66
+ return context.error.extend?.includes?.('unfinished_')
67
+ },
68
+ },
69
+ services: {},
70
+ }
71
+ )
72
+ }