1- // import { ZrxTreasuryContract } from '@0x/contracts-treasury';
1+ import { ZrxTreasuryContract } from '@0x/contracts-treasury' ;
22import { BigNumber } from '@0x/utils' ;
33import { gql , request } from 'graphql-request' ;
44import * as _ from 'lodash' ;
55import CircularProgress from 'material-ui/CircularProgress' ;
66import moment from 'moment' ;
77import * as React from 'react' ;
88import { useQuery } from 'react-query' ;
9- // import { useSelector } from 'react-redux';
9+ import { useSelector } from 'react-redux' ;
1010import styled from 'styled-components' ;
1111
1212import { Button } from 'ts/components/button' ;
@@ -18,10 +18,10 @@ import { Heading, Paragraph } from 'ts/components/text';
1818import { Text } from 'ts/components/ui/text' ;
1919import { Proposal , proposals as prodProposals , stagingProposals , TreasuryProposal } from 'ts/pages/governance/data' ;
2020import { VoteIndexCard } from 'ts/pages/governance/vote_index_card' ;
21- // import { State } from 'ts/redux/reducer';
21+ import { State } from 'ts/redux/reducer' ;
2222import { colors } from 'ts/style/colors' ;
2323import { OnChainProposal , TallyInterface , VotingCardType } from 'ts/types' ;
24- import { configs , GOVERNANCE_THEGRAPH_ENDPOINT } from 'ts/utils/configs' ;
24+ import { configs , GOVERNANCE_THEGRAPH_ENDPOINT , GOVERNOR_CONTRACT_ADDRESS } from 'ts/utils/configs' ;
2525import { constants } from 'ts/utils/constants' ;
2626import { documentConstants } from 'ts/utils/document_meta_constants' ;
2727import { environments } from 'ts/utils/environments' ;
@@ -147,29 +147,34 @@ export const VoteIndex: React.FC<VoteIndexProps> = () => {
147147 const [ filter , setFilter ] = React . useState < string > ( 'all' ) ;
148148 const [ tallys , setTallys ] = React . useState < ZeipTallyMap > ( undefined ) ;
149149 const [ proposals , setProposals ] = React . useState < ProposalWithOrder [ ] > ( [ ] ) ;
150- const [ isLoading , setLoading ] = React . useState < boolean > ( true ) ;
151150 const [ quorumThreshold , setQuorumThreshold ] = React . useState < BigNumber > ( ) ;
152151 const [ isExpanded , setIsExpanded ] = React . useState < boolean > ( false ) ;
153- // const providerState = useSelector((state: State) => state.providerState);
152+ const providerState = useSelector ( ( state : State ) => state . providerState ) ;
154153
155- const { data, isLoading : isQueryLoading } = useQuery ( 'proposals' , async ( ) => {
154+ const { data, isLoading } = useQuery ( 'proposals' , async ( ) => {
156155 const { proposals : treasuryProposals } = await request ( GOVERNANCE_THEGRAPH_ENDPOINT , FETCH_PROPOSALS ) ;
157156 return treasuryProposals ;
158157 } ) ;
159158
160- // const contract = new ZrxTreasuryContract(GOVERNOR_CONTRACT_ADDRESS.ZRX, providerState.provider);
161-
162159 React . useEffect ( ( ) => {
163160 // tslint:disable-next-line: no-floating-promises
164161 ( async ( ) => {
165- // const qThreshold = await contract.quorumThreshold().callAsync();
166- const hardCodeQuorumThreshold = new BigNumber ( '10000000' ) ;
167- setQuorumThreshold ( hardCodeQuorumThreshold ) ;
168162 const tallyMap : ZeipTallyMap = await fetchTallysAsync ( ) ;
169163 setTallys ( tallyMap ) ;
170164 } ) ( ) ;
165+ } , [ ] ) ;
171166
172- if ( data ) {
167+ React . useEffect ( ( ) => {
168+ const contract = new ZrxTreasuryContract ( GOVERNOR_CONTRACT_ADDRESS . ZRX , providerState . provider ) ;
169+ // tslint:disable-next-line: no-floating-promises
170+ ( async ( ) => {
171+ const qThreshold = await contract . quorumThreshold ( ) . callAsync ( ) ;
172+ setQuorumThreshold ( qThreshold ) ;
173+ } ) ( ) ;
174+ } , [ providerState ] ) ;
175+
176+ React . useEffect ( ( ) => {
177+ if ( data && quorumThreshold ) {
173178 const onChainProposals = data . map ( ( proposal : OnChainProposal ) => {
174179 const { id, votesAgainst, votesFor, description, executionTimestamp, voteEpoch } = proposal ;
175180 const againstVotes = new BigNumber ( votesAgainst ) ;
@@ -203,11 +208,10 @@ export const VoteIndex: React.FC<VoteIndexProps> = () => {
203208 endDate,
204209 } ;
205210 } ) ;
206- setLoading ( isQueryLoading ) ;
207211 sortProposals ( onChainProposals . reverse ( ) , ZEIP_PROPOSALS ) ;
208212 setProposals ( onChainProposals ) ;
209213 }
210- } , [ data , isQueryLoading , quorumThreshold ] ) ;
214+ } , [ data , quorumThreshold ] ) ;
211215
212216 const applyFilter = ( value : string ) => {
213217 setFilter ( value ) ;
0 commit comments