@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.
- package/CHANGELOG.md +4 -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/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.26](https://github.com/jetthai/cuora-module/compare/v1.0.25...v1.0.26) (2021-10-13)
|
|
6
|
+
|
|
7
|
+
### [1.0.25](https://github.com/jetthai/cuora-module/compare/v1.0.24...v1.0.25) (2021-08-30)
|
|
8
|
+
|
|
5
9
|
### [1.0.24](https://github.com/jetthai/cuora-module/compare/v1.0.23...v1.0.24) (2021-08-25)
|
|
6
10
|
|
|
7
11
|
### [1.0.23](https://github.com/jetthai/cuora-module/compare/v1.0.22...v1.0.23) (2021-08-25)
|
package/api/activity.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
getActivityTypes: ({ appSecret }) => ({ url: 'activities/types', method: 'get', params: { appSecret } }),
|
|
3
|
+
getActivityList: ({ appSecret, include }) => ({
|
|
4
|
+
url: 'activities/list',
|
|
5
|
+
method: 'get',
|
|
6
|
+
params: { appSecret, include },
|
|
7
|
+
}),
|
|
8
|
+
getActivityDetail: ({ activityNo, appSecret }) => ({
|
|
9
|
+
url: 'activities',
|
|
10
|
+
method: 'get',
|
|
11
|
+
params: { activityNo, appSecret },
|
|
12
|
+
}),
|
|
13
|
+
getAchievements: ({ limit, page, appSecret }) => ({
|
|
14
|
+
url: 'activities/achievements',
|
|
15
|
+
method: 'get',
|
|
16
|
+
params: {
|
|
17
|
+
limit,
|
|
18
|
+
page,
|
|
19
|
+
appSecret,
|
|
20
|
+
},
|
|
21
|
+
}),
|
|
22
|
+
getAchievementsProgress: ({ achievementNo, appSecret }) => ({
|
|
23
|
+
url: 'activities/achievements/progress',
|
|
24
|
+
method: 'get',
|
|
25
|
+
params: { achievementNo, appSecret },
|
|
26
|
+
}),
|
|
27
|
+
getAchievementsIssued: () => ({ url: 'activities/achievements/issue', method: 'get' }),
|
|
28
|
+
postPromoCode: (promoCode) => ({
|
|
29
|
+
url: 'activities/promo',
|
|
30
|
+
method: 'post',
|
|
31
|
+
params: { promoCode },
|
|
32
|
+
}),
|
|
33
|
+
sentAward: ({ activityNo, gender, email, score, suggest, uidSite, affiliateCode, appSecret }) => ({
|
|
34
|
+
url: 'activities/sentAward',
|
|
35
|
+
method: 'post',
|
|
36
|
+
params: { activityNo, gender, email, score, suggest, uidSite, affiliateCode, appSecret },
|
|
37
|
+
}),
|
|
38
|
+
getReward: ({ activityNo, receiveNo, appSecret }) => ({
|
|
39
|
+
url: 'activities/rewards',
|
|
40
|
+
method: 'post',
|
|
41
|
+
params: { activityNo, receiveNo, appSecret },
|
|
42
|
+
}),
|
|
43
|
+
getRewardList: ({ count, appSecret }) => ({ url: 'activities/rewards', method: 'get', params: { count, appSecret } }),
|
|
44
|
+
exchange: (data) => ({ url: 'activities/exchange', method: 'post', params: data }),
|
|
45
|
+
collect: ({ appSecret }) => ({ url: 'activities/collect', method: 'post', params: { appSecret } }),
|
|
46
|
+
}
|
package/api/auth.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
login: ({ username, password, provider, countryCode, phone }) => ({
|
|
3
|
+
url: 'login',
|
|
4
|
+
method: 'post',
|
|
5
|
+
params: { username, password, provider, countryCode, phone },
|
|
6
|
+
isPublic: true,
|
|
7
|
+
}),
|
|
8
|
+
register: (data) => ({
|
|
9
|
+
url: 'register?channel=official&subchannel=pwa',
|
|
10
|
+
method: 'post',
|
|
11
|
+
params: data,
|
|
12
|
+
isPublic: true,
|
|
13
|
+
}),
|
|
14
|
+
logout: () => ({ url: 'logout', method: 'post' }),
|
|
15
|
+
}
|
package/api/common.js
ADDED
package/api/game.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
getGameSHA: () => ({ method: 'get', url: 'game/list/v2/sha' }),
|
|
3
|
+
getOptionMap: (code) => ({ method: 'get', url: 'game/list/v2/options', params: { code } }),
|
|
4
|
+
getGameStatus: () => ({ method: 'get', url: 'game/list/v2/status' }),
|
|
5
|
+
getGameCategory: ({ id, first }) => ({ method: 'get', url: 'game/list/v2/category', params: { id, first } }),
|
|
6
|
+
addFavoriteGame: (code) => ({ method: 'post', url: 'game/myfavorite/add', params: { games: [code] } }),
|
|
7
|
+
removeFavoriteGame: (code) => ({ method: 'post', url: 'game/myfavorite/remove', params: { games: [code] } }),
|
|
8
|
+
getStatements: () => ({ url: 'game/statements', method: 'get' }),
|
|
9
|
+
playGame: (params) => ({ url: 'game/play', method: 'get', params }),
|
|
10
|
+
logoutGame: ({ uid_site, provider_id }) => ({ url: 'game/logout', method: 'get', params: { uid_site, provider_id } }),
|
|
11
|
+
|
|
12
|
+
getGameTags: ({ q }) => ({ url: 'game/search', method: 'get', params: { q } }),
|
|
13
|
+
getGameSearchList: ({ id, index, q, click, clickDefault }) => ({
|
|
14
|
+
url: 'game/search/list',
|
|
15
|
+
method: 'get',
|
|
16
|
+
params: { id, index, q, click, clickDefault },
|
|
17
|
+
}),
|
|
18
|
+
setGameSearchTrace: ({ traceId, tagId, tagIndex, gameCode, gameCodeIndex, query, click, clickDefault }) => ({
|
|
19
|
+
url: 'game/search/trace',
|
|
20
|
+
method: 'post',
|
|
21
|
+
params: {
|
|
22
|
+
traceId,
|
|
23
|
+
tagId,
|
|
24
|
+
tagIndex,
|
|
25
|
+
gameCode,
|
|
26
|
+
gameCodeIndex,
|
|
27
|
+
query,
|
|
28
|
+
click,
|
|
29
|
+
clickDefault,
|
|
30
|
+
},
|
|
31
|
+
}),
|
|
32
|
+
}
|
package/api/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import activity from './activity'
|
|
2
|
+
import auth from './auth'
|
|
3
|
+
import core from './common'
|
|
4
|
+
import game from './game'
|
|
5
|
+
import mailbox from './mailbox'
|
|
6
|
+
import payment from './payment'
|
|
7
|
+
import user from './user'
|
|
8
|
+
|
|
9
|
+
export default { activity, auth, core, game, mailbox, payment, user }
|
package/api/mailbox.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
getMessageTypes: () => ({ url: 'mailbox/getMessageTypes', method: 'get' }),
|
|
3
|
+
getMessageList: ({ type, limit = 10, page }) => ({
|
|
4
|
+
url: 'mailbox/getMessageList?include=cl',
|
|
5
|
+
method: 'post',
|
|
6
|
+
params: { type, limit, page },
|
|
7
|
+
}),
|
|
8
|
+
updateMessage: ({ groupId, isRead }) => ({
|
|
9
|
+
url: 'mailbox/updateMessage',
|
|
10
|
+
method: 'post',
|
|
11
|
+
params: { groupId, isRead },
|
|
12
|
+
}),
|
|
13
|
+
sendMessage: () => ({ url: 'mailbox/sendMessage', method: 'post' }),
|
|
14
|
+
getMessage: ({ groupId, limit = 10, pageIdx }) => ({
|
|
15
|
+
url: 'mailbox/getMessage',
|
|
16
|
+
method: 'post',
|
|
17
|
+
params: { groupId, limit, pageIdx },
|
|
18
|
+
}),
|
|
19
|
+
deleteMessage: ({ mid, isDelete }) => ({ url: 'mailbox/deleteMessage', method: 'post', params: { mid, isDelete } }),
|
|
20
|
+
}
|
package/api/payment.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
// getPaymentHistory: () => ({ url: 'payment/history', method: 'post' }),
|
|
3
|
+
getPaymentHistory: (returnDays) => ({ url: 'payment/v2/history', method: 'post', params: { returnDays } }),
|
|
4
|
+
getSpotMarket: () => ({ url: 'payment/spotmarket', method: 'get' }),
|
|
5
|
+
getPaymentInfo: () => ({ url: `payment/paymentInfo`, method: 'get' }),
|
|
6
|
+
updatePaymentInfo: ({
|
|
7
|
+
bankCode,
|
|
8
|
+
bankAccount,
|
|
9
|
+
firstNameTh,
|
|
10
|
+
lastNameTh,
|
|
11
|
+
firstNameEn,
|
|
12
|
+
lastNameEn,
|
|
13
|
+
bonus,
|
|
14
|
+
paymentProvider,
|
|
15
|
+
}) => ({
|
|
16
|
+
url: 'payment/updatePaymentInfo',
|
|
17
|
+
method: 'post',
|
|
18
|
+
params: { bankCode, bankAccount, firstNameTh, lastNameTh, firstNameEn, lastNameEn, bonus, paymentProvider },
|
|
19
|
+
}),
|
|
20
|
+
getBankList: (paymentMethod) => ({ url: `payment/${paymentMethod}/getBankList`, method: 'get' }),
|
|
21
|
+
makeTransaction: ({ type, payload, paymentMethod }) => ({
|
|
22
|
+
url: `payment/${paymentMethod}/transaction`,
|
|
23
|
+
method: 'post',
|
|
24
|
+
params: {
|
|
25
|
+
transferType: type,
|
|
26
|
+
...payload,
|
|
27
|
+
},
|
|
28
|
+
}),
|
|
29
|
+
checkTransaction: (paymentMethod) => ({ url: `payment/${paymentMethod}/checkTransaction`, method: 'post' }),
|
|
30
|
+
setBonusSetting: ({ bonus }) => ({ url: 'payment/setting', method: 'post', params: { bonus } }),
|
|
31
|
+
getCurrentWithdrawRule: () => ({ url: 'payment/getCurrentWithdrawRule', method: 'get' }),
|
|
32
|
+
convertFreeCredit: ({ exchangeType, cryptoNetwork, targetAddress }) => ({
|
|
33
|
+
url: 'payment/convertFreeCredit',
|
|
34
|
+
method: 'post',
|
|
35
|
+
params: { exchangeType, cryptoNetwork, targetAddress },
|
|
36
|
+
}),
|
|
37
|
+
mergeWallet: () => ({ url: 'payment/mergeWallet', method: 'post' }),
|
|
38
|
+
getPaymentDetail: ({ transferType }) => ({
|
|
39
|
+
url: 'payment/v2/paymentDetail',
|
|
40
|
+
method: 'post',
|
|
41
|
+
params: { transferType },
|
|
42
|
+
}),
|
|
43
|
+
getDepositExpectedResult: ({ method, amount, cryptoCurrency }) => ({
|
|
44
|
+
url: `payment/v2/${method}/expected/result`,
|
|
45
|
+
method: 'post',
|
|
46
|
+
params: { transferType: 'DEPOSIT', amount, cryptoCurrency },
|
|
47
|
+
}),
|
|
48
|
+
getWithdrawExpectedResult: ({ method, amount, cryptoNetwork }) => ({
|
|
49
|
+
url: `payment/v2/${method}/expected/result`,
|
|
50
|
+
method: 'post',
|
|
51
|
+
params: { transferType: 'WITHDRAW', amount, cryptoNetwork },
|
|
52
|
+
}),
|
|
53
|
+
submitDepositTransaction: ({ method, amount, cryptoCurrency, cryptoNetwork }) => ({
|
|
54
|
+
url: `payment/v2/${method}/transaction`,
|
|
55
|
+
method: 'post',
|
|
56
|
+
params: { transferType: 'DEPOSIT', amount, cryptoCurrency, cryptoNetwork },
|
|
57
|
+
}),
|
|
58
|
+
submitWithdrawTransaction: ({ method, amount, cryptoCurrency, cryptoNetwork, targetAddress }) => ({
|
|
59
|
+
url: `payment/v2/${method}/transaction`,
|
|
60
|
+
method: 'post',
|
|
61
|
+
params: { transferType: 'WITHDRAW', amount, cryptoCurrency, cryptoNetwork, targetAddress },
|
|
62
|
+
}),
|
|
63
|
+
}
|
package/api/user.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
getUserInfo: () => ({ url: 'self', method: 'get' }),
|
|
3
|
+
modifyUserInfo: (data) => ({ url: 'self', method: 'post', params: data }),
|
|
4
|
+
changePassword: (data) => ({ url: 'settings/password', method: 'post', params: data }),
|
|
5
|
+
setPreference: ({ defaultCategory }) => ({ url: 'settings/preference', method: 'post', params: { defaultCategory } }),
|
|
6
|
+
resetOtp: ({ requestId, number }) => ({ url: 'reset', method: 'post', params: { requestId, number } }),
|
|
7
|
+
getAffiliate: () => ({ url: 'affiliate', method: 'get' }),
|
|
8
|
+
postAffiliate: ({ affiliateCode }) => ({ url: 'affiliate', method: 'post', params: { affiliateCode } }),
|
|
9
|
+
passwordRecovery: (recoveryData) => ({ url: 'recovery', method: 'post', params: recoveryData, isPublic: true }),
|
|
10
|
+
passwordAbandon: ({ number }) => ({ url: 'recovery/abandon', method: 'post', params: { number }, isPublic: true }),
|
|
11
|
+
passwordAcknowledge: (acknowledgeData) => ({
|
|
12
|
+
url: 'recovery/acknowledge',
|
|
13
|
+
method: 'post',
|
|
14
|
+
params: acknowledgeData,
|
|
15
|
+
isPublic: true,
|
|
16
|
+
}),
|
|
17
|
+
verify: () => ({ url: 'verify', method: 'post' }),
|
|
18
|
+
acknowledge: ({ requestId, code }) => ({ url: 'acknowledge', method: 'post', params: { requestId, code } }),
|
|
19
|
+
}
|
package/index.js
CHANGED
|
@@ -1,58 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
export
|
|
4
|
-
const options = { ...this.options.cuora, ...moduleOptions }
|
|
5
|
-
|
|
6
|
-
this.addPlugin({
|
|
7
|
-
src: path.resolve(__dirname, './plugin/job/network.js'),
|
|
8
|
-
options,
|
|
9
|
-
mode: 'client',
|
|
10
|
-
})
|
|
11
|
-
|
|
12
|
-
this.addPlugin({
|
|
13
|
-
src: path.resolve(__dirname, './plugin/search.js'),
|
|
14
|
-
options,
|
|
15
|
-
})
|
|
16
|
-
|
|
17
|
-
this.addPlugin({
|
|
18
|
-
src: path.resolve(__dirname, './plugin/user.js'),
|
|
19
|
-
options,
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
this.addPlugin({
|
|
23
|
-
src: path.resolve(__dirname, './plugin/core.js'),
|
|
24
|
-
options,
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
this.addPlugin({
|
|
28
|
-
src: path.resolve(__dirname, './plugin/information.js'),
|
|
29
|
-
options,
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
this.addPlugin({
|
|
33
|
-
src: path.resolve(__dirname, './plugin/activity.js'),
|
|
34
|
-
options,
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
this.addPlugin({
|
|
38
|
-
src: path.resolve(__dirname, './plugin/payment.js'),
|
|
39
|
-
options,
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
this.addPlugin({
|
|
43
|
-
src: path.resolve(__dirname, './plugin/inbox.js'),
|
|
44
|
-
options,
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
this.addPlugin({
|
|
48
|
-
src: path.resolve(__dirname, './plugin/game.js'),
|
|
49
|
-
options,
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
this.addPlugin({
|
|
53
|
-
src: path.resolve(__dirname, './plugin/request.js'),
|
|
54
|
-
options,
|
|
55
|
-
})
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
module.exports.meta = require('./package.json')
|
|
1
|
+
import api from './api'
|
|
2
|
+
import machine from './machine'
|
|
3
|
+
export { api, machine }
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { createMachine, assign, respond } from 'xstate'
|
|
2
|
+
import api from '../../api/activity'
|
|
3
|
+
|
|
4
|
+
export default function (request) {
|
|
5
|
+
const { appSecret } = request.config
|
|
6
|
+
return createMachine(
|
|
7
|
+
{
|
|
8
|
+
id: 'activity',
|
|
9
|
+
initial: 'fetchingTimerDataList',
|
|
10
|
+
context: {
|
|
11
|
+
tick: 2000,
|
|
12
|
+
activityList: [],
|
|
13
|
+
activityMap: {},
|
|
14
|
+
rewardList: [],
|
|
15
|
+
tournamentList: [],
|
|
16
|
+
refs: {},
|
|
17
|
+
},
|
|
18
|
+
states: {
|
|
19
|
+
fetchingTimerDataList: {
|
|
20
|
+
invoke: {
|
|
21
|
+
src: 'fetchTimerDataList',
|
|
22
|
+
onDone: {
|
|
23
|
+
target: 'pending',
|
|
24
|
+
actions: ['setTimerDataList', 'setTournamentList'],
|
|
25
|
+
},
|
|
26
|
+
onError: {
|
|
27
|
+
target: 'pending',
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
pending: {
|
|
32
|
+
after: {
|
|
33
|
+
TIMEOUT: {
|
|
34
|
+
target: 'fetchingTimerDataList',
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
actions: {
|
|
42
|
+
setTournamentList: assign((context, event) => {
|
|
43
|
+
const tournamentList = event.data.activityList.filter((item) => item.tournament === 1)
|
|
44
|
+
return {
|
|
45
|
+
tournamentList,
|
|
46
|
+
}
|
|
47
|
+
}),
|
|
48
|
+
setTimerDataList: assign((context, event) => {
|
|
49
|
+
const { activityList, rewardList } = event.data
|
|
50
|
+
return {
|
|
51
|
+
activityList,
|
|
52
|
+
rewardList,
|
|
53
|
+
}
|
|
54
|
+
}),
|
|
55
|
+
},
|
|
56
|
+
delays: {
|
|
57
|
+
TIMEOUT: (context, event) => {
|
|
58
|
+
const { tick } = context
|
|
59
|
+
return tick * 10
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
services: {
|
|
63
|
+
fetchTimerDataList: async (context, event) => {
|
|
64
|
+
const [{ data: activityList }, { data: rewardList }] = await Promise.all([
|
|
65
|
+
request.send(api.getActivityList({ appSecret, include: 'cl' })),
|
|
66
|
+
request.send(api.getRewardList({ count: 30, appSecret })),
|
|
67
|
+
])
|
|
68
|
+
return { activityList, rewardList }
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
}
|
|
72
|
+
)
|
|
73
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { assign, createMachine } from 'xstate'
|
|
2
|
+
import api from '../../api/activity'
|
|
3
|
+
|
|
4
|
+
export default function (request) {
|
|
5
|
+
const { appSecret } = request.config
|
|
6
|
+
return createMachine(
|
|
7
|
+
{
|
|
8
|
+
id: 'continue_deposit_activity',
|
|
9
|
+
context: {
|
|
10
|
+
activityNo: null,
|
|
11
|
+
activityDetail: null,
|
|
12
|
+
stages: [],
|
|
13
|
+
currentStage: {},
|
|
14
|
+
receiveNo: null,
|
|
15
|
+
rewardType: '',
|
|
16
|
+
},
|
|
17
|
+
initial: 'idle',
|
|
18
|
+
states: {
|
|
19
|
+
idle: {
|
|
20
|
+
on: {
|
|
21
|
+
SET_ACTIVITY_NO: {
|
|
22
|
+
target: 'loading',
|
|
23
|
+
actions: 'setActivityNo',
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
loading: {
|
|
28
|
+
invoke: {
|
|
29
|
+
src: 'fetchActivityDetail',
|
|
30
|
+
onDone: {
|
|
31
|
+
target: 'loaded',
|
|
32
|
+
actions: ['setActivityDetail', 'setProperties', 'setReceiveNo'],
|
|
33
|
+
},
|
|
34
|
+
onError: {
|
|
35
|
+
target: 'idle',
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
loaded: {
|
|
40
|
+
always: [
|
|
41
|
+
{ target: 'receivable', cond: 'isReceivable' },
|
|
42
|
+
{ target: 'received', cond: 'isReceived' },
|
|
43
|
+
],
|
|
44
|
+
},
|
|
45
|
+
receivable: {
|
|
46
|
+
on: {
|
|
47
|
+
RECEIVE_REWARD: {
|
|
48
|
+
target: 'receiving',
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
receiving: {
|
|
53
|
+
invoke: {
|
|
54
|
+
src: 'receiveReward',
|
|
55
|
+
onDone: {
|
|
56
|
+
target: 'animating',
|
|
57
|
+
},
|
|
58
|
+
onError: {
|
|
59
|
+
target: 'loading',
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
animating: {
|
|
64
|
+
after: {
|
|
65
|
+
0: {
|
|
66
|
+
target: 'received',
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
received: {},
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
actions: {
|
|
75
|
+
setActivityNo: assign((context, event) => {
|
|
76
|
+
return {
|
|
77
|
+
activityNo: event.data,
|
|
78
|
+
}
|
|
79
|
+
}),
|
|
80
|
+
setActivityDetail: assign((context, event) => {
|
|
81
|
+
return {
|
|
82
|
+
activityDetail: event.data,
|
|
83
|
+
}
|
|
84
|
+
}),
|
|
85
|
+
setProperties: assign((context, event) => {
|
|
86
|
+
const { dayOfThePeriod, progress, policy } = event.data
|
|
87
|
+
const today = dayOfThePeriod - 1
|
|
88
|
+
const stages = progress.map((item, index) => {
|
|
89
|
+
return {
|
|
90
|
+
...item,
|
|
91
|
+
deposit: item.achieve ? item.target : Math.floor(item.deposit),
|
|
92
|
+
percentage: item.achieve ? 100 : Math.floor((item.deposit / item.target) * 100),
|
|
93
|
+
day: index + 1,
|
|
94
|
+
}
|
|
95
|
+
})
|
|
96
|
+
return {
|
|
97
|
+
currentStage: stages[today],
|
|
98
|
+
stages,
|
|
99
|
+
rewardType: policy,
|
|
100
|
+
}
|
|
101
|
+
}),
|
|
102
|
+
setReceiveNo: assign((context, event) => {
|
|
103
|
+
return {
|
|
104
|
+
receiveNo: event.data.receiveNo,
|
|
105
|
+
}
|
|
106
|
+
}),
|
|
107
|
+
},
|
|
108
|
+
guards: {
|
|
109
|
+
isReceivable: (context, event) => {
|
|
110
|
+
const { receiveNo, receiveStatus } = context.activityDetail
|
|
111
|
+
return receiveNo && receiveStatus === 2
|
|
112
|
+
},
|
|
113
|
+
isReceived: (context, event) => {
|
|
114
|
+
const { receiveStatus } = context.activityDetail
|
|
115
|
+
return receiveStatus === 1
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
services: {
|
|
119
|
+
fetchActivityDetail: async (context, event) => {
|
|
120
|
+
const { activityNo } = context
|
|
121
|
+
const { data } = await request.send(api.getActivityDetail({ activityNo, appSecret }))
|
|
122
|
+
return data
|
|
123
|
+
},
|
|
124
|
+
receiveReward: async (context, event) => {
|
|
125
|
+
const { activityNo, receiveNo } = context
|
|
126
|
+
const { data } = await request.send(api.getReward({ activityNo, receiveNo, appSecret }))
|
|
127
|
+
return data
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
}
|
|
131
|
+
)
|
|
132
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { assign, createMachine } from 'xstate'
|
|
2
|
+
import api from '../../api/activity'
|
|
3
|
+
|
|
4
|
+
export default function (request) {
|
|
5
|
+
const { appSecret } = request.config
|
|
6
|
+
return createMachine(
|
|
7
|
+
{
|
|
8
|
+
id: 'deposit_activity',
|
|
9
|
+
context: {
|
|
10
|
+
activityNo: null,
|
|
11
|
+
activityDetail: null,
|
|
12
|
+
duration: null,
|
|
13
|
+
},
|
|
14
|
+
initial: 'idle',
|
|
15
|
+
states: {
|
|
16
|
+
idle: {
|
|
17
|
+
on: {
|
|
18
|
+
SET_ACTIVITY_NO: {
|
|
19
|
+
target: 'loading',
|
|
20
|
+
actions: 'setActivityNo',
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
loading: {
|
|
25
|
+
invoke: {
|
|
26
|
+
src: 'fetchActivityDetail',
|
|
27
|
+
onDone: {
|
|
28
|
+
target: 'loaded',
|
|
29
|
+
actions: 'setActivityDetail',
|
|
30
|
+
},
|
|
31
|
+
onError: {
|
|
32
|
+
target: 'idle',
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
loaded: {
|
|
37
|
+
entry: 'setDuration',
|
|
38
|
+
always: [
|
|
39
|
+
{ target: 'expired', cond: 'isNotAvailable' },
|
|
40
|
+
{ target: 'expired', cond: 'isExpired' },
|
|
41
|
+
],
|
|
42
|
+
after: {
|
|
43
|
+
1000: {
|
|
44
|
+
target: 'loaded',
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
expired: {},
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
actions: {
|
|
53
|
+
setActivityNo: assign((context, event) => {
|
|
54
|
+
return {
|
|
55
|
+
activityNo: event.data,
|
|
56
|
+
}
|
|
57
|
+
}),
|
|
58
|
+
setActivityDetail: assign((context, event) => {
|
|
59
|
+
return {
|
|
60
|
+
activityDetail: event.data,
|
|
61
|
+
}
|
|
62
|
+
}),
|
|
63
|
+
setDuration: assign((context, event) => {
|
|
64
|
+
return {
|
|
65
|
+
duration: context?.activityDetail?.deadline - new Date().getTime() / 1000,
|
|
66
|
+
}
|
|
67
|
+
}),
|
|
68
|
+
},
|
|
69
|
+
guards: {
|
|
70
|
+
isExpired: (context, event) => {
|
|
71
|
+
return context.duration <= 0
|
|
72
|
+
},
|
|
73
|
+
isNotAvailable: (context, event) => {
|
|
74
|
+
return context?.activityDetail?.achieveStatus !== 1
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
services: {
|
|
78
|
+
fetchActivityDetail: async (context, event) => {
|
|
79
|
+
const { activityNo } = context
|
|
80
|
+
const { data } = await request.send(api.getActivityDetail({ activityNo, appSecret }))
|
|
81
|
+
return data
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
}
|
|
85
|
+
)
|
|
86
|
+
}
|