diff --git a/frontend/gostarkme-web/app/app/page.tsx b/frontend/gostarkme-web/app/app/page.tsx index 85a0307..bee5d72 100644 --- a/frontend/gostarkme-web/app/app/page.tsx +++ b/frontend/gostarkme-web/app/app/page.tsx @@ -1,44 +1,59 @@ -import React from "react"; +'use client'; import FundCards from "@/components/dashboard/fundCard"; import Footer from "@/components/ui/Footer"; import Navbar from "@/components/ui/Navbar"; +import { FUND_MANAGER_ADDR } from "@/constants"; +import { fund } from "@/contracts/abis/fund"; +import { fundManager } from "@/contracts/abis/fundManager"; +import { walletStarknetkitLatestAtom } from "@/state/connectedWallet"; +import { useAtomValue } from "jotai"; +import React, { useEffect, useState } from "react"; +import { byteArray, Contract, InvokeFunctionResponse } from "starknet"; import { navItems } from "@/constants"; const Dashboard = () => { - const funds = [ - { - type: "Project", - title: "Adrian's fund", - description: "I need help with my project", - }, - { - type: "Charity", - title: "Adrian's fund", - description: "I need help with my project", - }, - { - type: "Charity", - title: "Adrian's fund", - description: "I need help with my project", - }, - { - type: "Project", - title: "Adrian's fund", - description: "I need help with my project", - }, + const wallet = useAtomValue(walletStarknetkitLatestAtom); + + const [fundManagerContract, _setFundManagerContract] = useState(new Contract(fundManager, FUND_MANAGER_ADDR, wallet?.account)); + + const [funds, setFunds] = useState([]); + + function hex2ascii(hexx: string) { + var hex = hexx.toString();//force conversion + var str = ''; + for (var i = 0; i < hex.length; i += 2) + str += String.fromCharCode(parseInt(hex.substr(i, 2), 16)); + return str; + } + + async function getFunds() { + const id = await fundManagerContract.getCurrentId(); + let fundings = []; + for (let i = 1; i < id; i++) { + // GET FUND ADDRESS + let fundaddr = await fundManagerContract.getFund(i); + fundaddr = "0x" + fundaddr.toString(16); + const fundContract = new Contract(fund, fundaddr, wallet?.account); + // GET FUND NAME + let name = await fundContract.getName(); + name = hex2ascii(name.toString(16)); + // GET FUND DESCRIPTION + let desc = await fundContract.getReason(); + fundings.push({ + type: "Project", + title: name, + description: desc, + }); + } + console.log(fundings); + setFunds(fundings); + } + + useEffect(() => { + getFunds(); + }, []); - { - type: "Charity", - title: "Adrian's fund", - description: "I need help with my project", - }, - { - type: "Project", - title: "Adrian's fund", - description: "I need help with my project", - }, - ]; return (
{ Latest Funds -
- {funds.map((fund, index) => ( - - ))} -
+ {funds.length !== 0 ? ( +
+ {funds.map((fund: { type: string; title: string; description: string; }, index: number) => ( + + ))} +
+ ) : ( +
+
+ There is no fundings to display. +
+
+ )}
); diff --git a/frontend/gostarkme-web/components/dashboard/fundCard.tsx b/frontend/gostarkme-web/components/dashboard/fundCard.tsx index e1f5ecf..312e867 100644 --- a/frontend/gostarkme-web/components/dashboard/fundCard.tsx +++ b/frontend/gostarkme-web/components/dashboard/fundCard.tsx @@ -19,20 +19,23 @@ const FundCards = ({ fund, index }: FundCardProps) => {

{fund.type} {fund.type === "Project" ? 🚀 : 🫀}

-

+

{fund.title}

-

- {fund.description} -

+ {fund.description !== " " ? ( +

{fund.description}

+ ) : + ( +

No description provided

+ )}
diff --git a/frontend/gostarkme-web/components/ui/Bounded.tsx b/frontend/gostarkme-web/components/ui/Bounded.tsx index 81c9c3e..127e6d1 100644 --- a/frontend/gostarkme-web/components/ui/Bounded.tsx +++ b/frontend/gostarkme-web/components/ui/Bounded.tsx @@ -3,8 +3,8 @@ import Footer from "./Footer"; import Navbar from "./Navbar"; const navItems = [ - { label: 'My Profile', href: '/app/myprofile/1' }, - { label: 'My funds', href: '/app/myfunds/1' } + { label: 'My Profile', href: '/app/myprofile/' }, + { label: 'My funds', href: '/app/myfunds/' } ]; interface BoundedProps { children: ReactNode; diff --git a/frontend/gostarkme-web/constants/index.ts b/frontend/gostarkme-web/constants/index.ts index a6ff0fb..3066123 100644 --- a/frontend/gostarkme-web/constants/index.ts +++ b/frontend/gostarkme-web/constants/index.ts @@ -36,7 +36,10 @@ export const ARGENT_SESSION_SERVICE_BASE_URL = export const ARGENT_WEBWALLET_URL = process.env.NEXT_PUBLIC_ARGENT_WEBWALLET_URL || "https://web.argent.xyz" +export const FUND_MANAGER_ADDR = + "0x0263457e0646dc4312c4a583fcae334d98f9b4ff1cf7a9c091649c2bec02543a" + export const navItems = [ { label: 'My Profile', href: '/app/myprofile' }, { label: 'My funds', href: '/app/myfunds' } - ]; \ No newline at end of file + ]; diff --git a/frontend/gostarkme-web/contracts/abis/fund.ts b/frontend/gostarkme-web/contracts/abis/fund.ts new file mode 100644 index 0000000..39ad6cd --- /dev/null +++ b/frontend/gostarkme-web/contracts/abis/fund.ts @@ -0,0 +1,301 @@ +export const fund = [ + { + "type": "impl", + "name": "FundImpl", + "interface_name": "gostarkme::fund::IFund" + }, + { + "type": "struct", + "name": "core::byte_array::ByteArray", + "members": [ + { + "name": "data", + "type": "core::array::Array::" + }, + { + "name": "pending_word", + "type": "core::felt252" + }, + { + "name": "pending_word_len", + "type": "core::integer::u32" + } + ] + }, + { + "type": "struct", + "name": "core::integer::u256", + "members": [ + { + "name": "low", + "type": "core::integer::u128" + }, + { + "name": "high", + "type": "core::integer::u128" + } + ] + }, + { + "type": "interface", + "name": "gostarkme::fund::IFund", + "items": [ + { + "type": "function", + "name": "getId", + "inputs": [], + "outputs": [ + { + "type": "core::integer::u128" + } + ], + "state_mutability": "view" + }, + { + "type": "function", + "name": "getOwner", + "inputs": [], + "outputs": [ + { + "type": "core::starknet::contract_address::ContractAddress" + } + ], + "state_mutability": "view" + }, + { + "type": "function", + "name": "setName", + "inputs": [ + { + "name": "name", + "type": "core::felt252" + } + ], + "outputs": [], + "state_mutability": "external" + }, + { + "type": "function", + "name": "getName", + "inputs": [], + "outputs": [ + { + "type": "core::felt252" + } + ], + "state_mutability": "view" + }, + { + "type": "function", + "name": "setReason", + "inputs": [ + { + "name": "reason", + "type": "core::byte_array::ByteArray" + } + ], + "outputs": [], + "state_mutability": "external" + }, + { + "type": "function", + "name": "getReason", + "inputs": [], + "outputs": [ + { + "type": "core::byte_array::ByteArray" + } + ], + "state_mutability": "view" + }, + { + "type": "function", + "name": "receiveVote", + "inputs": [], + "outputs": [], + "state_mutability": "external" + }, + { + "type": "function", + "name": "getUpVotes", + "inputs": [], + "outputs": [ + { + "type": "core::integer::u32" + } + ], + "state_mutability": "view" + }, + { + "type": "function", + "name": "setGoal", + "inputs": [ + { + "name": "goal", + "type": "core::integer::u256" + } + ], + "outputs": [], + "state_mutability": "external" + }, + { + "type": "function", + "name": "getGoal", + "inputs": [], + "outputs": [ + { + "type": "core::integer::u256" + } + ], + "state_mutability": "view" + }, + { + "type": "function", + "name": "receiveDonation", + "inputs": [ + { + "name": "strks", + "type": "core::integer::u256" + } + ], + "outputs": [], + "state_mutability": "external" + }, + { + "type": "function", + "name": "getCurrentGoalState", + "inputs": [], + "outputs": [ + { + "type": "core::integer::u256" + } + ], + "state_mutability": "view" + }, + { + "type": "function", + "name": "setState", + "inputs": [ + { + "name": "state", + "type": "core::integer::u8" + } + ], + "outputs": [], + "state_mutability": "external" + }, + { + "type": "function", + "name": "getState", + "inputs": [], + "outputs": [ + { + "type": "core::integer::u8" + } + ], + "state_mutability": "view" + }, + { + "type": "function", + "name": "getVoter", + "inputs": [], + "outputs": [ + { + "type": "core::integer::u32" + } + ], + "state_mutability": "view" + }, + { + "type": "function", + "name": "withdraw", + "inputs": [], + "outputs": [], + "state_mutability": "external" + } + ] + }, + { + "type": "constructor", + "name": "constructor", + "inputs": [ + { + "name": "id", + "type": "core::integer::u128" + }, + { + "name": "owner", + "type": "core::starknet::contract_address::ContractAddress" + }, + { + "name": "name", + "type": "core::felt252" + }, + { + "name": "goal", + "type": "core::integer::u256" + } + ] + }, + { + "type": "event", + "name": "gostarkme::fund::Fund::DonationWithdraw", + "kind": "struct", + "members": [ + { + "name": "owner_address", + "type": "core::starknet::contract_address::ContractAddress", + "kind": "key" + }, + { + "name": "fund_contract_address", + "type": "core::starknet::contract_address::ContractAddress", + "kind": "data" + }, + { + "name": "withdrawn_amount", + "type": "core::integer::u256", + "kind": "data" + } + ] + }, + { + "type": "event", + "name": "gostarkme::fund::Fund::NewVoteReceived", + "kind": "struct", + "members": [ + { + "name": "voter", + "type": "core::starknet::contract_address::ContractAddress", + "kind": "key" + }, + { + "name": "fund", + "type": "core::starknet::contract_address::ContractAddress", + "kind": "data" + }, + { + "name": "votes", + "type": "core::integer::u32", + "kind": "data" + } + ] + }, + { + "type": "event", + "name": "gostarkme::fund::Fund::Event", + "kind": "enum", + "variants": [ + { + "name": "DonationWithdraw", + "type": "gostarkme::fund::Fund::DonationWithdraw", + "kind": "nested" + }, + { + "name": "NewVoteReceived", + "type": "gostarkme::fund::Fund::NewVoteReceived", + "kind": "nested" + } + ] + } + ] \ No newline at end of file diff --git a/frontend/gostarkme-web/contracts/abis/fundManager.ts b/frontend/gostarkme-web/contracts/abis/fundManager.ts new file mode 100644 index 0000000..e5fa5d3 --- /dev/null +++ b/frontend/gostarkme-web/contracts/abis/fundManager.ts @@ -0,0 +1,108 @@ +export const fundManager = [ + { + "type": "impl", + "name": "FundManagerImpl", + "interface_name": "gostarkme::fundManager::IFundManager" + }, + { + "type": "struct", + "name": "core::integer::u256", + "members": [ + { + "name": "low", + "type": "core::integer::u128" + }, + { + "name": "high", + "type": "core::integer::u128" + } + ] + }, + { + "type": "interface", + "name": "gostarkme::fundManager::IFundManager", + "items": [ + { + "type": "function", + "name": "newFund", + "inputs": [ + { + "name": "name", + "type": "core::felt252" + }, + { + "name": "goal", + "type": "core::integer::u256" + } + ], + "outputs": [], + "state_mutability": "external" + }, + { + "type": "function", + "name": "getCurrentId", + "inputs": [], + "outputs": [ + { + "type": "core::integer::u128" + } + ], + "state_mutability": "view" + }, + { + "type": "function", + "name": "getFund", + "inputs": [ + { + "name": "id", + "type": "core::integer::u128" + } + ], + "outputs": [ + { + "type": "core::starknet::contract_address::ContractAddress" + } + ], + "state_mutability": "view" + }, + { + "type": "function", + "name": "getOwner", + "inputs": [], + "outputs": [ + { + "type": "core::starknet::contract_address::ContractAddress" + } + ], + "state_mutability": "view" + }, + { + "type": "function", + "name": "getFundClassHash", + "inputs": [], + "outputs": [ + { + "type": "core::starknet::class_hash::ClassHash" + } + ], + "state_mutability": "view" + } + ] + }, + { + "type": "constructor", + "name": "constructor", + "inputs": [ + { + "name": "fund_class_hash", + "type": "core::felt252" + } + ] + }, + { + "type": "event", + "name": "gostarkme::fundManager::FundManager::Event", + "kind": "enum", + "variants": [] + } + ] \ No newline at end of file diff --git a/frontend/gostarkme-web/contracts/addresses.ts b/frontend/gostarkme-web/contracts/addresses.ts new file mode 100644 index 0000000..e69de29