From 95bb85c2d3f3acd0fdbaf499026a96a562606895 Mon Sep 17 00:00:00 2001 From: "devin-ai-integration[bot]" <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Thu, 15 Aug 2024 17:02:29 +0000 Subject: [PATCH] Implement exponential backoff with jitter for POAP fetching to prevent infinite loops. Improve user feedback during retry attempts. --- components/EventAttendanceVerification.tsx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/components/EventAttendanceVerification.tsx b/components/EventAttendanceVerification.tsx index 2b7399111..caa2ddf3f 100644 --- a/components/EventAttendanceVerification.tsx +++ b/components/EventAttendanceVerification.tsx @@ -111,15 +111,19 @@ const EventAttendanceProof: React.FC = ({ onVerified, } retries++; - if (retries === maxRetries) { + if (retries >= maxRetries) { setProofResult("Failed to fetch POAPs after multiple attempts. Please try again later."); setLocalPoaps([]); setMissingPoaps(eventIds); return; // Exit the retry loop after max retries } - // Wait for a short time before retrying - await new Promise(resolve => setTimeout(resolve, 1000 * retries)); // Exponential backoff + // Provide user feedback before retrying + setProofResult(`Retrying... Attempt ${retries + 1} of ${maxRetries}`); + + // Implement exponential backoff with jitter + const delay = Math.min(1000 * Math.pow(2, retries) + Math.random() * 1000, 10000); + await new Promise(resolve => setTimeout(resolve, delay)); } }