Skip to content

Conversation

@aimensahnoun
Copy link
Member

@aimensahnoun aimensahnoun commented Sep 2, 2024

Resolves #61 #108

This PR adds the following:

  • Fixes the use of deprecated currencyManager.from() to use either fromAddress() or getNativeCurrency() depending on the use-case

  • Enable the possibility to create and pay with native currencies by adding pn-eth-fee-proxy-contract

  • Adds all of the currencies that are supported by Payment Widget into the invoicing template to enable full interoperability

  • Custom currencies are now appended to the default currency array instead of overriding them.

  • Make sure that currencies are unique so we don't have duplicates in currency manager.

  • Enable switching to the newly added chains.

It might be worth to add a overrideDefaultCurrencies boolean as a prop in the future to allow users to override the default currencies still.

Screenshots:

CleanShot 2024-09-02 at 22 43 26

CleanShot 2024-09-02 at 22 43 42

CleanShot 2024-09-02 at 22 44 01

CleanShot 2024-09-02 at 22 44 16

CleanShot 2024-09-02 at 22 44 23

Summary by CodeRabbit

  • New Features

    • Enhanced currency handling for ERC20 tokens in invoice creation and dashboard components.
    • Introduced new utility function for streamlined currency retrieval based on type.
    • Added support for new stablecoin identifiers in the payment widget.
    • Expanded the range of supported currencies in the currency management system.
  • Bug Fixes

    • Improved robustness in handling request data and approval checks based on currency type.
  • Documentation

    • Updated comments and structure for better clarity and maintainability across components.
  • Chores

    • Restructured import statements for better organization and readability throughout the codebase.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 2, 2024

Walkthrough

The changes across multiple files enhance the handling of different currency types, particularly focusing on ERC20 tokens and Ethereum. The logic for preparing request parameters has been refined, and new utility functions have been introduced to improve currency management. Additionally, the structure of components has been reorganized for better clarity, and new currency identifiers have been added to support transactions involving stablecoins on the Sepolia network.

Changes

Files Change Summary
packages/create-invoice-form/src/lib/utils/prepareRequest.ts Improved currency handling logic for ERC20 and Ethereum, modified request structure for clarity.
packages/invoice-dashboard/src/lib/dashboard/invoice-view.svelte Reorganized imports, updated currency retrieval logic, refined approval checks based on currency type.
packages/invoice-dashboard/src/lib/view-requests.svelte Restructured imports, enhanced activeRequest variable, added reactive statement for processed requests.
packages/invoice-dashboard/src/utils/getCurrency.ts Introduced getCurrencyFromManager function for improved currency retrieval based on type.
packages/payment-widget/src/lib/utils/currencies.ts Added new stablecoin identifiers for Sepolia network.
packages/payment-widget/src/lib/utils/request.ts Modified prepareRequestParameters to conditionally set currency representation based on type.
shared/utils/initCurrencyManager.ts Streamlined currency initialization logic and expanded default currency IDs.

Assessment against linked issues

