on master help sign in
senate: fix post-vote return behavior

Previously didn't correctly update the voted flag (using an object for the key instead of the appropriate hash/address), and used non-idiomatic state updating logic. This improves on both of those.

commit92f0a0561b2d5d0b84872ac7e002b26bae5837c8 authorfang <git@fang.io> dateFri 14 May 2021, 13:24 (5 years ago) parent2063508
2 files changed+16−8
src/views/Senate/Documents.js+8−4 src/views/Senate/Upgrades.js+8−4
src/views/Senate/Documents.js+8−4
@@ -52,7 +52,7 @@ export default function Documents() {
5252 const _contracts = need.contracts(contracts);
5353 const _point = convertToInt(need.point(pointCursor), 10);
5454
55− const { construct, bind } = useCastDocumentVote();
55+ const { construct, reset, unconstruct, bind } = useCastDocumentVote();
5656
5757 // const [documentHash, setDocumentHash] = useState('0x...');
5858 const [majorities, setMajorities] = useState([]);
@@ -109,10 +109,14 @@ export default function Documents() {
109109 );
110110
111111 const didVote = useCallback(() => {
112− polls[votingOn].hasVoted = true;
113− setPolls(polls);
112+ reset();
113+ unconstruct();
114+ setPolls(polls => {
115+ polls[votingOn.hash].hasVoted = true;
116+ return polls;
117+ });
114118 setVotingOn({});
115− }, [polls, setPolls, votingOn]);
119+ }, [votingOn, reset, unconstruct]);
116120
117121 const majorityList = useMemo(() => {
118122 return majorities.map(doc => {
src/views/Senate/Upgrades.js+8−4
@@ -48,7 +48,7 @@ export default function Upgrades() {
4848 const _contracts = need.contracts(contracts);
4949 const _point = convertToInt(need.point(pointCursor), 10);
5050
51− const { construct, bind } = useCastUpgradeVote();
51+ const { construct, reset, unconstruct, bind } = useCastUpgradeVote();
5252
5353 const [proposals, setProposals] = useState([]);
5454 const [polls, setPolls] = useState({});
@@ -101,10 +101,14 @@ export default function Upgrades() {
101101 );
102102
103103 const didVote = useCallback(() => {
104− polls[votingOn].hasVoted = true;
105− setPolls(polls);
104+ reset();
105+ unconstruct();
106+ setPolls(polls => {
107+ polls[votingOn.address].hasVoted = true;
108+ return polls;
109+ });
106110 setVotingOn({});
107− }, [polls, setPolls, votingOn]);
111+ }, [votingOn, reset, unconstruct]);
108112
109113 const openList = useMemo(() => {
110114 return open.map(address => {