From a7d4e616c71bafc86fe7041af21392923b6fcb02 Mon Sep 17 00:00:00 2001 From: Akinwale Ariwodola Date: Thu, 19 Mar 2020 20:25:31 +0100 Subject: [PATCH] traditional mode if dht is enabled --- android | 2 +- src/component/AppNavigator.js | 1 + src/index.js | 6 ++- src/page/splash/view.js | 84 ++++++++++++++--------------------- 4 files changed, 39 insertions(+), 54 deletions(-) diff --git a/android b/android index 6d4d996..4d98c78 160000 --- a/android +++ b/android @@ -1 +1 @@ -Subproject commit 6d4d9965137441d4d0d460814b1d89d67f23bc81 +Subproject commit 4d98c789cbf19966169b7e561143e8d91bc1a740 diff --git a/src/component/AppNavigator.js b/src/component/AppNavigator.js index 7987944..6dc355b 100644 --- a/src/component/AppNavigator.js +++ b/src/component/AppNavigator.js @@ -447,6 +447,7 @@ class AppWithNavigationState extends React.Component { }; componentWillUnmount() { + DeviceEventEmitter.removeListener('onSdkReady', this.handleSdkReady); DeviceEventEmitter.removeListener('onDownloadAborted', this.handleDownloadAborted); DeviceEventEmitter.removeListener('onDownloadStarted', this.handleDownloadStarted); DeviceEventEmitter.removeListener('onDownloadUpdated', this.handleDownloadUpdated); diff --git a/src/index.js b/src/index.js index 54f376b..608c65e 100644 --- a/src/index.js +++ b/src/index.js @@ -55,8 +55,10 @@ import settingsReducer from 'redux/reducers/settings'; import thunk from 'redux-thunk'; window.__ = __; -Lbry.alternateConnectionString = 'https://api.lbry.tv/api/v1/proxy'; -Lbry.methodsUsingAlternateConnectionString = ['claim_search', 'resolve']; +if (!NativeModules.UtilityModule.dhtEnabled) { + Lbry.alternateConnectionString = 'https://api.lbry.tv/api/v1/proxy'; + Lbry.methodsUsingAlternateConnectionString = ['claim_search', 'resolve']; +} const globalExceptionHandler = (error, isFatal) => { if (error && NativeModules.Firebase) { diff --git a/src/page/splash/view.js b/src/page/splash/view.js index 683b783..11b64aa 100644 --- a/src/page/splash/view.js +++ b/src/page/splash/view.js @@ -85,7 +85,9 @@ class SplashScreen extends React.PureComponent { const { liteMode } = this.state; // authenticate immediately - this.authenticateWithoutSdk(); + if (!NativeModules.UtilityModule.dhtEnabled) { + this.authenticateWithoutSdk(); + } } navigateToMain = () => { @@ -203,15 +205,7 @@ class SplashScreen extends React.PureComponent { }; finishSplashScreen = () => { - const { - authenticate, - balanceSubscribe, - blacklistedOutpointsSubscribe, - filteredOutpointsSubscribe, - getSync, - updateBlockHeight, - user, - } = this.props; + const { authenticate, getSync, user } = this.props; // Leave the splash screen if (user && user.id && user.has_verified_email) { @@ -233,31 +227,14 @@ class SplashScreen extends React.PureComponent { }); }); } - // }); }; handleAccountUnlockFailed() { this.setState({ accountUnlockFailed: true }); } - _updateStatusCallback(status) { - const { fetchSubscriptions, getSync, setClientSetting } = this.props; - const startupStatus = status.startup_status; - const walletStatus = status.wallet; - - // At the minimum, wallet should be started and blocks_behind equal to 0 before calling resolve - const hasStarted = startupStatus.stream_manager && startupStatus.wallet && status.wallet.blocks_behind <= 0; - if (hasStarted) { - // 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({ - daemonReady: true, - isLagging: false, - isRunning: true, - }); - + handleSdkReady = () => { + this.setState({ daemonReady: true }, () => { Lbry.wallet_status().then(secureWalletStatus => { // For now, automatically unlock the wallet if a password is set so that downloads work NativeModules.UtilityModule.getSecureValue(Constants.KEY_WALLET_PASSWORD).then(password => { @@ -288,9 +265,12 @@ class SplashScreen extends React.PureComponent { } }); }); + }); + }; - return; - } + handleSdkStatusResponse = evt => { + const { status } = evt; + const walletStatus = status.wallet; const headerSyncProgress = walletStatus ? walletStatus.headers_synchronization_progress : null; if (headerSyncProgress && headerSyncProgress < 100) { @@ -325,23 +305,24 @@ class SplashScreen extends React.PureComponent { details: __('Initializing LBRY service'), }); } - - setTimeout(() => { - this.updateStatus(); - }, 1000); - } + }; componentWillMount() { DeviceEventEmitter.addListener('onNotificationTargetLaunch', this.onNotificationTargetLaunch); + DeviceEventEmitter.addListener('onSdkReady', this.handleSdkReady); + DeviceEventEmitter.addListener('onSdkStatusResponse', this.handleSdkStatusResponse); } componentWillUnmount() { DeviceEventEmitter.removeListener('onNotificationTargetLaunch', this.onNotificationTargetLaunch); + DeviceEventEmitter.removeListener('onSdkReady', this.handleSdkReady); + DeviceEventEmitter.removeListener('onSdkStatusResponse', this.handleSdkStatusResponse); } componentDidMount() { NativeModules.Firebase.track('app_launch', null); NativeModules.Firebase.setCurrentScreen('Splash'); + const { navigation } = this.props; const { resetUrl } = navigation.state.params; const isResetUrlSet = !!resetUrl; @@ -377,22 +358,23 @@ class SplashScreen extends React.PureComponent { } lbryConnect = () => { - this.updateStatus(); // skip lbry.connect for now (unless dht flag is enabled) - /* - Lbry.connect() - .then(() => { - this.updateStatus(); - }) - .catch(e => { - this.setState({ - isLagging: true, - message: __('Connection Failure'), - details: __( - 'We could not establish a connection to the SDK. Your data connection may be preventing LBRY from connecting. Contact hello@lbry.com if you think this is a software bug.', - ), + if (NativeModules.UtilityModule.dhtEnabled) { + Lbry.connect() + .then(() => { + this.updateStatus(); + }) + .catch(e => { + this.setState({ + isLagging: true, + message: __('Connection Failure'), + details: __( + 'We could not establish a connection to the SDK. Your data connection may be preventing LBRY from connecting. Contact hello@lbry.com if you think this is a software bug.', + ), + }); }); - }); - */ + } else { + this.updateStatus(); // skip lbry.connect for now (unless dht flag is enabled) + } }; handleContinueAnywayPressed = () => {