Skip to content

[$250] Discard modal doesn’t appear after swipe if only +/- was entered in manual expense #99042

Open

Description

@applause-bot

If you haven’t already, check out our contributing guidelines for onboarding. To join our Slack channel, fill out this form.


Version Number: 9.4.57-0
Reproducible in staging?: Yes
Reproducible in production?: Yes
If this was caught during regression testing, add the test name, ID and link from BrowserStack: #97020
Email or phone of affected tester (no customers): fischer9966+082026+97020@gmail.com
Issue reported by: Applause Internal Team
Bug source: Pull Request QA execution
Device used: iPhone 17 Pro / iOS 26.6
App Component: Left Hand Navigation (LHN)

Action Performed:

  1. Open Expensify App
  2. Login with any account
  3. Step 9 in PR > Tap the FAB > Create expense > Manual. Tap only the +/- key without typing a digit, then swipe back. Verify the discard modal appears.

Expected Result:

Discard modal appears after swipe back if only +/- was entered when creating a manual expense

Actual Result:

Discard modal does NOT appear after swipe back if only +/- was entered when creating a manual expense

Workaround:

Unknown

Platforms:

  • Android: App
  • Android: mWeb Chrome
  • iOS: App
  • iOS: mWeb Safari
  • iOS: mWeb Chrome
  • Windows: Chrome
  • MacOS: Chrome Safari

Screenshots/Videos

Bug7238034_1787212504229.PR97020-iOS-Manual-Expense-Swipe-Back-After-Flip.mp4

View all open jobs on GitHub

Applause Internal Information
Exported by: Julia Ponikarchuk
Bug ID: 7238034

Upwork Automation - Do Not Edit
Issue OwnerCurrent Issue Owner: @TaduJR

Activity

  1. applause-bot commented on Aug 20, 2026

    @applause-bot
    Author

    While Applause doesn't embed attachments for this bug, here are the links for quick view:
    https://platform.applause.com/services/links/v1/external/89606af7977dd6a304c25fe82e73b05e2d1ad6a3da1c7d8e90762a8b72296c90

  2. added
    BugSomething is broken. Auto assigns a BugZero manager.
    on Aug 20, 2026
  3. MelvinBot commented on Aug 20, 2026

    @MelvinBot
    Contributor

    Proposal

    What is the root cause of that problem?

    Tapping only the +/- key on the manual amount screen flips the visible sign but reports an empty change signal, so the screen never registers as "dirty" and the discard guard is never armed.

    When the sign is toggled, toggleNegative reports the newly-signed value to the amount step. But it gates the sign on the number being non-empty:

    MoneyRequestAmountForm.tsx:163 — onAmountChange?.(currentNumber && nextIsNegative ? -${currentNumber} : currentNumber)

    With no digit typed, currentNumber is '', so currentNumber && nextIsNegative is falsy and the reported value is '' — the sign is dropped. That '' is mirrored into typedAmount at IOURequestStepAmount.tsx:318, and the create-entry dirtiness check reads it as clean:

    MoneyRequestUtils.ts:210-211 — return typedAmount !== '' || committedAmount !== 0 || currencyChanged; → '' !== '' (false) || 0 !== 0 (false) || false → not dirty. getHasUnsavedChanges() returns false, so the discard guard's beforeRemove returns early and navigation proceeds with no modal.

    This regressed in PR #97020, which reworked the discard guard to arm only when the screen has unsaved changes. Its own test step 9 is exactly this scenario. The bug is App-only (iOS/Android) — not desktop web — because the +/- key is part of the touch-only BigNumberPad (shouldShowBigNumberPad={canUseTouchScreen}), so on a non-touch browser the key never renders (confirmed while attempting to verify on web).

    What changes do you think we should make in order to solve the problem?

    Stop dropping the sign signal when the amount is empty. In toggleNegative, report the value based on nextIsNegative rather than on currentNumber being truthy, so an empty negative flip reports '-' (marking the screen dirty via typedAmount !== '') and a flip back to positive reports '' (clean again).

    This is safe: typedAmount is only consumed by getAmountHasUnsavedChanges for dirtiness — the actual submit path composes the amount from the form's own getNumber()/isNegative, not typedAmount. One edge to handle: in the non-create (edit) branch of getAmountHasUnsavedChanges, Number.parseFloat('-') is NaN, so a bare '-' should be normalized to amount 0 there to avoid a false-dirty when editing an existing 0 amount.

    Evidence & data flow
    1. User taps +/- with no digit → NumberWithSymbolForm currentNumber is '' (getNumber() returns '').
    2. toggleNegative flips the sign but calls onAmountChange('') (sign dropped).
    3. setTypedAmount('') → typedAmount = ''.
    4. getHasUnsavedChanges → getAmountHasUnsavedChanges({typedAmount:'', committedAmount:0, isCreateEntry:true, currency unchanged}).
    5. Create-entry branch MoneyRequestUtils.ts:210-211 returns false → clean.
    6. Discard hook beforeRemove sees hasUnsavedChanges() === false and returns early → no modal.

    Confidence: High — every step is confirmed by static code reading. Web runtime verification wasn't possible because the +/- key only renders on touch platforms, which is consistent with the issue reproducing on iOS/Android App only.

    What alternative solutions did you explore? (Optional)

    Alternatively, mirror the form's isNegative state into IOURequestStepAmount's dirtiness computation instead of encoding it in the reported string. The form-level fix is smaller and keeps the sign logic co-located.


    Next Steps for Contributor+ team:
    To accept: @MelvinBot implement [this](https://github.com/Expensify/App/issues/99042) to create a draft PR.
    To refine: @MelvinBot <your feedback>
    To reject: Explain why you are rejecting Melvin's proposal.


    view run

  4. added
    ExternalAdded to denote the issue can be worked on by a contributor
    on Aug 20, 2026
  5. melvin-bot commented on Aug 20, 2026

    @melvin-bot

    Triggered auto assignment to Contributor-plus team member for initial proposal review - @marufsharifi (External)

  6. j3ffffff commented on Aug 20, 2026

    @j3ffffff
  7. melvin-bot commented on Aug 20, 2026

    @melvin-bot
  8. marufsharifi commented on Aug 20, 2026

    @marufsharifi
    Contributor

    reproduced, checking the proposal.

  9. Usama123talib commented on Aug 20, 2026

    @Usama123talib

    Proposal

    Please re-state the problem that we are trying to solve in this issue.

    When creating a manual expense on mobile/touch platforms (iOS and Android), tapping only the +/- (sign toggle) key without entering any digits and then swiping/navigating back fails to display the discard confirmation modal.


    What is the root cause of that problem?

    The discard confirmation hook (IOURequestStepAmount.tsx:139-151) calculates unsaved changes using typedAmount state via getAmountHasUnsavedChanges:

    // src/libs/MoneyRequestUtils.ts
    function getAmountHasUnsavedChanges({typedAmount, committedAmount, isCreateEntry, selectedCurrency, originalCurrency}: AmountHasUnsavedChangesParams): boolean {
        const currencyChanged = selectedCurrency !== originalCurrency;
        if (isCreateEntry) {
            return typedAmount !== '' || committedAmount !== 0 || currencyChanged;
        }
        const typedAmountInBackendUnits = typedAmount ? convertToBackendAmount(Number.parseFloat(typedAmount)) : 0;
        return typedAmountInBackendUnits !== committedAmount || currencyChanged;
    }

    In MoneyRequestAmountForm.tsx, the sign prefix is unnecessarily gated on number/amount being non-empty in 3 places:

    1. toggleNegative (line 158-164):

      onAmountChange?.(currentNumber && nextIsNegative ? `-${currentNumber}` : currentNumber);

      When no digits are entered, currentNumber is ''. Because currentNumber is falsy, it calls onAmountChange?.('') instead of onAmountChange?.('-'), silently dropping the minus sign.

    2. MoneyRequestAmountInput's onAmountChange wrapper (line 306-313):

      onAmountChange?.(newAmount && isNegative ? `-${newAmount}` : newAmount);

      If a user enters -5 and backspaces the 5, newAmount becomes ''. The wrapper evaluates newAmount && isNegative to '', reverting typedAmount to clean even though the - sign is still active on screen.

    3. clearNegative (line 166-168):

      const clearNegative = useCallback(() => {
          setIsNegative(false);
      }, []);

      When the user backspaces the bare - sign (triggering clearNegative), it resets isNegative to false but does not notify onAmountChange, leaving typedAmount out of sync.

    Because typedAmount remains '', getAmountHasUnsavedChanges returns false ('' !== ''), and useDiscardChangesConfirmation does not prompt the user.


    What changes do you think we should make in order to solve the problem?

    1. In src/pages/iou/MoneyRequestAmountForm.tsx:

    • In toggleNegative: report nextIsNegative ? \-${currentNumber}` : currentNumberso toggling to negative sends'-'and toggling back sends''`.
    • In clearNegative: call onAmountChange?.(currentNumber) so backspacing the minus sign resets typedAmount back to ''.
    • In useImperativeHandle: update getNumber() to isNegative ? \-${number}` : numberto guaranteegetNumber()andtypedAmount` remain 100% in sync at all times.
    • In MoneyRequestAmountInput onAmountChange: report isNegative ? \-${newAmount}` : newAmount`.
    // src/pages/iou/MoneyRequestAmountForm.tsx
    
    useImperativeHandle(amountFormRef, () => ({
        getNumber: () => {
            const number = moneyRequestAmountInputRef.current?.getNumber() ?? '';
            return isNegative ? `-${number}` : number;
        },
    }));
    
    const toggleNegative = useCallback(() => {
        const nextIsNegative = !isNegative;
        setIsNegative(nextIsNegative);
        const currentNumber = moneyRequestAmountInputRef.current?.getNumber() ?? '';
        onAmountChange?.(nextIsNegative ? `-${currentNumber}` : currentNumber);
    }, [isNegative, onAmountChange]);
    
    const clearNegative = useCallback(() => {
        setIsNegative(false);
        const currentNumber = moneyRequestAmountInputRef.current?.getNumber() ?? '';
        onAmountChange?.(currentNumber);
    }, [onAmountChange]);

    And in JSX:

    <MoneyRequestAmountInput
        ...
        onAmountChange={(newAmount) => {
            onAmountChange?.(isNegative ? `-${newAmount}` : newAmount);
            if (!formError) {
                return;
            }
            setFormError('');
        }}
    />

    2. In src/libs/MoneyRequestUtils.ts:

    Safely handle '-' in the edit branch of getAmountHasUnsavedChanges to prevent NaN when Number.parseFloat('-') is executed:

    // src/libs/MoneyRequestUtils.ts
    
    function getAmountHasUnsavedChanges({typedAmount, committedAmount, isCreateEntry, selectedCurrency, originalCurrency}: AmountHasUnsavedChangesParams): boolean {
        const currencyChanged = selectedCurrency !== originalCurrency;
        if (isCreateEntry) {
            return typedAmount !== '' || committedAmount !== 0 || currencyChanged;
        }
        const parsedAmount = Number.parseFloat(typedAmount);
        const typedAmountInBackendUnits = Number.isNaN(parsedAmount) ? 0 : convertToBackendAmount(parsedAmount);
        return typedAmountInBackendUnits !== committedAmount || currencyChanged;
    }

    What specific scenarios should we cover in automated tests to prevent regression?

    Add unit tests in tests/unit/MoneyRequestUtilsTest.ts for getAmountHasUnsavedChanges:

    1. Create flow with bare negative sign ('-'):
      • getAmountHasUnsavedChanges({typedAmount: '-', committedAmount: 0, isCreateEntry: true, selectedCurrency: 'USD', originalCurrency: 'USD'}) returns true.
    2. Create flow with empty input (''):
      • getAmountHasUnsavedChanges({typedAmount: '', committedAmount: 0, isCreateEntry: true, selectedCurrency: 'USD', originalCurrency: 'USD'}) returns false.
    3. Edit flow with bare negative sign ('-') and 0 committed amount:
      • getAmountHasUnsavedChanges({typedAmount: '-', committedAmount: 0, isCreateEntry: false, selectedCurrency: 'USD', originalCurrency: 'USD'}) returns false (handles NaN gracefully without a false-positive dirty flag).
    4. Edit flow with sign toggled (e.g. '-5' vs 500):
      • getAmountHasUnsavedChanges({typedAmount: '-5', committedAmount: 500, isCreateEntry: false, selectedCurrency: 'USD', originalCurrency: 'USD'}) returns true.
    5. Edit flow with matching negative amount (e.g. '-5' vs -500):
      • getAmountHasUnsavedChanges({typedAmount: '-5', committedAmount: -500, isCreateEntry: false, selectedCurrency: 'USD', originalCurrency: 'USD'}) returns false.

    What alternative solutions did you explore? (Optional)

    Alternative: Exposing isNegative on amountFormRef and adding signChanged parameter to getAmountHasUnsavedChanges

    We explored exposing isNegative via the imperative ref amountFormRef and passing signChanged to getAmountHasUnsavedChanges. However, this approach has notable drawbacks:

    1. Violates PR Fix iOS Track distance screen blink on swipe back #97020's architectural fix: PR Fix iOS Track distance screen blink on swipe back #97020 intentionally removed imperative ref reads during render in favor of state-driven change tracking (typedAmount) to eliminate timing windows and stale discard states during swipe transitions.
    2. Missing re-renders: If toggleNegative does not emit a change via onAmountChange, IOURequestStepAmount will not re-render when +/- is pressed, creating synchronization gaps.
    3. Unnecessary API expansion: Adding signChanged across AmountHasUnsavedChangesParams, MoneyRequestAmountFormHandle, and IOURequestStepAmount adds code overhead compared to treating the signed string ('-') as the single source of truth.

    cc @marufsharifi

  10. melvin-bot commented on Aug 20, 2026

    @melvin-bot

    📣 @Usama123talib! 📣
    Hey, it seems we don’t have your contributor details yet! You'll only have to do this once, and this is how we'll hire you on Upwork.
    Please follow these steps:

    1. Make sure you've read and understood the contributing guidelines.
    2. Get the email address used to login to your Expensify account. If you don't already have an Expensify account, create one here. If you have multiple accounts (e.g. one for testing), please use your main account email.
    3. Get the link to your Upwork profile. It's necessary because we only pay via Upwork. You can access it by logging in, and then clicking on your name. It'll look like this. If you don't already have an account, sign up for one here.
    4. Copy the format below and paste it in a comment on this issue. Replace the placeholder text with your actual details.
      Screen Shot 2022-11-16 at 4 42 54 PM
      Format:
    Contributor details
    Your Expensify account email: <REPLACE EMAIL HERE>
    Upwork Profile Link: <REPLACE LINK HERE>
    
  11. Usama123talib commented on Aug 20, 2026

    @Usama123talib

    Contributor details
    Your Expensify account email: talibusama1234@gmail.com
    Upwork Profile Link: https://www.upwork.com/freelancers/~0169f347c5f3562928

  12. melvin-bot commented on Aug 20, 2026

    @melvin-bot

    ✅ Contributor details stored successfully. Thank you for contributing to Expensify!

  13. marufsharifi commented on Aug 22, 2026

    @marufsharifi
    Contributor

    🆘 C+ Help Wanted

  14. 53 remaining items

  15. changed the title [-]Discard modal doesn’t appear after swipe if only +/- was entered in manual expense[/-] [+][$175] Discard modal doesn’t appear after swipe if only +/- was entered in manual expense[/+] on Nov 13, 2026
  16. added
    ExternalAdded to denote the issue can be worked on by a contributor
    and removed
    ExternalAdded to denote the issue can be worked on by a contributor
    on Nov 13, 2026
  17. melvin-bot commented on Nov 13, 2026

    @melvin-bot

    Triggered auto assignment to Contributor-plus team member for initial proposal review - @ikevin127 (External)

  18. changed the title [-][$175] Discard modal doesn’t appear after swipe if only +/- was entered in manual expense[/-] [+][$250] Discard modal doesn’t appear after swipe if only +/- was entered in manual expense[/+] on Nov 13, 2026
  19. mallenexpensify commented on Nov 13, 2026

    @mallenexpensify
    Contributor

    Claude posting on behalf of Matt:

    @TaduJR please take over as the Contributor. Use PR #100394 as a reference and open your own PR: #100394
    @ikevin127 please take over as C+.

    Please use MelvinBot where it can help.

  20. melvin-bot commented on Nov 13, 2026

    @melvin-bot

    Upwork job price has been updated to $250

  21. melvin-bot commented on Nov 13, 2026

    @melvin-bot

    📣 @TaduJR 🎉 An offer has been automatically sent to your Upwork account for the Contributor role 🎉 Thanks for contributing to the Expensify app!

    Offer link
    Upwork job
    Please accept the offer and leave a comment on the Github issue letting us know when we can expect a PR to be ready for review 🧑‍💻
    Keep in mind: Code of Conduct | Contributing 📖

  22. TaduJR commented on Nov 19, 2026

    @TaduJR
    Contributor

    Not Overdue.

    Working on PR.

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

Metadata

Metadata

Labels

BugSomething is broken. Auto assigns a BugZero manager.DailyKSv2ExternalAdded to denote the issue can be worked on by a contributor

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions