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

feat(spaceward): technical debt #868

Merged
merged 6 commits into from
Sep 20, 2024
Merged

feat(spaceward): technical debt #868

merged 6 commits into from
Sep 20, 2024

Conversation

alex-nax
Copy link
Contributor

@alex-nax alex-nax commented Sep 19, 2024

Summary by CodeRabbit

Release Notes

  • New Features

    • Expanded support for additional Ethereum-compatible chains: Astar, Avalanche, Ethereum Classic, and Polygon.
    • Introduced a new snapVersion constant for enhanced environment configuration.
    • Added a new function to generate balance query keys for improved consistency.
  • Improvements

    • Enhanced transaction handling for Ethereum and Cosmos actions to ensure balance updates post-transaction.
    • Streamlined Cosmos RPC client management with React Query for better performance.
  • UI Changes

    • Updated button label in the MetaMask Snap installation process for clarity.
    • Improved presentation of asset chain names in the Asset Selector component.
  • Bug Fixes

    • Noted potential issues with balance fetching on the Assets page for future attention.

@alex-nax alex-nax marked this pull request as draft September 19, 2024 13:49
Copy link
Contributor

coderabbitai bot commented Sep 19, 2024

Walkthrough

Walkthrough

The changes involve multiple updates across various files in the spaceward project, focusing on enhancing support for additional blockchain networks, particularly Ethereum-compatible chains. Key modifications include the addition of new constants for environment settings, improvements in handling Ethereum and Cosmos transactions, and the restructuring of hooks for managing Cosmos RPC clients. Additionally, several formatting adjustments and minor logical updates were made to improve code clarity and maintainability.

Changes

File Path Change Summary
spaceward/src/config/tokens.ts Removed commented-out TODO items for blockchain networks; updated _ENABLED_ETH_CHAINS to include Astar, Avalanche, Ethereum Classic, and Polygon.
spaceward/src/env.ts Added a new constant snapVersion derived from an environment variable or defaulting to "0.1.5".
spaceward/src/features/actions/StatusSidebar.tsx Introduced useQueryClient from @tanstack/react-query and modified functions to utilize the query client for Ethereum and Cosmos actions.
spaceward/src/features/actions/util.ts Enhanced handleEth and handleCosmos functions by adding a queryClient parameter to invalidate balance queries post-transaction.
spaceward/src/features/assets/hooks.ts Replaced useEffect with useQuery for managing Cosmos RPC clients, simplifying state management and error handling.
spaceward/src/features/assets/queries.ts Introduced getBalanceQueryKey function for generating query keys for balance queries, enhancing consistency.
spaceward/src/features/metamask/InstallMetaMaskSnapButton.tsx Updated button label from "Reinstall snap" to "Update snap" based on isReconnect prop.
spaceward/src/features/modals/AssetSelector.tsx Made formatting adjustments for better readability and presentation, including wrapping item.chainName in a <span> for CSS styling.
spaceward/src/hooks/useMetaMaskRequestSnap.ts Changed version parameter to have a default value of env.snapVersion, making it required.
spaceward/src/lib/eth/constants.ts Added new entries for Ethereum Classic and Astar in ETH_CHAIN_CONFIG, specified tokens for existing networks, and updated ETH_CHAINID_MAP.
spaceward/src/lib/metamask.ts Made formatting adjustments and minor logical modifications, including updating string comparisons to use double quotes.
spaceward/src/pages/Assets.tsx Added a comment in AssetsPage regarding potential issues with fetching balances, noting discrepancies in behavior compared to the receive modal.
spaceward/entrypoint.sh Added a call to replace_var for the WARDEN_SNAP_VERSION variable in the entrypoint script.

Possibly related PRs

Suggested labels

docs, wardenjs


Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 15b522a and 5c14d6d.

Files selected for processing (1)
  • spaceward/entrypoint.sh (1 hunks)
Additional comments not posted (1)
spaceward/entrypoint.sh (1)

31-31: LGTM!

The addition of the replace_var call for WARDEN_SNAP_VERSION is consistent with the existing pattern and looks good.

