From 51fe8a485c4a2a9632627ccc174e2ab211f68756 Mon Sep 17 00:00:00 2001 From: Lorenzo Ronzani Date: Wed, 19 Jun 2024 21:41:29 +0200 Subject: [PATCH] =?UTF-8?q?refactor=20=E2=9A=99:=20=20Refactoring=20the=20?= =?UTF-8?q?confirmDeployment=20flow?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/app/dashboard/new-deployment/page.tsx | 4 ++-- frontend/app/dashboard/page.tsx | 8 +++++--- frontend/services/deployment.ts | 3 ++- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/frontend/app/dashboard/new-deployment/page.tsx b/frontend/app/dashboard/new-deployment/page.tsx index 4873307..9c98fcd 100644 --- a/frontend/app/dashboard/new-deployment/page.tsx +++ b/frontend/app/dashboard/new-deployment/page.tsx @@ -19,7 +19,7 @@ import {displayE8sAsIcp, icpToE8s} from "@/helpers/ui"; import {Spinner} from "@/components/spinner"; import {NewDeploymentForm} from "@/components/new-deployment-form"; import {transferE8sToBackend} from "@/services/backend"; -import {sendManifestToProviderFlow} from "@/services/deployment"; +import {confirmDeployment} from "@/services/deployment"; const FETCH_DEPLOYMENT_PRICE_INTERVAL_MS = 30_000; // 30 seconds @@ -163,7 +163,7 @@ export default function NewDeployment() { el.hasOwnProperty("DeploymentCreated") )!; - await sendManifestToProviderFlow( + await confirmDeployment( deploymentUpdate.update, deploymentCreatedState, tlsCertificateData! diff --git a/frontend/app/dashboard/page.tsx b/frontend/app/dashboard/page.tsx index cefa722..d14342f 100644 --- a/frontend/app/dashboard/page.tsx +++ b/frontend/app/dashboard/page.tsx @@ -31,7 +31,7 @@ import { isDeploymentFailed, } from "@/helpers/deployment"; import {displayIcp} from "@/helpers/ui"; -import {queryLeaseStatus, sendManifestToProviderFlow} from "@/services/deployment"; +import {confirmDeployment, queryLeaseStatus} from "@/services/deployment"; import {DeploymentTier} from "@/types/deployment"; import {ChevronsUpDown} from "lucide-react"; import {useRouter} from "next/navigation"; @@ -131,7 +131,7 @@ export default function Dashboard() { try { const cert = await loadOrCreateCertificate(backendActor!); - await sendManifestToProviderFlow( + await confirmDeployment( lastState, deploymentCreatedState, cert! @@ -147,8 +147,10 @@ export default function Dashboard() { stepActive ) ); + + await fetchDeployments(backendActor!); } catch (e) { - console.error(e); + console.error("Failed to update deployment:", e); } } } diff --git a/frontend/services/deployment.ts b/frontend/services/deployment.ts index a4fdcef..6f2cef5 100644 --- a/frontend/services/deployment.ts +++ b/frontend/services/deployment.ts @@ -77,7 +77,7 @@ export const queryLeaseStatus = async (queryLeaseUrl: string, certData: X509Cert return await res.json(); }; -export const sendManifestToProviderFlow = async (deploymentState: DeploymentState, deploymentCreatedState: DeploymentState, cert: MTlsCertificateData) => { +export const confirmDeployment = async (deploymentState: DeploymentState, deploymentCreatedState: DeploymentState, cert: MTlsCertificateData) => { try { if ("LeaseCreated" in deploymentState) { const {manifest_sorted_json, dseq} = extractDeploymentCreated(deploymentCreatedState); @@ -94,6 +94,7 @@ export const sendManifestToProviderFlow = async (deploymentState: DeploymentStat manifest_sorted_json, cert! ); + } else { throw new Error("Deployment state is not in LeaseCreated state"); }