-
Notifications
You must be signed in to change notification settings - Fork 30.2k
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
[web3] Updated web3.utils.toWei()
Unit list and added default Unit value
#27528
Conversation
@zlumer Thank you for submitting this PR! 🔔 @simon-jentzsch @nitzantomer @zurbo @yxliang01 @phra @naddison36 @icaroharry @linusnorton @jpeletier @anneau @matrushka @andrevmatos @levino - please review this PR in the next few days. Be sure to explicitly select If no reviewer appears after a week, a DefinitelyTyped maintainer will review the PR instead. |
Good stuff. Will review tomorrow. |
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.
I think the "type check of the returned value" can be done more elegantly. See remark.
@@ -13,6 +13,7 @@ | |||
// Baris Gumustas <https://github.com/matrushka> | |||
// André Vitor de Lima Matos <https://github.com/andrevmatos> | |||
// Levin Keller <https://github.com/levino> | |||
// Dmitry Radkovskiy <https://github.com/zlumer> |
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.
Fair.
| "finney" | ||
| "milliether" |
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.
For reference https://web3js.readthedocs.io/en/1.0/web3-utils.html?highlight=toWei#id76
List goes not alphabetically but by the number of trailing zeros.
@@ -66,6 +71,7 @@ export default interface Utils { | |||
toDecimal(val: any): number; | |||
toHex(val: any): string; | |||
toUtf8(val: any): string; | |||
toWei(val: string | number | BigNumber, unit: Unit): string | BigNumber; | |||
toWei(val: string | number, unit?: Unit): string; | |||
toWei(val: BigNumber, unit?: Unit): BigNumber; |
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.
Reference for overloading: https://web3js.readthedocs.io/en/1.0/web3-utils.html?highlight=toWei#id77
types/web3/web3-tests.ts
Outdated
|
||
const weiStr = web3.utils.toWei("100", "gwei"); | ||
weiStr.endsWith(weiStr); | ||
const weiBn = web3.utils.toWei(web3.utils.toBN("1")); |
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.
I suggest
const weiBn: BigNumber = web3.utils.toWei(web3.utils.toBN("1"));
instead of line 22-23. What do you say?
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.
That's awesome, I don't even know why I didn't do it this way in the first place. Great idea.
@zlumer One or more reviewers has requested changes. Please address their comments. I'll be back once they sign off or you've pushed new commits or comments. Thank you! |
@zlumer Do you wanna change it? |
@levino updated. Let me know if there are more possible improvements. |
🔔 @levino - Thanks for your review of this PR! Can you please look at the new code and update your review status if appropriate? |
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.
I like it.
A definition owner has approved this PR ⭐️. A maintainer will merge this PR shortly. If it shouldn't be merged yet, please leave a comment saying so and we'll wait. Thank you for your contribution to DefinitelyTyped! |
…value (DefinitelyTyped#27528) * Updated `web3.utils.toWei()` Unit list and added default Unit value * edit tests for tslint * web3: reordered ether Unit list to match official docs * web3 tests improvement
This is a duplicate of #27137 that was unfortunately closed by bot.
I've added one more commit to better match official web3 docs.
npm test
.)npm run lint package-name
(ortsc
if notslint.json
is present).Select one of these and delete the others:
If changing an existing definition: