From f202943adbc956bf5acf0b360d31078b126221fa Mon Sep 17 00:00:00 2001 From: Akinwale Ariwodola Date: Wed, 27 Nov 2019 09:23:37 +0100 Subject: [PATCH 1/2] do not prompt new users for a password --- src/component/walletSyncDriver/index.js | 2 +- src/component/walletSyncDriver/view.js | 8 ++++---- src/page/firstRun/internal/wallet-page.js | 17 ++++++++++++++++- src/page/firstRun/view.js | 6 +++++- .../verification/internal/sync-verify-page.js | 12 +++++++++++- 5 files changed, 37 insertions(+), 8 deletions(-) diff --git a/src/component/walletSyncDriver/index.js b/src/component/walletSyncDriver/index.js index 1065158..1812ce2 100644 --- a/src/component/walletSyncDriver/index.js +++ b/src/component/walletSyncDriver/index.js @@ -3,7 +3,7 @@ import { doSetClientSetting } from 'redux/actions/settings'; import { makeSelectClientSetting } from 'redux/selectors/settings'; import { doToast } from 'lbry-redux'; import { selectUserEmail } from 'lbryinc'; -import Constants from 'constants'; +import Constants from 'constants'; // eslint-disable-line node/no-deprecated-api import WalletSyncDriver from './view'; const select = state => ({ diff --git a/src/component/walletSyncDriver/view.js b/src/component/walletSyncDriver/view.js index 799612c..cade63b 100644 --- a/src/component/walletSyncDriver/view.js +++ b/src/component/walletSyncDriver/view.js @@ -1,7 +1,7 @@ import React from 'react'; import { Alert, NativeModules, Switch, Text, View } from 'react-native'; import Button from 'component/button'; -import Constants from 'constants'; +import Constants from 'constants'; // eslint-disable-line node/no-deprecated-api import Link from 'component/link'; import walletStyle from 'styles/wallet'; @@ -43,7 +43,7 @@ class WalletSyncDriver extends React.PureComponent { Sync status - + {deviceWalletSynced ? 'On' : 'Off'} { Connected email - - {userEmail ? userEmail : 'No connected email'} + + {userEmail || 'No connected email'} diff --git a/src/page/firstRun/internal/wallet-page.js b/src/page/firstRun/internal/wallet-page.js index cad1931..aee7348 100644 --- a/src/page/firstRun/internal/wallet-page.js +++ b/src/page/firstRun/internal/wallet-page.js @@ -28,12 +28,26 @@ class WalletPage extends React.PureComponent { walletReady: false, hasCheckedSync: false, revealPassword: false, + autoPassword: false, }; componentDidMount() { this.checkWalletReady(); } + componentDidUpdate() { + const { hasSyncedWallet, getSyncIsPending, onPasswordChanged } = 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 + this.setState({ password: '', autoPassword: true }); + if (onPasswordChanged) { + onPasswordChanged('', true); + } + } + } + } + checkWalletReady = () => { // make sure the sdk wallet component is ready Lbry.status() @@ -86,7 +100,8 @@ class WalletPage extends React.PureComponent { {syncApplyIsPending ? 'Validating password' : 'Synchronizing'}... ); - } else { + } else if (hasSyncedWallet) { + // only display this view if it's not a new user content = ( Password diff --git a/src/page/firstRun/view.js b/src/page/firstRun/view.js index a136287..60d74f9 100644 --- a/src/page/firstRun/view.js +++ b/src/page/firstRun/view.js @@ -265,8 +265,12 @@ class FirstRunScreen extends React.PureComponent { this.setState({ showBottomContainer: true, showSkip: true }); }; - onWalletPasswordChanged = password => { + onWalletPasswordChanged = (password, finalStep) => { this.setState({ walletPassword: password !== null ? password : '' }); + if (finalStep) { + // final step for a new user + this.setFreshPassword(); + } }; onWalletViewLayout = () => { diff --git a/src/page/verification/internal/sync-verify-page.js b/src/page/verification/internal/sync-verify-page.js index 7990c8a..3054c5d 100644 --- a/src/page/verification/internal/sync-verify-page.js +++ b/src/page/verification/internal/sync-verify-page.js @@ -18,6 +18,7 @@ class SyncVerifyPage extends React.PureComponent { syncApplyStarted: false, syncChecked: false, revealPassword: false, + autoPassword: false, }; componentDidMount() { @@ -79,6 +80,15 @@ class SyncVerifyPage extends React.PureComponent { } } + componentDidUpdate() { + const { hasSyncedWallet } = this.props; + if (this.state.syncChecked && !this.state.autoPassword && !hasSyncedWallet) { + // new user sync, don't prompt for a password + this.setState({ password: '', autoPassword: true }); + this.onEnableSyncPressed(); + } + } + finishSync = (notifyUnlockFailed = false) => { const { navigation, notify, setClientSetting } = this.props; @@ -133,7 +143,7 @@ class SyncVerifyPage extends React.PureComponent { Retrieving your account information... ); - } else { + } else if (hasSyncedWallet) { content = ( Wallet Sync -- 2.45.2 From f1c48e734ebdcba2ad72f2be2ca218571c8b90f9 Mon Sep 17 00:00:00 2001 From: Akinwale Ariwodola Date: Thu, 28 Nov 2019 05:09:55 +0100 Subject: [PATCH 2/2] auto-login when no password is set --- src/page/firstRun/internal/wallet-page.js | 15 ++++++++---- src/page/firstRun/view.js | 13 +++++++++- .../verification/internal/sync-verify-page.js | 24 ++++++++++++++++--- 3 files changed, 44 insertions(+), 8 deletions(-) diff --git a/src/page/firstRun/internal/wallet-page.js b/src/page/firstRun/internal/wallet-page.js index aee7348..13e1c15 100644 --- a/src/page/firstRun/internal/wallet-page.js +++ b/src/page/firstRun/internal/wallet-page.js @@ -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 { Retrieving your account information... ); - } else if (syncApplyStarted || syncApplyIsPending) { + } else if (syncApplyStarted || syncApplyIsPending || syncApplyCompleted) { content = ( {syncApplyIsPending ? 'Validating password' : 'Synchronizing'}... ); - } 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 = ( Password diff --git a/src/page/firstRun/view.js b/src/page/firstRun/view.js index 60d74f9..5079965 100644 --- a/src/page/firstRun/view.js +++ b/src/page/firstRun/view.js @@ -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; diff --git a/src/page/verification/internal/sync-verify-page.js b/src/page/verification/internal/sync-verify-page.js index 3054c5d..41370c9 100644 --- a/src/page/verification/internal/sync-verify-page.js +++ b/src/page/verification/internal/sync-verify-page.js @@ -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 { Retrieving your account information... ); - } else if (hasSyncedWallet) { + } else if (this.state.autoLoginFlow && (syncApplyIsPending || this.state.syncApplyCompleted)) { + // first attempt at auto-login, only display activity indicator + content = ( + + + + + + ); + } else if (hasSyncedWallet && this.state.autoLoginAttempted) { content = ( Wallet Sync @@ -208,7 +226,7 @@ class SyncVerifyPage extends React.PureComponent { onPress={this.onEnableSyncPressed} /> )} - {syncApplyIsPending && ( + {(syncApplyIsPending || this.state.syncApplyCompleted) && ( -- 2.45.2