From 99f8c670b3cf033efe964fcad7d2b9e299950bcd Mon Sep 17 00:00:00 2001 From: villarley <115122095+Villarley@users.noreply.github.com> Date: Fri, 22 Nov 2024 09:03:56 -0600 Subject: [PATCH 1/3] feat: add owner check and conditional rendering for Fund component - Implemented owner check in the Fund component using `getOwner` from the contract. - Added conditional rendering for "Withdraw" and "Donate" buttons based on ownership and fund state. - Updated the `getDetails` function to include owner address retrieval. - Enhanced error handling for fetching fund details. - Improved user feedback with appropriate messages for different fund states. --- .../components/modules/Fund/Fund.tsx | 150 +++++++++++------- frontend/gostarkme-web/next.config.mjs | 57 +++---- 2 files changed, 123 insertions(+), 84 deletions(-) diff --git a/frontend/gostarkme-web/components/modules/Fund/Fund.tsx b/frontend/gostarkme-web/components/modules/Fund/Fund.tsx index e21fcc5..a4f25bc 100644 --- a/frontend/gostarkme-web/components/modules/Fund/Fund.tsx +++ b/frontend/gostarkme-web/components/modules/Fund/Fund.tsx @@ -17,57 +17,61 @@ import LoadingSpinner from "@/components/ui/LoadingSpinner"; import { FundWithdraw } from "./FundWithdraw"; const Fund = () => { - const wallet = useAtomValue(walletStarknetkitLatestAtom); - - const [fundManagerContract, _setFundManagerContract] = useState(new Contract(fundManager, FUND_MANAGER_ADDR, wallet?.account)); + const [fundManagerContract, _setFundManagerContract] = useState( + new Contract(fundManager, FUND_MANAGER_ADDR, wallet?.account) + ); const [fund, setFund] = useState({}); - const [loading, setLoading] = useState(true); + const [isOwner, setIsOwner] = useState(false); const clickedFund = useAtomValue(clickedFundState); async function getDetails() { - let addr = await fundManagerContract.getFund(clickedFund?.id); - addr = "0x" + addr.toString(16); - const fundContract = new Contract(fundAbi, addr, wallet?.account); - - // GET FUND NAME - let name = await fundContract.getName(); - // GET FUND DESCRIPTION - - let desc = await fundContract.getReason(); - if (desc == " ") { - desc = "No description provided"; + try { + let addr = await fundManagerContract.getFund(clickedFund?.id); + addr = "0x" + addr.toString(16); + const fundContract = new Contract(fundAbi, addr, wallet?.account); + + // Fetch fund details + let name = await fundContract.getName(); + let desc = await fundContract.getReason(); + if (desc == " ") { + desc = "No description provided"; + } + let state = await fundContract.getState(); + let currentBalance = await fundContract.get_current_goal_state(); + currentBalance = BigInt(currentBalance) / BigInt(10 ** 18); + let goal = await fundContract.getGoal(); + goal = BigInt(goal) / BigInt(10 ** 18); + let upVotes = await fundContract.getUpVotes(); + let evidenceLink = await fundContract.get_evidence_link(); + let contactHandle = await fundContract.get_contact_handle(); + + console.log(wallet?.account?.address.toLowerCase()); + // Fetch owner + const owner = (await fundContract.getOwner()).toString(); + setIsOwner(owner.toLowerCase() === wallet?.account?.address.toLowerCase()); + // IF you want to test the functionality of the owner, uncomment the line below + // setIsOwner("YOUR WALLET ADDRESS" === wallet?.account?.address.toLowerCase()); + + setFund({ + name: name, + desc: desc, + state: state, + currentBalance: currentBalance, + goal: goal, + upVotes: upVotes, + addr: addr, + evidenceLink: evidenceLink, + contactHandle: contactHandle, + }); + } catch (error) { + console.error("Error fetching fund details:", error); + } finally { + setLoading(false); } - let state = await fundContract.getState(); - - let currentBalance = await fundContract.get_current_goal_state(); - - currentBalance = BigInt(currentBalance) / BigInt(10 ** 18); - - let goal = await fundContract.getGoal(); - goal = BigInt(goal) / BigInt(10 ** 18); - - let upVotes = await fundContract.getUpVotes(); - - let evidenceLink = await fundContract.get_evidence_link(); - - let contactHandle = await fundContract.get_contact_handle(); - - setFund({ - name: name, - desc: desc, - state: state, - currentBalance: currentBalance, - goal: goal, - upVotes: upVotes, - addr: addr, - evidenceLink: evidenceLink, - contactHandle: contactHandle - }); - setLoading(false); } useEffect(() => { @@ -76,15 +80,13 @@ const Fund = () => { return ( <> - {loading && + {loading && (
-
- Loading funding... -
+
Loading funding...
- } - {!loading && + )} + {!loading && (

{fund.name}

@@ -92,17 +94,53 @@ const Fund = () => {

{fund.desc}

Evidence

- {fund.evidenceLink} + + {fund.evidenceLink} +

Contact handle

- {fund.contactHandle} - {Number(fund.state) === 0 &&

Fund is currently innactive.

} - {Number(fund.state) === 1 && } - {Number(fund.state) === 2 && } - {Number(fund.state) === 3 && } - {Number(fund.state) === 4 &&

Fund was already withdrawed.

} + + {fund.contactHandle} + + {Number(fund.state) === 0 &&

Fund is currently inactive.

} + {Number(fund.state) === 1 && ( + + )} + {Number(fund.state) === 2 && ( + <> + {isOwner ? ( +

You are the owner. Donations will go towards your funding goal.

+ ) : ( + + )} + + )} + {Number(fund.state) === 3 && isOwner && ( + + )} + {Number(fund.state) === 3 && !isOwner && ( +

Funds are ready for withdrawal by the owner.

+ )} + {Number(fund.state) === 4 &&

Fund was already withdrawn.

}
- } + )} ); }; diff --git a/frontend/gostarkme-web/next.config.mjs b/frontend/gostarkme-web/next.config.mjs index 50c9687..3150fc1 100644 --- a/frontend/gostarkme-web/next.config.mjs +++ b/frontend/gostarkme-web/next.config.mjs @@ -1,31 +1,32 @@ - /** @type {import('next').NextConfig} */ const nextConfig = { - /** - * Enable static exports for the App Router. - * - * @see https://nextjs.org/docs/app/building-your-application/deploying/static-exports - */ - output: "export", - - /** - * Set base path. This is the slug of your GitHub repository. - * - * @see https://nextjs.org/docs/app/api-reference/next-config-js/basePath - */ - basePath: "/gostarkme", + /** + * Enable static exports for the App Router. + * + * @see https://nextjs.org/docs/app/building-your-application/deploying/static-exports + */ + // output: "export", + + /** + * Set base path. This is the slug of your GitHub repository. + * + * @see https://nextjs.org/docs/app/api-reference/next-config-js/basePath + */ + // basePath: "/gostarkme", + + // assetPrefix: 'https://web3wagers.github.io/gostarkme', + + /** + * Disable server-based image optimization. Next.js does not support + * dynamic features with static exports. + * + * @see https://nextjs.org/docs/app/api-reference/components/image#unoptimized + */ + // images: { + // unoptimized: true, + // }, + + reactStrictMode: false, +}; - assetPrefix: 'https://web3wagers.github.io/gostarkme', - - /** - * Disable server-based image optimization. Next.js does not support - * dynamic features with static exports. - * - * @see https://nextjs.org/docs/app/api-reference/components/image#unoptimized - */ - images: { - unoptimized: true, - }, - }; - - export default nextConfig; +export default nextConfig; \ No newline at end of file From e266fdf5d58b30059ab63c6cde63ddc14b8262f5 Mon Sep 17 00:00:00 2001 From: villarley <115122095+Villarley@users.noreply.github.com> Date: Fri, 22 Nov 2024 21:27:15 -0600 Subject: [PATCH 2/3] Requested Changes Removed the p --- frontend/gostarkme-web/components/modules/Fund/Fund.tsx | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/frontend/gostarkme-web/components/modules/Fund/Fund.tsx b/frontend/gostarkme-web/components/modules/Fund/Fund.tsx index a4f25bc..55da3a4 100644 --- a/frontend/gostarkme-web/components/modules/Fund/Fund.tsx +++ b/frontend/gostarkme-web/components/modules/Fund/Fund.tsx @@ -53,8 +53,6 @@ const Fund = () => { // Fetch owner const owner = (await fundContract.getOwner()).toString(); setIsOwner(owner.toLowerCase() === wallet?.account?.address.toLowerCase()); - // IF you want to test the functionality of the owner, uncomment the line below - // setIsOwner("YOUR WALLET ADDRESS" === wallet?.account?.address.toLowerCase()); setFund({ name: name, @@ -114,9 +112,7 @@ const Fund = () => { )} {Number(fund.state) === 2 && ( <> - {isOwner ? ( -

You are the owner. Donations will go towards your funding goal.

- ) : ( + {!isOwner && ( Date: Sat, 23 Nov 2024 14:40:00 -0600 Subject: [PATCH 3/3] Requested change --- frontend/gostarkme-web/next.config.mjs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/frontend/gostarkme-web/next.config.mjs b/frontend/gostarkme-web/next.config.mjs index 3150fc1..638e733 100644 --- a/frontend/gostarkme-web/next.config.mjs +++ b/frontend/gostarkme-web/next.config.mjs @@ -5,16 +5,16 @@ const nextConfig = { * * @see https://nextjs.org/docs/app/building-your-application/deploying/static-exports */ - // output: "export", + output: "export", /** * Set base path. This is the slug of your GitHub repository. * * @see https://nextjs.org/docs/app/api-reference/next-config-js/basePath */ - // basePath: "/gostarkme", + basePath: "/gostarkme", - // assetPrefix: 'https://web3wagers.github.io/gostarkme', + assetPrefix: 'https://web3wagers.github.io/gostarkme', /** * Disable server-based image optimization. Next.js does not support @@ -22,11 +22,9 @@ const nextConfig = { * * @see https://nextjs.org/docs/app/api-reference/components/image#unoptimized */ - // images: { - // unoptimized: true, - // }, - - reactStrictMode: false, + images: { + unoptimized: true, + }, }; export default nextConfig; \ No newline at end of file