Skip to content

Commit

Permalink
[ECO-2469] Remove galxe campaign fetch in allowlist checks (#398)
Browse files Browse the repository at this point in the history
  • Loading branch information
xbtmatt authored Nov 20, 2024
1 parent cf2afe6 commit 451cad5
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ export const createSession = async (address: AccountAddressString) => {

cookies().set(COOKIE_FOR_HASHED_ADDRESS, hashed, {
httpOnly: true,
secure: process.env.NODE_ENV === "production",
secure: process.env.NODE_ENV === "production" || process.env.VERCEL === "1",
maxAge: COOKIE_LENGTH,
path: "/",
});

cookies().set(COOKIE_FOR_ACCOUNT_ADDRESS, address, {
httpOnly: true,
secure: process.env.NODE_ENV === "production",
secure: process.env.NODE_ENV === "production" || process.env.VERCEL === "1",
maxAge: COOKIE_LENGTH,
path: "/",
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useAptos } from "context/wallet-context/AptosContextProvider";
import { useEffect, useState } from "react";
import { motion } from "framer-motion";
import { standardizeAddress, truncateAddress } from "@sdk/utils";
import { getVerificationStatus } from "./get-verification-status";
import { getIsOnCustomAllowlist } from "./get-verification-status";
import { EXTERNAL_LINK_PROPS } from "components/link";
import { emoji } from "utils";
import { Emoji } from "utils/emoji";
Expand All @@ -32,10 +32,7 @@ export const ClientVerifyPage = () => {
setCustomAllowlisted(false);
} else {
const address = standardizeAddress(account.address);
getVerificationStatus(address).then(({ galxe, customAllowlisted }) => {
setGalxe(galxe);
setCustomAllowlisted(customAllowlisted);
});
getIsOnCustomAllowlist(address).then((res) => setCustomAllowlisted(res));
}
}, [account, connected]);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
"use server";
import { isOnCustomAllowlist } from "lib/utils/allowlist";

import { isInGalxeCampaign, isOnCustomAllowlist } from "lib/utils/allowlist";

export async function getVerificationStatus(address: `0x${string}`) {
const [galxe, customAllowlisted] = await Promise.all([
isInGalxeCampaign(address),
isOnCustomAllowlist(address),
]);
return {
galxe,
customAllowlisted,
};
export async function getIsOnCustomAllowlist(address: `0x${string}`) {
return await isOnCustomAllowlist(address);
}
7 changes: 1 addition & 6 deletions src/typescript/frontend/src/lib/server-env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@ if (!process.env.HASH_SEED || process.env.HASH_SEED.length < 8) {
throw new Error("Environment variable HASH_SEED must be set and at least 8 characters.");
}

if (
IS_ALLOWLIST_ENABLED &&
typeof process.env.ALLOWLISTER3K_URL === "undefined" &&
typeof process.env.GALXE_CAMPAIGN_ID === "undefined"
) {
if (IS_ALLOWLIST_ENABLED && typeof process.env.ALLOWLISTER3K_URL === "undefined") {
throw new Error("Allowlist is enabled but no allowlist provider is set.");
}

Expand All @@ -38,7 +34,6 @@ if (GEOBLOCKING_ENABLED) {
}

export const ALLOWLISTER3K_URL: string | undefined = process.env.ALLOWLISTER3K_URL;
export const GALXE_CAMPAIGN_ID: string | undefined = process.env.GALXE_CAMPAIGN_ID;
export const REVALIDATION_TIME: number = Number(process.env.REVALIDATION_TIME);
export const VPNAPI_IO_API_KEY: string = process.env.VPNAPI_IO_API_KEY!;
export const PRE_LAUNCH_TEASER: boolean = process.env.PRE_LAUNCH_TEASER === "true";
Expand Down
44 changes: 3 additions & 41 deletions src/typescript/frontend/src/lib/utils/allowlist.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import "server-only";

import { IS_ALLOWLIST_ENABLED } from "lib/env";
import { ALLOWLISTER3K_URL, GALXE_CAMPAIGN_ID } from "lib/server-env";
import { ALLOWLISTER3K_URL } from "lib/server-env";

export const GALXE_URL = "https://graphigo.prd.galaxy.eco/query";

// Checks if the given address is allow listed either in Galxe or in Allowlister3000.
// Checks if the given address is allow listed in Allowlister3000.
//
// If IS_ALLOWLIST_ENABLED is not truthy, the function returns true.
//
Expand All @@ -19,45 +17,9 @@ export async function isAllowListed(addressIn: string): Promise<boolean> {
? (addressIn as `0x${string}`)
: (`0x${addressIn}` as const);

const [inCampaign, onAllowlist] = await Promise.all([
isInGalxeCampaign(address),
isOnCustomAllowlist(address),
]);
return inCampaign || onAllowlist;
return await isOnCustomAllowlist(address);
}

export const isInGalxeCampaign = async (address: `0x${string}`): Promise<boolean> => {
if (GALXE_CAMPAIGN_ID !== undefined) {
const condition = await fetch(GALXE_URL, {
method: "POST",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
},
body: JSON.stringify({
query: `{
campaign(id: "${GALXE_CAMPAIGN_ID}") {
whitelistInfo(address: "${address}") {
maxCount
usedCount
claimedLoyaltyPoints
currentPeriodMaxLoyaltyPoints
currentPeriodClaimedLoyaltyPoints
}
}
}`,
}),
})
.then((r) => r.json())
.then((data) => data.data.campaign && data.data.campaign.whitelistInfo.usedCount === 1);
if (condition) {
return true;
}
}

return false;
};

export const isOnCustomAllowlist = async (address: `0x${string}`): Promise<boolean> => {
if (ALLOWLISTER3K_URL !== undefined) {
const condition = await fetch(`${ALLOWLISTER3K_URL}/${address}`)
Expand Down

0 comments on commit 451cad5

Please sign in to comment.