Skip to content

Guard P2P participant selection against negative-amount expenses from self DM#94661

Merged
puneetlath merged 5 commits into
mainfrom
claude-guardNegativeP2PParticipantSelection
Jul 1, 2026
Merged

Guard P2P participant selection against negative-amount expenses from self DM#94661
puneetlath merged 5 commits into
mainfrom
claude-guardNegativeP2PParticipantSelection

Conversation

@MelvinBot

@MelvinBot MelvinBot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Explanation of Change

P2P chats don't support negative amounts, but the "Submit it to someone" flow from a self DM let a user select a P2P participant after a negative amount was already entered. The picker offered the participant, the participant was assigned to the negative-amount transaction, and "Create expense" then submitted it — producing a backend error.

The only existing negative-P2P guard lived in the standalone amount step (AmountSubmission.ts), where resetToDefaultWorkspace routes a negative amount back to the default workspace when returning from confirmation through the amount step — a path the new manual expense flow never takes.

This change stops the user at selection rather than at submit, mirroring that resetToDefaultWorkspace behavior. In handleParticipantsAdded, when the selected participant is a P2P participant (isParticipantP2P) and the transaction amount is negative, the expense is kept on the self DM (its default, as a track expense) instead of being assigned to the P2P participant. Self-DM track expenses and policy-expense-chat expenses still allow negative amounts; positive amounts can still be submitted to a P2P participant as before.

This direction supersedes the earlier useConfirmationValidation approach in #94537 (now closed), which only blocked the negative amount at submit time rather than preventing the invalid P2P assignment.

Fixed Issues

$ #94261
PROPOSAL: #94261 (comment)

Tests

// TODO: The human co-author must fill out the tests you ran before marking this PR as "ready for review"
// Please describe what tests you performed that validates your changed worked.

  1. Go to a self DM.
  2. Create an expense with a negative amount.
  3. Click "Submit it to someone", enter an email and select the user.
  4. Verify the negative expense is not assigned to the P2P user — it stays on the self DM (as a track expense) instead of routing to the P2P participant.
  5. Verify a positive amount can still be submitted to a P2P user.
  6. Verify a negative amount can still be created in a workspace (policy expense chat) and as a self-DM track expense.
  • Verify that no errors appear in the JS console

Offline tests

Same as Tests.

QA Steps

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

  1. Go to a self DM.
  2. Create an expense with a negative amount.
  3. Click "Submit it to someone", enter an email and select the user.
  4. Verify the negative expense cannot be submitted to the P2P user (it is not assigned to them).
  • 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 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)
  • 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)
  • 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.
  • 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

Co-authored-by: thelullabyy <thelullabyy@users.noreply.github.com>
@codecov

codecov Bot commented Jun 26, 2026

Copy link
Copy Markdown

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/ParticipantPicker.tsx 95.23% <100.00%> (+0.23%) ⬆️
...s/iou/request/MoneyRequestParticipantsSelector.tsx 0.00% <0.00%> (ø)
...es/iou/request/step/IOURequestStepParticipants.tsx 0.00% <0.00%> (ø)
src/pages/iou/request/ParticipantSearchResults.tsx 0.66% <0.00%> (-0.01%) ⬇️
...es/iou/request/step/IOURequestStepConfirmation.tsx 63.07% <20.00%> (-0.48%) ⬇️
src/hooks/useParticipantSubmission.ts 0.00% <0.00%> (ø)
... and 35 files with indirect coverage changes

@thelullabyy

Copy link
Copy Markdown
Contributor

@codex review

@thelullabyy

Copy link
Copy Markdown
Contributor

@MelvinBot Please replace all [ ] characters in PR description by [x]

@MelvinBot

Copy link
Copy Markdown
Contributor Author

🤖 Done — replaced all [ ] checkboxes in the PR description with [x]. No empty checkboxes remain.

@thelullabyy

Copy link
Copy Markdown
Contributor

@MelvinBot All good now. Please mark this PR as ready for review

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

Copy link
Copy Markdown

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: 88d9780b4e

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

