fix: allow pasting amounts with thousand separators into the swap amount input #1361
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Pasting amounts with thousand separators (e.g., 12,500) into the widget’s amount input is not supported, requiring users to manually remove the commas first.
Fixes # (issue)
Previously, the swap amount input used the number type. To allow users to paste token amounts with thousand separators, we needed to switch the input to text, and I’ve made that change.
We also need a way to parse the raw text input into a valid number. For this, I added a function called
parseNumericValue, which takes the raw input string and converts it into a valid numeric value. This function:strips letters, spaces, commas, and symbols
preserves digits (0–9)
keeps only the first . as the decimal separator
We already have existing sanitizers for user input (such as removing leading or trailing zeros). These can remain unchanged; we only use parseNumericValue to convert the raw text into a valid number that the existing sanitizers can then process.
Additionally, I updated the
sanitizeInputAmountfunction (triggered on input blur) so that if the value ends with a decimal separator and has no decimal part, the separator is removed.How did you test this change?
Try entering both text and numbers. Only digits and a single decimal separator should be accepted in the input.
Paste different combinations of characters and numbers—the value displayed in the input should always be a valid number. For example:
"300,222" → "300222"
"12a3.4b5" → "123.45"
"1.2.3.4" → "1.234"
".5" → ".5"
Checklist: