import React, { useState } from 'react' import { Connect, createAppHook, useApp, useOrganization, } from '@aragon/connect-react' import connectVoting, { Voting, Vote } from '@aragon/connect-voting' // const NETWORK = 1 // const ORG_ADDRESS = 'governance.aragonproject.eth' // const VOTING_APP_FILTER = 'voting' const NETWORK = 4 const ORG_ADDRESS = '0x7cee20f778a53403d4fc8596e88deb694bc91c98' const VOTING_APP_FILTER = '0xf7f9a33ed13b01324884bd87137609251b5f7c88' const VOTES_PER_PAGE = 5 const useVoting = createAppHook(connectVoting) export default function App() { const [showActions, setShowActions] = useState(false) const [mountOrg, setMountOrg] = useState(true) const [mountApp, setMountApp] = useState(true) const [mountVotes, setMountVotes] = useState(true) return (
{showActions && (
)} {mountOrg && } {mountApp && } {mountVotes && }
) } function Organization() { const [org] = useOrganization() return (

Organization

{org?.address || 'Loading…'}

) } const VotingApp = React.memo(function VotingApp() { const [voting, { error, loading }] = useApp(VOTING_APP_FILTER) return (

Voting App

{(() => { if (loading) { return 'Loading…' } if (error) { return error.message } if (!voting) { return 'App not found.' } return voting?.address })()}

) }) function Votes() { const [page, setPage] = useState(0) const [voting, votingStatus] = useApp(VOTING_APP_FILTER) const [votes = [], votesStatus] = useVoting( voting, (app: Voting) => { return app.onVotes({ first: VOTES_PER_PAGE, skip: VOTES_PER_PAGE * page, }) }, [page] ) return (

Votes

{(() => { if (votingStatus.error) { return

{votingStatus.error.message}

} if (votesStatus.error) { return

{votesStatus.error.message}

} if (votingStatus.loading || votesStatus.loading) { return

Loading…

} if (votes && votes.length > 0) { return (
    {votes?.map((vote: Vote) => (
  • {formatVote(vote)}
  • ))}
) } return

No votes.

})()}
Page {page + 1}
) } function formatVote(vote: any): string { let str = vote.metadata str = str.replace(/\n/g, ' ') str = str.length > 40 ? str.slice(0, 40) + '…' : str return str || '(action)' }