-
Notifications
You must be signed in to change notification settings - Fork 8
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
Add discount icon with discount package in contracts table #3392
base: development
Are you sure you want to change the base?
Changes from 6 commits
074753a
bbc16ec
91b942a
ec2747c
88888eb
7be9a76
618ace6
8da4c15
9a18f62
7356136
654ffd2
3e41e62
779ccb5
5f63dc6
30ef189
6f61764
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,6 +70,9 @@ export interface GqlConsumption { | |
contracts: GqlContracts; | ||
contractBillReports: GqlContractBillReports[]; | ||
} | ||
export interface GqlDiscountPackage { | ||
contractBillReports: GqlContractBillReports[]; | ||
} | ||
|
||
export interface GqlContractBillReports { | ||
id: string; | ||
|
@@ -98,6 +101,11 @@ export interface GetConsumptionOptions { | |
id: number; | ||
} | ||
|
||
export interface GetDiscountPackageOptions { | ||
graphqlURL: string; | ||
id: number; | ||
} | ||
|
||
export interface CancelMyContractOptions { | ||
graphqlURL: string; | ||
} | ||
|
@@ -208,7 +216,35 @@ class TFContracts extends Contracts { | |
throw err; | ||
} | ||
} | ||
/** | ||
* Get contract discount package | ||
* @param {GetDiscountPackageOptions} options | ||
* @returns {Promie<DiscountLevel>} | ||
*/ | ||
async getDiscountPackage(options: GetDiscountPackageOptions): Promise<DiscountLevel> { | ||
const gqlClient = new Graphql(options.graphqlURL); | ||
const body = `query getConsumption($contractId: BigInt!){ | ||
contractBillReports(where: {contractID_eq: $contractId}, limit: 1 ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think this will make the first discount package will always displayed, i suggest to remove limit and get the last element in the list this may fix the issue |
||
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[0].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. | ||
* | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,9 +36,20 @@ | |
</template> | ||
|
||
<template #[`item.consumption`]="{ item }"> | ||
<p v-if="item?.consumption !== 0 && item?.consumption !== undefined"> | ||
{{ item.consumption.toFixed(3) }} TFT/hour | ||
</p> | ||
<v-row v-if="item?.consumption !== 0 && item?.consumption !== undefined" class="d-flex justify-center"> | ||
<p class="mr-2">{{ item.consumption.toFixed(3) }} TFT/hour</p> | ||
|
||
<v-tooltip bottom color="primary" close-delay="100" v-if="item.discountPackage"> | ||
<template v-slot:activator="{ props }"> | ||
<v-icon class="scale_beat mr-2" color="warning" v-bind="props">mdi-brightness-percent</v-icon> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think we should remove the mr-2 no need for it |
||
</template> | ||
|
||
<span> | ||
{{ item.discountPackage }} | ||
</span> | ||
</v-tooltip> | ||
</v-row> | ||
|
||
<p v-else>No Data Available</p> | ||
</template> | ||
|
||
|
@@ -278,7 +289,7 @@ | |
|
||
<script lang="ts" setup> | ||
// Import necessary types and libraries | ||
import { ContractStates, type GridClient, type LockDetails } from "@threefold/grid_client"; | ||
import { ContractStates, discountPackages, type GridClient, type LockDetails } from "@threefold/grid_client"; | ||
import type { NodeStatus } from "@threefold/gridproxy_client"; | ||
import type { ContractLock } from "@threefold/tfchain_client"; | ||
import { TFChainError } from "@threefold/tfchain_client"; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I notice that we can add order to the request body; i think this will be better