From c34e5a0549c9710bdde479012c558e686606baf7 Mon Sep 17 00:00:00 2001 From: Aditya Anand M C Date: Fri, 26 Apr 2024 17:45:24 +0530 Subject: [PATCH] temp-fix: fetch anchor address at checkout note: this needs to be reverted (this is temp fix to ensure cart with projects having no anchor can checkout) --- .../src/__tests__/reducers/projects.test.ts | 14 +++++ packages/data-layer/src/data-layer.test.ts | 1 + packages/data-layer/src/data.types.ts | 1 + packages/data-layer/src/queries.ts | 1 + packages/grant-explorer/src/checkoutStore.ts | 53 +++++++++++++++++-- .../utils/__tests__/getFilterLabel.test.tsx | 2 +- .../round/ViewCartPage/SummaryContainer.tsx | 3 +- 7 files changed, 69 insertions(+), 6 deletions(-) diff --git a/packages/builder/src/__tests__/reducers/projects.test.ts b/packages/builder/src/__tests__/reducers/projects.test.ts index 85c29d2c09..7ab0ef5274 100644 --- a/packages/builder/src/__tests__/reducers/projects.test.ts +++ b/packages/builder/src/__tests__/reducers/projects.test.ts @@ -35,6 +35,7 @@ describe("projects reducer", () => { metadataCid: "0x1", metadata: {} as ProjectApplicationMetadata, distributionTransaction: null, + anchorAddress: addressFrom(123) as `0x${string}`, round: { applicationsStartTime: "0", applicationsEndTime: "0", @@ -71,6 +72,7 @@ describe("projects reducer", () => { metadataCid: "0x1", metadata: {} as ProjectApplicationMetadata, distributionTransaction: null, + anchorAddress: addressFrom(123) as `0x${string}`, round: { applicationsStartTime: "0", applicationsEndTime: "0", @@ -116,6 +118,7 @@ describe("projects reducer", () => { metadataCid: "0x1", metadata: {}, distributionTransaction: null, + anchorAddress: addressFrom(123) as `0x${string}`, round: { applicationsStartTime: "0", applicationsEndTime: "0", @@ -159,6 +162,7 @@ describe("projects reducer", () => { metadataCid: "0x1", metadata: {} as ProjectApplicationMetadata, distributionTransaction: null, + anchorAddress: addressFrom(123) as `0x${string}`, round: { applicationsStartTime: "0", applicationsEndTime: "0", @@ -201,6 +205,7 @@ describe("projects reducer", () => { metadataCid: "0x2", metadata: {} as ProjectApplicationMetadata, distributionTransaction: null, + anchorAddress: addressFrom(123) as `0x${string}`, round: { applicationsStartTime: "0", applicationsEndTime: "0", @@ -240,6 +245,7 @@ describe("projects reducer", () => { metadataCid: "0x1", metadata: {} as ProjectApplicationMetadata, distributionTransaction: null, + anchorAddress: addressFrom(123) as `0x${string}`, round: { applicationsStartTime: "0", applicationsEndTime: "0", @@ -276,6 +282,7 @@ describe("projects reducer", () => { metadataCid: "0x2", metadata: {} as ProjectApplicationMetadata, distributionTransaction: null, + anchorAddress: addressFrom(123) as `0x${string}`, round: { applicationsStartTime: "0", applicationsEndTime: "0", @@ -329,6 +336,7 @@ describe("projects reducer", () => { metadataCid: "0x1", metadata: {} as ProjectApplicationMetadata, distributionTransaction: null, + anchorAddress: addressFrom(123) as `0x${string}`, round: { applicationsStartTime: "0", applicationsEndTime: "0", @@ -365,6 +373,7 @@ describe("projects reducer", () => { metadataCid: "0x1", metadata: {} as ProjectApplicationMetadata, distributionTransaction: null, + anchorAddress: addressFrom(123) as `0x${string}`, round: { applicationsStartTime: "0", applicationsEndTime: "0", @@ -399,6 +408,7 @@ describe("projects reducer", () => { metadataCid: "0x2", metadata: {} as ProjectApplicationMetadata, distributionTransaction: null, + anchorAddress: addressFrom(123) as `0x${string}`, round: { applicationsStartTime: "0", applicationsEndTime: "0", @@ -433,6 +443,7 @@ describe("projects reducer", () => { metadataCid: "0x3", metadata: {} as ProjectApplicationMetadata, distributionTransaction: null, + anchorAddress: addressFrom(123) as `0x${string}`, round: { applicationsStartTime: "0", applicationsEndTime: "0", @@ -467,6 +478,7 @@ describe("projects reducer", () => { metadataCid: "0x4", metadata: {} as ProjectApplicationMetadata, distributionTransaction: null, + anchorAddress: addressFrom(123) as `0x${string}`, round: { applicationsStartTime: "0", applicationsEndTime: "0", @@ -503,6 +515,7 @@ describe("projects reducer", () => { metadataCid: "0x1", metadata: {} as ProjectApplicationMetadata, distributionTransaction: null, + anchorAddress: addressFrom(123) as `0x${string}`, round: { applicationsStartTime: "0", applicationsEndTime: "0", @@ -548,6 +561,7 @@ describe("projects reducer", () => { metadataCid: "0x3", metadata: {}, distributionTransaction: null, + anchorAddress: addressFrom(123) as `0x${string}`, round: { applicationsStartTime: "0", applicationsEndTime: "0", diff --git a/packages/data-layer/src/data-layer.test.ts b/packages/data-layer/src/data-layer.test.ts index db360e3fd8..1b22e40bb4 100644 --- a/packages/data-layer/src/data-layer.test.ts +++ b/packages/data-layer/src/data-layer.test.ts @@ -67,6 +67,7 @@ const mockApplications: ProjectApplicationWithRound[] = [ totalAmountDonatedInUsd: 0, uniqueDonorsCount: 0, distributionTransaction: null, + anchorAddress: getAddress("0xe849b2a694184b8739a04c915518330757cdb133"), round: { strategyName: "allov1.QF", applicationsStartTime: "2024-02-20T17:27:40+00:00", diff --git a/packages/data-layer/src/data.types.ts b/packages/data-layer/src/data.types.ts index 68fa9361cc..b88010620a 100644 --- a/packages/data-layer/src/data.types.ts +++ b/packages/data-layer/src/data.types.ts @@ -289,6 +289,7 @@ export type ProjectApplicationForManager = ProjectApplication & { }; export type ProjectApplicationWithRound = ProjectApplication & { + anchorAddress: Address; round: { applicationsStartTime: string; applicationsEndTime: string; diff --git a/packages/data-layer/src/queries.ts b/packages/data-layer/src/queries.ts index 2bc0d05833..a02f9a8b3b 100644 --- a/packages/data-layer/src/queries.ts +++ b/packages/data-layer/src/queries.ts @@ -338,6 +338,7 @@ export const getApplicationsByRoundIdAndProjectIds = gql` status metadataCid metadata + anchorAddress round { applicationsStartTime applicationsEndTime diff --git a/packages/grant-explorer/src/checkoutStore.ts b/packages/grant-explorer/src/checkoutStore.ts index 06ac5e3a2a..22945db6bd 100644 --- a/packages/grant-explorer/src/checkoutStore.ts +++ b/packages/grant-explorer/src/checkoutStore.ts @@ -27,6 +27,7 @@ import { getContract, getPublicClient } from "@wagmi/core"; import { getPermitType } from "common/dist/allo/voting"; import { MRC_CONTRACTS } from "common/dist/allo/addresses/mrc"; import { getConfig } from "common/src/config"; +import { DataLayer } from "data-layer"; type ChainMap = Record; @@ -53,7 +54,8 @@ interface CheckoutState { checkout: ( chainsToCheckout: { chainId: ChainId; permitDeadline: number }[], walletClient: WalletClient, - allo: Allo + allo: Allo, + dataLayer: DataLayer ) => Promise; getCheckedOutProjects: () => CartProject[]; checkedOutProjects: CartProject[]; @@ -100,7 +102,8 @@ export const useCheckoutStore = create()( checkout: async ( chainsToCheckout: { chainId: ChainId; permitDeadline: number }[], walletClient: WalletClient, - allo: Allo + allo: Allo, + dataLayer: DataLayer ) => { const chainIdsToCheckOut = chainsToCheckout.map((chain) => chain.chainId); get().setChainsToCheckout( @@ -229,10 +232,52 @@ export const useCheckoutStore = create()( ); const groupedEncodedVotes: Record = {}; + for (const roundId in groupedDonations) { + const allProjectIds = groupedDonations[roundId].map( + (d) => d.projectRegistryId + ); + const response = + await dataLayer.getApplicationsByRoundIdAndProjectIds({ + chainId, + roundId, + projectIds: allProjectIds, + }); + + const roundDonations: { + roundId: string; + chainId: number; + amount: string; + recipient: string; + projectRegistryId: string; + applicationIndex: number; + anchorAddress: string; + }[] = []; + + groupedDonations[roundId].map((d) => { + const app = response.find( + (r) => r.projectId === d.projectRegistryId + ); + + if (!app) { + throw new Error( + `Application not found for projectRegistryId ${d.projectRegistryId} in round ${roundId} on chain ${chainId}` + ); + } + roundDonations.push({ + roundId: d.roundId, + chainId: d.chainId, + amount: d.amount, + recipient: d.recipient, + projectRegistryId: d.projectRegistryId, + applicationIndex: Number(app.id), + anchorAddress: app.anchorAddress, + }); + }); + groupedEncodedVotes[roundId] = isV2 - ? encodedQFAllocation(token, groupedDonations[roundId]) - : encodeQFVotes(token, groupedDonations[roundId]); + ? encodedQFAllocation(token, roundDonations) + : encodeQFVotes(token, roundDonations); } const groupedAmounts: Record = {}; diff --git a/packages/grant-explorer/src/features/discovery/utils/__tests__/getFilterLabel.test.tsx b/packages/grant-explorer/src/features/discovery/utils/__tests__/getFilterLabel.test.tsx index dc25e73fa1..fa2a813ab5 100644 --- a/packages/grant-explorer/src/features/discovery/utils/__tests__/getFilterLabel.test.tsx +++ b/packages/grant-explorer/src/features/discovery/utils/__tests__/getFilterLabel.test.tsx @@ -18,7 +18,7 @@ describe("getFilterLabel", () => { ).toEqual("Quadratic funding"); // Filters out commas expect( - getFilterLabel({ status: "", type: ",allov1.Direct", network: "" }).label + getFilterLabel({ status: "", type: "allov1.Direct", network: "" }).label ).toEqual("Direct grants"); }); it("Returns Multiple when many are selected from same category", async () => { diff --git a/packages/grant-explorer/src/features/round/ViewCartPage/SummaryContainer.tsx b/packages/grant-explorer/src/features/round/ViewCartPage/SummaryContainer.tsx index 84baf73a6f..caadcd49a2 100644 --- a/packages/grant-explorer/src/features/round/ViewCartPage/SummaryContainer.tsx +++ b/packages/grant-explorer/src/features/round/ViewCartPage/SummaryContainer.tsx @@ -349,7 +349,8 @@ export function SummaryContainer() { permitDeadline: currentPermitDeadline, })), walletClient, - allo + allo, + dataLayer ); } catch (error) { console.error(error);