diff --git a/src/Expensify.js b/src/Expensify.js index 370266fe262b4..a9e9dd5e9d251 100644 --- a/src/Expensify.js +++ b/src/Expensify.js @@ -1,6 +1,5 @@ import React, {Component} from 'react'; import {View} from 'react-native'; -import get from 'lodash.get'; // import {Beforeunload} from 'react-beforeunload'; import SignInPage from './page/SignInPage'; @@ -30,7 +29,7 @@ class Expensify extends Component { this.state = { loading: true, - authenticated: false, + authToken: '', }; } @@ -39,9 +38,9 @@ class Expensify extends Component { // redirect to the signin page if we do not have one. Otherwise when the app inits // we will fall through to the homepage and the user will see a brief flash of the main // app experience. - Ion.get(IONKEYS.SESSION) - .then((response) => { - this.setState({loading: false, authenticated: Boolean(get(response, 'authToken', false))}); + Ion.get(IONKEYS.SESSION, 'authToken', '') + .then((authToken) => { + this.setState({loading: false, authToken}); }); } @@ -63,7 +62,7 @@ class Expensify extends Component { // We can only have a redirectTo if this is not the initial render so if we have one we'll // always navigate to it. If we are not authenticated by this point then we'll force navigate to sign in. - const redirectTo = this.state.redirectTo || (!this.state.authenticated && '/signin'); + const redirectTo = this.state.redirectTo || (!this.state.authToken && '/signin'); return ( diff --git a/src/components/WithIon.js b/src/components/WithIon.js index cccff5754651b..3adfb99e5f143 100644 --- a/src/components/WithIon.js +++ b/src/components/WithIon.js @@ -5,8 +5,8 @@ */ import React from 'react'; import _ from 'underscore'; -import get from 'lodash.get'; -import has from 'lodash.has'; +import lodashGet from 'lodash.get'; +import lodashHas from 'lodash.has'; import Ion from '../lib/Ion'; /** @@ -52,9 +52,9 @@ export default function (mapIonToState) { // If any of the mappings use data from the props, then when the props change, all the // connections need to be reconnected with the new props _.each(mapIonToState, (mapping, propertyName) => { - if (has(mapping, 'pathForProps')) { - const prevPropsData = get(prevProps, mapping.pathForProps); - const currentPropsData = get(this.props, mapping.pathForProps); + if (lodashHas(mapping, 'pathForProps')) { + const prevPropsData = lodashGet(prevProps, mapping.pathForProps); + const currentPropsData = lodashGet(this.props, mapping.pathForProps); if (prevPropsData !== currentPropsData) { Ion.disconnect(this.activeConnectionIDsWithPropsData[mapping.pathForProps]); this.connectMappingToIon(mapping, propertyName, this.wrappedComponent); @@ -105,7 +105,7 @@ export default function (mapIonToState) { if (mapping.pathForProps) { // If there is a path for props data, then the data needs to be pulled out of props and parsed // into the key - const dataFromProps = get(this.props, mapping.pathForProps); + const dataFromProps = lodashGet(this.props, mapping.pathForProps); const keyWithPropsData = mapping.key.replace('%DATAFROMPROPS%', dataFromProps); ionConnectionConfig.key = keyWithPropsData; @@ -124,7 +124,7 @@ export default function (mapIonToState) { // If there is a path for props data, then the data needs to be pulled out of props and parsed // into the key if (mapping.pathForProps) { - const dataFromProps = get(this.props, mapping.pathForProps); + const dataFromProps = lodashGet(this.props, mapping.pathForProps); prefillKey = mapping.prefillWithKey.replace('%DATAFROMPROPS%', dataFromProps); } @@ -138,7 +138,7 @@ export default function (mapIonToState) { const paramsForLoaderFunction = _.map(mapping.loaderParams, (loaderParam) => { // Some params might com from the props data if (loaderParam === '%DATAFROMPROPS%') { - return get(this.props, mapping.pathForProps); + return lodashGet(this.props, mapping.pathForProps); } return loaderParam; }); diff --git a/src/lib/actions/ActionsReport.js b/src/lib/actions/ActionsReport.js index 64e1ff4950122..057f384e399c7 100644 --- a/src/lib/actions/ActionsReport.js +++ b/src/lib/actions/ActionsReport.js @@ -1,6 +1,6 @@ import moment from 'moment'; import _ from 'underscore'; -import get from 'lodash.get'; +import lodashGet from 'lodash.get'; import Ion from '../Ion'; import {queueRequest} from '../Network'; import IONKEYS from '../../IONKEYS'; @@ -110,7 +110,7 @@ function fetchAll() { return promiseAllSettled(reportFetchPromises) .then(data => fetchedReports = _.compact(_.map(data, (promiseResult) => { // Grab the report from the promise result which stores it in the `value` key - const report = get(promiseResult, 'value.reports', {}); + const report = lodashGet(promiseResult, 'value.reports', {}); // If there is no report found from the promise, return null // Otherwise, grab the actual report object from the first index in the values array @@ -172,7 +172,7 @@ function addHistoryItem(reportID, reportComment) { .then((values) => { const reportHistory = values[historyKey]; const email = values[IONKEYS.SESSION].email || ''; - const personalDetails = get(values, [IONKEYS.PERSONAL_DETAILS, email], {}); + const personalDetails = lodashGet(values, [IONKEYS.PERSONAL_DETAILS, email], {}); // The new sequence number will be one higher than the highest let highestSequenceNumber = _.chain(reportHistory)