import React from 'react'; import NavBar from 'containers/NavBar'; import ChannelClaimsDisplay from 'components/ChannelClaimsDisplay'; import request from 'utils/request'; class ShowChannel extends React.Component { constructor (props) { super(props); this.state = { error : null, name : null, shortId: null, longId : null, }; this.getAndStoreChannelData = this.getAndStoreChannelData.bind(this); } componentDidMount () { this.getAndStoreChannelData(this.props.requestName, this.props.requestId); } componentWillReceiveProps (nextProps) { if (nextProps.requestName !== this.props.requestName || nextProps.requestId !== this.props.requestId) { this.getAndStoreChannelData(nextProps.requestName, nextProps.requestId); } } getAndStoreChannelData (name, id) { if (!id) id = 'none'; const url = `/api/channel-data/${name}/${id}`; const that = this; return request(url) .then(({ success, message, data }) => { console.log('api/channel-data response:', data); if (!success) { return that.setState({error: message}); } this.setState({ error : null, name : data.channelName, longId : data.longChannelClaimId, shortId: data.shortChannelClaimId, }); }) .catch((error) => { that.setState({error: error.message}); }); } render () { return (
{this.state.error ? (

{this.state.error}

) : (

channel name: {this.state.name ? this.state.name : 'loading...'}

full channel id: {this.state.longId ? this.state.longId : 'loading...'}

short channel id: {this.state.shortId ? this.state.shortId : 'loading...'}

{(this.state.name && this.state.longId) && }
)}
); } }; export default ShowChannel;