2018-01-26 18:33:57 -05:00
|
|
|
import { ChangeNodeAction, ChangeNodeIntentAction, NodeAction, TypeKeys } from 'actions/config';
|
|
|
|
|
|
|
|
interface NodeLoaded {
|
|
|
|
pending: false;
|
|
|
|
nodeName: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface NodeChangePending {
|
|
|
|
pending: true;
|
2018-01-29 22:52:19 -05:00
|
|
|
nodeName: string;
|
2018-01-26 18:33:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
export type State = NodeLoaded | NodeChangePending;
|
|
|
|
|
|
|
|
export const INITIAL_STATE: NodeLoaded = {
|
|
|
|
nodeName: 'eth_mew',
|
|
|
|
pending: false
|
|
|
|
};
|
|
|
|
|
|
|
|
const changeNode = (_: State, { payload }: ChangeNodeAction): State => ({
|
|
|
|
nodeName: payload.networkName,
|
|
|
|
pending: false
|
|
|
|
});
|
|
|
|
|
2018-01-29 22:52:19 -05:00
|
|
|
const changeNodeIntent = (state: State, _: ChangeNodeIntentAction): State => ({
|
|
|
|
...state,
|
2018-01-26 18:33:57 -05:00
|
|
|
pending: true
|
|
|
|
});
|
|
|
|
|
|
|
|
export const selectedNode = (state: State = INITIAL_STATE, action: NodeAction) => {
|
|
|
|
switch (action.type) {
|
|
|
|
case TypeKeys.CONFIG_NODE_CHANGE:
|
|
|
|
return changeNode(state, action);
|
|
|
|
case TypeKeys.CONFIG_NODE_CHANGE_INTENT:
|
|
|
|
return changeNodeIntent(state, action);
|
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
};
|