tweak status check on email collection page

This commit is contained in:
Akinwale Ariwodola 2018-08-16 09:40:12 +01:00
parent 8ee0697056
commit 2f9616a487
4 changed files with 32 additions and 14 deletions

View file

@ -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) {

View file

@ -1,5 +1,6 @@
const Constants = {
KEY_FIRST_RUN_EMAIL: "firstRunEmail",
KEY_SHOULD_VERIFY_EMAIL: "shouldVerifyEmail",
SETTING_ALPHA_UNDERSTANDS_RISKS: "ALPHA_UNDERSTANDS_RISKS",

View file

@ -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() {

View file

@ -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) {