@jetthai/cuora 1.0.50 → 1.0.52

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.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ### [1.0.52](https://github.com/jetthai/cuora-module/compare/v1.0.51...v1.0.52) (2021-12-07)
6
+
7
+ ### [1.0.51](https://github.com/jetthai/cuora-module/compare/v1.0.50...v1.0.51) (2021-12-07)
8
+
5
9
  ### [1.0.50](https://github.com/jetthai/cuora-module/compare/v1.0.49...v1.0.50) (2021-12-01)
6
10
 
7
11
  ### [1.0.49](https://github.com/jetthai/cuora-module/compare/v1.0.48...v1.0.49) (2021-12-01)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jetthai/cuora",
3
- "version": "1.0.50",
3
+ "version": "1.0.52",
4
4
  "description": "",
5
5
  "main": "./src/index.js",
6
6
  "scripts": {
@@ -1,5 +1,6 @@
1
1
  import { assign, createMachine } from 'xstate'
2
2
  import api from '../api/game'
3
+ import UAParser from 'ua-parser-js'
3
4
 
4
5
  export default function (request) {
5
6
  return createMachine(
@@ -9,6 +10,8 @@ export default function (request) {
9
10
  context: {
10
11
  roomId: null,
11
12
  list: [],
13
+ gameList: [],
14
+ // play params
12
15
  game: {
13
16
  provider: null,
14
17
  game_id: null,
@@ -16,9 +19,8 @@ export default function (request) {
16
19
  mapping_id: null,
17
20
  },
18
21
  lang: 'en_US',
22
+ isMobile: new UAParser().getResult().device.type,
19
23
  gameURL: null,
20
- tick: 2000,
21
- isMobile: false,
22
24
  // game database
23
25
  sha: {
24
26
  category: null,
@@ -107,14 +109,16 @@ export default function (request) {
107
109
  target: 'checking',
108
110
  actions: 'setGameSHA',
109
111
  },
110
- onError: {},
112
+ onError: {
113
+ target: 'pending',
114
+ },
111
115
  },
112
116
  },
113
117
  checking: {
114
118
  always: [
115
119
  { target: 'updatingStatus', cond: 'isStatusChanged' },
116
120
  { target: 'updatingCategory', cond: 'isCategoryChanged' },
117
- { target: 'idle' },
121
+ { target: 'pending' },
118
122
  ],
119
123
  },
120
124
  updatingStatus: {
@@ -124,7 +128,9 @@ export default function (request) {
124
128
  target: 'updatingOption',
125
129
  actions: ['setStatus'],
126
130
  },
127
- onError: {},
131
+ onError: {
132
+ target: 'pending',
133
+ },
128
134
  },
129
135
  },
130
136
  updatingOption: {
@@ -134,23 +140,26 @@ export default function (request) {
134
140
  target: 'updatingCategory',
135
141
  actions: 'mergeOption',
136
142
  },
143
+ onError: {
144
+ target: 'pending',
145
+ },
137
146
  },
138
147
  },
139
148
  updatingCategory: {
140
149
  invoke: {
141
150
  src: 'getRoomItems',
142
151
  onDone: {
143
- target: 'idle',
152
+ target: 'pending',
144
153
  actions: 'setList',
145
154
  },
146
155
  onError: {
147
- target: 'idle',
156
+ target: 'pending',
148
157
  },
149
158
  },
150
159
  },
151
- idle: {
160
+ pending: {
152
161
  after: {
153
- TIMEOUT: {
162
+ 20000: {
154
163
  target: 'fetchingGameSHA',
155
164
  },
156
165
  },
@@ -158,21 +167,36 @@ export default function (request) {
158
167
  },
159
168
  },
160
169
  },
161
- on: {
162
- SET_MOBILE: {
163
- actions: 'setMobile',
164
- },
165
- },
166
170
  },
167
171
  {
168
172
  actions: {
169
173
  setRoomId: assign((context, event) => {
170
174
  return { roomId: event.roomId }
171
175
  }),
172
- setList: assign({
173
- list: (context, event) => {
174
- return event.data.list
175
- },
176
+ setList: assign((context, event) => {
177
+ const { statusMap, optionMap } = context
178
+ const { list } = event.data
179
+ const gameList = list
180
+ .map((item) => {
181
+ if (item.id) {
182
+ item.room = true
183
+ return item
184
+ }
185
+
186
+ const code = item.g
187
+ if (!code || !optionMap[code]) {
188
+ return
189
+ }
190
+
191
+ return {
192
+ ...optionMap[code],
193
+ code,
194
+ system_enable: statusMap[code][0],
195
+ }
196
+ })
197
+ .filter((item) => item && !item.header)
198
+ .sort((a, b) => a.system_enable - b.system_enable)
199
+ return { list, gameList }
176
200
  }),
177
201
  setGameURL: assign({
178
202
  gameURL: (context, event) => {
@@ -190,18 +214,13 @@ export default function (request) {
190
214
  const lang = event.data.locale.replace('-', '_')
191
215
  return { lang }
192
216
  }),
193
- setMobile: assign((context, event) => {
194
- return {
195
- isMobile: event.data,
196
- }
197
- }),
198
217
  setGameSHA: assign((context, event) => {
199
218
  const { sha } = context
200
219
  const newSha = event.data
201
220
  return {
202
221
  sha: newSha,
203
- isCategoryChanged: newSha.category !== (sha.category || '0'),
204
- isStatusChanged: newSha.status !== (sha.status || '0'),
222
+ isCategoryChanged: !sha.category || sha.category !== newSha.category,
223
+ isStatusChanged: !sha.status || sha.status !== newSha.status,
205
224
  }
206
225
  }),
207
226
  setStatus: assign((context, event) => {
@@ -220,11 +239,6 @@ export default function (request) {
220
239
  isCategoryChanged: (context, event) => context.isCategoryChanged,
221
240
  isStatusChanged: (context, event) => context.isStatusChanged,
222
241
  },
223
- delays: {
224
- TIMEOUT: (context, event) => {
225
- return context.tick * 10
226
- },
227
- },
228
242
  services: {
229
243
  getRoomItems: async (context, event) => {
230
244
  return await request.send(api.getGameCategory({ id: context.roomId }))
@@ -250,7 +264,6 @@ export default function (request) {
250
264
  return await request.send(api.logoutGame({ uid_site, provider_id: context.game.provider }))
251
265
  },
252
266
  fetchOption: async (context, event) => {
253
- const { optionIds } = context
254
267
  return await request.send(api.getOptionMap())
255
268
  },
256
269
  fetchGameSHA: async (context, event) => {
@@ -20,7 +20,9 @@ export default function (request) {
20
20
  target: 'idle',
21
21
  actions: 'setTransactionList',
22
22
  },
23
- onError: {},
23
+ onError: {
24
+ target: 'idle',
25
+ },
24
26
  },
25
27
  },
26
28
  fetchingSpotMarket: {
@@ -30,7 +32,9 @@ export default function (request) {
30
32
  target: 'idle',
31
33
  actions: 'setSpotMarket',
32
34
  },
33
- onError: {},
35
+ onError: {
36
+ target: 'idle',
37
+ },
34
38
  },
35
39
  },
36
40
  },
@@ -17,7 +17,7 @@ export default function (request) {
17
17
  src: 'getRoomItems',
18
18
  onDone: {
19
19
  target: 'room',
20
- actions: 'mapListToMenu',
20
+ actions: 'makeMenu',
21
21
  },
22
22
  onError: {
23
23
  target: 'room',
@@ -87,7 +87,7 @@ export default function (request) {
87
87
  },
88
88
  {
89
89
  actions: {
90
- mapListToMenu: assign((context, event) => {
90
+ makeMenu: assign((context, event) => {
91
91
  const { list = [] } = event.data
92
92
  const map = {
93
93
  home: ['SYSTEM_PERSONAL', 'SYSTEM_INDEX_LIST'],