tweak status check on email collection page
This commit is contained in:
parent
8ee0697056
commit
2f9616a487
4 changed files with 32 additions and 14 deletions
|
@ -39,9 +39,10 @@ import {
|
||||||
import { makeSelectClientSetting } from '../redux/selectors/settings';
|
import { makeSelectClientSetting } from '../redux/selectors/settings';
|
||||||
import { decode as atob } from 'base-64';
|
import { decode as atob } from 'base-64';
|
||||||
import Icon from 'react-native-vector-icons/FontAwesome5';
|
import Icon from 'react-native-vector-icons/FontAwesome5';
|
||||||
|
import Constants from '../constants';
|
||||||
import discoverStyle from '../styles/discover';
|
import discoverStyle from '../styles/discover';
|
||||||
import searchStyle from '../styles/search';
|
import searchStyle from '../styles/search';
|
||||||
import SearchRightHeaderIcon from "../component/searchRightHeaderIcon";
|
import SearchRightHeaderIcon from '../component/searchRightHeaderIcon';
|
||||||
|
|
||||||
const discoverStack = StackNavigator({
|
const discoverStack = StackNavigator({
|
||||||
Discover: {
|
Discover: {
|
||||||
|
@ -210,11 +211,15 @@ class AppWithNavigationState extends React.Component {
|
||||||
!emailVerifyPending &&
|
!emailVerifyPending &&
|
||||||
!this.state.emailVerifyDone &&
|
!this.state.emailVerifyDone &&
|
||||||
(emailToVerify || emailVerifyErrorMessage)) {
|
(emailToVerify || emailVerifyErrorMessage)) {
|
||||||
|
AsyncStorage.getItem(Constants.KEY_SHOULD_VERIFY_EMAIL).then(shouldVerify => {
|
||||||
|
if ('true' === shouldVerify) {
|
||||||
this.setState({ emailVerifyDone: true });
|
this.setState({ emailVerifyDone: true });
|
||||||
const message = emailVerifyErrorMessage ?
|
const message = emailVerifyErrorMessage ?
|
||||||
String(emailVerifyErrorMessage) : 'Your email address was successfully verified.';
|
String(emailVerifyErrorMessage) : 'Your email address was successfully verified.';
|
||||||
dispatch(doNotify({ message, displayType: ['toast'] }));
|
dispatch(doNotify({ message, displayType: ['toast'] }));
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_handleAppStateChange = (nextAppState) => {
|
_handleAppStateChange = (nextAppState) => {
|
||||||
|
@ -243,6 +248,7 @@ class AppWithNavigationState extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (verification.token && verification.recaptcha) {
|
if (verification.token && verification.recaptcha) {
|
||||||
|
AsyncStorage.setItem(Constants.KEY_SHOULD_VERIFY_EMAIL, 'true');
|
||||||
try {
|
try {
|
||||||
dispatch(doUserEmailVerify(verification.token, verification.recaptcha));
|
dispatch(doUserEmailVerify(verification.token, verification.recaptcha));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
const Constants = {
|
const Constants = {
|
||||||
KEY_FIRST_RUN_EMAIL: "firstRunEmail",
|
KEY_FIRST_RUN_EMAIL: "firstRunEmail",
|
||||||
|
KEY_SHOULD_VERIFY_EMAIL: "shouldVerifyEmail",
|
||||||
|
|
||||||
SETTING_ALPHA_UNDERSTANDS_RISKS: "ALPHA_UNDERSTANDS_RISKS",
|
SETTING_ALPHA_UNDERSTANDS_RISKS: "ALPHA_UNDERSTANDS_RISKS",
|
||||||
|
|
||||||
|
|
|
@ -10,15 +10,19 @@ import {
|
||||||
} from 'react-native';
|
} from 'react-native';
|
||||||
import Button from '../../../component/button';
|
import Button from '../../../component/button';
|
||||||
import Colors from '../../../styles/colors';
|
import Colors from '../../../styles/colors';
|
||||||
|
import Constants from '../../../constants';
|
||||||
import firstRunStyle from '../../../styles/firstRun';
|
import firstRunStyle from '../../../styles/firstRun';
|
||||||
|
|
||||||
class EmailCollectPage extends React.PureComponent {
|
class EmailCollectPage extends React.PureComponent {
|
||||||
|
static MAX_STATUS_TRIES = 15;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
this.state = {
|
this.state = {
|
||||||
email: null,
|
email: null,
|
||||||
authenticationStarted: false,
|
authenticationStarted: false,
|
||||||
authenticationFailed: false
|
authenticationFailed: false,
|
||||||
|
statusTries: 0
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,7 +38,7 @@ class EmailCollectPage extends React.PureComponent {
|
||||||
// call user/new
|
// call user/new
|
||||||
const { generateAuthToken, authenticating, authToken } = this.props;
|
const { generateAuthToken, authenticating, authToken } = this.props;
|
||||||
if (!authToken && !authenticating) {
|
if (!authToken && !authenticating) {
|
||||||
this.startAuthenticating(true);
|
this.startAuthenticating();
|
||||||
}
|
}
|
||||||
|
|
||||||
AsyncStorage.getItem('firstRunEmail').then(email => {
|
AsyncStorage.getItem('firstRunEmail').then(email => {
|
||||||
|
@ -44,22 +48,27 @@ class EmailCollectPage extends React.PureComponent {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
startAuthenticating = (useTimeout) => {
|
startAuthenticating = () => {
|
||||||
const { generateAuthToken } = this.props;
|
const { generateAuthToken } = this.props;
|
||||||
this.setState({ authenticationStarted: true, authenticationFailed: false });
|
this.setState({ authenticationStarted: true, authenticationFailed: false });
|
||||||
setTimeout(() => {
|
|
||||||
Lbry.status().then(info => {
|
Lbry.status().then(info => {
|
||||||
generateAuthToken(info.installation_id)
|
generateAuthToken(info.installation_id)
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
|
if (this.state.statusTries >= EmailCollectPage.MAX_STATUS_TRIES) {
|
||||||
this.setState({ authenticationFailed: true });
|
this.setState({ authenticationFailed: true });
|
||||||
|
} 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)
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}, useTimeout ? 10000 : 0); // if useTimeout is set, wait 10s to give the daemon some time to start
|
|
||||||
}
|
}
|
||||||
|
|
||||||
handleChangeText = (text) => {
|
handleChangeText = (text) => {
|
||||||
// save the value to the state email
|
// save the value to the state email
|
||||||
this.setState({ email: text });
|
this.setState({ email: text });
|
||||||
AsyncStorage.setItem('firstRunEmail', text);
|
AsyncStorage.setItem(Constants.KEY_FIRST_RUN_EMAIL, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
|
|
@ -13,6 +13,7 @@ import { NavigationActions } from 'react-navigation';
|
||||||
import { decode as atob } from 'base-64';
|
import { decode as atob } from 'base-64';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import Colors from '../../styles/colors';
|
import Colors from '../../styles/colors';
|
||||||
|
import Constants from '../../constants';
|
||||||
import splashStyle from '../../styles/splash';
|
import splashStyle from '../../styles/splash';
|
||||||
|
|
||||||
class SplashScreen extends React.PureComponent {
|
class SplashScreen extends React.PureComponent {
|
||||||
|
@ -78,6 +79,7 @@ class SplashScreen extends React.PureComponent {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
}
|
}
|
||||||
if (verification.token && verification.recaptcha) {
|
if (verification.token && verification.recaptcha) {
|
||||||
|
AsyncStorage.setItem(Constants.KEY_SHOULD_VERIFY_EMAIL, 'true');
|
||||||
try {
|
try {
|
||||||
verifyUserEmail(verification.token, verification.recaptcha);
|
verifyUserEmail(verification.token, verification.recaptcha);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue