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