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

Remove rpcs #220

Merged
merged 3 commits into from
Sep 5, 2024
Merged

Remove rpcs #220

merged 3 commits into from
Sep 5, 2024

Conversation

mvpoyatt
Copy link
Collaborator

@mvpoyatt mvpoyatt commented Sep 5, 2024

Summary by CodeRabbit

  • New Features

    • Introduced a new API endpoint for retrieving blockchain fee data based on the specified chain ID.
    • Enhanced configuration management by enforcing required environment variables for optimismRPC and baseRPC, eliminating fallback URLs.
  • Bug Fixes

    • Improved application reliability by ensuring that necessary environment variables must be defined before runtime, reducing potential errors.
  • Performance Improvements

    • Simplified fee data retrieval logic in the PacketDetails component, improving performance by reducing unnecessary API calls and dependencies.
    • Removed interval polling for transaction funding checks, optimizing resource usage.

Copy link

coderabbitai bot commented Sep 5, 2024

Walkthrough

The changes involve the handling of environment variables for the optimismRPC and baseRPC constants in the app/utils/chains/configs.ts file, where fallback URLs were removed in favor of direct assignment using the non-null assertion operator. Additionally, the PacketDetails component in app/(routes)/packets/packet-details.tsx was updated to use chain IDs instead of RPC URLs for fee calculations, and a new API endpoint for retrieving fee data was introduced in app/api/packets/fee-data/route.ts.

Changes

File Change Summary
app/utils/chains/configs.ts Modified optimismRPC and baseRPC to directly use environment variables with non-null assertion, removing fallback URLs.
app/(routes)/packets/packet-details.tsx Updated calcTxFunding to accept chainId instead of RPC URL, changed fee data fetching to an API call, and removed interval polling.
app/api/packets/fee-data/route.ts Introduced a new API endpoint for fetching fee data based on chainId, with error handling for invalid requests.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant PacketDetails
    participant FeeAPI

    User->>PacketDetails: Request funding information
    PacketDetails->>FeeAPI: Fetch fee data (chainId)
    FeeAPI-->>PacketDetails: Return fee data
    PacketDetails-->>User: Display funding information
Loading

Poem

🐰 In the meadow where I bound and leap,
Environment variables, I now keep!
No more fallback paths to make me weep,
Just clear chains that run so deep.
With every hop, I joyfully peep,
"Hooray for the changes, my heart will reap!" 🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 6ace938 and 6c8bf8a.

Files selected for processing (1)
  • app/utils/chains/configs.ts (1 hunks)

Comment on lines +12 to +13
let optimismRPC = process.env.OPTIMISM_RPC!;
let baseRPC = process.env.BASE_RPC!;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential risk of runtime errors due to non-null assertions.

The use of the non-null assertion operator (!) for optimismRPC and baseRPC assumes that these environment variables are always set. This change removes the previous safety net of fallback URLs and could lead to runtime errors if the environment variables are not set.

Consider adding error handling or documentation to ensure that these variables are set before deployment.


Consider adding runtime checks or fallback mechanisms.

The direct use of optimismRPC and baseRPC in the CHAIN_CONFIGS object without any checks could lead to failures if these environment variables are not set. This could compromise the application's robustness and lead to service disruptions.

Consider implementing runtime checks or fallback mechanisms within the CHAIN_CONFIGS object to handle cases where these variables might not be set.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 6c8bf8a and d778f7b.

Files selected for processing (2)
  • app/(routes)/packets/packet-details.tsx (3 hunks)
  • app/api/packets/fee-data/route.ts (1 hunks)
Additional context used
Biome
app/(routes)/packets/packet-details.tsx

[error] 190-190: Don't use 'Number' as a type.

Use lowercase primitives for consistency.
Safe fix: Use 'number' instead

(lint/complexity/noBannedTypes)

Additional comments not posted (6)
app/api/packets/fee-data/route.ts (5)

5-5: Clarify the use of the dynamic constant.

The constant dynamic is set to 'force-dynamic'. Please clarify its intended use, as it's not immediately clear from the context.


7-13: Good error handling for chainId.

The extraction and validation of chainId from the request URL are handled correctly, with appropriate error responses for invalid inputs.


15-23: Efficient loop for finding RPC URL.

The loop efficiently finds the RPC URL corresponding to the provided chainId and breaks immediately after finding a match, which is good for performance.


25-27: Appropriate error handling for missing RPC URL.

The function correctly handles the scenario where no RPC URL is found for the given chainId, returning a 404 error with a clear message.


29-32: Correct use of ethers library for fetching fee data.

The use of ethers.JsonRpcProvider to connect to the blockchain and fetch fee data is implemented correctly, with proper handling of asynchronous operations.

app/(routes)/packets/packet-details.tsx (1)

30-31: Verify the correctness of the chain ID usage.

The changes to use chain IDs instead of RPC URLs in the calcTxFunding function calls are aligned with the PR's objective to remove RPCs. Ensure that the chain IDs are correctly retrieved and used throughout the application.

Run the following script to verify the chain ID usage:

Verification successful

Chain ID Usage Verified

The usage of chainId in app/(routes)/packets/packet-details.tsx is consistent with the PR's objective to replace RPC URLs with chain IDs. The chainId is correctly utilized in the calcTxFunding function and API requests, confirming the correctness of the changes. No issues were found with the implementation.

  • app/(routes)/packets/packet-details.tsx: Correct usage of chainId in calcTxFunding and API calls.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the chain ID usage in the application.

# Test: Search for the chain ID usage. Expect: Only occurrences of the new chain ID usage.
rg --type typescript -A 5 $'chainId'

Length of output: 70


Script:

#!/bin/bash
# Description: Verify the chain ID usage in the application.

# Test: Search for the chain ID usage. Expect: Only occurrences of the new chain ID usage.
rg --type ts -A 5 'chainId'

Length of output: 30723

Comment on lines 190 to 196
async function calcTxFunding(chainId: Number, feesDeposited?: number, gasLimit?: number) {
if (!feesDeposited || !gasLimit) {
return 0;
}

const provider = new ethers.JsonRpcProvider(chainRpc)
const feeData = await provider.getFeeData();
const feeResponse = await fetch(`/api/packets/fee-data?chainId=${chainId}`, { cache: 'no-store' });
const feeData = await feeResponse.json();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct the type issue and approve the changes.

The function calcTxFunding has been updated to use a chain ID and fetch fee data from an API, aligning with the PR's objectives. However, the type 'Number' should be corrected to 'number' for consistency with TypeScript best practices.

Apply this diff to correct the type issue:

-async function calcTxFunding(chainId: Number, feesDeposited?: number, gasLimit?: number) {
+async function calcTxFunding(chainId: number, feesDeposited?: number, gasLimit?: number) {
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
async function calcTxFunding(chainId: Number, feesDeposited?: number, gasLimit?: number) {
if (!feesDeposited || !gasLimit) {
return 0;
}
const provider = new ethers.JsonRpcProvider(chainRpc)
const feeData = await provider.getFeeData();
const feeResponse = await fetch(`/api/packets/fee-data?chainId=${chainId}`, { cache: 'no-store' });
const feeData = await feeResponse.json();
async function calcTxFunding(chainId: number, feesDeposited?: number, gasLimit?: number) {
if (!feesDeposited || !gasLimit) {
return 0;
}
const feeResponse = await fetch(`/api/packets/fee-data?chainId=${chainId}`, { cache: 'no-store' });
const feeData = await feeResponse.json();
Tools
Biome

[error] 190-190: Don't use 'Number' as a type.

Use lowercase primitives for consistency.
Safe fix: Use 'number' instead

(lint/complexity/noBannedTypes)

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d778f7b and 53f8056.

Files selected for processing (1)
  • app/(routes)/packets/packet-details.tsx (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • app/(routes)/packets/packet-details.tsx

Copy link
Member

@dshiell dshiell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thx

@mvpoyatt mvpoyatt merged commit db7e9e2 into main Sep 5, 2024
5 checks passed
@mvpoyatt mvpoyatt deleted the mp/remove-rpcs branch September 5, 2024 16:04
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.

2 participants