Please ensure that:

  1. The WARDEN_SNAP_VERSION environment variable is properly set in the deployment configuration or environment.
  2. The %WARDEN_SNAP_VERSION% placeholder is used correctly in the relevant JavaScript files.

You can use the following commands to verify:

Verification successful

Verification successful: WARDEN_SNAP_VERSION usage is correct and necessary

The addition of WARDEN_SNAP_VERSION to the replace_var calls in spaceward/entrypoint.sh is correct and necessary for the proper functioning of the application. Here's why:

  1. The VITE_WARDEN_SNAP_VERSION environment variable is used in spaceward/src/env.ts with a fallback value.
  2. The Dockerfile sets Vite environment variables using %VARIABLE_NAME% placeholders.
  3. The replace_var function in entrypoint.sh replaces these placeholders with actual environment variable values.

This change ensures that the WARDEN_SNAP_VERSION value is properly propagated to the application's environment, maintaining consistency with other Vite-related variables.

Scripts executed

The following scripts were executed for the analysis:

Script:

# Check if WARDEN_SNAP_VERSION is set in the environment
echo $WARDEN_SNAP_VERSION

# Search for the usage of %WARDEN_SNAP_VERSION% in JavaScript files
rg --type js '%WARDEN_SNAP_VERSION%'

Length of output: 44


Script:

#!/bin/bash
# Search for any mentions of WARDEN_SNAP_VERSION in the entire codebase
rg "WARDEN_SNAP_VERSION"

# Check for configuration files that might mention this variable
fd -e yaml -e json -e env | xargs rg "WARDEN_SNAP_VERSION"

# Look for similar variable replacements in JavaScript files
rg --type js "%[A-Z_]+%"

Length of output: 261


Script:

#!/bin/bash
# Search for usage of VITE_WARDEN_SNAP_VERSION in the codebase
rg "VITE_WARDEN_SNAP_VERSION"

# Check for other Vite-related environment variables
rg "VITE_[A-Z_]+"

# Investigate the replace_var function in entrypoint.sh
rg -A 10 "replace_var\(\)" spaceward/entrypoint.sh

Length of output: 2650


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>, please review it.
    -- 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    -- @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.

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

Hey @alex-nax and thank you for opening this pull request! 👋🏼

It looks like you forgot to add a changelog entry for your changes. Make sure to add a changelog entry in the 'CHANGELOG.md' file.

Copy link

vercel bot commented Sep 19, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
warden-help-center ⬜️ Ignored (Inspect) Visit Preview Sep 20, 2024 10:09am

@alex-nax alex-nax marked this pull request as ready for review September 20, 2024 10:00
Copy link
Contributor

@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

Outside diff range and nitpick comments (4)
spaceward/src/pages/Assets.tsx (1)

53-54: Excellent TODO comment for tracking the balance fetching issue.

The comment provides good context about the inconsistency in fetching balances between this page and the receive modal. It also suggests a possible cause to investigate.

Consider creating a GitHub issue to track the resolution of this bug. This will ensure it gets the necessary attention and is not forgotten. Let me know if you would like me to create the issue for you.

spaceward/src/features/assets/hooks.ts (2)

35-35: Offer assistance to implement client health check.

There's a TODO comment to implement client health checks. Ensuring the clients are healthy before usage can improve reliability.

Would you like me to help implement the client health check function or open a new GitHub issue to track this task?


70-70: Remove unnecessary continue statement to improve code clarity.

The continue statement at line 70 is redundant because the code will naturally proceed to the next iteration of the loop after the catch block. Removing it simplifies the code without affecting functionality.

Apply this diff to remove the unnecessary continue statement:

-	continue;
Tools
Biome

[error] 70-70: Unnecessary continue statement

Unsafe fix: Delete the unnecessary continue statement

(lint/correctness/noUnnecessaryContinue)

spaceward/src/features/actions/util.ts (1)

362-365: Address the TODO: Implement a timeout for transaction confirmation.

There is a TODO comment suggesting the addition of a timeout mechanism because WalletConnect with Cosmos does not wait for the transaction result. Implementing a timeout can help handle cases where transaction confirmation takes too long or doesn't return.

Would you like assistance in implementing the timeout mechanism to improve transaction handling reliability?

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between f82a940 and 15b522a.

Files selected for processing (12)
  • spaceward/src/config/tokens.ts (1 hunks)
  • spaceward/src/env.ts (2 hunks)
  • spaceward/src/features/actions/StatusSidebar.tsx (3 hunks)
  • spaceward/src/features/actions/util.ts (5 hunks)
  • spaceward/src/features/assets/hooks.ts (1 hunks)
  • spaceward/src/features/assets/queries.ts (6 hunks)
  • spaceward/src/features/metamask/InstallMetaMaskSnapButton.tsx (1 hunks)
  • spaceward/src/features/modals/AssetSelector.tsx (2 hunks)
  • spaceward/src/hooks/useMetaMaskRequestSnap.ts (1 hunks)
  • spaceward/src/lib/eth/constants.ts (2 hunks)
  • spaceward/src/lib/metamask.ts (6 hunks)
  • spaceward/src/pages/Assets.tsx (2 hunks)
Additional context used
Biome
spaceward/src/features/assets/hooks.ts

[error] 70-70: Unnecessary continue statement

Unsafe fix: Delete the unnecessary continue statement

(lint/correctness/noUnnecessaryContinue)

Additional comments not posted (30)
spaceward/src/hooks/useMetaMaskRequestSnap.ts (1)

16-16: LGTM! Verify the impact of the change on the codebase.

The change to make the version parameter required with a default value improves code clarity and maintainability. It ensures a consistent value for the version parameter, either from the environment variable or explicitly provided.

To ensure this change doesn't break existing code, run the following script to search for invocations of useMetaMaskRequestSnap and verify that they provide a version argument or can rely on the default value:

Verification successful

Verification successful: Change is safe and improves code consistency

The modification to useMetaMaskRequestSnap in spaceward/src/hooks/useMetaMaskRequestSnap.ts is verified to be safe and doesn't negatively impact the codebase. The function is used in two other files (AddToMetaMaskButton.tsx and InstallMetaMaskSnapButton.tsx), and in both cases, it's called without arguments. This usage remains valid with the new default value for the version parameter.

  • The change improves code consistency by ensuring version always has a value.
  • Existing code using useMetaMaskRequestSnap doesn't need to be modified.
  • The default value env.snapVersion will be used when no argument is provided.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all invocations of `useMetaMaskRequestSnap` provide a `version` argument or can rely on the default value.

# Test: Search for the function usage. Expect: No occurrences of `useMetaMaskRequestSnap` without a `version` argument, unless the default value is acceptable.
rg --type typescript -A 5 $'useMetaMaskRequestSnap'

Length of output: 85


Script:

#!/bin/bash
# Description: Search for usage of useMetaMaskRequestSnap in TypeScript files

# Find all TypeScript files and search for useMetaMaskRequestSnap
fd -e ts -e tsx | xargs rg -n -A 5 'useMetaMaskRequestSnap'

Length of output: 2761

spaceward/src/features/metamask/InstallMetaMaskSnapButton.tsx (1)

41-41: LGTM!

The change to conditionally render the button text based on the isReconnect prop is correct and aligns with the component's purpose.

spaceward/src/env.ts (2)

13-14: LGTM!

The addition of the snapVersion constant is a good way to make the snap version configurable via an environment variable. The fallback default value ensures a version is always available.


39-39: LGTM!

Including the snapVersion constant in the exported env object is consistent with the other environment configuration options and makes it conveniently accessible to other parts of the codebase.

spaceward/src/lib/eth/constants.ts (6)

18-21: LGTM!

The addition of the Ethereum Classic network configuration looks good. The RPC URLs and token symbol are correctly specified, maintaining consistency with the existing structure.


24-24: LGTM!

Specifying the token symbol "MATIC" for the Polygon network is accurate and maintains consistency with the existing structure.


28-31: LGTM!

The addition of the Astar network configuration looks good. The RPC URLs and token symbol are correctly specified, maintaining consistency with the existing structure.


37-40: LGTM!

Specifying the token symbol "AVAX" for the Avalanche network is accurate and maintains consistency with the existing structure.


61-61: LGTM!

The addition of the mapping for Ethereum Classic looks good. The chain ID and name are correctly specified, maintaining consistency with the existing structure.


65-65: LGTM!

The addition of the mapping for Astar looks good. The chain ID and name are correctly specified, maintaining consistency with the existing structure.

spaceward/src/lib/metamask.ts (6)

1-1: LGTM!

Moving the env import to the top of the file is a good practice for organizing imports.


28-28: LGTM!

Changing the method string to use double quotes enhances consistency in string formatting.


58-58: LGTM!

Changing the event string to use double quotes enhances consistency in string formatting.


76-76: LGTM!

Changing the condition and event strings to use double quotes enhances consistency in string formatting.

Also applies to: 81-81, 83-83, 94-94


133-133: LGTM!

Changing the string comparison to use double quotes enhances consistency in string formatting. The function logic remains unchanged.


136-138: LGTM!

The change introduces a more explicit conditional structure to the return value of the shouldDisplayReconnectButton function. The logic is correct and enhances the readability of the function.

spaceward/src/config/tokens.ts (2)

221-222: LGTM!

The addition of Astar and Avalanche chains to the _ENABLED_ETH_CHAINS array is consistent with the PR objective of enhancing support for additional Ethereum-compatible chains. The changes look good.


225-228: Looks good!

The addition of Ethereum Classic and Polygon chains to the _ENABLED_ETH_CHAINS array aligns with the PR objective of expanding support for Ethereum-compatible chains. The changes are implemented correctly.

spaceward/src/features/modals/AssetSelector.tsx (2)

285-292: LGTM!

The formatting change improves the readability of the calculation without altering the logic.


306-311: LGTM!

The introduction of the <span> element with text overflow handling classes improves the presentation of the chain name within a constrained width. This change ensures that the chain name is displayed properly and truncated with an ellipsis if it exceeds the maximum width.

spaceward/src/features/actions/StatusSidebar.tsx (3)

23-23: LGTM!

The import statement for useQueryClient is correctly added.


47-47: LGTM!

The queryClient constant is correctly initialized using the useQueryClient hook.


312-312: Verify the handleEth and handleCosmos function implementations.

The queryClient is correctly passed as an additional argument to the handleEth and handleCosmos functions. This change allows these functions to utilize the queryClient for interacting with the server state.

Please ensure that the handleEth and handleCosmos function implementations have been updated to handle the additional queryClient argument.

Run the following script to verify the function usage:

Also applies to: 314-314

Verification successful

Changes implemented correctly, queryClient parameter added as requested.

The handleEth and handleCosmos functions in spaceward/src/features/actions/StatusSidebar.tsx have been updated to include the queryClient parameter as requested in the review comment. The changes are implemented on lines 312 and 314:

res = await handleEth({ action: item, w, queryClient });
res = await handleCosmos({ action: item, w, walletManager, queryClient });

These functions are imported from ./util, and their declarations can be found in spaceward/src/features/actions/util.ts. While we don't have the full function signatures, the consistent usage of the queryClient parameter suggests that the implementations have been updated accordingly.

The changes appear to be correctly implemented across the relevant files, addressing the concerns raised in the original review comment.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify `handleEth` and `handleCosmos` function implementations handle the additional `queryClient` argument.

# Test 1: Search for the `handleEth` function implementation.
# Expect: The function signature should include the `queryClient` argument.
ast-grep --lang typescript --pattern $'function handleEth($_) {
  $$$
}'

# Test 2: Search for the `handleCosmos` function implementation.
# Expect: The function signature should include the `queryClient` argument.
ast-grep --lang typescript --pattern $'function handleCosmos($_) {
  $$$
}'

Length of output: 150


Script:

#!/bin/bash
# Description: Perform a comprehensive search for `handleEth` and `handleCosmos` functions

# Search for handleEth function
echo "Searching for handleEth function:"
rg "handleEth\s*=?\s*(\(|async).*\{" --type ts --type tsx -A 5

echo "\n---\n"

# Search for handleCosmos function
echo "Searching for handleCosmos function:"
rg "handleCosmos\s*=?\s*(\(|async).*\{" --type ts --type tsx -A 5

echo "\n---\n"

# Search for files containing both function names
echo "Files containing both handleEth and handleCosmos:"
rg -l "handleEth.*handleCosmos" --type ts --type tsx

echo "\n---\n"

# List all TypeScript files in the project
echo "All TypeScript files in the project:"
fd -e ts -e tsx

Length of output: 25442


Script:

#!/bin/bash
# Description: Search for handleEth and handleCosmos functions in relevant files

# Search for handleEth function in the actions directory
echo "Searching for handleEth function:"
rg "handleEth\s*=?\s*(\(|async).*\{" spaceward/src/features/actions/ --type ts --type tsx -A 5

echo "\n---\n"

# Search for handleCosmos function in the actions directory
echo "Searching for handleCosmos function:"
rg "handleCosmos\s*=?\s*(\(|async).*\{" spaceward/src/features/actions/ --type ts --type tsx -A 5

echo "\n---\n"

# List all TypeScript files in the actions directory
echo "TypeScript files in the actions directory:"
fd -e ts -e tsx . spaceward/src/features/actions/

echo "\n---\n"

# Search for any mentions of handleEth or handleCosmos in the actions directory
echo "Files mentioning handleEth or handleCosmos:"
rg -l "handleEth|handleCosmos" spaceward/src/features/actions/ --type ts --type tsx

Length of output: 1148


Script:

#!/bin/bash
# Description: Search for handleEth and handleCosmos functions in specific files

# Function to search for handleEth and handleCosmos
search_functions() {
    echo "Searching in $1:"
    cat "$1" | grep -n -E "handleEth|handleCosmos"
    echo "---"
}

# Search in StatusSidebar.tsx (focus file)
search_functions "spaceward/src/features/actions/StatusSidebar.tsx"

# Search in other relevant files
search_functions "spaceward/src/features/actions/Action.tsx"
search_functions "spaceward/src/features/actions/Actions.tsx"
search_functions "spaceward/src/features/actions/ApproveSidebar.tsx"
search_functions "spaceward/src/features/actions/hooks.ts"
search_functions "spaceward/src/features/actions/util.ts"

# Display the content of StatusSidebar.tsx around lines 312-314
echo "Content of StatusSidebar.tsx around lines 312-314:"
cat "spaceward/src/features/actions/StatusSidebar.tsx" | sed -n '307,319p'

Length of output: 2792

spaceward/src/features/assets/queries.ts (4)

55-61: LGTM!

The getBalanceQueryKey function is a good addition that centralizes the logic for generating balance query keys. It enhances consistency and handles the case when the address is not provided.


71-75: Looks good!

The update to the queryKey for cosmosBalancesQuery to use the new getBalanceQueryKey function is consistent and handles the case when the address is not provided.


189-192: Looks good!

The update to the queryKey for eip155NativeBalanceQuery to use the new getBalanceQueryKey function, followed by the string "native", is consistent and handles the case when the address is not provided.


273-276: Looks good!

The update to the queryKey for eip155ERC20BalanceQuery to use the new getBalanceQueryKey function, followed by a string with the token prefixed by "erc20:", is consistent and handles the case when the address is not provided.

spaceward/src/features/actions/util.ts (3)

135-143: Implementation of MsgUpdateSpaceResponse handler is correct.

The getStatus function for MsgUpdateSpaceResponse appropriately returns pending: false, error: false, and done: true, indicating a successful completion without errors.


Line range hint 298-308:
Ensure all calls to handleCosmos are updated with the new queryClient parameter.

The handleCosmos function signature now includes queryClient. Please verify that all usages of this function are updated accordingly to include the new parameter.

You can run the following script to find any calls to handleCosmos missing the queryClient parameter:

#!/bin/bash
# Description: Find all calls to `handleCosmos` and check if `queryClient` is included.

# Searching for calls to `handleCosmos` without `queryClient`
rg --type typescript 'handleCosmos\s*\(\s*\{[^}]*\}' -l | xargs -I{} rg --type typescript -N 'handleCosmos\s*\(\s*\{(?!.*queryClient)[^}]*\}' {}

