From 2ec3f62407385c2f982bc9af74c272bc46197480 Mon Sep 17 00:00:00 2001 From: Sean Yesmunt Date: Wed, 16 Oct 2019 01:01:18 -0400 Subject: [PATCH] redirect to password screen if toggling sync from settings page --- package.json | 4 +-- src/ui/component/app/view.jsx | 4 +-- src/ui/component/button/view.jsx | 3 +- src/ui/component/syncPassword/view.jsx | 13 +++---- src/ui/component/syncToggle/index.js | 3 +- src/ui/component/syncToggle/view.jsx | 29 ++++++++++++--- src/ui/component/userSignIn/view.jsx | 17 +++++++-- src/ui/component/userVerify/view.jsx | 5 +-- src/ui/constants/modal_types.js | 1 - src/ui/index.jsx | 6 +--- .../modalRewardApprovalRequired/index.js | 25 ------------- .../modalRewardApprovalRequired/view.jsx | 35 ------------------- src/ui/modal/modalRouter/view.jsx | 3 -- src/ui/page/help/index.js | 2 +- src/ui/page/settings/view.jsx | 17 ++------- src/ui/util/saved-passwords.js | 6 ++-- yarn.lock | 8 ++--- 17 files changed, 66 insertions(+), 115 deletions(-) delete mode 100644 src/ui/modal/modalRewardApprovalRequired/index.js delete mode 100644 src/ui/modal/modalRewardApprovalRequired/view.jsx diff --git a/package.json b/package.json index 7fc753696..880b72f50 100644 --- a/package.json +++ b/package.json @@ -130,8 +130,8 @@ "husky": "^0.14.3", "json-loader": "^0.5.4", "lbry-format": "https://github.com/lbryio/lbry-format.git", - "lbry-redux": "lbryio/lbry-redux#0090f195eb88f4620db7d038f7b01eaa76119836", - "lbryinc": "lbryio/lbryinc#b8e1708ee4491db342c81576265e1b58f542bedb", + "lbry-redux": "lbryio/lbry-redux#b09e1699eb92fef8087986a0f35b3df3977af87f", + "lbryinc": "lbryio/lbryinc#fb2e73ab31c2b9f80a53f082843a01e3f213ca45", "lint-staged": "^7.0.2", "localforage": "^1.7.1", "lodash-es": "^4.17.14", diff --git a/src/ui/component/app/view.jsx b/src/ui/component/app/view.jsx index 4953080f2..fd135a823 100644 --- a/src/ui/component/app/view.jsx +++ b/src/ui/component/app/view.jsx @@ -124,7 +124,7 @@ function App(props: Props) { }, [hasVerifiedEmail, signIn, hasSignedIn]); useEffect(() => { - if (userId && hasVerifiedEmail && syncEnabled) { + if (hasVerifiedEmail && syncEnabled) { checkSync(); let syncInterval = setInterval(() => { @@ -135,7 +135,7 @@ function App(props: Props) { clearInterval(syncInterval); }; } - }, [hasVerifiedEmail, syncEnabled, checkSync, userId]); + }, [hasVerifiedEmail, syncEnabled, checkSync]); if (!user) { return null; diff --git a/src/ui/component/button/view.jsx b/src/ui/component/button/view.jsx index 564310e24..0182f1566 100644 --- a/src/ui/component/button/view.jsx +++ b/src/ui/component/button/view.jsx @@ -69,7 +69,6 @@ const Button = forwardRef((props: Props, ref: any) => { ...otherProps } = props; - const currentPath = pathname.split('/$/')[1]; const combinedClassName = classnames( 'button', button @@ -120,7 +119,7 @@ const Button = forwardRef((props: Props, ref: any) => { void, @@ -13,15 +14,10 @@ type Props = { function SyncPassword(props: Props) { const { getSync, getSyncIsPending } = props; const [password, setPassword] = React.useState(''); - const [rememberPassword, setRememberPassword] = React.useState(true); + const [rememberPassword, setRememberPassword] = usePersistedState(true); function handleSubmit() { - if (rememberPassword) { - setSavedPassword(password); - } else { - deleteSavedPassword(); - } - + setSavedPassword(password, rememberPassword); getSync(password); } @@ -39,6 +35,7 @@ function SyncPassword(props: Props) { onChange={e => setPassword(e.target.value)} /> ({ syncEnabled: makeSelectClientSetting(SETTINGS.ENABLE_SYNC)(state), verifiedEmail: selectUserVerifiedEmail(state), + getSyncError: selectGetSyncErrorMessage(state), }); const perform = dispatch => ({ diff --git a/src/ui/component/syncToggle/view.jsx b/src/ui/component/syncToggle/view.jsx index 84a20ac00..27d1c080b 100644 --- a/src/ui/component/syncToggle/view.jsx +++ b/src/ui/component/syncToggle/view.jsx @@ -1,25 +1,44 @@ // @flow +import * as PAGES from 'constants/pages'; import React from 'react'; -import { FormField } from 'component/common/form'; import Button from 'component/button'; +import { FormField } from 'component/common/form'; +import { withRouter } from 'react-router'; type Props = { setSyncEnabled: boolean => void, syncEnabled: boolean, verifiedEmail: ?string, + history: { push: string => void }, + location: UrlLocation, + getSyncError: ?string, }; function SyncToggle(props: Props) { - const { setSyncEnabled, syncEnabled, verifiedEmail } = props; - console.log('??', syncEnabled); + const { + setSyncEnabled, + syncEnabled, + verifiedEmail, + getSyncError, + history, + location: { pathname }, + } = props; + function handleChange() { setSyncEnabled(!syncEnabled); } + if (getSyncError) { + return history.push(`/$/${PAGES.AUTH}?redirect=${pathname}&immediate=true`); + } + return (
{!verifiedEmail ? ( -
) : ( , showEmailVerification && , - showUserVerification && , + showUserVerification && , showChannelCreation && , // @if TARGET='app' showYoutubeTransfer && ( @@ -132,6 +134,17 @@ function UserSignIn(props: Props) { for (var i = SIGN_IN_FLOW.length - 1; i > -1; i--) { const Component = SIGN_IN_FLOW[i]; if (Component) { + // If we want to redirect immediately, + // remember the first step so we can redirect once a new step has been reached + // Ignore the loading step + if (redirect && shouldRedirectImmediately) { + if (!initialSignInStep) { + setInitialSignInStep(i); + } else if (i !== initialSignInStep && i !== SIGN_IN_FLOW.length - 1) { + history.replace(redirect); + } + } + return Component; } } diff --git a/src/ui/component/userVerify/view.jsx b/src/ui/component/userVerify/view.jsx index d2bd095f1..958af9dab 100644 --- a/src/ui/component/userVerify/view.jsx +++ b/src/ui/component/userVerify/view.jsx @@ -12,6 +12,7 @@ type Props = { verifyUserIdentity: string => void, verifyPhone: () => void, fetchUser: () => void, + skipLink?: string, }; class UserVerify extends React.PureComponent { @@ -26,7 +27,7 @@ class UserVerify extends React.PureComponent { } render() { - const { errorMessage, isPending, verifyPhone, fetchUser } = this.props; + const { errorMessage, isPending, verifyPhone, fetchUser, skipLink } = this.props; return (
@@ -36,7 +37,7 @@ class UserVerify extends React.PureComponent { "We weren't able to auto-approve you for rewards. Please complete one of the steps below to unlock them." )}{' '}
diff --git a/src/ui/constants/modal_types.js b/src/ui/constants/modal_types.js index 5b72e0398..c5e1ef8ec 100644 --- a/src/ui/constants/modal_types.js +++ b/src/ui/constants/modal_types.js @@ -13,7 +13,6 @@ export const PHONE_COLLECTION = 'phone_collection'; export const FIRST_REWARD = 'first_reward'; export const AUTHENTICATION_FAILURE = 'auth_failure'; export const TRANSACTION_FAILED = 'transaction_failed'; -export const REWARD_APPROVAL_REQUIRED = 'reward_approval_required'; export const REWARD_GENERATED_CODE = 'reward_generated_code'; export const AFFIRM_PURCHASE = 'affirm_purchase'; export const CONFIRM_CLAIM_REVOKE = 'confirm_claim_revoke'; diff --git a/src/ui/index.jsx b/src/ui/index.jsx index fd02df782..d375c86ae 100644 --- a/src/ui/index.jsx +++ b/src/ui/index.jsx @@ -125,12 +125,8 @@ rewards.setCallback('claimFirstRewardSuccess', () => { app.store.dispatch(doOpenModal(MODALS.FIRST_REWARD)); }); -rewards.setCallback('rewardApprovalRequired', () => { - app.store.dispatch(doOpenModal(MODALS.REWARD_APPROVAL_REQUIRED)); -}); - rewards.setCallback('claimRewardSuccess', () => { - app.store.dispatch(doHideModal(MODALS.REWARD_APPROVAL_REQUIRED)); + app.store.dispatch(doHideModal()); }); // @if TARGET='app' diff --git a/src/ui/modal/modalRewardApprovalRequired/index.js b/src/ui/modal/modalRewardApprovalRequired/index.js deleted file mode 100644 index d1ef4743b..000000000 --- a/src/ui/modal/modalRewardApprovalRequired/index.js +++ /dev/null @@ -1,25 +0,0 @@ -import * as PAGES from 'constants/pages'; -import { connect } from 'react-redux'; -import { doHideModal } from 'redux/actions/app'; -import { withRouter } from 'react-router-dom'; -import ModalRewardApprovalRequired from './view'; - -const perform = (dispatch, ownProps) => ({ - doAuth: () => { - const { - location: { pathname }, - history, - } = ownProps; - const currentPath = pathname.split('/$/')[1]; - dispatch(doHideModal()); - history.push(`/$/${PAGES.AUTH}?redirect=${currentPath}`); - }, - closeModal: () => dispatch(doHideModal()), -}); - -export default withRouter( - connect( - null, - perform - )(ModalRewardApprovalRequired) -); diff --git a/src/ui/modal/modalRewardApprovalRequired/view.jsx b/src/ui/modal/modalRewardApprovalRequired/view.jsx deleted file mode 100644 index f49d65958..000000000 --- a/src/ui/modal/modalRewardApprovalRequired/view.jsx +++ /dev/null @@ -1,35 +0,0 @@ -// @flow -import React from 'react'; -import { Modal } from 'modal/modal'; - -type Props = { - closeModal: () => void, - doAuth: () => void, -}; - -class ModalRewardApprovalRequired extends React.PureComponent { - render() { - const { closeModal, doAuth } = this.props; - - return ( - -

- {__( - "Before we can give you any credits, we need to perform a brief check to make sure you're a new and unique person." - )} -

-
- ); - } -} - -export default ModalRewardApprovalRequired; diff --git a/src/ui/modal/modalRouter/view.jsx b/src/ui/modal/modalRouter/view.jsx index 65e215657..10c87acce 100644 --- a/src/ui/modal/modalRouter/view.jsx +++ b/src/ui/modal/modalRouter/view.jsx @@ -8,7 +8,6 @@ import ModalAutoUpdateDownloaded from 'modal/modalAutoUpdateDownloaded'; import ModalUpgrade from 'modal/modalUpgrade'; import ModalWelcome from 'modal/modalWelcome'; import ModalFirstReward from 'modal/modalFirstReward'; -import ModalRewardApprovalRequired from 'modal/modalRewardApprovalRequired'; import ModalRemoveFile from 'modal/modalRemoveFile'; import ModalTransactionFailed from 'modal/modalTransactionFailed'; import ModalFileTimeout from 'modal/modalFileTimeout'; @@ -65,8 +64,6 @@ function ModalRouter(props: Props) { return ; case MODALS.TRANSACTION_FAILED: return ; - case MODALS.REWARD_APPROVAL_REQUIRED: - return ; case MODALS.CONFIRM_FILE_REMOVE: return ; case MODALS.AFFIRM_PURCHASE: diff --git a/src/ui/page/help/index.js b/src/ui/page/help/index.js index 5e74a2690..d96578021 100644 --- a/src/ui/page/help/index.js +++ b/src/ui/page/help/index.js @@ -11,7 +11,7 @@ const select = state => ({ }); const perform = (dispatch, ownProps) => ({ - doAuth: () => ownProps.history.push(`/$/${PAGES.AUTH}?redirect=help`), + doAuth: () => ownProps.history.push(`/$/${PAGES.AUTH}?redirect=/$/${PAGES.HELP}`), fetchAccessToken: () => dispatch(doFetchAccessToken()), }); diff --git a/src/ui/page/settings/view.jsx b/src/ui/page/settings/view.jsx index 3d3e3c2cd..58d4cc90f 100644 --- a/src/ui/page/settings/view.jsx +++ b/src/ui/page/settings/view.jsx @@ -90,7 +90,6 @@ class SettingsPage extends React.PureComponent { (this: any).onInstantPurchaseMaxChange = this.onInstantPurchaseMaxChange.bind(this); (this: any).onThemeChange = this.onThemeChange.bind(this); (this: any).onAutomaticDarkModeChange = this.onAutomaticDarkModeChange.bind(this); - (this: any).clearCache = this.clearCache.bind(this); (this: any).onChangeTime = this.onChangeTime.bind(this); (this: any).onConfirmForgetPassword = this.onConfirmForgetPassword.bind(this); } @@ -175,19 +174,6 @@ class SettingsPage extends React.PureComponent { this.props.setDaemonSetting(name, value); } - clearCache() { - this.setState({ - clearingCache: true, - }); - const success = () => { - this.setState({ clearingCache: false }); - window.location.reload(); - }; - const clear = () => this.props.clearCache().then(success); - - setTimeout(clear, 1000, { once: true }); - } - render() { const { daemonSettings, @@ -210,6 +196,7 @@ class SettingsPage extends React.PureComponent { floatingPlayer, clearPlayingUri, darkModeTimes, + clearCache, } = this.props; const noDaemonSettings = !daemonSettings || Object.keys(daemonSettings).length === 0; @@ -651,7 +638,7 @@ class SettingsPage extends React.PureComponent {