From c5d63a31af4f3bf82a90bd933d1e709559ea9e42 Mon Sep 17 00:00:00 2001 From: HenryNguyen5 Date: Thu, 8 Feb 2018 20:59:44 -0500 Subject: [PATCH] Prune custom networks properly on node removal --- common/reducers/config/nodes/selectedNode.ts | 2 +- common/sagas/config/network.ts | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/common/reducers/config/nodes/selectedNode.ts b/common/reducers/config/nodes/selectedNode.ts index 406b1dd8..3d2fdd00 100644 --- a/common/reducers/config/nodes/selectedNode.ts +++ b/common/reducers/config/nodes/selectedNode.ts @@ -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, diff --git a/common/sagas/config/network.ts b/common/sagas/config/network.ts index b6a3f106..7f75e9c4 100644 --- a/common/sagas/config/network.ts +++ b/common/sagas/config/network.ts @@ -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 })); } } }