Skip to content
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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

DenysKarmazynDFINITY
Copy link
Contributor

Motivation

The util that will be used in ConvertAmountSource as customValidate function for the input. I extracted it from the component for the unit testing purposes.

Copy link
Collaborator

@AntonioVentilii AntonioVentilii left a 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;
Copy link
Collaborator

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?

Copy link
Contributor Author

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)) {
Copy link
Collaborator

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

Copy link
Contributor Author

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!

Copy link
Contributor Author

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 :)

@DenysKarmazynDFINITY
Copy link
Contributor Author

DenysKarmazynDFINITY commented Nov 16, 2024

@AntonioVentilii they are a few differences between them (mostly, in return types - one uses strings, and another one Error), but my idea was that they indeed can be standardised and reused in the future. I added a TODO comment for now.

P.S.: a good moment to do it would be while migrating the Send flow to the new design.

@DenysKarmazynDFINITY
Copy link
Contributor Author

@AntonioVentilii ready for another look

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants