Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update CMS immediately after tx submission #62

Merged
merged 2 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions hooks/use-buy-fraction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ const useHandleBuyFraction = (
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
order: any,
amount: number,
address?: Address
address: Address,
hypercertId: string | undefined,
comment: string | undefined,
) => {
if (!publicClient) {
throw new Error("No public client found");
Expand All @@ -35,7 +37,7 @@ const useHandleBuyFraction = (
order,
address,
amount,
order.price
order.price,
);

try {
Expand All @@ -60,7 +62,22 @@ const useHandleBuyFraction = (
takerOrder,
order.signature
);

const tx = await call();

fetch("/api/contributions", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
txId: tx.hash as `0x${string}`,
hypercertId: hypercertId,
amount: amount,
comment: comment,
}),
});

setTransactionHash(tx.hash as Address);
const txnReceipt = await waitForTransactionReceipt(publicClient, {
hash: tx.hash as `0x${string}`,
Expand Down
16 changes: 1 addition & 15 deletions hooks/use-support-form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,7 @@ const useSupportForm = (
throw new Error("No address found");
}

const txnReceipt = await handleBuyFraction(order, unitsToBuy, address);
if (txnReceipt) {
await fetch("/api/contributions", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
txId: txnReceipt.transactionHash as `0x${string}`,
hypercertId: hypercertId ?? "",
amount: values.fractionPayment,
comment: values.comment,
}),
});
}
await handleBuyFraction(order, unitsToBuy, address, hypercertId, values.comment);
};

return { form, isProcessing, onSubmit };
Expand Down
Loading