@jetthai/cuora 1.0.25 → 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.
- package/CHANGELOG.md +2 -0
- package/api/activity.js +46 -0
- package/api/auth.js +15 -0
- package/api/common.js +4 -0
- package/api/game.js +32 -0
- package/api/index.js +9 -0
- package/api/mailbox.js +20 -0
- package/api/payment.js +63 -0
- package/api/user.js +19 -0
- package/index.js +3 -58
- package/machine/activity/activity.js +73 -0
- package/machine/activity/continue_deposit_activity.js +132 -0
- package/machine/activity/deposit_activity.js +86 -0
- package/machine/activity/diamond_shop_activity.js +163 -0
- package/machine/activity/fafafa_activity.js +131 -0
- package/machine/activity/index.js +21 -0
- package/machine/activity/invite_friends_activity.js +121 -0
- package/machine/activity/ranking_activity.js +76 -0
- package/machine/activity/return_bonus_activity.js +150 -0
- package/machine/activity/specify_bets_activity.js +116 -0
- package/machine/auth.js +245 -0
- package/machine/auth_otp.js +191 -0
- package/machine/check.js +113 -0
- package/machine/common.js +163 -0
- package/machine/deposit.js +236 -0
- package/machine/error.js +72 -0
- package/machine/game.js +265 -0
- package/machine/game_favorite.js +123 -0
- package/machine/game_search.js +248 -0
- package/machine/inbox.js +246 -0
- package/machine/index.js +37 -0
- package/machine/merge.js +57 -0
- package/machine/payment_data.js +81 -0
- package/machine/reward.js +73 -0
- package/machine/setting.js +37 -0
- package/machine/side.js +147 -0
- package/machine/withdraw.js +367 -0
- package/package.json +3 -2
- package/request/config.js +18 -0
- package/request/cookie.js +52 -0
- package/request/request.js +97 -0
- package/plugin/activity.js +0 -289
- package/plugin/core.js +0 -518
- package/plugin/game.js +0 -474
- package/plugin/inbox.js +0 -216
- package/plugin/information.js +0 -57
- package/plugin/job/network.js +0 -61
- package/plugin/payment.js +0 -257
- package/plugin/request.js +0 -225
- package/plugin/search.js +0 -277
- package/plugin/user.js +0 -198
package/machine/inbox.js
ADDED
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import { assign, createMachine } from 'xstate'
|
|
2
|
+
import mailbox from '../api/mailbox'
|
|
3
|
+
import activity from '../api/activity'
|
|
4
|
+
|
|
5
|
+
// todo - 自動開啟系統信
|
|
6
|
+
// todo - 更新未讀數量
|
|
7
|
+
const messageState = {
|
|
8
|
+
// always: [{ actions: 'showUnread', cond: 'isShowUnread' }],
|
|
9
|
+
initial: 'idle',
|
|
10
|
+
states: {
|
|
11
|
+
idle: {
|
|
12
|
+
initial: 'hidden',
|
|
13
|
+
states: {
|
|
14
|
+
hidden: {},
|
|
15
|
+
shown: {
|
|
16
|
+
on: {
|
|
17
|
+
HIDE_MESSAGE: {
|
|
18
|
+
target: 'hidden',
|
|
19
|
+
actions: 'hideMessage',
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
on: {
|
|
25
|
+
SHOW_MESSAGE: [
|
|
26
|
+
{
|
|
27
|
+
target: '.shown',
|
|
28
|
+
actions: 'showMessage',
|
|
29
|
+
cond: 'isRead',
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
target: 'updating',
|
|
33
|
+
actions: ['showMessage', 'setMessageIsRead'],
|
|
34
|
+
},
|
|
35
|
+
],
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
updating: {
|
|
39
|
+
invoke: {
|
|
40
|
+
src: 'updateMessageIsRead',
|
|
41
|
+
onDone: {
|
|
42
|
+
target: 'idle.shown',
|
|
43
|
+
},
|
|
44
|
+
onError: {
|
|
45
|
+
target: 'idle.shown',
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export default function (request) {
|
|
53
|
+
const { appSecret } = request.config
|
|
54
|
+
return createMachine(
|
|
55
|
+
{
|
|
56
|
+
id: 'inbox',
|
|
57
|
+
initial: 'loading',
|
|
58
|
+
context: {
|
|
59
|
+
tabs: [],
|
|
60
|
+
currentTab: null,
|
|
61
|
+
inbox: {},
|
|
62
|
+
messageDetail: null,
|
|
63
|
+
// isShowUnread: false,
|
|
64
|
+
},
|
|
65
|
+
states: {
|
|
66
|
+
loading: {
|
|
67
|
+
invoke: {
|
|
68
|
+
src: 'fetchTabs',
|
|
69
|
+
onDone: {
|
|
70
|
+
target: 'checking',
|
|
71
|
+
actions: 'setTabs',
|
|
72
|
+
},
|
|
73
|
+
onError: {
|
|
74
|
+
target: 'failed',
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
checking: {
|
|
79
|
+
always: [
|
|
80
|
+
{
|
|
81
|
+
target: 'end',
|
|
82
|
+
cond: 'isEnd',
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
target: 'loadingMessages',
|
|
86
|
+
},
|
|
87
|
+
],
|
|
88
|
+
},
|
|
89
|
+
loadingMessages: {
|
|
90
|
+
invoke: {
|
|
91
|
+
src: 'fetchMessages',
|
|
92
|
+
onDone: {
|
|
93
|
+
target: 'more',
|
|
94
|
+
actions: 'setInbox',
|
|
95
|
+
},
|
|
96
|
+
onError: {
|
|
97
|
+
target: 'end',
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
more: {
|
|
102
|
+
...messageState,
|
|
103
|
+
on: {
|
|
104
|
+
LOAD_MESSAGES: {
|
|
105
|
+
target: 'checking',
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
end: {
|
|
110
|
+
...messageState,
|
|
111
|
+
},
|
|
112
|
+
failed: {},
|
|
113
|
+
},
|
|
114
|
+
on: {
|
|
115
|
+
// SHOW_SYSTEM_MESSAGE: {
|
|
116
|
+
// actions: 'showSystemMessage',
|
|
117
|
+
// },
|
|
118
|
+
SET_TAB: {
|
|
119
|
+
target: '.checking',
|
|
120
|
+
actions: ['setCurrentTab', 'hideMessage'],
|
|
121
|
+
cond: 'hasTabs',
|
|
122
|
+
},
|
|
123
|
+
PRESET_TAB: {
|
|
124
|
+
actions: ['setCurrentTab', 'hideMessage'],
|
|
125
|
+
},
|
|
126
|
+
RESET: {
|
|
127
|
+
target: '.loading',
|
|
128
|
+
actions: 'reset',
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
guards: {
|
|
134
|
+
hasTabs: (context, event) => {
|
|
135
|
+
return context.tabs.length > 0
|
|
136
|
+
},
|
|
137
|
+
isEnd: (context, event) => {
|
|
138
|
+
const { currentTab, inbox } = context
|
|
139
|
+
if (!inbox[currentTab]) {
|
|
140
|
+
return false
|
|
141
|
+
} else {
|
|
142
|
+
const { page, totalPage } = inbox[currentTab]
|
|
143
|
+
return page + 1 >= totalPage
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
isRead: (context, event) => {
|
|
147
|
+
return event.data.isRead
|
|
148
|
+
},
|
|
149
|
+
// isShowUnread: (context, event) => {
|
|
150
|
+
// return context.isShowUnread
|
|
151
|
+
// },
|
|
152
|
+
},
|
|
153
|
+
actions: {
|
|
154
|
+
reset: assign((context, event) => {
|
|
155
|
+
return {
|
|
156
|
+
tabs: [],
|
|
157
|
+
currentTab: null,
|
|
158
|
+
inbox: {},
|
|
159
|
+
messageDetail: null,
|
|
160
|
+
}
|
|
161
|
+
}),
|
|
162
|
+
setTabs: assign((context, event) => {
|
|
163
|
+
let { currentTab } = context
|
|
164
|
+
if (!currentTab) {
|
|
165
|
+
currentTab = event.data?.[0]
|
|
166
|
+
}
|
|
167
|
+
return {
|
|
168
|
+
tabs: event.data,
|
|
169
|
+
currentTab,
|
|
170
|
+
}
|
|
171
|
+
}),
|
|
172
|
+
setCurrentTab: assign((context, event) => {
|
|
173
|
+
return {
|
|
174
|
+
currentTab: event.data,
|
|
175
|
+
}
|
|
176
|
+
}),
|
|
177
|
+
showMessage: assign((context, event) => {
|
|
178
|
+
return {
|
|
179
|
+
messageDetail: event.data,
|
|
180
|
+
}
|
|
181
|
+
}),
|
|
182
|
+
hideMessage: assign((context, event) => {
|
|
183
|
+
return {
|
|
184
|
+
messageDetail: null,
|
|
185
|
+
}
|
|
186
|
+
}),
|
|
187
|
+
setInbox: assign((context, event) => {
|
|
188
|
+
return {
|
|
189
|
+
inbox: event.data,
|
|
190
|
+
}
|
|
191
|
+
}),
|
|
192
|
+
// showUnread: assign((context, event) => {
|
|
193
|
+
// const { currentTab, inbox } = context
|
|
194
|
+
// const messageDetail = inbox[currentTab]?.data.find((item) => !item.isRead)
|
|
195
|
+
// return {
|
|
196
|
+
// messageDetail,
|
|
197
|
+
// isShowUnread: false,
|
|
198
|
+
// }
|
|
199
|
+
// }),
|
|
200
|
+
setMessageIsRead: assign((context, event) => {
|
|
201
|
+
const { inbox, currentTab } = JSON.parse(JSON.stringify(context))
|
|
202
|
+
const data = inbox[currentTab].data.map((item) => {
|
|
203
|
+
if (item.groupId === event.data.groupId) {
|
|
204
|
+
item.isRead = true
|
|
205
|
+
}
|
|
206
|
+
return item
|
|
207
|
+
})
|
|
208
|
+
inbox[currentTab].data = data
|
|
209
|
+
return { inbox }
|
|
210
|
+
}),
|
|
211
|
+
// showSystemMessage: assign((context, event) => {
|
|
212
|
+
// return {
|
|
213
|
+
// currentTab: 'SYSTEM',
|
|
214
|
+
// isShowUnread: true,
|
|
215
|
+
// }
|
|
216
|
+
// }),
|
|
217
|
+
},
|
|
218
|
+
services: {
|
|
219
|
+
fetchTabs: async (context, event) => {
|
|
220
|
+
const res = await request.send(mailbox.getMessageTypes())
|
|
221
|
+
const tabs = res.data?.map((item) => item.type) || []
|
|
222
|
+
return tabs
|
|
223
|
+
},
|
|
224
|
+
fetchMessages: async (context, event) => {
|
|
225
|
+
const { currentTab, inbox } = JSON.parse(JSON.stringify(context))
|
|
226
|
+
if (currentTab === 'REWARD') {
|
|
227
|
+
const { data } = await request.send(activity.getRewardList({ count: 30, appSecret }))
|
|
228
|
+
inbox[currentTab] = { data, page: 0, totalPage: 1 }
|
|
229
|
+
} else {
|
|
230
|
+
const nextPage = inbox[currentTab]?.page && inbox[currentTab]?.page + 1
|
|
231
|
+
const { data, ...rest } = await request.send(mailbox.getMessageList({ type: currentTab, page: nextPage }))
|
|
232
|
+
const currentData = inbox[currentTab]?.data || []
|
|
233
|
+
inbox[currentTab] = { data: currentData.concat(data), ...rest }
|
|
234
|
+
}
|
|
235
|
+
return inbox
|
|
236
|
+
},
|
|
237
|
+
updateMessageIsRead: async (context, event) => {
|
|
238
|
+
const { data } = event
|
|
239
|
+
request.send(mailbox.updateMessage({ groupId: data.groupId, isRead: true }))
|
|
240
|
+
data.isRead = true
|
|
241
|
+
return data
|
|
242
|
+
},
|
|
243
|
+
},
|
|
244
|
+
}
|
|
245
|
+
)
|
|
246
|
+
}
|
package/machine/index.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import activity from './activity'
|
|
2
|
+
import auth from './auth'
|
|
3
|
+
import auth_otp from './auth_otp'
|
|
4
|
+
import check from './check'
|
|
5
|
+
import common from './common'
|
|
6
|
+
import deposit from './deposit'
|
|
7
|
+
import error from './error'
|
|
8
|
+
import game from './game'
|
|
9
|
+
import game_favorite from './game_favorite'
|
|
10
|
+
import game_search from './game_search'
|
|
11
|
+
import inbox from './inbox'
|
|
12
|
+
import merge from './merge'
|
|
13
|
+
import payment_data from './payment_data'
|
|
14
|
+
import reward from './reward'
|
|
15
|
+
import setting from './setting'
|
|
16
|
+
import side from './side'
|
|
17
|
+
import withdraw from './withdraw'
|
|
18
|
+
|
|
19
|
+
export default {
|
|
20
|
+
...activity,
|
|
21
|
+
auth,
|
|
22
|
+
auth_otp,
|
|
23
|
+
check,
|
|
24
|
+
common,
|
|
25
|
+
deposit,
|
|
26
|
+
error,
|
|
27
|
+
game,
|
|
28
|
+
game_favorite,
|
|
29
|
+
game_search,
|
|
30
|
+
inbox,
|
|
31
|
+
merge,
|
|
32
|
+
payment_data,
|
|
33
|
+
reward,
|
|
34
|
+
setting,
|
|
35
|
+
side,
|
|
36
|
+
withdraw,
|
|
37
|
+
}
|
package/machine/merge.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { createMachine, assign } from 'xstate'
|
|
2
|
+
import api from '../api/payment'
|
|
3
|
+
export default function (request) {
|
|
4
|
+
return createMachine(
|
|
5
|
+
{
|
|
6
|
+
id: 'merge',
|
|
7
|
+
initial: 'idle',
|
|
8
|
+
context: {
|
|
9
|
+
userInfo: null,
|
|
10
|
+
},
|
|
11
|
+
states: {
|
|
12
|
+
idle: {
|
|
13
|
+
always: [{ target: 'mergeable', cond: 'isMergeable' }],
|
|
14
|
+
},
|
|
15
|
+
mergeable: {
|
|
16
|
+
on: {
|
|
17
|
+
MERGE: {
|
|
18
|
+
target: 'merging',
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
merging: {
|
|
23
|
+
invoke: {
|
|
24
|
+
src: 'mergeWallet',
|
|
25
|
+
onDone: { target: 'idle' },
|
|
26
|
+
onError: { target: 'idle' },
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
on: {
|
|
31
|
+
SET_USER_INFO: {
|
|
32
|
+
actions: 'setUserInfo',
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
actions: {
|
|
38
|
+
setUserInfo: assign((context, event) => {
|
|
39
|
+
return {
|
|
40
|
+
userInfo: event.data,
|
|
41
|
+
}
|
|
42
|
+
}),
|
|
43
|
+
},
|
|
44
|
+
guards: {
|
|
45
|
+
isMergeable: (context, event) => {
|
|
46
|
+
const { retain, balance, withdraw_policy } = context.userInfo || {}
|
|
47
|
+
return retain > 0 && (parseFloat(balance) <= 5 || withdraw_policy === 'FREE')
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
services: {
|
|
51
|
+
mergeWallet: async (context, event) => {
|
|
52
|
+
return await request.send(api.mergeWallet())
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
}
|
|
56
|
+
)
|
|
57
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { createMachine, assign } from 'xstate'
|
|
2
|
+
import payment from '../api/payment'
|
|
3
|
+
|
|
4
|
+
export default function (request) {
|
|
5
|
+
return createMachine(
|
|
6
|
+
{
|
|
7
|
+
id: 'payment_data',
|
|
8
|
+
initial: 'idle',
|
|
9
|
+
context: {
|
|
10
|
+
transactionList: [],
|
|
11
|
+
spotMarketTime: null,
|
|
12
|
+
spotMarketList: [],
|
|
13
|
+
},
|
|
14
|
+
states: {
|
|
15
|
+
idle: {},
|
|
16
|
+
fetchingTransactionList: {
|
|
17
|
+
invoke: {
|
|
18
|
+
src: 'fetchTransactionList',
|
|
19
|
+
onDone: {
|
|
20
|
+
target: 'idle',
|
|
21
|
+
actions: 'setTransactionList',
|
|
22
|
+
},
|
|
23
|
+
onError: {},
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
fetchingSpotMarket: {
|
|
27
|
+
invoke: {
|
|
28
|
+
src: 'fetchSpotMarket',
|
|
29
|
+
onDone: {
|
|
30
|
+
target: 'idle',
|
|
31
|
+
actions: 'setSpotMarket',
|
|
32
|
+
},
|
|
33
|
+
onError: {},
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
on: {
|
|
38
|
+
GET_TRANSACTION_LIST: {
|
|
39
|
+
target: 'fetchingTransactionList',
|
|
40
|
+
},
|
|
41
|
+
GET_SPOT_MARKET: {
|
|
42
|
+
target: 'fetchingSpotMarket',
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
actions: {
|
|
48
|
+
setTransactionList: assign((context, event) => {
|
|
49
|
+
const statusMap = {
|
|
50
|
+
2: 'pending',
|
|
51
|
+
3: 'success',
|
|
52
|
+
4: 'fail',
|
|
53
|
+
6: 'reject',
|
|
54
|
+
}
|
|
55
|
+
const transactionList = event.data.map((item) => {
|
|
56
|
+
item.statusName = statusMap[item.status]
|
|
57
|
+
return item
|
|
58
|
+
})
|
|
59
|
+
return {
|
|
60
|
+
transactionList,
|
|
61
|
+
}
|
|
62
|
+
}),
|
|
63
|
+
setSpotMarket: assign((context, event) => {
|
|
64
|
+
const { timestamp, data } = event.data
|
|
65
|
+
return {
|
|
66
|
+
spotMarketTime: timestamp,
|
|
67
|
+
spotMarketList: data.slice(0, 100),
|
|
68
|
+
}
|
|
69
|
+
}),
|
|
70
|
+
},
|
|
71
|
+
services: {
|
|
72
|
+
fetchTransactionList: async (context, event) => {
|
|
73
|
+
return await request.send(payment.getPaymentHistory(7))
|
|
74
|
+
},
|
|
75
|
+
fetchSpotMarket: async (context, event) => {
|
|
76
|
+
return await request.send(payment.getSpotMarket())
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
}
|
|
80
|
+
)
|
|
81
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { createMachine, assign } from 'xstate'
|
|
2
|
+
import activity from '../api/activity'
|
|
3
|
+
|
|
4
|
+
export default function (request) {
|
|
5
|
+
const { appSecret } = request.config
|
|
6
|
+
return createMachine(
|
|
7
|
+
{
|
|
8
|
+
id: 'reward',
|
|
9
|
+
initial: 'loading',
|
|
10
|
+
context: {
|
|
11
|
+
rewardList: [],
|
|
12
|
+
},
|
|
13
|
+
states: {
|
|
14
|
+
loading: {
|
|
15
|
+
invoke: {
|
|
16
|
+
src: 'fetchRewardList',
|
|
17
|
+
onDone: {
|
|
18
|
+
target: 'loaded',
|
|
19
|
+
actions: 'setRewardList',
|
|
20
|
+
},
|
|
21
|
+
onError: {
|
|
22
|
+
target: 'loaded',
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
loaded: {
|
|
27
|
+
on: {
|
|
28
|
+
RECEIVE_REWARD: {
|
|
29
|
+
target: 'receiving',
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
receiving: {
|
|
34
|
+
invoke: {
|
|
35
|
+
src: 'receiveReward',
|
|
36
|
+
onDone: {
|
|
37
|
+
target: 'animating',
|
|
38
|
+
},
|
|
39
|
+
onError: {
|
|
40
|
+
target: 'loading',
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
animating: {
|
|
45
|
+
after: {
|
|
46
|
+
0: {
|
|
47
|
+
target: 'loading',
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
actions: {
|
|
55
|
+
setRewardList: assign((context, event) => {
|
|
56
|
+
return {
|
|
57
|
+
rewardList: event.data,
|
|
58
|
+
}
|
|
59
|
+
}),
|
|
60
|
+
},
|
|
61
|
+
services: {
|
|
62
|
+
fetchRewardList: async (context, event) => {
|
|
63
|
+
const { data } = await request.send(activity.getRewardList({ count: 30, appSecret }))
|
|
64
|
+
return data
|
|
65
|
+
},
|
|
66
|
+
receiveReward: async (context, event) => {
|
|
67
|
+
const { activityNo, receiveNo } = event.data
|
|
68
|
+
return await request.send(activity.getReward({ activityNo, receiveNo, appSecret }))
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
}
|
|
72
|
+
)
|
|
73
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { assign, createMachine } from 'xstate'
|
|
2
|
+
|
|
3
|
+
export default function () {
|
|
4
|
+
return createMachine(
|
|
5
|
+
{
|
|
6
|
+
id: 'setting',
|
|
7
|
+
initial: 'idle',
|
|
8
|
+
context: {
|
|
9
|
+
sound: false,
|
|
10
|
+
music: false,
|
|
11
|
+
locale: 'en-US',
|
|
12
|
+
},
|
|
13
|
+
entry: 'fetchSetting',
|
|
14
|
+
states: {
|
|
15
|
+
idle: {},
|
|
16
|
+
},
|
|
17
|
+
on: {
|
|
18
|
+
MODIFY_SETTING: {
|
|
19
|
+
actions: 'saveSetting',
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
actions: {
|
|
25
|
+
fetchSetting: assign(() => {
|
|
26
|
+
const setting = JSON.parse(localStorage.getItem('setting')) || { sound: true, music: true }
|
|
27
|
+
return { ...setting }
|
|
28
|
+
}),
|
|
29
|
+
saveSetting: assign((context, event) => {
|
|
30
|
+
const { sound, music, locale } = event.data
|
|
31
|
+
localStorage.setItem('setting', JSON.stringify({ sound, music, locale }))
|
|
32
|
+
return { sound, music, locale }
|
|
33
|
+
}),
|
|
34
|
+
},
|
|
35
|
+
}
|
|
36
|
+
)
|
|
37
|
+
}
|
package/machine/side.js
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { assign, createMachine } from 'xstate'
|
|
2
|
+
import api from '../api/game'
|
|
3
|
+
|
|
4
|
+
export default function (request) {
|
|
5
|
+
return createMachine(
|
|
6
|
+
{
|
|
7
|
+
id: 'side',
|
|
8
|
+
initial: 'preparing',
|
|
9
|
+
context: {
|
|
10
|
+
menu: {},
|
|
11
|
+
roomId: null,
|
|
12
|
+
roomHistory: [],
|
|
13
|
+
},
|
|
14
|
+
states: {
|
|
15
|
+
preparing: {
|
|
16
|
+
invoke: {
|
|
17
|
+
src: 'getRoomItems',
|
|
18
|
+
onDone: {
|
|
19
|
+
target: 'room',
|
|
20
|
+
actions: 'mapListToMenu',
|
|
21
|
+
},
|
|
22
|
+
onError: {
|
|
23
|
+
target: 'room',
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
room: {
|
|
28
|
+
entry: 'resetRoomHistory',
|
|
29
|
+
initial: 'home',
|
|
30
|
+
states: {
|
|
31
|
+
home: {
|
|
32
|
+
entry: assign({ roomId: (context, event) => context.menu['home'] }),
|
|
33
|
+
},
|
|
34
|
+
favorite: {
|
|
35
|
+
entry: assign({ roomId: (context, event) => context.menu['favorite'] }),
|
|
36
|
+
},
|
|
37
|
+
hot: {
|
|
38
|
+
entry: assign({ roomId: (context, event) => context.menu['hot'] }),
|
|
39
|
+
},
|
|
40
|
+
new: {
|
|
41
|
+
entry: assign({ roomId: (context, event) => context.menu['new'] }),
|
|
42
|
+
},
|
|
43
|
+
slot: {
|
|
44
|
+
entry: assign({ roomId: (context, event) => context.menu['slot'] }),
|
|
45
|
+
},
|
|
46
|
+
fish: {
|
|
47
|
+
entry: assign({ roomId: (context, event) => context.menu['fish'] }),
|
|
48
|
+
},
|
|
49
|
+
arcade: {
|
|
50
|
+
entry: assign({ roomId: (context, event) => context.menu['arcade'] }),
|
|
51
|
+
},
|
|
52
|
+
table: {
|
|
53
|
+
entry: assign({ roomId: (context, event) => context.menu['table'] }),
|
|
54
|
+
},
|
|
55
|
+
search: {},
|
|
56
|
+
history: {
|
|
57
|
+
type: 'history',
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
feature: {
|
|
62
|
+
on: {
|
|
63
|
+
RETURN: { target: 'room.history' },
|
|
64
|
+
CLICK_HOT: { target: 'room.hot' },
|
|
65
|
+
CLICK_NEW: { target: 'room.new' },
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
category: {
|
|
69
|
+
on: {
|
|
70
|
+
RETURN: { target: 'room.history' },
|
|
71
|
+
CLICK_SLOT: { target: 'room.slot' },
|
|
72
|
+
CLICK_FISH: { target: 'room.fish' },
|
|
73
|
+
CLICK_ARCADE: { target: 'room.arcade' },
|
|
74
|
+
CLICK_TABLE: { target: 'room.table' },
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
on: {
|
|
79
|
+
CLICK_HOME: { target: 'room.home' },
|
|
80
|
+
CLICK_FAVORITE: { target: 'room.favorite' },
|
|
81
|
+
CLICK_FEATURE: { target: 'feature' },
|
|
82
|
+
CLICK_CATEGORY: { target: 'category' },
|
|
83
|
+
CLICK_SEARCH: { target: 'room.search' },
|
|
84
|
+
FORWARD_ROOM: { actions: 'forwardRoom' },
|
|
85
|
+
BACKWARD_ROOM: { actions: 'backwardRoom' },
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
actions: {
|
|
90
|
+
mapListToMenu: assign((context, event) => {
|
|
91
|
+
const { list = [] } = event.data
|
|
92
|
+
const map = {
|
|
93
|
+
home: ['SYSTEM_PERSONAL', 'SYSTEM_INDEX_LIST'],
|
|
94
|
+
favorite: 'SYSTEM_MY_FAVORITE',
|
|
95
|
+
hot: 'SYSTEM_TOP_GAME',
|
|
96
|
+
new: 'SYSTEM_NEW_GAME',
|
|
97
|
+
slot: 'SYSTEM_BIG_CATEGORY_SLOT',
|
|
98
|
+
fish: 'SYSTEM_BIG_CATEGORY_FISHING',
|
|
99
|
+
arcade: 'SYSTEM_BIG_CATEGORY_ARCADE',
|
|
100
|
+
table: 'SYSTEM_BIG_CATEGORY_TABLECARD',
|
|
101
|
+
}
|
|
102
|
+
const menu = {}
|
|
103
|
+
Object.keys(map).forEach((key) => {
|
|
104
|
+
if (Array.isArray(map[key])) {
|
|
105
|
+
// 若是陣列則依順序決定館別內容
|
|
106
|
+
map[key].some((val) => {
|
|
107
|
+
const id = list.find((item) => item.category === val)?.id
|
|
108
|
+
if (id) {
|
|
109
|
+
menu[key] = id
|
|
110
|
+
return true
|
|
111
|
+
} else {
|
|
112
|
+
return false
|
|
113
|
+
}
|
|
114
|
+
})
|
|
115
|
+
} else {
|
|
116
|
+
menu[key] = list.find((item) => item.category === map[key])?.id
|
|
117
|
+
}
|
|
118
|
+
})
|
|
119
|
+
return { menu }
|
|
120
|
+
}),
|
|
121
|
+
forwardRoom: assign((context, event) => {
|
|
122
|
+
return {
|
|
123
|
+
roomId: event.data,
|
|
124
|
+
roomHistory: [...context.roomHistory, context.roomId],
|
|
125
|
+
}
|
|
126
|
+
}),
|
|
127
|
+
backwardRoom: assign((context, event) => {
|
|
128
|
+
const { roomHistory } = context
|
|
129
|
+
return {
|
|
130
|
+
roomId: roomHistory.slice(-1)[0],
|
|
131
|
+
roomHistory: roomHistory.slice(0, -1),
|
|
132
|
+
}
|
|
133
|
+
}),
|
|
134
|
+
resetRoomHistory: assign((context, event) => {
|
|
135
|
+
return {
|
|
136
|
+
roomHistory: [],
|
|
137
|
+
}
|
|
138
|
+
}),
|
|
139
|
+
},
|
|
140
|
+
services: {
|
|
141
|
+
getRoomItems: async (context, event) => {
|
|
142
|
+
return await request.send(api.getGameCategory({ id: context.roomId }))
|
|
143
|
+
},
|
|
144
|
+
},
|
|
145
|
+
}
|
|
146
|
+
)
|
|
147
|
+
}
|