2018-02-12 20:43:07 +00:00
|
|
|
import {
|
|
|
|
AddCustomNetworkAction,
|
|
|
|
RemoveCustomNetworkAction,
|
|
|
|
CustomNetworkAction,
|
|
|
|
TypeKeys
|
|
|
|
} from 'actions/config';
|
2018-04-05 20:53:36 +00:00
|
|
|
import { CustomNetworksState as State } from './types';
|
2018-02-12 20:43:07 +00:00
|
|
|
|
|
|
|
const addCustomNetwork = (state: State, { payload }: AddCustomNetworkAction): State => ({
|
|
|
|
...state,
|
2018-05-29 14:51:42 +00:00
|
|
|
[payload.id]: payload
|
2018-02-12 20:43:07 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
function removeCustomNetwork(state: State, { payload }: RemoveCustomNetworkAction): State {
|
|
|
|
const stateCopy = { ...state };
|
2018-05-29 14:51:42 +00:00
|
|
|
Reflect.deleteProperty(stateCopy, payload);
|
2018-02-12 20:43:07 +00:00
|
|
|
return stateCopy;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const customNetworks = (state: State = {}, action: CustomNetworkAction) => {
|
|
|
|
switch (action.type) {
|
|
|
|
case TypeKeys.CONFIG_ADD_CUSTOM_NETWORK:
|
|
|
|
return addCustomNetwork(state, action);
|
|
|
|
case TypeKeys.CONFIG_REMOVE_CUSTOM_NETWORK:
|
|
|
|
return removeCustomNetwork(state, action);
|
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
};
|