From a2cac6f0bb85d698247ac4645b99c760c55cbabf Mon Sep 17 00:00:00 2001 From: Marc Glasser Date: Wed, 16 Jun 2021 07:56:34 -1000 Subject: [PATCH] add check for isUsingExpensifyCard --- src/libs/API.js | 8 ++++++++ src/libs/Navigation/AppNavigator/AuthScreens.js | 2 +- src/libs/actions/User.js | 17 ++++++++++++++--- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/libs/API.js b/src/libs/API.js index 4a7e93120196..47bab64b22e7 100644 --- a/src/libs/API.js +++ b/src/libs/API.js @@ -929,6 +929,13 @@ function GetCurrencyList() { return Mobile_GetConstants({data: ['currencyList']}); } +/** + * @returns {Promise} + */ +function User_IsUsingExpensifyCard() { + return Network.post('User_IsUsingExpensifyCard', {}); +} + export { Authenticate, BankAccount_Create, @@ -967,6 +974,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 dd51541077d5..428fbd4116d0 100644 --- a/src/libs/Navigation/AppNavigator/AuthScreens.js +++ b/src/libs/Navigation/AppNavigator/AuthScreens.js @@ -123,7 +123,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 c43701d37c30..68b36ee4e4ac 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, };