diff --git a/packages/backend/src/entity/Project.ts b/packages/backend/src/entity/Project.ts index ea44483f..d9696767 100644 --- a/packages/backend/src/entity/Project.ts +++ b/packages/backend/src/entity/Project.ts @@ -52,6 +52,9 @@ export class Project { @Column({ type: 'simple-array', nullable: true }) deployerLrns!: string[] | null; + @Column('boolean', { default: false, nullable: true }) + fundsReleased!: boolean; + // TODO: Compute template & framework in import repository @Column('varchar', { nullable: true }) template!: string | null; diff --git a/packages/backend/src/registry.ts b/packages/backend/src/registry.ts index 89f53ebc..138fc52a 100644 --- a/packages/backend/src/registry.ts +++ b/packages/backend/src/registry.ts @@ -319,6 +319,21 @@ export class Registry { return deployerLrns; } + async releaseDeployerFunds( + auctionId: string + ): Promise { + const fee = parseGasAndFees(this.registryConfig.fee.gas, this.registryConfig.fee.fees); + const auction = await this.registry.releaseFunds( + { + auctionId + }, + this.registryConfig.privateKey, + fee + ); + + return auction; + } + /** * Fetch ApplicationDeploymentRecords for deployments */ diff --git a/packages/backend/src/schema.gql b/packages/backend/src/schema.gql index b4f74d72..ec67c5ca 100644 --- a/packages/backend/src/schema.gql +++ b/packages/backend/src/schema.gql @@ -74,6 +74,7 @@ type Project { description: String deployerLrns: [String] auctionId: String + fundsReleased: Boolean template: String framework: String webhooks: [String!] @@ -246,6 +247,7 @@ type Query { projectMembers(projectId: String!): [ProjectMember!] searchProjects(searchText: String!): [Project!] getAuctionData(auctionId: String!): Auction! + releaseDeployerFundsByProjectId(projectId: String!): Auction! domains(projectId: String!, filter: FilterDomainsInput): [Domain] } diff --git a/packages/backend/src/service.ts b/packages/backend/src/service.ts index 57ad9ef5..da7488ae 100644 --- a/packages/backend/src/service.ts +++ b/packages/backend/src/service.ts @@ -210,8 +210,12 @@ export class Service { baseDomains.push(baseDomain); } + // Release deployer funds on successful deployment + const fundsReleased = await this.releaseDeployerFundsByProjectId(project.id); + await this.db.updateProjectById(project.id, { - baseDomains + baseDomains, + fundsReleased, }) log( @@ -1261,4 +1265,24 @@ export class Service { const auctions = await this.laconicRegistry.getAuctionData(auctionId); return auctions[0]; } + + async releaseDeployerFundsByProjectId(projectId: string): Promise { + const project = await this.db.getProjectById(projectId); + + if (!project || !project.auctionId) { + log(`Project ${projectId} ${!project ? 'not found' : 'does not have an auction'}`); + return false; + } + + const auction = await this.laconicRegistry.releaseDeployerFunds(project.auctionId); + + if (auction.auction.fundsReleased) { + log(`Funds released for auction ${project.auctionId}`); + await this.db.updateProjectById(projectId, { fundsReleased: true }); + return true; + } + + log(`Error releasing funds for auction ${project.auctionId}`); + return false; + } } diff --git a/packages/frontend/src/components/projects/project/overview/Activity/AuctionCard.tsx b/packages/frontend/src/components/projects/project/overview/Activity/AuctionCard.tsx index e79e944b..dcf6f700 100644 --- a/packages/frontend/src/components/projects/project/overview/Activity/AuctionCard.tsx +++ b/packages/frontend/src/components/projects/project/overview/Activity/AuctionCard.tsx @@ -17,6 +17,7 @@ const WAIT_DURATION = 5000; export const AuctionCard = ({ project }: { project: Project }) => { const [auctionStatus, setAuctionStatus] = useState(''); const [deployerLrns, setDeployerLrns] = useState([]); + const [fundsStatus, setFundsStatus] = useState(false); const [auctionDetails, setAuctionDetails] = useState(null); const [openDialog, setOpenDialog] = useState(false); const client = useGQLClient(); @@ -29,13 +30,13 @@ export const AuctionCard = ({ project }: { project: Project }) => { setAuctionStatus(result.status); setAuctionDetails(result); setDeployerLrns(project.deployerLrns); - }, [client, project.auctionId, project.deployerLrns]); + setFundsStatus(project.fundsReleased); + }, []); useEffect(() => { if (auctionStatus !== 'completed') { checkAuctionStatus(); const intervalId = setInterval(checkAuctionStatus, WAIT_DURATION); - return () => clearInterval(intervalId); } }, [auctionStatus, checkAuctionStatus]); @@ -48,10 +49,9 @@ export const AuctionCard = ({ project }: { project: Project }) => { const updatedProject = await client.getProject(project.id); setDeployerLrns(updatedProject.project?.deployerLrns || []); }; - fetchUpdatedProject(); } - }, [auctionStatus, client, project.id]); + }, [auctionStatus, client]); const renderAuctionStatus = useCallback( () => ( @@ -101,6 +101,18 @@ export const AuctionCard = ({ project }: { project: Project }) => { ))} )} + +
+ Deployer Funds Status +
+ + {fundsStatus ? 'RELEASED' : 'LOCKED'} + +
+
diff --git a/packages/frontend/src/stories/MockStoriesData.ts b/packages/frontend/src/stories/MockStoriesData.ts index 92f71721..5559cbed 100644 --- a/packages/frontend/src/stories/MockStoriesData.ts +++ b/packages/frontend/src/stories/MockStoriesData.ts @@ -124,5 +124,6 @@ export const project: Project = { deployerLrns: ['lrn://deployer.apps.snowballtools.com '], webhooks: ['beepboop'], icon: 'Icon', + fundsReleased: true, baseDomains: ['baseDomain'], }; diff --git a/packages/gql-client/src/queries.ts b/packages/gql-client/src/queries.ts index 6f115a82..a87a4cb8 100644 --- a/packages/gql-client/src/queries.ts +++ b/packages/gql-client/src/queries.ts @@ -25,6 +25,7 @@ query ($projectId: String!) { prodBranch auctionId deployerLrns + fundsReleased framework repository webhooks @@ -76,6 +77,7 @@ query ($organizationSlug: String!) { framework auctionId deployerLrns + fundsReleased prodBranch webhooks repository @@ -193,6 +195,7 @@ query ($searchText: String!) { framework auctionId deployerLrns + fundsReleased prodBranch webhooks updatedAt diff --git a/packages/gql-client/src/types.ts b/packages/gql-client/src/types.ts index b1220898..15b9e073 100644 --- a/packages/gql-client/src/types.ts +++ b/packages/gql-client/src/types.ts @@ -171,6 +171,7 @@ export type Project = { framework: string; deployerLrns: string[]; auctionId: string; + fundsReleased: boolean; webhooks: string[]; members: ProjectMember[]; environmentVariables: EnvironmentVariable[];