// fail at submit. Mirror the resetToDefaultWorkspace behavior in AmountSubmission.ts and keep the
// expense on the self DM (its default) instead of assigning the P2P participant, so the user is
// stopped at selection rather than at submit.
const shouldKeepOnSelfDM = !!selectedParticipant?.isSelfDM || ((transaction?.amount ?? 0) < 0 && isParticipantP2P(selectedParticipant));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve workspace when rejecting negative P2P selections

When a negative manual expense is already associated with a policy expense chat (for example, global create auto-assigned the default workspace), choosing a P2P recipient now enters this branch and the following lines replace the destination with the self DM/unreported track flow. That is not the resetToDefaultWorkspace behavior referenced in the comment, which keeps auto-reported expenses on the default workspace; in this context the expense is silently converted into a personal tracked expense instead of staying on the workspace.

Useful? React with 👍 / 👎.

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.

🤖 I checked this — the concern is valid and reachable, and the "mirrors resetToDefaultWorkspace" justification in the code comment is inaccurate for the workspace case.

The bug: A global-create manual expense with an auto-reporting default workspace lands on confirmation already assigned to the policy expense chat (useDefaultParticipants.ts:72-74). The "To" row stays editable because canEditParticipant only checks isFromGlobalCreate, not whether the transaction is already on a workspace (MoneyRequestConfirmationList.tsx:260, :420, :437-449). So a user can open the picker manually and select a P2P recipient on a negative workspace expense — which makes shouldKeepOnSelfDM true (IOURequestStepConfirmation.tsx:322) and the branch unconditionally forces self-DM + UNREPORTED + iouType=TRACK (:324-326), silently converting the workspace expense into a personal track expense.

Why the comment justification is off: the referenced resetToDefaultWorkspace resets to the policy expense chat when auto-reporting is on (self DM only when it's off). The new code drops to self-DM/TRACK in all cases, so it doesn't actually mirror that behavior on a workspace transaction.

Suggested fix: gate the negative-P2P branch so it only forces the self-DM/track path when the transaction's current target is the self DM (i.e. don't trigger it for a transaction already bound to a policy expense chat) — or mirror the auto-report-aware target selection from resetToDefaultWorkspace so an auto-reporting workspace expense stays on the workspace instead of becoming a track expense.

Caveats: requires the NEW_MANUAL_EXPENSE_FLOW beta and an auto-reporting default workspace; if the default is the self DM, the concern doesn't apply. thelullabyy — want me to implement the gating fix? If so, reply tagging me.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@MelvinBot implement this

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.

🤖 Implemented in 24ddad22f.

Gated the negative-P2P branch in handleParticipantsAdded so it only forces the self-DM/track path when the transaction is not already bound to a policy expense chat (IOURequestStepConfirmation.tsx:324-325):

const isTransactionOnPolicyExpenseChat = transaction?.participants?.some((participant) => participant?.isPolicyExpenseChat);
const shouldKeepOnSelfDM = !!selectedParticipant?.isSelfDM || ((transaction?.amount ?? 0) < 0 && !isTransactionOnPolicyExpenseChat && isParticipantP2P(selectedParticipant));

Now a negative expense that was auto-assigned to a workspace (global create) stays on that workspace when a P2P recipient is selected, instead of being silently converted into a personal track expense. The self-DM "Submit it to someone" case still keeps the expense on the self DM as before. I also updated the code comment, which previously claimed to mirror resetToDefaultWorkspace (inaccurate for the workspace case), and applied the same exclusion to the participant-page path in addParticipant.

Verified: lint, typecheck (tsc + tsgo), React Compiler compliance (no regression), and the related Jest suites (IOURequestStepConfirmationPageTest, IOUUtilsTest, TimeExpenseConfirmationTest — 99 tests) all pass.

@MelvinBot MelvinBot marked this pull request as ready for review June 26, 2026 05:44
@MelvinBot MelvinBot requested a review from a team as a code owner June 26, 2026 05:44
@melvin-bot melvin-bot Bot requested review from thelullabyy and removed request for a team June 26, 2026 05:44
@melvin-bot

