1 import React from 'react'
2 import moment from 'moment'
3 import { connect } from 'react-redux'
4 import { Link } from 'react-router'
5 import { humanizeDuration } from 'utility/time'
6 import testnetUtils from 'features/testnet/utils'
7 import { navIcon } from '../../utils'
8 import navStyles from '../Navigation/Navigation.scss'
9 import styles from './Sync.scss'
11 class Sync extends React.Component {
22 if (snapshot && snapshot.inProgress) { // Currently downloading the snapshot.
23 const downloaded = (snapshot.downloaded / snapshot.size) * 100
25 return <ul className={`${navStyles.navigation} ${styles.main}`}>
27 <li className={navStyles.navigationTitle}>chain testnet snapshot</li>
30 <li className={navStyles.navigationTitle}>snapshot sync</li>
33 <li>{snapshot.height} blocks</li>
34 {!!downloaded && <li>{Math.round(downloaded)}% downloaded</li>}
35 {!!syncEstimates.snapshot && <li>Time remaining: {humanizeDuration(syncEstimates.snapshot)}</li>}
42 elems.push(<li key='sync-title' className={navStyles.navigationTitle}>chain testnet sync</li>)
44 elems.push(<li key='sync-title' className={navStyles.navigationTitle}>generator sync</li>)
47 if (onTestnet && !testnetError && testnetNextReset) {
48 const diff = testnetNextReset.diff(moment(), 'seconds')
49 if (diff < 2 * 24 * 60 * 60) {
50 elems.push(<li key='sync-reset-warning'><span className={styles.testnetReset}>Next reset: {humanizeDuration(diff)}</span></li>)
54 if (onTestnet && testnetError) {
55 elems.push(<li key='sync-error'>
57 {navIcon('error', navStyles)}
58 <span className={styles.testnetError}>Chain Testnet error</span>
62 if (replicationLag === null || replicationLag >= 2) {
63 elems.push(<li key='sync-lag'>Blocks behind: {replicationLag === null ? '-' : replicationLag}</li>)
65 if (syncEstimates.replicationLag) {
66 elems.push(<li key='sync-time'>Time remaining: {humanizeDuration(syncEstimates.replicationLag)}</li>)
69 elems.push(<li key='sync-done'>Local core fully synced.</li>)
73 return <ul className={`${navStyles.navigation} ${styles.main}`}>{elems}</ul>
77 export default connect(
79 onTestnet: state.core.onTestnet,
80 routing: state.routing, // required for <Link>s to update active state on navigation
81 replicationLag: state.core.replicationLag,
82 snapshot: state.core.snapshot,
83 syncEstimates: state.core.syncEstimates,
84 testnetError: testnetUtils.isBlockchainMismatch(state) || testnetUtils.isCrosscoreRpcMismatch(state),
85 testnetNextReset: state.testnet.nextReset,