2018-08-13 18:23:01 +02:00
// @flow
2018-03-26 23:32:43 +02:00
import * as React from 'react' ;
2018-05-05 21:04:47 +02:00
import { Lbry , MODALS } from 'lbry-redux' ;
2018-07-18 21:48:30 +02:00
import ModalWalletUnlock from 'modal/modalWalletUnlock' ;
2017-12-21 22:08:54 +01:00
import ModalIncompatibleDaemon from 'modal/modalIncompatibleDaemon' ;
import ModalUpgrade from 'modal/modalUpgrade' ;
import ModalDownloading from 'modal/modalDownloading' ;
2018-08-13 18:23:01 +02:00
import LoadScreen from './internal/load-screen' ;
2016-11-22 21:19:08 +01:00
2018-03-26 23:32:43 +02:00
type Props = {
checkDaemonVersion : ( ) => Promise < any > ,
2018-07-18 21:48:30 +02:00
notifyUnlockWallet : ( ) => Promise < any > ,
2018-08-13 18:23:01 +02:00
daemonVersionMatched : boolean ,
onReadyToLaunch : ( ) => void ,
2018-04-23 20:02:06 +02:00
notification : ? {
id : string ,
} ,
2018-03-26 23:32:43 +02:00
} ;
2017-05-17 10:10:25 +02:00
2018-03-26 23:32:43 +02:00
type State = {
details : string ,
message : string ,
isRunning : boolean ,
2018-07-18 21:48:30 +02:00
launchedModal : boolean ,
2018-03-26 23:32:43 +02:00
} ;
export class SplashScreen extends React . PureComponent < Props , State > {
constructor ( props : Props ) {
2017-05-17 10:10:25 +02:00
super ( props ) ;
this . state = {
2018-08-13 18:37:02 +02:00
details : _ _ ( 'Starting up' ) ,
2017-12-21 22:08:54 +01:00
message : _ _ ( 'Connecting' ) ,
2017-07-19 23:05:08 +02:00
isRunning : false ,
2018-07-18 21:48:30 +02:00
launchedModal : false ,
2017-05-17 10:10:25 +02:00
} ;
}
2018-08-13 18:23:01 +02:00
componentDidMount ( ) {
const { checkDaemonVersion } = this . props ;
Lbry . connect ( )
. then ( checkDaemonVersion )
. then ( ( ) => {
this . updateStatus ( ) ;
} )
. catch ( ( ) => {
this . setState ( {
message : _ _ ( 'Connection Failure' ) ,
details : _ _ (
'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-05-17 10:10:25 +02:00
updateStatus ( ) {
2018-04-18 06:03:01 +02:00
Lbry . status ( ) . then ( status => {
2018-08-13 18:23:01 +02:00
this . updateStatusCallback ( status ) ;
2017-06-06 23:19:12 +02:00
} ) ;
2017-05-17 10:10:25 +02:00
}
2018-08-13 18:23:01 +02:00
updateStatusCallback ( status ) {
2018-07-18 21:48:30 +02:00
const { notifyUnlockWallet } = this . props ;
const { launchedModal } = this . state ;
2018-08-15 20:39:58 +02:00
if ( status . wallet . is _locked ) {
2018-08-13 18:23:01 +02:00
this . setState ( {
message : _ _ ( 'Unlock Wallet' ) ,
details : _ _ ( 'Please unlock your wallet to proceed.' ) ,
isRunning : true ,
} ) ;
2018-08-15 17:51:12 +02:00
2018-08-13 18:23:01 +02:00
if ( launchedModal === false ) {
this . setState ( { launchedModal : true } , ( ) => notifyUnlockWallet ( ) ) ;
}
return ;
}
2018-07-18 21:48:30 +02:00
2018-08-13 18:23:01 +02:00
if ( status . is _running ) {
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-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
2018-04-18 06:03:01 +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 ;
}
2018-07-18 21:48:30 +02:00
2018-08-13 18:23:01 +02:00
if ( status . blockchain _headers && status . blockchain _headers . download _progress < 100 ) {
2017-07-29 23:52:32 +02:00
this . setState ( {
2017-12-21 22:08:54 +01:00
message : _ _ ( 'Blockchain Sync' ) ,
2018-08-13 18:23:01 +02:00
details : ` ${ _ _ ( 'Catching up with the blockchain' ) } ( ${
status . blockchain _headers . download _progress
} % ) ` ,
2017-07-29 23:52:32 +02:00
} ) ;
2018-08-13 18:23:01 +02:00
} else if ( status . wallet && status . wallet . blocks _behind > 0 ) {
const format = status . wallet . blocks _behind === 1 ? '%s block behind' : '%s blocks behind' ;
2018-07-18 21:48:30 +02:00
this . setState ( {
2018-08-13 18:23:01 +02:00
message : _ _ ( 'Blockchain Sync' ) ,
details : _ _ ( format , status . wallet . blocks _behind ) ,
2018-07-18 21:48:30 +02:00
} ) ;
2018-08-13 22:01:33 +02:00
} else if ( status . wallet && status . wallet . blocks _behind === 0 ) {
2017-07-29 23:52:32 +02:00
this . setState ( {
2018-08-13 18:23:01 +02:00
message : 'Network Loading' ,
details : 'Initializing LBRY service...' ,
2017-07-29 23:52:32 +02:00
} ) ;
}
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
}
render ( ) {
2018-04-23 20:02:06 +02:00
const { notification } = this . props ;
2018-08-13 18:23:01 +02:00
const { message , details , isRunning } = this . state ;
2017-07-19 23:05:08 +02:00
2018-04-23 20:02:06 +02:00
const notificationId = notification && notification . id ;
2018-08-13 18:23:01 +02:00
// {notificationId === MODALS.WALLET_UNLOCK && <ModalWalletUnlock />}
2017-06-06 23:19:12 +02:00
return (
2018-03-26 23:32:43 +02:00
< React.Fragment >
2018-08-13 18:23:01 +02:00
< LoadScreen message = { message } details = { details } / >
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 . * / }
2018-03-26 23:32:43 +02:00
{ isRunning && (
< React.Fragment >
2018-07-18 21:48:30 +02:00
{ notificationId === MODALS . WALLET _UNLOCK && < ModalWalletUnlock / > }
2018-05-05 21:04:47 +02:00
{ notificationId === MODALS . INCOMPATIBLE _DAEMON && < ModalIncompatibleDaemon / > }
{ notificationId === MODALS . UPGRADE && < ModalUpgrade / > }
{ notificationId === MODALS . DOWNLOADING && < ModalDownloading / > }
2018-03-26 23:32:43 +02:00
< / React.Fragment >
) }
< / React.Fragment >
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 ;