melvin-bot Bot commented Jun 26, 2026

Copy link
Copy Markdown

@thelullabyy 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 June 26, 2026 05:44
@thelullabyy

thelullabyy commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

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 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)
  • 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)
  • 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.
  • 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: mWeb Chrome
iOS: HybridApp
iOS: mWeb Safari
MacOS: Chrome / Safari
Screen.Recording.2026-06-30.at.05.59.52.mov

@thelullabyy

Copy link
Copy Markdown
Contributor

@MelvinBot Please check this comment #94661 (comment)

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

Copy link
Copy Markdown

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: 88d9780b4e

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

// fail at submit. Mirror the resetToDefaultWorkspace behavior in AmountSubmission.ts and keep the
// expense on the self DM (its default) instead of assigning the P2P participant, so the user is
// stopped at selection rather than at submit.
const shouldKeepOnSelfDM = !!selectedParticipant?.isSelfDM || ((transaction?.amount ?? 0) < 0 && isParticipantP2P(selectedParticipant));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Guard the participant-page path too

This guard only runs when the inline confirmation picker calls handleParticipantsAdded, but the “Submit it to someone” action from a tracked self-DM expense navigates through IOURequestStepParticipants (ChatActionableButtonscreateDraftTransactionAndNavigateToParticipantSelector) and useParticipantSubmission.addParticipant saves the selected P2P participant before navigating to confirmation. In that path this callback is never invoked, so a negative tracked expense can still reach confirmation with a P2P destination and fail on submit; the same negative/P2P check needs to be applied before setMoneyRequestParticipants in the participant-page flow as well.

Useful? React with 👍 / 👎.

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.

🤖 I checked this — the bot is correct, this is a real gap. The guard only covers the inline-confirmation picker path; the participant-page path is unguarded.

Why: The new guard lives only in handleParticipantsAdded, whose only call site is the inline ParticipantPicker rendered behind the NEW_MANUAL_EXPENSE_FLOW beta at IOURequestStepConfirmation.tsx:884-892. The "Submit it to someone" flow does not go through it.

Traced path that bypasses the guard
  1. "Submit it to someone" on a tracked self-DM expense → createDraftTransactionAndNavigateToParticipantSelector with actionName = SUBMIT, which navigates to MONEY_REQUEST_STEP_PARTICIPANTS (ReportUtils.ts SUBMIT branch).
  2. IOURequestStepParticipants wires the selector to useParticipantSubmission.addParticipantnot handleParticipantsAdded.
  3. addParticipant has only one special case — isSelfDM → trackExpense() (L216-L219). A real P2P participant falls through to setMoneyRequestParticipants (L230-L237) with no amount < 0 / isParticipantP2P check, then goToNextStep navigates to confirmation with the P2P destination.

So a negative tracked expense can still reach confirmation with a P2P destination via this path and fail at submit — exactly the scenario the guard was meant to stop at selection time.

Suggested fix: apply the same (transaction?.amount ?? 0) < 0 && isParticipantP2P(selectedParticipant) → keep-on-self-DM logic before setMoneyRequestParticipants in addParticipant. Worth confirming which path is active per beta state — when NEW_MANUAL_EXPENSE_FLOW is off, the inline picker isn't rendered at all, so the participant-page path is the only one and the guard never runs.

Reply @MelvinBot implement this and I'll add the equivalent guard to addParticipant.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@MelvinBot implement this

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.

🤖 Implemented in 24ddad22f.

Added the same negative-amount/P2P guard to the participant-page path in addParticipant: when the draft transaction's amount is negative and the selected participant is a P2P participant (isParticipantP2P), it now routes to trackExpense() and keeps the expense on the self DM instead of saving the P2P participant via setMoneyRequestParticipants. This stops the "Submit it to someone" flow at selection time even when NEW_MANUAL_EXPENSE_FLOW is off (the path that never reaches handleParticipantsAdded).

