Only do node checks when node change is not pending (#1525)

* Only do node checks when node change isnt pending

* bump mycrypto-shepherd version

* Use shepherds selectors

* Use shepherd pending state for checking for offline

* Fix tsc error

* mycrypto-shepherd -> myc-shepherd

* set mycrypto-shepherd
This commit is contained in:
HenryNguyen5 2018-04-16 18:51:15 -04:00 committed by Daniel Ternyak
parent adad64d45f
commit 6c8f3ff64a
4 changed files with 31 additions and 12 deletions

View File

@ -4,6 +4,8 @@ import { tokenBalanceHandler } from './tokenBalanceProxy';
import { IProviderConfig } from 'mycrypto-shepherd/dist/lib/ducks/providerConfigs';
type DeepPartial<T> = Partial<{ [key in keyof T]: Partial<T[key]> }>;
const { selectors, store } = redux;
const { providerBalancerSelectors: { balancerConfigSelectors } } = selectors;
export const makeProviderConfig = (options: DeepPartial<IProviderConfig> = {}): IProviderConfig => {
const defaultConfig: IProviderConfig = {
@ -48,12 +50,14 @@ shepherd
provider => (shepherdProvider = (new Proxy(provider, tokenBalanceHandler) as any) as INode)
);
export const getShepherdManualMode = () =>
redux.store.getState().providerBalancer.balancerConfig.manual;
export const getShepherdOffline = () =>
redux.store.getState().providerBalancer.balancerConfig.offline;
export const getShepherdNetwork = () =>
redux.store.getState().providerBalancer.balancerConfig.network;
export const getShepherdManualMode = () => balancerConfigSelectors.getManualMode(store.getState());
export const getShepherdOffline = () => balancerConfigSelectors.isOffline(store.getState());
export const getShepherdNetwork = () => balancerConfigSelectors.getNetwork(store.getState());
export const getShepherdPending = () =>
balancerConfigSelectors.isSwitchingNetworks(store.getState());
export const makeWeb3Network = (network: string) => `WEB3_${network}`;
export const stripWeb3Network = (network: string) => network.replace('WEB3_', '');

View File

@ -43,7 +43,8 @@ import {
shepherdProvider,
stripWeb3Network,
makeProviderConfig,
getShepherdNetwork
getShepherdNetwork,
getShepherdPending
} from 'libs/nodes';
export function* pollOfflineStatus(): SagaIterator {
@ -70,8 +71,14 @@ export function* pollOfflineStatus(): SagaIterator {
while (true) {
yield call(delay, 2500);
const pending: ReturnType<typeof getShepherdPending> = yield call(getShepherdPending);
if (pending) {
continue;
}
const isOffline: boolean = yield select(getOffline);
const balancerOffline = yield call(getShepherdOffline);
if (!balancerOffline && isOffline) {
// If we were able to ping but redux says we're offline, mark online
yield put(restoreNotif);

View File

@ -30,7 +30,7 @@
"lodash": "4.17.5",
"moment": "2.22.1",
"moment-timezone": "0.5.14",
"mycrypto-shepherd": "1.0.2",
"mycrypto-shepherd": "1.1.0",
"normalizr": "3.2.4",
"qrcode": "1.2.0",
"qrcode.react": "0.8.0",

View File

@ -38,7 +38,7 @@ import { selectedNodeExpectedState } from './nodes/selectedNode.spec';
import { customNodesExpectedState, firstCustomNodeId } from './nodes/customNodes.spec';
import { unsetWeb3Node, unsetWeb3NodeOnWalletEvent } from 'sagas/config/web3';
import { shepherd } from 'mycrypto-shepherd';
import { getShepherdOffline } from 'libs/nodes';
import { getShepherdOffline, getShepherdPending } from 'libs/nodes';
// init module
configuredStore.getState();
@ -57,8 +57,14 @@ describe('pollOfflineStatus*', () => {
expect(offlineOnFirstTimeCase.next().value).toEqual(call(delay, 2500));
});
it('should skip if a node change is pending', () => {
expect(offlineOnFirstTimeCase.next().value).toEqual(call(getShepherdPending));
expect(offlineOnFirstTimeCase.next(true).value).toEqual(call(delay, 2500));
expect(offlineOnFirstTimeCase.next().value).toEqual(call(getShepherdPending));
});
it('should select offline', () => {
expect(offlineOnFirstTimeCase.next().value).toEqual(select(getOffline));
expect(offlineOnFirstTimeCase.next(false).value).toEqual(select(getOffline));
});
it('should select shepherd"s offline', () => {
@ -75,7 +81,8 @@ describe('pollOfflineStatus*', () => {
it('should loop around then go back online, putting a restore msg', () => {
expect(offlineOnFirstTimeCase.next().value).toEqual(call(delay, 2500));
expect(offlineOnFirstTimeCase.next().value).toEqual(select(getOffline));
expect(offlineOnFirstTimeCase.next().value).toEqual(call(getShepherdPending));
expect(offlineOnFirstTimeCase.next(false).value).toEqual(select(getOffline));
expect(offlineOnFirstTimeCase.next(true).value).toEqual(call(getShepherdOffline));
expect((offlineOnFirstTimeCase.next().value as any).PUT.action.payload.msg).toEqual(
restoreNotif
@ -85,7 +92,8 @@ describe('pollOfflineStatus*', () => {
it('should put a generic lost connection notif on every time afterwards', () => {
expect(offlineOnFirstTimeCase.next().value).toEqual(call(delay, 2500));
expect(offlineOnFirstTimeCase.next().value).toEqual(select(getOffline));
expect(offlineOnFirstTimeCase.next().value).toEqual(call(getShepherdPending));
expect(offlineOnFirstTimeCase.next(false).value).toEqual(select(getOffline));
expect(offlineOnFirstTimeCase.next(false).value).toEqual(call(getShepherdOffline));
expect(offlineOnFirstTimeCase.next(true).value).toEqual(put(setOffline()));
expect((offlineOnFirstTimeCase.next().value as any).PUT.action.payload.msg).toEqual(