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
16 changes: 15 additions & 1 deletion src/libs/CardUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import type {
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import type IconAsset from '@src/types/utils/IconAsset';
import {isBankAccountPartiallySetup} from './BankAccountUtils';
import DateUtils from './DateUtils';
import {filterObject} from './ObjectUtils';
import {arePersonalDetailsMissing, getDisplayNameOrDefault} from './PersonalDetailsUtils';
import StringUtils from './StringUtils';
Expand Down Expand Up @@ -1314,6 +1315,17 @@ function generateCardID(): number {
return Math.floor(Math.random() * 2 ** 21) * 2 ** 32 + Math.floor(Math.random() * 2 ** 32);
}

/**
* Check if the card has expired
*/
function isExpiredCard(card: Card): boolean {
if (!card.nameValuePairs?.validThru) {
return false;
}
const currentTime = DateUtils.getDBTime();
Copy link
Contributor

Choose a reason for hiding this comment

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

validThru is stored as YYYY-MM-DD format, while getDBTime() returns YYYY-MM-DD HH:mm:ss format (e.g., 2026-02-25 14:30:00). so a card with validThru: "2026-02-25" would be considered expired at any point on 2026-02-25 itself, even at midnight. For card expiration, typically a card should be valid through the entire day of its validThru date. The comparison should be date-to-date, not date-to-datetime. cc @lakchote

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dukenv0307 validThru is stored with YYYY-MM-DD HH:mm:ss format

Screenshot 2026-03-12 at 11 44 45

Copy link
Contributor

Choose a reason for hiding this comment

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

return card.nameValuePairs.validThru < currentTime;
}

/**
* Check if there are any assigned cards that should be displayed in the wallet page.
* This includes active Expensify cards, company cards (domain), and personal cards.
Expand All @@ -1327,7 +1339,8 @@ function hasDisplayableAssignedCards(cardList: CardList | undefined): boolean {
(card) =>
CONST.EXPENSIFY_CARD.ACTIVE_STATES.includes(card.state ?? 0) &&
(isExpensifyCard(card) || !!card.domainName || isPersonalCard(card)) &&
card.cardName !== CONST.COMPANY_CARDS.CARD_NAME.CASH,
card.cardName !== CONST.COMPANY_CARDS.CARD_NAME.CASH &&
(!isExpensifyCard(card) || !isExpiredCard(card)),
);
}

Expand Down Expand Up @@ -1482,6 +1495,7 @@ export {
isCardFrozen,
isCardWithPotentialFraud,
getDisplayableExpensifyCards,
isExpiredCard,
};

export type {CompanyCardFeedIcons, CompanyCardBankIcons};
4 changes: 3 additions & 1 deletion src/pages/settings/Wallet/PaymentMethodList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
isCardFrozen,
isExpensifyCard,
isExpensifyCardPendingAction,
isExpiredCard,
isPersonalCard,
lastFourNumbersFromCardName,
maskCardNumber,
Expand Down Expand Up @@ -214,7 +215,8 @@ function PaymentMethodList({
(card) =>
CONST.EXPENSIFY_CARD.ACTIVE_STATES.includes(card.state ?? 0) &&
(isExpensifyCard(card) || !!card.domainName || isPersonalCard(card)) &&
card.cardName !== CONST.COMPANY_CARDS.CARD_NAME.CASH,
card.cardName !== CONST.COMPANY_CARDS.CARD_NAME.CASH &&
(!isExpensifyCard(card) || !isExpiredCard(card)),
);

const assignedCardsSorted = lodashSortBy(assignedCards, getAssignedCardSortKey);
Expand Down
29 changes: 29 additions & 0 deletions tests/unit/CardUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import {
isDirectFeed as isDirectFeedCardUtils,
isExpensifyCard,
isExpensifyCardFullySetUp,
isExpiredCard,
isMatchingCard,
isPersonalCard,
lastFourNumbersFromCardName,
Expand All @@ -63,6 +64,7 @@ import {
splitCardFeedWithDomainID,
splitMaskedCardNumber,
} from '@src/libs/CardUtils';
import DateUtils from '@src/libs/DateUtils';
import type {
BankAccountList,
Card,
Expand Down Expand Up @@ -3503,6 +3505,33 @@ describe('CardUtils', () => {
});
});

describe('isExpiredCard', () => {
afterEach(() => {
jest.restoreAllMocks();
});

it('returns false when validThru is missing', () => {
jest.spyOn(DateUtils, 'getDBTime').mockReturnValue('2026-02-25 00:00:00');
expect(isExpiredCard({} as Card)).toBe(false);
expect(isExpiredCard({nameValuePairs: {}} as Card)).toBe(false);
});

it('returns true when validThru is before current time (UTC)', () => {
jest.spyOn(DateUtils, 'getDBTime').mockReturnValue('2026-02-25 00:00:00');
expect(isExpiredCard({nameValuePairs: {validThru: '2026-02-24 23:59:59'}} as Card)).toBe(true);
});

it('returns false when validThru equals current time', () => {
jest.spyOn(DateUtils, 'getDBTime').mockReturnValue('2026-02-25 00:00:00');
expect(isExpiredCard({nameValuePairs: {validThru: '2026-02-25 00:00:00'}} as Card)).toBe(false);
});

it('returns false when validThru is after current time', () => {
jest.spyOn(DateUtils, 'getDBTime').mockReturnValue('2026-02-25 00:00:00');
expect(isExpiredCard({nameValuePairs: {validThru: '2026-02-25 00:00:01'}} as Card)).toBe(false);
});
});

describe('getFeedConnectionBrokenCard', () => {
it('Should return undefined when feedCards is undefined', () => {
expect(getFeedConnectionBrokenCard(undefined)).toBeUndefined();
Expand Down
Loading