Skip to content

Commit

Permalink
Merge branch 'main' into local-dev-env-setup
Browse files Browse the repository at this point in the history
  • Loading branch information
codenamejason authored Feb 14, 2024
2 parents f773a15 + af7ce95 commit 2528bdd
Show file tree
Hide file tree
Showing 38 changed files with 1,965 additions and 1,858 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ node_modules
dist/
coverage/
.eslintcache
bun.lockb
tmp
bun.lockb
2 changes: 2 additions & 0 deletions packages/builder/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ yarn-error.log*
.eslintcache
.vercel
.env*.local

/cache
2 changes: 1 addition & 1 deletion packages/builder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"dompurify": "^2.4.3",
"ethers": "^5.7.2",
"framer-motion": "^6",
"gitcoin-lit-js-sdk": "^1.2.9",
"gitcoin-lit-js-sdk": "^1.3.1",
"history": "^5.3.0",
"https-browserify": "^1.0.0",
"jest": "^27.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import "@testing-library/jest-dom";
import { act, fireEvent, screen, waitFor } from "@testing-library/react";
import { Store } from "redux";
import { RoundApplicationMetadata } from "data-layer";
import { Store } from "redux";
import * as projects from "../../../actions/projects";
import { web3ChainIDLoaded } from "../../../actions/web3";
import Form from "../../../components/application/Form";
Expand Down Expand Up @@ -45,6 +45,7 @@ const roundApplicationMetadata: RoundApplicationMetadata = {
};

