Page MenuHomePhabricator

[Cashtab] Consolidate send xec validation functions
ClosedPublic

Authored by bytesofman on Mar 11 2024, 17:22.

Details

Reviewers
PiRK
Group Reviewers
Restricted Project
Commits
rABC996e154ec774: [Cashtab] Consolidate send xec validation functions
Summary

Cashtab send xec validation is ambiguous. We have one function, shouldRejectAmountInput, that specifically validates the user input of the SendXec field. We have another function, isValidXecSendAmount, that validates XEC send amounts for multi-send or param passing input. The rules in both cases are the same, so we should have one function.

Consolidate to a single function, isValidXecSendAmount, and implement everywhere we validate xec send amounts. Implement the new fiatToSatoshis function to replace legacy fiatToCrypto, a dependency of legacy validation approach.

Test Plan

npm test

Diff Detail

Repository
rABC Bitcoin ABC
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

PiRK accepted this revision.EditedMar 12 2024, 14:20
PiRK added a subscriber: PiRK.

Having the function return a True or a truthy string feels a bit weird and kind of violates the principle of least astonishment imo. But I can't really think of a more concise way of doing, and you documented the behavior in the doxygen comment.

No strong opinion on this, but extracting the error via an empty object passed as a param feels a little bit more familiar / less surprising to me, but maybe that's my C++ bias.
https://stackoverflow.com/a/3175838/4494781

var error = {};
if (!isLegal("something", error)) {
    alert(error.val);
}

On the other hand, this makes the isValidMultiSendUserInput and isValidXecSendAmount functions consistent, so that's a good point.

This revision is now accepted and ready to land.Mar 12 2024, 14:20