Implement functionality to release funds on successful deployment
This commit is contained in:
parent
d486f44cfe
commit
e497ac2228
@ -52,6 +52,9 @@ export class Project {
|
|||||||
@Column({ type: 'simple-array', nullable: true })
|
@Column({ type: 'simple-array', nullable: true })
|
||||||
deployerLrns!: string[] | null;
|
deployerLrns!: string[] | null;
|
||||||
|
|
||||||
|
@Column('boolean', { default: false, nullable: true })
|
||||||
|
fundsReleased!: boolean;
|
||||||
|
|
||||||
// TODO: Compute template & framework in import repository
|
// TODO: Compute template & framework in import repository
|
||||||
@Column('varchar', { nullable: true })
|
@Column('varchar', { nullable: true })
|
||||||
template!: string | null;
|
template!: string | null;
|
||||||
|
@ -319,6 +319,21 @@ export class Registry {
|
|||||||
return deployerLrns;
|
return deployerLrns;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async releaseDeployerFunds(
|
||||||
|
auctionId: string
|
||||||
|
): Promise<any> {
|
||||||
|
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
|
* Fetch ApplicationDeploymentRecords for deployments
|
||||||
*/
|
*/
|
||||||
|
@ -74,6 +74,7 @@ type Project {
|
|||||||
description: String
|
description: String
|
||||||
deployerLrns: [String]
|
deployerLrns: [String]
|
||||||
auctionId: String
|
auctionId: String
|
||||||
|
fundsReleased: Boolean
|
||||||
template: String
|
template: String
|
||||||
framework: String
|
framework: String
|
||||||
webhooks: [String!]
|
webhooks: [String!]
|
||||||
@ -246,6 +247,7 @@ type Query {
|
|||||||
projectMembers(projectId: String!): [ProjectMember!]
|
projectMembers(projectId: String!): [ProjectMember!]
|
||||||
searchProjects(searchText: String!): [Project!]
|
searchProjects(searchText: String!): [Project!]
|
||||||
getAuctionData(auctionId: String!): Auction!
|
getAuctionData(auctionId: String!): Auction!
|
||||||
|
releaseDeployerFundsByProjectId(projectId: String!): Auction!
|
||||||
domains(projectId: String!, filter: FilterDomainsInput): [Domain]
|
domains(projectId: String!, filter: FilterDomainsInput): [Domain]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -210,8 +210,12 @@ export class Service {
|
|||||||
baseDomains.push(baseDomain);
|
baseDomains.push(baseDomain);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Release deployer funds on successful deployment
|
||||||
|
const fundsReleased = await this.releaseDeployerFundsByProjectId(project.id);
|
||||||
|
|
||||||
await this.db.updateProjectById(project.id, {
|
await this.db.updateProjectById(project.id, {
|
||||||
baseDomains
|
baseDomains,
|
||||||
|
fundsReleased,
|
||||||
})
|
})
|
||||||
|
|
||||||
log(
|
log(
|
||||||
@ -1261,4 +1265,24 @@ export class Service {
|
|||||||
const auctions = await this.laconicRegistry.getAuctionData(auctionId);
|
const auctions = await this.laconicRegistry.getAuctionData(auctionId);
|
||||||
return auctions[0];
|
return auctions[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async releaseDeployerFundsByProjectId(projectId: string): Promise<boolean> {
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@ const WAIT_DURATION = 5000;
|
|||||||
export const AuctionCard = ({ project }: { project: Project }) => {
|
export const AuctionCard = ({ project }: { project: Project }) => {
|
||||||
const [auctionStatus, setAuctionStatus] = useState<string>('');
|
const [auctionStatus, setAuctionStatus] = useState<string>('');
|
||||||
const [deployerLrns, setDeployerLrns] = useState<string[]>([]);
|
const [deployerLrns, setDeployerLrns] = useState<string[]>([]);
|
||||||
|
const [fundsStatus, setFundsStatus] = useState<boolean>(false);
|
||||||
const [auctionDetails, setAuctionDetails] = useState<Auction | null>(null);
|
const [auctionDetails, setAuctionDetails] = useState<Auction | null>(null);
|
||||||
const [openDialog, setOpenDialog] = useState<boolean>(false);
|
const [openDialog, setOpenDialog] = useState<boolean>(false);
|
||||||
const client = useGQLClient();
|
const client = useGQLClient();
|
||||||
@ -29,13 +30,13 @@ export const AuctionCard = ({ project }: { project: Project }) => {
|
|||||||
setAuctionStatus(result.status);
|
setAuctionStatus(result.status);
|
||||||
setAuctionDetails(result);
|
setAuctionDetails(result);
|
||||||
setDeployerLrns(project.deployerLrns);
|
setDeployerLrns(project.deployerLrns);
|
||||||
}, [client, project.auctionId, project.deployerLrns]);
|
setFundsStatus(project.fundsReleased);
|
||||||
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (auctionStatus !== 'completed') {
|
if (auctionStatus !== 'completed') {
|
||||||
checkAuctionStatus();
|
checkAuctionStatus();
|
||||||
const intervalId = setInterval(checkAuctionStatus, WAIT_DURATION);
|
const intervalId = setInterval(checkAuctionStatus, WAIT_DURATION);
|
||||||
|
|
||||||
return () => clearInterval(intervalId);
|
return () => clearInterval(intervalId);
|
||||||
}
|
}
|
||||||
}, [auctionStatus, checkAuctionStatus]);
|
}, [auctionStatus, checkAuctionStatus]);
|
||||||
@ -48,10 +49,9 @@ export const AuctionCard = ({ project }: { project: Project }) => {
|
|||||||
const updatedProject = await client.getProject(project.id);
|
const updatedProject = await client.getProject(project.id);
|
||||||
setDeployerLrns(updatedProject.project?.deployerLrns || []);
|
setDeployerLrns(updatedProject.project?.deployerLrns || []);
|
||||||
};
|
};
|
||||||
|
|
||||||
fetchUpdatedProject();
|
fetchUpdatedProject();
|
||||||
}
|
}
|
||||||
}, [auctionStatus, client, project.id]);
|
}, [auctionStatus, client]);
|
||||||
|
|
||||||
const renderAuctionStatus = useCallback(
|
const renderAuctionStatus = useCallback(
|
||||||
() => (
|
() => (
|
||||||
@ -101,6 +101,18 @@ export const AuctionCard = ({ project }: { project: Project }) => {
|
|||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
<div className="flex justify-between items-center mt-1">
|
||||||
|
<span className="text-elements-high-em text-sm font-medium tracking-tight">Deployer Funds Status</span>
|
||||||
|
<div className="ml-2">
|
||||||
|
<Tag
|
||||||
|
size="xs"
|
||||||
|
type={fundsStatus ? 'positive' : 'emphasized'}
|
||||||
|
>
|
||||||
|
{fundsStatus ? 'RELEASED' : 'LOCKED'}
|
||||||
|
</Tag>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Dialog open={openDialog} onClose={handleCloseDialog} fullWidth maxWidth="md">
|
<Dialog open={openDialog} onClose={handleCloseDialog} fullWidth maxWidth="md">
|
||||||
|
@ -124,5 +124,6 @@ export const project: Project = {
|
|||||||
deployerLrns: ['lrn://deployer.apps.snowballtools.com '],
|
deployerLrns: ['lrn://deployer.apps.snowballtools.com '],
|
||||||
webhooks: ['beepboop'],
|
webhooks: ['beepboop'],
|
||||||
icon: 'Icon',
|
icon: 'Icon',
|
||||||
|
fundsReleased: true,
|
||||||
baseDomains: ['baseDomain'],
|
baseDomains: ['baseDomain'],
|
||||||
};
|
};
|
||||||
|
@ -25,6 +25,7 @@ query ($projectId: String!) {
|
|||||||
prodBranch
|
prodBranch
|
||||||
auctionId
|
auctionId
|
||||||
deployerLrns
|
deployerLrns
|
||||||
|
fundsReleased
|
||||||
framework
|
framework
|
||||||
repository
|
repository
|
||||||
webhooks
|
webhooks
|
||||||
@ -76,6 +77,7 @@ query ($organizationSlug: String!) {
|
|||||||
framework
|
framework
|
||||||
auctionId
|
auctionId
|
||||||
deployerLrns
|
deployerLrns
|
||||||
|
fundsReleased
|
||||||
prodBranch
|
prodBranch
|
||||||
webhooks
|
webhooks
|
||||||
repository
|
repository
|
||||||
@ -193,6 +195,7 @@ query ($searchText: String!) {
|
|||||||
framework
|
framework
|
||||||
auctionId
|
auctionId
|
||||||
deployerLrns
|
deployerLrns
|
||||||
|
fundsReleased
|
||||||
prodBranch
|
prodBranch
|
||||||
webhooks
|
webhooks
|
||||||
updatedAt
|
updatedAt
|
||||||
|
@ -171,6 +171,7 @@ export type Project = {
|
|||||||
framework: string;
|
framework: string;
|
||||||
deployerLrns: string[];
|
deployerLrns: string[];
|
||||||
auctionId: string;
|
auctionId: string;
|
||||||
|
fundsReleased: boolean;
|
||||||
webhooks: string[];
|
webhooks: string[];
|
||||||
members: ProjectMember[];
|
members: ProjectMember[];
|
||||||
environmentVariables: EnvironmentVariable[];
|
environmentVariables: EnvironmentVariable[];
|
||||||
|
Loading…
Reference in New Issue
Block a user