From 09e87e2b5704477690bae88d44f6778e2a19d5f3 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Tue, 28 Jun 2022 12:59:07 -0600 Subject: [PATCH 1/7] create openApp --- src/libs/Navigation/AppNavigator/AuthScreens.js | 1 + src/libs/actions/App.js | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/src/libs/Navigation/AppNavigator/AuthScreens.js b/src/libs/Navigation/AppNavigator/AuthScreens.js index 8a0e5e53dcfe8..0d40ad9ed839f 100644 --- a/src/libs/Navigation/AppNavigator/AuthScreens.js +++ b/src/libs/Navigation/AppNavigator/AuthScreens.js @@ -105,6 +105,7 @@ class AuthScreens extends React.Component { // Listen for report changes and fetch some data we need on initialization UnreadIndicatorUpdater.listenForReportChanges(); App.getAppData(false); + App.openApp(); App.fixAccountAndReloadData(); App.setUpPoliciesAndNavigate(this.props.session); diff --git a/src/libs/actions/App.js b/src/libs/actions/App.js index 06596e9003ca0..fb200a56b59ef 100644 --- a/src/libs/actions/App.js +++ b/src/libs/actions/App.js @@ -2,6 +2,7 @@ import {AppState, Linking} from 'react-native'; import Onyx from 'react-native-onyx'; import lodashGet from 'lodash/get'; import Str from 'expensify-common/lib/str'; +import * as API from '../API'; import ONYXKEYS from '../../ONYXKEYS'; import * as DeprecatedAPI from '../deprecatedAPI'; import CONST from '../../CONST'; @@ -124,6 +125,13 @@ function getAppData(shouldSyncPolicyList = true, shouldSyncVBA = true) { ]); } +/** + * Fetches data needed for app initialization + */ +function openApp() { + API.read('OpenApp'); +} + /** * Run FixAccount to check if we need to fix anything for the user or run migrations. Reinitialize the data if anything changed * because some migrations might create new chat reports or their change data. @@ -203,4 +211,5 @@ export { getAppData, fixAccountAndReloadData, setUpPoliciesAndNavigate, + openApp, }; From 2b281f6740df11edba8101c8568b042ee0117175 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Tue, 28 Jun 2022 13:20:58 -0600 Subject: [PATCH 2/7] rm usage of getCurrencyList --- src/libs/actions/App.js | 1 - src/libs/actions/PersonalDetails.js | 15 --------------- src/libs/deprecatedAPI.js | 8 -------- src/pages/iou/IOUCurrencySelection.js | 16 ---------------- src/pages/workspace/WorkspaceSettingsPage.js | 16 ---------------- 5 files changed, 56 deletions(-) diff --git a/src/libs/actions/App.js b/src/libs/actions/App.js index fb200a56b59ef..57ee0e0011f26 100644 --- a/src/libs/actions/App.js +++ b/src/libs/actions/App.js @@ -106,7 +106,6 @@ function getAppData(shouldSyncPolicyList = true, shouldSyncVBA = true) { User.getUserDetails(); User.getBetas(); User.getDomainInfo(); - PersonalDetails.fetchLocalCurrency(); GeoLocation.fetchCountryCodeByRequestIP(); BankAccounts.fetchUserWallet(); diff --git a/src/libs/actions/PersonalDetails.js b/src/libs/actions/PersonalDetails.js index cc7add84320e4..05caaa6bd9c0b 100644 --- a/src/libs/actions/PersonalDetails.js +++ b/src/libs/actions/PersonalDetails.js @@ -295,19 +295,6 @@ function setPersonalDetails(details, shouldGrowl) { }); } -/** - * Sets the onyx with the currency list from the network - * @returns {Object} - */ -function getCurrencyList() { - return DeprecatedAPI.GetCurrencyList() - .then((data) => { - const currencyListObject = JSON.parse(data.currencyList); - Onyx.merge(ONYXKEYS.CURRENCY_LIST, currencyListObject); - return currencyListObject; - }); -} - /** * Fetches the local currency based on location and sets currency code/symbol to local storage */ @@ -323,7 +310,6 @@ function fetchLocalCurrency() { .then((data) => { currency = data.currency; }) - .then(getCurrencyList) .then(() => { Onyx.merge(ONYXKEYS.MY_PERSONAL_DETAILS, {localCurrencyCode: currency}); }) @@ -379,7 +365,6 @@ export { setAvatar, deleteAvatar, fetchLocalCurrency, - getCurrencyList, getMaxCharacterError, extractFirstAndLastNameFromAvailableDetails, }; diff --git a/src/libs/deprecatedAPI.js b/src/libs/deprecatedAPI.js index 67333741f0a71..f42a55ddee6a2 100644 --- a/src/libs/deprecatedAPI.js +++ b/src/libs/deprecatedAPI.js @@ -756,13 +756,6 @@ function GetLocalCurrency(parameters) { return Network.post(commandName, parameters); } -/** - * @returns {Promise} - */ -function GetCurrencyList() { - return Mobile_GetConstants({data: ['currencyList']}); -} - /** * @returns {Promise} */ @@ -980,7 +973,6 @@ export { Wallet_GetOnfidoSDKToken, TransferWalletBalance, GetLocalCurrency, - GetCurrencyList, Policy_Create, Policy_CustomUnit_Update, Policy_CustomUnitRate_Update, diff --git a/src/pages/iou/IOUCurrencySelection.js b/src/pages/iou/IOUCurrencySelection.js index a8dfad9ff257c..d1d496e11a1cc 100644 --- a/src/pages/iou/IOUCurrencySelection.js +++ b/src/pages/iou/IOUCurrencySelection.js @@ -59,18 +59,6 @@ class IOUCurrencySelection extends Component { this.changeSearchValue = this.changeSearchValue.bind(this); } - componentDidMount() { - this.fetchData(); - } - - componentDidUpdate(prevProps) { - if (!prevProps.network.isOffline || this.props.network.isOffline) { - return; - } - - this.fetchData(); - } - /** * Returns the sections needed for the OptionsSelector * @@ -102,10 +90,6 @@ class IOUCurrencySelection extends Component { })); } - fetchData() { - PersonalDetails.getCurrencyList(); - } - /** * Sets new search value * @param {String} searchValue diff --git a/src/pages/workspace/WorkspaceSettingsPage.js b/src/pages/workspace/WorkspaceSettingsPage.js index c9692d464ea49..4d0d11e8ee090 100644 --- a/src/pages/workspace/WorkspaceSettingsPage.js +++ b/src/pages/workspace/WorkspaceSettingsPage.js @@ -54,18 +54,6 @@ class WorkspaceSettingsPage extends React.Component { this.validate = this.validate.bind(this); } - componentDidMount() { - this.fetchData(); - } - - componentDidUpdate(prevProps) { - if (!prevProps.network.isOffline || this.props.network.isOffline) { - return; - } - - this.fetchData(); - } - /** * @returns {Object[]} */ @@ -77,10 +65,6 @@ class WorkspaceSettingsPage extends React.Component { })); } - fetchData() { - PersonalDetails.getCurrencyList(); - } - removeAvatar() { this.setState({previewAvatarURL: ''}); Policy.update(this.props.policy.id, {avatarURL: ''}, true); From 425480b66fb877091d9aaec02a66bf745d29ec07 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Tue, 28 Jun 2022 13:29:03 -0600 Subject: [PATCH 3/7] rm unused imports --- src/pages/iou/IOUCurrencySelection.js | 5 ----- src/pages/workspace/WorkspaceSettingsPage.js | 6 ------ 2 files changed, 11 deletions(-) diff --git a/src/pages/iou/IOUCurrencySelection.js b/src/pages/iou/IOUCurrencySelection.js index d1d496e11a1cc..c05ea3379f012 100644 --- a/src/pages/iou/IOUCurrencySelection.js +++ b/src/pages/iou/IOUCurrencySelection.js @@ -2,7 +2,6 @@ import React, {Component} from 'react'; import PropTypes from 'prop-types'; import {withOnyx} from 'react-native-onyx'; import _ from 'underscore'; -import * as PersonalDetails from '../../libs/actions/PersonalDetails'; import ONYXKEYS from '../../ONYXKEYS'; import * as OptionsListUtils from '../../libs/OptionsListUtils'; import OptionsSelector from '../../components/OptionsSelector'; @@ -15,7 +14,6 @@ import KeyboardAvoidingView from '../../components/KeyboardAvoidingView'; import * as IOU from '../../libs/actions/IOU'; import * as CurrencySymbolUtils from '../../libs/CurrencySymbolUtils'; import {withNetwork} from '../../components/OnyxProvider'; -import networkPropTypes from '../../components/networkPropTypes'; /** * IOU Currency selection for selecting currency @@ -33,10 +31,7 @@ const propTypes = { ISO4217: PropTypes.string, })), - /** Information about the network from Onyx */ - network: networkPropTypes.isRequired, ...withLocalizePropTypes, - }; const defaultProps = { diff --git a/src/pages/workspace/WorkspaceSettingsPage.js b/src/pages/workspace/WorkspaceSettingsPage.js index 4d0d11e8ee090..3b20f0e86c39d 100644 --- a/src/pages/workspace/WorkspaceSettingsPage.js +++ b/src/pages/workspace/WorkspaceSettingsPage.js @@ -15,21 +15,15 @@ import AvatarWithImagePicker from '../../components/AvatarWithImagePicker'; import defaultTheme from '../../styles/themes/default'; import CONST from '../../CONST'; import Picker from '../../components/Picker'; -import * as PersonalDetails from '../../libs/actions/PersonalDetails'; import TextInput from '../../components/TextInput'; import FixedFooter from '../../components/FixedFooter'; import WorkspacePageWithSections from './WorkspacePageWithSections'; import FullScreenLoadingIndicator from '../../components/FullscreenLoadingIndicator'; import withFullPolicy, {fullPolicyPropTypes, fullPolicyDefaultProps} from './withFullPolicy'; import {withNetwork} from '../../components/OnyxProvider'; -import networkPropTypes from '../../components/networkPropTypes'; const propTypes = { - /** Information about the network from Onyx */ - network: networkPropTypes.isRequired, - ...fullPolicyPropTypes, - ...withLocalizePropTypes, }; From 2dfa6f0efd4d2c676912ae598b8cbbe04f20012d Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Tue, 28 Jun 2022 14:03:27 -0600 Subject: [PATCH 4/7] create reconnectApp --- src/libs/actions/App.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/libs/actions/App.js b/src/libs/actions/App.js index 57ee0e0011f26..db49c22c41405 100644 --- a/src/libs/actions/App.js +++ b/src/libs/actions/App.js @@ -131,6 +131,13 @@ function openApp() { API.read('OpenApp'); } +/** + * Refreshes data when the app reconnects + */ +function reconnectApp() { + API.read('ReconnectApp'); +} + /** * Run FixAccount to check if we need to fix anything for the user or run migrations. Reinitialize the data if anything changed * because some migrations might create new chat reports or their change data. @@ -200,7 +207,10 @@ function setUpPoliciesAndNavigate(session) { } // When the app reconnects from being offline, fetch all initialization data -NetworkConnection.onReconnect(() => getAppData(true, false)); +NetworkConnection.onReconnect(() => { + getAppData(true, false); + reconnectApp(); +}); export { setCurrentURL, From 1dac2396a9e987d672d6a32e1ef4ce0f55d0c6a6 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Tue, 28 Jun 2022 15:41:44 -0600 Subject: [PATCH 5/7] rm Mobile_GetConstants --- src/libs/deprecatedAPI.js | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/src/libs/deprecatedAPI.js b/src/libs/deprecatedAPI.js index f42a55ddee6a2..81baa947a6d25 100644 --- a/src/libs/deprecatedAPI.js +++ b/src/libs/deprecatedAPI.js @@ -730,21 +730,6 @@ function DeleteBankAccount(parameters) { return Network.post(commandName, parameters); } -/** - * @param {Object} parameters - * @returns {Promise} - */ -function Mobile_GetConstants(parameters) { - const commandName = 'Mobile_GetConstants'; - requireParameters(['data'], parameters, commandName); - - // Stringify the parameters object as we cannot send an object via FormData - const finalParameters = parameters; - finalParameters.data = JSON.stringify(parameters.data); - - return Network.post(commandName, finalParameters); -} - /** * @param {Object} parameters * @param {Number} [parameters.latitude] From 1c8d490e079437eb3e72f07dd9d7866f599e0ad7 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Wed, 13 Jul 2022 11:22:10 -0700 Subject: [PATCH 6/7] update currencyList tests --- tests/unit/CurrencySymbolUtilsTest.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/unit/CurrencySymbolUtilsTest.js b/tests/unit/CurrencySymbolUtilsTest.js index dc072a03fae8c..bba1eabce7a0e 100644 --- a/tests/unit/CurrencySymbolUtilsTest.js +++ b/tests/unit/CurrencySymbolUtilsTest.js @@ -2,9 +2,10 @@ import _ from 'underscore'; import * as CurrencySymbolUtils from '../../src/libs/CurrencySymbolUtils'; // This file can get outdated. In that case, you can follow these steps to update it: -// - in src/libs/API.js -// - call: GetCurrencyList().then(data => console.log(data.currencyList)); -// - copy the json from console and format it to valid json using some external tool +// - open your browser concole and navigate to the Network tab +// - refresh the App +// - click on the OpenApp request and in the preview tab locate the key `currencyList` +// - copy the value and format it to valid json using some external tool // - update currencyList.json import currencyList from './currencyList.json'; @@ -35,4 +36,3 @@ describe('CurrencySymbolUtils', () => { }); }); }); - From 10406bfdbdf1883cf27c74facec2d6b29ae541e1 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Wed, 13 Jul 2022 11:37:54 -0700 Subject: [PATCH 7/7] fix typo --- tests/unit/CurrencySymbolUtilsTest.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/CurrencySymbolUtilsTest.js b/tests/unit/CurrencySymbolUtilsTest.js index bba1eabce7a0e..274a48aa0c910 100644 --- a/tests/unit/CurrencySymbolUtilsTest.js +++ b/tests/unit/CurrencySymbolUtilsTest.js @@ -2,7 +2,7 @@ import _ from 'underscore'; import * as CurrencySymbolUtils from '../../src/libs/CurrencySymbolUtils'; // This file can get outdated. In that case, you can follow these steps to update it: -// - open your browser concole and navigate to the Network tab +// - open your browser console and navigate to the Network tab // - refresh the App // - click on the OpenApp request and in the preview tab locate the key `currencyList` // - copy the value and format it to valid json using some external tool