Skip to content

Commit

Permalink
dispatch owner
Browse files Browse the repository at this point in the history
  • Loading branch information
0xKurt committed Jan 25, 2024
1 parent f1d204f commit ea93016
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/builder/src/actions/grantsMetadata.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { datadogRum } from "@datadog/browser-rum";
import { getConfig } from "common/src/config";
import { DataLayer } from "data-layer";
import { AddressAndRole, DataLayer } from "data-layer";
import { Dispatch } from "redux";
import { Metadata } from "../types";
import { getProjectURIComponents, getV1HashedProjectId } from "../utils/utils";
import { projectOwnersLoaded } from "./projects";

export const GRANT_METADATA_LOADING_URI = "GRANT_METADATA_LOADING_URI";
export interface GrantMetadataLoadingURI {
Expand Down Expand Up @@ -126,6 +127,12 @@ export const fetchGrantData =
throw new Error("metadata is null");
}

const ownerAddresses = project.roles
.filter((role: AddressAndRole) => role.role === "OWNER")
.map((role) => role.address);

dispatch(projectOwnersLoaded(id, ownerAddresses));

dispatch(grantMetadataFetched(item));
} catch (e) {
datadogRum.addError(e);
Expand Down
42 changes: 42 additions & 0 deletions packages/common/src/allo/backends/test-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { vi } from "vitest";
import { AlloV1 } from "./allo-v1";
import { zeroAddress, Hex } from "viem";
import { createMockTransactionSender } from "../transaction-sender";
import { success } from "../common";
import { Allo } from "../allo";
import { AlloV2 } from "./allo-v2";

const ipfsUploader = vi.fn().mockResolvedValue(success("ipfsHash"));
const waitUntilIndexerSynced = vi.fn().mockResolvedValue(success(null));
const projectRegistryAddress = zeroAddress;
const chainId = 1;

const transactionSender = createMockTransactionSender();
export const zeroTxHash = ("0x" + "0".repeat(64)) as Hex;

export const alloV1: Allo = new AlloV1({
chainId,
projectRegistryAddress,
ipfsUploader,
transactionSender,
waitUntilIndexerSynced,
});

export const alloV2: Allo = new AlloV2({
chainId,
projectRegistryAddress, // todo: not used
ipfsUploader,
transactionSender,
waitUntilIndexerSynced,
});

export const getAllo = (version: string): Allo => {
switch (version) {
case "allo-v1":
return alloV1;
case "allo-v2":
return alloV2;
default:
throw new Error(`Unknown Allo version: ${version}`);
}
};
6 changes: 6 additions & 0 deletions packages/data-layer/src/data-layer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ const mockProjects: v2Project[] = [
projectNumber: null,
registryAddress: "0x4aacca72145e1df2aec137e1f3c5e3d75db8b5f3",
tags: ["allo-v2"],
roles: [
{
address: "0x8a79249b63395c25bd121ba6ff280198c399d4fb",
role: "OWNER",
},
],
},
];

Expand Down
6 changes: 6 additions & 0 deletions packages/data-layer/src/data.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ export type ProjectMetadata = {
createdAt?: number;
};

export type AddressAndRole = {
address: string;
role: string;
};

/**
* The project type for v1
*
Expand Down Expand Up @@ -157,6 +162,7 @@ export type v2Project = {
* The block the project was updated at
*/
updatedAtBlock: number;
roles: AddressAndRole[];
};

export type ProjectEvents = {
Expand Down
4 changes: 4 additions & 0 deletions packages/data-layer/src/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ export const getProjectById = gql`
projectNumber
registryAddress
tags
roles {
address
role
}
}
}
`;
Expand Down

0 comments on commit ea93016

Please sign in to comment.