Prune custom networks properly on node removal

This commit is contained in:
HenryNguyen5 2018-02-08 20:59:44 -05:00
parent 77cf4b8f50
commit c5d63a31af
2 changed files with 12 additions and 5 deletions

View File

@ -34,7 +34,7 @@ const changeNodeIntent = (state: State, _: ChangeNodeIntentAction): State => ({
pending: true
});
const handleRemoveCustomNode = (state: State, _: RemoveCustomNodeAction): State => INITIAL_STATE;
const handleRemoveCustomNode = (_: State, _1: RemoveCustomNodeAction): State => INITIAL_STATE;
export const selectedNode = (
state: State = INITIAL_STATE,

View File

@ -4,7 +4,7 @@ import { removeCustomNetwork, TypeKeys } from 'actions/config';
import { SagaIterator } from 'redux-saga';
import { AppState } from 'reducers';
// If there are any orphaned custom networks, purge them
// If there are any orphaned custom networks, prune them
export function* pruneCustomNetworks(): SagaIterator {
const customNodes: AppState['config']['nodes']['customNodes'] = yield select(
getCustomNodeConfigs
@ -13,9 +13,16 @@ export function* pruneCustomNetworks(): SagaIterator {
getCustomNetworkConfigs
);
for (const n of Object.values(customNodes)) {
if (!customNetworks[n.network]) {
yield put(removeCustomNetwork({ id: n.network }));
//construct lookup table of networks
const linkedNetworks = Object.values(customNodes).reduce(
(networkMap, currentNode) => ({ ...networkMap, [currentNode.network]: true }),
{}
);
for (const currNetwork of Object.keys(customNetworks)) {
if (!linkedNetworks[currNetwork]) {
yield put(removeCustomNetwork({ id: currNetwork }));
}
}
}