Browse Source

SingUp recognition container

develop
Ezerous 7 years ago
parent
commit
5833b7605d
  1. 22
      contracts/Migrations.sol
  2. 5
      package.json
  3. 69
      src/containers/Menu.js
  4. 2
      src/layouts/home/Home.js

22
contracts/Migrations.sol

@ -8,16 +8,16 @@ contract Migrations {
if (msg.sender == owner) _; if (msg.sender == owner) _;
} }
constructor() public { constructor() public {
owner = msg.sender; owner = msg.sender;
} }
function setCompleted(uint completed) public restricted { function setCompleted(uint completed) public restricted {
last_completed_migration = completed; last_completed_migration = completed;
} }
function upgrade(address new_address) public restricted { function upgrade(address new_address) public restricted {
Migrations upgraded = Migrations(new_address); Migrations upgraded = Migrations(new_address);
upgraded.setCompleted(last_completed_migration); upgraded.setCompleted(last_completed_migration);
} }
} }

5
package.json

@ -11,11 +11,12 @@
"drizzle-react": "^1.1.1", "drizzle-react": "^1.1.1",
"drizzle-react-components": "^1.1.0", "drizzle-react-components": "^1.1.0",
"eth-block-tracker-es5": "^2.3.2", "eth-block-tracker-es5": "^2.3.2",
"prop-types": "^15.6.1",
"react": "^16.3.2", "react": "^16.3.2",
"react-dom": "^16.3.2", "react-dom": "^16.3.2",
"react-scripts": "1.1.1", "react-scripts": "^1.1.4",
"react-redux": "^5.0.7", "react-redux": "^5.0.7",
"react-router": "3.2.1", "react-router": "^3.2.1",
"react-router-redux": "^4.0.8", "react-router-redux": "^4.0.8",
"redux": "^3.7.2", "redux": "^3.7.2",
"redux-auth-wrapper": "1.1.0", "redux-auth-wrapper": "1.1.0",

69
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 (
<span> </span>
)
}
// 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 (
<span> </span>
)
}
let displayData = this.props.contracts[contract][method][this.dataKey].value;
if (displayData) {
return(
<span>User has signed up!</span>
)
}
return(
<span>User doesn't exist!</span>
)
}
}
Menu.contextTypes = {
drizzle: PropTypes.object
};
const mapStateToProps = state => {
return {
contracts: state.contracts
}
};
export default drizzleConnect(Menu, mapStateToProps)

2
src/layouts/home/Home.js

@ -1,5 +1,6 @@
import React, { Component } from 'react' import React, { Component } from 'react'
import { AccountData, ContractData, ContractForm } from 'drizzle-react-components' import { AccountData, ContractData, ContractForm } from 'drizzle-react-components'
import Menu from './../../containers/Menu'
class Home extends Component { class Home extends Component {
render() { render() {
@ -15,6 +16,7 @@ class Home extends Component {
<AccountData accountIndex="0" units="ether" precision="3" /> <AccountData accountIndex="0" units="ether" precision="3" />
<p><strong>Username</strong>: <ContractData contract="Forum" method="getUsername" methodArgs={[this.props.accounts[0]]}/></p> <p><strong>Username</strong>: <ContractData contract="Forum" method="getUsername" methodArgs={[this.props.accounts[0]]}/></p>
<ContractForm contract="Forum" method="signUp" /> <ContractForm contract="Forum" method="signUp" />
<Menu method="hasUserSignedUp" methodArgs={[this.props.accounts[0]]} />
<br/><br/> <br/><br/>
</div> </div>
</div> </div>

Loading…
Cancel
Save