From f51ba49435ca86f6d66840e491d1a064bad3aa4d Mon Sep 17 00:00:00 2001 From: Zintarh Date: Thu, 10 Jul 2025 11:41:05 +0100 Subject: [PATCH 1/4] feat: cancel pool logic --- src/app/hooks/useCancelPool.ts | 49 ++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/app/hooks/useCancelPool.ts diff --git a/src/app/hooks/useCancelPool.ts b/src/app/hooks/useCancelPool.ts new file mode 100644 index 0000000..98dbc10 --- /dev/null +++ b/src/app/hooks/useCancelPool.ts @@ -0,0 +1,49 @@ +import { ActionType } from "@/lib/types"; +import { myProvider } from "@/lib/utils"; +import { PREDIFI_CONTRACT_ADDRESS } from "@/static"; +import { useAccount } from "@starknet-react/core"; +import React, { useState } from "react"; +import toast from "react-hot-toast"; +import { cairo, CallData } from "starknet"; + +export default function useCancelPool(poolId: string) { + const { account } = useAccount(); + + const [cancelstatus, setCancelStatus] = useState("idle"); + + const cancelPool = async () => { + if (!account) { + return; + } + try { + setCancelStatus("pending"); + const result = await account.execute({ + contractAddress: PREDIFI_CONTRACT_ADDRESS, + entrypoint: "cancel_pool", + calldata: CallData.compile({ + pool_id: cairo.uint256(poolId), + }), + }); + + const status = await myProvider.waitForTransaction( + result.transaction_hash + ); + + if (status.isSuccess()) { + toast.success("Success! pool cancelled successfully."); + setCancelStatus("success"); + } + } catch (err) { + console.log(err); + setCancelStatus("error"); + toast.error("Error cancelling pool ."); + } finally { + setCancelStatus("idle"); + } + }; + + return { + cancelstatus, + cancelPool, + }; +} From be7ac9555a46d53c3ca1ae5665da5fe4a5d0ed2d Mon Sep 17 00:00:00 2001 From: Zintarh Date: Thu, 10 Jul 2025 11:42:00 +0100 Subject: [PATCH 2/4] feat: action type --- src/lib/types.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib/types.ts b/src/lib/types.ts index 1dbc6a8..24c53e0 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -78,3 +78,4 @@ export type PoolDetails = { poolType: string; status: string; }; +export type ActionType = "idle" | "pending" | "success" | "error"; From 634e3973a32ca1542016ce09bf3cbcdd2a7e8e03 Mon Sep 17 00:00:00 2001 From: Zintarh Date: Thu, 10 Jul 2025 11:42:51 +0100 Subject: [PATCH 3/4] feat: implement cancel pool --- .../[id]/components/poolPrediction.tsx | 59 +++++++++++++------ src/app/dashboard/pool-market/[id]/page.tsx | 37 ++++++------ src/contexts/pool-creation-context.tsx | 3 +- 3 files changed, 61 insertions(+), 38 deletions(-) diff --git a/src/app/dashboard/pool-market/[id]/components/poolPrediction.tsx b/src/app/dashboard/pool-market/[id]/components/poolPrediction.tsx index c63ac9e..21caaef 100644 --- a/src/app/dashboard/pool-market/[id]/components/poolPrediction.tsx +++ b/src/app/dashboard/pool-market/[id]/components/poolPrediction.tsx @@ -1,20 +1,34 @@ -import { Button } from '@/components/ui/button'; -import { Input } from '@/components/ui/input'; -import Image from 'next/image'; -import React, { useState } from 'react'; +import useCancelPool from "@/app/hooks/useCancelPool"; +import { Button } from "@/components/ui/button"; +import { Input } from "@/components/ui/input"; +import { useAccount } from "@starknet-react/core"; +import Image from "next/image"; +import React, { useState } from "react"; interface Prediction { - name: string + name: string; + creator: string; + poolId: string; predictions: { options: string; odds: string; }[]; } -export default function PoolPrediction({ predictions, name }: Prediction) { - const [stake, setStake] = useState('0'); - const [selectedOption, setSelectedOption] = useState('Option 1'); - const [selectedOdds, setSelectedOdds] = useState('1.17'); +export default function PoolPrediction({ + predictions, + name, + creator, + poolId +}: Prediction) { + const [stake, setStake] = useState("0"); + const [selectedOption, setSelectedOption] = useState("Option 1"); + const [selectedOdds, setSelectedOdds] = useState("1.17"); + const { address } = useAccount(); + const creatorAddress = creator as `0x${string}`; + + const { cancelPool, cancelstatus } = useCancelPool(poolId); + return (
@@ -23,8 +37,8 @@ export default function PoolPrediction({ predictions, name }: Prediction) { ))} - {/* Stake input */} +
Stake @@ -54,7 +68,6 @@ export default function PoolPrediction({ predictions, name }: Prediction) {
- {/* Stake Preview */}

Preview

@@ -82,11 +95,23 @@ export default function PoolPrediction({ predictions, name }: Prediction) {
- + {address && creatorAddress === address && ( + + )} + + {!address && ( + + )} +
- {' '} + {" "} Once confirmed, this bet cannot be changed.
diff --git a/src/app/dashboard/pool-market/[id]/page.tsx b/src/app/dashboard/pool-market/[id]/page.tsx index 99ab7ac..f9144d1 100644 --- a/src/app/dashboard/pool-market/[id]/page.tsx +++ b/src/app/dashboard/pool-market/[id]/page.tsx @@ -4,10 +4,7 @@ import { useParams } from "next/navigation"; import { useContractFetch } from "@/app/hooks/useBlockchain"; import { PREDIFI_ABI } from "@/app/abi/predifi_abi"; import { GET_POOL } from "@/constants/functionNames"; -import { - PoolCardDetails, - PoolDescription, -} from "./components/poolDetails"; +import { PoolCardDetails, PoolDescription } from "./components/poolDetails"; import PoolPrediction from "./components/poolPrediction"; import SocialsShare from "./components/socialsShare"; import Comments from "@/components/ui/comments"; @@ -100,7 +97,6 @@ export default function Market() { ); } - return (
@@ -111,7 +107,6 @@ export default function Market() {
- {/* Section 1 */} {readIsLoading ? ( ) : readError ? ( @@ -212,19 +207,23 @@ export default function Market() {
- + {poolDetails && ( + + )}
); diff --git a/src/contexts/pool-creation-context.tsx b/src/contexts/pool-creation-context.tsx index 6388750..a96b903 100644 --- a/src/contexts/pool-creation-context.tsx +++ b/src/contexts/pool-creation-context.tsx @@ -57,7 +57,7 @@ export function PoolCreationProvider({ children }: { children: ReactNode }) { } try { setIsCreatingPool(true); - toast("heeeyyy"); + const result = await account.execute({ contractAddress: PREDIFI_CONTRACT_ADDRESS, entrypoint: "create_pool", @@ -86,7 +86,6 @@ export function PoolCreationProvider({ children }: { children: ReactNode }) { result.transaction_hash ); - console.log(status); if (status.isSuccess()) { toast.success("Success! 🎉 Your pool has been created."); setIsComplete(true); From fd77451bff70b8013c0e94381fb83fda081f4038 Mon Sep 17 00:00:00 2001 From: Zintarh Date: Tue, 29 Jul 2025 08:59:44 +0100 Subject: [PATCH 4/4] fix: ux fix --- .../[id]/components/CancelPool.tsx | 27 ++++++++ .../[id]/components/poolPrediction.tsx | 65 ++++--------------- src/app/hooks/useCancelPool.ts | 1 + 3 files changed, 39 insertions(+), 54 deletions(-) create mode 100644 src/app/dashboard/pool-market/[id]/components/CancelPool.tsx diff --git a/src/app/dashboard/pool-market/[id]/components/CancelPool.tsx b/src/app/dashboard/pool-market/[id]/components/CancelPool.tsx new file mode 100644 index 0000000..4744983 --- /dev/null +++ b/src/app/dashboard/pool-market/[id]/components/CancelPool.tsx @@ -0,0 +1,27 @@ +import useCancelPool from '@/app/hooks/useCancelPool'; +import { Button } from '@/components/ui/button'; +import { useAccount } from '@starknet-react/core'; + +interface CancelPoolProps { + poolId: string; + creator: string; +} + +export default function CancelPool({ poolId, creator }: CancelPoolProps) { + const { address } = useAccount(); + const creatorAddress = creator as `0x${string}`; + const { cancelPool, cancelstatus } = useCancelPool(poolId); + + if (!address || creatorAddress !== address) { + return null; + } + + return ( + + ); +} diff --git a/src/app/dashboard/pool-market/[id]/components/poolPrediction.tsx b/src/app/dashboard/pool-market/[id]/components/poolPrediction.tsx index cedb6d0..fa60d02 100644 --- a/src/app/dashboard/pool-market/[id]/components/poolPrediction.tsx +++ b/src/app/dashboard/pool-market/[id]/components/poolPrediction.tsx @@ -1,18 +1,10 @@ -<<<<<<< HEAD -import useCancelPool from "@/app/hooks/useCancelPool"; -import { Button } from "@/components/ui/button"; -import { Input } from "@/components/ui/input"; -import { useAccount } from "@starknet-react/core"; -import Image from "next/image"; -import React, { useState } from "react"; -======= import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { truncate } from '@/lib/utils'; import Image from 'next/image'; import React, { useState } from 'react'; import { FaSpinner } from 'react-icons/fa'; ->>>>>>> 55325bae59988d2b94495668222e4934c581a2a4 +import CancelPool from './CancelPool'; interface Prediction { name: string; @@ -28,37 +20,23 @@ interface Prediction { isParticipationLoading?: boolean; } -<<<<<<< HEAD -export default function PoolPrediction({ - predictions, - name, - creator, - poolId -}: Prediction) { - const [stake, setStake] = useState("0"); - const [selectedOption, setSelectedOption] = useState("Option 1"); - const [selectedOdds, setSelectedOdds] = useState("1.17"); - const { address } = useAccount(); - const creatorAddress = creator as `0x${string}`; - - const { cancelPool, cancelstatus } = useCancelPool(poolId); - -======= -export default function PoolPrediction({ predictions, name, isConnected, address, hasParticipatedAlready, isParticipationLoading }: Prediction) { +export default function PoolPrediction({ predictions, name, creator, poolId, isConnected, address, hasParticipatedAlready, isParticipationLoading }: Prediction) { const [stake, setStake] = useState('0'); const [selectedOption, setSelectedOption] = useState('Option 1'); const [selectedOdds, setSelectedOdds] = useState('1.17'); ->>>>>>> 55325bae59988d2b94495668222e4934c581a2a4 return (
-

Select Prediction

+
+

Select Prediction

+ +
{predictions.map((prediction, index) => ( ))} - + {/* Stake input */}
Stake @@ -88,6 +66,7 @@ export default function PoolPrediction({ predictions, name, isConnected, address
+ {/* Stake Preview */}

Preview

@@ -114,27 +93,6 @@ export default function PoolPrediction({ predictions, name, isConnected, address {+selectedOdds * +stake} strk
-<<<<<<< HEAD -
- {address && creatorAddress === address && ( - - )} - - {!address && ( - - )} - -
- {" "} - Once confirmed, this bet cannot be changed. -======= { isParticipationLoading ?
->>>>>>> 55325bae59988d2b94495668222e4934c581a2a4
: hasParticipatedAlready ? @@ -195,4 +152,4 @@ export function SelectPrediction({
{odds}
); -} +} \ No newline at end of file diff --git a/src/app/hooks/useCancelPool.ts b/src/app/hooks/useCancelPool.ts index 98dbc10..455564e 100644 --- a/src/app/hooks/useCancelPool.ts +++ b/src/app/hooks/useCancelPool.ts @@ -13,6 +13,7 @@ export default function useCancelPool(poolId: string) { const cancelPool = async () => { if (!account) { + toast.error("Account not connected!"); return; } try {