Skip to content

Commit

Permalink
add whitelist
Browse files Browse the repository at this point in the history
  • Loading branch information
0xKurt committed Nov 8, 2024
1 parent d854b67 commit 796571c
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 33 deletions.
1 change: 1 addition & 0 deletions packages/common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -488,3 +488,4 @@ export function isLitUnavailable(chainId: number) {
}

export * from "./chains";
export * from "./programWhitelist";
20 changes: 20 additions & 0 deletions packages/common/src/programWhitelist.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export async function getWhitelistedPrograms(): Promise<string[]> {
try {
const response = await fetch(
"https://docs.google.com/spreadsheets/d/e/2PACX-1vQxC34V_N3ubt3ycs7LvMya_zYeBmAqTxPczt0yDbLSfpI-kMp6o5E08fC0BxQG4uMp7EPV5bxP-64a/pub?gid=0&single=true&output=csv"
);

if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const csvText = await response.text();

const stringArray = csvText
.split(/\r?\n/)
.filter((line) => line.trim() !== "");

return stringArray;
} catch (error) {
return [];
}
}
13 changes: 10 additions & 3 deletions packages/data-layer/src/data-layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -942,18 +942,25 @@ export class DataLayer {
first,
orderBy,
filter,
whitelistedPrograms,
}: {
chainIds: number[];
first: number;
orderBy?: OrderByRounds;
orderDirection?: "asc" | "desc";
filter?: RoundsQueryVariables["filter"];
whitelistedPrograms?: string[];
}): Promise<{ rounds: RoundGetRound[] }> {
return await request(this.gsIndexerEndpoint, getRoundsQuery, {
orderBy: orderBy ?? "NATURAL",
chainIds,
first,
filter,
filter: whitelistedPrograms
? {
...filter,
projectId: { in: whitelistedPrograms },
}
: filter,
});
}

Expand Down Expand Up @@ -1011,8 +1018,8 @@ export class DataLayer {
async getAttestationCount({
attestationChainIds,
}: {
attestationChainIds: number[]
attestationChainIds: number[];
}): Promise<number> {
return this.attestationService.getAttestationCount({attestationChainIds});
return this.attestationService.getAttestationCount({ attestationChainIds });
}
}
14 changes: 11 additions & 3 deletions packages/grant-explorer/src/features/api/rounds.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { getWhitelistedPrograms } from "common";
import useSWR, { SWRResponse } from "swr";
import { createISOTimestamp } from "../discovery/utils/createRoundsStatusFilter";
import { RoundGetRound, RoundsQueryVariables, useDataLayer } from "data-layer";

