Skip to content

Commit 8c936ef

Browse files
authored
Handle rented node in grace period (#3742)
* Handle rented node in grace period * Handle Error * Remove the error toast * Remove unused imports * Add timeout with promise to catch grace period error * Remove umwanted imports * Handle console error * rm timeout * Fix recursive calls * q - Remove unwanted contract validation - Early exit for check it node is rented and not in dedicated farm - Remove the check only if dedicated filter is ON
1 parent 96da187 commit 8c936ef

File tree

3 files changed

+15
-28
lines changed

3 files changed

+15
-28
lines changed

packages/playground/src/components/node_selector/TfAutoNodeSelector.vue

+3-12
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ import { RequestError } from "@threefold/types";
148148
import type AwaitLock from "await-lock";
149149
import equals from "lodash/fp/equals.js";
150150
import { computed, nextTick, onMounted, onUnmounted, type PropType, ref } from "vue";
151-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
152-
import type { VCard } from "vuetify/components/VCard";
151+
152+
import { normalizeError } from "@/utils/helpers";
153153
154154
import { useAsync, usePagination, useWatchDeep } from "../../hooks";
155155
import { ValidatorStatus } from "../../hooks/form_validator";
@@ -167,7 +167,6 @@ import {
167167
validateRentContract,
168168
} from "../../utils/nodeSelector";
169169
import TfNodeDetailsCard from "./TfNodeDetailsCard.vue";
170-
171170
export default {
172171
name: "TfAutoNodeSelector",
173172
components: { TfNodeDetailsCard },
@@ -304,16 +303,8 @@ export default {
304303
305304
const nodeInputValidateTask = useAsync<boolean, string, [NodeInfo | undefined]>(
306305
async node => {
307-
if (node && node?.rentContractId !== 0) {
308-
const { state } = await gridStore.grid.contracts.get({
309-
id: node?.rentContractId,
310-
});
311-
if (state.gracePeriod) {
312-
return false;
313-
}
314-
}
315306
const nodeCapacityValid = await checkNodeCapacityPool(gridStore, node, props.filters);
316-
const rentContractValid = props.filters.dedicated ? await validateRentContract(gridStore, node) : true;
307+
const rentContractValid = await validateRentContract(gridStore, node);
317308
318309
if (node && !isNodeValid(props.getFarm, node!, props.selectedMachines, filters.value)) {
319310
throw `Node (${node.nodeId}) is not valid.`;

packages/playground/src/components/node_selector/TfNodeDetailsCard.vue

+8-9
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,7 @@
1313
"
1414
:flat="flat"
1515
v-bind="{
16-
onClick: selectable
17-
? async () => {
18-
if (status === 'Init' && node) {
19-
$emit('node:select', (node as NodeInfo));
20-
}
21-
if(node?.dedicated && node.rentContractId === 0) return false
22-
await validateRentContract(gridStore, node as NodeInfo);
23-
}
24-
: undefined,
16+
onClick: selectable ? async () => await handleNodeClick() : undefined,
2517
}"
2618
>
2719
<template #loader>
@@ -364,6 +356,12 @@ export default {
364356
tftsNeeded();
365357
});
366358
359+
async function handleNodeClick() {
360+
if (props.status === "Init" && props.node) {
361+
ctx.emit("node:select", props.node as NodeInfo);
362+
}
363+
}
364+
367365
async function refreshStakingDiscount() {
368366
loadingStakingDiscount.value = true;
369367
if (props.node) {
@@ -622,6 +620,7 @@ export default {
622620
lastDeploymentTime,
623621
loadingdiscountTableItems,
624622
gridStore,
623+
handleNodeClick,
625624
};
626625
},
627626
};

packages/playground/src/utils/nodeSelector.ts

+4-7
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import type {
1919
SelectionDetailsFilters,
2020
SelectionDetailsFiltersValidators,
2121
} from "../types/nodeSelector";
22-
import { createCustomToast, ToastType } from "./custom_toast";
2322
import { normalizeError } from "./helpers";
2423

2524
export interface GetLocationsConfig {
@@ -229,20 +228,18 @@ export async function validateRentContract(
229228
if (!node || !node.nodeId) {
230229
throw "Node ID is required.";
231230
}
231+
if (node.dedicated && node.rentedByTwinId === 0 && !node.inDedicatedFarm) return true;
232232

233233
try {
234234
if (node.dedicated && node.rentedByTwinId === 0 && node.inDedicatedFarm) {
235235
throw `Node ${node.nodeId} is not rented`;
236236
}
237237
if (node.rentContractId !== 0) {
238-
const contractInfo = await gridStore.grid.contracts.get({
238+
const { state } = await gridStore.grid.contracts.get({
239239
id: node.rentContractId,
240240
});
241-
if (contractInfo.state.gracePeriod) {
242-
createCustomToast(
243-
`You can't deploy on node ${node.nodeId}, its rent contract is in grace period.`,
244-
ToastType.danger,
245-
);
241+
if (state.gracePeriod) {
242+
throw `You can't deploy on node ${node.nodeId}, its rent contract is in grace period.`;
246243
}
247244
}
248245

0 commit comments

Comments
 (0)