To stay consistent with the workspace-preservation fix, the guard is skipped when the expense is already bound to a policy expense chat, so it can't silently convert a workspace expense into a track expense (useParticipantSubmission.ts:223-226).

Verified: lint, typecheck (tsc + tsgo), React Compiler compliance (no regression), and the related Jest suites (IOURequestStepConfirmationPageTest, IOUUtilsTest, TimeExpenseConfirmationTest — 99 tests) all pass.

@thelullabyy

Copy link
Copy Markdown
Contributor

Please check this comment @MelvinBot #94661 (comment)

…elections

Co-authored-by: thelullabyy <thelullabyy@users.noreply.github.com>
@MelvinBot MelvinBot requested a review from a team as a code owner June 26, 2026 06:15
@melvin-bot melvin-bot Bot requested a review from puneetlath June 26, 2026 06:15
@melvin-bot

melvin-bot Bot commented Jun 26, 2026

Copy link
Copy Markdown

@puneetlath 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 removed the request for review from a team June 26, 2026 06:15
@thelullabyy

Copy link
Copy Markdown
Contributor

@MelvinBot Please resolve conflicts

…2PParticipantSelection

Co-authored-by: thelullabyy <thelullabyy@users.noreply.github.com>

# Conflicts:
#	src/pages/iou/request/step/IOURequestStepConfirmation.tsx
@thelullabyy

Copy link
Copy Markdown
Contributor

@codex review

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

