diff --git a/src/components/MoneyRequestAmountInput.tsx b/src/components/MoneyRequestAmountInput.tsx index 85bb79f85518..791b3e4d5e48 100644 --- a/src/components/MoneyRequestAmountInput.tsx +++ b/src/components/MoneyRequestAmountInput.tsx @@ -88,18 +88,6 @@ type MoneyRequestAmountInputProps = { * Autogrow input container length based on the entered text. */ autoGrow?: boolean; - - /** - * Determines whether the amount should be reset. - */ - shouldResetAmount?: boolean; - - /** - * Callback function triggered when the amount is reset. - * - * @param resetValue - A boolean indicating whether the amount should be reset. - */ - onResetAmount?: (resetValue: boolean) => void; }; type Selection = { @@ -135,8 +123,6 @@ function MoneyRequestAmountInput( hideFocusedState = true, shouldKeepUserInput = false, autoGrow = true, - shouldResetAmount, - onResetAmount, ...props }: MoneyRequestAmountInputProps, forwardedRef: ForwardedRef, @@ -216,21 +202,10 @@ function MoneyRequestAmountInput( })); useEffect(() => { - const frontendAmount = onFormatAmount(amount, currency); - setCurrentAmount(frontendAmount); - if (shouldResetAmount) { - setSelection({ - start: frontendAmount.length, - end: frontendAmount.length, - }); - onResetAmount?.(false); - return; - } - if ((!currency || typeof amount !== 'number' || (formatAmountOnBlur && isTextInputFocused(textInput))) ?? shouldKeepUserInput) { return; } - + const frontendAmount = onFormatAmount(amount, currency); setCurrentAmount(frontendAmount); // Only update selection if the amount prop was changed from the outside and is not the same as the current amount we just computed @@ -241,7 +216,10 @@ function MoneyRequestAmountInput( end: frontendAmount.length, }); } - }, [amount, currency, formatAmountOnBlur, shouldKeepUserInput, onFormatAmount, shouldResetAmount, onResetAmount, currentAmount]); + + // we want to re-initialize the state only when the amount changes + // eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps + }, [amount, shouldKeepUserInput]); // Modifies the amount to match the decimals for changed currency. useEffect(() => { diff --git a/src/components/MoneyRequestConfirmationList.tsx b/src/components/MoneyRequestConfirmationList.tsx index 98ed13a08363..772b1476b84a 100755 --- a/src/components/MoneyRequestConfirmationList.tsx +++ b/src/components/MoneyRequestConfirmationList.tsx @@ -300,7 +300,7 @@ function MoneyRequestConfirmationList({ const isMerchantRequired = isPolicyExpenseChat && (!isScanRequest || isEditingSplitBill) && shouldShowMerchant; const isCategoryRequired = !!policy?.requiresCategory; - const [shouldResetAmount, setShouldResetAmount] = useState(false); + useEffect(() => { if (shouldDisplayFieldError && didConfirmSplit) { setFormError('iou.error.genericSmartscanFailureMessage'); @@ -479,8 +479,6 @@ function MoneyRequestConfirmationList({ onFormatAmount={CurrencyUtils.convertToDisplayStringWithoutCurrency} onAmountChange={(value: string) => onSplitShareChange(participantOption.accountID ?? -1, Number(value))} maxLength={formattedTotalAmount.length} - shouldResetAmount={shouldResetAmount} - onResetAmount={(resetValue) => setShouldResetAmount(resetValue)} /> ), })); @@ -503,7 +501,6 @@ function MoneyRequestConfirmationList({ transaction?.comment?.splits, transaction?.splitShares, onSplitShareChange, - shouldResetAmount, ]); const isSplitModified = useMemo(() => { @@ -521,7 +518,6 @@ function MoneyRequestConfirmationList({ { IOU.resetSplitShares(transaction); - setShouldResetAmount(true); }} accessibilityLabel={CONST.ROLE.BUTTON} role={CONST.ROLE.BUTTON}