Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor and Enhance Ethereum API Routes #156

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

CreeptoGengar
Copy link

Description

This pull request introduces key improvements and refactorings to the ethereum-data and get-transactions API routes, including:

1. Code Refinement

  • Improved readability by aligning variable names and comments.
  • Ensured consistent formatting throughout the codebase.

2. Enhanced Error Handling

  • Added validation to handle API errors more gracefully.
  • Introduced additional error checks for external API responses.

3. Optimization

  • Centralized configuration variables (e.g., START_BLOCK and cache durations) for better maintainability.
  • Standardized fetch calls to ensure cache settings are explicitly defined.

4. Bug Fixes

  • Resolved discrepancies in the response handling between ethereum-data and get-transactions routes.
  • Addressed potential runtime issues with etherscan API calls.

5. Environment Variables

  • Made use of NEXT_PUBLIC environment variables to enhance flexibility for deployments.

Files Updated

  1. app/api/ethereum-data/route.ts:

    • Added stricter response validation.
    • Improved handling of cache and response processing.
  2. app/api/get-transactions/route.ts:

    • Fixed endpoint construction and clarified transaction interface.

Impact

This update improves reliability, maintainability, and performance for fetching Ethereum-related data via the APIs.


Feel free to review and provide feedback. Maintainers are welcome to make edits to this branch.

These changes will improve:

- Code reliability: Added response status checks for the API.
- Readability: Enhanced the comment for the caching constant.
- Error handling: Introduced checks for errors in the API response.
- Accuracy of status codes: Implemented the use of 502 Bad Gateway for external API errors.
These changes improve the code as follows:

- Added a check for response.ok.
- Introduced the Transaction interface instead of using any.
- Moved the starting block number into a constant.
- Enhanced error handling with specific error messages.
- The code is now more type-safe.
Copy link

vercel bot commented Dec 27, 2024

@CreeptoGengar is attempting to deploy a commit to the Eclipse Labs Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant