Skip to content

Fix cardholder name contrast on Expensify and company card images#91234

Open
roryabraham wants to merge 21 commits into
mainfrom
fix-card-holder-name-contrast-91137-91139
Open

Fix cardholder name contrast on Expensify and company card images#91234
roryabraham wants to merge 21 commits into
mainfrom
fix-card-holder-name-contrast-91137-91139

Conversation

@roryabraham
Copy link
Copy Markdown
Contributor

@roryabraham roryabraham commented May 20, 2026

Explanation of Change

Cardholder names on card images used theme.textLight to determine text color. This breaks in two ways:

  1. Expensify Card - User name is not visible on the card image in high contrast mode #91137 — High contrast mode flips textLight to dark (#002E22). The Expensify Card has a dark green (#002e22) background, so the name becomes invisible — same color as the card.
  2. Company cards - User name is white on white card image #91139 — In normal light mode, textLight is white (#FFFFFF). Company cards on light feeds (e.g. Plaid, which has a white card face) render invisible white text on a white background.

Fix: compute text color from the card's actual SVG background using WCAG 2.1 relative luminance. Card artwork never changes with the app theme, so theme.textLight is semantically wrong here.

New file src/styles/utils/card.ts:

  • getRelativeLuminance(hex) — WCAG 2.1 formula
  • getCardHolderTextColor(bgHex) — returns colors.white or colors.productLight900 based on WCAG crossover luminance (0.179)
  • getCardFeedBackgroundColor(feedName) — background hex for every known card SVG, derived directly from the SVG artwork

walletCardHolder loses its color property; each callsite passes a computed {color} override.

Fixed Issues

$ #91137
$ #91139

Tests