Copy link
Copy Markdown

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: 89ce348a55

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/hooks/useParticipantSubmission.ts Outdated
Comment on lines 226 to 227
if ((firstParticipant?.isSelfDM || shouldKeepNegativeExpenseOnSelfDM) && !isSplitRequest) {
trackExpense();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Stop auto-finish after falling back to track

When this branch is hit from the full participant step, ParticipantSearchResults.addSingleParticipant still calls onFinish(..., newParticipants) immediately after onParticipantsAdded for any non-self row. Returning here only exits addParticipant: trackExpense() queues a TRACK confirmation, then goToNextStep queues its own navigation with the stale selectedReportID and the P2P nextParticipants, so the user can land on a SUBMIT confirmation for the unreported/self-DM draft instead of staying in the track flow. The negative-P2P fallback needs to also prevent or coordinate the subsequent finish callback.

Useful? React with 👍 / 👎.

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.

Good catch — verified and fixed in 734be7c.

You're right that this was a real regression. ParticipantSearchResults.addSingleParticipant calls onParticipantsAdded (→ addParticipant) and then, for any non-self row, also calls onFinish (→ goToNextStep), gated only by if (!option.isSelfDM). Since P2P participants aren't self-DM, both fired: addParticipant ran the negative-P2P fallback (trackExpense() + early return), but goToNextStep still ran afterward and queued a SUBMIT navigation with the stale selectedReportID (the early return happens before selectedReportID.current is updated), which could override the track flow. The pre-existing self-DM path never hit this because self-DM rows are excluded from the onFinish call.

Fix: mirror the same guard in goToNextStep so it bails out when the fallback already routed to the track flow, and extract the shared condition into a shouldKeepNegativeExpenseOnSelfDM helper to avoid duplicating the logic:

const effectiveParticipants = nextParticipants ?? currentParticipants;

// ...skip the submit navigation when the negative-P2P fallback already kept the expense on the self DM.
if (!isSplitRequest && shouldKeepNegativeExpenseOnSelfDM(effectiveParticipants?.at(0))) {
    return;
}

Verified locally: ESLint, typecheck-tsgo, and React Compiler compliance all pass.

@thelullabyy

Copy link
Copy Markdown
Contributor

@MelvinBot Please check this comment and fix if needed #94661 (comment)

…ps expense on self DM

Co-authored-by: thelullabyy <thelullabyy@users.noreply.github.com>
@thelullabyy

Copy link
Copy Markdown
Contributor

BUG: @MelvinBot

  1. Go to staging.new.expensify.com
  2. Go to self DM.
  3. Create an expense with negative amount.
  4. Click Submit it to someone.
  5. Enter email and select user.
  6. Click Create expense.

Expected Result:
In Step 5, user will not show up in participant list when amount is negative and user cannot select to go confirm details.

Actual Result:
In Step 5, user shows up in participant list when amount is negative.
In Step 6, it goes to Confirm details page with To is self DM

image image

…tly keeping on self DM

Co-authored-by: thelullabyy <thelullabyy@users.noreply.github.com>
@puneetlath

Copy link
Copy Markdown
Contributor

@MelvinBot can you address the comment above?

@thelullabyy

Copy link
Copy Markdown
Contributor

@MelvinBot Could you please check and address this comment #94661 (comment)

@thelullabyy

Copy link
Copy Markdown
Contributor

@codex review

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

Copy link
Copy Markdown

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: 71356f05b6

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

includeOwnedWorkspaceChats: iouType === CONST.IOU.TYPE.SUBMIT || iouType === CONST.IOU.TYPE.CREATE || iouType === CONST.IOU.TYPE.SPLIT || iouType === CONST.IOU.TYPE.TRACK,
excludeNonAdminWorkspaces: action === CONST.IOU.ACTION.SHARE,
includeP2P: !isCategorizeOrShareAction && !isPerDiemRequest && !isTimeRequest && !isTransactionFromCreditCardImport,
includeP2P: !isCategorizeOrShareAction && !isPerDiemRequest && !isTimeRequest && !isTransactionFromCreditCardImport && !shouldExcludeP2P,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Keep self-DM visible when hiding P2P recipients

When shouldExcludeP2P is true for a negative amount, this passes includeP2P: false into the generic report filter. That filter treats includeP2P=false as “policy expense chats only” (!includeP2P && !isPolicyExpenseChat), so it also removes the self-DM even though self-DM is the valid Track destination and includeSelfDM is still requested. In the negative self-DM flow, users without a workspace chat (or users who want to keep the expense personal) can end up with no selectable Personal/self-DM option and cannot proceed from the participant step.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We also excluded self DM in original flow

@puneetlath puneetlath merged commit e3b4f3c into main Jul 1, 2026
40 checks passed
@puneetlath puneetlath deleted the claude-guardNegativeP2PParticipantSelection branch July 1, 2026 22:54
@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

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

@OSBotify

OSBotify commented Jul 1, 2026

Copy link
Copy Markdown
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

OSBotify commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/puneetlath in version: 9.4.27-1 🚀

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

@MelvinBot

Copy link
Copy Markdown
Contributor Author

🤖 Help site review — no changes required

I reviewed this PR against App/docs/articles and don't think a help site update is warranted.

What this PR changes: It adds a validation guard so that a negative-amount track expense created in a self DM can't be assigned to a P2P (individual) participant via Submit it to someone — the expense stays on the self DM as a track expense instead, since P2P chats don't support negative amounts. Positive amounts still submit to individuals, and negative amounts are still allowed on workspace (policy expense chat) expenses and self-DM track expenses.

Why no docs change is needed:

  • The only closely related article, Track-Expenses.md, documents the happy-path Submit it to someone flow but never mentions negative amounts or a P2P amount restriction — so nothing in it becomes inaccurate.
  • Negative amounts are an uncommon edge case, and this is an internal validation guard (preventing a backend error), not a new user-facing feature or workflow. Per the authoring guidelines, articles should "solve one primary workflow" and stay "concise and actionable" — documenting this corner-case restriction would add obscure detail below the threshold the help site covers.
  • No existing article claims you can submit a negative/credit amount to an individual, so there's no contradictory content to correct.

Since no changes are required, I did not open a draft help site PR.

@thelullabyy, please confirm you agree this doesn't need a help site update. If you'd like an FAQ entry added to Track-Expenses.md clarifying that individual (P2P) submissions don't support negative amounts, let me know and I'll create the draft PR.

@OSBotify

OSBotify commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/grgia in version: 9.4.27-2 🚀

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

Bundle Size Analysis (Sentry):

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.

4 participants