-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Verify Farmer page, stakeholders address array
- Loading branch information
1 parent
8e72e97
commit d7f9cde
Showing
13 changed files
with
193 additions
and
10 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
.verify{ | ||
padding: 10px; | ||
} | ||
.heading { | ||
font-size: 2rem; | ||
font-weight: bold; | ||
color: #023B59; | ||
text-align: center; | ||
text-transform: uppercase; | ||
text-decoration: overline underline; | ||
} | ||
|
||
.card-key { | ||
font-size: 1rem; | ||
font-weight: bold; | ||
color: #023B59; | ||
} | ||
|
||
.card-value { | ||
font-size: 1rem; | ||
font-weight: 500; | ||
color: #482673; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { useContext, useEffect, useState } from "react"; | ||
import { ContractContext } from "../../../Services/Contexts/ContractContext"; | ||
import '../../../Assests/Styles/verify.page.css'; | ||
import RenderFarmer from "./renderFarmer"; | ||
|
||
const VerifyFarmer = () => { | ||
const {contractState} = useContext(ContractContext); | ||
const [addresses, setAddresses] = useState([]); | ||
useEffect(() => { | ||
(async() => { | ||
if(contractState.farmerContract){ | ||
setAddresses(await contractState.farmerContract.methods.getAddresses().call()); | ||
} | ||
})(); | ||
}, [contractState.farmerContract]) | ||
return ( | ||
<div className="verify"> | ||
<div className="heading">Verify Farmer</div> | ||
<div className="row"> | ||
{addresses.map(address => ( | ||
<RenderFarmer id={address} /> | ||
))} | ||
</div> | ||
</div> | ||
) | ||
} | ||
export default VerifyFarmer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import { useContext, useEffect, useState } from "react"; | ||
|
||
import { AuthContext } from "../../../Services/Contexts/AuthContext"; | ||
import { ContractContext } from "../../../Services/Contexts/ContractContext"; | ||
import '../../../Assests/Styles/verify.page.css'; | ||
import Toast from "../../../Components/Toast"; | ||
import farmer_default from "../../../Assests/Images/admin/rawProducts_o0t5az.jpg"; | ||
|
||
const RenderFarmer = ({id}) => { | ||
const {authState} = useContext(AuthContext); | ||
const {contractState} = useContext(ContractContext); | ||
const [farmer, setFarmer] = useState({ | ||
id: "00000", | ||
name: "", | ||
location: "", | ||
rawProducts: [], | ||
}); | ||
useEffect(() => { | ||
if(contractState.farmerContract){ | ||
(async() => { | ||
const response = await contractState.farmerContract.methods.getFarmer(id).call({from: id}); | ||
setFarmer(farmer => { | ||
return { | ||
...response.farmer, | ||
formattedAddress: id.substring(0, 6) + "..." + id.substring(id.length - 4, id.length), | ||
rawProducts: response.rawProducts | ||
} | ||
}); | ||
})(); | ||
} | ||
}, []) | ||
|
||
const verify = async () => { | ||
try{ | ||
await contractState.farmerContract.methods.verify(id).send({from: authState.address}); | ||
setFarmer(farmer => { | ||
return { | ||
...farmer, | ||
isVerified: true | ||
} | ||
}) | ||
Toast("success", "Farmer verified successfully"); | ||
} catch(e){ | ||
Toast("error", e.message); | ||
} | ||
} | ||
|
||
return ( | ||
<div className="col-12 col-lg-6 my-1"> | ||
<div className="row d-flex justify-content-around align-items-center"> | ||
<div className="col-4"> | ||
<img | ||
src={farmer_default} | ||
width="100%" | ||
/> | ||
</div> | ||
<div className="col-8"> | ||
<span className="card-key">Id: </span> | ||
<span className="card-value">{farmer.formattedAddress}</span> | ||
<br/> | ||
<span className="card-key">Name: </span> | ||
<span className="card-value">{farmer.name}</span> | ||
<br/> | ||
<span className="card-key">Location: </span> | ||
<span className="card-value">{farmer.location}</span> | ||
<br/> | ||
<span className="card-key">Raw Products: </span> | ||
{farmer.rawProducts.map(rawProduct => ( | ||
<span className="card-value">{rawProduct+", "}</span> | ||
))} | ||
<br/> | ||
<span className="row text-center"> | ||
{farmer.isVerified? | ||
<span className=""> | ||
<span className="badge bg-success">Verified</span> | ||
</span> | ||
: | ||
<span className=""> | ||
<span | ||
className="badge bg-info" | ||
type="button" | ||
onClick={verify} | ||
> | ||
Verify | ||
</span> | ||
</span> | ||
} | ||
</span> | ||
</div> | ||
</div> | ||
</div> | ||
) | ||
} | ||
export default RenderFarmer; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters