import axios from 'axios'; import AppDispatcher from '../dispatcher/AppDispatcher'; import ActionTypes from '../constants/ActionTypes'; const ClientActions = { fetchTransferData: () => { return axios.get('/client/stats') .then((json = {}) => { return json.data; }) .then((transferData) => { AppDispatcher.dispatchServerAction({ type: ActionTypes.CLIENT_FETCH_TRANSFER_DATA_SUCCESS, data: { transferData } }); }) .catch((error) => { AppDispatcher.dispatchServerAction({ type: ActionTypes.CLIENT_FETCH_TRANSFER_DATA_ERROR, data: { error } }); }); }, fetchTransferHistory: (opts) => { return axios.get('/client/history', { params: opts }) .then((json = {}) => { return json.data; }) .then((data) => { AppDispatcher.dispatchServerAction({ type: ActionTypes.CLIENT_FETCH_TRANSFER_HISTORY_SUCCESS, data }); }) .catch((error) => { AppDispatcher.dispatchServerAction({ type: ActionTypes.CLIENT_FETCH_TRANSFER_HISTORY_ERROR, error }); }) }, setThrottle: (direction, throttle) => { return axios.put('/client/settings/speed-limits', { direction, throttle }) .then((json = {}) => { return json.data; }) .then((transferData) => { AppDispatcher.dispatchServerAction({ type: ActionTypes.CLIENT_SET_THROTTLE_SUCCESS, data: { transferData } }); }) .catch((error) => { AppDispatcher.dispatchServerAction({ type: ActionTypes.CLIENT_SET_THROTTLE_ERROR, data: { error } }); }); } }; export default ClientActions;