Skip to content

Commit 8b4839f

Browse files
Use longest-prefix match in getCardFeedColors
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>
1 parent 078bb24 commit 8b4839f

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

src/libs/CardArtworkColors.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ import colors from '@styles/theme/colors';
1818
* <path>, and read its fill — either the inline fill="..." attribute or the CSS class.
1919
*
2020
* Keys are the runtime string values of CONST.COMPANY_CARD.FEED_BANK_NAME and
21-
* CONST.EXPENSIFY_CARD.BANK. Lookup uses prefix-matching (see getCardFeedColors),
22-
* so partial feed-name suffixes (e.g. "vcf123") still resolve correctly.
21+
* CONST.EXPENSIFY_CARD.BANK. Lookup uses longest-prefix matching (see getCardFeedColors),
22+
* so partial feed-name suffixes (e.g. "vcf123") resolve correctly, and more specific keys
23+
* always take precedence over shorter ones.
2324
*/
2425

2526
type CardArtworkColors = {background: string; text: string};

src/libs/CardUtils.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ function getCardFeedColors(cardFeed: string | undefined): {background: string; t
6060
if (!cardFeed) {
6161
return GENERIC_CARD_COLORS;
6262
}
63-
const feedKey = Object.keys(CARD_FEED_COLORS).find((key) => cardFeed.startsWith(key));
63+
const feedKey = Object.keys(CARD_FEED_COLORS)
64+
.sort((a, b) => b.length - a.length)
65+
.find((key) => cardFeed.startsWith(key));
6466
return feedKey !== undefined ? CARD_FEED_COLORS[feedKey] : GENERIC_CARD_COLORS;
6567
}
6668

0 commit comments

Comments
 (0)