Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/207 #208

Merged
merged 2 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions contracts/src/fund.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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::<FundManagerConstants::VALID_ADDRESS_1>();
let valid_address_2 = contract_address_const::<FundManagerConstants::VALID_ADDRESS_2>();
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 {
Expand All @@ -206,19 +210,15 @@ 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.');
assert(
self.get_current_goal_state() >= self.getGoal(), 'Fund hasnt reached its goal yet'
);
let valid_address = contract_address_const::<FundManagerConstants::VALID_ADDRESS_1>();
// 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);
Expand Down
4 changes: 4 additions & 0 deletions contracts/tests/test_fund.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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::<FundManagerConstants::VALID_ADDRESS_1>()
}
fn _setup_() -> ContractAddress {
let contract = declare("Fund").unwrap();
let mut calldata: Array<felt252> = array![];
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ 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);
const actualFund = useAtomValue(clickedFundState);
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 (
<>
Expand Down Expand Up @@ -49,6 +51,10 @@ const Confirmation = () => {
{tx?.type === "donation" &&
<DonationConfirmation message={donationMessage} txHash={tx.txHash} />
}

{tx?.type === "withdrawn" &&
<WithdrawConfirmation message={withdrawnMessage} txHash={tx.txHash} />
}
</div>
}
</>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import ShareXButton from "@/components/ui/ShareOnX";
import React from "react";

interface WithdrawConfirmationProps {
txHash: String;
message: String;
}

const WithdrawConfirmation: React.FC<WithdrawConfirmationProps> = ({
txHash,
message,
}) => (
<>
<div className="flex flex-col items-center justify-center gap-4 text-center">
<p className="text-2xl font-light m-5">🎉 Success! Your funds have been withdrawn. Check out the transaction details and celebrate! 💸✨ <a className="text-blue-600" target="_blank" href={"https://sepolia.voyager.online/tx/" + txHash}>here.</a></p>
<p className="text-2xl font-light m-5">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!</p>
<ShareXButton message={message} />
</div>
</>
);

export default WithdrawConfirmation;
2 changes: 1 addition & 1 deletion frontend/gostarkme-web/components/ui/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const Footer = (): React.JSX.Element => {
</g>
</svg>
</a>
<a className="mx-1" href="https://x.com/web3_wagers">
<a className="mx-1" href="https://x.com/undefined_org_">
<svg
height="35"
viewBox="0 0 24 24"
Expand Down
Loading