Skip to content

fix: show scan error instead of populating $0 amount when scan fails - #98871

Open
x-dev90 wants to merge 31 commits into
Expensify:mainfrom
x-dev90:fix/scan-failed-amount-handling
Open

x-dev90 wants to merge 31 commits into
Expensify:mainfrom
x-dev90:fix/scan-failed-amount-handling

Conversation

@x-dev90

@x-dev90 x-dev90 commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Explanation of Change

When a receipt fails to scan, the Amount field showed "$0.00" with no error instead of staying empty. This fixes it across the expense details page, confirmation list, report table, and chat preview — the amount now stays empty with a "missing amount" error until the user manually confirms a value (including 0). Also fixes bulk-editing a failed-scan expense's amount to 0, which previously silently failed to save.

Fixed Issues

$ #94494
PROPOSAL: #94494 (comment)

Tests

Flow 1: Workspace failed scan expense

  1. Open the workspace chat.
  2. Create a scan expense with a receipt/image that will fail SmartScan.
  3. Wait until the scan fails.
  4. Open the expense details.
  5. Verify the Amount field is empty instead of showing $0.00.
  6. Verify the Amount field shows the missing amount error.
  7. Open the Amount field.
  8. Enter 0 and save.
  9. Verify the Amount field shows $0.00.
  10. Verify the missing amount error is cleared.

Flow 2: Split expense failed scan

  1. Start a group chat.
  2. Split an expense using scan and upload an image that will fail SmartScan.
  3. Wait until the scan fails.
  4. Open the split expense details.
  5. Verify the Amount field is empty instead of showing $0.00.
  6. Verify the Amount field shows the missing amount error.

Flow 3: Report table inline amount edit

  1. Using the failed scan expense from Flow 1, open the parent Expense Report to see the transaction table.
  2. Verify the Amount column for that row is empty instead of showing 0.00.
  3. Verify the row shows a "Missing amount" indicator.
  4. Click the Amount cell's edit icon.
  5. Enter 0 and save.
  6. Verify the Amount cell shows 0.00.
  7. Verify the "Missing amount" indicator is cleared.

Flow 4: Report table inline edit no-op check

  1. Using another failed scan expense in the same report, click the Amount cell's edit icon.
  2. Without typing anything, click away to blur the cell.
  3. Verify the Amount cell is still empty.
  4. Verify the "Missing amount" indicator is still shown.

Flow 5: Self-DM (track expense) failed scan

  1. Go to your own personal space (self-DM).
  2. Track an expense using scan and upload an image that will fail SmartScan.
  3. Wait until the scan fails.
  4. Verify the expense preview in the chat shows an empty amount and a "Missing amount" indicator.
  5. Open the expense.
  6. Enter 0 as the amount and save.
  7. Verify the preview updates to show 0.00.
  8. Verify the "Missing amount" indicator is cleared.

Flow 6: Manual $0.00 expense in self-DM (regression check)

  1. Go to your own personal space (self-DM).
  2. Create a manual expense (not scan) with amount 0.00.
  3. Verify the expense preview in the chat shows 0.00 (not blank).
  4. Open the expense.
  5. Verify the Amount field shows 0.00 (not blank).

Flow 7: Bulk edit multiple to 0

  1. In the workspace chat, create a scan expense with a receipt/image that will fail SmartScan.
  2. Wait until the scan fails.
  3. Go to Search (or the report), select the failed scan expense's checkbox.
  4. Click the dropdown button → Edit multiple.
  5. Click Amount, enter 0, and save.
  6. Open the expense.
  7. Verify the Amount field shows 0.00.
  8. Verify the missing amount error is cleared.

Flow 8: System message stays consistent after confirming 0

  1. Create a workspace scan expense with a receipt that will fail SmartScan.
  2. Wait until the scan fails.
  3. Open the Amount field, enter 0, and save.
  4. Verify the system message in the chat reads "set the amount to $0.00" (no "previously" clause).
  5. Go to Account → Troubleshoot → Clear cache and restart → Reset and refresh.
  6. Reopen the same expense/chat.
  7. Verify the system message still reads "set the amount to $0.00" — identical to step 4, no flip to a different/generic message.
  • 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]."

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

