Skip to content

Commit

Permalink
feat: update frontend matching estimates
Browse files Browse the repository at this point in the history
  • Loading branch information
vacekj committed Oct 12, 2023
1 parent 2b4662e commit 1412e78
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 12 deletions.
3 changes: 3 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"trailingComma": "es5"
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,16 @@ export function RoundInCart(
roundId: getAddress(round?.id ?? zeroAddress),
chainId: props.roundCart[0].chainId,
potentialVotes: props.roundCart.map((proj) => ({
roundId: getAddress(round?.id ?? zeroAddress),
projectId: proj.projectRegistryId,
amount: parseUnits(
proj.amount ?? "0",
votingTokenForChain.decimal ?? 18
),
recipient: proj.recipient,
contributor: address ?? zeroAddress,
grantAddress: proj.recipient,
voter: address ?? zeroAddress,
token: votingTokenForChain.address.toLowerCase(),
applicationId: proj.grantApplicationId,
})),
},
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,11 +295,14 @@ export function SummaryContainer() {
proj.amount ?? "0",
getVotingTokenForChain(parseChainId(proj.chainId)).decimal ?? 18
),
recipient: proj.recipient,
contributor: address as Address,
grantAddress: proj.recipient,
voter: address as Address,
token: getVotingTokenForChain(
parseChainId(proj.chainId)
).address.toLowerCase(),
projectId: proj.projectRegistryId,
applicationId: proj.grantApplicationId,
roundId: getAddress(round.id ?? ""),
})),
};
}) ?? [];
Expand Down
27 changes: 19 additions & 8 deletions packages/grant-explorer/src/hooks/matchingEstimate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@ type UseMatchingEstimatesParams = {
roundId: Address;
chainId: ChainId;
potentialVotes: {
contributor: string;
recipient: string;
amount: bigint;
projectId: string;
roundId: string;
applicationId: string;
token: string;
voter: string;
grantAddress: string;
amount: bigint;
}[];
};

Expand All @@ -35,21 +38,29 @@ interface JSONObject {
}

function getMatchingEstimates(
params: UseMatchingEstimatesParams,
params: UseMatchingEstimatesParams
): Promise<MatchingEstimateResult[]> {
const replacer = (_key: string, value: JSONValue) =>
typeof value === "bigint" ? value.toString() : value;

/* The indexer wants just the application id number, not the whole application */
const fixedApplicationId = params.potentialVotes.map((vote) => ({
...vote,
applicationId: vote.applicationId.includes("-")
? vote.applicationId.split("-")[1]
: vote.applicationId,
}));

return fetch(
`${process.env.REACT_APP_ALLO_API_URL}/api/v1/chains/${params.chainId}/rounds/${params.roundId}/estimate`,
{
headers: {
Accept: "application/json",
"content-type": "application/json",
},
body: JSON.stringify({ potentialVotes: params.potentialVotes }, replacer),
body: JSON.stringify({ potentialVotes: fixedApplicationId }, replacer),
method: "POST",
},
}
).then((r) => r.json());
}

Expand All @@ -59,12 +70,12 @@ function getMatchingEstimates(
*/
export function useMatchingEstimates(params: UseMatchingEstimatesParams[]) {
return useSWR(params, (params) =>
Promise.all(params.map((params) => getMatchingEstimates(params))),
Promise.all(params.map((params) => getMatchingEstimates(params)))
);
}

export function matchingEstimatesToText(
matchingEstimates?: MatchingEstimateResult[][],
matchingEstimates?: MatchingEstimateResult[][]
) {
return matchingEstimates
?.flat()
Expand Down

0 comments on commit 1412e78

Please sign in to comment.