diff --git a/src/libs/API.js b/src/libs/API.js index f4b7feace7a5..1a9cfeebd7b1 100644 --- a/src/libs/API.js +++ b/src/libs/API.js @@ -935,6 +935,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] @@ -1001,6 +1008,7 @@ export { User_SignUp, User_GetBetas, User_IsFromPublicDomain, + User_IsUsingExpensifyCard, User_ReopenAccount, User_SecondaryLogin_Send, User_UploadAvatar, diff --git a/src/libs/Navigation/AppNavigator/AuthScreens.js b/src/libs/Navigation/AppNavigator/AuthScreens.js index a9bee4541796..0eccf8732a96 100644 --- a/src/libs/Navigation/AppNavigator/AuthScreens.js +++ b/src/libs/Navigation/AppNavigator/AuthScreens.js @@ -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(); diff --git a/src/libs/actions/User.js b/src/libs/actions/User.js index e3788fe46613..afba94f91361 100644 --- a/src/libs/actions/User.js +++ b/src/libs/actions/User.js @@ -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; @@ -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); } }); } @@ -214,5 +225,5 @@ export { setExpensifyNewsStatus, setSecondaryLogin, validateLogin, - getPublicDomainInfo, + getDomainInfo, };