Skip to content

Commit

Permalink
Updated Round Types - Builder, Common, Data-Layer (#2949)
Browse files Browse the repository at this point in the history
* update strategy name/round types

* update stats and type in data-layer

* clean up
  • Loading branch information
codenamejason authored Feb 16, 2024
1 parent 7f2292b commit 383e196
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 98 deletions.
48 changes: 14 additions & 34 deletions packages/builder/src/actions/rounds.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { datadogLogs } from "@datadog/browser-logs";
import { datadogRum } from "@datadog/browser-rum";
import { RoundType, getV2RoundType } from "common";
import { getConfig } from "common/src/config";
import { DataLayer } from "data-layer";
import { ethers } from "ethers";
import { Dispatch } from "redux";
import { Status } from "../reducers/rounds";
import { Round } from "../types";
import { graphqlFetch } from "../utils/graphql";
import { parseRoundApplicationMetadata } from "../utils/roundApplication";

export type RoundType = "MERKLE" | "DIRECT";

export const ROUNDS_LOADING_ROUND = "ROUNDS_LOADING_ROUND";
interface RoundsLoadingRoundAction {
type: typeof ROUNDS_LOADING_ROUND;
Expand Down Expand Up @@ -99,39 +99,19 @@ export const loadRound =
projectId: v2Round.roundMetadata.programContractAddress,
})) || "";

// TODO: FETCH FROM INDEXER
let roundPayoutStrategy: RoundType;
try {
if (version === "allo-v1") {
const resp = await graphqlFetch(
`
query GetRoundById($roundId: String) {
rounds(where: {
id: $roundId
}) {
id
payoutStrategy {
id
strategyName
}
}
}
`,
chainId!,
{ roundId: roundId.toLowerCase() }
);
roundPayoutStrategy = resp.data.rounds[0].payoutStrategy
? resp.data.rounds[0].payoutStrategy.strategyName
: "MERKLE";
} else {
roundPayoutStrategy = getV2RoundType(v2Round.strategyId);
}
} catch (e) {
datadogRum.addError(e);
datadogLogs.logger.error("sg: error loading round payoutStrategy");
dispatch(loadingError(roundId, "error loading round payoutStrategy"));
console.error(e);
return;

switch (v2Round.strategyName) {
case "allov1.QF":
case "allov2.DonationVotingMerkleDistributionDirectTransferStrategy":
roundPayoutStrategy = "MERKLE";
break;
case "allov1.Direct":
case "allov2.DirectGrantsSimpleStrategy":
roundPayoutStrategy = "DIRECT";
break;
default:
roundPayoutStrategy = "MERKLE";
}

const round = {
Expand Down
3 changes: 1 addition & 2 deletions packages/builder/src/components/grants/ApplicationCard.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { RoundType } from "common";
import { Badge, Box, Button, Image, Spinner } from "@chakra-ui/react";
import { ApplicationStatus, useDataLayer } from "data-layer";
import { useEffect } from "react";
import { useDispatch, useSelector } from "react-redux";
import { Link } from "react-router-dom";
import { loadRound } from "../../actions/rounds";
import { RoundType, loadRound } from "../../actions/rounds";
import { RootState } from "../../reducers";
import { roundApplicationViewPath } from "../../routes";
import { ApplicationCardType, RoundSupport } from "../../types";
Expand Down
12 changes: 7 additions & 5 deletions packages/builder/src/components/grants/rounds/RoundListItem.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// eslint-disable max-len
import { ApplicationStatus, ProjectApplication } from "data-layer";
import { Badge, Box, Spinner } from "@chakra-ui/react";
import { useSelector } from "react-redux";
import { ROUND_PAYOUT_DIRECT } from "common";
import { ApplicationStatus, ProjectApplication } from "data-layer";
import { useEffect, useState } from "react";
import { ROUND_PAYOUT_DIRECT, ROUND_PAYOUT_MERKLE, RoundType } from "common";
import { useSelector } from "react-redux";
import { RoundType } from "../../../actions/rounds";
import { RootState } from "../../../reducers";
import { roundApplicationPathForProject } from "../../../routes";
import { Round, RoundDisplayType } from "../../../types";
Expand Down Expand Up @@ -87,6 +88,7 @@ export default function RoundListItem({

const roundPayoutStrategy = roundData?.payoutStrategy;

// todo: temp fix for rendering badges
return (
<span>
<Badge
Expand All @@ -96,12 +98,12 @@ export default function RoundListItem({
p={2}
textTransform="inherit"
>
{roundPayoutStrategy === ROUND_PAYOUT_MERKLE ? (
{roundPayoutStrategy === "MERKLE" ? (
<span className={`text-${colorScheme?.text} text-sm`}>
Quadratic Funding
</span>
) : null}
{roundPayoutStrategy === ROUND_PAYOUT_DIRECT ? (
{roundPayoutStrategy === "DIRECT" ? (
<span className={`text-${colorScheme?.text} text-sm`}>
Direct Grant
</span>
Expand Down
4 changes: 2 additions & 2 deletions packages/builder/src/components/grants/stats/Stats.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Spinner } from "@chakra-ui/react";
import { ChainId, ROUND_PAYOUT_MERKLE, RoundPayoutType } from "common";
import { ChainId, RoundPayoutType } from "common";
import { useEffect, useState } from "react";
import { useDispatch, useSelector } from "react-redux";
import { useParams } from "react-router-dom";
Expand Down Expand Up @@ -52,7 +52,7 @@ export default function RoundStats() {
applications.forEach((app) => {
const roundType =
props.rounds[app.roundId]?.round?.payoutStrategy || "";
if (roundType !== "" && roundType === ROUND_PAYOUT_MERKLE) {
if (roundType !== "" && roundType === "MERKLE") {
rounds.push({
roundId: app.roundId,
chainId: app.chainId,
Expand Down
45 changes: 0 additions & 45 deletions packages/common/src/allo/roundIdentifier.ts

This file was deleted.

18 changes: 8 additions & 10 deletions packages/common/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Signer } from "@ethersproject/abstract-signer";
import { Network, Web3Provider } from "@ethersproject/providers";
import { useMemo, useState } from "react";
import { useParams as useRouterParams } from "react-router";
import { useOutletContext } from "react-router-dom";
import useSWR from "swr";
import z from "zod";
import { useOutletContext } from "react-router-dom";
import { Network, Web3Provider } from "@ethersproject/providers";
import { Signer } from "@ethersproject/abstract-signer";
import { graphql_fetch } from "./graphql_fetch";
import { ChainId } from "./chain-ids";
import { useParams as useRouterParams } from "react-router";
import { graphql_fetch } from "./graphql_fetch";

export * from "./icons";
export * from "./markdown";
Expand Down Expand Up @@ -325,7 +325,7 @@ export { AlloV2 } from "./allo/backends/allo-v2";
export {
createWaitForIndexerSyncTo,
getCurrentSubgraphBlockNumber,
waitForSubgraphSyncTo,
waitForSubgraphSyncTo
} from "./allo/indexer";
export type { WaitUntilIndexerSynced } from "./allo/indexer";
export { createPinataIpfsUploader } from "./allo/ipfs";
Expand All @@ -336,7 +336,7 @@ export {
createViemTransactionSender,
decodeEventFromReceipt,
sendRawTransaction,
sendTransaction,
sendTransaction
} from "./allo/transaction-sender";

export type AnyJson =
Expand Down Expand Up @@ -376,6 +376,4 @@ export interface Web3Instance {
signer?: Signer;
}

export { graphql_fetch, graphQlEndpoints } from "./graphql_fetch";

export * from "./allo/roundIdentifier";
export { graphQlEndpoints, graphql_fetch } from "./graphql_fetch";
1 change: 1 addition & 0 deletions packages/data-layer/src/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ export const getRoundByIdAndChainId = gql`
applicationMetadataCid
strategyId
strategyAddress
strategyName
}
}
`;
Expand Down

0 comments on commit 383e196

Please sign in to comment.