Skip to content

Commit

Permalink
fix: added string check
Browse files Browse the repository at this point in the history
  • Loading branch information
RyRy79261 committed Oct 29, 2024
1 parent 8562329 commit e369b05
Showing 1 changed file with 27 additions and 19 deletions.
46 changes: 27 additions & 19 deletions src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,35 @@ export function middleware(request: NextRequest, event: NextFetchEvent) {
});

return new Promise((resolve) => {
publicClient
.readContract({
address: Celo.contracts.MentoGovernor.address,
abi: GovernorABI,
functionName: "proposals",
args: [BigInt(id)],
})
.then((proposal) => {
if (proposal) {
resolve(NextResponse.next());
} else {
try {
const parsedId = BigInt(id);

publicClient
.readContract({
address: Celo.contracts.MentoGovernor.address,
abi: GovernorABI,
functionName: "proposals",
args: [BigInt(parsedId)],
})
.then((proposal) => {
if (proposal) {
resolve(NextResponse.next());
} else {
const url = new URL("/", request.url);
console.log("Proposal not found, redirecting");
resolve(NextResponse.redirect(url.origin));
}
})
.catch((error) => {
console.log("Proposal not found on Celo chain, redirecting");
const url = new URL("/", request.url);
console.log("Proposal not found, redirecting");
resolve(NextResponse.redirect(url.origin));
}
})
.catch((error) => {
console.log("Proposal not found on Celo chain, redirecting");
const url = new URL("/", request.url);
resolve(NextResponse.redirect(url.origin));
});
});
} catch (error) {
console.log("Proposal ID not found, redirecting");
const url = new URL("/", request.url);
resolve(NextResponse.redirect(url.origin));
}
});
} else {
console.log("Proposal ID not found, redirecting");
Expand Down

0 comments on commit e369b05

Please sign in to comment.