Setup — inject a mock Expensify Card via the browser console (only needed if you don't have a real card assigned; skip if you already have one in your wallet):

  1. Sign in at https://dev.new.expensify.com:8082/
  2. Open DevTools → Console and run:
// Inject personal details so the cardholder name renders
await window.Onyx.merge('personalDetailsList', {
  '728': { accountID: <your_account_id>, login: '<your_login>', displayName: 'First Last', firstName: 'First', lastName: 'Last' }
});
await window.Onyx.merge('privatePersonalDetails', { legalFirstName: 'First', legalLastName: 'Last' });

// Inject a fake Expensify Card into the card list
await window.Onyx.merge('cardList', {
  '88001': {
    cardID: 88001,
    bank: 'Expensify Card',
    cardName: 'Test Card Virtual',
    lastFourPAN: '4242',
    accountID: <your_account_id>,
    isVirtual: true,
    nameValuePairs: { isVirtual: true, issuedBy: '<your_login>', cardTitle: 'Test Virtual' },
    limit: 100000,
    availableSpend: 100000,
    fundID: '999',
    domainName: '<your_domain>',
  }
});

Reproduce #91137 (Expensify Card, high contrast mode):

  1. Navigate to Account > Preferences > Theme, enable High contrast mode
  2. Navigate to /settings/wallet/card
  3. Before fix: the cardholder name on the dark green card is invisible (dark text #002E22 on dark green #002e22 background)
  4. After fix: the cardholder name is white and clearly visible

Reproduce #91139 (company card with light background, normal mode):

  1. Disable high contrast mode
  2. On staging with a Plaid-connected company card (white card face), open Workspace > Company Cards > the assigned card
  3. Before fix: cardholder name is invisible (white text on white card)
  4. After fix: cardholder name is dark and clearly visible
  • Verify that no errors appear in the JS console

Offline tests

N/A — display-only style change, no API calls involved.

QA Steps

Retest the linked issues:

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I verified there are no new alerts related to the canBeMissing param for useOnyx
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
      • If any non-english text was added/modified, I used JaimeGPT to get English > Spanish translation. I then posted it in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.ts or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

MacOS: Chrome fix-91137-white-text-on-dark-card-high-contrast fix-91139-dark-text-on-white-card-normal-mode

Use fixed overlay colors for card art instead of theme.textLight so
names stay visible in high contrast and on light company card feeds.

Co-authored-by: Cursor <cursoragent@cursor.com>
Use WCAG luminance to select text color based on the card's actual
background color. Card artwork never changes with app theme, so
theme.textLight is wrong — it flips to dark in high-contrast mode,
making text invisible on dark-background cards (#91137). Plaid and
generic company cards have light backgrounds where the default white
text is also invisible (#91139).

New utilities in CardUtils:
- getRelativeLuminance: WCAG 2.1 relative luminance from hex color
- getCardHolderTextColor: returns colors.white or colors.productLight900
  based on WCAG crossover luminance (0.179)
- getCardFeedBackgroundColor: background hex for each known card feed
  from the SVG artwork

walletCardHolder loses its color property; each callsite passes a
computed {color} style override so Expensify Card pages always get
white text and company card pages get a color appropriate to their
feed's card art.

Co-authored-by: Cursor <cursoragent@cursor.com>
@codecov
Copy link
Copy Markdown

codecov Bot commented May 20, 2026

Codecov Report

❌ Looks like you've decreased code coverage for some files. Please write tests to increase, or at least maintain, the existing level of code coverage. See our documentation here for how to interpret this table.

Files with missing lines Coverage Δ
src/components/CardPreview.tsx 100.00% <100.00%> (ø)
src/libs/CardArtworkColors.ts 100.00% <100.00%> (ø)
src/styles/index.ts 57.51% <ø> (ø)
...e/companyCards/WorkspaceCompanyCardDetailsPage.tsx 0.00% <0.00%> (ø)
...xpensifyCard/WorkspaceExpensifyCardDetailsPage.tsx 0.00% <0.00%> (ø)
src/libs/CardUtils.ts 82.20% <72.72%> (-0.14%) ⬇️
... and 28 files with indirect coverage changes

roryabraham and others added 10 commits May 20, 2026 14:18
Co-authored-by: Cursor <cursoragent@cursor.com>
Move getCardFeedBackgroundColor and getCardHolderTextColor from
@styles/utils/card into @libs/CardUtils (which already had the unused
colors import ready for them), and update all import sites to use
@libs/CardUtils instead. Delete the now-empty @styles/utils/card module.

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Replaces the hardcoded CARD_FEED_BACKGROUND_COLORS in CardUtils.ts with a
dedicated CardArtworkColors.ts file. Each entry is annotated with the SVG file
it was sourced from, making the color-artwork relationship explicit rather than
implicit. Renames CardUtils/index.ts back to CardUtils.ts since there is no
longer a subdirectory needed.

Adds a drift-detection describe block to CardUtilsTest.ts that parses each
card SVG at test time and asserts that the committed constants match. If someone
updates card artwork without updating CardArtworkColors.ts, CI will fail with a
clear message pointing to the affected entry.

Co-authored-by: Cursor <cursoragent@cursor.com>
…rgo to cspell

Co-authored-by: Cursor <cursoragent@cursor.com>
@OSBotify

This comment has been minimized.

@OSBotify
Copy link
Copy Markdown
Contributor

A preview of your ExpensifyHelp changes have been deployed to https://a217d755.helpdot.pages.dev ⚡️

roryabraham and others added 4 commits May 21, 2026 13:23
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@roryabraham roryabraham marked this pull request as ready for review May 21, 2026 21:47
@roryabraham roryabraham requested review from a team as code owners May 21, 2026 21:47
@melvin-bot melvin-bot Bot requested review from joekaufmanexpensify and mananjadhav and removed request for a team May 21, 2026 21:47
@melvin-bot
Copy link
Copy Markdown

melvin-bot Bot commented May 21, 2026

@mananjadhav Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@melvin-bot melvin-bot Bot requested review from a team and removed request for a team May 21, 2026 21:47
@melvin-bot melvin-bot Bot requested review from ZhenjaHorbach and removed request for a team May 21, 2026 21:47
@melvin-bot
Copy link
Copy Markdown

melvin-bot Bot commented May 21, 2026

@ZhenjaHorbach Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

chatgpt-codex-connector[bot]

This comment was marked as resolved.

roryabraham and others added 2 commits May 21, 2026 15:29
The previous threshold (0.179) is the crossover for pure black vs white.
Our dark text is colors.productLight900 (#002E22, L≈0.021), not black, so
the true crossover is higher (~0.222). This caused mid-luminance backgrounds
like Citibank (#0281c4, L≈0.197) to get dark text even though white gives
better contrast (4.25:1 vs 3.49:1).

Replace the magic constant with a derived value computed from the actual
dark color's luminance using the WCAG crossover formula, so the threshold
stays correct if the design token changes.

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@shawnborton
Copy link
Copy Markdown
Contributor

The video seems good to me. I am no engineer, but candidly the solution feels over-engineered. I thought for the white background cards, we're simply using our text-dark color (from light mode). And for the cards that have a BG, we're simply using white for the text?

@dannymcclain
Copy link
Copy Markdown
Contributor

Also not an engineer but I kinda feel the same as Shawn. The screenshots look good though 🤷‍♂️

@roryabraham roryabraham changed the title Fix cardholder name contrast on Expensify and company card images [HOLD] Fix cardholder name contrast on Expensify and company card images May 22, 2026
Removes ColorUtils.ts and all runtime WCAG luminance calculations.
CardArtworkColors.ts now exports CARD_FEED_COLORS — a single map of
feed key → {background, text} — where the text color is expressed
directly alongside the background color it was chosen to contrast with.

CardUtils exposes getCardFeedTextColor() and the existing
getCardFeedBackgroundColor() both delegate to a shared getCardFeedColors()
lookup, so call sites that only need the text color no longer need to
call two functions.

Co-authored-by: Cursor <cursoragent@cursor.com>
@roryabraham
Copy link
Copy Markdown
Contributor Author

roryabraham commented May 22, 2026

I thought for the white background cards, we're simply using our text-dark color (from light mode). And for the cards that have a BG, we're simply using white for the text?

That is effectively what we do here - look at the color of the card, and choose the light or dark text color from our theme based on whichever results in higher contrast. However, when I started this implementation I assumed we could read the color directly from the SVG at runtime, so adding more colors would "just work". However, it turns out that by the time we reach runtime, the SVG is gone. And React Native doesn't yet support the window.getComputedStyle API to observe the card background color directly. So we ended up with a hardcoded list of card colors anyways, so we can just hardcode the text color as well.

@roryabraham roryabraham changed the title [HOLD] Fix cardholder name contrast on Expensify and company card images Fix cardholder name contrast on Expensify and company card images May 22, 2026
Copy link
Copy Markdown
Contributor

@joekaufmanexpensify joekaufmanexpensify left a comment

Choose a reason for hiding this comment

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

Good for product

@shawnborton
Copy link
Copy Markdown
Contributor

Cool, that works for me. The simpler the better IMO!

Comment thread src/libs/CardUtils.ts Outdated
if (!cardFeed) {
return GENERIC_CARD_COLORS;
}
const feedKey = Object.keys(CARD_FEED_COLORS).find((key) => cardFeed.startsWith(key));
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I am not sure if it's a problem today, but in this scenario shorter key would match first. For example vcf and vcf.test, etc. Would that be aproblem?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

updated to sort by longest first

Copy link
Copy Markdown
Collaborator

@mananjadhav mananjadhav left a comment

Choose a reason for hiding this comment

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

Overall looks good. Left one comment.

Sorts keys by length descending before prefix-matching so that more
specific keys (e.g. vcf.something) always win over shorter ones
(e.g. vcf), regardless of insertion order in CARD_FEED_COLORS.

Co-authored-by: Cursor <cursoragent@cursor.com>
@mananjadhav
Copy link
Copy Markdown
Collaborator

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
  • I checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified that the composer does not automatically focus or open the keyboard on mobile unless explicitly intended. This includes checking that returning the app from the background does not unexpectedly open the keyboard.
  • I verified tests pass on all platforms & I tested again on:
    • Android: HybridApp
    • Android: mWeb Chrome
    • iOS: HybridApp
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified proper code patterns were followed (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick).
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.ts or at the top of the file that uses the constant) are defined as such
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • For any bug fix or new feature in this PR, I verified that sufficient unit tests are included to prevent regressions in this flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Android: HybridApp android-card-holder-name
Android: mWeb Chrome mweb-chrome-card-holder-name
iOS: HybridApp ios-card-holder-name
iOS: mWeb Safari mweb-safari-card-holder-name
MacOS: Chrome / Safari
web-card-holder-name.mov

Copy link
Copy Markdown
Collaborator

@mananjadhav mananjadhav left a comment

Choose a reason for hiding this comment

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

@roryabraham Can you please resolve the conflicts?

@melvin-bot melvin-bot Bot requested a review from youssef-lr May 26, 2026 19:01
@melvin-bot
Copy link
Copy Markdown

melvin-bot Bot commented May 26, 2026

@youssef-lr Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@roryabraham
Copy link
Copy Markdown
Contributor Author

conflicts resolved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants