Skip to content

Handle rented node in grace period #3742

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

Merged
merged 13 commits into from
Feb 24, 2025
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ import { RequestError } from "@threefold/types";
import type AwaitLock from "await-lock";
import equals from "lodash/fp/equals.js";
import { computed, nextTick, onMounted, onUnmounted, type PropType, ref } from "vue";
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import type { VCard } from "vuetify/components/VCard";

import { normalizeError } from "@/utils/helpers";

import { useAsync, usePagination, useWatchDeep } from "../../hooks";
import { ValidatorStatus } from "../../hooks/form_validator";
Expand All @@ -167,7 +167,6 @@ import {
validateRentContract,
} from "../../utils/nodeSelector";
import TfNodeDetailsCard from "./TfNodeDetailsCard.vue";

export default {
name: "TfAutoNodeSelector",
components: { TfNodeDetailsCard },
Expand Down Expand Up @@ -304,16 +303,8 @@ export default {

const nodeInputValidateTask = useAsync<boolean, string, [NodeInfo | undefined]>(
async node => {
if (node && node?.rentContractId !== 0) {
const { state } = await gridStore.grid.contracts.get({
id: node?.rentContractId,
});
if (state.gracePeriod) {
return false;
}
}
const nodeCapacityValid = await checkNodeCapacityPool(gridStore, node, props.filters);
const rentContractValid = props.filters.dedicated ? await validateRentContract(gridStore, node) : true;
const rentContractValid = await validateRentContract(gridStore, node);

if (node && !isNodeValid(props.getFarm, node!, props.selectedMachines, filters.value)) {
throw `Node (${node.nodeId}) is not valid.`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,7 @@
"
:flat="flat"
v-bind="{
onClick: selectable
? async () => {
if (status === 'Init' && node) {
$emit('node:select', (node as NodeInfo));
}
if(node?.dedicated && node.rentContractId === 0) return false
await validateRentContract(gridStore, node as NodeInfo);
}
: undefined,
onClick: selectable ? async () => await handleNodeClick() : undefined,
}"
>
<template #loader>
Expand Down Expand Up @@ -364,6 +356,12 @@ export default {
tftsNeeded();
});

async function handleNodeClick() {
if (props.status === "Init" && props.node) {
ctx.emit("node:select", props.node as NodeInfo);
}
}

async function refreshStakingDiscount() {
loadingStakingDiscount.value = true;
if (props.node) {
Expand Down Expand Up @@ -622,6 +620,7 @@ export default {
lastDeploymentTime,
loadingdiscountTableItems,
gridStore,
handleNodeClick,
};
},
};
Expand Down
11 changes: 4 additions & 7 deletions packages/playground/src/utils/nodeSelector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import type {
SelectionDetailsFilters,
SelectionDetailsFiltersValidators,
} from "../types/nodeSelector";
import { createCustomToast, ToastType } from "./custom_toast";
import { normalizeError } from "./helpers";

export interface GetLocationsConfig {
Expand Down Expand Up @@ -225,20 +224,18 @@ export async function validateRentContract(
if (!node || !node.nodeId) {
throw "Node ID is required.";
}
if (node.dedicated && node.rentedByTwinId === 0 && !node.inDedicatedFarm) return true;

try {
if (node.dedicated && node.rentedByTwinId === 0 && node.inDedicatedFarm) {
throw `Node ${node.nodeId} is not rented`;
}
if (node.rentContractId !== 0) {
const contractInfo = await gridStore.grid.contracts.get({
const { state } = await gridStore.grid.contracts.get({
id: node.rentContractId,
});
if (contractInfo.state.gracePeriod) {
createCustomToast(
`You can't deploy on node ${node.nodeId}, its rent contract is in grace period.`,
ToastType.danger,
);
if (state.gracePeriod) {
throw `You can't deploy on node ${node.nodeId}, its rent contract is in grace period.`;
}
}

Expand Down
Loading