diff --git a/contracts/Migrations.sol b/contracts/Migrations.sol index 4b532ee..184150a 100644 --- a/contracts/Migrations.sol +++ b/contracts/Migrations.sol @@ -8,16 +8,16 @@ contract Migrations { if (msg.sender == owner) _; } -constructor() public { -owner = msg.sender; -} + constructor() public { + owner = msg.sender; + } -function setCompleted(uint completed) public restricted { -last_completed_migration = completed; -} + function setCompleted(uint completed) public restricted { + last_completed_migration = completed; + } -function upgrade(address new_address) public restricted { -Migrations upgraded = Migrations(new_address); -upgraded.setCompleted(last_completed_migration); -} -} + function upgrade(address new_address) public restricted { + Migrations upgraded = Migrations(new_address); + upgraded.setCompleted(last_completed_migration); + } +} \ No newline at end of file diff --git a/package.json b/package.json index 04af20b..159cbbf 100644 --- a/package.json +++ b/package.json @@ -11,11 +11,12 @@ "drizzle-react": "^1.1.1", "drizzle-react-components": "^1.1.0", "eth-block-tracker-es5": "^2.3.2", + "prop-types": "^15.6.1", "react": "^16.3.2", "react-dom": "^16.3.2", - "react-scripts": "1.1.1", + "react-scripts": "^1.1.4", "react-redux": "^5.0.7", - "react-router": "3.2.1", + "react-router": "^3.2.1", "react-router-redux": "^4.0.8", "redux": "^3.7.2", "redux-auth-wrapper": "1.1.0", diff --git a/src/containers/Menu.js b/src/containers/Menu.js new file mode 100644 index 0000000..e4be872 --- /dev/null +++ b/src/containers/Menu.js @@ -0,0 +1,69 @@ +import { drizzleConnect } from 'drizzle-react' +import React, { Component } from 'react' +import PropTypes from 'prop-types' + +const contract = "Forum"; +const method = "hasUserSignedUp"; + +class Menu extends Component { + constructor(props, context) { + super(props); + + this.contracts = context.drizzle.contracts; + + // Get the contract ABI + const abi = this.contracts[contract].abi; + + // Fetch initial value from chain and return cache key for reactive updates. + let methodArgs = this.props.methodArgs ? this.props.methodArgs : []; + this.dataKey = this.contracts[contract].methods[method].cacheCall(...methodArgs); + + // Iterate over abi for correct function. + for (let i = 0; i < abi.length; i++) { + if (abi[i].name === this.props.method) { + this.fnABI = abi[i]; + break + } + } + } + + render() { + // Contract is not yet intialized. + if(!this.props.contracts[contract].initialized) { + return ( + + ) + } + + // If the cache key we received earlier isn't in the store yet; the initial value is still being fetched. + if(!(this.dataKey in this.props.contracts[contract][method])) { + return ( + + ) + } + + let displayData = this.props.contracts[contract][method][this.dataKey].value; + + if (displayData) { + return( + User has signed up! + ) + } + + return( + User doesn't exist! + ) + } +} + +Menu.contextTypes = { + drizzle: PropTypes.object +}; + +const mapStateToProps = state => { + return { + contracts: state.contracts + } +}; + +export default drizzleConnect(Menu, mapStateToProps) \ No newline at end of file diff --git a/src/layouts/home/Home.js b/src/layouts/home/Home.js index 4ee67a7..eade9af 100644 --- a/src/layouts/home/Home.js +++ b/src/layouts/home/Home.js @@ -1,5 +1,6 @@ import React, { Component } from 'react' import { AccountData, ContractData, ContractForm } from 'drizzle-react-components' +import Menu from './../../containers/Menu' class Home extends Component { render() { @@ -15,6 +16,7 @@ class Home extends Component {

Username:

+