@jetthai/cuora 1.0.25 → 1.0.27

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 (55) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/dist/index.js +2 -0
  3. package/dist/index.js.LICENSE.txt +30 -0
  4. package/package.json +10 -4
  5. package/src/api/activity.js +46 -0
  6. package/src/api/auth.js +15 -0
  7. package/src/api/common.js +4 -0
  8. package/src/api/game.js +32 -0
  9. package/src/api/index.js +9 -0
  10. package/src/api/mailbox.js +20 -0
  11. package/src/api/payment.js +63 -0
  12. package/src/api/user.js +19 -0
  13. package/src/index.js +6 -0
  14. package/src/machine/activity/activity.js +73 -0
  15. package/src/machine/activity/continue_deposit_activity.js +132 -0
  16. package/src/machine/activity/deposit_activity.js +86 -0
  17. package/src/machine/activity/diamond_shop_activity.js +163 -0
  18. package/src/machine/activity/fafafa_activity.js +131 -0
  19. package/src/machine/activity/index.js +21 -0
  20. package/src/machine/activity/invite_friends_activity.js +121 -0
  21. package/src/machine/activity/ranking_activity.js +76 -0
  22. package/src/machine/activity/return_bonus_activity.js +150 -0
  23. package/src/machine/activity/specify_bets_activity.js +116 -0
  24. package/src/machine/auth.js +245 -0
  25. package/src/machine/auth_otp.js +191 -0
  26. package/src/machine/check.js +113 -0
  27. package/src/machine/common.js +163 -0
  28. package/src/machine/deposit.js +236 -0
  29. package/src/machine/error.js +72 -0
  30. package/src/machine/game.js +265 -0
  31. package/src/machine/game_favorite.js +123 -0
  32. package/src/machine/game_search.js +248 -0
  33. package/src/machine/inbox.js +246 -0
  34. package/src/machine/index.js +37 -0
  35. package/src/machine/merge.js +57 -0
  36. package/src/machine/payment_data.js +81 -0
  37. package/src/machine/reward.js +73 -0
  38. package/src/machine/setting.js +37 -0
  39. package/src/machine/side.js +147 -0
  40. package/src/machine/withdraw.js +367 -0
  41. package/src/request/config.js +18 -0
  42. package/src/request/cookie.js +52 -0
  43. package/src/request/request.js +97 -0
  44. package/webpack.config.js +19 -0
  45. package/index.js +0 -58
  46. package/plugin/activity.js +0 -289
  47. package/plugin/core.js +0 -518
  48. package/plugin/game.js +0 -474
  49. package/plugin/inbox.js +0 -216
  50. package/plugin/information.js +0 -57
  51. package/plugin/job/network.js +0 -61
  52. package/plugin/payment.js +0 -257
  53. package/plugin/request.js +0 -225
  54. package/plugin/search.js +0 -277
  55. package/plugin/user.js +0 -198
