Skip to content

Commit

Permalink
remove payout column if value is nil
Browse files Browse the repository at this point in the history
  • Loading branch information
emmanuelokoye committed Feb 8, 2022
1 parent 7c487b4 commit 561f9d0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 20 deletions.
2 changes: 1 addition & 1 deletion packages/react-app/src/routes/party/Party.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export default function Party({
console.log(error);
return null;
}
}, [partyData, strategy]);
}, [partyData, strategy, amountToDistribute]);

const cachedVoteTable = useMemo(() => {
try {
Expand Down
33 changes: 14 additions & 19 deletions packages/react-app/src/routes/party/components/ViewTable.jsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
import {
Box,
Center,
Table,
Thead,
Tbody,
Tfoot,
Tr,
Th,
Td,
} from "@chakra-ui/react";
import { Box, Center, Table, Thead, Tbody, Tfoot, Tr, Th, Td } from "@chakra-ui/react";
import React, { useState, useMemo } from "react";
import AddressChakra from "../../../components/AddressChakra";

Expand All @@ -18,7 +8,8 @@ export const ViewTable = ({ partyData, mainnetProvider, votesData, distribution,

const candidateRows = useMemo(() => {
const ballotVotes = votesData && votesData[0] && JSON.parse(votesData[0].data.ballot.votes);
const dist = distribution && distribution.reduce((obj, item) => Object.assign(obj, { [item.address]: item.score }), {});
const dist =
distribution && distribution.reduce((obj, item) => Object.assign(obj, { [item.address]: item.score }), {});
const row =
partyData &&
partyData.candidates &&
Expand All @@ -39,17 +30,19 @@ export const ViewTable = ({ partyData, mainnetProvider, votesData, distribution,
<Td>
<Center>{!isNaN(dist[d] * 1) && dist && (dist[d] * 100).toFixed(2)}%</Center>
</Td>
<Td>
<Center>{!isNaN(dist[d]) ? (dist[d] * amountToDistribute).toFixed(2) : amountToDistribute}</Center>
</Td>
{amountToDistribute ? (
<Td>
<Center>{(dist[d] * amountToDistribute).toFixed(2)}</Center>
</Td>
) : null}
</Tr>
</Tbody>
);
});

setCastVotes(ballotVotes);
return row;
}, [partyData, votesData, distribution, strategy, amountToDistribute]);
}, [partyData, votesData, distribution, strategy, amountToDistribute]);

return (
<Box>
Expand All @@ -65,9 +58,11 @@ export const ViewTable = ({ partyData, mainnetProvider, votesData, distribution,
<Th>
<Center>{`Score (${strategy})`}</Center>
</Th>
<Th>
<Center>{"possible payout"}</Center>
</Th>
{amountToDistribute ? (
<Th>
<Center>{"Payout"}</Center>
</Th>
) : null}
</Tr>
</Thead>
{candidateRows}
Expand Down

0 comments on commit 561f9d0

Please sign in to comment.