diff --git a/frontend/gostarkme-web/components/modules/Fund/Fund.tsx b/frontend/gostarkme-web/components/modules/Fund/Fund.tsx index e21fcc5..55da3a4 100644 --- a/frontend/gostarkme-web/components/modules/Fund/Fund.tsx +++ b/frontend/gostarkme-web/components/modules/Fund/Fund.tsx @@ -17,57 +17,59 @@ 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()); + + 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 +78,13 @@ const Fund = () => { return ( <> - {loading && + {loading && (
-
- Loading funding... -
+
Loading funding...
- } - {!loading && + )} + {!loading && (

{fund.name}

@@ -92,17 +92,51 @@ 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 && ( + + )} + + )} + {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..638e733 100644 --- a/frontend/gostarkme-web/next.config.mjs +++ b/frontend/gostarkme-web/next.config.mjs @@ -1,31 +1,30 @@ - /** @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, + }, +}; - 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