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,14 +303,24 @@ 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;
try {
if (node && node.rentContractId !== 0) {
const { state } = await gridStore.grid.contracts.get({
id: node?.rentContractId,
});
if (state.gracePeriod) {
const err = `You can't deploy on node ${node.nodeId}, its rent contract is in grace period.`;
throw err;
}
}
} catch (error) {
const err = normalizeError(
error,
"Something went wrong while checking status of the node. Please check your connection and try again.",
);
throw err;
}

const nodeCapacityValid = await checkNodeCapacityPool(gridStore, node, props.filters);
const rentContractValid = props.filters.dedicated ? await validateRentContract(gridStore, node) : true;

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,18 @@ export default {
tftsNeeded();
});

async function handleNodeClick() {
try {
if (props.status === "Init" && props.node) {
ctx.emit("node:select", props.node as NodeInfo);
}
if (props.node?.dedicated && props.node.rentContractId === 0) return false;
await validateRentContract(gridStore, props.node as NodeInfo);
} catch (error) {
return error;
}
}

async function refreshStakingDiscount() {
loadingStakingDiscount.value = true;
if (props.node) {
Expand Down Expand Up @@ -622,6 +626,7 @@ export default {
lastDeploymentTime,
loadingdiscountTableItems,
gridStore,
handleNodeClick,
};
},
};
Expand Down
10 changes: 3 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 @@ -231,14 +230,11 @@ export async function validateRentContract(
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