William O'Beirne 1aad9d1c21 Standardize Redux Actions / Reducers (#95)
* Convert Swap to consistent style

* Generate wallet reducer cleanup.

* Confirm empty action in swap reducer

* Union types. Fix gen wallet collision

* Fix not using all actions in reducer. Added reducer state for is fetching from bity. Added todo to make that a loader.

* Readme instructions.

* Remove common action constants.

* Bring all actions and reducers inline with readme instructions.

* Readme fixes

* address comments
2017-07-27 12:05:09 -05:00

59 lines
1.2 KiB
JavaScript

// @flow
import type {
ConfigAction,
ChangeNodeAction,
ChangeLanguageAction,
ChangeGasPriceAction
} from 'actions/config';
import { languages, NODES } from '../config/data';
export type State = {
// FIXME
languageSelection: string,
nodeSelection: string,
gasPriceGwei: number
};
export const INITIAL_STATE: State = {
languageSelection: languages[0].sign,
nodeSelection: Object.keys(NODES)[0],
gasPriceGwei: 21
};
function changeLanguage(state: State, action: ChangeLanguageAction): State {
return {
...state,
languageSelection: action.value
};
}
function changeNode(state: State, action: ChangeNodeAction): State {
return {
...state,
nodeSelection: action.value
};
}
function changeGasPrice(state: State, action: ChangeGasPriceAction): State {
return {
...state,
gasPriceGwei: action.value
};
}
export function config(
state: State = INITIAL_STATE,
action: ConfigAction
): State {
switch (action.type) {
case 'CONFIG_LANGUAGE_CHANGE':
return changeLanguage(state, action);
case 'CONFIG_NODE_CHANGE':
return changeNode(state, action);
case 'CONFIG_GAS_PRICE':
return changeGasPrice(state, action);
default:
return state;
}
}