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 @@ -301,14 +300,29 @@ 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.`;
await new Promise((_, reject) => {
setTimeout(() => {
reject(Error(err));
}, 2000);
});
console.error(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
12 changes: 7 additions & 5 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 @@ -235,10 +234,13 @@ export async function validateRentContract(
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,
);
const err = `You can't deploy on node ${node.nodeId}, its rent contract is in grace period.`;
await new Promise((_, reject) => {
setTimeout(() => {
reject(Error(err));
}, 2000);
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't think we need to add timeout here, not the auto one there is no toast overlap what do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

totally agree, removed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see you removed timeout in the automatic on to, can you explain why I think ti is a better UX even if we set it to only one sec

console.error(err);
}
}

Expand Down
Loading