{"size": 1145, "ext": "js", "max_stars_repo_path": "src/components/Transactions/Stats.js", "max_stars_repo_name": "harmony-one/ens-app", "max_stars_repo_stars_event_min_datetime": "2021-03-14T20:35:24.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-28T17:43:00.000Z", "max_issues_repo_path": "src/components/Transactions/Stats.js", "max_issues_repo_name": "harmony-one/ens-app", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/components/Transactions/Stats.js", "max_forks_repo_name": "harmony-one/ens-app", "max_forks_repo_forks_event_min_datetime": "2021-03-27T04:23:31.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-27T04:23:31.000Z"}
{"max_stars_count": 5, "max_issues_count": null, "max_forks_count": 1, "avg_line_length": 22.4509803922, "max_line_length": 80, "alphanum_fraction": 0.6323144105}
import React from 'react'
import styled from '@emotion/styled/macro'

const StatsContainer = styled('div')`
  margin-bottom: 2em;
`

class Stats extends React.Component {
  constructor(props) {
    super(props)
    this.state = {
      error: null,
      isLoaded: false,
      totalRegistered: null,
      totalFundsRaised: null,
      items: []
    }
  }

  componentDidMount() {
    this.getData()
  }

  async getData() {
    // const response = await fetch('https://hmny-t.co/one-registrations');
    const stats = await fetch('https://hmny-t.co/one-stats')
    const data = await stats.json()
    this.setState({
      totalRegistered: data.totalRegistered,
      totalFundsRaised: data.totalFundsRaised
    })
  }

  render() {
    const { totalRegistered, totalFundsRaised } = this.state

    if (totalRegistered) {
      return (
        <StatsContainer>
          <strong>{totalRegistered}</strong> registered.{' '}
          <strong>{totalFundsRaised}</strong> ONEs contributed to community DAO.
        </StatsContainer>
      )
    } else {
      return <StatsContainer>Loading...</StatsContainer>
    }
  }
}

export default Stats
