Skip to content

Centralize HTTP/RPC calls with services layer architecture - #410

Merged
Mikey-222 merged 2 commits into
Hel-Phone:mainfrom
open-source-from-mainnet:feat/services-layer-centralization
Aug 30, 2026
Merged

Centralize HTTP/RPC calls with services layer architecture#410
Mikey-222 merged 2 commits into
Hel-Phone:mainfrom
open-source-from-mainnet:feat/services-layer-centralization

Conversation

@Mainnet-ops

Copy link
Copy Markdown

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

@drips-wave

drips-wave Bot commented Aug 29, 2026

Copy link
Copy Markdown

@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! 🚀

Learn more about application limits

@Mikey-222
Mikey-222 merged commit cd395a7 into Hel-Phone:main Aug 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants