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

Proper units (Wei, Tokens, Ratio) #59

Merged
merged 9 commits into from
May 16, 2019
Merged

Proper units (Wei, Tokens, Ratio) #59

merged 9 commits into from
May 16, 2019

Conversation

phraktle
Copy link
Contributor

No description provided.

@phraktle phraktle requested review from rszaloki and szerintedmi May 14, 2019 15:34
Copy link
Member

@szerintedmi szerintedmi left a comment

Choose a reason for hiding this comment

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

Great one in general! A few semantic suggestions/questions

  1. instead of Tokens.parse(string) wouldn't be better:
    Tokens(string|number|BN|Tokens)
    It's the defacto constructor standard in bn.js and BigNumber (although it doesn't mean it's the best way.. )

  2. Percent is not really percent.. Should it be Ppm ?

  3. Tokens.of(number), Percent.of(number) and Wei.of(number) :

    • .of reads a bit weird for me. not sure what would be better. Idea:. Wei.fromEth, Ppm.fromPercent and Tokens.fromDecimal ?
    • allow .of(number | string )?

@phraktle
Copy link
Contributor Author

phraktle commented May 14, 2019

  1. instead of Tokens.parse(string) wouldn't be better:
    Tokens(string|number|BN|Tokens)
    It's the defacto constructor standard in bn.js and BigNumber (although it doesn't mean it's the best way.. )

I don't consider this a good practice: if you meant to parse a string, a type error should be thrown if you pass in anything else. Also, other parameters may be added later, which may not make sense for other types (e.g. base).

  1. Percent is not really percent.. Should it be Ppm ?

Started off with PPM, but Percent seemed better for fluent readability and semantics (it's a dimensionless ratio and would still make sense if we happened to use 5 or 7 digits of precision). Potential alternatives are Fraction, Ratio or Rate. But I'm okay with PPM as well.

(Btw, I was considering Ethers instead of Wei. What do you think?)

  1. Tokens.of(number), Percent.of(number) and Wei.of(number) :

    • .of reads a bit weird for me. not sure what would be better. Idea:. Wei.fromEth, Ppm.fromPercent and Tokens.fromDecimal ?

A more verbose form would make readability worse in test cases (plenty of constants there). Foo.from(..) might be okay, if you find that more pleasant to read.

  • allow .of(number | string )?

same as above, with even more confusion (number is treated as a decimal. should a string be interpreted the same way here?)

Copy link
Contributor

@rszaloki rszaloki left a comment

Choose a reason for hiding this comment

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

Please fix ts lint errors!

@phraktle
Copy link
Contributor Author

@rszaloki is there a build target to run the linter? Or if it’s some other process, could you please add it to the README?

@phraktle
Copy link
Contributor Author

@szerintedmi Percent renamed to Ratio.

@rszaloki Fixed some linter warnings. Some others I happen to disagree with :)

@phraktle phraktle changed the title Proper units (Wei, Tokens, Percent) Proper units (Wei, Tokens, Ratio) May 15, 2019
@phraktle phraktle marked this pull request as ready for review May 15, 2019 19:54
@phraktle phraktle requested a review from szerintedmi May 15, 2019 19:55
@szerintedmi szerintedmi merged commit 44d6ac9 into staging May 16, 2019
@szerintedmi szerintedmi deleted the units branch May 16, 2019 11:13
rszaloki pushed a commit that referenced this pull request May 16, 2019
* staging:
  Proper units (Wei, Tokens, Ratio) (#59)

# Conflicts:
#	src/Exchange.ts
#	src/constants.ts
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