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

Migrate data type conversion utils functions from 1.x #4405

Merged
merged 10 commits into from
Oct 6, 2021

Conversation

nazarhussain
Copy link
Contributor

Description

Create conversion functions for web3-utils

Fixes #4350

Type of change

  • New feature (non-breaking change which adds functionality)

Checklist:

  • I have selected the correct base branch.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have made corresponding changes to the documentation.
  • My changes generate no new warnings.
  • Any dependent changes have been merged and published in downstream modules.
  • I ran npm run dtslint with success and extended the tests and types if necessary.
  • I ran npm run test:unit with success.
  • I ran npm run test:cov and my test cases cover all the lines and branches of the added code.
  • I ran npm run build and tested dist/web3.min.js in a browser.
  • I have tested my code on the live network.
  • I have checked the Deploy Preview and it looks correct.
  • I have updated the CHANGELOG.md file in the root folder.

@nazarhussain nazarhussain self-assigned this Sep 29, 2021
@nazarhussain nazarhussain linked an issue Sep 29, 2021 that may be closed by this pull request
@spacesailor24 spacesailor24 added the 4.x 4.0 related label Sep 30, 2021
Base automatically changed from nh/4349-web3-utils to 4.x September 30, 2021 10:46
@nazarhussain nazarhussain marked this pull request as ready for review October 1, 2021 22:34
Copy link
Contributor

@spacesailor24 spacesailor24 left a comment

Choose a reason for hiding this comment

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

There aren't any tests for BigDecimal

tether: expo10(30),
};

const errorMessage = (value: unknown, error: string) =>
Copy link
Contributor

Choose a reason for hiding this comment

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

I would think this should be defined in errors.ts to be used by all the inline errors below

@luu-alex
Copy link
Contributor

luu-alex commented Oct 4, 2021

Since we are replacing bn.js with just using the type bigint we should probably make a note.

As it looks like we are removing the toBN function

@nazarhussain
Copy link
Contributor Author

@luu-alex Yes we are replacing bn.js with native bigint. So any function related to it will also be removed.

Comment on lines 281 to 283
if (numberOfZerosInDenomination <= 0) {
return number.toString();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand what's happening here, could you clarify with a comment?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh I think I understand, this handles if the provided unit is wei or noether?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes you are right.


// value in wei would always be integer
// 13456789, 1234
const value = String(toNumber(number));
Copy link
Contributor

Choose a reason for hiding this comment

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

Is all the casting necessary? Above you just do number.toString()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The input number is of type Numbers which is better to be casted with toNumber as it could include HexString as well.

@nazarhussain nazarhussain merged commit e634254 into 4.x Oct 6, 2021
@nazarhussain nazarhussain deleted the nh/4350-web3-utils-converters branch October 6, 2021 18:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4.x 4.0 related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Migrate data type conversion utils functions from 1.x
3 participants