Introduction
A production-ready set of React blocks for integrating Trustless Work’s escrow flows.
npx trustless-work listconst { selectedEscrow } = useEscrowContext();
const handleSubmit = form.handleSubmit(async (payload) => {
/**
* Create the final payload for the change milestone status mutation
*
* @param payload - The payload from the form
* @returns The final payload for the change milestone status mutation
*/
const finalPayload: ChangeMilestoneStatusPayload = {
contractId: selectedEscrow?.contractId || '', // contractId from the selectedEscrow
milestoneIndex: payload.milestoneIndex,
newStatus: payload.status,
newEvidence: payload.evidence || undefined,
serviceProvider: walletAddress || '',
};
/**
* Call the change milestone status mutation
*
* @param payload - The final payload for the change milestone statusmutation
* @param type - The type of the escrow
* @param address - The address of the escrow
*/
await changeMilestoneStatus.mutateAsync({
payload: finalPayload,
type: selectedEscrow?.type || 'multi-release',
address: walletAddress || '',
});
}const { setSelectedEscrow } = useEscrowContext();
const onCardClick = (escrow: Escrow) => {
setSelectedEscrow(escrow);
dialogStates.second.setIsOpen(true);
};const { selectedEscrow, updateEscrow } = useEscrowContext();
const handleSubmit = form.handleSubmit(async (payload) => {
/**
* Call the change milestone status mutation
*
* @param payload - The final payload for the change milestone status mutation
* @param type - The type of the escrow
* @param address - The address of the escrow
*/
await changeMilestoneStatus.mutateAsync({
payload: finalPayload,
type: selectedEscrow?.type || "multi-release", // type from the selectedEscrow
address: walletAddress || "",
});
toast.success("Milestone status updated successfully");
// Update the selected escrow in the context with the new status and evidence
updateEscrow({
...selectedEscrow,
milestones: selectedEscrow?.milestones.map((milestone, index) => {
if (index === Number(payload.milestoneIndex)) {
return {
...milestone,
status: payload.status,
evidence: payload.evidence || undefined,
};
}
return milestone;
}),
});
}npx trustless-work add escrowsnpx trustless-work add escrows/single-release