Allow Network Change Offline (#1683)

* Allow changing to offline node when currently offline

* Fix tests
This commit is contained in:
William O'Beirne 2018-04-26 23:55:31 -04:00 committed by Daniel Ternyak
parent 5733833f5e
commit 82e0530bec
2 changed files with 20 additions and 13 deletions

View File

@ -160,6 +160,7 @@ export function* handleNodeChangeIntent({
);
}
const isOffline = yield select(getOffline);
if (isAutoNode(nodeIdToSwitchTo)) {
shepherd.auto();
if (getShepherdNetwork() !== nextNodeConfig.network) {
@ -167,20 +168,22 @@ export function* handleNodeChangeIntent({
}
} else {
try {
yield apply(shepherd, shepherd.manual, [nodeIdToSwitchTo, false]);
yield apply(shepherd, shepherd.manual, [nodeIdToSwitchTo, isOffline]);
} catch (err) {
console.error(err);
return yield* bailOut(translateRaw('ERROR_32'));
}
}
let currentBlock;
let currentBlock = '???';
try {
currentBlock = yield apply(shepherdProvider, shepherdProvider.getCurrentBlock);
} catch (err) {
if (!isOffline) {
console.error(err);
return yield* bailOut(translateRaw('ERROR_32'));
}
}
yield put(setLatestBlock(currentBlock));
yield put(changeNode({ networkId: nextNodeConfig.network, nodeId: nodeIdToSwitchTo }));

View File

@ -133,7 +133,7 @@ describe('handleNodeChangeIntent*', () => {
: acc
);
const newNodeConfig: StaticNodeConfig = (staticNodesExpectedState as any).initialState[newNodeId];
const isOffline = false;
const changeNodeIntentAction = changeNodeIntent(newNodeId);
const latestBlock = '0xa';
@ -174,21 +174,25 @@ describe('handleNodeChangeIntent*', () => {
expect(data.gen.next(newNodeConfig).value).toMatchSnapshot();
});
it('should show error and revert to previous node if check times out', () => {
data.clone1 = data.gen.clone();
data.clone1.next(true);
expect(data.clone1.throw('err').value).toEqual(select(getNodeId));
expect(data.clone1.next(defaultNodeId).value).toEqual(
it('should select isOffline', () => {
expect(data.gen.next(true).value).toEqual(select(getOffline));
});
it('should show error and revert to previous node if online check times out', () => {
data.nodeError = data.gen.clone();
data.nodeError.next(isOffline);
expect(data.nodeError.throw('err').value).toEqual(select(getNodeId));
expect(data.nodeError.next(defaultNodeId).value).toEqual(
put(showNotification('danger', translateRaw('ERROR_32'), 5000))
);
expect(data.clone1.next().value).toEqual(
expect(data.nodeError.next().value).toEqual(
put(changeNode({ networkId: defaultNodeConfig.network, nodeId: defaultNodeId }))
);
expect(data.clone1.next().done).toEqual(true);
expect(data.nodeError.next().done).toEqual(true);
});
it('should sucessfully switch to the manual node', () => {
expect(data.gen.next(latestBlock).value).toEqual(
expect(data.gen.next(isOffline).value).toEqual(
apply(shepherd, shepherd.manual, [newNodeId, false])
);
});