Starting on homestead shows reload snackbar (#4043)
* Fix issue where starting on homestead showed reload * Align snackbar timing with errors (60s)
This commit is contained in:
parent
d16ab5eac5
commit
1ef67f68ed
@ -15,6 +15,7 @@
|
|||||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import { showSnackbar } from './snackbarActions';
|
import { showSnackbar } from './snackbarActions';
|
||||||
|
import { DEFAULT_NETCHAIN } from './statusReducer';
|
||||||
|
|
||||||
export default class ChainMiddleware {
|
export default class ChainMiddleware {
|
||||||
toMiddleware () {
|
toMiddleware () {
|
||||||
@ -23,11 +24,11 @@ export default class ChainMiddleware {
|
|||||||
const { collection } = action;
|
const { collection } = action;
|
||||||
|
|
||||||
if (collection && collection.netChain) {
|
if (collection && collection.netChain) {
|
||||||
const chain = collection.netChain;
|
const newChain = collection.netChain;
|
||||||
const { nodeStatus } = store.getState();
|
const { nodeStatus } = store.getState();
|
||||||
|
|
||||||
if (chain !== nodeStatus.netChain) {
|
if (newChain !== nodeStatus.netChain && nodeStatus.netChain !== DEFAULT_NETCHAIN) {
|
||||||
store.dispatch(showSnackbar(`Switched to ${chain}. Please reload the page.`, 5000));
|
store.dispatch(showSnackbar(`Switched to ${newChain}. Please reload the page.`, 60000));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
86
js/src/redux/providers/chainMiddleware.spec.js
Normal file
86
js/src/redux/providers/chainMiddleware.spec.js
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
// Copyright 2015, 2016 Parity Technologies (UK) Ltd.
|
||||||
|
// This file is part of Parity.
|
||||||
|
|
||||||
|
// Parity is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
|
||||||
|
// Parity is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
import sinon from 'sinon';
|
||||||
|
|
||||||
|
import { initialState as defaultNodeStatusState } from './statusReducer';
|
||||||
|
import ChainMiddleware from './chainMiddleware';
|
||||||
|
|
||||||
|
let middleware;
|
||||||
|
let next;
|
||||||
|
let store;
|
||||||
|
|
||||||
|
function createMiddleware (collection = {}) {
|
||||||
|
middleware = new ChainMiddleware().toMiddleware();
|
||||||
|
next = sinon.stub();
|
||||||
|
store = {
|
||||||
|
dispatch: sinon.stub(),
|
||||||
|
getState: () => {
|
||||||
|
return {
|
||||||
|
nodeStatus: Object.assign({}, defaultNodeStatusState, collection)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return middleware;
|
||||||
|
}
|
||||||
|
|
||||||
|
function callMiddleware (action) {
|
||||||
|
return middleware(store)(next)(action);
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('reduxs/providers/ChainMiddleware', () => {
|
||||||
|
describe('next action', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
createMiddleware();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('calls next with matching actiontypes', () => {
|
||||||
|
callMiddleware({ type: 'statusCollection' });
|
||||||
|
|
||||||
|
expect(next).to.have.been.calledWithMatch({ type: 'statusCollection' });
|
||||||
|
});
|
||||||
|
|
||||||
|
it('calls next with non-matching actiontypes', () => {
|
||||||
|
callMiddleware({ type: 'nonMatchingType' });
|
||||||
|
|
||||||
|
expect(next).to.have.been.calledWithMatch({ type: 'nonMatchingType' });
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('chain switching', () => {
|
||||||
|
it('does not dispatch when moving from the initial/unknown chain', () => {
|
||||||
|
createMiddleware();
|
||||||
|
callMiddleware({ type: 'statusCollection', collection: { netChain: 'homestead' } });
|
||||||
|
|
||||||
|
expect(store.dispatch).not.to.have.been.called;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does not dispatch when moving to the same chain', () => {
|
||||||
|
createMiddleware({ netChain: 'homestead' });
|
||||||
|
callMiddleware({ type: 'statusCollection', collection: { netChain: 'homestead' } });
|
||||||
|
|
||||||
|
expect(store.dispatch).not.to.have.been.called;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does dispatch when moving between chains', () => {
|
||||||
|
createMiddleware({ netChain: 'homestead' });
|
||||||
|
callMiddleware({ type: 'statusCollection', collection: { netChain: 'ropsten' } });
|
||||||
|
|
||||||
|
expect(store.dispatch).to.have.been.called;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
@ -17,6 +17,7 @@
|
|||||||
import BigNumber from 'bignumber.js';
|
import BigNumber from 'bignumber.js';
|
||||||
import { handleActions } from 'redux-actions';
|
import { handleActions } from 'redux-actions';
|
||||||
|
|
||||||
|
const DEFAULT_NETCHAIN = '(unknown)';
|
||||||
const initialState = {
|
const initialState = {
|
||||||
blockNumber: new BigNumber(0),
|
blockNumber: new BigNumber(0),
|
||||||
blockTimestamp: new Date(),
|
blockTimestamp: new Date(),
|
||||||
@ -32,7 +33,7 @@ const initialState = {
|
|||||||
gasLimit: new BigNumber(0),
|
gasLimit: new BigNumber(0),
|
||||||
hashrate: new BigNumber(0),
|
hashrate: new BigNumber(0),
|
||||||
minGasPrice: new BigNumber(0),
|
minGasPrice: new BigNumber(0),
|
||||||
netChain: 'ropsten',
|
netChain: DEFAULT_NETCHAIN,
|
||||||
netPeers: {
|
netPeers: {
|
||||||
active: new BigNumber(0),
|
active: new BigNumber(0),
|
||||||
connected: new BigNumber(0),
|
connected: new BigNumber(0),
|
||||||
@ -82,3 +83,8 @@ export default handleActions({
|
|||||||
return Object.assign({}, state, { refreshStatus });
|
return Object.assign({}, state, { refreshStatus });
|
||||||
}
|
}
|
||||||
}, initialState);
|
}, initialState);
|
||||||
|
|
||||||
|
export {
|
||||||
|
DEFAULT_NETCHAIN,
|
||||||
|
initialState
|
||||||
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user