Skip to content

Conversation

@sstefdev
Copy link
Contributor

@sstefdev sstefdev commented Nov 18, 2024

Fixes: PR

Problem

The Invoice Dashboard occasionally displays non-checksummed Ethereum addresses, which can lead to inconsistencies and reduced clarity. This issue arises because addresses retrieved from IPFS may be in lowercase.

Changes Made

  • Updated logic in the Invoice Dashboard to convert and display Ethereum addresses in checksummed format.
  • Modified the Request creation process to ensure addresses are stored in checksummed format by default.

Summary by CodeRabbit

  • New Features

    • Enhanced address validation for Ethereum addresses in invoice creation and dashboard functionalities.
    • Improved formatting of Ethereum addresses to ensure valid checksum representation.
  • Bug Fixes

    • Address handling errors are now logged for better troubleshooting.
  • Documentation

    • Updated method signatures to reflect changes in address processing logic.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 18, 2024

Walkthrough

The pull request introduces modifications to the prepareRequestParams function in the prepareRequest.ts file, enhancing Ethereum address validation by utilizing the getAddress function for several address fields. The formatAddress function in formatAddress.ts has also been updated to incorporate address validation and formatting improvements, ensuring that a valid checksum address is returned. Both functions maintain their overall structure and control flow, focusing on improved address handling without altering their parameters or return types.

Changes

File Path Change Summary
packages/create-invoice-form/src/lib/utils/prepareRequest.ts Updated prepareRequestParams to use getAddress for validating creatorId, payerAddress, payeeAddress, and address. Import statement for getAddress added.
packages/invoice-dashboard/src/utils/formatAddress.ts Modified formatAddress to use getAddress for converting addresses to checksum format, replacing previous slicing logic and retaining error handling.

Possibly related PRs

  • Fix : generate pdf invoices correctly #119: The changes in this PR also modify the prepareRequestParams function in prepareRequest.ts, enhancing the handling of currency types and improving the request parameters, which is closely related to the address validation improvements made in the main PR.

Suggested reviewers

  • rodrigopavezi
  • aimensahnoun
  • MantisClone

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.

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.

@sstefdev sstefdev self-assigned this Nov 18, 2024
@sstefdev sstefdev changed the title fix: added formatting to checksum addresses Added formatting to checksum addresses Nov 18, 2024
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 (3)
packages/invoice-dashboard/src/utils/formatAddress.ts (2)

1-2: Consider consolidating address validation logic

The code currently uses both checkAddress from shared utils and getAddress from viem for validation. Since getAddress already performs address validation and checksumming, we could simplify the code by removing the redundant check.

-import { checkAddress } from "@requestnetwork/shared-utils/checkEthAddress";

-  if (!checkAddress(address)) {
-    console.error("Invalid address!");
-  }
+  try {
+    const checksumAddress = getAddress(address);
+    return `${checksumAddress.slice(0, first)}...${checksumAddress.slice(-last)}`;
+  } catch (error) {
+    console.error("Invalid address!", error);
+    return address;
+  }

Line range hint 8-11: Improve error handling for invalid addresses

The current implementation logs an error but continues execution, which could lead to runtime errors if getAddress receives an invalid address. Consider implementing proper error handling with a fallback behavior.

-  if (!checkAddress(address)) {
-    console.error("Invalid address!");
-  }
-
-  const checksumAddress = getAddress(address);
+  try {
+    const checksumAddress = getAddress(address);
+    return `${checksumAddress.slice(0, first)}...${checksumAddress.slice(-last)}`;
+  } catch (error) {
+    console.error("Invalid address:", error);
+    return address; // Return original address as fallback
+  }
packages/create-invoice-form/src/lib/utils/prepareRequest.ts (1)

Ethereum address checksumming needs to be applied consistently

The codebase has inconsistent handling of Ethereum addresses. While the reviewed file correctly uses getAddress for checksumming, there are other instances that need attention:

  • packages/payment-widget/src/lib/utils/request.ts: Uses raw addresses without checksumming for sellerAddress, payerAddress, and feeAddress
  • shared/utils/initCurrencyManager.ts: Uses toLowerCase() for address comparison instead of proper checksumming
  • shared/utils/formatAddress.ts: Some instances use raw addresses without checksumming
  • shared/utils/getCurrency.ts: Uses raw address from currency.value without checksumming
🔗 Analysis chain

Line range hint 1-127: Verify consistent address handling across the codebase

Let's ensure all Ethereum addresses in the codebase are handled consistently with checksumming.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for other potential Ethereum address fields that might need checksumming

# Look for potential address fields or variables
rg -i "address|ethereum|0x" --type ts

# Look for direct address assignments without getAddress
ast-grep --pattern 'value: $address'

# Look for other instances where addresses might be used
rg -i "type.*ethereum.*address" --type ts

Length of output: 12321

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 94f6f0d and 0641479.

📒 Files selected for processing (2)
  • packages/create-invoice-form/src/lib/utils/prepareRequest.ts (4 hunks)
  • packages/invoice-dashboard/src/utils/formatAddress.ts (2 hunks)
🔇 Additional comments (2)
packages/create-invoice-form/src/lib/utils/prepareRequest.ts (2)

1-1: LGTM! Appropriate use of viem's getAddress

The addition of getAddress from viem is the correct choice for implementing EIP-55 checksum validation.


37-37: LGTM! Consistent address checksumming

The changes correctly apply checksumming to all Ethereum addresses in the request parameters, ensuring consistency throughout the system.

Also applies to: 41-41, 52-52, 125-125

@sstefdev sstefdev merged commit 949d045 into main Nov 19, 2024
1 check passed
@sstefdev sstefdev deleted the 160-display-checksummed-addresses-in-the-invoice-dashboard-write-checksummed-addresses-when-creating-requests-in-create-request-form branch November 19, 2024 13:01
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.

Display checksummed addresses in the Invoice Dashboard. Write checksummed addresses when creating Requests in Create Request Form

3 participants