diff --git a/app/components/status-pill.js b/app/components/status-pill.js index 25c2d8d..bf53973 100644 --- a/app/components/status-pill.js +++ b/app/components/status-pill.js @@ -6,6 +6,7 @@ import styled, { keyframes, withTheme } from 'styled-components'; import { TextComponent } from './text'; import { DARK } from '../constants/themes'; +import { NODE_SYNC_TYPES } from '../constants/node-sync-types'; import readyIconDark from '../assets/images/green_check_dark.png'; import readyIconLight from '../assets/images/green_check_light.png'; @@ -71,7 +72,10 @@ class Component extends PureComponent { componentDidUpdate(prevProps: 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 this.cleanUpdateInterval(); this.timer = setInterval(() => getBlockchainStatus(), MINUTE_IN_MILI); @@ -91,7 +95,7 @@ class Component extends PureComponent { isSyncing = () => { const { nodeSyncType } = this.props; - return nodeSyncType === 'syncing'; + return nodeSyncType === NODE_SYNC_TYPES.SYNCING; }; getReadyIcon = () => { @@ -113,11 +117,11 @@ class Component extends PureComponent { const { nodeSyncType } = this.props; switch (nodeSyncType) { - case 'syncing': + case NODE_SYNC_TYPES.SYNCING: return this.getSyncingIcon(); - case 'ready': + case NODE_SYNC_TYPES.READY: return this.getReadyIcon(); - case 'error': + case NODE_SYNC_TYPES.ERROR: return this.getErrorIcon(); default: return null; @@ -127,8 +131,8 @@ class Component extends PureComponent { render() { const icon = this.getIcon(); const { nodeSyncType, nodeSyncProgress } = this.props; - const percent = nodeSyncType === 'syncing' ? `(${nodeSyncProgress.toFixed(2)}%)` : ''; - const typeText = nodeSyncType === 'ready' ? 'Synced' : nodeSyncType; + const percent = nodeSyncType === NODE_SYNC_TYPES.SYNCING ? `(${nodeSyncProgress.toFixed(2)}%)` : ''; + const typeText = nodeSyncType === NODE_SYNC_TYPES.READY ? 'Synced' : nodeSyncType; return ( diff --git a/app/constants/node-sync-types.js b/app/constants/node-sync-types.js new file mode 100644 index 0000000..85d2c23 --- /dev/null +++ b/app/constants/node-sync-types.js @@ -0,0 +1,7 @@ +// @flow + +export const NODE_SYNC_TYPES = { + READY: 'ready', + SYNCING: 'syncing', + ERROR: 'error', +}; diff --git a/app/containers/status-pill.js b/app/containers/status-pill.js index e98d50c..ddef1a1 100644 --- a/app/containers/status-pill.js +++ b/app/containers/status-pill.js @@ -3,11 +3,11 @@ import { connect } from 'react-redux'; import eres from 'eres'; import { BigNumber } from 'bignumber.js'; + import { updateNodeSyncStatus } from '../redux/modules/app'; - import { StatusPill } from '../components/status-pill'; - import rpc from '../../services/api'; +import { NODE_SYNC_TYPES } from '../constants/node-sync-types'; import type { Dispatch } from '../types/redux'; import type { AppState } from '../types/app-state'; @@ -34,7 +34,7 @@ const mapDispatchToProps = (dispatch: Dispatch): MapDispatchToProps => ({ return dispatch( updateNodeSyncStatus({ nodeSyncProgress: 0, - nodeSyncType: 'error', + nodeSyncType: NODE_SYNC_TYPES.ERROR, }), ); } @@ -44,7 +44,9 @@ const mapDispatchToProps = (dispatch: Dispatch): MapDispatchToProps => ({ dispatch( updateNodeSyncStatus({ 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, }), ); },