Skip to content

use ethjs-unit for unit conversions - #506

Merged
brad-decker merged 1 commit into
draft-gasfee-controllerfrom
superior-unit-conversions
Jul 1, 2021
Merged

use ethjs-unit for unit conversions#506
brad-decker merged 1 commit into
draft-gasfee-controllerfrom
superior-unit-conversions

Conversation

@brad-decker

Copy link
Copy Markdown
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 ownerJuly 1, 2021 17:58
@brad-decker
brad-deckerforce-pushed the superior-unit-conversions branch from 34da470 to 6be939aCompareJuly 1, 2021 18:02
@brad-decker
brad-deckerforce-pushed the superior-unit-conversions branch from 6be939a to 78b4c52CompareJuly 1, 2021 18:04
@brad-decker
brad-decker merged commit da1f81c into draft-gasfee-controllerJul 1, 2021
@brad-decker
brad-decker deleted the superior-unit-conversions branch July 1, 2021 19:33
Comment threadsrc/util.ts
if (Number.isNaN(n)) {
return new BN(0);
}
return toWei(n.toString(), 'gwei');

Copy link
Copy Markdown
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 freeto 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

@brad-decker@darkwing@Gudahtt