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

use ethjs-unit for unit conversions #506

Merged
merged 1 commit into from
Jul 1, 2021

Conversation

brad-decker
Copy link
Contributor

I needed a hex wei to dec gwei conversion utility and i didn't see one existed. I also saw we already have ethjs-unit included as dependency of a dependency, this is what web3.js uses for its .toWei/.fromWei functions...

It uses BN under the hood but is far more robust than our utilities.

@brad-decker brad-decker requested a review from a team as a code owner July 1, 2021 17:58
@brad-decker brad-decker force-pushed the superior-unit-conversions branch from 34da470 to 6be939a Compare July 1, 2021 18:02
@brad-decker brad-decker force-pushed the superior-unit-conversions branch from 6be939a to 78b4c52 Compare July 1, 2021 18:04
@brad-decker brad-decker merged commit da1f81c into draft-gasfee-controller Jul 1, 2021
@brad-decker brad-decker deleted the superior-unit-conversions branch July 1, 2021 19:33
if (Number.isNaN(n)) {
return new BN(0);
}
return toWei(n.toString(), 'gwei');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this now throws an error if you input a number with too many decimal places. Beforehand it would ignore the extra decimals instead.

This seems safer. I just wanted to note the change in behaviour.

brad-decker added a commit that referenced this pull request Jul 2, 2021
brad-decker added a commit that referenced this pull request Jul 7, 2021
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.

3 participants