App icon indicating copy to clipboard operation
App copied to clipboard

[Due for payment 2026-12-08] [$250] Discard modal doesn’t appear after swipe if only +/- was entered in manual expense

Open applause-bot[bot] opened this issue 3 months ago • 60 comments

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: https://github.com/Expensify/App/pull/97020 Email or phone of affected tester (no customers): [email protected] 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:

  • [x] Android: App
  • [ ] Android: mWeb Chrome
  • [x] iOS: App
  • [ ] iOS: mWeb Safari
  • [ ] iOS: mWeb Chrome
  • [ ] Windows: Chrome
  • [ ] MacOS: Chrome Safari

Screenshots/Videos

https://github.com/user-attachments/assets/100eb7f2-9948-4a3b-9d09-c21921aef3bb

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: @ikevin127

applause-bot[bot] avatar Aug 20 '26 08:08 applause-bot[bot]

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

applause-bot[bot] avatar Aug 20 '26 08:08 applause-bot[bot]

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 Expensify/App#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

MelvinBot avatar Aug 20 '26 08:08 MelvinBot

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

melvin-bot[bot] avatar Aug 20 '26 08:08 melvin-bot[bot]

VERDICT: POST ROOT_CAUSE_ONELINER: PR #97020's toggleNegative in MoneyRequestAmountForm.tsx calls onAmountChange('') when the sign is toggled with no digits entered, which is indistinguishable from the initial state, so getAmountHasUnsavedChanges returns false and the discard modal is suppressed. PROPOSAL_TYPE: FIRST AUTOPOST_SAFE: YES

j3ffffff avatar Aug 20 '26 08:08 j3ffffff

Job added to Upwork: https://www.upwork.com/jobs/~022090359280174593037

melvin-bot[bot] avatar Aug 20 '26 08:08 melvin-bot[bot]

reproduced, checking the proposal.

marufsharifi avatar Aug 20 '26 13:08 marufsharifi

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 #97020's architectural fix: PR #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

Usama123talib avatar Aug 20 '26 15:08 Usama123talib

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

melvin-bot[bot] avatar Aug 20 '26 15:08 melvin-bot[bot]

Contributor details Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~0169f347c5f3562928

Usama123talib avatar Aug 20 '26 15:08 Usama123talib

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

melvin-bot[bot] avatar Aug 20 '26 15:08 melvin-bot[bot]

🆘 C+ Help Wanted

marufsharifi avatar Aug 22 '26 11:08 marufsharifi

Proposal

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

When creating a new manual expense on mobile, tapping the +/- button while the amount field is empty changes the visible sign, but the app does not consider this an unsaved change.

As a result, swiping back closes the page without displaying the discard confirmation modal.

What is the root cause of that problem?

MoneyRequestAmountForm stores the visible sign separately from the amount text.

When the user taps +/- without entering digits, the form updates local isNegative, but the amount callback reports an empty string because no numeric value exists:

const currentNumber = moneyRequestAmountInputRef.current?.getNumber() ?? '';
onAmountChange?.(currentNumber && nextIsNegative ? `-${currentNumber}` : currentNumber);

Therefore:

  • Visible sign changes from positive to negative.
  • Amount text remains "".
  • IOURequestStepAmount receives typedAmount: "".
  • The committed amount remains 0 and currency is unchanged.
  • The existing dirty check considers the page clean, so the discard guard is not enabled.

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

Keep amount text and sign state separate, and explicitly include the sign state in dirty-state detection.

  1. Add an optional sign-change callback to MoneyRequestAmountForm:
onNegativeChange?: (isNegative: boolean) => void;
  1. Notify the parent when the user toggles or clears the sign:
const toggleNegative = useCallback(() => {
    const nextIsNegative = !isNegative;
    setIsNegative(nextIsNegative);
    onNegativeChange?.(nextIsNegative);

    const currentNumber = moneyRequestAmountInputRef.current?.getNumber() ?? '';
    onAmountChange?.(currentNumber && nextIsNegative ? `-${currentNumber}` : currentNumber);
}, [isNegative, onAmountChange, onNegativeChange]);

const clearNegative = useCallback(() => {
    setIsNegative(false);
    onNegativeChange?.(false);
}, [onNegativeChange]);
  1. Keep initializeIsNegative strictly local to the form without invoking the parent callback during initialization:
const initializeIsNegative = useCallback((currentAmount: number) => {
    setIsNegative(currentAmount < 0);
}, []);
  1. Track the initial and current sign in IOURequestStepAmount, resetting them only when the active request tab changes:
const [initialIsNegative, setInitialIsNegative] = useState(() => transactionAmount < 0);
const [isAmountNegative, setIsAmountNegative] = useState(initialIsNegative);

useEffect(() => {
    const currentSign = transactionAmount < 0;
    setInitialIsNegative(currentSign);
    setIsAmountNegative(currentSign);
    setTypedAmount(undefined);
    // eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps
}, [iouRequestType]);

Pass the callback to the form:

<MoneyRequestAmountForm
    ...
    onAmountChange={setTypedAmount}
    onNegativeChange={setIsAmountNegative}
/>
  1. Include sign changes in the dirty check:
hasSignChanged: isAmountNegative !== initialIsNegative,
function getAmountHasUnsavedChanges({
    typedAmount,
    committedAmount,
    isCreateEntry,
    selectedCurrency,
    originalCurrency,
    hasSignChanged = false,
}: AmountHasUnsavedChangesParams): boolean {
    if (hasSignChanged) {
        return true;
    }

    // Existing amount and currency dirty-state logic
}

Resulting Flow:

  • Single +/- tap on an empty amount: onNegativeChange(true) → dirty → swipe-back displays the discard modal.
  • Double +/- tap on an empty amount: onNegativeChange(false) → clean → swipe-back closes without a modal.
  • Tab switch reset: Tap +/- on Manual → switch to Scan → return to Manual → sign baseline and typed amount reset.

What alternative solutions did you explore? (Optional)

An alternative is to report "-" as the amount after an empty negative toggle:

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

This is smaller because the existing dirty check sees a non-empty value. However, "-" is not a valid amount:

Number.parseFloat('-'); // NaN

Using it as a dirty-state marker mixes visual sign state with amount text and can introduce parsing edge cases.

Test plan

  • [ ] Create a manual expense, tap +/- with no digits, then swipe back: discard modal appears.
  • [ ] Tap +/- twice with no digits, then swipe back: discard modal does not appear.
  • [ ] Tap +/-, switch to Scan, return to Manual, then swipe back: discard modal does not appear.
  • [ ] Enter a numeric amount and verify existing positive/negative discard behavior remains unchanged.
  • [ ] Toggle the sign on an existing positive amount: page becomes dirty.
  • [ ] Toggle the sign back to the initial sign with no other changes: page becomes clean.
  • [ ] Verify an existing negative amount starts with the correct sign baseline.

Reproduced Demo

https://github.com/user-attachments/assets/fa344d62-5404-484a-bd13-7820e2b66283

Fixed Demo

https://github.com/user-attachments/assets/96d897b8-2282-4989-bea7-ce0000724a76

nabi-ebrahimi avatar Aug 22 '26 11:08 nabi-ebrahimi

Proposal

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

On the manual "Create expense" amount screen, if the user taps only the +/- key (toggling the sign) without typing any digit, then swipes back, the discard-changes confirmation modal does not appear — even though the user made an edit. If a digit is typed first (with or without pressing +/-), the modal appears correctly, so the bug is specific to the "sign toggled, no digits" state.

What is the root cause of that problem?

The amount screen decides whether to show the discard modal by comparing a locally-tracked typedAmount string against the empty baseline. typedAmount is only ever updated through onAmountChange, which the amount form calls both when the user types digits and when the +/- button is pressed: https://github.com/Expensify/App/blob/e6745c32e627f9c5cc2862e685535b96eb2eb34b/src/pages/iou/request/step/IOURequestStepAmount.tsx#L318

The discard hook is wired up to getAmountHasUnsavedChanges, using typedAmount (falling back to the baseline when still undefined): https://github.com/Expensify/App/blob/e6745c32e627f9c5cc2862e685535b96eb2eb34b/src/pages/iou/request/step/IOURequestStepAmount.tsx#L139-L147

The actual bug lives in toggleNegative, the handler invoked when the +/- button is pressed. It reads the current digits (currentNumber), and is supposed to report the signed value to the parent "like a keystroke would": https://github.com/Expensify/App/blob/e6745c32e627f9c5cc2862e685535b96eb2eb34b/src/pages/iou/MoneyRequestAmountForm.tsx#L158-L164

The problem is line 163: onAmountChange?.(currentNumber && nextIsNegative ? -${currentNumber} : currentNumber). When no digits have been typed, currentNumber is '' (falsy), so the && short-circuits and the ternary always resolves to the else branch — currentNumber itself ('') — regardless of nextIsNegative. In other words, the sign-toggle state is silently dropped whenever there are no digits yet, and the parent's typedAmount stays '', identical to the untouched baseline.

That empty string then flows into the create-entry branch of getAmountHasUnsavedChanges, which is a plain string comparison against '': https://github.com/Expensify/App/blob/e6745c32e627f9c5cc2862e685535b96eb2eb34b/src/libs/MoneyRequestUtils.ts#L208-L215

typedAmount !== '' || committedAmount !== 0 || currencyChanged evaluates to false, so no unsaved change is detected and the discard modal is skipped. Once at least one digit has been typed, currentNumber is truthy, so toggleNegative correctly emits -5 (say) instead of 5, typedAmount becomes non-empty, and the modal appears as expected — which matches the reported "works with digits, fails without" behavior exactly.

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

The fix belongs in toggleNegative — it should report the sign change even when there are no digits yet, instead of guarding the whole expression on currentNumber being truthy: https://github.com/Expensify/App/blob/e6745c32e627f9c5cc2862e685535b96eb2eb34b/src/pages/iou/MoneyRequestAmountForm.tsx#L162-L163

const currentNumber = moneyRequestAmountInputRef.current?.getNumber() ?? '';
onAmountChange?.(nextIsNegative ? `-${currentNumber}` : currentNumber);

Removing the currentNumber && guard means:

  • Pressing +/- once with no digits reports '-' (instead of '') to the parent. typedAmount becomes '-', which is !== '', so getAmountHasUnsavedChanges correctly returns true and the discard modal appears.
  • Pressing +/- a second time (toggling back to positive) with still no digits reports '' again — matching the baseline, so no discard modal — which is correct since the user is back to the original unedited state.
  • Typing digits first is unaffected: currentNumber is truthy in that case, so the expression behaves exactly as before.

This is a minimal, localized change: typedAmount is only ever consumed by the discard-check in IOURequestStepAmount.tsx (confirmed by searching all usages), so this doesn't affect submission logic — the imperative getNumber() handle used for actually submitting the expense is a separate code path and is unaffected by this change.

Edge cases considered:

  • Editing an existing expense: if the user clears all digits from an already-populated amount and then presses +/-, currentNumber is '', so this now reports '-' instead of ''. In the edit branch of getAmountHasUnsavedChanges, Number.parseFloat('-') is NaN, and NaN !== committedAmount is always true, so the modal still correctly appears — the same outcome as before the fix (where the prior '' also produced 0 !== committedAmount → true for any non-zero committed amount), so there's no regression there.
  • Currency change: unaffected, since currencyChanged is evaluated independently of typedAmount.
  • Web vs iOS vs Android: toggleNegative and getAmountHasUnsavedChanges are platform-agnostic shared logic, so the fix applies uniformly across all platforms.
  • Offline: this is purely client-side state comparison with no network dependency, so offline behavior is unaffected.

abbasifaizan70 avatar Aug 22 '26 11:08 abbasifaizan70

Proposal

What is the root cause of that problem?

We already report the toggled sign to the discard-dirtiness check, but we drop it whenever the amount is empty, so a sign-only flip reads as no input at all.

In the OP video the manual amount is $0 and the user taps only the Flip (+/-) key before swiping back. Tapping it runs toggleNegative, which reports the newly-signed value — but gates the sign on the number being non-empty:

https://github.com/Expensify/App/blob/be5b3677c16d29dd98c4e660dd7a02ce3dc1eb34/src/pages/iou/MoneyRequestAmountForm.tsx#L163

With no digit typed, currentNumber is '', so currentNumber && nextIsNegative is falsy and the reported value collapses to '' — the sign is lost. That '' is written straight into typedAmount via onAmountChange={setTypedAmount}, and the create-entry branch of getAmountHasUnsavedChanges reads it as clean: '' !== '' (false) || 0 !== 0 (false) || false → not dirty. useDiscardChangesConfirmation's getHasUnsavedChanges (wired here) then returns false, its beforeRemove returns early, and the swipe proceeds with no modal.

Typing any digit reports a non-empty string, so the check arms — which is why the modal works for every case except the sign-only one. This regressed in PR #97020, which gated the discard guard on unsaved changes. It is App-only because the +/- key lives on the touch-only BigNumberPad (shouldShowBigNumberPad={canUseTouchScreen}), so on non-touch web the key never renders — matching the iOS/Android-only platform matrix. The net result: the discard modal doesn't appear after swipe if only +/- was entered.

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

Stop collapsing the sign when the amount is empty in toggleNegative. Report a value that is non-empty (so the create check sees it as dirty) but still numerically zero (so nothing downstream misreads it):

onAmountChange?.(nextIsNegative ? `-${currentNumber || '0'}` : currentNumber);

An empty negative flip now reports -0 (dirty via typedAmount !== ''), a flip back to positive reports '' (clean again), and a real amount keeps its existing signed value (-5, unchanged).

This is safe and self-contained: typedAmount is consumed only by getAmountHasUnsavedChanges as the dirty signal (its single reader) — it is never submitted or displayed (submit composes the amount from the form's own getNumber, not typedAmount). And -0 parses cleanly: in the edit branch Number.parseFloat('-0') → -0 → convertToBackendAmount → -0, and -0 !== committedAmount is false at zero, so there is no false-dirty and no downstream guard is required.

Adjacent coverage: the same collapse exists in the input's own change handler at MoneyRequestAmountForm.tsx#L306-L308 — after typing a digit while negative and deleting it back to empty (the sign stays active until a further backspace triggers clearNegative), it reports '' and re-marks clean. Apply the same shape there: onAmountChange?.(isNegative ? -${newAmount || '0'} : newAmount).

What alternative solutions did you explore? (Optional)

  • Report a bare '-' and normalize it inside getAmountHasUnsavedChanges (the Melvin proposal): fixes the create case, but Number.parseFloat('-') is NaN, so convertToBackendAmount(NaN) makes the edit branch (NaN !== committedAmount) permanently dirty — forcing a second patch there. Reporting -0 keeps the change to a single site with no downstream guard.
  • Thread the form's isNegative into the dirty check as a separate boolean: more correct in spirit but adds a prop/callback and state to IOURequestStepAmount, and still has to reconcile against the committed sign in edit mode. The string channel already carries the sign for every other case, so keeping it there is smaller.

yusufdeveloper2903 avatar Aug 22 '26 11:08 yusufdeveloper2903

Proposal

What is the root cause of that problem?

The amount step has two independent user inputs — the magnitude and the +/- sign — but PR #97020's discard guard only mirrors the magnitude into render-visible dirtiness state. The sign is folded into the magnitude string, and folding a sign into an empty magnitude is impossible without producing an invalid number, so the guard is blind to a bare sign toggle.

The discard modal on the amount screen is armed by useDiscardChangesConfirmation inside IOURequestStepAmount, and its dirtiness comes entirely from typedAmount (a single string):

IOURequestStepAmount.tsx#L134-L147 — the only signal fed to getAmountHasUnsavedChanges is typedAmount ?? baselineAmount, and typedAmount is set from onAmountChange (IOURequestStepAmount.tsx#L318). There is no channel for the form's isNegative state.

The +/- key (rendered by NumberWithSymbolForm, touch-only via allowFlippingAmount && canUseTouchScreen at NumberWithSymbolForm.tsx#L765 — which is why it's App-only) flips the form's local isNegative, but the only thing that reaches the step is the signed magnitude string. With no digit typed, the magnitude is '', so the reported string is '' — sign-less — for both the toggle path (MoneyRequestAmountForm.tsx#L158-L164) and the keystroke path (MoneyRequestAmountForm.tsx#L306-L313).

So the create-entry branch of getAmountHasUnsavedChanges sees typedAmount === '' and returns clean:

MoneyRequestUtils.ts#L208-L215 — typedAmount !== '' || committedAmount !== 0 || currencyChanged → false || false || false → not dirty → beforeRemove returns early → no modal.

The bug isn't that one call site drops a sign — it's that the sign is smuggled through a string that structurally can't represent it at the empty boundary.

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

Fix layer: data/selector. Give the sign its own render-visible mirror and make "sign differs from the committed sign" a dirtiness condition — exactly the state-mirror pattern PR #97020 already applied to every other field. Keep the magnitude string a clean number; never encode a sign into it.

Three small edits:

  1. MoneyRequestAmountForm — report the sign on its own channel from toggleNegative (leave the existing onAmountChange string alone):
// inside toggleNegative, alongside the existing onAmountChange call
onNegativeChange?.(nextIsNegative);
  1. IOURequestStepAmount — mirror it and diff against the committed sign:
const baselineIsNegative = transactionAmount < 0;
const [typedIsNegative, setTypedIsNegative] = useState<boolean | undefined>(undefined);
// ...pass onNegativeChange={setTypedIsNegative} to the form, and:
signChanged: typedIsNegative !== undefined && typedIsNegative !== baselineIsNegative,
  1. getAmountHasUnsavedChanges — OR the new optional axis in:
// isCreateEntry: ... || currencyChanged || signChanged
// editing:       ... || currencyChanged || signChanged

This is race-free: dirtiness is pure derived state (mirror vs baseline), no timer or flag that a later microtask clears. A bare +/- tap now reports typedIsNegative = true against baselineIsNegative = false → signChanged → dirty → modal appears. Two taps return to baseline → clean.

Because the magnitude string stays numeric, the edit-mode diff (Number.parseFloat(typedAmount)) never has to cope with a non-numeric value — a whole class of parsing edge case simply doesn't arise.

Verification. The guard is getAmountHasUnsavedChanges, covered by tests/unit/MoneyRequestUtilsTest.ts. signChanged is an optional param defaulting to false, so all 9 existing assertions in that describe are unchanged (I traced each — the empty-field, revisit-after-Next, currency-change, and edit "5" vs "5.00" cases all evaluate identically). New failing-on-main test: getAmountHasUnsavedChanges({typedAmount:'', committedAmount:0, isCreateEntry:true, selectedCurrency:'USD', originalCurrency:'USD', signChanged:true}) → main ignores the unknown prop and returns false; with the patch it returns true. So 20 existing branches preserved + 1 new. Full disclosure: I traced this by hand rather than executing jest — my checkout has no node_modules and the repro key is touch-only, so I couldn't drive a live before/after; the assertion above is deterministic pure logic.

What alternative solutions did you explore? (Optional)

Rejected — compute dirtiness inside MoneyRequestAmountForm and lift a single hasUnsavedChanges boolean up. Falsifiable and false: the baseline the guard needs (committedAmount, selectedCurrency/originalCurrency, isCreateEntry) lives in IOURequestStepAmount, not the form — the form has no access to the committed amount, so it can't decide dirtiness alone.

Rejected — reset isNegative to baseline whenever the magnitude empties, so an empty field can't carry a stray sign. That silently flips the sign the user just tapped (a UX regression) and still wouldn't flag the reported single-tap, since the tap is the empty-negative state.

Encoding the sign into the amount string (as already proposed above) fixes the reported tap but makes the amount-diff path special-case a non-numeric value; keeping the sign on its own boolean is what lets me avoid that entirely, which is the meaningful difference here.

oqildev avatar Aug 22 '26 11:08 oqildev

Proposal

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

On iOS/Android, when you create a manual expense and tap only the +/- key (no digit) then swipe back, the discard modal doesn't appear — but it should, because you changed the form's sign. Web is unaffected: the +/- key lives in the touch-only BigNumberPad, so a non-touch browser never renders it.

What is the root cause of that problem?

The discard guard decides dirtiness from typedAmount (the string the form reports), and toggleNegative drops the sign whenever the amount is empty.

MoneyRequestAmountForm.tsx#L158-L164 — a sign flip reports currentNumber && nextIsNegative ? \-${currentNumber}` : currentNumber. With no digit, currentNumberis'', so currentNumber && nextIsNegativeis falsy and it reports''. That flows straight into typedAmount via [onAmountChange={setTypedAmount}](https://github.com/Expensify/App/blob/be5b3677c16d29dd98c4e660dd7a02ce3dc1eb34/src/pages/iou/request/step/IOURequestStepAmount.tsx#L332), and the create branch of [getAmountHasUnsavedChanges`](https://github.com/Expensify/App/blob/be5b3677c16d29dd98c4e660dd7a02ce3dc1eb34/src/libs/MoneyRequestUtils.ts#L208-L215) reads it clean:

return typedAmount !== '' || committedAmount !== 0 || currencyChanged; → '' , 0 , false → false.

So getHasUnsavedChanges returns false and the guard's beforeRemove bails — no modal — even though the on-screen - is now showing. The identical gate sits in the keystroke wrapper at MoneyRequestAmountForm.tsx#L306-L313, which yields the analogous "type -5, backspace the 5" symptom — same class, out of scope here.

I grepped typedAmount in IOURequestStepAmount: it appears only at its declaration, the getAmountHasUnsavedChanges call, and onAmountChange={setTypedAmount} — the submit path composes the amount from getNumber()+isNegative at MoneyRequestAmountForm.tsx#L202-L215, never from typedAmount. And I ran the create branch: getAmountHasUnsavedChanges({typedAmount:'-', committedAmount:0, isCreateEntry:true, USD→USD}) returns true; typedAmount:'' returns false.

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

Stop gating the reported sign on the amount being non-empty, so an empty negative flip reports '-' (dirty) and a flip back reports '' (clean).

// src/pages/iou/MoneyRequestAmountForm.tsx — toggleNegative
-        onAmountChange?.(currentNumber && nextIsNegative ? `-${currentNumber}` : currentNumber);
+        onAmountChange?.(nextIsNegative ? `-${currentNumber}` : currentNumber);
// src/libs/MoneyRequestUtils.ts — edit branch of getAmountHasUnsavedChanges
-    const typedAmountInBackendUnits = typedAmount ? convertToBackendAmount(Number.parseFloat(typedAmount)) : 0;
+    const typedAmountInBackendUnits = typedAmount ? convertToBackendAmount(Number.parseFloat(typedAmount) || 0) : 0;

Two changes. (1) is the fix — the empty sign flip now reports '-', typedAmount !== '' fires, the modal shows; toggling back reports '' and it's clean again. (2) is needed only because of (1): the create branch returns before Number.parseFloat, so the reported flow never parses '-', but the edit branch would, and Number.parseFloat('-') is NaN — which would falsely mark a $0-amount edit dirty. || 0 parses a bare - to 0, keeping −0 === 0 clean.

Safe because typedAmount is purely the dirtiness mirror; the submit value is built from getNumber() (line 202/213), so '-' can't leak into a submission.

  • Precedent: the sibling getStringFieldHasUnsavedChanges already encodes "any non-empty typed string ⇒ dirty on create"; my change just makes the sign flip produce such a string. The || 0 guard mirrors the create branch's own typedAmount ? … : 0 defense against non-numeric input.
  • Layer: form-level change signal + one guard in the pure util. No new prop, ref read, or param.
  • Edge cases: toggle-then-toggle-back → clean; typed-digit and currency-change paths unchanged.

What alternative solutions did you explore? (Optional)

Fix only the dirtiness util, leave the form alone. Can't work — on an empty sign flip none of the create branch's inputs change (typedAmount stays '', committedAmount stays 0, currency unchanged), so no util-only edit can detect it. The signal has to originate at the form.

Expose isNegative from the form and thread a new signChanged param through the util and the step. It works, but it carries the same one bit on a second channel across three files, when typedAmount — already the sole input to getAmountHasUnsavedChanges — carries it with the one-token change above.

Abdulloh0109 avatar Aug 22 '26 11:08 Abdulloh0109

Proposal

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

When creating a manual expense, tapping only the +/- (sign toggle) key without typing any digit and then swiping back does not show the discard confirmation modal. The modal is expected to appear because the user interacted with the form.

What is the root cause of that problem?

The discard guard on the amount step decides whether to show the modal from getAmountHasUnsavedChanges, which judges dirtiness purely from the typed amount string (plus currency). The sign of the amount is not part of that signal, so a sign toggle on an empty amount is invisible to it.

Concretely, the amount step mirrors the form's typed value into typedAmount and feeds it to the dirtiness check:

The form composes the reported value so that an empty amount has no negative representation — getNumber() returns '' for an empty negative because the sign is gated on the number being non-empty:

So with no digit, toggling the sign reports '', typedAmount stays '', and the create-entry branch reads it as clean:

  • MoneyRequestUtils.ts#L210-L211 — return typedAmount !== '' || committedAmount !== 0 || currencyChanged; → '' !== '' (false) || 0 !== 0 (false) || false → not dirty, so the discard guard returns early and navigation proceeds with no modal.

This is App-only (iOS/Android) because the +/- key lives in the touch-only BigNumberPad, so a non-touch browser never renders it.

The deeper point: the sign is a distinct piece of the form's state, separate from the amount value. An empty-negative is still a zero/empty amount, so an amount-only dirtiness check is correctly clean for it — the check is simply missing the sign as an input. The fix must add the sign to the dirtiness signal, not encode it back into the amount string.

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

Feed the sign into the dirtiness computation as a first-class signal, comparing the form's current sign against the committed baseline sign.

1. Expose the current sign from the form — add it to the imperative handle in MoneyRequestAmountForm.tsx (the handle already has no deps array, so it recomputes each render and reads the live isNegative):

type MoneyRequestAmountFormHandle = {
    getNumber: () => string;
    isNegative: boolean;
};
useImperativeHandle(amountFormRef, () => ({
    getNumber: () => {
        const number = moneyRequestAmountInputRef.current?.getNumber() ?? '';
        return number && isNegative ? `-${number}` : number;
    },
    isNegative,
}));

2. Add the sign to the pure dirtiness function in MoneyRequestUtils.ts via a signChanged param, so both the create and edit branches account for it:

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

3. Compute signChanged in the amount step in IOURequestStepAmount.tsx, comparing the form's current sign to the committed amount's sign:

const baselineIsNegative = transactionAmount < 0;
getHasUnsavedChanges: () =>
    getAmountHasUnsavedChanges({
        typedAmount: typedAmount ?? baselineAmount,
        committedAmount: transactionAmount,
        isCreateEntry: isAmountCreateEntry,
        selectedCurrency,
        originalCurrency,
        signChanged: (amountFormRef.current?.isNegative ?? baselineIsNegative) !== baselineIsNegative,
    }),

Now, on create (baselineIsNegative = false), tapping +/- once flips the form to negative → signChanged = true → dirty → modal shows; tapping it back → clean again. On edit it works uniformly: flipping away from the committed sign marks dirty, flipping back marks clean. No change is needed in toggleNegative, and typedAmount stays a faithful mirror of getNumber().

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

Because the sign now flows through the pure getAmountHasUnsavedChanges, it is directly unit-testable:

  • Create, empty amount, sign toggled → getAmountHasUnsavedChanges({typedAmount: '', committedAmount: 0, isCreateEntry: true, selectedCurrency: 'USD', originalCurrency: 'USD', signChanged: true}) returns true (the regression this issue reports).
  • Create, empty amount, no interaction → same call with signChanged: false returns false (no false discard prompt).
  • Edit, digits unchanged, sign flipped from the committed sign → signChanged: true returns true.
  • Edit, sign matches the committed sign → signChanged: false and an equal amount returns false.

Optionally, a component-level test on IOURequestStepAmount asserting the discard modal appears after toggleNegative on an empty manual create, then swipe/back.

What alternative solutions did you explore? (Optional)

Report '-' from toggleNegative when the amount is empty (the approach in the proposal above — driving dirtiness off the amount string alone). This works for the create branch ('-' !== ''), but it has two downsides worth flagging:

  1. It makes typedAmount diverge from getNumber() — the form never yields a bare '-' (getNumber returns '' for an empty negative), so it breaks the documented "typedAmount mirrors the amount input" invariant.
  2. Because of (1), the edit branch needs a special-case: Number.parseFloat('-') is NaN, so a bare '-' would falsely mark a $0 edit dirty unless it is normalized to 0 in the shared util.

Treating the sign as its own state (this proposal) keeps the amount string faithful to getNumber(), needs no NaN guard in the shared util, and covers create and edit with one uniform rule.

cc @marufsharifi

David-2002065 avatar Aug 22 '26 11:08 David-2002065

Unable to auto-create job on Upwork. The BZ team member should create it manually for this issue.

melvin-bot[bot] avatar Aug 22 '26 11:08 melvin-bot[bot]

🚨 Edited by proposal-police: This proposal was edited at 2026-08-22 12:32:22 UTC.

Proposal

What is the root cause of that problem?

PR #97020 moved the amount step's dirtiness off the form ref and onto a typedAmount string that the form reports on every change. The step compares that string against the committed amount, so anything the form fails to encode into it is invisible to the discard guard.

https://github.com/Expensify/App/blob/f2e972156affcdfd5386ca5cbe77273af7754535/src/pages/iou/request/step/IOURequestStepAmount.tsx#L140-L150

The form reports that string from two places, and both drop the sign when the number is empty:

https://github.com/Expensify/App/blob/f2e972156affcdfd5386ca5cbe77273af7754535/src/pages/iou/MoneyRequestAmountForm.tsx#L158-L164

https://github.com/Expensify/App/blob/f2e972156affcdfd5386ca5cbe77273af7754535/src/pages/iou/MoneyRequestAmountForm.tsx#L306-L309

What I watched happen on the emulator, on the manual amount step of a fresh create:

  • Tapped the +/- key with no digit typed. The field rendered -UZS0, so isNegative was true while the input's getNumber() was still ''.
  • currentNumber && nextIsNegative collapses to '' at that point, so the sign never left the form and setTypedAmount received an empty string.
  • The create-entry branch then evaluated '' !== '' || 0 !== 0 || false, every term false, so getHasUnsavedChanges() returned false.
  • beforeRemove read that false and returned without calling preventDefault. The swipe back landed on Home with no modal, which is the reported behaviour.
  • The identical guard sits on the input-change reporter, so deleting the last digit while the sign is on also reports ''. The number pad's backspace never calls clearNegative, so the minus stays on screen while the step reads clean.
flowchart TD
    A["Tap +/- on an empty amount"] -->|"getNumber() is ''"| B["toggleNegative reports ''"]
    B -->|"setTypedAmount('')"| C["typedAmount stays ''"]
    C -->|"create branch, '' !== '' is false"| D["getHasUnsavedChanges() returns false"]
    D -->|"beforeRemove returns before preventDefault"| E["Swipe back goes straight to Home"]

https://github.com/Expensify/App/blob/f2e972156affcdfd5386ca5cbe77273af7754535/src/libs/MoneyRequestUtils.ts#L208-L215

https://github.com/Expensify/App/blob/f2e972156affcdfd5386ca5cbe77273af7754535/src/hooks/useDiscardChangesConfirmation/index.ts#L104-L108

That last bullet matters for the fix. Patching only toggleNegative closes the key press and leaves the backspace case reporting a clean state under a visible minus, since the pad's backspace bails out on an empty number without touching the sign:

https://github.com/Expensify/App/blob/f2e972156affcdfd5386ca5cbe77273af7754535/src/components/NumberWithSymbolForm.tsx#L381-L389

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

Report the signed value from one place in the form instead of two, and drop the "only if there are digits" guard so an empty negative field reports -. That is a non-empty string, which is exactly what the create branch already treats as dirty.

+    const isNegativeRef = useRef(false);
+
+    const updateIsNegative = useCallback((value: boolean) => {
+        isNegativeRef.current = value;
+        setIsNegative(value);
+    }, []);
+
+    const reportAmountChange = useCallback(
+        (number: string) => {
+            onAmountChange?.(isNegativeRef.current ? `-${number}` : number);
+        },
+        [onAmountChange],
+    );
+
     const toggleNegative = useCallback(() => {
-        const nextIsNegative = !isNegative;
-        setIsNegative(nextIsNegative);
-        const currentNumber = moneyRequestAmountInputRef.current?.getNumber() ?? '';
-        onAmountChange?.(currentNumber && nextIsNegative ? `-${currentNumber}` : currentNumber);
-    }, [isNegative, onAmountChange]);
+        updateIsNegative(!isNegativeRef.current);
+        reportAmountChange(moneyRequestAmountInputRef.current?.getNumber() ?? '');
+    }, [reportAmountChange, updateIsNegative]);

