-
Notifications
You must be signed in to change notification settings - Fork 9
Implement getTFTBillingRate #4430
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
base: development
Are you sure you want to change the base?
Conversation
… w getTFTBillingRate in grid client & playground
| const minPrice = (minRes.toPrimitive() as number) ?? 0; | ||
| const maxPrice = (maxRes.toPrimitive() as number) ?? 0; | ||
| const averagePrice = (avgRes.toPrimitive() as number) ?? 0; |
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’m not deep into TypeScript, but this raises a question: is there a reason we’re masking the failure rather than throwing?
I think continuing with a missing or invalid value is risky, as it will produce incorrect billing while giving no indication that something went wrong, and it completely obscures the real issue, making debugging much harder.
| private async convertToTFT(USD: Decimal) { | ||
| try { | ||
| const tftPrice = (await this.client.tftPrice.get()) ?? 0; | ||
| const tftPrice = (await this.client.tftPrice.getTFTBillingRate()) ?? 0; |
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.
The same error masking happens here
| return priceInMili / 1000; | ||
| } | ||
|
|
||
| async getTFTBillingRate(): Promise<number> { |
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.
The same name getTFTBillingRate() is used at the tfchain_client and tfgrid_client, but they return different units. In the call sites, some divide by 1000 after getting the value, some don't, based on the place/client where they import the method. For example, Callers using the grid client should not divide again.
I would suggest changing the tfgrid client method name to getTFTBillingRateUSD() to avoid potential confusion about the unit returned at call sites. Optionally, the tfchain client method name can also reflect the unit (getTFTBillingRateMUSD)
| } | ||
|
|
||
| @checkConnection | ||
| async getTFTBillingRateMUSD(): Promise<number> { |
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.
The uppercase M sounds like it's millions not milli
| async getTFTBillingRateMUSD(): Promise<number> { | |
| async getTFTBillingRatemUSD(): Promise<number> { | |
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.
The capital 'M' in MUSD was used strictly to adhere to camel case convention. Within this repo, we exclusively deal with standard USD and milli-USD; we do not use the Mega prefix anywhere. Therefore, the limited scope of our units ensures there is no ambiguity for the reader.
#4340