@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.
- package/CHANGELOG.md +4 -0
- package/dist/index.js +2 -0
- package/dist/index.js.LICENSE.txt +30 -0
- package/package.json +10 -4
- package/src/api/activity.js +46 -0
- package/src/api/auth.js +15 -0
- package/src/api/common.js +4 -0
- package/src/api/game.js +32 -0
- package/src/api/index.js +9 -0
- package/src/api/mailbox.js +20 -0
- package/src/api/payment.js +63 -0
- package/src/api/user.js +19 -0
- package/src/index.js +6 -0
- package/src/machine/activity/activity.js +73 -0
- package/src/machine/activity/continue_deposit_activity.js +132 -0
- package/src/machine/activity/deposit_activity.js +86 -0
- package/src/machine/activity/diamond_shop_activity.js +163 -0
- package/src/machine/activity/fafafa_activity.js +131 -0
- package/src/machine/activity/index.js +21 -0
- package/src/machine/activity/invite_friends_activity.js +121 -0
- package/src/machine/activity/ranking_activity.js +76 -0
- package/src/machine/activity/return_bonus_activity.js +150 -0
- package/src/machine/activity/specify_bets_activity.js +116 -0
- package/src/machine/auth.js +245 -0
- package/src/machine/auth_otp.js +191 -0
- package/src/machine/check.js +113 -0
- package/src/machine/common.js +163 -0
- package/src/machine/deposit.js +236 -0
- package/src/machine/error.js +72 -0
- package/src/machine/game.js +265 -0
- package/src/machine/game_favorite.js +123 -0
- package/src/machine/game_search.js +248 -0
- package/src/machine/inbox.js +246 -0
- package/src/machine/index.js +37 -0
- package/src/machine/merge.js +57 -0
- package/src/machine/payment_data.js +81 -0
- package/src/machine/reward.js +73 -0
- package/src/machine/setting.js +37 -0
- package/src/machine/side.js +147 -0
- package/src/machine/withdraw.js +367 -0
- package/src/request/config.js +18 -0
- package/src/request/cookie.js +52 -0
- package/src/request/request.js +97 -0
- package/webpack.config.js +19 -0
- package/index.js +0 -58
- 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
|
@@ -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
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,367 @@
|
|
|
1
|
+
import { assign, createMachine } from 'xstate'
|
|
2
|
+
import api from '../api/payment'
|
|
3
|
+
import findLastIndex from 'lodash/findLastIndex'
|
|
4
|
+
|
|
5
|
+
export default function (request) {
|
|
6
|
+
return createMachine(
|
|
7
|
+
{
|
|
8
|
+
id: 'withdraw',
|
|
9
|
+
initial: 'idle',
|
|
10
|
+
context: {
|
|
11
|
+
isTurnoverMode: false,
|
|
12
|
+
siteConfig: null,
|
|
13
|
+
userInfo: null,
|
|
14
|
+
crypto: null,
|
|
15
|
+
networks: [],
|
|
16
|
+
currentNetwork: '',
|
|
17
|
+
currentAddress: '',
|
|
18
|
+
withdrawMethods: [],
|
|
19
|
+
withdrawRuleName: null,
|
|
20
|
+
withdrawRules: [],
|
|
21
|
+
withdrawLimit: null,
|
|
22
|
+
withdrawAmount: null,
|
|
23
|
+
withdrawLeft: null,
|
|
24
|
+
tutorialUrls: [],
|
|
25
|
+
balance: null,
|
|
26
|
+
charge: null,
|
|
27
|
+
},
|
|
28
|
+
states: {
|
|
29
|
+
idle: {
|
|
30
|
+
on: {
|
|
31
|
+
PRESET: {
|
|
32
|
+
target: 'mode',
|
|
33
|
+
actions: ['setSiteConfig', 'setUserInfo', 'preset'],
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
mode: {
|
|
38
|
+
always: [{ target: 'free', cond: 'isFree' }, { target: 'cash' }],
|
|
39
|
+
},
|
|
40
|
+
free: {
|
|
41
|
+
initial: 'preparing',
|
|
42
|
+
states: {
|
|
43
|
+
preparing: {
|
|
44
|
+
invoke: {
|
|
45
|
+
src: 'fetchWithdrawRules',
|
|
46
|
+
onDone: {
|
|
47
|
+
target: 'convertible',
|
|
48
|
+
actions: 'updateWithdrawCondition',
|
|
49
|
+
},
|
|
50
|
+
onError: {
|
|
51
|
+
target: 'notConvertible',
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
notConvertible: {},
|
|
56
|
+
convertible: {
|
|
57
|
+
initial: 'preparing',
|
|
58
|
+
states: {
|
|
59
|
+
preparing: {
|
|
60
|
+
invoke: {
|
|
61
|
+
src: 'fetchPayments',
|
|
62
|
+
onDone: {
|
|
63
|
+
target: 'operation',
|
|
64
|
+
actions: 'setCrypto',
|
|
65
|
+
},
|
|
66
|
+
onError: {
|
|
67
|
+
target: '#withdraw.free.notConvertible',
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
operation: {
|
|
72
|
+
on: {
|
|
73
|
+
SET_NETWORK: {
|
|
74
|
+
actions: 'setNetwork',
|
|
75
|
+
},
|
|
76
|
+
SET_ADDRESS: {
|
|
77
|
+
actions: 'setAddress',
|
|
78
|
+
},
|
|
79
|
+
CALCULATE: {
|
|
80
|
+
target: 'calculating',
|
|
81
|
+
cond: 'isCalculable',
|
|
82
|
+
},
|
|
83
|
+
SUBMIT: {
|
|
84
|
+
target: '#withdraw.free.converting',
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
calculating: {
|
|
89
|
+
entry: 'resetCharge',
|
|
90
|
+
invoke: {
|
|
91
|
+
src: 'fetchCalculation',
|
|
92
|
+
onDone: {
|
|
93
|
+
target: 'operation',
|
|
94
|
+
actions: 'setCalculatedResult',
|
|
95
|
+
},
|
|
96
|
+
onError: {
|
|
97
|
+
target: 'operation',
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
converting: {
|
|
104
|
+
invoke: {
|
|
105
|
+
src: 'submitWithdrawFree',
|
|
106
|
+
onDone: {
|
|
107
|
+
target: 'converted',
|
|
108
|
+
},
|
|
109
|
+
onError: {
|
|
110
|
+
target: 'convertible.operation',
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
converted: {},
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
cash: {
|
|
118
|
+
initial: 'checking',
|
|
119
|
+
states: {
|
|
120
|
+
checking: {
|
|
121
|
+
entry: 'calculateCashLeft',
|
|
122
|
+
always: [
|
|
123
|
+
{ target: 'disable', cond: 'isWithdrawDisable' },
|
|
124
|
+
{ target: 'transferable', cond: 'isTransferable' },
|
|
125
|
+
{ target: 'notTransferable' },
|
|
126
|
+
],
|
|
127
|
+
},
|
|
128
|
+
disable: {},
|
|
129
|
+
notTransferable: {},
|
|
130
|
+
transferable: {
|
|
131
|
+
entry: 'setBalanceToWithdrawAmount',
|
|
132
|
+
initial: 'preparing',
|
|
133
|
+
states: {
|
|
134
|
+
preparing: {
|
|
135
|
+
invoke: {
|
|
136
|
+
src: 'fetchPayments',
|
|
137
|
+
onDone: {
|
|
138
|
+
target: 'operation',
|
|
139
|
+
actions: 'setCrypto',
|
|
140
|
+
},
|
|
141
|
+
onError: {
|
|
142
|
+
target: '#withdraw.cash.checking',
|
|
143
|
+
},
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
operation: {
|
|
147
|
+
on: {
|
|
148
|
+
SET_NETWORK: {
|
|
149
|
+
actions: 'setNetwork',
|
|
150
|
+
},
|
|
151
|
+
SET_ADDRESS: {
|
|
152
|
+
actions: 'setAddress',
|
|
153
|
+
},
|
|
154
|
+
CALCULATE: {
|
|
155
|
+
target: 'calculating',
|
|
156
|
+
cond: 'isCalculable',
|
|
157
|
+
},
|
|
158
|
+
SUBMIT: {
|
|
159
|
+
target: '#withdraw.cash.transferring',
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
},
|
|
163
|
+
calculating: {
|
|
164
|
+
entry: 'resetCharge',
|
|
165
|
+
invoke: {
|
|
166
|
+
src: 'fetchCalculation',
|
|
167
|
+
onDone: {
|
|
168
|
+
target: 'operation',
|
|
169
|
+
actions: 'setCalculatedResult',
|
|
170
|
+
},
|
|
171
|
+
onError: {
|
|
172
|
+
target: 'operation',
|
|
173
|
+
},
|
|
174
|
+
},
|
|
175
|
+
},
|
|
176
|
+
},
|
|
177
|
+
},
|
|
178
|
+
transferring: {
|
|
179
|
+
invoke: {
|
|
180
|
+
src: 'submitWithdraw',
|
|
181
|
+
onDone: {
|
|
182
|
+
target: 'transferred',
|
|
183
|
+
},
|
|
184
|
+
onError: {
|
|
185
|
+
target: 'transferable.operation',
|
|
186
|
+
},
|
|
187
|
+
},
|
|
188
|
+
},
|
|
189
|
+
transferred: {},
|
|
190
|
+
},
|
|
191
|
+
},
|
|
192
|
+
},
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
actions: {
|
|
196
|
+
setUserInfo: assign((context, event) => {
|
|
197
|
+
return {
|
|
198
|
+
userInfo: event.data.userInfo,
|
|
199
|
+
}
|
|
200
|
+
}),
|
|
201
|
+
setSiteConfig: assign((context, event) => {
|
|
202
|
+
return {
|
|
203
|
+
siteConfig: event.data.siteConfig,
|
|
204
|
+
}
|
|
205
|
+
}),
|
|
206
|
+
preset: assign((context, event) => {
|
|
207
|
+
const { userInfo, siteConfig } = event.data
|
|
208
|
+
const { withdraw_rule, withdraw_limit } = userInfo || {}
|
|
209
|
+
const balance = parseFloat(userInfo?.balance)
|
|
210
|
+
const methods = siteConfig?.paymentMethods?.withdraw || []
|
|
211
|
+
let withdrawLimit
|
|
212
|
+
if (methods.includes('amb')) {
|
|
213
|
+
withdrawLimit = (withdraw_limit + balance) * -1
|
|
214
|
+
} else {
|
|
215
|
+
withdrawLimit = withdraw_limit * -1
|
|
216
|
+
}
|
|
217
|
+
return {
|
|
218
|
+
balance,
|
|
219
|
+
withdrawRuleName: withdraw_rule,
|
|
220
|
+
withdrawLimit,
|
|
221
|
+
}
|
|
222
|
+
}),
|
|
223
|
+
updateWithdrawCondition: assign((context, event) => {
|
|
224
|
+
const rules = event.data.rules.filter((rule) => rule.maxWithdrawAmount > 0)
|
|
225
|
+
const tutorialUrls = event.data.adUrl.map((item) => item.url)
|
|
226
|
+
|
|
227
|
+
const { balance, withdrawLimit } = context
|
|
228
|
+
const lastMatchedIndex = findLastIndex(rules, (rule) => balance >= rule.greaterEqualThen)
|
|
229
|
+
|
|
230
|
+
let left = 0,
|
|
231
|
+
limit,
|
|
232
|
+
amount = 0
|
|
233
|
+
if (lastMatchedIndex > -1) {
|
|
234
|
+
rules[lastMatchedIndex].match = true
|
|
235
|
+
amount = rules[lastMatchedIndex].maxWithdrawAmount
|
|
236
|
+
limit = rules[lastMatchedIndex].greaterEqualThen
|
|
237
|
+
} else if (withdrawLimit) {
|
|
238
|
+
const diff = withdrawLimit - balance
|
|
239
|
+
limit = withdrawLimit
|
|
240
|
+
if (diff < 0) {
|
|
241
|
+
amount = balance
|
|
242
|
+
} else {
|
|
243
|
+
left = diff
|
|
244
|
+
}
|
|
245
|
+
} else {
|
|
246
|
+
left = rules[0]?.greaterEqualThen - balance
|
|
247
|
+
limit = rules[0]?.greaterEqualThen
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
return {
|
|
251
|
+
withdrawLeft: left,
|
|
252
|
+
withdrawAmount: amount,
|
|
253
|
+
withdrawLimit: limit,
|
|
254
|
+
withdrawRules: rules,
|
|
255
|
+
tutorialUrls,
|
|
256
|
+
}
|
|
257
|
+
}),
|
|
258
|
+
setBalanceToWithdrawAmount: assign((context, event) => {
|
|
259
|
+
return {
|
|
260
|
+
withdrawAmount: context.balance,
|
|
261
|
+
}
|
|
262
|
+
}),
|
|
263
|
+
setCrypto: assign((context, event) => {
|
|
264
|
+
return {
|
|
265
|
+
crypto: event.data?.[0],
|
|
266
|
+
networks: event.data?.[0]?.optional || [],
|
|
267
|
+
}
|
|
268
|
+
}),
|
|
269
|
+
setNetwork: assign((context, event) => {
|
|
270
|
+
return {
|
|
271
|
+
currentNetwork: event.data,
|
|
272
|
+
}
|
|
273
|
+
}),
|
|
274
|
+
setAddress: assign((context, event) => {
|
|
275
|
+
return {
|
|
276
|
+
currentAddress: event.data,
|
|
277
|
+
}
|
|
278
|
+
}),
|
|
279
|
+
setCalculatedResult: assign((context, event) => {
|
|
280
|
+
return {
|
|
281
|
+
charge: event.data.charge,
|
|
282
|
+
}
|
|
283
|
+
}),
|
|
284
|
+
resetCharge: assign((context, event) => {
|
|
285
|
+
return {
|
|
286
|
+
charge: null,
|
|
287
|
+
}
|
|
288
|
+
}),
|
|
289
|
+
calculateCashLeft: assign((context, event) => {
|
|
290
|
+
const { balance, withdrawLimit } = context
|
|
291
|
+
const diff = withdrawLimit - balance
|
|
292
|
+
const left = Math.max(diff, 0)
|
|
293
|
+
return {
|
|
294
|
+
withdrawLeft: left,
|
|
295
|
+
}
|
|
296
|
+
}),
|
|
297
|
+
},
|
|
298
|
+
guards: {
|
|
299
|
+
isFree: (context, event) => {
|
|
300
|
+
return context.userInfo?.withdraw_policy === 'FREE'
|
|
301
|
+
},
|
|
302
|
+
isWithdrawDisable: (context, event) => {
|
|
303
|
+
const { siteConfig } = context
|
|
304
|
+
const methods = siteConfig?.paymentMethods?.withdraw || []
|
|
305
|
+
return methods.length === 0
|
|
306
|
+
},
|
|
307
|
+
isTransferable: (context, event) => {
|
|
308
|
+
const { balance, withdrawLimit, isTurnoverMode } = context
|
|
309
|
+
if (balance === 0) {
|
|
310
|
+
return false
|
|
311
|
+
}
|
|
312
|
+
if (isTurnoverMode) {
|
|
313
|
+
return withdrawLimit === 0
|
|
314
|
+
} else {
|
|
315
|
+
return balance - withdrawLimit >= 0
|
|
316
|
+
}
|
|
317
|
+
},
|
|
318
|
+
isCalculable: (context, event) => {
|
|
319
|
+
const { currentNetwork, balance } = context
|
|
320
|
+
return currentNetwork && balance
|
|
321
|
+
},
|
|
322
|
+
},
|
|
323
|
+
services: {
|
|
324
|
+
fetchWithdrawRules: async (context, event) => {
|
|
325
|
+
return await request.send(api.getCurrentWithdrawRule())
|
|
326
|
+
},
|
|
327
|
+
fetchPayments: async (context, event) => {
|
|
328
|
+
return await request.send(api.getPaymentDetail({ transferType: 'WITHDRAW' }))
|
|
329
|
+
},
|
|
330
|
+
submitWithdraw: async (context, event) => {
|
|
331
|
+
const { crypto, currentNetwork, currentAddress, withdrawAmount } = context
|
|
332
|
+
const method = crypto.method
|
|
333
|
+
return await request.send(
|
|
334
|
+
api.submitWithdrawTransaction({
|
|
335
|
+
method,
|
|
336
|
+
amount: withdrawAmount,
|
|
337
|
+
cryptoCurrency: crypto.channel,
|
|
338
|
+
cryptoNetwork: currentNetwork,
|
|
339
|
+
targetAddress: currentAddress,
|
|
340
|
+
})
|
|
341
|
+
)
|
|
342
|
+
},
|
|
343
|
+
submitWithdrawFree: async (context, event) => {
|
|
344
|
+
const { currentNetwork, currentAddress } = context
|
|
345
|
+
return await request.send(
|
|
346
|
+
api.convertFreeCredit({
|
|
347
|
+
exchangeType: 1,
|
|
348
|
+
cryptoNetwork: currentNetwork,
|
|
349
|
+
targetAddress: currentAddress,
|
|
350
|
+
})
|
|
351
|
+
)
|
|
352
|
+
},
|
|
353
|
+
fetchCalculation: async (context, event) => {
|
|
354
|
+
const { crypto, currentNetwork, withdrawAmount } = context
|
|
355
|
+
const method = crypto.method
|
|
356
|
+
return await request.send(
|
|
357
|
+
api.getWithdrawExpectedResult({
|
|
358
|
+
method,
|
|
359
|
+
amount: withdrawAmount,
|
|
360
|
+
cryptoNetwork: currentNetwork,
|
|
361
|
+
})
|
|
362
|
+
)
|
|
363
|
+
},
|
|
364
|
+
},
|
|
365
|
+
}
|
|
366
|
+
)
|
|
367
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import urljoin from 'url-join'
|
|
2
|
+
|
|
3
|
+
export default class Config {
|
|
4
|
+
constructor({ apiURL, apiVersion, clientId, appSecret, platform, version }) {
|
|
5
|
+
this.apiURL = apiURL
|
|
6
|
+
this.apiVersion = apiVersion
|
|
7
|
+
this.clientId = clientId
|
|
8
|
+
this.appSecret = appSecret
|
|
9
|
+
this.platform = platform
|
|
10
|
+
this.version = version
|
|
11
|
+
this.fullURL = urljoin(this.apiURL, this.apiVersion, this.clientId)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
setApiURL(url) {
|
|
15
|
+
this.apiURL = url
|
|
16
|
+
this.fullURL = urljoin(this.apiURL, this.apiVersion, this.clientId)
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import Cookies from 'universal-cookie'
|
|
2
|
+
|
|
3
|
+
export default class Cookie {
|
|
4
|
+
constructor(tokenKey) {
|
|
5
|
+
this.cookies = new Cookies()
|
|
6
|
+
this.tokenKey = tokenKey
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
setToken(token) {
|
|
10
|
+
this.cookies.set(this.tokenKey, token, {
|
|
11
|
+
path: '/',
|
|
12
|
+
maxAge: 300,
|
|
13
|
+
})
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
prolongToken() {
|
|
17
|
+
const token = this.getToken()
|
|
18
|
+
if (token) {
|
|
19
|
+
this.setToken(token)
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
getToken() {
|
|
24
|
+
return this.cookies.get(this.tokenKey)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
removeToken() {
|
|
28
|
+
this.cookies.remove(this.tokenKey, {
|
|
29
|
+
path: '/',
|
|
30
|
+
maxAge: 300,
|
|
31
|
+
})
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
setUser(user) {
|
|
35
|
+
this.cookies.set('cuora_tempuser', user, {
|
|
36
|
+
path: '/',
|
|
37
|
+
maxAge: 60 * 60 * 24,
|
|
38
|
+
})
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
getUser() {
|
|
42
|
+
return this.cookies.get('cuora_tempuser')
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
set(name, value, options) {
|
|
46
|
+
this.cookies.set(name, value, options)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
get(name, options) {
|
|
50
|
+
return this.cookies.get(name, options)
|
|
51
|
+
}
|
|
52
|
+
}
|