Skip to content

Commit

Permalink
fix: enable useRestricted() hook to work when no wallet is connected
Browse files Browse the repository at this point in the history
  • Loading branch information
LilaRest committed Apr 9, 2024
1 parent 9dd6f5e commit d2f59e6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
7 changes: 4 additions & 3 deletions src/app/api/aml/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import { isAddress } from "viem";

const restrictedCountriesCodes = ["US", "IR", "KP", "SY", "CU", "SD", "SO", "YE", "IQ", "LY", "VE"];

export const revalidate = 3600 * 24 * 7; // 1 week
// export const revalidate = 3600 * 24 * 7; // 1 week
export const revalidate = 0;

function sendSlackAlert(message: string) {
return fetch(env.AML_ALERT_WEBHOOK, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ text: `[FRONTEND] ${message}` }),
next: { revalidate: 3600 * 24 * 7 },
// next: { revalidate: 3600 * 24 * 7 },
});
}

Expand Down Expand Up @@ -54,7 +55,7 @@ export const GET = async (request: NextRequest) => {
blockchain: "Ethereum",
coin: "ALL",
}),
next: { revalidate: 3600 * 24 * 7 },
// next: { revalidate: 3600 * 24 * 7 },
});
const scoreChainRes = await scoreChainReq.json();

Expand Down
11 changes: 4 additions & 7 deletions src/hooks/useRestricted.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ const useRestricted = () => {

const updateRestrictionStatus = async () => {
setIsLoading(true);
const response = await fetch(`/api/aml?address=${account.address}`, {
next: { revalidate: 3600 * 24 * 7 },
const addressParam = account.address ? `?address=${account.address}` : "";
const response = await fetch(`/api/aml${addressParam}`, {
// next: { revalidate: 3600 * 24 * 7 },
});
if (!response.ok) console.error(`Error while fetching AML endpoint (${response.statusText})`);
else {
Expand All @@ -20,13 +21,9 @@ const useRestricted = () => {
};

useEffect(() => {
if (account.address) updateRestrictionStatus();
updateRestrictionStatus();
}, []);

// useEffect(() => {
// if (account.address) updateRestrictionStatus();
// }, [account.address]);

return { isRestricted, isLoading };
};

Expand Down

0 comments on commit d2f59e6

Please sign in to comment.