const round: Round = {
id: `1:${addressFrom(1)}:1`,
address: "0x123",
applicationsStartTime: 123,
applicationsEndTime: 123,
Expand Down
12 changes: 8 additions & 4 deletions packages/builder/src/actions/grantsMetadata.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { datadogRum } from "@datadog/browser-rum";
import { getConfig } from "common/src/config";
import { AddressAndRole, DataLayer } from "data-layer";
import { ethers } from "ethers";
import { Dispatch } from "redux";
import { Metadata } from "../types";
import { getProjectURIComponents, getV1HashedProjectId } from "../utils/utils";
import { projectOwnersLoaded } from "./projects";
import { projectAnchorsLoaded, projectOwnersLoaded } from "./projects";

export const GRANT_METADATA_LOADING_URI = "GRANT_METADATA_LOADING_URI";
export interface GrantMetadataLoadingURI {
Expand Down Expand Up @@ -117,19 +118,22 @@ export const fetchGrantData =
createdAt: project.metadata.createdAt,
updatedAt: project.metadata.createdAt, // todo: get this value
credentials: project.metadata.credentials,
protocol: 1,
protocol: project.metadata.protocol,
pointer: project.metadataCid,
userGithub: project.metadata.userGithub,
projectGithub: project.metadata.projectGithub,
projectTwitter: project.metadata.projectTwitter,
};

const ownerAddresses = project.roles
const ownerAddresses: `0x${string}`[] = project.roles
.filter((role: AddressAndRole) => role.role === "OWNER")
.map((role) => role.address);
.map((role) => ethers.utils.getAddress(role.address));

dispatch(projectOwnersLoaded(id, ownerAddresses));

const anchorAddress = project.anchorAddress!;
dispatch(projectAnchorsLoaded(id, anchorAddress));

dispatch(grantMetadataFetched(item));
} catch (e) {
datadogRum.addError(e);
Expand Down
21 changes: 20 additions & 1 deletion packages/builder/src/actions/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,16 @@ interface ProjectStatsLoadedAction {
stats: ProjectStats[];
}

export const PROJECT_ANCHORS_LOADED = "PROJECT_ANCHORS_LOADED";

interface ProjectAnchorsLoadedAction {
type: typeof PROJECT_ANCHORS_LOADED;
payload: {
projectID: string;
anchor: string;
};
}

/** Actions */

/** Project Action Types */
Expand All @@ -134,7 +144,8 @@ export type ProjectsActions =
| ProjectApplicationUpdatedAction
| ProjectOwnersLoadedAction
| ProjectStatsLoadingAction
| ProjectStatsLoadedAction;
| ProjectStatsLoadedAction
| ProjectAnchorsLoadedAction;

/** Action Creators */
export const projectsLoading = (chainID: ChainId): ProjectsLoadingAction => ({
Expand Down Expand Up @@ -165,6 +176,14 @@ export const projectOwnersLoaded = (projectID: string, owners: string[]) => ({
},
});

export const projectAnchorsLoaded = (projectID: string, anchor: string) => ({
type: PROJECT_ANCHORS_LOADED,
payload: {
projectID,
anchor,
},
});

/**
* Load projects for a given chain
*
Expand Down
52 changes: 28 additions & 24 deletions packages/builder/src/actions/roundApplication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,21 +145,22 @@ export function chainIdToChainName(chainId: number): string {
}

export const submitApplication =
(roundAddress: string, formInputs: RoundApplicationAnswers, allo: Allo) =>
(roundId: string, formInputs: RoundApplicationAnswers, allo: Allo) =>
async (dispatch: Dispatch, getState: () => RootState) => {
const state = getState();
const roundState = state.rounds[roundAddress];
const roundState = state.rounds[roundId];
const isV2 = getConfig().allo.version === "allo-v2";

dispatch({
type: ROUND_APPLICATION_LOADING,
roundAddress,
roundAddress: roundId, // todo: roundAddress is misleading
status: Status.BuildingApplication,
});

if (roundState === undefined) {
dispatchAndLogApplicationError(
dispatch,
roundAddress,
roundId,
"cannot load round data",
Status.BuildingApplication
);
Expand All @@ -170,7 +171,7 @@ export const submitApplication =
if (roundApplicationMetadata === undefined) {
dispatchAndLogApplicationError(
dispatch,
roundAddress,
roundId,
"cannot load round application metadata",
Status.BuildingApplication
);
Expand All @@ -185,7 +186,7 @@ export const submitApplication =
if (!projectQuestion) {
dispatchAndLogApplicationError(
dispatch,
roundAddress,
roundId,
"cannot find project question id",
Status.BuildingApplication
);
Expand All @@ -204,7 +205,7 @@ export const submitApplication =
if (projectMetadata === undefined) {
dispatchAndLogApplicationError(
dispatch,
roundAddress,
roundId,
"cannot find selected project metadata",
Status.BuildingApplication
);
Expand All @@ -217,7 +218,7 @@ export const submitApplication =
if (chainID === undefined) {
dispatchAndLogApplicationError(
dispatch,
roundAddress,
roundId,
"cannot find chain id",
Status.BuildingApplication
);
Expand All @@ -227,14 +228,16 @@ export const submitApplication =

dispatch({
type: ROUND_APPLICATION_LOADING,
roundAddress,
roundId,
status: Status.LitAuthentication,
});

let application: RoundApplication;
let deterministicApplication: string;

try {
const roundAddress = roundState.round!.address;

const builder = new RoundApplicationBuilder(
true,
project,
Expand All @@ -249,7 +252,7 @@ export const submitApplication =
} catch (error) {
dispatchAndLogApplicationError(
dispatch,
roundAddress,
roundId,
"error building round application",
Status.LitAuthentication
);
Expand All @@ -265,7 +268,7 @@ export const submitApplication =

dispatch({
type: ROUND_APPLICATION_LOADING,
roundAddress,
roundId,
status: Status.SigningApplication,
});

Expand All @@ -275,7 +278,7 @@ export const submitApplication =
} catch (e) {
dispatchAndLogApplicationError(
dispatch,
roundAddress,
roundId,
"error signing round application",
Status.SigningApplication
);
Expand All @@ -287,31 +290,32 @@ export const submitApplication =
application,
};

const projectUniqueID = generateUniqueRoundApplicationID(
Number(projectChainId),
projectNumber,
projectRegistryAddress
) as Hex;
const projectUniqueID = isV2
? (state.projects.anchor![projectID] as Hex)
: (generateUniqueRoundApplicationID(
Number(projectChainId),
projectNumber,
projectRegistryAddress
) as Hex);

dispatch({
type: ROUND_APPLICATION_LOADING,
roundAddress,
roundAddress: roundId,
status: Status.UploadingMetadata,
});

const result = allo.applyToRound({
projectId: projectUniqueID,
roundId: roundAddress as Hex,
roundId: isV2 ? Number(roundId) : (roundId as Hex),
metadata: signedApplication as unknown as AnyJson,
});

await result
.on("ipfs", (res) => {
if (res.type === "success") {
console.log("IPFS CID", res.value);
dispatch({
type: ROUND_APPLICATION_LOADING,
roundAddress,
roundAddress: roundId,
status: Status.SendingTx,
});
} else {
Expand All @@ -320,7 +324,7 @@ export const submitApplication =
datadogLogs.logger.error("ipfs: error uploading metadata");
dispatchAndLogApplicationError(
dispatch,
roundAddress,
roundId,
"error uploading round application metadata",
Status.UploadingMetadata
);
Expand All @@ -340,13 +344,13 @@ export const submitApplication =
if (res.type === "success") {
dispatch({
type: ROUND_APPLICATION_LOADED,
roundAddress,
roundAddress: roundId,
projectId: projectID,
});
} else {
dispatchAndLogApplicationError(
dispatch,
roundAddress,
roundId,
"error calling applyToRound",
Status.SendingTx
);
Expand Down
37 changes: 25 additions & 12 deletions packages/builder/src/actions/rounds.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
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 { PayoutStrategy, Status } from "../reducers/rounds";
import { Status } from "../reducers/rounds";
import { Round } from "../types";
import { graphqlFetch } from "../utils/graphql";
import { parseRoundApplicationMetadata } from "../utils/roundApplication";
Expand Down Expand Up @@ -61,9 +63,15 @@ export const unloadRounds = () => roundsUnloaded();
export const loadRound =
(roundId: string, dataLayer: DataLayer, chainId: number) =>
async (dispatch: Dispatch) => {
const { version } = getConfig().allo;

try {
// address validation
ethers.utils.getAddress(roundId);
if (version === "allo-v1") {
ethers.utils.getAddress(roundId);
} else if (roundId.includes("0x")) {
throw new Error(`Invalid roundId ${roundId}`);
}
} catch (e) {
datadogRum.addError(e);
datadogLogs.logger.warn(`invalid address or address checksum ${roundId}`);
Expand Down Expand Up @@ -92,10 +100,11 @@ export const loadRound =
})) || "";

// TODO: FETCH FROM INDEXER
let roundPayoutStrategy: PayoutStrategy;
let roundPayoutStrategy: RoundType;
try {
const resp = await graphqlFetch(
`
if (version === "allo-v1") {
const resp = await graphqlFetch(
`
query GetRoundById($roundId: String) {
rounds(where: {
id: $roundId
Expand All @@ -108,12 +117,15 @@ export const loadRound =
}
}
`,
chainId!,
{ roundId: roundId.toLowerCase() }
);
roundPayoutStrategy = resp.data.rounds[0].payoutStrategy
? resp.data.rounds[0].payoutStrategy.strategyName
: "MERKLE";
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");
Expand All @@ -123,7 +135,8 @@ export const loadRound =
}

const round = {
address: roundId,
id: version === "allo-v1" ? roundId : v2Round.id,
address: version === "allo-v1" ? roundId : v2Round.strategyAddress,
applicationsStartTime:
Date.parse(`${v2Round.applicationsStartTime}Z`) / 1000,
applicationsEndTime: Date.parse(`${v2Round.applicationsEndTime}Z`) / 1000,
Expand Down
3 changes: 2 additions & 1 deletion packages/builder/src/components/application/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export default function Form({
const { chainID } = state.web3;

return {
anchors: state.projects.anchor,
projectIDs: state.projects.ids,
allProjectMetadata,
chainID,
Expand Down Expand Up @@ -848,7 +849,7 @@ export default function Form({
open={showErrorModal}
onClose={closeErrorModal}
onRetry={handleSubmitApplicationRetry}
title="Round Application Period Closed"
title="Round Application Error"
>
{round.applicationsEndTime < now ? (
<div className="my-2">
Expand Down
Loading

0 comments on commit 2528bdd

Please sign in to comment.