From 1cbebd0c9ef67a4044ddcfc7be14383d2e1e33c1 Mon Sep 17 00:00:00 2001 From: Akinwale Ariwodola Date: Fri, 22 Jun 2018 02:06:21 +0100 Subject: [PATCH] add blockchain_headers download progress bar to splash screen --- app/src/page/splash/view.js | 46 +++++++++++++++++++++++++++++++++---- app/src/styles/splash.js | 5 ++++ 2 files changed, 46 insertions(+), 5 deletions(-) diff --git a/app/src/page/splash/view.js b/app/src/page/splash/view.js index 931446e3..bbefcf41 100644 --- a/app/src/page/splash/view.js +++ b/app/src/page/splash/view.js @@ -1,6 +1,14 @@ import React from 'react'; import { Lbry } from 'lbry-redux'; -import { ActivityIndicator, View, Text, Linking, NativeModules } from 'react-native'; +import { + ActivityIndicator, + Linking, + NativeModules, + Platform, + ProgressBarAndroid, + Text, + View +} from 'react-native'; import { NavigationActions } from 'react-navigation'; import PropTypes from 'prop-types'; import Colors from '../../styles/colors'; @@ -17,7 +25,10 @@ class SplashScreen extends React.PureComponent { message: 'Connecting', isRunning: false, isLagging: false, - launchUrl: null + launchUrl: null, + didDownloadHeaders: false, + isDownloadingHeaders: false, + headersDownloadProgress: 0 }); if (NativeModules.DaemonServiceControl) { @@ -76,8 +87,27 @@ class SplashScreen extends React.PureComponent { }); return; } - if (status.blockchain_status && status.blockchain_status.blocks_behind > 0) { - const behind = status.blockchain_status.blocks_behind; + + const blockchainStatus = status.blockchain_status; + if (blockchainStatus) { + this.setState({ + isDownloadingHeaders: blockchainStatus.is_downloading_headers, + headersDownloadProgress: blockchainStatus.headers_download_progress + }); + } + + if (blockchainStatus && (blockchainStatus.is_downloading_headers || + (this.state.didDownloadHeaders && 'loading_wallet' === startupStatus.code))) { + if (!this.state.didDownloadHeaders) { + this.setState({ didDownloadHeaders: true }); + } + this.setState({ + message: 'Blockchain Sync', + details: `Catching up with the blockchain (${blockchainStatus.headers_download_progress}%)`, + isLagging: startupStatus.is_lagging + }); + } else if (blockchainStatus && blockchainStatus.blocks_behind > 0) { + const behind = blockchainStatus.blocks_behind; const behindText = behind + ' block' + (behind == 1 ? '' : 's') + ' behind'; this.setState({ message: 'Blockchain Sync', @@ -128,7 +158,13 @@ class SplashScreen extends React.PureComponent { return ( LBRY - + {'android' === Platform.OS && this.state.isDownloadingHeaders && + } + {!this.state.isDownloadingHeaders && } {message} {details} diff --git a/app/src/styles/splash.js b/app/src/styles/splash.js index f1b442e1..bfddbc99 100644 --- a/app/src/styles/splash.js +++ b/app/src/styles/splash.js @@ -17,6 +17,11 @@ const splashStyle = StyleSheet.create({ loading: { marginBottom: 36 }, + progress: { + alignSelf: 'center', + marginBottom: 36, + width: '50%' + }, details: { fontFamily: 'Metropolis-Regular', fontSize: 14,