npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@1hive/connect-gardens

v0.1.15

Published

Access gardens data.

Downloads

278

Readme

Garden Connector

Connector for the Garden frontend implemented using Aragon Connect. It connects to a garden subgraph created using The Graph indexing protocol.

The garden subgraph collects, stores and indexes garden-related data from the blockchain and serves it through a GraphQL endpoint. The connector is an abstraction over this subgraph which offers an API that can be use by any client to fetch data.

Documentation

Check out the documentation for an in-depth explanation of the API.

Usage of Garden Connector

Set up

  1. Add the following dependencies to your project:

    yarn add @1hive/connect
    yarn add @1hive/connect-gardens
  2. Import them:

    import connect from '@1hive/connect'
    import { connectGarden } from '@1hive/connect-gardens'
  3. Set up the connector:

    const org = await connect(DAO_ADDRESS_OR_ENS, 'thegraph', { network: CHAIN_ID })
    
    const gardenConnector = await connectGarden(org)

Set up in a React App

  1. Add the following dependencies to your project:

    yarn add @1hive/connect-react
    yarn add @1hive/connect-gardens
  2. Wrap your main <App/> component in the <Connect/> component provided by the @1hive/connect-react library.

    import { Connect } from '@1hive/connect-react'
    ;<Connect
      location={DAO_ADDRESS_OR_ENS}
      connector="thegraph"
      options={{
        network: CHAIN_ID,
      }}
    >
      <App />
    </Connect>
  3. Set up the connector:

    import { useOrganization } from '@1hive/connect-react'
    
    function App() {
      const [gardenConnector, setGardenConnector] = useState(null)
      const [organization] = useOrganization()
    
      useEffect(() => {
        if (!organization) {
          return
        }
    
        let cancelled = false
    
        const fetchGardenConnector = async () => {
          try {
            const gardenConnector = await connectGarden(organization)
    
            if (!cancelled) {
              setGardenConnector(gardenConnector)
            }
          } catch (err) {
            console.error(`Error fetching hatch connector: ${err}`)
          }
        }
    
        fetchGardenConnector()
    
        return () => {
          cancelled = true
        }
      }, [organization])
    }

Data fetch example

Below there is an example of how to fetch 100 proposals, sorted in ascending order by their creation time and skipping the first 50. Filtering by all proposal types and all proposal statuses with an empty metadata (proposal name) filter.

const ALL_PROPOSAL_TYPES = [0, 1, 2, 3] // [Suggestion, Proposal, Decision, Stream]
const ALL_PROPOSAL_STATUSES = [0, 1, 2] // [Active, Cancelled, Executed]

const proposals = await gardenConnector.proposals({
  first: 100,
  skip: 50,
  orderBy: 'createdAt',
  orderDirection: 'asc',
  types: ALL_PROPOSAL_TYPES,
  statuses: ALL_PROPOSAL_STATUSES,
  metadata: '',
})

Data updates subscription example

This is an example of how to set a proposals data subscription of the first 20 proposals, sorted in descending order by their creation time and skipping the first 5. Filtering by proposals of type Suggestion and Proposal with Active status and that has metadata "funding" in their names.

const handler = gardenConnector.onProposals(
  {
    first: 20,
    skip: 5,
    orderBy: 'totalAmount',
    orderDirection: 'desc',
    types: [0, 1],
    statuses: [0],
    metadata: 'funding',
  },
  (proposals) => {
    console.log('Updated proposals: ', proposals)
  }
)

// ...

handler.unsubscribe()

Usage of useGardens and useUser

Data fetch example of useGardens

This is an example of how to create a React hook to fetch a list of Gardens order by they HNY liquidity.

import { getGardens } from '@1hive/connect-gardens'

function useGardensList() {
  const [gardens, setGardens] = useState([])
  const [loading, setLoading] = useState(true)

  useEffect(() => {
    setLoading(true)
    const fetchGardens = async () => {
      try {
        setLoading(true)

        const result = await getGardens({ network: CHAIN_ID }, { orderBy: 'honeyLiquidity' })

        setGardens(result)
      } catch (err) {
        setGardens([])
        console.error(`Error fetching gardens ${err}`)
      }
      setLoading(false)
    }

    fetchGardens()
  }, [sorting.queryArgs])

  return [gardens, loading]
}

Data fetch example of useUser

This is an example of how to create a React hook to fetch a user data given their address.

import { getUser } from '@1hive/connect-gardens'

function useUser(address) {
  const [user, setUser] = useState(null)
  const mounted = useMounted()

  useEffect(() => {
    if (!address) {
      return
    }

    const fetchUser = async () => {
      try {
        const user = await getUser({ network: CHAIN_ID }, { id: address.toLowerCase() })
        if (mounted()) {
          setUser(transformUserData(user))
        }
      } catch (err) {
        console.error(`Failed to fetch user: ${err}`)
      }
    }

    fetchUser()
  }, [address, mounted])

  return user
}

For more information check out the Aragon Connect docs.

Contributing

We welcome community contributions!

Please check out our open Issues to get started.