Skip to content

Commit

Permalink
Merge pull request #41 from bitbeckers/feat/payout_calc_empty_evaluat…
Browse files Browse the repository at this point in the history
…ions

Feat/payout calc empty evaluations
  • Loading branch information
bitbeckers authored Mar 30, 2023
2 parents 383f19a + fabc297 commit bfe52eb
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 42 deletions.
10 changes: 6 additions & 4 deletions app/components/FUX/CommitFuxModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,17 @@ const CommitFuxModal: React.FC<{

const newFux = watch("fux");

console.log("NEW FUX: ", newFux);

const { config } = usePrepareContractWrite({
address: contractAddresses.fuxContractAddress,
abi: contractABI.fux,
functionName: "commitToWorkstream",
args: [workstreamID, newFux ? newFux : 0],
args: [workstreamID, newFux],
onError(error) {
console.log('Error', error)
},
});
const { data, write, variables } = useContractWrite({

const { data, write } = useContractWrite({
...config,
onError(e) {
error(e);
Expand Down
52 changes: 22 additions & 30 deletions app/components/FUX/FinalizeForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
Text,
Stat,
StatNumber,
Flex,
} from "@chakra-ui/react";
import { BigNumberish, ethers } from "ethers";
import _, { groupBy, mapValues, meanBy } from "lodash";
Expand All @@ -25,12 +26,11 @@ type Ratings = {
};

const parseEvaluations = (workstream: Workstream) => {
let data: Ratings = {};
const currentEvaluations = groupBy(workstream?.evaluations, "contributor.id");
data = mapValues(currentEvaluations, (ratings) => meanBy(ratings, "rating"));
console.log("AVERAGES: ", data);

return data;
return mapValues(currentEvaluations, (evaluation) =>
meanBy(evaluation, (e) => Number(e.rating))
) as Ratings;
};

const calculateRelative = (data: Ratings) => {
Expand All @@ -41,8 +41,6 @@ const calculateRelative = (data: Ratings) => {
(value) => _.divide(Number(value), Number(total)) * 100
);

console.log("RELATIVE: ", relative);

let sum = 0;
Object.entries(relative).forEach(([key, value], i) => {
if ((i = Object.keys(relative).length - 1)) {
Expand Down Expand Up @@ -109,47 +107,46 @@ const FinalizeForm: React.FC<{
return;
}

console.log("WRITING");
write?.();
};

console.log("Workstream: ", workstream);

const contributors = _workstream.contributors;
const coordinator = _workstream.coordinator?.id;
const funding = ethers.utils.formatEther(_workstream.funding);

const finalizeForm =
contributors && contributors?.length > 0 ? (
<>
<Grid gap={2} templateColumns="repeat(12, 1fr)">
<GridItem colSpan={5}>
<Grid gap={2} templateColumns="repeat(16, 1fr)">
<GridItem colSpan={8}>
<Text>Contributor</Text>
</GridItem>
<GridItem colSpan={2}>
<GridItem colSpan={3}>
<Text>Committed</Text>
</GridItem>
<GridItem colSpan={2}>
<Text>vFUX</Text>
</GridItem>
<GridItem colSpan={1}>
<Text>Coordinator</Text>
</GridItem>
<GridItem colSpan={2}>
<GridItem colSpan={3}>
<Text>Funds</Text>
</GridItem>
{contributors.map((contributor, index) => {
const address = contributor.contributor.id as `0x${string}`;
return (
<Fragment key={index}>
<GridItem colSpan={5}>
<User
address={address as `0x${string}`}
direction="horizontal"
displayAvatar={true}
/>
<GridItem colSpan={8}>
<Flex align={"center"}>
<User
address={address as `0x${string}`}
direction="horizontal"
displayAvatar={true}
/>
{coordinator?.toLowerCase() === address.toLowerCase() ? (
<StarIcon ml={"1em"} />
) : undefined}
</Flex>
</GridItem>
<GridItem colSpan={2}>
<GridItem colSpan={3}>
<Stat>
<StatNumber>{`${contributor.commitment || 0}%`}</StatNumber>
</Stat>
Expand All @@ -161,23 +158,18 @@ const FinalizeForm: React.FC<{
</StatNumber>
</Stat>
</GridItem>
<GridItem colSpan={1}>
{coordinator?.toLowerCase() === address.toLowerCase() ? (
<StarIcon mr={"1em"} />
) : undefined}
</GridItem>
<GridItem
bg="#301A3A"
display={"inline-grid"}
colSpan={2}
colSpan={3}
justifyContent="end"
alignContent="center"
>
{relative[address]
? `${_.multiply(
Number(funding),
relative[address] / 100
)} ${nativeToken}`
).toFixed(4)} ${nativeToken}`
: `0 ${nativeToken}`}
</GridItem>
</Fragment>
Expand Down
8 changes: 0 additions & 8 deletions app/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,6 @@ const Home: NextPage = () => {
address: address?.toLowerCase() || "",
},
});

const { data: ensName } = useEnsName({
address,
chainId: 1,
});

console.log(ensName);

const { data, fetching, error } = result;

const claimLink = (
Expand Down

1 comment on commit bfe52eb

@vercel
Copy link

@vercel vercel bot commented on bfe52eb Mar 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.