Skip to content

Commit

Permalink
Using decimal
Browse files Browse the repository at this point in the history
  • Loading branch information
zaelgohary committed Jun 25, 2023
1 parent ec39dc9 commit 75c8403
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions packages/dashboard/src/portal/components/FarmNodesTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@
</template>
<script lang="ts">
import { QueryClient } from "@threefold/tfchain_client";
import { Decimal } from "decimal.js";
import jsPDF from "jspdf";
import { default as PrivateIp } from "private-ip";
import { Component, Prop, Vue } from "vue-property-decorator";
Expand Down Expand Up @@ -696,15 +697,20 @@ export default class FarmNodesTable extends Vue {
async openExtraFee(node: nodeInterface) {
this.nodeToEdit = node;
// convert fees from USD to mili USD while getting
this.extraFee =
(await this.queryClient.contracts.getDedicatedNodeExtraFee({ nodeId: this.nodeToEdit.nodeId })) / 1000;
const fee = new Decimal(
await this.queryClient.contracts.getDedicatedNodeExtraFee({ nodeId: this.nodeToEdit.nodeId }),
);
const feeUSD = fee.div(10 ** 3).toNumber();
this.extraFee = feeUSD;
this.openExtraFeeDialogue = true;
}
async saveExtraFee(fee: number) {
this.loadingExtraFee = true;
// convert fees from mili USD to USD while setting
setDedicatedNodeExtraFee(this.$store.state.credentials.account.address, this.nodeToEdit.nodeId, fee * 1000)
const feeDecimal = new Decimal(fee);
const feeUSD = feeDecimal.mul(10 ** 3).toNumber();
setDedicatedNodeExtraFee(this.$store.state.credentials.account.address, this.nodeToEdit.nodeId, feeUSD)
.then(() => {
this.$toasted.show(`Transaction succeeded: Fee is added to node ${this.nodeToEdit.nodeId}`);
this.loadingExtraFee = false;
Expand Down

0 comments on commit 75c8403

Please sign in to comment.