From 4ce58aaf05291df022d1ac604aaf3ddcf90dcfbe Mon Sep 17 00:00:00 2001 From: fatmaebrahim Date: Mon, 14 Jul 2025 20:28:37 +0300 Subject: [PATCH 1/4] fix: used contract cost function instead of consumption for contracts billing rate --- packages/grid_client/src/modules/contracts.ts | 24 +++++++++++++++++++ .../contracts_list/contracts_table.vue | 11 ++++----- packages/playground/src/utils/contracts.ts | 12 ++++++++++ 3 files changed, 40 insertions(+), 7 deletions(-) diff --git a/packages/grid_client/src/modules/contracts.ts b/packages/grid_client/src/modules/contracts.ts index 2728b55e7b..ba53c00c0d 100644 --- a/packages/grid_client/src/modules/contracts.ts +++ b/packages/grid_client/src/modules/contracts.ts @@ -29,6 +29,7 @@ import { expose } from "../helpers/expose"; import { validateInput } from "../helpers/validator"; import { Nodes } from "../primitives/nodes"; import { BaseModule } from "./base"; +import { currency } from "./currency"; import { BatchCancelContractsModel, ContractCancelModel, @@ -555,6 +556,29 @@ class Contracts { return this.client.contracts.getConsumption({ id: options.id, graphqlURL: this.config.graphqlURL }); } + /** + * Get the contract cost details per hour in TFT. + * + * @param {number} contractId - The contract cost parameters. + * @returns {Promise} A promise resolving to the cost details, + * @decorators + * - `@expose`: Exposes the method for external use. + */ + @expose + async getContractCost(contractId: number): Promise { + const HOURS_ONE_MONTH = 24 * 30; + const proxy = new GridProxyClient(this.config.proxyURL); + const contractInfo = (await proxy.contracts.list({ contractId })).data[0]; + /** Cost in USD */ + const contractMonthlyCost = await this.client.contracts.getContractCost(contractInfo, proxy); + /** Cost in TFT */ + const tftPrice = (await this.client.tftPrice.get()) ?? 0; + const contractMonthlyCostTFT = Number(new currency(tftPrice, 15).convertUSDtoTFT({ amount: contractMonthlyCost })); + /** contract cost per hour in TFT */ + const contractCost = contractMonthlyCostTFT / HOURS_ONE_MONTH; + return contractCost; + } + /** * Retrieves the deletion time of a contract based on the provided options. * diff --git a/packages/playground/src/components/contracts_list/contracts_table.vue b/packages/playground/src/components/contracts_list/contracts_table.vue index 5b0971d163..206ecd4b5b 100644 --- a/packages/playground/src/components/contracts_list/contracts_table.vue +++ b/packages/playground/src/components/contracts_list/contracts_table.vue @@ -36,19 +36,16 @@