Allow Network Change Offline (#1683)
* Allow changing to offline node when currently offline * Fix tests
This commit is contained in:
parent
5733833f5e
commit
82e0530bec
|
@ -160,6 +160,7 @@ export function* handleNodeChangeIntent({
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const isOffline = yield select(getOffline);
|
||||||
if (isAutoNode(nodeIdToSwitchTo)) {
|
if (isAutoNode(nodeIdToSwitchTo)) {
|
||||||
shepherd.auto();
|
shepherd.auto();
|
||||||
if (getShepherdNetwork() !== nextNodeConfig.network) {
|
if (getShepherdNetwork() !== nextNodeConfig.network) {
|
||||||
|
@ -167,19 +168,21 @@ export function* handleNodeChangeIntent({
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
yield apply(shepherd, shepherd.manual, [nodeIdToSwitchTo, false]);
|
yield apply(shepherd, shepherd.manual, [nodeIdToSwitchTo, isOffline]);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
return yield* bailOut(translateRaw('ERROR_32'));
|
return yield* bailOut(translateRaw('ERROR_32'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let currentBlock;
|
let currentBlock = '???';
|
||||||
try {
|
try {
|
||||||
currentBlock = yield apply(shepherdProvider, shepherdProvider.getCurrentBlock);
|
currentBlock = yield apply(shepherdProvider, shepherdProvider.getCurrentBlock);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err);
|
if (!isOffline) {
|
||||||
return yield* bailOut(translateRaw('ERROR_32'));
|
console.error(err);
|
||||||
|
return yield* bailOut(translateRaw('ERROR_32'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
yield put(setLatestBlock(currentBlock));
|
yield put(setLatestBlock(currentBlock));
|
||||||
|
|
|
@ -133,7 +133,7 @@ describe('handleNodeChangeIntent*', () => {
|
||||||
: acc
|
: acc
|
||||||
);
|
);
|
||||||
const newNodeConfig: StaticNodeConfig = (staticNodesExpectedState as any).initialState[newNodeId];
|
const newNodeConfig: StaticNodeConfig = (staticNodesExpectedState as any).initialState[newNodeId];
|
||||||
|
const isOffline = false;
|
||||||
const changeNodeIntentAction = changeNodeIntent(newNodeId);
|
const changeNodeIntentAction = changeNodeIntent(newNodeId);
|
||||||
const latestBlock = '0xa';
|
const latestBlock = '0xa';
|
||||||
|
|
||||||
|
@ -174,21 +174,25 @@ describe('handleNodeChangeIntent*', () => {
|
||||||
expect(data.gen.next(newNodeConfig).value).toMatchSnapshot();
|
expect(data.gen.next(newNodeConfig).value).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should show error and revert to previous node if check times out', () => {
|
it('should select isOffline', () => {
|
||||||
data.clone1 = data.gen.clone();
|
expect(data.gen.next(true).value).toEqual(select(getOffline));
|
||||||
data.clone1.next(true);
|
});
|
||||||
expect(data.clone1.throw('err').value).toEqual(select(getNodeId));
|
|
||||||
expect(data.clone1.next(defaultNodeId).value).toEqual(
|
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))
|
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 }))
|
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', () => {
|
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])
|
apply(shepherd, shepherd.manual, [newNodeId, false])
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue