diff --git a/packages/grid_client/src/clients/tf-grid/contracts.ts b/packages/grid_client/src/clients/tf-grid/contracts.ts index 122124a64d..715eaa07af 100644 --- a/packages/grid_client/src/clients/tf-grid/contracts.ts +++ b/packages/grid_client/src/clients/tf-grid/contracts.ts @@ -79,6 +79,9 @@ export interface GqlContracts { export interface GqlConsumption extends GqlContracts { contractBillReports: GqlContractBillReports[]; } +export interface GqlDiscountPackage { + contractBillReports: GqlContractBillReports[]; +} export interface GqlContractBillReports { id: string; @@ -107,6 +110,11 @@ export interface GetConsumptionOptions { id: number; } +export interface GetDiscountPackageOptions { + graphqlURL: string; + id: number; +} + export interface CancelMyContractOptions { graphqlURL: string; } @@ -251,7 +259,37 @@ class TFContracts extends Contracts { throw err; } } + /** + * Get contract discount package + * @param {GetDiscountPackageOptions} options + * @returns {Promie} + */ + async getDiscountPackage(options: GetDiscountPackageOptions): Promise { + const gqlClient = new Graphql(options.graphqlURL); + + const body = `query getConsumption($contractId: BigInt!){ + contractBillReports(where: {contractID_eq: $contractId} , orderBy: timestamp_DESC) { + discountReceived + + } + }`; + + try { + const response = await gqlClient.query(body, { contractId: options.id }); + const gqlDiscountPackage: GqlDiscountPackage = response["data"] as GqlDiscountPackage; + const billReports = gqlDiscountPackage.contractBillReports; + if (billReports.length === 0) { + return "None"; + } else { + const discountPackage = billReports[billReports.length - 1].discountReceived; + return discountPackage; + } + } catch (err) { + (err as Error).message = formatErrorMessage(`Error getting discount package for contract ${options.id}.`, err); + throw err; + } + } /** * Get contract consumption per hour in TFT. * diff --git a/packages/grid_client/src/modules/contracts.ts b/packages/grid_client/src/modules/contracts.ts index c92c01b444..1dca479e2f 100644 --- a/packages/grid_client/src/modules/contracts.ts +++ b/packages/grid_client/src/modules/contracts.ts @@ -11,6 +11,7 @@ import * as PATH from "path"; import { ContractsOverdue, + type DiscountLevel, GqlContracts, GqlNameContract, GqlNodeContract, @@ -31,6 +32,7 @@ import { BatchCancelContractsModel, ContractCancelModel, ContractConsumption, + ContractDiscountPackage, ContractGetByNodeIdAndHashModel, ContractGetModel, ContractLockModel, @@ -523,7 +525,19 @@ class Contracts { async setDedicatedNodeExtraFee(options: SetDedicatedNodeExtraFeesModel) { return (await this.client.contracts.setDedicatedNodeExtraFee(options)).apply(); } - + /** + * Get contract discount package + * @param {ContractDiscountPackage} options + * @returns {Promie} + * @decorators + * - `@expose`: Exposes the method for external use. + * - `@validateInput`: Validates the input options. + */ + @expose + @validateInput + async getDiscountPackage(options: ContractDiscountPackage): Promise { + return this.client.contracts.getDiscountPackage({ id: options.id, graphqlURL: this.config.graphqlURL }); + } /** * Get contract consumption per hour in TFT. * diff --git a/packages/grid_client/src/modules/models.ts b/packages/grid_client/src/modules/models.ts index 2abd77f7bd..173098d81f 100644 --- a/packages/grid_client/src/modules/models.ts +++ b/packages/grid_client/src/modules/models.ts @@ -390,6 +390,10 @@ class ContractConsumption { @Expose() @IsInt() @Min(1) id: number; } +class ContractDiscountPackage { + @Expose() @IsInt() @Min(1) id: number; +} + class ContractLockModel extends ContractConsumption {} class TwinCreateModel { @@ -974,6 +978,7 @@ export { ContractsByTwinId, ContractsByAddress, ContractConsumption, + ContractDiscountPackage, ContractLockModel, TwinCreateModel, TwinGetModel, diff --git a/packages/playground/src/components/contracts_list/contracts_table.vue b/packages/playground/src/components/contracts_list/contracts_table.vue index d46fbd6a04..31317731b9 100644 --- a/packages/playground/src/components/contracts_list/contracts_table.vue +++ b/packages/playground/src/components/contracts_list/contracts_table.vue @@ -36,9 +36,23 @@ @@ -289,7 +303,7 @@