export const useRounds = (
variables: RoundsQueryVariables,
chainIds: number[]
chainIds: number[],
onlywWhitelistedPrograms = false
): SWRResponse<RoundGetRound[]> => {
const dataLayer = useDataLayer();

Expand All @@ -13,12 +15,17 @@ export const useRounds = (
// same, cache will be used instead of new requests)
["rounds", chainIds, variables],
async () => {
const whitelistedPrograms = onlywWhitelistedPrograms
? await getWhitelistedPrograms()
: undefined;

const [spamRounds, { rounds }] = await Promise.all([
fetchSpamRounds(),
dataLayer.getRounds({
...variables,
first: 500,
chainIds,
whitelistedPrograms,
}),
]);

Expand Down Expand Up @@ -64,8 +71,9 @@ const OVERRIDE_PRIVATE_ROUND_IDS = [
export const filterOutPrivateRounds = (rounds: RoundGetRound[]) => {
return rounds.filter(
(round) =>
(round.roundMetadata && round.roundMetadata.roundType) &&
round.roundMetadata.roundType !== "private" ||
(round.roundMetadata &&
round.roundMetadata.roundType &&
round.roundMetadata.roundType !== "private") ||
OVERRIDE_PRIVATE_ROUND_IDS.includes(round.id.toLowerCase())
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,24 @@ import { getExplorerPageTitle } from "./utils/getExplorerPageTitle";
import { RoundsGrid } from "./RoundsGrid";
import { getEnabledChains } from "../../app/chainConfig";
import { useMemo } from "react";
import { getWhitelistedPrograms } from "common";

const ExploreRoundsPage = () => {
const [params] = useSearchParams();
const filter = getRoundSelectionParamsFromUrlParams(params);

// Pass the filter from the search params and build the graphql query
const rounds = useFilterRounds(filter, getEnabledChains());
const rounds = useFilterRounds(filter, getEnabledChains(), true);

const publicRounds = useMemo(() => rounds.data?.filter(round => (round.roundMetadata && round.roundMetadata.roundType) && round.roundMetadata.roundType?.toLowerCase() !== "private"), [rounds]);
const publicRounds = useMemo(
() =>
rounds.data?.filter(
(round) =>
round.roundMetadata &&
round.roundMetadata.roundType &&
round.roundMetadata.roundType?.toLowerCase() !== "private"
),
[rounds]
);
rounds.data = publicRounds;

const sectionTitle = getExplorerPageTitle(filter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ import { CollectionsGrid } from "../collections/CollectionsGrid";
const LandingPage = () => {
const activeRounds = useFilterRounds(
ACTIVE_ROUNDS_FILTER,
getEnabledChains()
getEnabledChains(),
true
);
const roundsEndingSoon = useFilterRounds(
ROUNDS_ENDING_SOON_FILTER,
getEnabledChains()
getEnabledChains(),
true
);

const filteredActiveRounds = useMemo(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ export const ROUNDS_ENDING_SOON_FILTER: RoundSelectionParams & {

export const useFilterRounds = (
where: RoundSelectionParams,
chains: TChain[]
chains: TChain[],
onlywWhitelistedPrograms?: boolean
): SWRResponse<RoundGetRound[]> => {
const chainIds =
where.network === undefined || where.network.trim() === ""
Expand Down Expand Up @@ -102,7 +103,7 @@ export const useFilterRounds = (
const orderBy =
where.orderBy === undefined ? "CREATED_AT_BLOCK_DESC" : where.orderBy;
const vars = { orderBy, filter };
return useRounds(vars, chainIds);
return useRounds(vars, chainIds, onlywWhitelistedPrograms);
};

const createRoundWhereFilter = (
Expand Down
60 changes: 40 additions & 20 deletions packages/round-manager/src/features/program/TabGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -312,31 +312,49 @@ export const TabGroup = () => {
aria-current={tab.name === currentTab ? "page" : undefined}
>
<span>{tab.name}</span>
{["Quadratic funding", "Direct grants"].includes(tab.name) &&
{["Quadratic funding", "Direct grants"].includes(
tab.name
) && (
<span
className={`py-1 px-2 mx-2 bg-${tab.name === "Quadratic funding" ? "green" : "yellow"}-100 rounded-full text-xs font-mono`}
>
{tab.name === "Quadratic funding" ? qfRounds.length : dgRounds.length}
{tab.name === "Quadratic funding"
? qfRounds.length
: dgRounds.length}
</span>
}
)}
</span>
))}
</div>
<div className="flex flex-row items-center">
{programToRender?.tags?.includes(getAlloVersion()) && (
<span
onClick={() => {
setIsModalOpen(true);
}}
className="flex flex-row justify-between items-center hover:shadow-md p-2 rounded-lg text-sm text-grey-500 font-mono ml-auto bg-yellow-100 cursor-pointer"
data-testid="create-round-small-link"
>
<PlusSmIcon
className="h-5 w-5 inline ml-1"
aria-hidden="true"
/>
<span className="mr-2">Create round</span>
</span>
<div className="flex flex-row items-center gap-2">
<span
onClick={() => {
setIsModalOpen(true);
}}
className="flex flex-row justify-between items-center hover:shadow-md p-2 rounded-lg text-sm text-grey-500 font-mono ml-auto bg-yellow-100 cursor-pointer"
data-testid="create-round-small-link"
>
<PlusSmIcon
className="h-5 w-5 inline ml-1"
aria-hidden="true"
/>
<span className="mr-2">Create round</span>
</span>
<span
onClick={() => {
window.open(
`https://docs.google.com/forms/d/e/1FAIpQLSeplytOjF6mbG51bLOccNMmxOUZlZIDQdyOOw3KiDu5VZkvmA/viewform?usp=pp_url&entry.658554959=${programToRender?.id}&entry.1289763714=${programToRender?.metadata?.name}`,
"_blank"
);
}}
className="flex flex-row justify-between items-center hover:shadow-md p-2 rounded-lg text-sm text-grey-500 font-mono ml-auto bg-blue-100 cursor-pointer"
data-testid="create-round-small-link"
>
<span className="mr-2">Request Explorer Listing</span>
</span>
</div>
)}
</div>
</nav>
Expand All @@ -355,17 +373,19 @@ export const TabGroup = () => {
<div className="md:mb-8">{dgRoundItems}</div>
</div>
)}
{ currentTab === "Settings" && (
<ViewManageProgram program={programToRender!} userAddress={address || "0x"} />
{currentTab === "Settings" && (
<ViewManageProgram
program={programToRender!}
userAddress={address || "0x"}
/>
)}
</div>
</div>
{isRoundsFetched &&
rounds.length === 0 &&
programToRender?.tags?.includes(getAlloVersion()) &&
currentTab !== "Settings" &&
noRoundsGroup
}
noRoundsGroup}
<Transition.Root show={isModalOpen} as={Fragment}>
<Dialog
as="div"
Expand Down

0 comments on commit 796571c

Please sign in to comment.