From 2f9616a48710ac66c461bb8a7f47e547fb3222f1 Mon Sep 17 00:00:00 2001 From: Akinwale Ariwodola Date: Thu, 16 Aug 2018 09:40:12 +0100 Subject: [PATCH] tweak status check on email collection page --- app/src/component/AppNavigator.js | 16 +++++++---- app/src/constants.js | 1 + .../firstRun/internal/email-collect-page.js | 27 ++++++++++++------- app/src/page/splash/view.js | 2 ++ 4 files changed, 32 insertions(+), 14 deletions(-) diff --git a/app/src/component/AppNavigator.js b/app/src/component/AppNavigator.js index 60d401c1..479f90db 100644 --- a/app/src/component/AppNavigator.js +++ b/app/src/component/AppNavigator.js @@ -39,9 +39,10 @@ import { import { makeSelectClientSetting } from '../redux/selectors/settings'; import { decode as atob } from 'base-64'; import Icon from 'react-native-vector-icons/FontAwesome5'; +import Constants from '../constants'; import discoverStyle from '../styles/discover'; import searchStyle from '../styles/search'; -import SearchRightHeaderIcon from "../component/searchRightHeaderIcon"; +import SearchRightHeaderIcon from '../component/searchRightHeaderIcon'; const discoverStack = StackNavigator({ Discover: { @@ -210,10 +211,14 @@ class AppWithNavigationState extends React.Component { !emailVerifyPending && !this.state.emailVerifyDone && (emailToVerify || emailVerifyErrorMessage)) { - this.setState({ emailVerifyDone: true }); - const message = emailVerifyErrorMessage ? - String(emailVerifyErrorMessage) : 'Your email address was successfully verified.'; - dispatch(doNotify({ message, displayType: ['toast'] })); + AsyncStorage.getItem(Constants.KEY_SHOULD_VERIFY_EMAIL).then(shouldVerify => { + if ('true' === shouldVerify) { + this.setState({ emailVerifyDone: true }); + const message = emailVerifyErrorMessage ? + String(emailVerifyErrorMessage) : 'Your email address was successfully verified.'; + dispatch(doNotify({ message, displayType: ['toast'] })); + } + }); } } @@ -243,6 +248,7 @@ class AppWithNavigationState extends React.Component { } if (verification.token && verification.recaptcha) { + AsyncStorage.setItem(Constants.KEY_SHOULD_VERIFY_EMAIL, 'true'); try { dispatch(doUserEmailVerify(verification.token, verification.recaptcha)); } catch (error) { diff --git a/app/src/constants.js b/app/src/constants.js index 6cc5685f..2bb046e3 100644 --- a/app/src/constants.js +++ b/app/src/constants.js @@ -1,5 +1,6 @@ const Constants = { KEY_FIRST_RUN_EMAIL: "firstRunEmail", + KEY_SHOULD_VERIFY_EMAIL: "shouldVerifyEmail", SETTING_ALPHA_UNDERSTANDS_RISKS: "ALPHA_UNDERSTANDS_RISKS", diff --git a/app/src/page/firstRun/internal/email-collect-page.js b/app/src/page/firstRun/internal/email-collect-page.js index eeabc52d..179a1e25 100644 --- a/app/src/page/firstRun/internal/email-collect-page.js +++ b/app/src/page/firstRun/internal/email-collect-page.js @@ -10,15 +10,19 @@ import { } from 'react-native'; import Button from '../../../component/button'; import Colors from '../../../styles/colors'; +import Constants from '../../../constants'; import firstRunStyle from '../../../styles/firstRun'; class EmailCollectPage extends React.PureComponent { + static MAX_STATUS_TRIES = 15; + constructor() { super(); this.state = { email: null, authenticationStarted: false, - authenticationFailed: false + authenticationFailed: false, + statusTries: 0 }; } @@ -34,7 +38,7 @@ class EmailCollectPage extends React.PureComponent { // call user/new const { generateAuthToken, authenticating, authToken } = this.props; if (!authToken && !authenticating) { - this.startAuthenticating(true); + this.startAuthenticating(); } AsyncStorage.getItem('firstRunEmail').then(email => { @@ -44,22 +48,27 @@ class EmailCollectPage extends React.PureComponent { }); } - startAuthenticating = (useTimeout) => { + startAuthenticating = () => { const { generateAuthToken } = this.props; this.setState({ authenticationStarted: true, authenticationFailed: false }); - setTimeout(() => { - Lbry.status().then(info => { + Lbry.status().then(info => { generateAuthToken(info.installation_id) - }).catch(error => { + }).catch(error => { + if (this.state.statusTries >= EmailCollectPage.MAX_STATUS_TRIES) { this.setState({ authenticationFailed: true }); - }); - }, useTimeout ? 10000 : 0); // if useTimeout is set, wait 10s to give the daemon some time to start + } else { + setTimeout(() => { + this.startAuthenticating(); + this.setState({ statusTries: this.state.statusTries + 1 }); + }, 1000); // Retry every second for a maximum of MAX_STATUS_TRIES tries (15 seconds) + } + }); } handleChangeText = (text) => { // save the value to the state email this.setState({ email: text }); - AsyncStorage.setItem('firstRunEmail', text); + AsyncStorage.setItem(Constants.KEY_FIRST_RUN_EMAIL, text); } render() { diff --git a/app/src/page/splash/view.js b/app/src/page/splash/view.js index 4767bce3..4dfabe1d 100644 --- a/app/src/page/splash/view.js +++ b/app/src/page/splash/view.js @@ -13,6 +13,7 @@ import { NavigationActions } from 'react-navigation'; import { decode as atob } from 'base-64'; import PropTypes from 'prop-types'; import Colors from '../../styles/colors'; +import Constants from '../../constants'; import splashStyle from '../../styles/splash'; class SplashScreen extends React.PureComponent { @@ -78,6 +79,7 @@ class SplashScreen extends React.PureComponent { console.log(error); } if (verification.token && verification.recaptcha) { + AsyncStorage.setItem(Constants.KEY_SHOULD_VERIFY_EMAIL, 'true'); try { verifyUserEmail(verification.token, verification.recaptcha); } catch (error) {