Skip to content
Open
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
29 changes: 27 additions & 2 deletions src/contexts/pool-creation-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,26 @@ export function PoolCreationProvider({ children }: { children: ReactNode }) {
try {
setIsCreatingPool(true);

// 1. Collect pool creation fee
toast.loading("Collecting pool creation fee...");
const feeResult = await account.execute({
contractAddress: PREDIFI_CONTRACT_ADDRESS,
entrypoint: "collect_pool_creation_fee",
calldata: [account.address],
});
const feeStatus = await myProvider.waitForTransaction(feeResult.transaction_hash);
if (!feeStatus.isSuccess()) {
toast.dismiss();
toast.error("Failed to collect pool creation fee. Please check your balance.");
setIsCreatingPool(false);
return;
}
toast.dismiss();
toast.success("Fee collected. Creating pool...");
// 2. Proceed to create pool



const result = await account.execute({
contractAddress: PREDIFI_CONTRACT_ADDRESS,
entrypoint: "create_pool",
Expand All @@ -81,7 +101,6 @@ export function PoolCreationProvider({ children }: { children: ReactNode }) {
category: createCairoEnum(formData.categories[0]),
}),
});

const status = await myProvider.waitForTransaction(
result.transaction_hash
);
Expand All @@ -90,7 +109,13 @@ export function PoolCreationProvider({ children }: { children: ReactNode }) {
toast.success("Success! 🎉 Your pool has been created.");
setIsComplete(true);
}
} catch (err) {
} catch (err: any) {
toast.dismiss();
if (err?.message?.includes("insufficient")) {
toast.error("Insufficient balance to collect pool creation fee.");
} else {
toast.error("An error occurred during pool creation.");
}
console.log(err);
} finally {
setIsCreatingPool(false);
Expand Down