/
actions.js
77 lines (69 loc) 路 2.91 KB
/
actions.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// @flow
import { diskStorageService } from '/infra/diskStorageService';
import { httpService } from '/infra/httpService';
import { Action, Dispatch } from '/types';
export const SET_ALLOCATION: string = 'SET_ALLOCATION';
export const GET_DRIVES_LIST: string = 'GET_DRIVES_LIST';
export const RESET_NODE_SETTINGS: string = 'RESET_NODE_SETTINGS';
export const SET_LOCAL_NODE_SETUP_PROGRESS: string = 'SET_LOCAL_NODE_SETUP_PROGRESS';
export const SET_TOTAL_EARNINGS: string = 'SET_TOTAL_EARNINGS';
export const SET_UPCOMING_EARNINGS: string = 'SET_UPCOMING_EARNINGS';
export const SET_AWARDS_ADDRESS: string = 'SET_AWARDS_ADDRESS';
export const getDrivesList = (): Action => async (dispatch: Dispatch): Dispatch => {
try {
const drives = await diskStorageService.getDriveList();
dispatch({ type: GET_DRIVES_LIST, payload: { drives } });
} catch (err) {
dispatch({ type: GET_DRIVES_LIST, payload: { drives: [] } });
throw err;
}
};
export const resetNodeSettings = (): Action => ({ type: RESET_NODE_SETTINGS });
export const getLocalNodeSetupProgress = (): Action => async (dispatch: Dispatch): Dispatch => {
try {
const progress = await httpService.getLocalNodeSetupProgress();
dispatch({ type: SET_LOCAL_NODE_SETUP_PROGRESS, payload: { progress } });
} catch (err) {
dispatch({ type: SET_LOCAL_NODE_SETUP_PROGRESS, payload: { progress: null } });
throw err;
}
};
export const getTotalEarnings = (): Action => async (dispatch: Dispatch): Dispatch => {
try {
const totalEarnings = await httpService.getTotalEarnings();
dispatch({ type: SET_TOTAL_EARNINGS, payload: { totalEarnings } });
} catch (err) {
dispatch({ type: SET_TOTAL_EARNINGS, payload: { progress: null } });
throw err;
}
};
export const getUpcomingEarnings = (): Action => async (dispatch: Dispatch): Dispatch => {
try {
const upcomingEarnings = await httpService.getUpcomingEarnings();
dispatch({ type: SET_UPCOMING_EARNINGS, payload: { upcomingEarnings } });
} catch (err) {
dispatch({ type: SET_UPCOMING_EARNINGS, payload: { progress: null } });
throw err;
}
};
export const setLocalNodeStorage = ({ capacity, drive }: { capacity: { id: number, label: string }, drive: { id: number, label: string } }): Action => async (
dispatch: Dispatch
): Dispatch => {
try {
const commitmentSize = Math.floor(capacity.id / 1048576); // Bytes to MB
const logicalDrive = drive.label;
await httpService.setCommitmentSize({ commitmentSize });
await httpService.setLogicalDrive({ logicalDrive });
dispatch({ type: SET_ALLOCATION, payload: { capacity, drive } });
} catch (err) {
throw err;
}
};
export const setAwardsAddress = ({ awardsAddress }: { awardsAddress: string }): Action => async (dispatch: Dispatch): Dispatch => {
try {
await httpService.setAwardsAddress({ awardsAddress });
dispatch({ type: SET_AWARDS_ADDRESS, payload: { awardsAddress } });
} catch (err) {
throw err;
}
};