Skip to content

Commit

Permalink
Merge pull request #3664 from Expensify/marcaaron-checkPublicDomainEx…
Browse files Browse the repository at this point in the history
…pensifyCard

[No QA] Add check for isUsingExpensifyCard
  • Loading branch information
marcaaron authored Jun 23, 2021
2 parents 94aed1b + 486ef05 commit 9c89d8b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
8 changes: 8 additions & 0 deletions src/libs/API.js
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,13 @@ function GetCurrencyList() {
return Mobile_GetConstants({data: ['currencyList']});
}

/**
* @returns {Promise}
*/
function User_IsUsingExpensifyCard() {
return Network.post('User_IsUsingExpensifyCard', {});
}

/**
* @param {Object} parameters
* @param {String} [parameters.type]
Expand Down Expand Up @@ -1004,6 +1011,7 @@ export {
User_SignUp,
User_GetBetas,
User_IsFromPublicDomain,
User_IsUsingExpensifyCard,
User_ReopenAccount,
User_SecondaryLogin_Send,
User_UploadAvatar,
Expand Down
2 changes: 1 addition & 1 deletion src/libs/Navigation/AppNavigator/AuthScreens.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class AuthScreens extends React.Component {
PersonalDetails.fetchPersonalDetails();
User.getUserDetails();
User.getBetas();
User.getPublicDomainInfo();
User.getDomainInfo();
PersonalDetails.fetchCurrencyPreferences();
fetchAllReports(true, true);
fetchCountryCodeByRequestIP();
Expand Down
17 changes: 14 additions & 3 deletions src/libs/actions/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ function validateLogin(accountID, validateCode) {
* 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.
*/
function getPublicDomainInfo() {
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;
Expand All @@ -198,10 +198,21 @@ function getPublicDomainInfo() {
if (response.jsonCode === 200) {
const {isFromPublicDomain} = response;
Onyx.merge(ONYXKEYS.USER, {isFromPublicDomain});

// If the user is not on a public domain we'll want to know whether they are on a domain that has
// already provisioned the Expensify card
if (isFromPublicDomain) {
return;
}

API.User_IsUsingExpensifyCard()
.then(({isUsingExpensifyCard}) => {
Onyx.merge(ONYXKEYS.USER, {isUsingExpensifyCard});
});
} else {
// eslint-disable-next-line max-len
console.debug(`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(getPublicDomainInfo, RETRY_TIMEOUT);
setTimeout(getDomainInfo, RETRY_TIMEOUT);
}
});
}
Expand All @@ -214,5 +225,5 @@ export {
setExpensifyNewsStatus,
setSecondaryLogin,
validateLogin,
getPublicDomainInfo,
getDomainInfo,
};

0 comments on commit 9c89d8b

Please sign in to comment.