Skip to content

Commit

Permalink
Merge pull request #71 from daqhris/dev-fixes
Browse files Browse the repository at this point in the history
Implement exponential backoff with jitter for POAP fetching to preven…
  • Loading branch information
daqhris authored Aug 15, 2024
2 parents e2ba478 + 95bb85c commit ee8a28d
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions components/EventAttendanceVerification.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,19 @@ const EventAttendanceProof: React.FC<EventAttendanceProofProps> = ({ 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));
}
}

Expand Down

0 comments on commit ee8a28d

Please sign in to comment.