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

Fix: billing rate on first billing cycle #3490

Merged
merged 2 commits into from
Oct 8, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions packages/grid_client/src/clients/tf-grid/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ export interface GqlContracts {
}

export interface GqlConsumption {
contracts: GqlContracts;
nameContracts: GqlNameContract[];
nodeContracts: GqlNodeContract[];
rentContracts: GqlRentContract[];
Copy link
Contributor

Choose a reason for hiding this comment

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

you can extend this interface instead GqlContracts

contractBillReports: GqlContractBillReports[];
}

Expand Down Expand Up @@ -239,16 +241,16 @@ class TFContracts extends Contracts {
if (billReports.length === 0) {
return 0;
} else {
let duration: number;
let duration = 1;
const amountBilled = new Decimal(billReports[0].amountBilled);
if (billReports.length === 2) {
duration = (billReports[0].timestamp - billReports[1].timestamp) / 3600; // one hour
} else {
let createdAt: number;
for (const contracts of [
gqlConsumption.contracts.nodeContracts,
gqlConsumption.contracts.nameContracts,
gqlConsumption.contracts.rentContracts,
gqlConsumption.nodeContracts,
gqlConsumption.nameContracts,
gqlConsumption.rentContracts,
]) {
if (contracts.length === 1) {
createdAt = +contracts[0].createdAt;
Expand All @@ -257,11 +259,8 @@ class TFContracts extends Contracts {
}
}
}
if (!duration) {
duration = 1;
}
return amountBilled
.div(duration)
.div(duration || 1)
.div(10 ** 7)
.toNumber();
}
Expand Down
Loading