-
Notifications
You must be signed in to change notification settings - Fork 1
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(BigNumberInput): Extendable component #100
Conversation
This is a copy of the `big-number-input` library, with modifications to avoid using BigNumber and migrate to the use of native BigInt. Tests were added to ensure that the minimum functionality is met.
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
# Conflicts: # package.json
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.
Just checked the functionality (not the code), it seems to work all right.
Let's wait for a more technical review from @luchobonatti before merging.
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.
@fernandomg Nice job, the code is clean and understandable and has tests! :D !
I have some doubts about this component:
- I'm not sure about the component name "BigNumberInput". What about CurrencyInput, TokenInput, AssetInput?
- Is there a way to format the number in the input? like changing the thousand separator and decimal separator?
- What happens in a real use case when the user changes the decimals prop and the input has a previous value with another decimals?
- Shouldn’t handling the input with bigInt instead of number-as-string be better?
- now decimals prevent the user from typing more than the valid amount of decimals.
- In uniswap, you can put any amount of decimals in any token. I guess that we can take a similar approach here and handle the decimal amount behind the scenes. What do you think?
font-weight: 400; | ||
` | ||
|
||
const decimals = 6 |
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 a real use case this value can change by the user.
hey @luchobonatti, thanks for the thorough feedback!
With those names, you're restricting the component's use. I'm not a fan of that approach. At most "BigInput" or "BigIntInput" but both seem to be a bit off.
Yes, there is, on a different task. As we talked in Slack.
That must be something that the user implementing the state around the component should handle, why the component must reset its state on those conditions? Maybe you're trying to build an "AmountInput" with all that functionality, but that shouldn't be part of a base component.
Well, my reasoning was: If I'm giving the control to the "implementer", that "implementer" will have the necessary information to cast the value to bigInt or BigNumber, or Big, or whatever they want. With all that said, what will be the most common case? Because if everybody is casting the value back to a BigInt, we can change the returned value. Even more, we can give the option to opt for BigInt or HumanReadable. WDYT?
We shouldn't allow more than the required amount of decimals. That's why I copied the behavior from the gnosis-bridge implementation. I'll wait for your feedback before moving fw with the modifications. Thanks again and keep them coming! |
Well, I think all is there. Thank you for your time to well-answer my doubts! |
Closes #26
Description:
This PR includes a modification of
big-number-input
library.The original idea was to include it as it is, and then modify it to avoid using "BigNumber" dependencies. It was impossible as its current implementation relies on that library to handle max/min values.
Thus, I modified it to use
viem
'sparseUnit
andformatUnit
, which use the native BigInt behind the scenes.I also added a couple of missing functionalities, so we don't need to always rely on a personalized component:
disabled
attribute is now supporteddecimals
prevent the user from typing more than the valid amount of decimals.Also, tests were added to ensure consistency in the functionality.
To be able to test a react component, some dependencies were added:
Also, vitest configuration was slightly modified.
Steps:
You can test it in /tokens, there's
ADemoInput
component being rendered with default valuesType of change:
How Has This Been Tested?
Remember to check that:
Screenshots
Screen.Recording.2024-06-06.at.8.17.41.PM.mov