Skip to content
Draft
Show file tree
Hide file tree
Changes from 3 commits
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
11 changes: 9 additions & 2 deletions packages/grid_client/src/clients/tf-grid/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,11 @@ class TFContracts extends Contracts {
* @returns {Promise<Consumption>} A promise resolving to the consumption details,
* including the amount billed and the discount received.
*/
async getConsumption(options: GetConsumptionOptions): Promise<Consumption> {
async getConsumption(
options: GetConsumptionOptions,
contract: Contract,
proxy: GridProxyClient,
Copy link
Contributor

Choose a reason for hiding this comment

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

We may have a new function called, for example, getConsumptionWithEstimation,
As these changes will break the current usage of this function in other places, and maybe in other clients

): Promise<Consumption> {
const gqlClient = new Graphql(options.graphqlURL);
const body = `query getConsumption($contractId: BigInt!){
contractBillReports(where: {contractID_eq: $contractId}, limit: 2 , orderBy: timestamp_DESC) {
Expand All @@ -305,8 +309,10 @@ class TFContracts extends Contracts {
const gqlConsumption: GqlConsumption = response["data"] as GqlConsumption;
const billReports = gqlConsumption.contractBillReports;
if (billReports.length === 0) {
const contractCostUSD = await this.getContractCost(contract, proxy);
Copy link
Contributor

Choose a reason for hiding this comment

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

no need to pass the contract only proxy client can handle that
const contract = (await proxy.contracts.list({ contractId: options.id }))[0];

const contractCostTFT = await this.convertToTFT(Decimal(contractCostUSD));
return {
amountBilled: 0,
amountBilled: contractCostTFT.div(HOURS_ONE_MONTH).toNumber(),
discountReceived: "None",
};
} else {
Expand All @@ -328,6 +334,7 @@ class TFContracts extends Contracts {
}
}
}

return {
amountBilled: amountBilled
.div(duration || 1)
Expand Down
9 changes: 8 additions & 1 deletion packages/grid_client/src/modules/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,14 @@ class Contracts {
@expose
@validateInput
async getConsumption(options: ContractConsumption): Promise<Consumption> {
return this.client.contracts.getConsumption({ id: options.id, graphqlURL: this.config.graphqlURL });
const proxy = new GridProxyClient(this.config.proxyURL);
const contractId = options.id;
const contractInfo = (await proxy.contracts.list({ contractId })).data[0];
return this.client.contracts.getConsumption(
{ id: options.id, graphqlURL: this.config.graphqlURL },
contractInfo,
proxy,
);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,18 @@
</template>

<template #[`item.consumption`]="{ item }">
<div
v-if="item?.consumption !== 0 && item?.consumption !== undefined"
class="d-flex justify-center align-center"
>
<p class="mr-2 text-no-wrap" cols="8">{{ item.consumption.toFixed(3) }} TFT/hour</p>
<div v-if="item?.consumption !== undefined" class="d-flex justify-center align-center">
<p class="mr-2 text-no-wrap" cols="8">
{{ item.consumption === 0 ? item.consumption : item.consumption.toFixed(3) }} TFT/hour
</p>

<v-tooltip v-if="item.discountPackage" bottom color="primary" close-delay="100" cols="2">
<v-tooltip v-if="item.discountPackage !== 'None'" bottom color="primary" close-delay="100" cols="2">
<template #activator="{ props: discountProps }">
<v-icon class="scale_beat" color="warning" v-bind="discountProps"> mdi-brightness-percent </v-icon>
</template>

<a
v-if="item.discountPackage === 'None'"
v-if="item.discountPackage === undefined"
class="app-link"
target="_blank"
:href="manual.discount_levels"
Expand Down