Skip to content

Commit

Permalink
perf: optimize AML endpoint caching
Browse files Browse the repository at this point in the history
  • Loading branch information
LilaRest committed Apr 10, 2024
1 parent 81645b0 commit 785f2c9
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
2 changes: 2 additions & 0 deletions src/app/api/aml/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ export const GET = async (request: NextRequest) => {
args: [address],
});

console.log(isSanctioned);

// If the wallet is sanctioned
if (isSanctioned) return NextResponse.json({ restricted: true });
}
Expand Down
14 changes: 7 additions & 7 deletions src/components/app/DepositDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ export const DepositDialog: FC<Props> = ({ children, underlyingSymbol, onOpenCha
});

// Refresh some data every 5 blocks
const queryKeys = [queryKey];
const { data: blockNumber } = useBlockNumber({ watch: true });
const queryClient = useQueryClient();
useEffect(() => {
if (blockNumber && blockNumber % 5n === 0n)
queryKeys.forEach((k) => queryClient.invalidateQueries({ queryKey: k }));
}, [blockNumber, ...queryKeys]);
// const queryKeys = [queryKey];
// const { data: blockNumber } = useBlockNumber({ watch: true });
// const queryClient = useQueryClient();
// useEffect(() => {
// if (blockNumber && blockNumber % 5n === 0n)
// queryKeys.forEach((k) => queryClient.invalidateQueries({ queryKey: k }));
// }, [blockNumber, ...queryKeys]);

// Fetch restriction status
const { isRestricted, isLoading: isRestrictionLoading } = useRestricted();
Expand Down
14 changes: 7 additions & 7 deletions src/components/app/WithdrawDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ export const WithdrawDialog: FC<Props> = ({ children, underlyingSymbol, onOpenCh
});

// Refresh some data every 5 blocks
const queryKeys = [queryKey];
const { data: blockNumber } = useBlockNumber({ watch: true });
const queryClient = useQueryClient();
useEffect(() => {
if (blockNumber && blockNumber % 5n === 0n)
queryKeys.forEach((k) => queryClient.invalidateQueries({ queryKey: k }));
}, [blockNumber, ...queryKeys]);
// const queryKeys = [queryKey];
// const { data: blockNumber } = useBlockNumber({ watch: true });
// const queryClient = useQueryClient();
// useEffect(() => {
// if (blockNumber && blockNumber % 5n === 0n)
// queryKeys.forEach((k) => queryClient.invalidateQueries({ queryKey: k }));
// }, [blockNumber, ...queryKeys]);

// Fetch restriction status
const { isRestricted, isLoading: isRestrictionLoading } = useRestricted();
Expand Down
3 changes: 2 additions & 1 deletion src/hooks/useRestricted.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ const useRestricted = () => {
setIsLoading(true);
const addressParam = account.address ? `?address=${account.address}` : "";
const response = await fetch(`/api/aml${addressParam}`, {
// next: { revalidate: 3600 * 24 * 7 },
cache: "force-cache",
next: { revalidate: 60 },
});
if (!response.ok) console.error(`Error while fetching AML endpoint (${response.statusText})`);
else {
Expand Down

0 comments on commit 785f2c9

Please sign in to comment.