Prune custom networks properly on node removal
This commit is contained in:
parent
77cf4b8f50
commit
c5d63a31af
|
@ -34,7 +34,7 @@ const changeNodeIntent = (state: State, _: ChangeNodeIntentAction): State => ({
|
||||||
pending: true
|
pending: true
|
||||||
});
|
});
|
||||||
|
|
||||||
const handleRemoveCustomNode = (state: State, _: RemoveCustomNodeAction): State => INITIAL_STATE;
|
const handleRemoveCustomNode = (_: State, _1: RemoveCustomNodeAction): State => INITIAL_STATE;
|
||||||
|
|
||||||
export const selectedNode = (
|
export const selectedNode = (
|
||||||
state: State = INITIAL_STATE,
|
state: State = INITIAL_STATE,
|
||||||
|
|
|
@ -4,7 +4,7 @@ import { removeCustomNetwork, TypeKeys } from 'actions/config';
|
||||||
import { SagaIterator } from 'redux-saga';
|
import { SagaIterator } from 'redux-saga';
|
||||||
import { AppState } from 'reducers';
|
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 {
|
export function* pruneCustomNetworks(): SagaIterator {
|
||||||
const customNodes: AppState['config']['nodes']['customNodes'] = yield select(
|
const customNodes: AppState['config']['nodes']['customNodes'] = yield select(
|
||||||
getCustomNodeConfigs
|
getCustomNodeConfigs
|
||||||
|
@ -13,9 +13,16 @@ export function* pruneCustomNetworks(): SagaIterator {
|
||||||
getCustomNetworkConfigs
|
getCustomNetworkConfigs
|
||||||
);
|
);
|
||||||
|
|
||||||
for (const n of Object.values(customNodes)) {
|
//construct lookup table of networks
|
||||||
if (!customNetworks[n.network]) {
|
|
||||||
yield put(removeCustomNetwork({ id: n.network }));
|
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 }));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue