Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix card number previews and expiration date format on expensify card page #34677

Merged
merged 3 commits into from
Jan 19, 2024
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
17 changes: 17 additions & 0 deletions src/libs/CardUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,22 @@ function getYearFromExpirationDateString(expirationDateString: string) {
return cardYear.length === 2 ? `20${cardYear}` : cardYear;
}

/**
* @returns string with a month in MM/YYYY format
*/
function formatCardExpiration(expirationDateString: string) {
// already matches MM/YYYY format
const dateFormat = /^\d{2}\/\d{4}$/;
if (dateFormat.test(expirationDateString)) {
return expirationDateString;
}

const expirationMonth = getMonthFromExpirationDateString(expirationDateString);
const expirationYear = getYearFromExpirationDateString(expirationDateString);

return `${expirationMonth}/${expirationYear}`;
}

/**
* @param cardList - collection of assigned cards
* @returns collection of assigned cards grouped by domain
Expand Down Expand Up @@ -120,6 +136,7 @@ export {
isExpensifyCard,
isCorporateCard,
getDomainCards,
formatCardExpiration,
getMonthFromExpirationDateString,
getYearFromExpirationDateString,
maskCard,
Expand Down
6 changes: 3 additions & 3 deletions src/pages/settings/Wallet/ExpensifyCardPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ function ExpensifyCardPage({
{details.pan ? (
<CardDetails
pan={details.pan}
expiration={details.expiration}
expiration={CardUtils.formatCardExpiration(details.expiration)}
cvv={details.cvv}
privatePersonalDetails={{address: details.address}}
domain={domain}
Expand All @@ -235,7 +235,7 @@ function ExpensifyCardPage({
<>
<MenuItemWithTopDescription
description={translate('cardPage.virtualCardNumber')}
title={CardUtils.maskCard(virtualCard.lastFourPAN)}
title={CardUtils.maskCard('')}
interactive={false}
titleStyle={styles.walletCardNumber}
shouldShowRightComponent
Expand Down Expand Up @@ -271,7 +271,7 @@ function ExpensifyCardPage({
description={translate('cardPage.physicalCardNumber')}
title={CardUtils.maskCard(physicalCard.lastFourPAN)}
interactive={false}
titleStyle={styles.walletCardMenuItem}
titleStyle={styles.walletCardNumber}
/>
<MenuItem
title={translate('reportCardLostOrDamaged.report')}
Expand Down
10 changes: 10 additions & 0 deletions tests/unit/CardUtilsTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,14 @@ describe('CardUtils', () => {
expect(cardUtils.getMonthFromExpirationDateString(shortDate)).toBe(expectedMonth);
expect(cardUtils.getYearFromExpirationDateString(shortDate)).toBe(expectedYear);
});

it('Test MM/YYYY format given MM/YY', () => {
expect(cardUtils.formatCardExpiration(shortDateSlashed)).toBe(longDateSlashed);
expect(cardUtils.formatCardExpiration(shortDateSlashed)).toBe(longDateSlashed);
});

it('Test MM/YYYY format given MMYY', () => {
expect(cardUtils.formatCardExpiration(shortDate)).toBe(longDateSlashed);
expect(cardUtils.formatCardExpiration(shortDate)).toBe(longDateSlashed);
});
});
Loading