-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(frontend): validateConvertAmount util #3585
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In component SendAmount
we have a similar logic: is there any way that the two functions can be merged? Meaning, can we use your function there too?
totalFee?: bigint; | ||
}): ConvertAmountErrorType => { | ||
if (isNullish(totalFee)) { | ||
return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I saw that in the code we do the same elsewhere, but I don't remember why? is it possible that the validation comes in another component when the fee is nullish?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good point. After thinking about it, I think it makes sense to validate insufficient-funds
case even if totalFee
is nullish. Therefore, I removed this check and adjusted the tests.
return 'insufficient-funds'; | ||
} | ||
|
||
if (nonNullish(totalFee) && userAmount.add(totalFee).gt(parsedSendBalance)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
theoretically here the nonNullish
function is not needed, right? you already checked above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, good catch, removing it!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doch - the check stays because of the comments above :)
@AntonioVentilii they are a few differences between them (mostly, in return types - one uses P.S.: a good moment to do it would be while migrating the Send flow to the new design. |
@AntonioVentilii ready for another look |
Motivation
The util that will be used in
ConvertAmountSource
ascustomValidate
function for the input. I extracted it from the component for the unit testing purposes.