Skip to content
1 change: 1 addition & 0 deletions src/languages/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2768,6 +2768,7 @@ const translations: TranslationDeepObject<typeof en> = {
fixConnectionIn: (companyCardsRoute: string) => `Bitte beheben Sie diese Verbindung in <a href="${companyCardsRoute}">Firmenkarten</a>`,
askAdminToFixConnection: 'Bitte bitten Sie eine(n) Admin, diese Verbindung zu reparieren',
reconnectBank: 'Ihre Bankverbindung muss erneut authentifiziert werden',
pending: 'Ausstehend',
},
bankAccountStatus: {
active: 'Aktiv',
Expand Down
1 change: 1 addition & 0 deletions src/languages/el.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2826,6 +2826,7 @@ const translations: TranslationDeepObject<typeof en> = {
fixConnectionIn: (companyCardsRoute: string) => `Παρακαλούμε διορθώστε αυτήν τη σύνδεση στις <a href="${companyCardsRoute}">εταιρικές κάρτες</a>`,
askAdminToFixConnection: 'Παρακαλούμε ζητήστε από έναν διαχειριστή να διορθώσει αυτήν τη σύνδεση',
reconnectBank: 'Η σύνδεσή σας με την τράπεζα χρειάζεται επαναπιστοποίηση',
pending: 'Σε εκκρεμότητα',
},
bankAccountStatus: {
active: 'Ενεργό',
Expand Down
1 change: 1 addition & 0 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2840,6 +2840,7 @@ const translations = {
cardStatus: {
active: 'Active',
inactive: 'Inactive',
pending: 'Pending',
fixConnection: 'Please fix this connection',
fixConnectionIn: (companyCardsRoute: string) => `Please fix this connection in <a href="${companyCardsRoute}">company cards</a>`,
askAdminToFixConnection: 'Please ask an admin to fix this connection',
Expand Down
1 change: 1 addition & 0 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2688,6 +2688,7 @@ const translations: TranslationDeepObject<typeof en> = {
fixConnectionIn: (companyCardsRoute) => `Por favor, corrige esta conexión en <a href="${companyCardsRoute}">tarjetas de la empresa</a>`,
askAdminToFixConnection: 'Pídele a un administrador que solucione esta conexión',
reconnectBank: 'Tu conexión bancaria necesita volver a autenticarse',
pending: 'Pendiente',
},
bankAccountStatus: {
active: 'Activo',
Expand Down
1 change: 1 addition & 0 deletions src/languages/fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2774,6 +2774,7 @@ const translations: TranslationDeepObject<typeof en> = {
fixConnectionIn: (companyCardsRoute: string) => `Veuillez corriger cette connexion dans <a href="${companyCardsRoute}">cartes d’entreprise</a>`,
askAdminToFixConnection: 'Veuillez demander à un administrateur de corriger cette connexion',
reconnectBank: 'Votre connexion bancaire doit être réauthentifiée',
pending: 'En attente',
},
bankAccountStatus: {
active: 'Actif',
Expand Down
1 change: 1 addition & 0 deletions src/languages/it.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2758,6 +2758,7 @@ const translations: TranslationDeepObject<typeof en> = {
fixConnectionIn: (companyCardsRoute: string) => `Correggi questa connessione in <a href="${companyCardsRoute}">carte aziendali</a>`,
askAdminToFixConnection: 'Chiedi a un amministratore di correggere questa connessione',
reconnectBank: 'La connessione con la tua banca deve essere nuovamente autenticata',
pending: 'In sospeso',
},
bankAccountStatus: {
active: 'Attiva',
Expand Down
1 change: 1 addition & 0 deletions src/languages/ja.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2736,6 +2736,7 @@ const translations: TranslationDeepObject<typeof en> = {
fixConnectionIn: (companyCardsRoute: string) => `この接続を<a href="${companyCardsRoute}">会社カード</a>で修正してください`,
askAdminToFixConnection: '管理者にこの接続の修正を依頼してください',
reconnectBank: '銀行連携の再認証が必要です',
pending: '保留中',
},
bankAccountStatus: {
active: 'アクティブ',
Expand Down
1 change: 1 addition & 0 deletions src/languages/nl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2761,6 +2761,7 @@ const translations: TranslationDeepObject<typeof en> = {
fixConnectionIn: (companyCardsRoute: string) => `Repareer deze verbinding in <a href="${companyCardsRoute}">bedrijfskaarten</a>`,
askAdminToFixConnection: 'Vraag een/beheerder om deze verbinding te herstellen',
reconnectBank: 'Je bankverbinding moet opnieuw worden geverifieerd',
pending: 'In behandeling',
},
bankAccountStatus: {
active: 'Actief',
Expand Down
1 change: 1 addition & 0 deletions src/languages/pl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2795,6 +2795,7 @@ const translations: TranslationDeepObject<typeof en> = {
fixConnectionIn: (companyCardsRoute: string) => `Napraw to połączenie w <a href="${companyCardsRoute}">firmowe karty</a>`,
askAdminToFixConnection: 'Poproś administratora o naprawienie tego połączenia',
reconnectBank: 'Twoje połączenie z bankiem wymaga ponownego uwierzytelnienia',
pending: 'Oczekujące',
},
bankAccountStatus: {
active: 'Aktywne',
Expand Down
1 change: 1 addition & 0 deletions src/languages/pt-BR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2753,6 +2753,7 @@ const translations: TranslationDeepObject<typeof en> = {
fixConnectionIn: (companyCardsRoute: string) => `Corrija esta conexão em <a href="${companyCardsRoute}">cartões corporativos</a>`,
askAdminToFixConnection: 'Peça para um administrador corrigir essa conexão',
reconnectBank: 'Sua conexão bancária precisa ser autenticada novamente',
pending: 'Pendente',
},
bankAccountStatus: {
active: 'Ativo',
Expand Down
1 change: 1 addition & 0 deletions src/languages/zh-hans.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2663,6 +2663,7 @@ const translations: TranslationDeepObject<typeof en> = {
fixConnectionIn: (companyCardsRoute: string) => `请在<a href="${companyCardsRoute}">公司卡</a>中修复此连接`,
askAdminToFixConnection: '请联系管理员修复此连接',
reconnectBank: '您的银行连接需要重新验证',
pending: '待处理',
},
bankAccountStatus: {
active: '活跃',
Expand Down
36 changes: 30 additions & 6 deletions src/libs/CardUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ type CardConnectionStatusDisplayParams = {
isCardBroken: boolean;
shouldShowRBR: boolean;
isCardInactive: boolean;
isCardPending: boolean;
isExpensifyCard: boolean;
isPersonalCard: boolean;
isAdminForCardPolicy: boolean;
Expand Down Expand Up @@ -1439,6 +1440,7 @@ function getCardConnectionStatusDisplay({
isCardBroken,
shouldShowRBR,
isCardInactive: isCardInactiveStatus,
isCardPending: isCardPendingStatus,
isExpensifyCard: isExpensifyCardStatus,
isPersonalCard: isPersonalCardStatus,
isAdminForCardPolicy,
Expand All @@ -1454,10 +1456,15 @@ function getCardConnectionStatusDisplay({
// is right for it in any state. It still reports its status so the row keeps the background, hover and press
// styling every other row in the list gets, which hangs off the status being present rather than the message.
if (isExpensifyCardStatus) {
return {
statusKey: isCardInactiveStatus ? 'walletPage.cardStatus.inactive' : 'walletPage.cardStatus.active',
statusTone: isCardInactiveStatus ? 'default' : 'success',
};
if (isCardInactiveStatus) {
return {statusKey: 'walletPage.cardStatus.inactive', statusTone: 'default'};
}
// A card waiting to be issued or activated cannot be spent on yet. It shares the tone with a pending bank
// account, so the wallet reads the same way whichever kind of row the status is on.
if (isCardPendingStatus) {
return {statusKey: 'walletPage.cardStatus.pending', statusTone: 'danger'};
}
return {statusKey: 'walletPage.cardStatus.active', statusTone: 'success'};
}

const shouldShowMessage = isCardBroken || shouldShowRBR || isCardInactiveStatus;
Expand Down Expand Up @@ -1724,6 +1731,22 @@ function isCardPendingActivate(card?: Card) {
return card?.state === CONST.EXPENSIFY_CARD.STATE.NOT_ACTIVATED;
}

/** The two states a card passes through before it can be spent on, whether or not the cardholder can act on them. */
function isCardPendingIssueOrActivation(card?: Card) {
return isCardPendingIssue(card) || isCardPendingActivate(card);
}

/**
* True when an Expensify Card is waiting to be issued or activated and so cannot be spent on yet.
*
* Those two states describe a physical card on its way to the cardholder. A virtual card is issued and spendable as
* soon as it is assigned and has no activation step, so it is never waiting on either, which is why
* `isExpensifyCardPendingAction` leaves virtual cards out as well.
*/
function isExpensifyCardPending(card?: Card) {
return card?.bank === CONST.EXPENSIFY_CARD.BANK && !card.nameValuePairs?.isVirtual && isCardPendingIssueOrActivation(card);
}

/** True when this card has a wallet addition waiting for the cardholder to confirm or deny. */
function isCardPendingDigitalWalletApproval(card?: Card) {
return !!card?.nameValuePairs?.pendingDigitalWalletApproval;
Expand Down Expand Up @@ -1772,7 +1795,7 @@ function isCardWithPotentialFraud(card: Card): boolean {

function isCardPendingReplace(card?: Card) {
return (
(isCardPendingActivate(card) || isCardPendingIssue(card)) &&
isCardPendingIssueOrActivation(card) &&
!!card?.nameValuePairs?.terminationReason &&
card?.nameValuePairs?.statusChanges?.at(-1)?.status === CONST.EXPENSIFY_CARD.STATE.STATE_DEACTIVATED
);
Expand All @@ -1795,7 +1818,7 @@ function isExpensifyCardPendingAction(card?: Card, privatePersonalDetails?: Priv
return (
card?.bank === CONST.EXPENSIFY_CARD.BANK &&
!card.nameValuePairs?.isVirtual &&
(isCardPendingIssue(card) || isCardPendingActivate(card) || isCardPendingReplace(card) || arePersonalDetailsMissing(privatePersonalDetails)) &&
(isCardPendingIssueOrActivation(card) || isCardPendingReplace(card) || arePersonalDetailsMissing(privatePersonalDetails)) &&
(!card.lastScrapeResult || CONST.COMPANY_CARDS.BROKEN_CONNECTION_IGNORED_STATUSES.includes(card.lastScrapeResult))
);
}
Expand Down Expand Up @@ -2318,6 +2341,7 @@ export {
getPersonalBankCardDetailsImage,
isCardPendingIssue,
isCardPendingActivate,
isExpensifyCardPending,
isCardPendingDigitalWalletApproval,
isActiveExpensifyCard,
hasActiveExpensifyCard,
Expand Down
2 changes: 2 additions & 0 deletions src/pages/settings/Wallet/PaymentMethodList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
isCardInactive,
isCardPendingDigitalWalletApproval,
isExpensifyCard,
isExpensifyCardPending,
isExpensifyCardPendingAction,
isExpiredCard,
isLastScrapePastDismissThreshold,
Expand Down Expand Up @@ -322,6 +323,7 @@ function PaymentMethodList({
isCardBroken,
shouldShowRBR,
isCardInactive: isCardInactiveState,
isCardPending: isExpensifyCardPending(card),
isExpensifyCard: isUserExpensifyCard,
isPersonalCard: isUserPersonalCard,
isAdminForCardPolicy,
Expand Down
60 changes: 60 additions & 0 deletions tests/unit/CardUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ import {
isCardPendingDigitalWalletApproval,
isExpensifyCard,
isExpensifyCardFullySetUp,
isExpensifyCardPending,
isExpiredCard,
isMatchingCard,
isPersonalCard,
Expand Down Expand Up @@ -4886,6 +4887,7 @@ describe('getCardConnectionStatusDisplay', () => {
isCardBroken: false,
shouldShowRBR: false,
isCardInactive: false,
isCardPending: false,
isExpensifyCard: false,
isPersonalCard: false,
isAdminForCardPolicy: false,
Expand Down Expand Up @@ -4971,6 +4973,29 @@ describe('getCardConnectionStatusDisplay', () => {
});
});

// A card waiting to be issued or activated is not spendable yet, so it reads neither Active nor Inactive.
it('reports a pending status for an Expensify Card waiting to be issued or activated', () => {
expect(getCardConnectionStatusDisplay({...defaultParams, isExpensifyCard: true, isCardPending: true})).toEqual({
statusKey: 'walletPage.cardStatus.pending',
statusTone: 'danger',
});
});

// Suspended outranks pending, so a card the back end turned off never reads as merely waiting.
it('keeps an inactive Expensify Card inactive even while it is pending', () => {
expect(getCardConnectionStatusDisplay({...defaultParams, isExpensifyCard: true, isCardPending: true, isCardInactive: true})).toEqual({
statusKey: 'walletPage.cardStatus.inactive',
statusTone: 'default',
});
});

it('leaves a non-pending Expensify Card active', () => {
expect(getCardConnectionStatusDisplay({...defaultParams, isExpensifyCard: true})).toEqual({
statusKey: 'walletPage.cardStatus.active',
statusTone: 'success',
});
});

it('does not show a company-cards link without a policy ID', () => {
expect(getCardConnectionStatusDisplay({...defaultParams, shouldShowRBR: true, isAdminForCardPolicy: true})).toEqual({
statusKey: 'walletPage.cardStatus.inactive',
Expand Down Expand Up @@ -5124,6 +5149,41 @@ describe('isCardPendingDigitalWalletApproval', () => {
});
});

describe('isExpensifyCardPending', () => {
it('is true for a card waiting to be issued', () => {
expect(isExpensifyCardPending(createRandomExpensifyCard(1, {state: CONST.EXPENSIFY_CARD.STATE.STATE_NOT_ISSUED}))).toBe(true);
});

it('is true for a card waiting to be activated', () => {
expect(isExpensifyCardPending(createRandomExpensifyCard(1, {state: CONST.EXPENSIFY_CARD.STATE.NOT_ACTIVATED}))).toBe(true);
});

// Those two states describe a physical card on its way to the cardholder. A virtual card is spendable as soon as
// it is assigned, so reading it as pending would tell the cardholder to wait for something that never arrives.
it('is false for a virtual card in either of those states', () => {
const card: Card = {
...createRandomExpensifyCard(1, {state: CONST.EXPENSIFY_CARD.STATE.NOT_ACTIVATED}),
nameValuePairs: createMock<Card['nameValuePairs']>({isVirtual: true}),
};
expect(isExpensifyCardPending(card)).toBe(false);
});

// A company card's states mean something else entirely, so the Expensify Card states must not be read off one.
it('is false for a company card in one of those states', () => {
const companyCard: Card = {...createRandomCompanyCard(1), state: CONST.EXPENSIFY_CARD.STATE.NOT_ACTIVATED};

expect(isExpensifyCardPending(companyCard)).toBe(false);
});

it('is false for a card that has been issued and activated', () => {
expect(isExpensifyCardPending(createRandomExpensifyCard(1, {state: CONST.EXPENSIFY_CARD.STATE.OPEN}))).toBe(false);
});

it('is false when there is no card', () => {
expect(isExpensifyCardPending(undefined)).toBe(false);
});
});

describe('hasActiveExpensifyCard', () => {
it('is true when the user holds an active Expensify Card', () => {
const cardList: CardList = {'1': createRandomExpensifyCard(1, {state: CONST.EXPENSIFY_CARD.STATE.OPEN})};
Expand Down
Loading