2017-09-25 02:06:28 +00:00
|
|
|
import {
|
|
|
|
ChangeGasPriceAction,
|
2017-07-20 17:06:10 +00:00
|
|
|
ChangeLanguageAction,
|
2017-09-25 02:06:28 +00:00
|
|
|
ChangeNodeAction,
|
2017-10-19 02:29:49 +00:00
|
|
|
ConfigAction
|
2017-07-04 03:21:19 +00:00
|
|
|
} from 'actions/config';
|
2017-09-25 02:06:28 +00:00
|
|
|
import { TypeKeys } from 'actions/config/constants';
|
2017-10-11 05:04:49 +00:00
|
|
|
import { NODES } from '../config/data';
|
2017-04-14 06:25:01 +00:00
|
|
|
|
2017-09-25 02:06:28 +00:00
|
|
|
export interface State {
|
2017-07-02 05:49:06 +00:00
|
|
|
// FIXME
|
2017-09-25 02:06:28 +00:00
|
|
|
languageSelection: string;
|
|
|
|
nodeSelection: string;
|
|
|
|
gasPriceGwei: number;
|
2017-10-11 05:04:49 +00:00
|
|
|
offline: boolean;
|
|
|
|
forceOffline: boolean;
|
2017-09-25 02:06:28 +00:00
|
|
|
}
|
2017-04-14 06:25:01 +00:00
|
|
|
|
2017-07-27 17:05:09 +00:00
|
|
|
export const INITIAL_STATE: State = {
|
2017-09-26 23:03:38 +00:00
|
|
|
languageSelection: 'en',
|
2017-07-20 17:06:10 +00:00
|
|
|
nodeSelection: Object.keys(NODES)[0],
|
2017-10-11 05:04:49 +00:00
|
|
|
gasPriceGwei: 21,
|
|
|
|
offline: false,
|
|
|
|
forceOffline: false
|
2017-07-02 05:49:06 +00:00
|
|
|
};
|
2017-04-14 06:25:01 +00:00
|
|
|
|
2017-07-04 01:25:01 +00:00
|
|
|
function changeLanguage(state: State, action: ChangeLanguageAction): State {
|
2017-07-04 03:21:19 +00:00
|
|
|
return {
|
|
|
|
...state,
|
2017-10-11 05:04:49 +00:00
|
|
|
languageSelection: action.payload
|
2017-07-04 03:21:19 +00:00
|
|
|
};
|
2017-06-26 22:27:55 +00:00
|
|
|
}
|
|
|
|
|
2017-07-04 01:25:01 +00:00
|
|
|
function changeNode(state: State, action: ChangeNodeAction): State {
|
2017-07-04 03:21:19 +00:00
|
|
|
return {
|
|
|
|
...state,
|
2017-10-11 05:04:49 +00:00
|
|
|
nodeSelection: action.payload
|
2017-07-04 03:21:19 +00:00
|
|
|
};
|
2017-04-14 06:25:01 +00:00
|
|
|
}
|
|
|
|
|
2017-07-20 17:06:10 +00:00
|
|
|
function changeGasPrice(state: State, action: ChangeGasPriceAction): State {
|
|
|
|
return {
|
|
|
|
...state,
|
2017-10-11 05:04:49 +00:00
|
|
|
gasPriceGwei: action.payload
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-10-19 02:29:49 +00:00
|
|
|
function toggleOffline(state: State): State {
|
2017-10-11 05:04:49 +00:00
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
offline: !state.offline
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-10-19 02:29:49 +00:00
|
|
|
function forceOffline(state: State): State {
|
2017-10-11 05:04:49 +00:00
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
forceOffline: !state.forceOffline
|
2017-07-20 17:06:10 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-07-04 03:21:19 +00:00
|
|
|
export function config(
|
2017-07-27 17:05:09 +00:00
|
|
|
state: State = INITIAL_STATE,
|
2017-07-04 03:21:19 +00:00
|
|
|
action: ConfigAction
|
|
|
|
): State {
|
2017-07-02 05:49:06 +00:00
|
|
|
switch (action.type) {
|
2017-09-25 02:06:28 +00:00
|
|
|
case TypeKeys.CONFIG_LANGUAGE_CHANGE:
|
2017-07-04 03:21:19 +00:00
|
|
|
return changeLanguage(state, action);
|
2017-09-25 02:06:28 +00:00
|
|
|
case TypeKeys.CONFIG_NODE_CHANGE:
|
2017-07-04 03:21:19 +00:00
|
|
|
return changeNode(state, action);
|
2017-09-25 02:06:28 +00:00
|
|
|
case TypeKeys.CONFIG_GAS_PRICE:
|
2017-07-20 17:06:10 +00:00
|
|
|
return changeGasPrice(state, action);
|
2017-10-11 05:04:49 +00:00
|
|
|
case TypeKeys.CONFIG_TOGGLE_OFFLINE:
|
2017-10-19 02:29:49 +00:00
|
|
|
return toggleOffline(state);
|
2017-10-11 05:04:49 +00:00
|
|
|
case TypeKeys.CONFIG_FORCE_OFFLINE:
|
2017-10-19 02:29:49 +00:00
|
|
|
return forceOffline(state);
|
2017-07-02 05:49:06 +00:00
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
2017-04-14 06:25:01 +00:00
|
|
|
}
|