auto-login when no password is set

This commit is contained in:
Akinwale Ariwodola 2019-11-28 05:09:55 +01:00
parent f202943adb
commit f1c48e734e
3 changed files with 44 additions and 8 deletions

View file

@ -29,6 +29,7 @@ class WalletPage extends React.PureComponent {
hasCheckedSync: false,
revealPassword: false,
autoPassword: false,
autoLoginAttempted: false,
};
componentDidMount() {
@ -36,7 +37,7 @@ class WalletPage extends React.PureComponent {
}
componentDidUpdate() {
const { hasSyncedWallet, getSyncIsPending, onPasswordChanged } = this.props;
const { hasSyncedWallet, getSyncIsPending, onPasswordChanged, autoLogin } = this.props;
if (this.state.walletReady && this.state.hasCheckedSync && !getSyncIsPending) {
if (!hasSyncedWallet && !this.state.autoPassword) {
// new account, in which case, don't ask for a password, and act as the final first run step
@ -45,6 +46,11 @@ class WalletPage extends React.PureComponent {
onPasswordChanged('', true);
}
}
if (hasSyncedWallet && !this.state.autoLoginAttempted && autoLogin) {
autoLogin();
this.setState({ autoLoginAttempted: true });
}
}
}
@ -83,6 +89,7 @@ class WalletPage extends React.PureComponent {
hasSyncedWallet,
syncApplyIsPending,
syncApplyStarted,
syncApplyCompleted,
} = this.props;
let content;
@ -93,15 +100,15 @@ class WalletPage extends React.PureComponent {
<Text style={firstRunStyle.paragraph}>Retrieving your account information...</Text>
</View>
);
} else if (syncApplyStarted || syncApplyIsPending) {
} else if (syncApplyStarted || syncApplyIsPending || syncApplyCompleted) {
content = (
<View style={firstRunStyle.centered}>
<ActivityIndicator size="large" color={Colors.White} style={firstRunStyle.waiting} />
<Text style={firstRunStyle.paragraph}>{syncApplyIsPending ? 'Validating password' : 'Synchronizing'}...</Text>
</View>
);
} else if (hasSyncedWallet) {
// only display this view if it's not a new user
} else if (hasSyncedWallet && this.state.autoLoginAttempted) {
// only display this view if it's not a new user (or auto-login has been attempted once)
content = (
<View onLayout={onWalletViewLayout}>
<Text style={firstRunStyle.title}>Password</Text>

View file

@ -35,6 +35,7 @@ class FirstRunScreen extends React.PureComponent {
showBottomContainer: false,
walletPassword: '',
syncApplyStarted: false,
syncApplyCompleted: false,
};
componentDidMount() {
@ -78,8 +79,9 @@ class FirstRunScreen extends React.PureComponent {
if (this.state.syncApplyStarted && !syncApplyIsPending) {
if (syncApplyErrorMessage && syncApplyErrorMessage.trim().length > 0) {
notify({ message: syncApplyErrorMessage, isError: true });
this.setState({ showBottomContainer: true, syncApplyStarted: false });
this.setState({ showBottomContainer: true, syncApplyStarted: false, syncApplyCompleted: false });
} else {
this.setState({ syncApplyCompleted: true });
// password successfully verified
NativeModules.UtilityModule.setSecureValue(
Constants.KEY_WALLET_PASSWORD,
@ -160,6 +162,13 @@ class FirstRunScreen extends React.PureComponent {
});
};
autoLogin = () => {
const { hasSyncedWallet } = this.props;
if (hasSyncedWallet && !this.state.syncApplyStarted) {
this.checkWalletPassword();
}
};
handleContinuePressed = () => {
const { notify, user, hasSyncedWallet } = this.props;
const pageIndex = FirstRunScreen.pages.indexOf(this.state.currentPage);
@ -376,8 +385,10 @@ class FirstRunScreen extends React.PureComponent {
getSyncIsPending={getSyncIsPending}
syncApplyIsPending={syncApplyIsPending}
syncApplyStarted={this.state.syncApplyStarted}
syncApplyCompleted={this.state.syncApplyCompleted}
onWalletViewLayout={this.onWalletViewLayout}
onPasswordChanged={this.onWalletPasswordChanged}
autoLogin={this.autoLogin}
/>
);
break;

View file

@ -16,9 +16,12 @@ class SyncVerifyPage extends React.PureComponent {
password: null,
placeholder: 'password',
syncApplyStarted: false,
syncApplyCompleted: false,
syncChecked: false,
revealPassword: false,
autoPassword: false,
autoLoginAttempted: false,
autoLoginFlow: true,
};
componentDidMount() {
@ -65,9 +68,11 @@ class SyncVerifyPage extends React.PureComponent {
if (this.state.syncApplyStarted && !syncApplyIsPending) {
if (syncApplyErrorMessage && syncApplyErrorMessage.trim().length > 0) {
notify({ message: syncApplyErrorMessage, isError: true });
this.setState({ syncApplyStarted: false });
this.setState({ syncApplyStarted: false, autoLoginFlow: false });
} else {
// password successfully verified
this.setState({ syncApplyCompleted: true });
if (NativeModules.UtilityModule) {
NativeModules.UtilityModule.setSecureValue(
Constants.KEY_WALLET_PASSWORD,
@ -87,6 +92,10 @@ class SyncVerifyPage extends React.PureComponent {
this.setState({ password: '', autoPassword: true });
this.onEnableSyncPressed();
}
if (this.state.syncChecked && hasSyncedWallet && !this.state.autoLoginAttempted) {
this.setState({ autoLoginAttempted: true, password: '' }, () => this.onEnableSyncPressed());
}
}
finishSync = (notifyUnlockFailed = false) => {
@ -143,7 +152,16 @@ class SyncVerifyPage extends React.PureComponent {
<Text style={firstRunStyle.paragraph}>Retrieving your account information...</Text>
</View>
);
} else if (hasSyncedWallet) {
} else if (this.state.autoLoginFlow && (syncApplyIsPending || this.state.syncApplyCompleted)) {
// first attempt at auto-login, only display activity indicator
content = (
<View>
<View style={firstRunStyle.centerInside}>
<ActivityIndicator size={'small'} color={Colors.White} />
</View>
</View>
);
} else if (hasSyncedWallet && this.state.autoLoginAttempted) {
content = (
<View>
<Text style={rewardStyle.verificationTitle}>Wallet Sync</Text>
@ -208,7 +226,7 @@ class SyncVerifyPage extends React.PureComponent {
onPress={this.onEnableSyncPressed}
/>
)}
{syncApplyIsPending && (
{(syncApplyIsPending || this.state.syncApplyCompleted) && (
<View style={firstRunStyle.centerInside}>
<ActivityIndicator size={'small'} color={Colors.White} />
</View>