Line range hint 217-225:
Ensure all calls to handleEth are updated with the new queryClient parameter.

The handleEth function signature has been updated to include queryClient. Please verify that all invocations of this function have been updated to pass the queryClient parameter to prevent any runtime errors.

You can run the following script to check for any calls to handleEth missing the queryClient parameter:

Verification successful

All calls to handleEth have been updated with the new queryClient parameter.

Our verification process found only one call to handleEth in the entire codebase, located in spaceward/src/features/actions/StatusSidebar.tsx at line 312. This call already includes the queryClient parameter:

res = await handleEth({ action: item, w, queryClient });

No other calls to handleEth were found, so we can confidently say that all instances have been properly updated.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find all calls to `handleEth` and check if `queryClient` is included.

# Searching for calls to `handleEth` without `queryClient`
rg --type typescript 'handleEth\s*\(\s*\{[^}]*\}' -l | xargs -I{} rg --type typescript -N 'handleEth\s*\(\s*\{(?!.*queryClient)[^}]*\}' {}

Length of output: 185


Script:

#!/bin/bash
# Find TypeScript files and search for handleEth calls without queryClient

# Find all TypeScript files
fd -e ts -e tsx | xargs grep -n "handleEth[[:space:]]*([[:space:]]*{" | grep -v "queryClient"

Length of output: 93


Script:

#!/bin/bash
# Script 1: Search for the definition of handleEth
echo "Searching for handleEth definition:"
fd -e ts -e tsx | xargs grep -n "function handleEth"

# Script 2: Search for all calls to handleEth
echo "Searching for all handleEth calls:"
fd -e ts -e tsx | xargs grep -n "handleEth[[:space:]]*("

Length of output: 390

: endpoint.url,
});

clients.push([client, chainName]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Store created clients in rpcClients to enable caching.

Currently, the newly created clients are not stored in rpcClients, which means the caching mechanism is ineffective. Storing the clients will allow subsequent iterations to reuse existing clients, improving performance.

Apply this diff to store the clients in rpcClients:

	clients.push([client, chainName]);
+	rpcClients[chainName] = client;
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
clients.push([client, chainName]);
clients.push([client, chainName]);
rpcClients[chainName] = client;

Comment on lines +285 to +291
return provider.waitForTransaction(res.hash).then(() => {
queryClient.invalidateQueries({
queryKey: getBalanceQueryKey("eip155", chainName, "").slice(0, -1),
});

return true;
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Add error handling for transaction confirmation and query invalidation.

Currently, if provider.waitForTransaction(res.hash) or queryClient.invalidateQueries() throws an error, it might cause unhandled promise rejections. Consider adding error handling to manage potential issues during transaction confirmation or query invalidation.

You can modify the code as follows to include error handling:

 return provider.waitForTransaction(res.hash)
   .then(() => {
     queryClient.invalidateQueries({
       queryKey: getBalanceQueryKey("eip155", chainName, "").slice(0, -1),
     });
     return true;
+  })
+  .catch((error) => {
+    // Handle the error appropriately
+    console.error('Error during transaction confirmation or query invalidation:', error);
+    return false; // or rethrow the error as needed
   });
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
return provider.waitForTransaction(res.hash).then(() => {
queryClient.invalidateQueries({
queryKey: getBalanceQueryKey("eip155", chainName, "").slice(0, -1),
});
return true;
});
return provider.waitForTransaction(res.hash)
.then(() => {
queryClient.invalidateQueries({
queryKey: getBalanceQueryKey("eip155", chainName, "").slice(0, -1),
});
return true;
})
.catch((error) => {
// Handle the error appropriately
console.error('Error during transaction confirmation or query invalidation:', error);
return false; // or rethrow the error as needed
});

@jjheywood jjheywood merged commit 019809a into main Sep 20, 2024
16 checks passed
@jjheywood jjheywood deleted the bugfix-and-tech-debt branch September 20, 2024 10:14
@coderabbitai coderabbitai bot mentioned this pull request Oct 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants