@@ -292,15 +292,31 @@ function AssetPicker(props: Props) {
292292 </ Typography >
293293 ) : null ;
294294
295- const handleAmountChange = useCallback ( ( newValue : string ) : void => {
296- setAmountInput ( newValue ) ;
297- setSelectedPercentButton ( 0 ) ; // Reset selected percent button when amount changes
298- } , [ ] ) ;
295+ const handleAmountChange = useCallback (
296+ ( newValue : string ) : void => {
297+ setAmountInput ( newValue ) ;
298+ setSelectedPercentButton ( 0 ) ; // Reset selected percent button when amount changes
299+
300+ if ( ! newValue ) {
301+ // If the input is cleared, we need to clear the amount in handleAmountChange instead of handleDebouncedAmountChange.
302+ // This case is important when user switches the token selection, which results in clearing the amount.
303+ // If we do this in handleDebouncedAmountChange, it will get a new quote for the previous amount before clearing it
304+ // and may cause the received amount to set to that quoted amount after user clears the input.
305+ dispatch ( setAmount ( newValue ) ) ;
306+ }
307+ } ,
308+ [ dispatch ] ,
309+ ) ;
299310
300311 const handleDebouncedAmountChange = useCallback (
301312 ( newValue : string ) : void => {
302- dispatch ( setAmount ( newValue ) ) ;
303313 setDebouncedAmountInput ( newValue ) ;
314+ if ( newValue ) {
315+ // Only update the amount in the store if the input is not empty
316+ // When the amount is cleared, it is handled in handleAmountChange
317+ // Please see the comments in handleAmountChange for more details.
318+ dispatch ( setAmount ( newValue ) ) ;
319+ }
304320 } ,
305321 [ dispatch ] ,
306322 ) ;
0 commit comments