Objective Addressed Explanation
Support ETH (native) payments on all supported chains ( #61 )
Add REQ on Ethereum as part of the default list ( #61 ) REQ support is not mentioned in the changes.

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.
Early access features: disabled

We are currently testing the following features in early access:

  • Anthropic claude-3-5-sonnet for code reviews: Anthropic claims that the new Claude model has stronger code understanding and code generation capabilities than their previous models. Note: Our default code review model was also updated late last week. Please compare the quality of the reviews between the two models by toggling the early access feature.

Note:

  • You can enable or disable early access features from the CodeRabbit UI or by updating the CodeRabbit configuration file.
  • Please join our Discord Community to provide feedback and report issues on the discussion post.

@aimensahnoun aimensahnoun self-assigned this Sep 2, 2024
@aimensahnoun aimensahnoun requested review from MantisClone and sstefdev and removed request for sstefdev September 2, 2024 12:15
@aimensahnoun aimensahnoun marked this pull request as ready for review September 2, 2024 19:57
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: 1

Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between 03cced2 and 502e5d8.

Files selected for processing (7)
  • packages/create-invoice-form/src/lib/utils/prepareRequest.ts (1 hunks)
  • packages/invoice-dashboard/src/lib/dashboard/invoice-view.svelte (5 hunks)
  • packages/invoice-dashboard/src/lib/view-requests.svelte (6 hunks)
  • packages/invoice-dashboard/src/utils/getCurrency.ts (1 hunks)
  • packages/payment-widget/src/lib/utils/currencies.ts (1 hunks)
  • packages/payment-widget/src/lib/utils/request.ts (1 hunks)
  • shared/utils/initCurrencyManager.ts (1 hunks)
Additional context used
Biome
packages/invoice-dashboard/src/utils/getCurrency.ts

[error] 10-10: Forbidden non-null assertion.

(lint/style/noNonNullAssertion)

Additional comments not posted (23)
shared/utils/initCurrencyManager.ts (2)

12-45: LGTM!

The expansion of the defaultCurrencyIds array with new currency identifiers is approved. This change enhances the functionality and flexibility of the currency management system by increasing the variety of currencies that can be initialized through the CurrencyManager.


53-60: LGTM!

The restructuring of the logic for determining the list of currencies to use is approved. The changes streamline the logic, ensure that the default currencies are always included, and improve the clarity and efficiency of the currency initialization process.

packages/payment-widget/src/lib/utils/currencies.ts (1)

50-51: LGTM!

The code changes are approved. The addition of new currency identifiers for stablecoins on the Sepolia network expands the supported currencies without altering the existing functionality or behavior.

packages/create-invoice-form/src/lib/utils/prepareRequest.ts (4)

21-23: LGTM!

The code changes are approved.


24-54: LGTM!

The code changes are approved.


57-105: LGTM!

The code changes are approved.


106-129: LGTM!

The code changes are approved.

packages/payment-widget/src/lib/utils/request.ts (1)

93-93: LGTM!

The code changes are approved. The conditional logic ensures that the correct representation of the currency is used based on its type, improving the flexibility and accuracy of the request parameters.

packages/invoice-dashboard/src/lib/dashboard/invoice-view.svelte (10)

2-2: LGTM!

The change in the import order improves code readability without affecting functionality.


6-11: LGTM!

The reorganization of import statements improves code readability without affecting functionality.


15-15: LGTM!

The import statement for the Button component is necessary for the component to function correctly.


27-29: LGTM!

The import statements for the formatUnits, exportToPDF, walletClientToSigner, and getCurrencyFromManager functions are necessary for the component to function correctly.


40-40: LGTM!

Extracting the currency determination logic into a separate getCurrencyFromManager function improves code readability and maintainability.


101-101: LGTM!

Updating the currency variable using the getCurrencyFromManager function ensures that the currency is always determined based on the latest request and currencyManager values.


113-118: LGTM!

The conditional approval check based on the currency type improves efficiency by only calling the checkApproval function for ERC20 tokens and automatically setting the approval to true for non-ERC20 currencies.


200-209: LGTM!

The addition of new network options in the getNetworkIdFromNetworkName function improves the flexibility and compatibility of the component with various blockchain networks.


462-462: LGTM!

The simplified error message for unsupported networks improves the user experience by providing a clear and concise indication of the issue.


34-34: Verify the impact of making the request prop required.

The request prop is now always expected to be defined and not optional. Ensure that all usages of the invoice-view component provide the required request prop to avoid runtime errors.

Run the following script to verify the request prop usage:

packages/invoice-dashboard/src/lib/view-requests.svelte (5)

9-9: LGTM!

The reorganization of the import statements improves code clarity and consistency without affecting functionality.

Also applies to: 11-11, 13-13


54-59: LGTM!

The updated type of activeRequest enhances the data structure and allows for easier access to formatted currency information.


200-221: LGTM!

The new reactive statement $: processedRequests improves data handling and presentation by transforming paginatedRequests into a more useful format with formatted currency information. This allows for easier access to these values in the template.


266-269: LGTM!

The updated request parameter type in the handleRequestSelect function signature matches the new structure of activeRequest, ensuring seamless handling of the additional properties.


453-454: LGTM!

The template changes, such as iterating over processedRequests and displaying the formattedAmount and currencySymbol properties, reflect the new data structure and ensure the correct display of formatted currency information in the UI.

Also applies to: 513-514

@aimensahnoun aimensahnoun enabled auto-merge (squash) September 2, 2024 20:06
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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between 502e5d8 and 6dfc989.

Files selected for processing (1)
  • shared/utils/initCurrencyManager.ts (1 hunks)
Additional comments not posted (4)
shared/utils/initCurrencyManager.ts (4)

12-45: LGTM!

The expansion of the defaultCurrencyIds array is a positive change that increases the range of supported currencies, making the system more versatile.


55-62: LGTM!

The restructuring of the logic for determining the list of currencies to use improves the clarity and efficiency of the currency initialization process. The changes ensure that default currencies are consistently included, enhancing the robustness of the system.


65-79: LGTM!

The updated deduplication logic is more comprehensive and handles both ETH and ERC20 currency types correctly, ensuring that duplicate currencies are effectively filtered out.


48-49: LGTM!

The new import statement for Types from @requestnetwork/request-client.js is necessary for the updated deduplication logic that handles both ETH and ERC20 currency types.

@MantisClone
Copy link
Member

@coderabbitai

Objective Addressed Explanation
Support ETH (native) payments on all supported chains ( #61 )
Add REQ on Ethereum as part of the default list ( #61 ) REQ support is not mentioned in the changes.

Actually "Add REQ on Ethereum as part of the default list" WAS addressed.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 3, 2024

Tip

For best results, initiate chat on the files or code changes.

@MantisClone, you are correct. The objective "Add REQ on Ethereum as part of the default list" was indeed addressed in the PR, as "REQ-mainnet" is included in the default list of currencies. I will update the status accordingly. Thank you for pointing this out!

Analysis chain
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for the inclusion of REQ on Ethereum in the default list of currencies.
rg 'REQ' -A 5

Length of output: 3885

@aimensahnoun aimensahnoun merged commit 9d799bc into main Sep 3, 2024
@aimensahnoun aimensahnoun deleted the 108-invoice-dashboard-displays-incorrect-amount-when-token-is-unknown-and-has-less-than-18-decimals branch September 3, 2024 13:55
@MantisClone MantisClone changed the title Feat: support same same currencies as checkout and fix currency display Feat: support same currencies as checkout and fix currency display Sep 19, 2024
@coderabbitai coderabbitai bot mentioned this pull request Sep 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants