/
reducer.js
63 lines (60 loc) 路 1.53 KB
/
reducer.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
// @flow
import type { Action } from '/types';
import { LOGOUT } from '/redux/auth/actions';
import { SET_ALLOCATION, RESET_NODE_SETTINGS, GET_DRIVES_LIST, SET_LOCAL_NODE_SETUP_PROGRESS, SET_TOTAL_EARNINGS, SET_UPCOMING_EARNINGS, SET_AWARDS_ADDRESS } from './actions';
const initialState = {
drive: null,
capacity: null,
drives: [],
progress: null,
totalEarnings: null,
upcomingEarnings: null,
awardsAddress: null,
pathToLocalNode: null
};
const reducer = (state: any = initialState, action: Action) => {
switch (action.type) {
case SET_ALLOCATION: {
const {
payload: { capacity, drive }
} = action;
return { ...state, capacity, drive };
}
case GET_DRIVES_LIST: {
const {
payload: { drives }
} = action;
return { ...state, drives };
}
case LOGOUT:
case RESET_NODE_SETTINGS:
return initialState;
case SET_LOCAL_NODE_SETUP_PROGRESS: {
const {
payload: { progress }
} = action;
return { ...state, progress: +progress };
}
case SET_TOTAL_EARNINGS: {
const {
payload: { totalEarnings }
} = action;
return { ...state, totalEarnings };
}
case SET_UPCOMING_EARNINGS: {
const {
payload: { upcomingEarnings }
} = action;
return { ...state, upcomingEarnings };
}
case SET_AWARDS_ADDRESS: {
const {
payload: { awardsAddress }
} = action;
return { ...state, awardsAddress };
}
default:
return state;
}
};
export default reducer;