{"size": 1089, "ext": "js", "max_stars_repo_path": "src/hooks/useCoveragePoolsAPY.js", "max_stars_repo_name": "test200ok/website", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/hooks/useCoveragePoolsAPY.js", "max_issues_repo_name": "test200ok/website", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/hooks/useCoveragePoolsAPY.js", "max_forks_repo_name": "test200ok/website", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 23.170212766, "max_line_length": 67, "alphanum_fraction": 0.5665748393}
import { useEffect, useState } from "react"
import { CoveragePoolsFactory } from "../lib/coverage-pool"

const coveragePoolV1 = CoveragePoolsFactory.create()
const useCoveragePoolsAPY = () => {
  const [isFetching, setIsFetching] = useState(true)
  const [coveragePoolAPY, setCoveragePoolAPY] = useState([])
  const [error, setError] = useState(null)

  useEffect(() => {
    let shouldSetState = true

    setIsFetching(true)
    coveragePoolV1
      .apy()
      .then((apy) => {
        if (shouldSetState) {
          setCoveragePoolAPY([
            {
              value: apy,
              pool: "COVERAGE",
            },
          ])
          setIsFetching(false)
        }
      })
      .catch((error) => {
        if (shouldSetState) {
          setIsFetching(false)
          setError(error)
        }
        console.log(
          "Unexpected error while fetching liquidity rewards APY:",
          error
        )
      })

    return () => {
      shouldSetState = false
    }
  }, [])

  return [coveragePoolAPY, isFetching, error]
}

export default useCoveragePoolsAPY
