diff --git a/donorfront/src/App.js b/donorfront/src/App.js
index 46aebad..e8671db 100644
--- a/donorfront/src/App.js
+++ b/donorfront/src/App.js
@@ -1,31 +1,43 @@
import React, { useState, useEffect } from 'react';
+import { BrowserRouter as Router, Route, Switch } from 'react-router-dom';
+import Navigation from './Navigation';
import BeneficiaryList from './BeneficiaryList';
+import BeneficiaryDetails from './BeneficiaryDetails';
import DonationForm from './DonationForm';
import UtilizationList from './UtilizationList';
import AdminPanel from './AdminPanel';
-import { useWeb3 } from '../hooks/useWeb3';
-// import { getContractInstance } from '../utils/contractHelpers';
+import UserDashboard from './UserDashboard';
+import { Web3Provider } from '../contexts/Web3Context';
+import { UserProvider } from '../contexts/UserContext';
const App = () => {
const [userRole, setUserRole] = useState(null);
- const [beneficiaries, setBeneficiaries] = useState([]);
- const [donations, setDonations] = useState([]);
- const [utilizations, setUtilizations] = useState([]);
- const { account, web3 } = useWeb3();
useEffect(() => {
- // TODO: Fetch user role, beneficiaries, donations, and utilizations from the smart contract
+ // TODO: Fetch user role from the smart contract
}, []);
return (
-
-
Charity Smart Contract UI
-
-
-
- {userRole === 'ROLE_ADMIN' &&
}
-
+
+
+
+
+
+
+
+
+
+
+
+ {userRole === 'admin' && }
+
+
+
+
+
+
+
);
};
-export default App;
+export default App;
\ No newline at end of file
diff --git a/donorfront/src/UserDashboard.js b/donorfront/src/UserDashboard.js
new file mode 100644
index 0000000..e69de29
diff --git a/donorfront/src/components/AdminPanel.js b/donorfront/src/components/AdminPanel.js
index e38956d..08b5d93 100644
--- a/donorfront/src/components/AdminPanel.js
+++ b/donorfront/src/components/AdminPanel.js
@@ -1,81 +1,107 @@
-import React, { useState } from 'react';
+import React, { useState, useEffect } from 'react';
+import { useWeb3 } from '../hooks/useWeb3';
+import { getBeneficiaries, registerBeneficiary, approveUtilization } from '../utils/contractHelpers';
const AdminPanel = () => {
- const [beneficiaryName, setBeneficiaryName] = useState('');
- const [beneficiaryDescription, setBeneficiaryDescription] = useState('');
- const [beneficiaryTargetAmount, setBeneficiaryTargetAmount] = useState('');
- const [utilizationBeneficiaryId, setUtilizationBeneficiaryId] = useState('');
- const [utilizationDescription, setUtilizationDescription] = useState('');
- const [utilizationAmount, setUtilizationAmount] = useState('');
+ const [beneficiaries, setBeneficiaries] = useState([]);
+ const [newBeneficiary, setNewBeneficiary] = useState({ name: '', description: '', targetAmount: '' });
+ const [utilizationRequests, setUtilizationRequests] = useState([]);
+ const { contract, address } = useWeb3();
- const handleRegisterBeneficiary = (e) => {
- e.preventDefault();
- // TODO: Call the register-beneficiary function from the smart contract
- console.log('Register beneficiary:', { beneficiaryName, beneficiaryDescription, beneficiaryTargetAmount });
+ useEffect(() => {
+ fetchBeneficiaries();
+ fetchUtilizationRequests();
+ }, [contract]);
+
+ const fetchBeneficiaries = async () => {
+ if (contract) {
+ const beneficiaryList = await getBeneficiaries(contract);
+ setBeneficiaries(beneficiaryList);
+ }
+ };
+
+ const fetchUtilizationRequests = async () => {
+ // TODO: Implement fetching utilization requests from the contract
};
- const handleAddUtilization = (e) => {
+ const handleRegisterBeneficiary = async (e) => {
e.preventDefault();
- // TODO: Call the add-utilization function from the smart contract
- console.log('Add utilization:', { utilizationBeneficiaryId, utilizationDescription, utilizationAmount });
+ try {
+ await registerBeneficiary(contract, address, newBeneficiary.name, newBeneficiary.description, newBeneficiary.targetAmount);
+ setNewBeneficiary({ name: '', description: '', targetAmount: '' });
+ fetchBeneficiaries();
+ } catch (error) {
+ console.error('Error registering beneficiary:', error);
+ }
+ };
+
+ const handleApproveUtilization = async (beneficiaryId, milestoneId) => {
+ try {
+ await approveUtilization(contract, address, beneficiaryId, milestoneId);
+ fetchUtilizationRequests();
+ } catch (error) {
+ console.error('Error approving utilization:', error);
+ }
};
return (
-
-
Admin Panel
-
+
+
Admin Panel
+
+
+
Register New Beneficiary
+
+
-
+
+
Utilization Requests
+ {utilizationRequests.length === 0 ? (
+
No pending utilization requests.
+ ) : (
+
+ {utilizationRequests.map((request) => (
+ -
+ {request.description} - {request.amount} STX
+
+
+ ))}
+
+ )}
+
);
};
-export default AdminPanel;
+export default AdminPanel;
\ No newline at end of file
diff --git a/donorfront/src/components/BeneficiaryDetails.js b/donorfront/src/components/BeneficiaryDetails.js
new file mode 100644
index 0000000..e69de29
diff --git a/donorfront/src/components/BeneficiaryList.js b/donorfront/src/components/BeneficiaryList.js
index fd257d1..8297de8 100644
--- a/donorfront/src/components/BeneficiaryList.js
+++ b/donorfront/src/components/BeneficiaryList.js
@@ -1,23 +1,57 @@
-import React from 'react';
+import React, { useState, useEffect } from 'react';
+import { Link } from 'react-router-dom';
+import { useWeb3 } from '../hooks/useWeb3';
+import { getBeneficiaries } from '../utils/contractHelpers';
+
+const BeneficiaryList = () => {
+ const [beneficiaries, setBeneficiaries] = useState([]);
+ const { contract } = useWeb3();
+
+ useEffect(() => {
+ const fetchBeneficiaries = async () => {
+ if (contract) {
+ const beneficiaryList = await getBeneficiaries(contract);
+ setBeneficiaries(beneficiaryList);
+ }
+ };
+
+ fetchBeneficiaries();
+ }, [contract]);
-const BeneficiaryList = ({ beneficiaries }) => {
return (
-
-
Beneficiaries
-
+
+
Beneficiaries
+
{beneficiaries.map((beneficiary) => (
-
-
-
{beneficiary.name}
- {beneficiary.description}
- Target Amount: {beneficiary.targetAmount}
- Received Amount: {beneficiary.receivedAmount}
- Status: {beneficiary.status}
-
+
+
+
{beneficiary.name}
+
{beneficiary.description}
+
+
+ {beneficiary.receivedAmount} / {beneficiary.targetAmount} STX
+
+
+ View Details
+
+
+
+
+
))}
-
+
);
};
-export default BeneficiaryList;
-
\ No newline at end of file
+export default BeneficiaryList;
\ No newline at end of file
diff --git a/donorfront/src/components/DonationForm.js b/donorfront/src/components/DonationForm.js
index 226e001..5f8f925 100644
--- a/donorfront/src/components/DonationForm.js
+++ b/donorfront/src/components/DonationForm.js
@@ -1,42 +1,60 @@
import React, { useState } from 'react';
+import { useParams } from 'react-router-dom';
+import { useWeb3 } from '../hooks/useWeb3';
+import { donate } from '../utils/contractHelpers';
-const DonationForm = ({ beneficiaries }) => {
- const [selectedBeneficiary, setSelectedBeneficiary] = useState('');
+const DonationForm = () => {
+ const { id } = useParams();
const [amount, setAmount] = useState('');
+ const [isLoading, setIsLoading] = useState(false);
+ const [error, setError] = useState(null);
+ const { contract, address } = useWeb3();
- const handleSubmit = (e) => {
+ const handleSubmit = async (e) => {
e.preventDefault();
- // TODO: Call the donate function from the smart contract
- console.log('Donation submitted:', { beneficiaryId: selectedBeneficiary, amount });
+ setIsLoading(true);
+ setError(null);
+
+ try {
+ await donate(contract, address, id, amount);
+ // TODO: Show success message and update UI
+ } catch (err) {
+ setError(err.message);
+ } finally {
+ setIsLoading(false);
+ }
};
return (
-
-
Make a Donation
-