@@ -49,6 +49,9 @@ type MoneyRequestAmountFormProps = {
49
49
50
50
/** The current tab we have navigated to in the request modal. String that corresponds to the request type. */
51
51
selectedTab ?: SelectedTabRequest ;
52
+
53
+ /** Whether the user input should be kept or not */
54
+ shouldKeepUserInput ?: boolean ;
52
55
} ;
53
56
54
57
type Selection = {
@@ -66,7 +69,7 @@ const getNewSelection = (oldSelection: Selection, prevLength: number, newLength:
66
69
67
70
const isAmountInvalid = ( amount : string ) => ! amount . length || parseFloat ( amount ) < 0.01 ;
68
71
const isTaxAmountInvalid = ( currentAmount : string , taxAmount : number , isTaxAmountForm : boolean ) =>
69
- isTaxAmountForm && Number . parseFloat ( currentAmount ) > CurrencyUtils . convertToFrontendAmount ( Math . abs ( taxAmount ) ) ;
72
+ isTaxAmountForm && Number . parseFloat ( currentAmount ) > CurrencyUtils . convertToFrontendAmountAsInteger ( Math . abs ( taxAmount ) ) ;
70
73
71
74
const AMOUNT_VIEW_ID = 'amountView' ;
72
75
const NUM_PAD_CONTAINER_VIEW_ID = 'numPadContainerView' ;
@@ -82,6 +85,7 @@ function MoneyRequestAmountForm(
82
85
onCurrencyButtonPress,
83
86
onSubmitButtonPress,
84
87
selectedTab = CONST . TAB_REQUEST . MANUAL ,
88
+ shouldKeepUserInput = false ,
85
89
} : MoneyRequestAmountFormProps ,
86
90
forwardedRef : ForwardedRef < BaseTextInputRef > ,
87
91
) {
@@ -93,7 +97,7 @@ function MoneyRequestAmountForm(
93
97
const isTaxAmountForm = Navigation . getActiveRoute ( ) . includes ( 'taxAmount' ) ;
94
98
95
99
const decimals = CurrencyUtils . getCurrencyDecimals ( currency ) ;
96
- const selectedAmountAsString = amount ? CurrencyUtils . convertToFrontendAmount ( amount ) . toString ( ) : '' ;
100
+ const selectedAmountAsString = amount ? CurrencyUtils . convertToFrontendAmountAsString ( amount ) : '' ;
97
101
98
102
const [ currentAmount , setCurrentAmount ] = useState ( selectedAmountAsString ) ;
99
103
const [ formError , setFormError ] = useState < MaybePhraseKey > ( '' ) ;
@@ -135,7 +139,7 @@ function MoneyRequestAmountForm(
135
139
} ;
136
140
137
141
const initializeAmount = useCallback ( ( newAmount : number ) => {
138
- const frontendAmount = newAmount ? CurrencyUtils . convertToFrontendAmount ( newAmount ) . toString ( ) : '' ;
142
+ const frontendAmount = newAmount ? CurrencyUtils . convertToFrontendAmountAsString ( newAmount ) : '' ;
139
143
setCurrentAmount ( frontendAmount ) ;
140
144
setSelection ( {
141
145
start : frontendAmount . length ,
@@ -144,13 +148,13 @@ function MoneyRequestAmountForm(
144
148
} , [ ] ) ;
145
149
146
150
useEffect ( ( ) => {
147
- if ( ! currency || typeof amount !== 'number' ) {
151
+ if ( ! currency || typeof amount !== 'number' || shouldKeepUserInput ) {
148
152
return ;
149
153
}
150
154
initializeAmount ( amount ) ;
151
155
// we want to re-initialize the state only when the selected tab or amount changes
152
156
// eslint-disable-next-line react-hooks/exhaustive-deps
153
- } , [ selectedTab , amount ] ) ;
157
+ } , [ selectedTab , amount , shouldKeepUserInput ] ) ;
154
158
155
159
/**
156
160
* Sets the selection and the amount accordingly to the value passed to the input
@@ -264,13 +268,8 @@ function MoneyRequestAmountForm(
264
268
return ;
265
269
}
266
270
267
- // Update display amount string post-edit to ensure consistency with backend amount
268
- // Reference: https://github.com/Expensify/App/issues/30505
269
- const backendAmount = CurrencyUtils . convertToBackendAmount ( Number . parseFloat ( currentAmount ) ) ;
270
- initializeAmount ( backendAmount ) ;
271
-
272
271
onSubmitButtonPress ( { amount : currentAmount , currency} ) ;
273
- } , [ currentAmount , taxAmount , isTaxAmountForm , onSubmitButtonPress , currency , formattedTaxAmount , initializeAmount ] ) ;
272
+ } , [ currentAmount , taxAmount , isTaxAmountForm , onSubmitButtonPress , currency , formattedTaxAmount ] ) ;
274
273
275
274
/**
276
275
* Input handler to check for a forward-delete key (or keyboard shortcut) press.
0 commit comments