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,
|
|
|
|
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-07-04 01:25:01 +00:00
|
|
|
import { languages, 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-04-14 06:25:01 +00:00
|
|
|
|
2017-07-27 17:05:09 +00:00
|
|
|
export const INITIAL_STATE: State = {
|
2017-07-04 03:21:19 +00:00
|
|
|
languageSelection: languages[0].sign,
|
2017-07-20 17:06:10 +00:00
|
|
|
nodeSelection: Object.keys(NODES)[0],
|
|
|
|
gasPriceGwei: 21
|
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,
|
|
|
|
languageSelection: action.value
|
|
|
|
};
|
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,
|
|
|
|
nodeSelection: action.value
|
|
|
|
};
|
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,
|
|
|
|
gasPriceGwei: action.value
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
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-07-02 05:49:06 +00:00
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
2017-04-14 06:25:01 +00:00
|
|
|
}
|