Skip to content
This repository has been archived by the owner on Feb 10, 2025. It is now read-only.

Commit

Permalink
add custom fields based on pool type
Browse files Browse the repository at this point in the history
  • Loading branch information
thelostone-mc committed Jan 27, 2025
1 parent 97b556e commit b4b530e
Show file tree
Hide file tree
Showing 6 changed files with 182 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Button } from "@/primitives/Button";
import { Icon, IconType } from "@/primitives/Icon";
import { StatCardProps } from "@/primitives/StatCard";
import { StatCardGroup } from "@/primitives/StatCardGroup";
import { PoolType } from "@/types";

import { ApplicationsSection } from "~checker/components";
import { useGetApplicationsReviewPage } from "~checker/hooks";
Expand All @@ -15,7 +16,7 @@ import {
useCheckerContext,
useCheckerDispatchContext,
} from "~checker/store";
import { getManagerUrl } from "~checker/utils";
import { getManagerUrl, getRoundLinkOnManager } from "~checker/utils";
import { PoolSummary } from "~pool";

export const ReviewApplicationsPage = ({ isStandalone }: { isStandalone: boolean }) => {
Expand Down Expand Up @@ -51,7 +52,10 @@ export const ReviewApplicationsPage = ({ isStandalone }: { isStandalone: boolean
};

const openRoundInManager = () => {
window.open(`${getManagerUrl(chainId)}/#/chain/${chainId}/round/${poolId}`, "_blank");
window.open(
getRoundLinkOnManager(chainId, poolId, poolData?.strategyName as PoolType),
"_blank",
);
};

const openCheckerApplicationEvaluations = (projectId: string) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { useToast } from "@/hooks/useToast";
import { Button } from "@/primitives/Button";
import { Icon, IconType } from "@/primitives/Icon";
import { StatCardGroup } from "@/primitives/StatCardGroup";
import { Step } from "@/types";
import { PoolType, Step } from "@/types";

import { ProjectEvaluationList } from "~checker/components";
import { useGetApplicationsFinalEvaluationPage } from "~checker/hooks";
Expand All @@ -19,7 +19,7 @@ import {
useCheckerContext,
} from "~checker/store";
import { EvaluationAction, ReviewBody } from "~checker/types";
import { getManagerUrl } from "~checker/utils";
import { getManagerUrl, getRoundLinkOnManager } from "~checker/utils";
import { PoolSummary } from "~pool";

import { SubmitFinalEvaluationModal } from "./SubmitFinalEvaluationModal";
Expand Down Expand Up @@ -136,7 +136,13 @@ export const SubmitFinalEvaluationPage = ({
variant="secondry"
icon={<Icon type={IconType.CHEVRON_LEFT} />}
onClick={() =>
window.open(`${getManagerUrl(chainId as number)}/#/chain/${chainId}/round/${poolId}`)
window.open(
getRoundLinkOnManager(
chainId as number,
poolId as string,
poolData?.strategyName as PoolType,
),
)
}
value="back to round manager"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Icon, IconType } from "@/primitives/Icon";
import { ApplicationSummary, SummaryAccordians } from "~application";
import { ReviewDropdownList } from "~checker/components";
import { useApplicationEvaluations, useGetPastApplications } from "~checker/hooks";
import { getExplorerUrl } from "~checker/utils";
import { getApplicationLinkOnExplorer, getExplorerUrl } from "~checker/utils";
import { ProjectBanner } from "~project";
import { ProjectSummary } from "~project";

Expand Down Expand Up @@ -80,10 +80,7 @@ export const ViewApplicationEvaluationsPage: React.FC<ViewApplicationEvaluations
variant="none"
className="h-[38px] w-40 bg-white"
onClick={() => {
window.open(
`${getExplorerUrl(chainId)}/#/round/${chainId}/${poolId}/${applicationId}`,
"_blank",
);
window.open(getApplicationLinkOnExplorer(chainId, poolId, applicationId), "_blank");
}}
/>
</div>
Expand Down
109 changes: 94 additions & 15 deletions src/features/checker/utils/getGitcoinLinks.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { getChains, TChain } from "@gitcoin/gitcoin-chain-data";

import { PoolType } from "@/types";

type ChainIdToType = Record<number, string>;

const chainData = getChains();
Expand All @@ -9,23 +11,100 @@ const chainIdToType: ChainIdToType = chainData.reduce((acc, chain: TChain) => {
return acc;
}, {} as ChainIdToType);

export const getManagerUrl = (chainId: number): string => {
const chainType = chainIdToType[chainId];
return chainType === "mainnet"
? "https://manager.gitcoin.co"
: "https://grants-stack-manager-staging.vercel.app";
// --- Manager ---

export const getManagerUrl = (chainId: number, strategyName?: PoolType): string => {
switch (strategyName) {
case PoolType.Retrofunding:
return "https://retrofunding-amber.vercel.app";
default:
const chainType = chainIdToType[chainId];
return chainType === "mainnet"
? "https://manager.gitcoin.co"
: "https://grants-stack-manager-staging.vercel.app";
}
};

export const getProgramLinkOnManager = (
chainId: number,
programId: string,
strategyName?: PoolType,
) => {
switch (strategyName) {
default:
return `${getManagerUrl(chainId, strategyName)}/#/chain/${chainId}/program/${programId}`;
}
};

export const getRoundLinkOnManager = (chainId: number, poolId: string, strategyName?: PoolType) => {
switch (strategyName) {
default:
return `${getManagerUrl(chainId, strategyName)}/#/chain/${chainId}/round/${poolId}`;
}
};

// Builder

export const getBuilderUrl = (chainId: number, strategyName?: PoolType): string => {
switch (strategyName) {
case PoolType.Retrofunding:
default:
const chainType = chainIdToType[chainId];
return chainType === "mainnet"
? "https://builder.gitcoin.co"
: "https://grants-stack-builder-staging.vercel.app";
}
};

export const getApplyLink = (chainId: number, poolId: string, strategyName?: PoolType) => {
switch (strategyName) {
default:
return `${getBuilderUrl(chainId, strategyName)}/#/chains/${chainId}/rounds/${poolId}/apply`;
}
};

// --- Explorer ---
export const getExplorerUrl = (chainId: number, strategyName?: PoolType): string => {
switch (strategyName) {
case PoolType.Retrofunding:
return "https://retrofunding-vote.vercel.app";
default:
const chainType = chainIdToType[chainId];
return chainType === "mainnet"
? "https://explorer.gitcoin.co"
: "https://grants-stack-explorer-staging.vercel.app";
}
};

export const getPoolLinkOnExplorer = (chainId: number, poolId: string, strategyName?: PoolType) => {
switch (strategyName) {
default:
return `${getExplorerUrl(chainId, strategyName)}/#/round/${chainId}/${poolId}`;
}
};

export const getBuilderUrl = (chainId: number): string => {
const chainType = chainIdToType[chainId];
return chainType === "mainnet"
? "https://builder.gitcoin.co"
: "https://grants-stack-builder-staging.vercel.app";
export const getApplicationLinkOnExplorer = (
chainId: number,
poolId: string,
applicationId: string,
strategyName?: PoolType,
) => {
switch (strategyName) {
default:
return `${getExplorerUrl(
chainId,
strategyName,
)}/#/round/${chainId}/${poolId}/${applicationId}`;
}
};

export const getExplorerUrl = (chainId: number): string => {
const chainType = chainIdToType[chainId];
return chainType === "mainnet"
? "https://explorer.gitcoin.co"
: "https://grants-stack-explorer-staging.vercel.app";
export const getVotingInterfaceLinkOnExplorer = (
chainId: number,
poolId: string,
strategyName?: PoolType,
) => {
switch (strategyName) {
default:
return `${getExplorerUrl(chainId, strategyName)}/#/round/${chainId}/${poolId}/voting`;
}
};
31 changes: 21 additions & 10 deletions src/features/pool/components/PoolSummary/PoolSummary.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,35 @@
import type { Meta, StoryObj } from "@storybook/react";

import { PoolType } from "@/types";

import { PoolSummary, PoolSummaryProps } from "./PoolSummary";

const defaultProps = {
chainId: 1,
name: "Beta Round",
poolId: "1",
strategyName: PoolType.QuadraticFunding,
applicationsStartTime: "2024-12-09T19:22:56.413Z",
applicationsEndTime: "2024-12-10T19:23:30.678Z",
donationsStartTime: "2024-12-09T19:22:56.413Z",
donationsEndTime: "2024-12-09T19:22:56.413Z",
};

const meta: Meta<PoolSummaryProps> = {
title: "Features/Pool/PoolSummary",
component: PoolSummary,
args: {
chainId: 1,
name: "Beta Round",
poolId: "1",
strategyName: "allov2.DonationVotingMerkleDistributionDirectTransferStrategy",
applicationsStartTime: "2024-12-09T19:22:56.413Z",
applicationsEndTime: "2024-12-10T19:23:30.678Z",
donationsStartTime: "2024-12-09T19:22:56.413Z",
donationsEndTime: "2024-12-09T19:22:56.413Z",
},
args: defaultProps,
} satisfies Meta;

export default meta;

type Story = StoryObj<typeof PoolSummary>;

export const Default: Story = {};

export const Retrofunding: Story = {
args: {
...defaultProps,
strategyName: PoolType.Retrofunding,
},
};
65 changes: 50 additions & 15 deletions src/features/pool/components/PoolSummary/PoolSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ import { Button } from "@/primitives/Button";
import { Icon, IconType } from "@/primitives/Icon";
import { PoolStatus, PoolType } from "@/types";

import { getManagerUrl, getBuilderUrl, getExplorerUrl } from "~checker/utils";
import {
getApplyLink,
getPoolLinkOnExplorer,
getProgramLinkOnManager,
getManagerUrl,
getVotingInterfaceLinkOnExplorer,
} from "~checker/utils";

import { PoolBadge } from "../PoolBadge";

Expand All @@ -38,13 +44,11 @@ export const PoolSummary = (pool: PoolSummaryProps) => {
const { toast } = useToast();
const chainInfo = getChainInfo(pool.chainId);

const managerUrl = getManagerUrl(pool.chainId);
const builderUrl = getBuilderUrl(pool.chainId);
const explorerUrl = getExplorerUrl(pool.chainId);

let poolStatus: PoolStatus;
const poolType = pool.strategyName as PoolType;

const managerUrl = getManagerUrl(pool.chainId, poolType);

const now = new Date();

const registerStartDate = pool.applicationsStartTime
Expand All @@ -67,9 +71,9 @@ export const PoolSummary = (pool: PoolSummaryProps) => {
} else {
poolStatus = PoolStatus.PreRound;
}
const applyLink = `${builderUrl}/#/chains/${pool.chainId}/rounds/${pool.poolId}/apply`;
const explorerLink = `${explorerUrl}/#/round/${pool.chainId}/${pool.poolId}`;
const managerProgramLink = `${managerUrl}/#/chain/${pool.chainId}/program/${pool.programId}`;
const applyLink = getApplyLink(pool.chainId, pool.poolId, poolType);
const explorerLink = getPoolLinkOnExplorer(pool.chainId, pool.poolId, poolType);
const managerProgramLink = getProgramLinkOnManager(pool.chainId, pool.programId, poolType);
const breadcrumbItems = [
{ label: "My Programs", href: managerUrl },
{
Expand All @@ -81,6 +85,9 @@ export const PoolSummary = (pool: PoolSummaryProps) => {
href: explorerLink,
},
];

const { allocationDateLabel, viewButton } = getInfoBasedOnPoolType(poolType, pool, explorerLink);

return (
<div className={cn(variants.variants.default, "grid grid-cols-2 py-6")}>
<div className="flex flex-col items-start justify-start gap-4">
Expand Down Expand Up @@ -112,7 +119,7 @@ export const PoolSummary = (pool: PoolSummaryProps) => {
startDate={allocationStartDate}
endDate={allocationEndDate}
isLoading={pool.isLoading}
label="Voting"
label={allocationDateLabel}
/>
</div>
</div>
Expand Down Expand Up @@ -140,14 +147,42 @@ export const PoolSummary = (pool: PoolSummaryProps) => {
);
}}
/>
<Button
icon={<Icon type={IconType.EXPLORER} />}
className="border-grey-100 bg-white text-black shadow-sm"
value="View round"
onClick={() => window.open(explorerLink, "_blank")}
/>
{viewButton}
</div>
</div>
</div>
);
};

function getInfoBasedOnPoolType(poolType: PoolType, pool: PoolSummaryProps, explorerLink: string) {
let allocationDateLabel;
let viewButton;

if (poolType === PoolType.Retrofunding) {
allocationDateLabel = "Voting";
viewButton = (
<Button
icon={<Icon type={IconType.LINK} />}
className="border-grey-100 bg-white text-black shadow-sm"
value="Voting Interface"
onClick={() =>
window.open(
getVotingInterfaceLinkOnExplorer(pool.chainId, pool.poolId, poolType),
"_blank",
)
}
/>
);
} else {
allocationDateLabel = "Allocation";
viewButton = (
<Button
icon={<Icon type={IconType.EXPLORER} />}
className="border-grey-100 bg-white text-black shadow-sm"
value="View round"
onClick={() => window.open(explorerLink, "_blank")}
/>
);
}
return { allocationDateLabel, viewButton };
}

0 comments on commit b4b530e

Please sign in to comment.