From cd4081848a849e9b9821509e86a21477057660d1 Mon Sep 17 00:00:00 2001 From: Yuwen Memon Date: Thu, 28 Jul 2022 18:28:23 -0600 Subject: [PATCH 01/15] Start using BeginSignIn command in place of GetAccountStatus --- README.md | 2 +- src/libs/Network/MainQueue.js | 2 +- src/libs/Network/enhanceParameters.js | 2 +- src/libs/actions/Session/index.js | 73 +++++++++++++-------------- src/libs/deprecatedAPI.js | 13 ----- src/pages/signin/LoginForm.js | 4 +- src/pages/signin/PasswordForm.js | 7 +-- src/pages/signin/SignInPage.js | 21 ++------ 8 files changed, 45 insertions(+), 79 deletions(-) diff --git a/README.md b/README.md index 85cf05ac619e..7e315c640241 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ For an M1 Mac, read this [SO](https://stackoverflow.com/c/expensify/questions/11 1. If you are having issues with **_Getting Started_**, please reference [React Native's Documentation](https://reactnative.dev/docs/environment-setup) 2. If you are running into CORS errors like (in the browser dev console) ```sh - Access to fetch at 'https://www.expensify.com/api?command=GetAccountStatus' from origin 'http://localhost:8080' has been blocked by CORS policy + Access to fetch at 'https://www.expensify.com/api?command=BeginSignIn' from origin 'http://localhost:8080' has been blocked by CORS policy ``` You probably have a misconfigured `.env` file - remove it (`rm .env`) and try again diff --git a/src/libs/Network/MainQueue.js b/src/libs/Network/MainQueue.js index 2143cee9d851..bb0804565893 100644 --- a/src/libs/Network/MainQueue.js +++ b/src/libs/Network/MainQueue.js @@ -19,7 +19,7 @@ let networkRequestQueue = []; * @return {Boolean} */ function canMakeRequest(request) { - // Some requests are always made even when we are in the process of authenticating (typically because they require no authToken e.g. Log, GetAccountStatus) + // Some requests are always made even when we are in the process of authenticating (typically because they require no authToken e.g. Log, BeginSignIn) // However, if we are in the process of authenticating we always want to queue requests until we are no longer authenticating. return request.data.forceNetworkRequest === true || (!NetworkStore.isAuthenticating() && !SequentialQueue.isRunning()); } diff --git a/src/libs/Network/enhanceParameters.js b/src/libs/Network/enhanceParameters.js index 093c0d96c087..1a014338d8c8 100644 --- a/src/libs/Network/enhanceParameters.js +++ b/src/libs/Network/enhanceParameters.js @@ -15,7 +15,7 @@ function isAuthTokenRequired(command) { 'Log', 'Graphite_Timer', 'Authenticate', - 'GetAccountStatus', + 'BeginSignIn', 'SetPassword', 'User_SignUp', 'ResendValidateCode', diff --git a/src/libs/actions/Session/index.js b/src/libs/actions/Session/index.js index 5059a434ad43..6d8065631e42 100644 --- a/src/libs/actions/Session/index.js +++ b/src/libs/actions/Session/index.js @@ -18,12 +18,12 @@ import Timers from '../../Timers'; import * as Pusher from '../../Pusher/pusher'; import NetworkConnection from '../../NetworkConnection'; import * as User from '../User'; -import * as ValidationUtils from '../../ValidationUtils'; import * as Authentication from '../../Authentication'; import * as ErrorUtils from '../../ErrorUtils'; import * as Welcome from '../Welcome'; import * as API from '../../API'; import * as NetworkStore from '../../Network/NetworkStore'; +import DateUtils from '../../DateUtils'; let credentials = {}; Onyx.connect({ @@ -138,44 +138,41 @@ function resendValidationLink(login = credentials.login) { * @param {String} login */ function fetchAccountDetails(login) { - Onyx.merge(ONYXKEYS.ACCOUNT, {...CONST.DEFAULT_ACCOUNT_DATA, loading: true}); + const optimisticData = [ + { + onyxMethod: CONST.ONYX.METHOD.MERGE, + key: ONYXKEYS.ACCOUNT, + value: { + ...CONST.DEFAULT_ACCOUNT_DATA, + isLoading: true, + }, + }, + ]; - DeprecatedAPI.GetAccountStatus({email: login, forceNetworkRequest: true}) - .then((response) => { - if (response.jsonCode === 200) { - Onyx.merge(ONYXKEYS.CREDENTIALS, { - login: response.normalizedLogin, - }); - Onyx.merge(ONYXKEYS.ACCOUNT, { - accountExists: response.accountExists, - validated: response.validated, - closed: response.isClosed, - forgotPassword: false, - validateCodeExpired: false, - }); - - if (!response.accountExists) { - createAccount(login); - } else if (response.isClosed) { - reopenAccount(login); - } else if (!response.validated) { - resendValidationLink(login); - } - } else if (response.jsonCode === 402) { - Onyx.merge(ONYXKEYS.ACCOUNT, { - error: ValidationUtils.isNumericWithSpecialChars(login) - ? Localize.translateLocal('common.error.phoneNumber') - : Localize.translateLocal('loginForm.error.invalidFormatEmailLogin'), - }); - } else if (response.jsonCode === CONST.JSON_CODE.UNABLE_TO_RETRY) { - Onyx.merge(ONYXKEYS.ACCOUNT, {error: Localize.translateLocal('session.offlineMessageRetry')}); - } else { - Onyx.merge(ONYXKEYS.ACCOUNT, {error: response.message}); - } - }) - .finally(() => { - Onyx.merge(ONYXKEYS.ACCOUNT, {loading: false}); - }); + const successData = [ + { + onyxMethod: CONST.ONYX.METHOD.MERGE, + key: ONYXKEYS.ACCOUNT, + value: { + isLoading: false, + }, + }, + ]; + + const failureData = [ + { + onyxMethod: CONST.ONYX.METHOD.MERGE, + key: ONYXKEYS.ACCOUNT, + value: { + isLoading: false, + errors: { + [DateUtils.getMicroseconds()]: 'Cannot get account details, please try again', + }, + }, + }, + ]; + + API.read('BeginSignIn', {email: login}, {optimisticData, successData, failureData}); } /** diff --git a/src/libs/deprecatedAPI.js b/src/libs/deprecatedAPI.js index 5042475d22b9..bfe6191f1853 100644 --- a/src/libs/deprecatedAPI.js +++ b/src/libs/deprecatedAPI.js @@ -134,18 +134,6 @@ function Get(parameters, shouldUseSecure = false) { return Network.post(commandName, parameters, CONST.NETWORK.METHOD.POST, shouldUseSecure); } -/** - * @param {Object} parameters - * @param {String} parameters.email - * @param {Boolean} parameters.forceNetworkRequest - * @returns {Promise} - */ -function GetAccountStatus(parameters) { - const commandName = 'GetAccountStatus'; - requireParameters(['email'], parameters, commandName); - return Network.post(commandName, parameters); -} - /** * @param {Object} parameters * @param {String} parameters.debtorEmail @@ -727,7 +715,6 @@ export { DeleteLogin, DeleteBankAccount, Get, - GetAccountStatus, GetStatementPDF, GetIOUReport, GetFullPolicy, diff --git a/src/pages/signin/LoginForm.js b/src/pages/signin/LoginForm.js index 43e3b7b6e656..248d65ca5bcb 100755 --- a/src/pages/signin/LoginForm.js +++ b/src/pages/signin/LoginForm.js @@ -34,7 +34,7 @@ const propTypes = { success: PropTypes.string, /** Whether or not a sign on form is loading (being submitted) */ - loading: PropTypes.bool, + isLoading: PropTypes.bool, }), ...windowDimensionsPropTypes, @@ -174,7 +174,7 @@ class LoginForm extends React.Component {