Skip to content

Conversation

@zaelgohary
Copy link
Contributor

  • Implement getTFTBillingRate n tfchain client
  • Replace get tft price w getTFTBillingRate in grid client & playground

#4340

… w getTFTBillingRate in grid client & playground
Comment on lines 23 to 25
const minPrice = (minRes.toPrimitive() as number) ?? 0;
const maxPrice = (maxRes.toPrimitive() as number) ?? 0;
const averagePrice = (avgRes.toPrimitive() as number) ?? 0;
Copy link
Member

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;
Copy link
Member

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> {
Copy link
Member

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> {
Copy link
Contributor

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

Suggested change
async getTFTBillingRateMUSD(): Promise<number> {
async getTFTBillingRatemUSD(): Promise<number> {

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 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.

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.

4 participants