Cleanup the Status View (#5317)
* Better view of Settings and Mining Settings * Cleanup Status view * Node Logs refactoring * Cleanup Status * Move RPC Calls files * Basic Peers view * Add Peers table * style table header
This commit is contained in:
committed by
Gav Wood
parent
8930f510fc
commit
5fa088114c
@@ -17,16 +17,14 @@
|
||||
import { newError } from '~/ui/Errors/actions';
|
||||
import { setAddressImage } from './providers/imagesActions';
|
||||
import { openSnackbar, showSnackbar } from './providers/snackbarActions';
|
||||
import { clearStatusLogs, toggleStatusLogs, toggleStatusRefresh } from './providers/statusActions';
|
||||
import { toggleStatusRefresh } from './providers/statusActions';
|
||||
import { toggleView } from '~/views/Settings/actions';
|
||||
|
||||
export {
|
||||
newError,
|
||||
clearStatusLogs,
|
||||
setAddressImage,
|
||||
openSnackbar,
|
||||
showSnackbar,
|
||||
toggleStatusLogs,
|
||||
toggleStatusRefresh,
|
||||
toggleView
|
||||
};
|
||||
|
||||
@@ -20,7 +20,6 @@ import ErrorsMiddleware from '~/ui/Errors/middleware';
|
||||
import SettingsMiddleware from '~/views/Settings/middleware';
|
||||
import SignerMiddleware from './providers/signerMiddleware';
|
||||
|
||||
import statusMiddleware from '~/views/Status/middleware';
|
||||
import CertificationsMiddleware from './providers/certifications/middleware';
|
||||
import ChainMiddleware from './providers/chainMiddleware';
|
||||
import RegistryMiddleware from './providers/registry/middleware';
|
||||
@@ -44,8 +43,7 @@ export default function (api, browserHistory, forEmbed = false) {
|
||||
middleware.push(certifications, registry);
|
||||
}
|
||||
|
||||
const status = statusMiddleware();
|
||||
const routeMiddleware = browserHistory ? routerMiddleware(browserHistory) : [];
|
||||
|
||||
return middleware.concat(status, routeMiddleware, thunk);
|
||||
return middleware.concat(routeMiddleware, thunk);
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ import { LOG_KEYS, getLogger } from '~/config';
|
||||
import UpgradeStore from '~/modals/UpgradeParity/store';
|
||||
|
||||
import BalancesProvider from './balances';
|
||||
import { statusBlockNumber, statusCollection, statusLogs } from './statusActions';
|
||||
import { statusBlockNumber, statusCollection } from './statusActions';
|
||||
|
||||
const log = getLogger(LOG_KEYS.Signer);
|
||||
let instance = null;
|
||||
@@ -59,6 +59,14 @@ export default class Status {
|
||||
return instance;
|
||||
}
|
||||
|
||||
static get () {
|
||||
if (!instance) {
|
||||
throw new Error('The Status Provider has not been initialized yet');
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
start () {
|
||||
log.debug('status::start');
|
||||
|
||||
@@ -66,7 +74,6 @@ export default class Status {
|
||||
.all([
|
||||
this._subscribeBlockNumber(),
|
||||
|
||||
this._pollLogs(),
|
||||
this._pollLongStatus(),
|
||||
this._pollStatus()
|
||||
])
|
||||
@@ -187,25 +194,12 @@ export default class Status {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
const { refreshStatus } = this._store.getState().nodeStatus;
|
||||
|
||||
const statusPromises = [ this._api.eth.syncing() ];
|
||||
|
||||
if (refreshStatus) {
|
||||
statusPromises.push(this._api.parity.netPeers());
|
||||
statusPromises.push(this._api.eth.hashrate());
|
||||
}
|
||||
const statusPromises = [ this._api.eth.syncing(), this._api.parity.netPeers() ];
|
||||
|
||||
return Promise
|
||||
.all(statusPromises)
|
||||
.then(([ syncing, ...statusResults ]) => {
|
||||
const status = statusResults.length === 0
|
||||
? { syncing }
|
||||
: {
|
||||
syncing,
|
||||
netPeers: statusResults[0],
|
||||
hashrate: statusResults[1]
|
||||
};
|
||||
.then(([ syncing, netPeers ]) => {
|
||||
const status = { netPeers, syncing };
|
||||
|
||||
if (!isEqual(status, this._status)) {
|
||||
this._store.dispatch(statusCollection(status));
|
||||
@@ -220,39 +214,6 @@ export default class Status {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Miner settings should never changes unless
|
||||
* Parity is restarted, or if the values are changed
|
||||
* from the UI
|
||||
*/
|
||||
_pollMinerSettings = () => {
|
||||
return Promise
|
||||
.all([
|
||||
this._api.eth.coinbase(),
|
||||
this._api.parity.extraData(),
|
||||
this._api.parity.minGasPrice(),
|
||||
this._api.parity.gasFloorTarget()
|
||||
])
|
||||
.then(([
|
||||
coinbase, extraData, minGasPrice, gasFloorTarget
|
||||
]) => {
|
||||
const minerSettings = {
|
||||
coinbase,
|
||||
extraData,
|
||||
minGasPrice,
|
||||
gasFloorTarget
|
||||
};
|
||||
|
||||
if (!isEqual(minerSettings, this._minerSettings)) {
|
||||
this._store.dispatch(statusCollection(minerSettings));
|
||||
this._minerSettings = minerSettings;
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('_pollMinerSettings', error);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* The data fetched here should not change
|
||||
* unless Parity is restarted. They are thus
|
||||
@@ -272,23 +233,16 @@ export default class Status {
|
||||
this._timeoutIds.longStatus = setTimeout(() => this._pollLongStatus(), timeout);
|
||||
};
|
||||
|
||||
// Poll Miner settings just in case
|
||||
const minerPromise = this._pollMinerSettings();
|
||||
|
||||
const mainPromise = Promise
|
||||
return Promise
|
||||
.all([
|
||||
this._api.parity.netPeers(),
|
||||
this._api.web3.clientVersion(),
|
||||
this._api.net.version(),
|
||||
this._api.parity.defaultExtraData(),
|
||||
this._api.parity.netChain(),
|
||||
this._api.parity.netPort(),
|
||||
this._api.parity.rpcSettings(),
|
||||
this._api.parity.enode().then((enode) => enode).catch(() => '-'),
|
||||
this._upgradeStore.checkUpgrade()
|
||||
])
|
||||
.then(([
|
||||
netPeers, clientVersion, netVersion, defaultExtraData, netChain, netPort, rpcSettings, enode, upgradeStatus
|
||||
netPeers, clientVersion, netVersion, netChain, upgradeStatus
|
||||
]) => {
|
||||
const isTest = [
|
||||
'2', // morden
|
||||
@@ -299,13 +253,9 @@ export default class Status {
|
||||
const longStatus = {
|
||||
netPeers,
|
||||
clientVersion,
|
||||
defaultExtraData,
|
||||
netChain,
|
||||
netPort,
|
||||
netVersion,
|
||||
rpcSettings,
|
||||
isTest,
|
||||
enode
|
||||
isTest
|
||||
};
|
||||
|
||||
if (!isEqual(longStatus, this._longStatus)) {
|
||||
@@ -319,42 +269,5 @@ export default class Status {
|
||||
.then(() => {
|
||||
nextTimeout(60000);
|
||||
});
|
||||
|
||||
return Promise.all([ minerPromise, mainPromise ]);
|
||||
}
|
||||
|
||||
_pollLogs = () => {
|
||||
const nextTimeout = (timeout = 1000) => {
|
||||
if (this._timeoutIds.logs) {
|
||||
clearTimeout(this._timeoutIds.logs);
|
||||
}
|
||||
|
||||
this._timeoutIds.logs = setTimeout(this._pollLogs, timeout);
|
||||
};
|
||||
|
||||
const { devLogsEnabled } = this._store.getState().nodeStatus;
|
||||
|
||||
if (!devLogsEnabled) {
|
||||
nextTimeout();
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
return Promise
|
||||
.all([
|
||||
this._api.parity.devLogs(),
|
||||
this._api.parity.devLogsLevels()
|
||||
])
|
||||
.then(([devLogs, devLogsLevels]) => {
|
||||
this._store.dispatch(statusLogs({
|
||||
devLogs: devLogs.slice(-1024),
|
||||
devLogsLevels
|
||||
}));
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('_pollLogs', error);
|
||||
})
|
||||
.then(() => {
|
||||
return nextTimeout();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,30 +27,3 @@ export function statusCollection (collection) {
|
||||
collection
|
||||
};
|
||||
}
|
||||
|
||||
export function statusLogs (logInfo) {
|
||||
return {
|
||||
type: 'statusLogs',
|
||||
logInfo
|
||||
};
|
||||
}
|
||||
|
||||
export function toggleStatusLogs (devLogsEnabled) {
|
||||
return {
|
||||
type: 'toggleStatusLogs',
|
||||
devLogsEnabled
|
||||
};
|
||||
}
|
||||
|
||||
export function clearStatusLogs () {
|
||||
return {
|
||||
type: 'clearStatusLogs'
|
||||
};
|
||||
}
|
||||
|
||||
export function toggleStatusRefresh (refreshStatus) {
|
||||
return {
|
||||
type: 'toggleStatusRefresh',
|
||||
refreshStatus
|
||||
};
|
||||
}
|
||||
|
||||
@@ -21,32 +21,20 @@ const DEFAULT_NETCHAIN = '(unknown)';
|
||||
const initialState = {
|
||||
blockNumber: new BigNumber(0),
|
||||
blockTimestamp: new Date(),
|
||||
devLogs: [],
|
||||
devLogsLevels: null,
|
||||
devLogsEnabled: false,
|
||||
clientVersion: '',
|
||||
coinbase: '',
|
||||
defaultExtraData: '',
|
||||
enode: '',
|
||||
extraData: '',
|
||||
gasFloorTarget: new BigNumber(0),
|
||||
gasLimit: new BigNumber(0),
|
||||
hashrate: new BigNumber(0),
|
||||
minGasPrice: new BigNumber(0),
|
||||
netChain: DEFAULT_NETCHAIN,
|
||||
netPeers: {
|
||||
active: new BigNumber(0),
|
||||
connected: new BigNumber(0),
|
||||
max: new BigNumber(0)
|
||||
max: new BigNumber(0),
|
||||
peers: []
|
||||
},
|
||||
netPort: new BigNumber(0),
|
||||
netVersion: '0',
|
||||
rpcSettings: {},
|
||||
syncing: true,
|
||||
isConnected: false,
|
||||
isConnecting: false,
|
||||
isTest: undefined,
|
||||
refreshStatus: false,
|
||||
traceMode: undefined
|
||||
};
|
||||
|
||||
@@ -61,28 +49,6 @@ export default handleActions({
|
||||
const { collection } = action;
|
||||
|
||||
return Object.assign({}, state, collection);
|
||||
},
|
||||
|
||||
statusLogs (state, action) {
|
||||
const { logInfo } = action;
|
||||
|
||||
return Object.assign({}, state, logInfo);
|
||||
},
|
||||
|
||||
toggleStatusLogs (state, action) {
|
||||
const { devLogsEnabled } = action;
|
||||
|
||||
return Object.assign({}, state, { devLogsEnabled });
|
||||
},
|
||||
|
||||
clearStatusLogs (state, action) {
|
||||
return Object.assign({}, state, { devLogs: [] });
|
||||
},
|
||||
|
||||
toggleStatusRefresh (state, action) {
|
||||
const { refreshStatus } = action;
|
||||
|
||||
return Object.assign({}, state, { refreshStatus });
|
||||
}
|
||||
}, initialState);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user