The render site then calls reportAmountChange(newAmount), and clearNegative / initializeIsNegative route through updateIsNegative so the ref never drifts from the state. IOURequestStepAmount is the only parent that passes onAmountChange, so nothing else sees the new sentinel.

The ref is doing real work rather than dodging a lint rule. toggleNegative is also called from inside the input's own change handler when a - is typed or pasted, and that handler reports its value immediately afterwards, before a setIsNegative update could land. Reading the sign from the ref keeps whichever report comes last correct.

One guard has to stay as it is: the getNumber imperative handle keeps number && isNegative, because the submit path composes the real amount from it and must never see a bare -.

getAmountHasUnsavedChanges also needs to know what - is worth, since Number.parseFloat('-') is NaN and would compare unequal to everything in the edit branch:

-    const typedAmountInBackendUnits = typedAmount ? convertToBackendAmount(Number.parseFloat(typedAmount)) : 0;
+    const typedAmountInBackendUnits = typedAmount && typedAmount !== '-' ? convertToBackendAmount(Number.parseFloat(typedAmount)) : 0;

With this in place the same swipe raised the "Discard changes?" modal on the emulator, and typing a digit then continuing still behaves as before. tests/ui/MoneyRequestAmountFormTest.tsx covers the form half: the empty-flip case and the delete-last-digit case both fail on current main with Expected: "-", Received: "", and pass with the change, while a plain positive amount still reports 5 unsigned either way. Three cases in MoneyRequestUtilsTest cover the sentinel itself, and the edit-branch one fails without the guard, returning true where NaN made an unchanged zero look dirty.

What alternative solutions did you explore? (Optional)

I looked at passing isNegative up to IOURequestStepAmount as its own value and folding it into the dirtiness check there. It works, but it widens the callback contract and leaves two sources of truth for the same sign that the form already encodes into the string it sends.

I also considered clearing the sign whenever the field empties, so the display and the reported value agree the other way round. That would make the modal correct while silently undoing a flip the user deliberately made, which reads worse than the bug.

mukhrr avatar Aug 22 '26 11:08 mukhrr

Proposal

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

When creating a manual expense on Android/iOS, tapping only the +/- key (without typing any digit) and then swiping back does not show the discard-changes confirmation modal — even though the amount field visibly shows the minus sign, i.e. the user has entered something.

What is the root cause of that problem?

The discard guard on the amount step reads a typedAmount state that mirrors the amount input. The form reports every change into that mirror through the onAmountChange callback, and toggleNegative composes the reported value as currentNumber && nextIsNegative ? '-' + currentNumber : currentNumber:

https://github.com/Expensify/App/blob/c156d5f334a5840a577812693f17455f94615d6d/src/pages/iou/MoneyRequestAmountForm.tsx#L158-L164

When only the +/- key has been tapped, getNumber() returns an empty string, so the currentNumber && short-circuit makes the callback report '' instead of '-'. The guard therefore evaluates dirtiness with typedAmount: '':

https://github.com/Expensify/App/blob/c156d5f334a5840a577812693f17455f94615d6d/src/pages/iou/request/step/IOURequestStepAmount.tsx#L134-L147

and the create-entry check typedAmount !== '' || committedAmount !== 0 || currencyChanged is false on a fresh manual expense:

https://github.com/Expensify/App/blob/c156d5f334a5840a577812693f17455f94615d6d/src/libs/MoneyRequestUtils.ts#L208-L215

so useDiscardChangesConfirmation treats the form as clean and lets the swipe-back proceed without the modal. Meanwhile the input itself still renders the standalone minus sign even with no digits typed (the sign is drawn from the isNegative flag, independent of the number), so there is visible unsaved input on screen that the guard is blind to.

The same short-circuit exists on the keystroke path (newAmount && isNegative ? '-' + newAmount : newAmount), so deleting all digits while the sign is active also reports '' while the field still displays the minus:

https://github.com/Expensify/App/blob/c156d5f334a5840a577812693f17455f94615d6d/src/pages/iou/MoneyRequestAmountForm.tsx#L303-L313

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

In MoneyRequestAmountForm, report the sign as user input even when no digits have been typed:

  1. In toggleNegative, drop the currentNumber && guard so composing the reported value with an empty number and an active sign yields a lone '-' (i.e. report nextIsNegative ? '-' + currentNumber : currentNumber).
  2. Apply the same composition in the input's onAmountChange handler (report isNegative ? '-' + newAmount : newAmount), so deleting every digit while the sign is active still reports '-', matching what the field displays.
  3. In clearNegative — which runs when backspace removes the sign from an empty field — also report the now-unsigned current number, so the mirrored typedAmount does not stay stale at '-' after the sign is gone.

With a lone '-' reported, the existing create-entry check typedAmount !== '' becomes true and the discard modal appears after the swipe, exactly as the test step expects. Toggling the sign back off reports '' again, so a visually clean form still dismisses without a prompt. The edit path also stays correct: a bare '-' parses to NaN, which never equals the committed amount, so a field cleared down to just the minus counts as changed. No changes are needed in the guard or in getAmountHasUnsavedChanges itself.

Compare branch: https://github.com/Expensify/App/compare/main...wildan-m:App:wildan/99042-report-sign-as-typed-amount?expand=1

What alternative solutions did you explore? (Optional)

Making the guard sign-aware at the page level instead — e.g. having IOURequestStepAmount track the sign separately or read the form's imperative getNumber() handle (which has the same number && isNegative short-circuit and would need the same one-line fix). This works, but it splits the "what did the user type" knowledge across two places; keeping the single typedAmount mirror as the sole source of truth and fixing the reporting at the form level is smaller and matches the design of the existing guard wiring.

wildan-m avatar Aug 22 '26 11:08 wildan-m