Skip to content

Commit

Permalink
[App.js] Get informations from new added functions
Browse files Browse the repository at this point in the history
Humbly read

Signed-off-by: sigmoid <[email protected]>
  • Loading branch information
NAKsir-melody committed Mar 8, 2019
1 parent a9c8e87 commit fc4df4c
Showing 1 changed file with 35 additions and 5 deletions.
40 changes: 35 additions & 5 deletions client/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class App extends Component {
// Use web3 to get the user's accounts.
const accounts = await web3.eth.getAccounts();

web3.defaultAccount = accounts[0];

// Get the contract instance.
const networkId = await web3.eth.net.getId();
const deployedNetwork = StudyContract.networks[networkId];
Expand All @@ -38,12 +40,10 @@ class App extends Component {

runExample = async () => {
const { accounts, contract } = this.state;

// Stores a given value, "Admin" by default.
contract.methods.setAdmin("Admin").send({ from: accounts[0] });
contract.methods.setMember("0x01").send({ from: accounts[0] });
contract.methods.setSyllabus("0x01").send({ from: accounts[0] });

//contract.methods.setAdmin("Admin").send({ from: accounts[0] }); // Deprecated
contract.methods.setMember(this.state.web3.utils.asciiToHex("0x01",8)).send({ from: accounts[0] });
contract.methods.setSyllabus(this.state.web3.utils.asciiToHex("0x01",4)).send({ from: accounts[0] });
// Get the value from the contract to prove it worked.
const adminResponse = await contract.methods.getAdmin().call();
const memberResponse = await contract.methods.getMembers().call();
Expand All @@ -53,6 +53,31 @@ class App extends Component {
this.setState({ adminName: adminResponse });
this.setState({ members: memberResponse });
this.setState({ syllabus: syllabusResponse });

// register new student informaion
contract.methods.setStudent(this.state.web3.utils.asciiToHex("name",32), this.state.web3.utils.asciiToHex("[email protected]",32)).send({ from: accounts[0] });
const stu_resp = await contract.methods.getStudent(accounts[0]).call();
this.setState({ stu_n: stu_resp[0], stu_e: stu_resp[1] });

// get lecture list
const lec_resp = await contract.methods.getLectures().call();
this.setState({ lec: lec_resp });

// set attendee to lectures
// lecture0
contract.methods.setAttendance(0).send({ from: accounts[0] });
contract.methods.setAttendance(0).send({ from: accounts[1] });
contract.methods.setAttendance(0).send({ from: accounts[2] });
// lecture1
contract.methods.setAttendance(1).send({ from: accounts[3] });
contract.methods.setAttendance(1).send({ from: accounts[4] });

// get attendee
const lec0_att = await contract.methods.getAttendance(0).call();
const lec1_att = await contract.methods.getAttendance(1).call();
this.setState({ lec0: lec0_att });
this.setState({ lec1: lec1_att });

};

render() {
Expand All @@ -74,6 +99,11 @@ class App extends Component {
<div>The Admin is: {this.state.adminName }</div>
<div>The members are: {this.state.members }</div>
<div>The syllabus are: {this.state.syllabus }</div>
<div>The student name is: {this.state.stu_n }</div>
<div>The student email is: {this.state.stu_e }</div>
<div>The lectures are: {this.state.lec }</div>
<div>The lecture0 attandance are: {this.state.lec0 }</div>
<div>The lecture1 attandance are: {this.state.lec1 }</div>
</div>
);
}
Expand Down

0 comments on commit fc4df4c

Please sign in to comment.