@@ -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
+ }
@@ -0,0 +1,265 @@
1
+ import { assign, createMachine } from 'xstate'
2
+ import api from '../api/game'
3
+
4
+ export default function (request) {
5
+ return createMachine(
6
+ {
7
+ id: 'game',
8
+ type: 'parallel',
9
+ context: {
10
+ roomId: null,
11
+ list: [],
12
+ game: {
13
+ provider: null,
14
+ game_id: null,
15
+ game_type: null,
16
+ mapping_id: null,
17
+ },
18
+ lang: 'en_US',
19
+ gameURL: null,
20
+ tick: 2000,
21
+ isMobile: false,
22
+ // game database
23
+ sha: {
24
+ category: null,
25
+ status: null,
26
+ },
27
+ isCategoryChanged: false,
28
+ isStatusChanged: false,
29
+ statusMap: {},
30
+ optionMap: {},
31
+ },
32
+ states: {
33
+ flow: {
34
+ initial: 'idle',
35
+ states: {
36
+ idle: {
37
+ enter: 'clearGameInfo',
38
+ on: {
39
+ ENTER_ROOM: {
40
+ target: 'loading',
41
+ actions: 'setRoomId',
42
+ cond: (context, event) => {
43
+ return context.roomId !== event.roomId
44
+ },
45
+ },
46
+ ENTER_GAME: {
47
+ target: 'connecting',
48
+ actions: ['setGameInfo', 'setLang'],
49
+ cond: (context, event) => {
50
+ return context.list.length > 0
51
+ },
52
+ },
53
+ },
54
+ },
55
+ loading: {
56
+ invoke: {
57
+ src: 'getRoomItems',
58
+ onDone: {
59
+ target: 'idle',
60
+ actions: 'setList',
61
+ },
62
+ onError: {
63
+ target: 'idle',
64
+ actions: assign({ list: [] }),
65
+ },
66
+ },
67
+ },
68
+ connecting: {
69
+ invoke: {
70
+ src: 'connectGame',
71
+ onDone: {
72
+ target: 'playing',
73
+ actions: 'setGameURL',
74
+ },
75
+ onError: {
76
+ target: 'idle',
77
+ },
78
+ },
79
+ },
80
+ playing: {
81
+ on: {
82
+ EXIT_GAME: {
83
+ target: 'disconnect',
84
+ },
85
+ },
86
+ },
87
+ disconnect: {
88
+ invoke: {
89
+ src: 'disconnectGame',
90
+ onDone: {
91
+ target: 'idle',
92
+ },
93
+ onError: {
94
+ target: 'idle',
95
+ },
96
+ },
97
+ },
98
+ },
99
+ },
100
+ schedule: {
101
+ initial: 'fetchingGameSHA',
102
+ states: {
103
+ fetchingGameSHA: {
104
+ invoke: {
105
+ src: 'fetchGameSHA',
106
+ onDone: {
107
+ target: 'checking',
108
+ actions: 'setGameSHA',
109
+ },
110
+ onError: {},
111
+ },
112
+ },
113
+ checking: {
114
+ always: [
115
+ { target: 'updatingStatus', cond: 'isStatusChanged' },
116
+ { target: 'updatingCategory', cond: 'isCategoryChanged' },
117
+ { target: 'idle' },
118
+ ],
119
+ },
120
+ updatingStatus: {
121
+ invoke: {
122
+ src: 'fetchStatus',
123
+ onDone: {
124
+ target: 'updatingOption',
125
+ actions: ['setStatus'],
126
+ },
127
+ onError: {},
128
+ },
129
+ },
130
+ updatingOption: {
131
+ invoke: {
132
+ src: 'fetchOption',
133
+ onDone: {
134
+ target: 'updatingCategory',
135
+ actions: 'mergeOption',
136
+ },
137
+ },
138
+ },
139
+ updatingCategory: {
140
+ invoke: {
141
+ src: 'getRoomItems',
142
+ onDone: {
143
+ target: 'idle',
144
+ actions: 'setList',
145
+ },
146
+ onError: {
147
+ target: 'idle',
148
+ },
149
+ },
150
+ },
151
+ idle: {
152
+ after: {
153
+ TIMEOUT: {
154
+ target: 'fetchingGameSHA',
155
+ },
156
+ },
157
+ },
158
+ },
159
+ },
160
+ },
161
+ on: {
162
+ SET_MOBILE: {
163
+ actions: 'setMobile',
164
+ },
165
+ },
166
+ },
167
+ {
168
+ actions: {
169
+ setRoomId: assign((context, event) => {
170
+ return { roomId: event.roomId }
171
+ }),
172
+ setList: assign({
173
+ list: (context, event) => {
174
+ return event.data.list
175
+ },
176
+ }),
177
+ setGameURL: assign({
178
+ gameURL: (context, event) => {
179
+ return event.data.gameURL
180
+ },
181
+ }),
182
+ clearGameInfo: assign((context, event) => {
183
+ return { game: { provider: null, game_id: null, game_type: null, mapping_id: null } }
184
+ }),
185
+ setGameInfo: assign((context, event) => {
186
+ const { provider, game_id, game_type, mapping_id } = event.data.game
187
+ return { game: { provider, game_id, game_type, mapping_id } }
188
+ }),
189
+ setLang: assign((context, event) => {
190
+ const lang = event.data.locale.replace('-', '_')
191
+ return { lang }
192
+ }),
193
+ setMobile: assign((context, event) => {
194
+ return {
195
+ isMobile: event.data,
196
+ }
197
+ }),
198
+ setGameSHA: assign((context, event) => {
199
+ const { sha } = context
200
+ const newSha = event.data
201
+ return {
202
+ sha: newSha,
203
+ isCategoryChanged: newSha.category !== (sha.category || '0'),
204
+ isStatusChanged: newSha.status !== (sha.status || '0'),
205
+ }
206
+ }),
207
+ setStatus: assign((context, event) => {
208
+ return {
209
+ statusMap: event.data,
210
+ }
211
+ }),
212
+ mergeOption: assign((context, event) => {
213
+ const { optionMap } = context
214
+ return {
215
+ optionMap: { ...optionMap, ...event.data },
216
+ }
217
+ }),
218
+ },
219
+ guards: {
220
+ isCategoryChanged: (context, event) => context.isCategoryChanged,
221
+ isStatusChanged: (context, event) => context.isStatusChanged,
222
+ },
223
+ delays: {
224
+ TIMEOUT: (context, event) => {
225
+ return context.tick * 10
226
+ },
227
+ },
228
+ services: {
229
+ getRoomItems: async (context, event) => {
230
+ return await request.send(api.getGameCategory({ id: context.roomId }))
231
+ },
232
+ connectGame: async (context, event) => {
233
+ const { lang, isMobile } = context
234
+ const { provider, game_id, game_type, mapping_id } = context.game
235
+ const params = {
236
+ provider_id: provider,
237
+ game_id: game_id,
238
+ gametype_id: game_type,
239
+ mapping_id: mapping_id,
240
+ is_demo: false,
241
+ is_mobile: isMobile,
242
+ lang,
243
+ return_url: window.location.href,
244
+ }
245
+ const { redirect_url } = await request.send(api.playGame(params))
246
+ return { gameURL: redirect_url }
247
+ },
248
+ disconnectGame: async (context, event) => {
249
+ const uid_site = event.data
250
+ return await request.send(api.logoutGame({ uid_site, provider_id: context.game.provider }))
251
+ },
252
+ fetchOption: async (context, event) => {
253
+ const { optionIds } = context
254
+ return await request.send(api.getOptionMap())
255
+ },
256
+ fetchGameSHA: async (context, event) => {
257
+ return await request.send(api.getGameSHA())
258
+ },
259
+ fetchStatus: async (context, event) => {
260
+ return await request.send(api.getGameStatus())
261
+ },
262
+ },
263
+ }
264
+ )
265
+ }
@@ -0,0 +1,123 @@
1
+ import { createMachine, assign } from 'xstate'
2
+ import api from '../api/game'
3
+
4
+ export default function (request) {
5
+ return createMachine(
6
+ {
7
+ id: 'favorite',
8
+ type: 'parallel',
9
+ context: {
10
+ list: [],
11
+ },
12
+ states: {
13
+ fetching: {
14
+ initial: 'disable',
15
+ states: {
16
+ disable: {},
17
+ enable: {
18
+ invoke: {
19
+ src: 'fetchList',
20
+ onDone: {
21
+ actions: 'setList',
22
+ },
23
+ onError: {
24
+ actions: assign({ list: [] }),
25
+ },
26
+ },
27
+ },
28
+ },
29
+ },
30
+ adding: {
31
+ initial: 'disable',
32
+ states: {
33
+ disable: {},
34
+ enable: {
35
+ invoke: {
36
+ src: 'add',
37
+ onDone: {},
38
+ onError: {
39
+ actions: 'removeFromList',
40
+ },
41
+ },
42
+ },
43
+ },
44
+ },
45
+ removing: {
46
+ initial: 'disable',
47
+ states: {
48
+ disable: {},
49
+ enable: {
50
+ invoke: {
51
+ src: 'remove',
52
+ onDone: {},
53
+ onError: {
54
+ actions: 'addToList',
55
+ },
56
+ },
57
+ },
58
+ },
59
+ },
60
+ },
61
+ on: {
62
+ FETCH_LIST: {
63
+ target: 'fetching.enable',
64
+ },
65
+ ADD: {
66
+ target: 'adding.enable',
67
+ actions: 'addToList',
68
+ cond: 'isNotExist',
69
+ },
70
+ REMOVE: {
71
+ target: 'removing.enable',
72
+ actions: 'removeFromList',
73
+ cond: 'isExist',
74
+ },
75
+ },
76
+ },
77
+ {
78
+ actions: {
79
+ setList: assign((context, event) => {
80
+ return {
81
+ list: event.data,
82
+ }
83
+ }),
84
+ addToList: assign((context, event) => {
85
+ return {
86
+ list: [...context.list, event.data],
87
+ }
88
+ }),
89
+ removeFromList: assign((context, event) => {
90
+ return {
91
+ list: context.list.filter((item) => item !== event.data),
92
+ }
93
+ }),
94
+ },
95
+ guards: {
96
+ isExist: (context, event) => context.list.includes(event.data),
97
+ isNotExist: (context, event) => !context.list.includes(event.data),
98
+ },
99
+ services: {
100
+ add: async (context, event) => {
101
+ try {
102
+ return await request.send(api.addFavoriteGame(event.data))
103
+ } catch (error) {
104
+ throw event.data
105
+ }
106
+ },
107
+ remove: async (context, event) => {
108
+ try {
109
+ return await request.send(api.removeFavoriteGame(event.data))
110
+ } catch (error) {
111
+ throw event.data
112
+ }
113
+ },
114
+ fetchList: async (context, event) => {
115
+ const main = await request.send(api.getGameCategory({}))
116
+ const room = main.list.find((item) => item.category === 'SYSTEM_MY_FAVORITE')
117
+ const favorite = await request.send(api.getGameCategory({ id: room.id }))
118
+ return favorite.list.map((item) => item.g)
119
+ },
120
+ },
121
+ }
122
+ )
123
+ }