Flow:1

Screen_Recording_20260724_005653_New.Expensify.Dev.mp4

Flow:2

Screen_Recording_20260724_005952_New.Expensify.Dev.mp4
Android: mWeb Chrome

Flow:1

Screen_Recording_20260724_002037_Chrome.mp4

Flow:2

Screen_Recording_20260724_010057_Chrome.mp4
iOS: Native

Flow:1

Screen.Recording.2026-07-24.at.12.35.40.AM.mp4

Flow:2

Screen.Recording.2026-07-24.at.12.40.00.AM.mp4
iOS: mWeb Safari

Flow:1

Screen.Recording.2026-07-24.at.12.40.54.AM.mp4

Flow:2

Screen.Recording.2026-07-24.at.12.42.25.AM.mp4
MacOS: Chrome / Safari

Flow 1:

Flow.1.mp4

Flow 2:

Flow.2.mp4

Flow 3:

Flow.3.mov

Flow 4:

Flow.4.mov

Flow 5:

Flow.5.mov

Flow 6:

Flow.6.mov

Flow 7:

Flow.7.mov

Flow 8:

Screen.Recording.2026-08-25.at.10.55.32.AM.mov

@codecov

codecov Bot commented Aug 18, 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 Δ
...estConfirmationList/hooks/useConfirmationAmount.ts 95.45% <100.00%> (+0.45%) ⬆️
...eyRequestConfirmationList/sections/AmountField.tsx 73.33% <100.00%> (+11.98%) ⬆️
...MoneyRequestConfirmationList/sections/selectors.ts 84.15% <ø> (ø)
...ponents/TransactionItemRow/DataCells/TotalCell.tsx 91.04% <100.00%> (+12.71%) ⬆️
src/libs/IOUAmountSubmission.ts 86.84% <100.00%> (+0.06%) ⬆️
src/libs/ModifiedExpenseMessage.ts 91.45% <100.00%> (ø)
src/libs/ReportUtils.ts 87.47% <100.00%> (+0.04%) ⬆️
src/libs/TransactionPreviewUtils.ts 85.64% <100.00%> (+0.14%) ⬆️
src/libs/TransactionUtils/amountUtils.ts 100.00% <100.00%> (ø)
src/libs/TransactionUtils/index.ts 93.29% <100.00%> (-0.04%) ⬇️
... and 3 more
... and 15 files with indirect coverage changes

@x-dev90
x-dev90 marked this pull request as ready for review August 20, 2026 12:38
@x-dev90
x-dev90 requested review from a team as code owners August 20, 2026 12:38
@melvin-bot
melvin-bot Bot requested review from Ollyws and joekaufmanexpensify and removed request for a team August 20, 2026 12:38
@melvin-bot

melvin-bot Bot commented Aug 20, 2026

Copy link
Copy Markdown

@Ollyws 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 August 20, 2026 12:38
@x-dev90

x-dev90 commented Aug 20, 2026

Copy link
Copy Markdown
Contributor Author

