2017-06-06 23:19:12 +02:00
import React from "react" ;
2017-11-29 06:03:53 +01:00
import PropTypes from "prop-types" ;
2017-08-18 19:09:40 +02:00
import lbry from "lbry.js" ;
2017-07-19 23:05:08 +02:00
import LoadScreen from "../load_screen.js" ;
2017-08-18 19:09:40 +02:00
import ModalIncompatibleDaemon from "modal/modalIncompatibleDaemon" ;
import ModalUpgrade from "modal/modalUpgrade" ;
import ModalDownloading from "modal/modalDownloading" ;
2017-10-03 23:52:53 +02:00
import * as modals from "constants/modal_types" ;
2016-11-22 21:19:08 +01:00
2017-06-08 06:42:19 +02:00
export class SplashScreen extends React . PureComponent {
2017-05-17 10:10:25 +02:00
static propTypes = {
2017-11-29 06:03:53 +01:00
message : PropTypes . string ,
onLoadDone : PropTypes . func ,
2017-06-06 23:19:12 +02:00
} ;
2017-05-17 10:10:25 +02:00
constructor ( props ) {
super ( props ) ;
this . state = {
2017-06-06 23:19:12 +02:00
details : _ _ ( "Starting daemon" ) ,
2017-05-31 12:55:32 +02:00
message : _ _ ( "Connecting" ) ,
2017-07-19 23:05:08 +02:00
isRunning : false ,
2016-04-15 12:41:01 +02:00
isLagging : false ,
2017-05-17 10:10:25 +02:00
} ;
}
updateStatus ( ) {
2017-06-06 23:19:12 +02:00
lbry . status ( ) . then ( status => {
this . _updateStatusCallback ( status ) ;
} ) ;
2017-05-17 10:10:25 +02:00
}
_updateStatusCallback ( status ) {
2017-06-06 23:19:12 +02:00
const startupStatus = status . startup _status ;
if ( startupStatus . code == "started" ) {
2017-01-18 16:29:47 +01:00
// Wait until we are able to resolve a name before declaring
// that we are done.
// TODO: This is a hack, and the logic should live in the daemon
// to give us a better sense of when we are actually started
this . setState ( {
2017-05-31 12:55:32 +02:00
message : _ _ ( "Testing Network" ) ,
details : _ _ ( "Waiting for name resolution" ) ,
2017-06-06 23:19:12 +02:00
isLagging : false ,
2017-07-19 23:05:08 +02:00
isRunning : true ,
2017-01-18 16:29:47 +01:00
} ) ;
2016-04-14 08:27:06 +02:00
2017-06-06 23:19:12 +02:00
lbry . resolve ( { uri : "lbry://one" } ) . then ( ( ) => {
2017-07-19 23:05:08 +02:00
// Only leave the load screen if the daemon version matched;
// otherwise we'll notify the user at the end of the load screen.
if ( this . props . daemonVersionMatched ) {
this . props . onReadyToLaunch ( ) ;
}
2016-04-14 08:27:06 +02:00
} ) ;
2017-01-18 16:29:47 +01:00
return ;
}
2017-07-30 17:27:50 +02:00
if (
status . blockchain _status &&
status . blockchain _status . blocks _behind > 0
) {
2017-11-24 15:31:05 +01:00
const format =
status . blockchain _status . blocks _behind == 1
? "%s block behind"
: "%s blocks behind" ;
2017-07-29 23:52:32 +02:00
this . setState ( {
message : _ _ ( "Blockchain Sync" ) ,
2017-07-30 17:27:50 +02:00
details : _ _ ( format , status . blockchain _status . blocks _behind ) ,
2017-07-29 23:52:32 +02:00
isLagging : startupStatus . is _lagging ,
} ) ;
} else {
this . setState ( {
message : _ _ ( "Network Loading" ) ,
2017-07-30 17:27:50 +02:00
details :
startupStatus . message + ( startupStatus . is _lagging ? "" : "..." ) ,
2017-07-29 23:52:32 +02:00
isLagging : startupStatus . is _lagging ,
} ) ;
}
2017-01-18 16:29:47 +01:00
setTimeout ( ( ) => {
2017-04-09 17:06:23 +02:00
this . updateStatus ( ) ;
2017-01-18 16:29:47 +01:00
} , 500 ) ;
2017-05-17 10:10:25 +02:00
}
componentDidMount ( ) {
2017-06-06 23:19:12 +02:00
lbry
. connect ( )
2017-07-19 23:05:08 +02:00
. then ( this . props . checkDaemonVersion )
2017-06-06 23:19:12 +02:00
. then ( ( ) => {
this . updateStatus ( ) ;
} )
2017-05-31 01:56:48 +02:00
. catch ( ( ) => {
2017-04-09 17:06:23 +02:00
this . setState ( {
isLagging : true ,
2017-05-31 12:55:32 +02:00
message : _ _ ( "Connection Failure" ) ,
2017-06-06 23:19:12 +02:00
details : _ _ (
2017-06-23 12:49:23 +02:00
"Try closing all LBRY processes and starting again. If this still happens, your anti-virus software or firewall may be preventing LBRY from connecting. Contact hello@lbry.io if you think this is a software bug."
2017-06-06 23:19:12 +02:00
) ,
} ) ;
} ) ;
2017-05-17 10:10:25 +02:00
}
render ( ) {
2017-07-19 23:05:08 +02:00
const { modal } = this . props ;
2017-12-10 21:27:55 +01:00
const { message , details , isLagging , isRunning } = this . state ;
2017-07-19 23:05:08 +02:00
2017-06-06 23:19:12 +02:00
return (
2017-07-19 23:05:08 +02:00
< div >
< LoadScreen
2017-12-10 21:27:55 +01:00
message = { message }
details = { details }
isWarning = { isLagging }
2017-07-19 23:05:08 +02:00
/ >
{ / * T e m p h a c k : d o n ' t s h o w a n y m o d a l s o n s p l a s h s c r e e n d a e m o n i s r u n n i n g ;
daemon doesn ' t let you quit during startup , so the "Quit" buttons
in the modals won ' t work . * / }
{ modal == "incompatibleDaemon" &&
2017-12-10 21:27:55 +01:00
isRunning && < ModalIncompatibleDaemon / > }
{ modal == modals . UPGRADE && isRunning && < ModalUpgrade / > }
2017-10-03 23:52:53 +02:00
{ modal == modals . DOWNLOADING &&
2017-12-10 21:27:55 +01:00
isRunning && < ModalDownloading / > }
2017-07-19 23:05:08 +02:00
< / div >
2017-06-06 23:19:12 +02:00
) ;
2016-04-10 02:00:56 +02:00
}
2017-05-17 10:10:25 +02:00
}
2016-11-22 21:19:08 +01:00
export default SplashScreen ;