import React, { Component } from 'react' import PropTypes from 'prop-types' import QRCode from 'qrcode.react' import copy from 'copy-to-clipboard' import Isvg from 'react-inlinesvg' import zapLogo from 'icons/zap_logo.svg' import copyIcon from 'icons/copy.svg' import { showNotification } from 'lib/utils/notifications' import styles from './Syncing.scss' class Syncing extends Component { state = { timer: null, syncMessageDetail: null, syncMessageExtraDetail: null } componentWillMount() { const { syncStatus } = this.props // If we are still waiting for peers after some time, advise te user it could take a wile. let timer = setTimeout(() => { if (syncStatus === 'waiting') { this.setState({ syncMessageDetail: 'It looks like this could take some time - you might want to grab a coffee or try again later!' }) } }, 10000) this.setState({ timer }) } componentWillUnmount() { const { timer } = this.state clearInterval(timer) } render() { const { hasSynced, syncStatus, syncPercentage, address, blockHeight, lndBlockHeight, lndCfilterHeight } = this.props let { syncMessageDetail, syncMessageExtraDetail } = this.state const copyClicked = () => { copy(address) showNotification('Noice', 'Successfully copied to clipboard') } let syncMessage if (syncStatus === 'waiting') { syncMessage = 'Waiting for peers...' } else if (syncStatus === 'in-progress') { if (typeof syncPercentage === 'undefined' || syncPercentage <= 0) { syncMessage = 'Preparing...' syncMessageDetail = null } else if (syncPercentage) { syncMessage = `${syncPercentage}%` syncMessageDetail = `Block: ${lndBlockHeight.toLocaleString()} of ${blockHeight.toLocaleString()}` syncMessageExtraDetail = `Commitment Filter: ${lndCfilterHeight.toLocaleString()} of ${blockHeight.toLocaleString()}` } } if (typeof hasSynced === 'undefined') { return null } return (
{hasSynced === true && (

Welcome back to your Zap wallet!

Please wait a while whilst we fetch all of your latest data from the blockchain.

)} {hasSynced === false && (

Fund your Zap wallet

Might as well fund your wallet while you're waiting to sync.

{address && address.length ? (
{address}
) : (
)}
)}

Syncing to the blockchain

{syncMessage}

{syncMessageDetail && ( {syncMessageDetail} )} {syncMessageExtraDetail && (
{syncMessageExtraDetail}
)}
) } } Syncing.propTypes = { address: PropTypes.string.isRequired, hasSynced: PropTypes.bool, syncStatus: PropTypes.string.isRequired, syncPercentage: PropTypes.number, blockHeight: PropTypes.number, lndBlockHeight: PropTypes.number, lndCfilterHeight: PropTypes.number } export default Syncing