Skip to content

Commit

Permalink
Get fund type from contract
Browse files Browse the repository at this point in the history
  • Loading branch information
EmmanuelAR committed Dec 16, 2024
1 parent 306c43a commit bd8f18d
Show file tree
Hide file tree
Showing 6 changed files with 161 additions and 93 deletions.
4 changes: 3 additions & 1 deletion frontend/gostarkme-web/app/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ const Dashboard = () => {
}
// GET FUND ID
let fund_id = await fundContract.get_id();
// GET FUND TYPE
let fund_type = await fundContract.get_type();
fundings.push({
type: "Project",
type: Number(BigInt(fund_type)) === 1 ? "Project" : "Charity",
title: name,
description: desc,
fund_id: fund_id.toString(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ interface FundingStepProps {
setEvidenceLink: (name: string) => void;
contactHandle: string;
setContactHandle: (name: string) => void;
errors: { fundingName: string; goal: string ;evidenceLink: string; contactHandle: string }; // Expecting errors as props
setErrors: React.Dispatch<React.SetStateAction<{ fundingName: string; goal: string ;evidenceLink: string; contactHandle: string }>>; // Specify the type for setErrors
type: string;
setType: (name: string) => void;
errors: { fundingName: string; goal: string ;evidenceLink: string; contactHandle: string; type: string};
setErrors: React.Dispatch<React.SetStateAction<{ fundingName: string; goal: string ;evidenceLink: string; contactHandle: string; type:string }>>;
}

const FundingStep: React.FC<FundingStepProps> = ({
Expand All @@ -22,6 +24,8 @@ const FundingStep: React.FC<FundingStepProps> = ({
setEvidenceLink,
contactHandle,
setContactHandle,
type,
setType,
errors,
setErrors,
}) => {
Expand Down Expand Up @@ -67,9 +71,19 @@ const FundingStep: React.FC<FundingStepProps> = ({
const newValue = e.target.value;
setContactHandle(newValue);
if (!newValue) {
setErrors((prev) => ({ ...prev, evidenceLink: 'Contact handle is required.' }));
setErrors((prev) => ({ ...prev, contactHandle: 'Contact handle is required.' }));
} else {
setErrors((prev) => ({ ...prev, evidenceLink: '' }));
setErrors((prev) => ({ ...prev, contactHandle: '' }));
}
};

const handleType = (e: React.ChangeEvent<HTMLSelectElement>) => {
const newValue = e.target.value;
setType(newValue);
if (!newValue) {
setErrors((prev) => ({ ...prev, type: 'Type is required.' }));
} else {
setErrors((prev) => ({ ...prev, type: '' }));
}
};

Expand Down Expand Up @@ -108,6 +122,16 @@ const FundingStep: React.FC<FundingStepProps> = ({
className={`mt-4 p-2 pl-4 border rounded w-full placeholder:text-base ${errors.contactHandle ? 'border-red-500' : 'border-black'}`}
required
/>
<select
className={`mt-4 p-2 pl-4 border rounded w-full text-base ${errors.type ? 'border-red-500' : 'border-black'}`}
value={type}
onChange={handleType}
required
>
<option value="" disabled>Select the fund type</option>
<option value="1">Project</option>
<option value="2">Charity</option>
</select>

{/* Error Messages */}
{errors.fundingName && (
Expand All @@ -122,6 +146,9 @@ const FundingStep: React.FC<FundingStepProps> = ({
{errors.contactHandle && (
<p className="mt-5 text-red-500 text-center mb-4">{errors.contactHandle}</p>
)}
{errors.type && (
<p className="mt-5 text-red-500 text-center mb-4">{errors.type}</p>
)}
</div>
);
};
Expand Down
14 changes: 11 additions & 3 deletions frontend/gostarkme-web/components/modules/newfunding/Stages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ const Stages = () => {
const [fundingName, setFundingName] = useState("");
const [goal, setGoal] = useState("");
const [fundingDescription, setFundingDescription] = useState("");
const [errors, setErrors] = useState({ fundingName: "", goal: "", evidenceLink: "", contactHandle: "" });
const [errors, setErrors] = useState({ fundingName: "", goal: "", evidenceLink: "", contactHandle: "" ,type:""});
const [evidenceLink, setEvidenceLink] = useState("");
const [contactHandle, setContactHandle] = useState("");
const [type, setType] = useState("");
const setLatesTx = useSetAtom(latestTxAtom);
const setActualFund = useSetAtom(clickedFundState);

Expand All @@ -27,7 +28,7 @@ const Stages = () => {

const handleNextStep = () => {
// Reset errors
setErrors({ fundingName: "", goal: "", evidenceLink: "", contactHandle: "" });
setErrors({ fundingName: "", goal: "", evidenceLink: "", contactHandle: "" ,type:""});

// Validate fields
let hasErrors = false;
Expand All @@ -48,6 +49,10 @@ const Stages = () => {
setErrors((prev) => ({ ...prev, contactHandle: "The contact handle is required." }));
hasErrors = true;
}
if (!type) {
setErrors((prev) => ({ ...prev, type: "The type is required." }));
hasErrors = true;
}
}

// If there are no errors, proceed to the next step
Expand All @@ -65,8 +70,9 @@ const Stages = () => {
};

async function newFund() {

const fundManagerContract = new Contract(fundManager, FUND_MANAGER_ADDR, wallet?.account);
fundManagerContract.new_fund(fundingName, cairo.uint256(Number(goal) * Number(10) ** Number(18) ) , evidenceLink, contactHandle, fundingDescription)
fundManagerContract.new_fund(fundingName, cairo.uint256(Number(goal) * Number(10) ** Number(18) ) , evidenceLink, contactHandle, fundingDescription, Number(type) )
.then(async (resp: InvokeFunctionResponse) => {
setLatesTx({ txHash: resp.transaction_hash, type: "newfund" });
setActualFund({id: 0, name: fundingName});
Expand All @@ -88,6 +94,8 @@ const Stages = () => {
setEvidenceLink={setEvidenceLink}
contactHandle={contactHandle}
setContactHandle={setContactHandle}
type={type}
setType={setType}
errors={errors} // Pass errors down
setErrors={setErrors} // Pass setErrors down,
/>
Expand Down
4 changes: 2 additions & 2 deletions frontend/gostarkme-web/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ export const ARGENT_WEBWALLET_URL =
process.env.NEXT_PUBLIC_ARGENT_WEBWALLET_URL || "https://web.argent.xyz"

export const FUND_MANAGER_ADDR =
"0x051da2e0a541f35cf09d7978278495cb6940b53d7c9fbdb0ad4d5d678991be9e"
"0x04e75cce044fcb8012eacd7532dee521925a468301d58d09b866ccc43580e84a"

export const navItems = [
// { label: 'My Profile', href: '/app/myprofile' },
// { label: 'My funds', href: '/app/myfunds' }
{ label: 'My funds', href: '/app/myfunds' }
];

export const upVotesNeeded = 50;
Loading

0 comments on commit bd8f18d

Please sign in to comment.