MyCrypto/common/reducers/config.js

59 lines
1.2 KiB
JavaScript
Raw Normal View History

2017-06-26 15:27:55 -07:00
// @flow
2017-07-03 20:21:19 -07:00
import type {
ConfigAction,
ChangeNodeAction,
ChangeLanguageAction,
ChangeGasPriceAction
2017-07-03 20:21:19 -07:00
} from 'actions/config';
2017-07-03 18:25:01 -07:00
import { languages, NODES } from '../config/data';
2017-06-26 15:27:55 -07:00
export type State = {
2017-07-01 22:49:06 -07:00
// FIXME
languageSelection: string,
nodeSelection: string,
gasPriceGwei: number
2017-07-01 22:49:06 -07:00
};
export const initialState: State = {
2017-07-03 20:21:19 -07:00
languageSelection: languages[0].sign,
nodeSelection: Object.keys(NODES)[0],
gasPriceGwei: 21
2017-07-01 22:49:06 -07:00
};
2017-07-03 18:25:01 -07:00
function changeLanguage(state: State, action: ChangeLanguageAction): State {
2017-07-03 20:21:19 -07:00
return {
...state,
languageSelection: action.value
};
2017-06-26 15:27:55 -07:00
}
2017-07-03 18:25:01 -07:00
function changeNode(state: State, action: ChangeNodeAction): State {
2017-07-03 20:21:19 -07:00
return {
...state,
nodeSelection: action.value
};
}
function changeGasPrice(state: State, action: ChangeGasPriceAction): State {
return {
...state,
gasPriceGwei: action.value
};
}
2017-07-03 20:21:19 -07:00
export function config(
state: State = initialState,
action: ConfigAction
): State {
2017-07-01 22:49:06 -07:00
switch (action.type) {
2017-07-03 20:21:19 -07:00
case 'CONFIG_LANGUAGE_CHANGE':
return changeLanguage(state, action);
case 'CONFIG_NODE_CHANGE':
return changeNode(state, action);
case 'CONFIG_GAS_PRICE':
return changeGasPrice(state, action);
2017-07-01 22:49:06 -07:00
default:
return state;
}
}