Skip to content
This repository was archived by the owner on Oct 11, 2024. It is now read-only.

Commit 30f4afe

Browse files
committed
Fix infinite loop
1 parent ee163f2 commit 30f4afe

File tree

3 files changed

+34
-25
lines changed

3 files changed

+34
-25
lines changed

ts/pages/governance/modal_vote.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export const ModalVote: React.FC<ModalVoteProps> = ({ zeipId, isOpen, onDismiss,
8989
logUtils.warn(err);
9090
errorReporter.report(err);
9191
});
92-
}, [account.address, apiClient, networkId, providerState.web3Wrapper, isFetchingVotingPowerData]);
92+
}, [account.address, apiClient, networkId, providerState.web3Wrapper]);
9393

9494
const onToggleConnectWalletDialog = React.useCallback(
9595
(open: boolean) => {
@@ -229,15 +229,15 @@ export const ModalTreasuryVote: React.FC<ModalVoteProps> = ({
229229
if (!account.address || isFetchingVotingPowerData) {
230230
return;
231231
}
232-
232+
setIsFetchingVotingPowerData(true);
233233
fetchVotingPower()
234234
.then(() => setIsFetchingVotingPowerData(false))
235235
.catch((err) => {
236236
setIsFetchingVotingPowerData(false);
237237
logUtils.warn(err);
238238
errorReporter.report(err);
239239
});
240-
}, [account.address, apiClient, contract, isFetchingVotingPowerData]);
240+
}, [account.address, apiClient, contract]);
241241

242242
const onToggleConnectWalletDialog = React.useCallback(
243243
(open: boolean) => {

ts/pages/governance/treasury.tsx

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { ZrxTreasuryContract } from '@0x/contracts-treasury';
12
import { BigNumber } from '@0x/utils';
23
import { gql, request } from 'graphql-request';
34
import * as _ from 'lodash';
@@ -7,6 +8,7 @@ import moment from 'moment';
78
import * as React from 'react';
89
import ReactMarkdown from 'react-markdown';
910
import { useQuery } from 'react-query';
11+
import { useSelector } from 'react-redux';
1012
import { Redirect, useParams } from 'react-router-dom';
1113
import styled from 'styled-components';
1214

@@ -23,9 +25,10 @@ import { TreasuryProposal } from 'ts/pages/governance/data';
2325
import { ModalTreasuryVote } from 'ts/pages/governance/modal_vote';
2426
import { VoteInfo, VoteValue } from 'ts/pages/governance/vote_form';
2527
import { VoteStats } from 'ts/pages/governance/vote_stats';
28+
import { State } from 'ts/redux/reducer';
2629
import { colors } from 'ts/style/colors';
2730
import { WebsitePaths } from 'ts/types';
28-
import { configs, GOVERNANCE_THEGRAPH_ENDPOINT } from 'ts/utils/configs';
31+
import { configs, GOVERNANCE_THEGRAPH_ENDPOINT, GOVERNOR_CONTRACT_ADDRESS } from 'ts/utils/configs';
2932
import { documentConstants } from 'ts/utils/document_meta_constants';
3033
import { utils } from 'ts/utils/utils';
3134

@@ -62,6 +65,7 @@ export const Treasury: React.FC<{}> = () => {
6265
const [isVoteModalOpen, setIsVoteModalOpen] = React.useState<boolean>(false);
6366
const [quorumThreshold, setQuorumThreshold] = React.useState<BigNumber>();
6467
const { id: proposalId } = useParams();
68+
const providerState = useSelector((state: State) => state.providerState);
6569

6670
const { data } = useQuery('proposal', async () => {
6771
const { proposal: proposalFromGraph } = await request(GOVERNANCE_THEGRAPH_ENDPOINT, FETCH_PROPOSAL, {
@@ -72,15 +76,16 @@ export const Treasury: React.FC<{}> = () => {
7276
});
7377

7478
React.useEffect(() => {
75-
// tslint:disable-next-line:no-floating-promises
79+
const contract = new ZrxTreasuryContract(GOVERNOR_CONTRACT_ADDRESS.ZRX, providerState.provider);
80+
// tslint:disable-next-line: no-floating-promises
7681
(async () => {
77-
// const qThreshold = await contract.quorumThreshold().callAsync();
78-
// setQuorumThreshold(qThreshold);
79-
const hardCodeQuorumThreshold = new BigNumber('10000000');
80-
setQuorumThreshold(hardCodeQuorumThreshold);
82+
const qThreshold = await contract.quorumThreshold().callAsync();
83+
setQuorumThreshold(qThreshold);
8184
})();
85+
}, [providerState]);
8286

83-
if (data) {
87+
React.useEffect(() => {
88+
if (data && quorumThreshold) {
8489
// Disabling linter to allow for shadowed variables
8590
// tslint:disable no-shadowed-variable
8691
const {

ts/pages/governance/vote_index.tsx

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
// import { ZrxTreasuryContract } from '@0x/contracts-treasury';
1+
import { ZrxTreasuryContract } from '@0x/contracts-treasury';
22
import { BigNumber } from '@0x/utils';
33
import { gql, request } from 'graphql-request';
44
import * as _ from 'lodash';
55
import CircularProgress from 'material-ui/CircularProgress';
66
import moment from 'moment';
77
import * as React from 'react';
88
import { useQuery } from 'react-query';
9-
// import { useSelector } from 'react-redux';
9+
import { useSelector } from 'react-redux';
1010
import styled from 'styled-components';
1111

1212
import { Button } from 'ts/components/button';
@@ -18,10 +18,10 @@ import { Heading, Paragraph } from 'ts/components/text';
1818
import { Text } from 'ts/components/ui/text';
1919
import { Proposal, proposals as prodProposals, stagingProposals, TreasuryProposal } from 'ts/pages/governance/data';
2020
import { VoteIndexCard } from 'ts/pages/governance/vote_index_card';
21-
// import { State } from 'ts/redux/reducer';
21+
import { State } from 'ts/redux/reducer';
2222
import { colors } from 'ts/style/colors';
2323
import { 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';
2525
import { constants } from 'ts/utils/constants';
2626
import { documentConstants } from 'ts/utils/document_meta_constants';
2727
import { 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

Comments
 (0)