mirror of https://gitlab.com/ecentrics/concordia
Ezerous
7 years ago
6 changed files with 60 additions and 149 deletions
@ -1,48 +0,0 @@ |
|||||
import { drizzleConnect } from 'drizzle-react' |
|
||||
import React, { Component } from 'react' |
|
||||
import PropTypes from 'prop-types' |
|
||||
|
|
||||
const contract = "Forum"; |
|
||||
const method = "hasUserSignedUp"; |
|
||||
|
|
||||
class AuthWrapperContainer extends Component { |
|
||||
constructor(props, context) { |
|
||||
super(props); |
|
||||
|
|
||||
this.contracts = context.drizzle.contracts; |
|
||||
|
|
||||
this.dataKey = this.contracts[contract].methods[method].cacheCall(...[this.props.accounts[0]]); |
|
||||
} |
|
||||
|
|
||||
render() { |
|
||||
// Contract is not yet intialized.
|
|
||||
if(!this.props.contracts[contract].initialized) |
|
||||
return (null); |
|
||||
|
|
||||
// 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 (null); |
|
||||
|
|
||||
let userHasSignedUp = this.props.contracts[contract][method][this.dataKey].value; |
|
||||
const authRender = this.props.authRender; |
|
||||
const guestRender = this.props.guestRender; |
|
||||
|
|
||||
if (userHasSignedUp) |
|
||||
return(<div>{authRender}</div>); |
|
||||
|
|
||||
return(<div>{guestRender}</div>); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
AuthWrapperContainer.contextTypes = { |
|
||||
drizzle: PropTypes.object |
|
||||
}; |
|
||||
|
|
||||
const mapStateToProps = state => { |
|
||||
return { |
|
||||
accounts: state.accounts, |
|
||||
contracts: state.contracts, |
|
||||
} |
|
||||
}; |
|
||||
|
|
||||
export default drizzleConnect(AuthWrapperContainer, mapStateToProps) |
|
@ -1,26 +0,0 @@ |
|||||
import React, { Component } from 'react' |
|
||||
import { ContractData } from 'drizzle-react-components' |
|
||||
import UsernameFormContainer from '../../containers/UsernameFormContainer' |
|
||||
|
|
||||
class Home extends Component { |
|
||||
render() { |
|
||||
return ( |
|
||||
<main className="container"> |
|
||||
<div className="pure-g"> |
|
||||
<div className="pure-u-1-1 header"> |
|
||||
<h1>Apella</h1> |
|
||||
<br/><br/> |
|
||||
</div> |
|
||||
<div className="pure-u-1-1"> |
|
||||
<h2>Account</h2> |
|
||||
<p><strong>Username</strong>: <ContractData contract="Forum" method="getUsername" methodArgs={[this.props.accounts[0]]}/></p> |
|
||||
<UsernameFormContainer/> |
|
||||
<br/><br/> |
|
||||
</div> |
|
||||
</div> |
|
||||
</main> |
|
||||
) |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
export default Home |
|
Loading…
Reference in new issue