Skip to content

Commit

Permalink
temp-fix: fetch anchor address at checkout
Browse files Browse the repository at this point in the history
note: this needs to be reverted (this is temp fix to ensure cart
with projects having no anchor can checkout)
  • Loading branch information
thelostone-mc committed Apr 26, 2024
1 parent bf0e0c5 commit c34e5a0
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 6 deletions.
14 changes: 14 additions & 0 deletions packages/builder/src/__tests__/reducers/projects.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -116,6 +118,7 @@ describe("projects reducer", () => {
metadataCid: "0x1",
metadata: {},
distributionTransaction: null,
anchorAddress: addressFrom(123) as `0x${string}`,
round: {
applicationsStartTime: "0",
applicationsEndTime: "0",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -548,6 +561,7 @@ describe("projects reducer", () => {
metadataCid: "0x3",
metadata: {},
distributionTransaction: null,
anchorAddress: addressFrom(123) as `0x${string}`,
round: {
applicationsStartTime: "0",
applicationsEndTime: "0",
Expand Down
1 change: 1 addition & 0 deletions packages/data-layer/src/data-layer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions packages/data-layer/src/data.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ export type ProjectApplicationForManager = ProjectApplication & {
};

export type ProjectApplicationWithRound = ProjectApplication & {
anchorAddress: Address;
round: {
applicationsStartTime: string;
applicationsEndTime: string;
Expand Down
1 change: 1 addition & 0 deletions packages/data-layer/src/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ export const getApplicationsByRoundIdAndProjectIds = gql`
status
metadataCid
metadata
anchorAddress
round {
applicationsStartTime
applicationsEndTime
Expand Down
53 changes: 49 additions & 4 deletions packages/grant-explorer/src/checkoutStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> = Record<ChainId, T>;

Expand All @@ -53,7 +54,8 @@ interface CheckoutState {
checkout: (
chainsToCheckout: { chainId: ChainId; permitDeadline: number }[],
walletClient: WalletClient,
allo: Allo
allo: Allo,
dataLayer: DataLayer
) => Promise<void>;
getCheckedOutProjects: () => CartProject[];
checkedOutProjects: CartProject[];
Expand Down Expand Up @@ -100,7 +102,8 @@ export const useCheckoutStore = create<CheckoutState>()(
checkout: async (
chainsToCheckout: { chainId: ChainId; permitDeadline: number }[],
walletClient: WalletClient,
allo: Allo
allo: Allo,
dataLayer: DataLayer
) => {
const chainIdsToCheckOut = chainsToCheckout.map((chain) => chain.chainId);
get().setChainsToCheckout(
Expand Down Expand Up @@ -229,10 +232,52 @@ export const useCheckoutStore = create<CheckoutState>()(
);

const groupedEncodedVotes: Record<string, Hex[]> = {};

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<string, bigint> = {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,8 @@ export function SummaryContainer() {
permitDeadline: currentPermitDeadline,
})),
walletClient,
allo
allo,
dataLayer
);
} catch (error) {
console.error(error);
Expand Down

0 comments on commit c34e5a0

Please sign in to comment.