feat(node-sync): add node-sync-types constants
This commit is contained in:
parent
41b2b3848c
commit
777807d1b3
|
@ -6,6 +6,7 @@ import styled, { keyframes, withTheme } from 'styled-components';
|
||||||
import { TextComponent } from './text';
|
import { TextComponent } from './text';
|
||||||
|
|
||||||
import { DARK } from '../constants/themes';
|
import { DARK } from '../constants/themes';
|
||||||
|
import { NODE_SYNC_TYPES } from '../constants/node-sync-types';
|
||||||
|
|
||||||
import readyIconDark from '../assets/images/green_check_dark.png';
|
import readyIconDark from '../assets/images/green_check_dark.png';
|
||||||
import readyIconLight from '../assets/images/green_check_light.png';
|
import readyIconLight from '../assets/images/green_check_light.png';
|
||||||
|
@ -71,7 +72,10 @@ class Component extends PureComponent<Props> {
|
||||||
|
|
||||||
componentDidUpdate(prevProps: Props) {
|
componentDidUpdate(prevProps: Props) {
|
||||||
const { getBlockchainStatus, nodeSyncType } = this.props;
|
const { getBlockchainStatus, nodeSyncType } = this.props;
|
||||||
if (prevProps.nodeSyncType === 'syncing' && nodeSyncType === 'ready') {
|
if (
|
||||||
|
prevProps.nodeSyncType === NODE_SYNC_TYPES.SYNCING
|
||||||
|
&& nodeSyncType === NODE_SYNC_TYPES.READY
|
||||||
|
) {
|
||||||
// if the status is "ready", we can increase the interval to avoid useless rpc calls
|
// if the status is "ready", we can increase the interval to avoid useless rpc calls
|
||||||
this.cleanUpdateInterval();
|
this.cleanUpdateInterval();
|
||||||
this.timer = setInterval(() => getBlockchainStatus(), MINUTE_IN_MILI);
|
this.timer = setInterval(() => getBlockchainStatus(), MINUTE_IN_MILI);
|
||||||
|
@ -91,7 +95,7 @@ class Component extends PureComponent<Props> {
|
||||||
|
|
||||||
isSyncing = () => {
|
isSyncing = () => {
|
||||||
const { nodeSyncType } = this.props;
|
const { nodeSyncType } = this.props;
|
||||||
return nodeSyncType === 'syncing';
|
return nodeSyncType === NODE_SYNC_TYPES.SYNCING;
|
||||||
};
|
};
|
||||||
|
|
||||||
getReadyIcon = () => {
|
getReadyIcon = () => {
|
||||||
|
@ -113,11 +117,11 @@ class Component extends PureComponent<Props> {
|
||||||
const { nodeSyncType } = this.props;
|
const { nodeSyncType } = this.props;
|
||||||
|
|
||||||
switch (nodeSyncType) {
|
switch (nodeSyncType) {
|
||||||
case 'syncing':
|
case NODE_SYNC_TYPES.SYNCING:
|
||||||
return this.getSyncingIcon();
|
return this.getSyncingIcon();
|
||||||
case 'ready':
|
case NODE_SYNC_TYPES.READY:
|
||||||
return this.getReadyIcon();
|
return this.getReadyIcon();
|
||||||
case 'error':
|
case NODE_SYNC_TYPES.ERROR:
|
||||||
return this.getErrorIcon();
|
return this.getErrorIcon();
|
||||||
default:
|
default:
|
||||||
return null;
|
return null;
|
||||||
|
@ -127,8 +131,8 @@ class Component extends PureComponent<Props> {
|
||||||
render() {
|
render() {
|
||||||
const icon = this.getIcon();
|
const icon = this.getIcon();
|
||||||
const { nodeSyncType, nodeSyncProgress } = this.props;
|
const { nodeSyncType, nodeSyncProgress } = this.props;
|
||||||
const percent = nodeSyncType === 'syncing' ? `(${nodeSyncProgress.toFixed(2)}%)` : '';
|
const percent = nodeSyncType === NODE_SYNC_TYPES.SYNCING ? `(${nodeSyncProgress.toFixed(2)}%)` : '';
|
||||||
const typeText = nodeSyncType === 'ready' ? 'Synced' : nodeSyncType;
|
const typeText = nodeSyncType === NODE_SYNC_TYPES.READY ? 'Synced' : nodeSyncType;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Wrapper id='status-pill'>
|
<Wrapper id='status-pill'>
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
// @flow
|
||||||
|
|
||||||
|
export const NODE_SYNC_TYPES = {
|
||||||
|
READY: 'ready',
|
||||||
|
SYNCING: 'syncing',
|
||||||
|
ERROR: 'error',
|
||||||
|
};
|
|
@ -3,11 +3,11 @@
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import eres from 'eres';
|
import eres from 'eres';
|
||||||
import { BigNumber } from 'bignumber.js';
|
import { BigNumber } from 'bignumber.js';
|
||||||
|
|
||||||
import { updateNodeSyncStatus } from '../redux/modules/app';
|
import { updateNodeSyncStatus } from '../redux/modules/app';
|
||||||
|
|
||||||
import { StatusPill } from '../components/status-pill';
|
import { StatusPill } from '../components/status-pill';
|
||||||
|
|
||||||
import rpc from '../../services/api';
|
import rpc from '../../services/api';
|
||||||
|
import { NODE_SYNC_TYPES } from '../constants/node-sync-types';
|
||||||
|
|
||||||
import type { Dispatch } from '../types/redux';
|
import type { Dispatch } from '../types/redux';
|
||||||
import type { AppState } from '../types/app-state';
|
import type { AppState } from '../types/app-state';
|
||||||
|
@ -34,7 +34,7 @@ const mapDispatchToProps = (dispatch: Dispatch): MapDispatchToProps => ({
|
||||||
return dispatch(
|
return dispatch(
|
||||||
updateNodeSyncStatus({
|
updateNodeSyncStatus({
|
||||||
nodeSyncProgress: 0,
|
nodeSyncProgress: 0,
|
||||||
nodeSyncType: 'error',
|
nodeSyncType: NODE_SYNC_TYPES.ERROR,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,9 @@ const mapDispatchToProps = (dispatch: Dispatch): MapDispatchToProps => ({
|
||||||
dispatch(
|
dispatch(
|
||||||
updateNodeSyncStatus({
|
updateNodeSyncStatus({
|
||||||
nodeSyncProgress: newProgress,
|
nodeSyncProgress: newProgress,
|
||||||
nodeSyncType: new BigNumber(newProgress).gt(99.99) ? 'ready' : 'syncing',
|
nodeSyncType: new BigNumber(newProgress).gt(99.99)
|
||||||
|
? NODE_SYNC_TYPES.READY
|
||||||
|
: NODE_SYNC_TYPES.SYNCING,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue