EstateChain/my-app/components/CreateEscrowButton.tsx
2024-10-13 00:47:01 +03:00

31 lines
844 B
TypeScript

import React from 'react';
import { useEscrow } from '../hooks/useEscrow';
interface CreateEscrowButtonProps {
seller: string;
buyer: string;
amount: number;
}
export const CreateEscrowButton: React.FC<CreateEscrowButtonProps> = ({ seller, buyer, amount }) => {
const { createEscrow, isLoading } = useEscrow();
const handleCreateEscrow = async () => {
try {
await createEscrow(seller, buyer, amount.toString());
alert('Escrow created successfully!');
} catch (error) {
if (error instanceof Error) {
alert(`Failed to create escrow: ${error.message}`);
} else {
alert('Failed to create escrow: Unknown error');
}
}
};
return (
<button onClick={handleCreateEscrow} disabled={isLoading}>
{isLoading ? 'Creating Escrow...' : 'Create Escrow'}
</button>
);
};