@Ollyws, as i checked This (issue #98783) is a backend issue,

I compared the network response for the amount edit itself against the OpenReport response after a full cache reset, and they're identical. The MODIFIEDEXPENSE action's originalMessage never includes oldAmount/oldCurrency, even in the very first response:

"originalMessage": {
    "amount": 0,
    "currency": "TJS",
    "isNewDot": true,
    "lastModified": "..."
}

So this isn't a caching/Onyx timing issue — the backend never persisted the "previous" value for this edit. The client only shows the detailed message initially because of its own optimistic data, which gets replaced once the real data loads fresh, causing the flip to the generic "changed the expense" message.

Needs: the backend should persist oldAmount/oldCurrency on this action (even when the numeric value is unchanged, e.g. confirming a failed-scan placeholder as 0), so the message stays consistent instead of flipping after a refresh.

cc @arosiclair

@x-dev90

x-dev90 commented Aug 20, 2026

Copy link
Copy Markdown
Contributor Author

@Ollyws — just flagging that issue #98788 is out of scope of our issue and wasn't discussed in the issue or PR review, it's an edge case.
It only showed up because of how we fixed the failed-scan amount — the bulk edit page has its own separate check for detecting whether the amount actually changed, and that check wasn't updated to account for it. By the way, I've fixed it now in this PR.

Thanks!

cc @arosiclair

Comment thread tests/ui/TotalCellTest.tsx Outdated

@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: 11b5ddd12c

ℹ️ 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/libs/TransactionUtils/index.ts Outdated

@joekaufmanexpensify joekaufmanexpensify left a comment

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.

Good for product.

@arosiclair

Copy link
Copy Markdown
Contributor

I compared the network response for the amount edit itself against the OpenReport response after a full cache reset, and they're identical. The MODIFIEDEXPENSE action's originalMessage never includes oldAmount/oldCurrency, even in the very first response:

"originalMessage": {
    "amount": 0,
    "currency": "TJS",
    "isNewDot": true,
    "lastModified": "..."
}

For this issue, I think the data is fine. In product, I think the message text should just say "changed the amount to $0.00" with no "previously" part. And that should stay consistent with the optimistic data and also after the cache reset. Does that work?

@x-dev90

x-dev90 commented Aug 22, 2026

Copy link
Copy Markdown
Contributor Author

I compared the network response for the amount edit itself against the OpenReport response after a full cache reset, and they're identical. The MODIFIEDEXPENSE action's originalMessage never includes oldAmount/oldCurrency, even in the very first response:

"originalMessage": {
    "amount": 0,
    "currency": "TJS",
    "isNewDot": true,
    "lastModified": "..."
}

For this issue, I think the data is fine. In product, I think the message text should just say "changed the amount to $0.00" with no "previously" part. And that should stay consistent with the optimistic data and also after the cache reset. Does that work?

@arosiclair @Ollyws — implemented this. One thing to confirm: the existing message mechanism already supports a "no previously" phrasing, but it uses the verb "set" — so it renders as "set the amount to $0.00", not "changed the amount to $0.00". Getting the literal word "changed" would need a new translation string. Is "set the amount to $0.00" good to ship, or do you want "changed" specifically?
Thanks!

Screenshot 2026-08-22 at 11 38 29 AM

Comment thread src/libs/ModifiedExpenseMessage.ts
@Ollyws

Ollyws commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

@x-dev90 we're only getting the set the amount... message when updating to $0, any other value and we get changed the amount...

Screenshot 2026-09-09 at 10 14 59

@x-dev90

x-dev90 commented Sep 9, 2026

Copy link
Copy Markdown
Contributor Author

I compared the network response for the amount edit itself against the OpenReport response after a full cache reset, and they're identical. The MODIFIEDEXPENSE action's originalMessage never includes oldAmount/oldCurrency, even in the very first response:

"originalMessage": {
    "amount": 0,
    "currency": "TJS",
    "isNewDot": true,
    "lastModified": "..."
}

For this issue, I think the data is fine. In product, I think the message text should just say "changed the amount to $0.00" with no "previously" part. And that should stay consistent with the optimistic data and also after the cache reset. Does that work?

@arosiclair @Ollyws — implemented this. One thing to confirm: the existing message mechanism already supports a "no previously" phrasing, but it uses the verb "set" — so it renders as "set the amount to $0.00", not "changed the amount to $0.00". Getting the literal word "changed" would need a new translation string. Is "set the amount to $0.00" good to ship, or do you want "changed" specifically? Thanks!

Screenshot 2026-08-22 at 11 38 29 AM

@Ollyws, thanks for checking. I confirmed this here, and it’s expected behavior.

@Ollyws

Ollyws commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Hmm seems a little inconsistent to use set the amount only when we set it to $0 (from blank), and changed the amount if we set it to any other value..
What do you think @arosiclair?
Other than that looks good to go.

@arosiclair

Copy link
Copy Markdown
Contributor

Hmm seems a little inconsistent to use set the amount only when we set it to $0 (from blank), and changed the amount if we set it to any other value

So when there is no previous value, setting it to $0 shows "set the amount to $0.00" and setting it to $5 shows "changed the amount to $5.00"? I think we should show "set the amount" in both of those scenarios.

@x-dev90

x-dev90 commented Sep 11, 2026

Copy link
Copy Markdown
Contributor Author

Hmm seems a little inconsistent to use set the amount only when we set it to $0 (from blank), and changed the amount if we set it to any other value

So when there is no previous value, setting it to $0 shows "set the amount to $0.00" and setting it to $5 shows "changed the amount to $5.00"? I think we should show "set the amount" in both of those scenarios.

@Ollyws, after checking this further, the nonzero case requires a backend change.

For the first amount entered after a failed scan, the backend returns:

{
  "amount": 400,
  "currency": "TJS",
  "oldAmount": 0,
  "oldCurrency": "TJS"
}

Because oldAmount is present, the frontend renders changed the amount… previously TJS 0.00.

A frontend-only fix would be unsafe because a legitimate 0 → 4 edit has the same data, and an optimistic workaround would be lost after a cache reset.

The backend should omit oldAmount and oldCurrency from the first MODIFIEDEXPENSE action after a failed scan, for both zero and nonzero values. Subsequent edits should continue returning these fields normally.
could you please take another look at this?

Thanks!

cc @arosiclair

@arosiclair

arosiclair commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Okay I'll find someone who can update the API to do that. Asked here

@dukenv0307

Copy link
Copy Markdown
Contributor

will take a look

@dukenv0307

Copy link
Copy Markdown
Contributor

@x-dev90 BE is deployed to prod, please check again

@x-dev90

x-dev90 commented Sep 16, 2026

Copy link
Copy Markdown
Contributor Author

Hmm seems a little inconsistent to use set the amount only when we set it to $0 (from blank), and changed the amount if we set it to any other value.. What do you think @arosiclair? Other than that looks good to go.

@Ollyws, addressed this as well. The first amount entry now consistently uses “set the amount” for both zero and nonzero values. Please take another look, thanks!

@Ollyws

Ollyws commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

@x-dev90 On split expense we have an issue where it won't split a $0 expense (expected?) but if we change to a valid value the error persists:

Screen.Recording.2026-09-16.at.14.29.50.mov

@x-dev90

x-dev90 commented Sep 17, 2026

Copy link
Copy Markdown
Contributor Author

@x-dev90 On split expense we have an issue where it won't split a $0 expense (expected?) but if we change to a valid value the error persists:

@Ollyws, I’ve addressed this as well. Could you please check it once again? Thanks!

@Ollyws

Ollyws commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

I'm assuming disallowing setting the amount to $0 is expected on P2P transactions as this is the current behaviour on staging, if anyone disagrees then let me know.

@Ollyws Ollyws left a comment

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.

LGTM.

@melvin-bot
melvin-bot Bot requested a review from arosiclair September 17, 2026 11:15
@x-dev90

x-dev90 commented Sep 17, 2026

Copy link
Copy Markdown
Contributor Author

I found one more edge case with a Scan expense:

Steps to reproduce:

  1. While online, open a workspace chat and select + → Create expense → Scan.
  2. Upload an unreadable receipt. On the confirmation page, expand Show more and enter Amount: 0.00, a merchant, and a date.
  3. Go offline before clicking Submit.
  4. Submit while offline, then open the created expense and its report.

Expected: The amount shows 0.00.
Actual on this PR: It shows as missing.

@arosiclair, Could we hold off on merging while I investigate this further? I’ll share an update once I’ve confirmed the cause. Thanks for your time and review!

@arosiclair

Copy link
Copy Markdown
Contributor

Okay let me know when it's ready for review. Btw, we closed out this deploy blocker from the last PR recently: #98737. Let's also make sure that's not still an issue

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.

5 participants