Centralize HTTP/RPC calls with services layer architecture - #410
Merged
Mikey-222 merged 2 commits intoAug 30, 2026
Merged
Conversation
added 2 commits
August 29, 2026 21:25
|
@Mainnet-ops Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description: This PR abstracts all external HTTP requests and blockchain RPC calls into a dedicated API service layer to centralize error handling and improve maintainability.
Changes Made
✅ Created Services Directory (src/services/)
api.ts: Core API service with standardized error handling, timeout/retry logic, and interceptors
preferences.ts: User preferences service for server/localStorage sync
responderStatus.ts: Responder availability status management
feedback.ts: Feedback submission with validation
zkProver.ts: ZK proof generation and blockchain RPC service
index.ts: Centralized exports for all services
✅ Migrated All Fetch Calls
Updated
Help.tsx
to use services instead of direct fetch calls
Replaced scattered fetch calls with service methods:
Preferences API calls → preferencesService
Responder status calls → responderStatusService
Feedback submission → feedbackService
✅ Added Standardized Error Handling
Global error interceptors for consistent error logging
Configurable retry logic with exponential backoff
Timeout handling for all HTTP requests
Normalized error responses across all API calls
✅ Updated Documentation
Added comprehensive services layer documentation to README.md
Updated project structure to reflect new services directory
Added usage examples and API documentation
Key Features
Centralized Error Handling: All API errors are processed consistently with retry logic
Maintainability: API logic is abstracted into reusable service classes
Testability: Services can be easily mocked for unit testing
Consistency: All HTTP requests follow the same pattern with standardized configurations
Observability: Interceptors provide hooks for monitoring and logging
Technical Details
Services use singleton pattern for easy access
Configurable timeout, retry, and retry delay settings
Supports request/response interceptors for custom logic
TypeScript interfaces for all service responses
Automatic JSON parsing and error handling
Migration Impact
No breaking changes: Existing functionality preserved
Improved error recovery: Network errors automatically retried
Better developer experience: Consistent API patterns across codebase
Easier testing: Services can be mocked for unit tests
Files Changed
src/services/api.ts
src/services/zkProver.ts
src/services/responderStatus.ts
src/services/preferences.ts
src/services/feedback.ts
src/services/index.ts
src/pages/Help.tsx
README.md
Testing
All existing functionality continues to work
Services handle edge cases (network errors, timeouts, server errors)
Error recovery logic tested with simulated failures
This PR addresses the issue of scattered fetch calls by providing a centralized, maintainable services layer that follows best practices for API abstraction and error handling in React applications.
Closes #75
Closes #76
Closes #74
Closes #73