From 967eded8b1424fc7ee1333c4a69ff4ebd14a74ed Mon Sep 17 00:00:00 2001 From: IshaVenikar Date: Wed, 23 Oct 2024 10:45:15 +0530 Subject: [PATCH] Display deployer LRNs in dropdown --- packages/backend/src/registry.ts | 1 + packages/backend/src/service.ts | 39 ++++++++++++++++--- .../components/projects/create/Configure.tsx | 38 +++++++++++------- .../project/overview/Activity/AuctionCard.tsx | 8 +++- packages/gql-client/src/queries.ts | 2 +- 5 files changed, 67 insertions(+), 21 deletions(-) diff --git a/packages/backend/src/registry.ts b/packages/backend/src/registry.ts index f4df1353..9371baaa 100644 --- a/packages/backend/src/registry.ts +++ b/packages/backend/src/registry.ts @@ -283,6 +283,7 @@ export class Registry { this.registryConfig.privateKey, fee ); + log(`Application deployment request record published: ${result.id}`); log('Application deployment request data:', applicationDeploymentRequest); diff --git a/packages/backend/src/service.ts b/packages/backend/src/service.ts index 635c522f..258a99e6 100644 --- a/packages/backend/src/service.ts +++ b/packages/backend/src/service.ts @@ -443,11 +443,6 @@ export class Service { return dbDeployments; } - async getDeployers(): Promise { - const dbDeployers = await this.db.getDeployers(); - return dbDeployers; - } - async getEnvironmentVariablesByProjectId( projectId: string, ): Promise { @@ -1374,4 +1369,38 @@ export class Service { return false; } + + async getDeployers(): Promise { + const dbDeployers = await this.db.getDeployers(); + + if (dbDeployers.length > 0) { + this.updateDeployersFromRegistry(); + return dbDeployers; + } else { + return await this.updateDeployersFromRegistry(); + } + } + + async updateDeployersFromRegistry(): Promise { + const deployerRecords = await this.laconicRegistry.getDeployerRecordsByFilter({}); + + for (const record of deployerRecords) { + const deployerId = record.id; + const deployerLrn = record.names[0]; + + const deployerApiUrl = record.attributes.apiUrl; + const baseDomain = deployerApiUrl.substring(deployerApiUrl.indexOf('.') + 1); + + const deployerData = { + deployerId, + deployerLrn, + deployerApiUrl, + baseDomain + }; + + await this.db.addDeployer(deployerData); + } + + return await this.db.getDeployers(); + } } diff --git a/packages/frontend/src/components/projects/create/Configure.tsx b/packages/frontend/src/components/projects/create/Configure.tsx index 95d4712b..0eaf4721 100644 --- a/packages/frontend/src/components/projects/create/Configure.tsx +++ b/packages/frontend/src/components/projects/create/Configure.tsx @@ -155,19 +155,19 @@ const Configure = () => { if (templateId) { createFormData.option === 'Auction' ? navigate( - `/${orgSlug}/projects/create/success/${projectId}?isAuction=true`, - ) + `/${orgSlug}/projects/create/success/${projectId}?isAuction=true`, + ) : navigate( - `/${orgSlug}/projects/create/template/deploy?projectId=${projectId}&templateId=${templateId}`, - ); + `/${orgSlug}/projects/create/template/deploy?projectId=${projectId}&templateId=${templateId}`, + ); } else { createFormData.option === 'Auction' ? navigate( - `/${orgSlug}/projects/create/success/${projectId}?isAuction=true`, - ) + `/${orgSlug}/projects/create/success/${projectId}?isAuction=true`, + ) : navigate( - `/${orgSlug}/projects/create/deploy?projectId=${projectId}`, - ); + `/${orgSlug}/projects/create/deploy?projectId=${projectId}`, + ); } }, [client, createProject, dismiss, toast], @@ -176,9 +176,9 @@ const Configure = () => { const fetchDeployers = useCallback(async () => { const res = await client.getDeployers() setDeployers(res.deployers) - }, [client]) + }, [client]) - useEffect(()=>{ + useEffect(() => { fetchDeployers() }, []) @@ -236,15 +236,25 @@ const Configure = () => { > The app will be deployed by the configured deployer - - Enter LRN for deployer - ( - +