2018-02-02 22:34:38 +00:00
|
|
|
import { select, takeEvery, put } from 'redux-saga/effects';
|
|
|
|
import { getCustomNodeConfigs, getCustomNetworkConfigs } from 'selectors/config';
|
|
|
|
import { removeCustomNetwork, TypeKeys } from 'actions/config';
|
|
|
|
import { SagaIterator } from 'redux-saga';
|
|
|
|
import { AppState } from 'reducers';
|
|
|
|
|
|
|
|
// If there are any orphaned custom networks, purge them
|
2018-02-05 14:48:15 +00:00
|
|
|
export function* pruneCustomNetworks(): SagaIterator {
|
2018-02-02 22:34:38 +00:00
|
|
|
const customNodes: AppState['config']['nodes']['customNodes'] = yield select(
|
|
|
|
getCustomNodeConfigs
|
|
|
|
);
|
|
|
|
const customNetworks: AppState['config']['networks']['customNetworks'] = yield select(
|
|
|
|
getCustomNetworkConfigs
|
|
|
|
);
|
|
|
|
|
2018-02-05 14:48:15 +00:00
|
|
|
for (const n of Object.values(customNodes)) {
|
2018-02-02 22:34:38 +00:00
|
|
|
if (!customNetworks[n.network]) {
|
|
|
|
yield put(removeCustomNetwork({ id: n.network }));
|
|
|
|
}
|
2018-02-05 14:48:15 +00:00
|
|
|
}
|
2018-02-02 22:34:38 +00:00
|
|
|
}
|
|
|
|
|
2018-02-05 14:48:15 +00:00
|
|
|
export const network = [takeEvery(TypeKeys.CONFIG_REMOVE_CUSTOM_NODE, pruneCustomNetworks)];
|