[Cashtab] Refactor address validation to accept prefixless addresses
Summary:
T1868
Cashtab address validation has developed incrementally based on shifting demands for address format types, including bitcoincash: format, simpleledger: format, both these legacy formats and the new ecash: + etoken: standard, and only the new standard. Some exchanges have begun using valid ecash: and etoken: addresses without prefixes, so Cashtab should support these too.
Another lingering complication is that the backend only accepts addresses in bitcoincash: or simpleledger: format. So, Cashtab must preserve methods for converting to these formats (even while it does not recognize them as valid user input).
A diff was submitted (D10158) to accomplish this -- but did so by adding another layer of technical debt. At this point, the address validation should be refactored to support ecash formats.
This diff introduces new simplified methods for validating addresses input by the user.
isValidXecAddress - Accepts a valid ecash address with or without the ecash: prefix (checksum must match ecash: prefix
isValidEtokenAddress Accepts a valid etoken address with or without the etoken: prefix (checksum must match etoken: prefix
toLegacyCash - Accepts a valid ecash: address and returns a valid bitcoincash: address
toLegacyToken - Accepts a valid etoken: address and returns a valid simpleledger: address
Validation for send to many was also updated to support these new methods. Previous validation was complicated by the existence of address validation in the parseAddress function. This function has been refactored and simplified.
Some functions were moved from Ticker.js into cashMethods.js as part of this refactor because they are related to each other.
A future diff will remove the now-obsolete isValidCashPrefix and isValidTokenPrefix functions from Ticker.js and ScanQRCode.js. Another future diff will move other functions from Ticker.js that belong in cashMethods.js
Test Plan:
npm start
- Navigate to Send screen
- Enter a valid ecash address with prefix. Confirm no error
- Delete the prefix. Confirm no error.
- Enter a valid bitcoincash address with prefix. Confirm error.
- Enter a valid bitcoincash address without prefix. Confirm error.
- Enter a valid legacy BTC address. Confirm error.
- Enter a random string. Confirm error.
- Perform same tests with amounts in "multi send"
- Navigate to Send Token page. Perform steps 2-7 with simpleledger address instead of bitcoincash address.
Reviewers: #bitcoin_abc, emack
Reviewed By: #bitcoin_abc, emack
Subscribers: emack
Differential Revision: https://reviews.bitcoinabc.org/D10687