Skip to content

Fix duplicate assign card rows for commercial feed cards#83737

Merged
amyevans merged 15 commits intomainfrom
cm-duplicate-assigned-cards
Mar 24, 2026
Merged

Fix duplicate assign card rows for commercial feed cards#83737
amyevans merged 15 commits intomainfrom
cm-duplicate-assigned-cards

Conversation

@carlosmiceli
Copy link
Contributor

@carlosmiceli carlosmiceli commented Feb 27, 2026

Explanation of Change

Fixed Issues

$ https://github.com/Expensify/Expensify/issues/600254
PROPOSAL:

Tests

Before (production):

Image Image

After (this PR):
https://github.com/Expensify/Expensify/issues/600254#issuecomment-4075647842

  • Verify that no errors appear in the JS console

Offline tests

QA Steps

// TODO: These must be filled out, or the issue title must include "[No QA]."

We'll QA this with @joekaufmanexpensify

  • Verify that no errors appear in the JS console

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 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

Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari

@carlosmiceli
Copy link
Contributor Author

@MelvinBot please fix errors and review

MelvinBot and others added 2 commits February 27, 2026 17:47
Co-authored-by: Carlos Miceli <carlosmiceli@users.noreply.github.com>
Co-authored-by: Carlos Miceli <carlosmiceli@users.noreply.github.com>
@MelvinBot
Copy link
Contributor

ESLint Fixes

Pushed two commits to fix the failing ESLint check:

  1. entries[0]entries.at(0) in the test file (prefer-at rule)
  2. lastFourPAN || cardName — kept the || operator with an eslint-disable comment rather than changing to ??. The || behavior is intentional here: when lastFourPAN is an empty string '', it needs to fall through to cardName. Using ?? would preserve the empty string (since '' is not null/undefined), breaking the dedup for old-format cards. This matches the existing pattern on line 150 of the same file.

Code Review

The dedup logic is correct for the primary scenario and handles edge cases well. A few observations:

Looks Good

  • The isLinkedByName enrichment (line 75-77) is necessary for dedup to work — without setting encryptedCardNumber from the matched cardList entry, the coveredEncrypted.has() check couldn't detect duplicates.
  • The otherMatchedCards.length > 0 guard correctly handles ambiguous suffix matches (multiple cardList entries ending in the same digits).
  • 3+ cards resolving to the same entry are handled correctly — only the first is kept.
  • Iteration order doesn't affect correctness since both old-format and new-format cards resolve to the same cardName/encryptedCardNumber values.

Minor Concerns

  1. Else branch coveredNames pollution (line 119-123): When a duplicate is skipped, the code adds the original (un-resolved) card.cardName (e.g. '0487') to coveredNames. If a completely separate unassigned card in cardList or accountList happened to have a normalized name of '0487', it would be incorrectly suppressed from Phase 2. This is unlikely with typical masked card numbers but worth noting.

  2. panSuffix semantic drift (line 62): When lastFourPAN is empty and cardName is a full masked name (e.g. '553312XXXXXX0487'), panSuffix becomes the entire card name, turning the "suffix match" on line 80 into an effective exact match. This doesn't cause bugs currently because isLinkedByName catches this case first, but it's fragile — if normalizeCardName ever strips characters from a cardList key causing the name match to fail, the suffix match would use the full card name instead of the intended last-4-digits.

Neither of these is a blocker — the test coverage confirms the primary scenario works correctly.

@codecov
Copy link

codecov bot commented Feb 27, 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/hooks/useCompanyCards.ts 98.41% <100.00%> (-1.59%) ⬇️
... and 14 files with indirect coverage changes

@carlosmiceli carlosmiceli changed the title Cm duplicate assigned cards Fix duplicate assigned card rows for commercial feed cards Feb 27, 2026
@carlosmiceli
Copy link
Contributor Author

@MelvinBot please increase the code coverage.

@carlosmiceli carlosmiceli added the InternalQA This pull request required internal QA label Feb 27, 2026
@carlosmiceli carlosmiceli marked this pull request as ready for review February 27, 2026 18:02
@carlosmiceli carlosmiceli requested review from a team as code owners February 27, 2026 18:02
@melvin-bot melvin-bot bot requested review from ikevin127 and removed request for a team February 27, 2026 18:02
@melvin-bot
Copy link

melvin-bot bot commented Feb 27, 2026

@ikevin127 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 JmillsExpensify and removed request for a team February 27, 2026 18:02
@carlosmiceli carlosmiceli requested review from a team and fedirjh and removed request for JmillsExpensify and ikevin127 February 27, 2026 18:02
@melvin-bot melvin-bot bot requested review from hoangzinh and removed request for a team February 27, 2026 18:02
@melvin-bot
Copy link

melvin-bot bot commented Feb 27, 2026

@hoangzinh 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 heyjennahay and removed request for a team February 27, 2026 18:03
@carlosmiceli carlosmiceli requested review from joekaufmanexpensify and removed request for heyjennahay March 11, 2026 14:14
@amyevans
Copy link
Contributor

@carlosmiceli can you use https://stackoverflowteams.com/c/expensify/questions/23399 to add screenshots (either redacted, or in the linked E/E issue) of before/after for affected account(s)?

@amyevans
Copy link
Contributor

@codex review

@chatgpt-codex-connector
Copy link

Codex Review: Something went wrong. Try again later by commenting “@codex review”.

Failed to set up container
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@amyevans
Copy link
Contributor

@codex review

@chatgpt-codex-connector
Copy link

Codex Review: Something went wrong. Try again later by commenting “@codex review”.

Failed to set up container
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@carlosmiceli
Copy link
Contributor Author

carlosmiceli commented Mar 12, 2026

@MelvinBot please merge main and fix tests

@carlosmiceli
Copy link
Contributor Author

@codex review

…-cards

Co-authored-by: Carlos Miceli <carlosmiceli@users.noreply.github.com>
@MelvinBot
Copy link
Contributor

Merged main into this branch. There were no conflicts — clean merge. ✅

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a50adf4f7a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +116 to +120
const cardEntryID = encryptedCardNumber ?? normalizedName;

const existingEntry = entriesMap.get(cardEntryID);

const isRicherRecord = card.lastFourPAN && !existingEntry?.assignedCard?.lastFourPAN;

Choose a reason for hiding this comment

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

P1 Badge Preserve distinct assigned cards when suffix matching is ambiguous

When resolveCardListEntry() cannot disambiguate old-format cards (e.g., two cardList names both end with 0487), it returns the original cards without an encrypted ID, and this code then uses the fallback cardName as cardEntryID. If two different assigned cards share that same short name, they collide on the same map key and one row is dropped, so affected workspaces can lose visibility/access to unassign one of the assigned cards.

Useful? React with 👍 / 👎.

Copy link
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. Noting for myself that this is a follow up to #82788 (comment) for when I QA this

@carlosmiceli carlosmiceli changed the title Fix duplicate assigned card rows for commercial feed cards Fix duplicate assign card rows for commercial feed cards Mar 13, 2026
@carlosmiceli
Copy link
Contributor Author

@carlosmiceli can you use https://stackoverflowteams.com/c/expensify/questions/23399 to add screenshots (either redacted, or in the linked E/E issue) of before/after for affected account(s)?

Added to issue description!

@brianlee-expensify
Copy link
Contributor

@joekaufmanexpensify can this be merged now?

@amyevans
Copy link
Contributor

@carlosmiceli
Copy link
Contributor Author

@amyevans was the Slack response sufficient? Are you able to review?

@amyevans
Copy link
Contributor

Sorry, I didn't see the emoji reaction on the message there 😅

@amyevans amyevans merged commit 0adae4c into main Mar 24, 2026
51 checks passed
@amyevans amyevans deleted the cm-duplicate-assigned-cards branch March 24, 2026 01:34
@github-actions
Copy link
Contributor

🚧 @amyevans has triggered a test Expensify/App build. You can view the workflow run here.

@OSBotify
Copy link
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@OSBotify
Copy link
Contributor

🚀 Deployed to staging by https://github.com/amyevans in version: 9.3.43-0 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

Bundle Size Analysis (Sentry):

@amyevans
Copy link
Contributor

@joekaufmanexpensify could you QA this one on staging please?

@joekaufmanexpensify
Copy link
Contributor

QA'ing and I think the behavior here is not quite what we want still. Discussing.

@joekaufmanexpensify
Copy link
Contributor

Checked off because above discussion does not block proceeding

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

Labels

InternalQA This pull request required internal QA

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants