satoshipay / solar

🌞 Stellar wallet. Secure and user-friendly.
https://solarwallet.io
MIT License
191 stars 59 forks source link

Fix trading form input field issues #1253

Closed ebma closed 3 years ago

ebma commented 3 years ago

Fixes issues on iOS where the user was unable to enter a valid amount because the on-screen keyboard only showed a comma which was not accepted by the validation mechanism (when the device is set up for EU regions).

Seems like this issue appears on iOS only. When entering a value with a comma into the input field (either the primary amount or manual price, does not matter) it is not propagated correctly, i.e. the onChange event only contains "". Removing the type: "number" prop helps here, but this is not enough as Big.js somehow still has issues with the comma string and throws an Invalid number error when trying to instantiate a new Big(). That's where the replaceCommaWithDot(input:string) function comes into play.

Also closes #1251 by re-introducing the validation rule such that the price input field will already show an "Invalid amount" error instead of first showing it when the user clicks on the submit button.

ebma commented 3 years ago

I moved the new utility functions to a new file and created a new function called FormBigNumber() which should be used instead of BigNumber() whenever we are instantiating a Big with user input. And I also changed the regex such that .xx or ,xx are also accepted.