[Cashtab] Refactor parseAddressForParams to support all address and bip21 validation
Summary:
Supporting bip21, aliases, and fiat send amounts from one screen demands complex validation. This validation should be handled in a function that can be unit tested automatically.
Move address validation logic from SendXec and SendToken components into parseAddressInput function, which is called anyway, and already performs other types of validation.
Return error messages specific to bip21 parameters, if present.
Return error message specific to queryString, if present.
Add automated integration tests to SendXec and SendToken components to test these conditions.
Background
We have a lot going on in this diff. SendXec and SendToken handle slightly different input cases. Originally, only addresses were handled. Then we supported only the amount param in query strings. Then the extension implemented its own way of populating txs with txInfoFromUrl.
All of the validation should be handled in one easily unit tested function. Before this diff, validation was done piecemeal, with some occuring in the components (where it had to manually tested), and some occuring in parseAddressForParams.
After this diff, all validation except the alias server call occurs in parseAddressInput, which replaces the legacy parseAddressForParams. We now return more granular error msgs. We also have automatic integration testing to cover the more complex range of available user input, including the alias server calls. This will simplify planned support of additional bip21 features like multiple outputs and op_return_raw.
Test Plan:
npm ci
npm test
SendXec
To test QR code scanning, navigate to https://cashtab-local-dev.netlify.app on mobile
- Scan a QR code of an ecash: address and it populates in the field
- Scan a QR code of an etoken: address and it populates in the field
- Generate a QR code with params, scan it, verify it populates field with expected errors (e.g. enter ecash:qp89xgjhcqdnzzemts0aj378nfe2mhu9yvxj9nhgg6?amount=5 at https://www.qr-code-generator.com/ and verify amount field is updated and see error msgs)
- Enter a valid XEC address and amount, no validation errors (handled by npm test)
- Invalid XEC address, addr validation error (handled by npm test)
- Valid XEC address with valid amount. Amount is entered in amount field and input is disabled. (handled by npm test)
- Valid XEC address with invalid amount param. Validation error appears below amount field. Amount field is disabled. (handled by npm test)
- Valid XEC address with invalid query string. Amount and Send are disabled. Expected validation error msg. (handled by npm test)
- Above use cases with alias instead of XEC address, including alias server error and alias server unregistered response (handled by npm test)
SendToken screen
- Enter a valid XEC address, no validation errors (handled by npm test)
- Invalid XEC address, addr validation error (handled by npm test)
- Valid eToken address, no validation errors (handled by npm test)
- Valid XEC address with valid query string. Error msg that query strings are not supported for SendToken. (handled by npm test)
- Above use cases with alias instead of XEC address, including alias server error and alias server unregistered response (handled by npm test)
Reviewers: #bitcoin_abc, emack
Reviewed By: #bitcoin_abc, emack
Subscribers: emack
Differential Revision: https://reviews.bitcoinabc.org/D15139