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

Make gweiDecToWEIBN util resilient against params with too many decimals #544

Merged
merged 3 commits into from
Jul 28, 2021

Conversation

danjm
Copy link
Contributor

@danjm danjm commented Jul 28, 2021

gweiDecToWEIBN uses toWei from ethjs-unit

toWei will throw an error if it receives more than 9 decimal places when converting from gwei (because WEI cannot have decimal parts)

given that gweiDecToWEIBN can receive data from an external api, errors can happen if that data is flawed in having too many decimal places.

This PR ensures that such faulty data is correctly handled.

@danjm danjm requested a review from a team as a code owner July 28, 2021 12:36
dan437
dan437 previously approved these changes Jul 28, 2021
}

const decimalPartToRemove = decimalPart.slice(9);
const decimalRoundingDigit = decimalPartToRemove[0];
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice! I was about to comment on the previous code, but this updated version looks great!

Copy link
Member

@andrepimenta andrepimenta left a comment

Choose a reason for hiding this comment

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

LGTM!

@danjm danjm merged commit 873c585 into main Jul 28, 2021
@danjm danjm deleted the gweiDecToWEIBN-improvement branch July 28, 2021 14:53
@rickycodes rickycodes mentioned this pull request Jul 28, 2021
rickycodes added a commit that referenced this pull request Aug 3, 2021
…to dynamic-speed-up

* 'dynamic-speed-up' of github.com:MetaMask/controllers:
  Bump @metamask/auto-changelog from 2.4.0 to 2.5.0 (#549)
  Update Changelog (#548)
  14.0.2 (#547)
  Fix `resetPolling` functionality (#546)
  TokenService improvements (#541)
  Release/14.0.1 (#545)
  Make gweiDecToWEIBN util resilient against params with too many decimals (#544)
  Bump @metamask/contract-metadata from 1.27.0 to 1.28.0 (#540)
  14.0.0 (#539)
  Bug: Mainnet NFT Autodetect API  (#536)
MajorLift pushed a commit that referenced this pull request Oct 11, 2023
…als (#544)

* Make gweiDecToWEIBN util resilient against params with too many decimals

* Handle special rounding cases when there are more than 10 decimals passed to gweiDecToWEIBN

* Normalize invalid decimal responses from gasFeeEstimates api
MajorLift pushed a commit that referenced this pull request Oct 11, 2023
…als (#544)

* Make gweiDecToWEIBN util resilient against params with too many decimals

* Handle special rounding cases when there are more than 10 decimals passed to gweiDecToWEIBN

* Normalize invalid decimal responses from gasFeeEstimates api
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