Skip to content

Commit 5568f75

Browse files
author
Emre Bogazliyanlioglu
committed
fix: the lingering quote after token switch
Signed-off-by: Emre Bogazliyanlioglu <emre@wormholelabs.xyz>
1 parent ef0d706 commit 5568f75

2 files changed

Lines changed: 22 additions & 6 deletions

File tree

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/views/v3/Bridge/AssetPicker/index.tsx

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)