From 79a3b3519e75b758da65f2403222b587d64ea70f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emmanuel=20Ag=C3=BCero?= <54730752+EmmanuelAR@users.noreply.github.com> Date: Fri, 8 Nov 2024 12:21:11 -0600 Subject: [PATCH 1/2] setState method only can be call by admins --- contracts/src/fund.cairo | 8 ++++---- contracts/tests/test_fund.cairo | 4 ++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/contracts/src/fund.cairo b/contracts/src/fund.cairo index 0e3f6ff..d809d38 100644 --- a/contracts/src/fund.cairo +++ b/contracts/src/fund.cairo @@ -197,6 +197,10 @@ pub mod Fund { self.token_dispatcher().balance_of(get_contract_address()) } fn setState(ref self: ContractState, state: u8) { + let caller = get_caller_address(); + let valid_address_1 = contract_address_const::(); + let valid_address_2 = contract_address_const::(); + assert!(valid_address_1 == caller || valid_address_2 == caller, "Only Admins can change the fund state."); self.state.write(state); } fn getState(self: @ContractState) -> u8 { @@ -206,7 +210,6 @@ pub mod Fund { return self.voters.read(get_caller_address()); } fn withdraw(ref self: ContractState) { - // Verifications let caller = get_caller_address(); assert!(self.owner.read() == caller, "You are not the owner"); assert(self.state.read() == FundStates::CLOSED, 'Fund not close goal yet.'); @@ -214,11 +217,8 @@ pub mod Fund { self.get_current_goal_state() >= self.getGoal(), 'Fund hasnt reached its goal yet' ); let valid_address = contract_address_const::(); - // Withdraw let withdrawn_amount = self.get_current_goal_state() * 95 / 100; let fund_manager_amount = self.get_current_goal_state() * 5 / 100; - // TODO: Calculate balance to deposit in owner address and in fund manager address (95% - // and 5%), also transfer the amount to fund manager address. self.token_dispatcher().approve(self.getOwner(), withdrawn_amount); self.token_dispatcher().transfer(self.getOwner(), withdrawn_amount); self.token_dispatcher().approve(valid_address, fund_manager_amount); diff --git a/contracts/tests/test_fund.cairo b/contracts/tests/test_fund.cairo index 836705e..f0fc4df 100644 --- a/contracts/tests/test_fund.cairo +++ b/contracts/tests/test_fund.cairo @@ -57,6 +57,9 @@ fn CONTACT_HANDLE_1() -> ByteArray { fn CONTACT_HANDLE_2() -> ByteArray { "Lorem impsum, Lorem impsum, Lorem impsum, Lorem impsum, Lorem impsum, Lorem impsum, Lorem impsum, Lorem impsum" } +fn VALID_ADDRESS_1() -> ContractAddress { + contract_address_const::() +} fn _setup_() -> ContractAddress { let contract = declare("Fund").unwrap(); let mut calldata: Array = array![]; @@ -362,6 +365,7 @@ fn test_emit_event_donation_received() { let token_dispatcher = IERC20Dispatcher { contract_address: token_address }; //Donation target configuration in the dispatcher + start_cheat_caller_address(contract_address, VALID_ADDRESS_1()); dispatcher.setState(2); start_cheat_caller_address(contract_address, FUND_MANAGER()); dispatcher.setGoal(goal); From c3cc2853bb89523a315875000f00c1d181dc09ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emmanuel=20Ag=C3=BCero?= <54730752+EmmanuelAR@users.noreply.github.com> Date: Fri, 8 Nov 2024 12:21:30 -0600 Subject: [PATCH 2/2] Add withdraw page confirmation page and fix x url --- .../components/modules/Fund/FundWithdraw.tsx | 2 +- .../modules/confirmation/Confirmation.tsx | 6 +++++ .../confirmation/WithdrawConfirmation.tsx | 22 +++++++++++++++++++ .../gostarkme-web/components/ui/Footer.tsx | 2 +- 4 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 frontend/gostarkme-web/components/modules/confirmation/WithdrawConfirmation.tsx diff --git a/frontend/gostarkme-web/components/modules/Fund/FundWithdraw.tsx b/frontend/gostarkme-web/components/modules/Fund/FundWithdraw.tsx index b939bcf..cc2c592 100644 --- a/frontend/gostarkme-web/components/modules/Fund/FundWithdraw.tsx +++ b/frontend/gostarkme-web/components/modules/Fund/FundWithdraw.tsx @@ -31,7 +31,7 @@ export const FundWithdraw = ({ currentBalance, goal, addr, setLoading, getDetail const fundContract = new Contract(fundAbi, addr, wallet?.account); fundContract.withdraw() .then(async (resp: InvokeFunctionResponse) => { - setLatestTx({ txHash: resp.transaction_hash, type: "vote" }); + setLatestTx({ txHash: resp.transaction_hash, type: "withdrawn" }); router.push("/app/confirmation"); }) .catch((e: any) => { getDetails() }); diff --git a/frontend/gostarkme-web/components/modules/confirmation/Confirmation.tsx b/frontend/gostarkme-web/components/modules/confirmation/Confirmation.tsx index f4c6093..563c5f5 100644 --- a/frontend/gostarkme-web/components/modules/confirmation/Confirmation.tsx +++ b/frontend/gostarkme-web/components/modules/confirmation/Confirmation.tsx @@ -9,6 +9,7 @@ import Navbar from "@/components/ui/Navbar"; import { navItems } from "@/constants"; import { clickedFundState } from "@/state/nFunds"; import { walletStarknetkitLatestAtom } from "@/state/connectedWallet"; +import WithdrawConfirmation from "./WithdrawConfirmation"; const Confirmation = () => { const tx = useAtomValue(latestTxAtom); @@ -16,6 +17,7 @@ const Confirmation = () => { const voteMessage = ` πŸ—³οΈ Just cast my vote for an amazing cause called ${actualFund?.name} on Go Stark Me! This fund needs more votes to start raising fundsβ€”every vote counts! Let’s support projects that make a difference at https://web3wagers.github.io/gostarkme/ @undefined_org_ πŸ™ŒπŸ’« #GoStarkMe #Starknet #CommunityPower`; const donationMessage = `πŸ™Œ Proud to support ${actualFund?.name} on Go Stark Me! Donations make a difference. πŸ’ͺ Go ahead and donate at https://web3wagers.github.io/gostarkme/ @undefined_org_ #Starknet #GoStarkMe #Web3Wagers`; const newFundMessage = `πŸš€ Just launched a new fund on Go Stark Me called ${actualFund?.name}! I’m raising support for an important cause, and every contribution makes a difference. Join me in making an impact at https://web3wagers.github.io/gostarkme/! πŸ’ͺ🌍 Check it out on @undefined_org_ #GoStarkMe #Starknet #BlockchainForGood`; + const withdrawnMessage = `πŸŽ‰ We did it! The goal for ${actualFund?.name} on Go Stark Me has been reached, and funds have been successfully withdrawn! πŸ™Œ Huge thanks to everyone who contributed and made this possible. Let’s keep making an impact! 🌍πŸ’ͺ Check it out at https://web3wagers.github.io/gostarkme/ #GoStarkMe #Starknet #CommunitySuccess`; return ( <> @@ -49,6 +51,10 @@ const Confirmation = () => { {tx?.type === "donation" && } + + {tx?.type === "withdrawn" && + + } } diff --git a/frontend/gostarkme-web/components/modules/confirmation/WithdrawConfirmation.tsx b/frontend/gostarkme-web/components/modules/confirmation/WithdrawConfirmation.tsx new file mode 100644 index 0000000..cf1f07e --- /dev/null +++ b/frontend/gostarkme-web/components/modules/confirmation/WithdrawConfirmation.tsx @@ -0,0 +1,22 @@ +import ShareXButton from "@/components/ui/ShareOnX"; +import React from "react"; + +interface WithdrawConfirmationProps { + txHash: String; + message: String; +} + +const WithdrawConfirmation: React.FC = ({ + txHash, + message, +}) => ( + <> +
+

πŸŽ‰ Success! Your funds have been withdrawn. Check out the transaction details and celebrate! πŸ’Έβœ¨ here.

+

Goal Achieved! Your funds have been withdrawn, and the campaign is a success! Share your contribution on X and let everyone know how awesome you are!

+ +
+ +); + +export default WithdrawConfirmation; diff --git a/frontend/gostarkme-web/components/ui/Footer.tsx b/frontend/gostarkme-web/components/ui/Footer.tsx index bb647eb..29a44c7 100644 --- a/frontend/gostarkme-web/components/ui/Footer.tsx +++ b/frontend/gostarkme-web/components/ui/Footer.tsx @@ -32,7 +32,7 @@ const Footer = (): React.JSX.Element => { - +