import React, { Component } from 'react'; import { connect } from 'react-redux'; import { drizzle } from '../index'; import UserAvatar from 'react-user-avatar'; import epochTimeConverter from '../helpers/EpochTimeConverter'; import UsernameFormContainer from '../containers/UsernameFormContainer'; const callsInfo = [{ contract: 'Forum', method: 'getUserDateOfRegister' },{ contract: 'Forum', method: 'getOrbitDBId' }] class ProfileInformation extends Component { constructor(props) { super(props); this.getBlockchainData = this.getBlockchainData.bind(this); this.dataKey = []; this.state = { pageStatus: 'initialized', dateOfRegister: '', orbitDBId: '' }; } getBlockchainData(){ if (this.state.pageStatus === 'initialized' && this.props.drizzleStatus['initialized']) { callsInfo.forEach((call, index) => { this.dataKey[index] = drizzle.contracts[call.contract] .methods[call.method].cacheCall(this.props.address); }) this.setState({ pageStatus: 'loading' }); } if (this.state.pageStatus === 'loading') { var pageStatus = 'loaded'; callsInfo.forEach((call, index) => { if (!this.props.contracts[call.contract][call.method][this.dataKey[index]]) { pageStatus = 'loading'; return; } }) if (pageStatus === 'loaded') { this.setState({ pageStatus: pageStatus }); } } if (this.state.pageStatus === 'loaded'){ if (this.state.dateOfRegister === ''){ let transaction = this.props.contracts[callsInfo[0].contract][callsInfo[0].method][this.dataKey[0]]; if (transaction){ this.setState({ dateOfRegister: transaction.value }); } } if (this.state.orbitDBId === ''){ let transaction = this.props.contracts[callsInfo[1].contract][callsInfo[1].method][this.dataKey[1]]; if (transaction){ this.setState({ orbitDBId: transaction.value }); } } } } render() { return (
{this.props.avatarUrl && } {this.state.dateOfRegister && }
Username: {this.props.username}
Account address: {this.props.address}
OrbitDB: {this.state.orbitDBId}
Number of topics created: {this.props.numberOfTopics}
Number of posts: {this.props.numberOfPosts}
Member since: {epochTimeConverter(this.state.dateOfRegister)}
{this.props.self && }
); } componentDidMount() { this.getBlockchainData(); } componentDidUpdate(){ this.getBlockchainData(); } }; const mapStateToProps = state => { return { drizzleStatus: state.drizzleStatus, contracts: state.contracts, user: state.user } }; export default connect(mapStateToProps)(ProfileInformation);