Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 4 additions & 35 deletions src/libs/actions/User.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import _ from 'underscore';
import lodashGet from 'lodash/get';
import Onyx from 'react-native-onyx';
import Str from 'expensify-common/lib/str';
import {PUBLIC_DOMAINS as COMMON_PUBLIC_DOMAINS} from 'expensify-common/lib/CONST';
import moment from 'moment';
import ONYXKEYS from '../../ONYXKEYS';
import * as DeprecatedAPI from '../deprecatedAPI';
Expand All @@ -25,13 +23,11 @@ import * as SequentialQueue from '../Network/SequentialQueue';
import PusherUtils from '../PusherUtils';

let sessionAuthToken = '';
let sessionEmail = '';
let currentUserAccountID = '';
Onyx.connect({
key: ONYXKEYS.SESSION,
callback: (val) => {
sessionAuthToken = lodashGet(val, 'authToken', '');
sessionEmail = lodashGet(val, 'email', '');
currentUserAccountID = lodashGet(val, 'accountID', '');
},
});
Expand Down Expand Up @@ -267,39 +263,12 @@ function isBlockedFromConcierge(blockedFromConcierge) {
}

/**
* Fetch the public domain info for the current user.
*
* This API is a bit weird in that it sometimes depends on information being cached in bedrock.
* If the info for the domain is not in bedrock, then it creates an asynchronous bedrock job to gather domain info.
* If that happens, this function will automatically retry itself in 10 minutes.
* Fetch whether the user has the Expensify card enabled.
*/
function getDomainInfo() {
// If this command fails, we'll retry again in 10 minutes,
// arbitrarily chosen giving Bedrock time to resolve the ClearbitCheckPublicEmail job for this email.
const RETRY_TIMEOUT = 600000;

// First check list of common public domains
if (_.contains(COMMON_PUBLIC_DOMAINS, sessionEmail)) {
Onyx.merge(ONYXKEYS.USER, {isFromPublicDomain: true});
return;
}

// If it is not a common public domain, check the API
DeprecatedAPI.User_IsFromPublicDomain({email: sessionEmail})
.then((response) => {
if (response.jsonCode === 200) {
const {isFromPublicDomain} = response;
Onyx.merge(ONYXKEYS.USER, {isFromPublicDomain});

DeprecatedAPI.User_IsUsingExpensifyCard()
.then(({isUsingExpensifyCard}) => {
Onyx.merge(ONYXKEYS.USER, {isUsingExpensifyCard});
});
} else {
// eslint-disable-next-line max-len
Log.info(`Command User_IsFromPublicDomain returned error code: ${response.jsonCode}. Most likely, this means that the domain ${Str.extractEmail(sessionEmail)} is not in the bedrock cache. Retrying in ${RETRY_TIMEOUT / 1000 / 60} minutes`);
setTimeout(getDomainInfo, RETRY_TIMEOUT);
}
DeprecatedAPI.User_IsUsingExpensifyCard()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This command will be refactored in a separate PR

.then(({isUsingExpensifyCard}) => {
Onyx.merge(ONYXKEYS.USER, {isUsingExpensifyCard});
});
}

Expand Down
16 changes: 0 additions & 16 deletions src/libs/deprecatedAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -456,21 +456,6 @@ function User_GetBetas() {
return Network.post('User_GetBetas');
}

/**
* @param {Object} parameters
* @param {String} parameters.email
* @param {Boolean} [parameters.requireCertainty]
* @returns {Promise}
*/
function User_IsFromPublicDomain(parameters) {
const commandName = 'User_IsFromPublicDomain';
requireParameters(['email'], parameters, commandName);
return Network.post(commandName, {
...{requireCertainty: true},

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We changed this to false in the Web-E PR since all use cases in NewDot default to false in case we don't have a Clearbit response in time.

...parameters,
});
}

/**
* @param {Object} parameters
* @param {String} parameters.email
Expand Down Expand Up @@ -953,7 +938,6 @@ export {
User_SignUp,
User_Delete,
User_GetBetas,
User_IsFromPublicDomain,
User_IsUsingExpensifyCard,
User_ReopenAccount,
User_SecondaryLogin_Send,
Expand Down