Skip to content

Conversation

@aimensahnoun
Copy link
Member

@aimensahnoun aimensahnoun commented Sep 2, 2024

Resolves #111

  • Update generatePdf method to always have fallback in case of missing data and always generate pdf.

Invoice generated from `Payment Widget (Checkout)

CleanShot 2024-09-03 at 00 37 42

Invoice created by Invoicing with details

CleanShot 2024-09-03 at 00 38 07

Summary by CodeRabbit

  • New Features

    • Enhanced currency handling in invoice preparation, supporting both ERC20 and ETH currencies.
    • Introduced new currency identifiers for FUSDT and FUSDC on the Sepolia network.
  • Improvements

    • Improved type safety and clarity in invoice view components.
    • Enhanced invoice PDF generation with better formatting and error handling.
    • Streamlined request handling with enriched currency information.
  • Bug Fixes

    • Fixed issues related to undefined properties in invoice rendering and request management.
  • Chores

    • Reorganized import statements for better code clarity across various components.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 2, 2024

Walkthrough

The changes encompass various enhancements across multiple components within the invoice management system. Key modifications include improved handling of currency types, refinements in request parameter preparation, and updates to the PDF generation process. Additionally, new utility functions have been introduced for better currency management, and the overall structure of components has been organized for clarity and maintainability.

Changes

Files Change Summary
packages/create-invoice-form/src/lib/utils/prepareRequest.ts Enhanced currency handling in prepareRequestParams, added conditional checks for ERC20, and refined request structures.
packages/invoice-dashboard/src/lib/dashboard/invoice-view.svelte Reorganized imports, enforced required request property, updated currency logic with getCurrencyFromManager, refined approval checks based on currency type, and expanded network options.
packages/invoice-dashboard/src/lib/view-requests.svelte Reorganized imports, expanded activeRequest type, introduced reactive statement for processed requests, and updated rendering logic.
packages/invoice-dashboard/src/utils/generateInvoice.ts Introduced utility functions for date formatting and address rendering, improved handling of undefined properties, and refined invoice item rendering logic.
packages/invoice-dashboard/src/utils/getCurrency.ts New utility function getCurrencyFromManager for retrieving currency information based on type and manager instance.
packages/payment-widget/src/lib/utils/currencies.ts Added new currency identifiers for FUSDT_SEPOLIA and FUSDC_SEPOLIA.
packages/payment-widget/src/lib/utils/request.ts Modified prepareRequestParameters to conditionally assign currency based on ERC20 flag.
shared/utils/initCurrencyManager.ts Enhanced initializeCurrencyManager to ensure default currencies are included and prevent duplicates.

Assessment against linked issues

Objective Addressed Explanation
[invoice dashboard] Download PDF does not work on requests created by the Checkout (#111)

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.

@aimensahnoun aimensahnoun enabled auto-merge (squash) September 2, 2024 21:40
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 03cced2 and d6c108d.

Files selected for processing (8)
  • 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 (7 hunks)
  • packages/invoice-dashboard/src/utils/generateInvoice.ts (4 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
Learnings (1)
packages/invoice-dashboard/src/utils/getCurrency.ts (1)
Learnt from: aimensahnoun
PR: RequestNetwork/web-components#118
File: packages/invoice-dashboard/src/utils/getCurrency.ts:4-14
Timestamp: 2024-09-02T20:05:27.723Z
Learning: The `network` property is always present in the currency object within the `getCurrencyFromManager` function, making the non-null assertion safe to use.
Biome
packages/invoice-dashboard/src/utils/getCurrency.ts

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

(lint/style/noNonNullAssertion)

Additional comments not posted (23)
packages/invoice-dashboard/src/utils/getCurrency.ts (1)

1-14: LGTM!

The code changes are approved.

The static analysis error can be safely ignored based on the learning:

The network property is always present in the currency object within the getCurrencyFromManager function, making the non-null assertion safe to use.

Tools
Biome

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

(lint/style/noNonNullAssertion)

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

50-51: LGTM!

The code changes are approved for the following reasons:

  • The additions expand the set of supported currencies by introducing new currency identifiers for FUSDT_SEPOLIA and FUSDC_SEPOLIA.
  • The entries follow the existing structure of the CURRENCY_ID constant and map to the appropriate string values.
  • The change is self-contained, does not affect the control flow, and aligns with the likely intention of accommodating new currency options.
shared/utils/initCurrencyManager.ts (4)

12-43: LGTM!

The code changes are approved.


48-49: LGTM!

The code changes are approved.


55-62: LGTM!

The code changes are approved. The new implementation ensures that the default currencies are always included and custom currencies are appended only if present, which is an improvement over the previous implementation.


65-80: LGTM!

The code changes are approved. The new filtering mechanism is robust and ensures that the final list of currencies used in the CurrencyManager is unique. The logic for identifying duplicates is well-defined and differentiates between currency types (ETH and ERC20) based on network and address properties.

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

21-129: LGTM!

The changes in the prepareRequestParams function enhance the handling of currency types and streamline the construction of the request parameters. The key improvements include:

  • Introduction of a conditional check to determine if the currency type is ERC20, which influences how the currency address is assigned within the requestInfo and contentData structures.
  • Dynamic assignment of the payment network ID based on the currency type in the paymentNetwork section, ensuring that the correct network is utilized for both ETH and ERC20 currencies.
  • Refinement of the contentData section, with the addition of the currency field in the invoiceItems mapping, which now reflects the appropriate currency symbol or address based on the currency type.

These changes not only enhance the functionality of the function but also improve its robustness and adaptability to various currency types, leading to a more reliable invoice preparation process.

packages/invoice-dashboard/src/utils/generateInvoice.ts (6)

26-28: LGTM!

The formatDate utility function is a nice addition that improves code readability by abstracting date formatting logic. It also handles the case when the date is undefined.


30-38: LGTM!

The renderAddress utility function is a nice addition that improves code readability by abstracting address rendering logic. It also handles the case when some or all address fields are missing.


46-48: LGTM!

Moving the font family declaration to the <style> block is a good change that improves separation of concerns and reduces duplication.


Line range hint 51-139: LGTM!

The changes to the HTML structure of the invoice are well-implemented and improve the presentation and robustness of the invoice:

  • Using the formatDate and renderAddress utility functions for formatting improves readability and maintainability.
  • Handling potentially undefined properties using optional chaining and default values ensures that the invoice remains informative even when some data is missing.
  • Formatting monetary values using the formatUnits function from the viem library ensures that the values are displayed correctly.

Line range hint 145-151: LGTM!

Renaming the "Memo" section to "Note" improves the clarity of the section. Conditionally rendering the section based on the presence of invoice.contentData?.note is a good practice to avoid rendering empty sections.


159-179: LGTM!

The changes to the PDF generation process are well-implemented and improve the functionality:

  • Including the invoice number in the filename (with a fallback to "unknown") makes it easier to identify the generated PDF.
  • Adding the useCORS and letterRendering options to the html2canvas configuration improves the rendering quality and compatibility of the generated PDF.
  • Using a temporary <div> element to hold the invoice content is a good practice to avoid modifying the existing DOM structure.
packages/payment-widget/src/lib/utils/request.ts (1)

93-93: LGTM!

The code change is approved. It enhances the flexibility of the prepareRequestParameters function by allowing it to handle different types of currency representations based on the context of the request.

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

2-2: LGTM!

The reorganization of import statements enhances clarity and consistency.

Also applies to: 8-11, 15-15


34-34: LGTM!

Making the request property required is a good change that enforces stricter type safety and prevents runtime errors.


40-40: LGTM!

The update to use the getCurrencyFromManager utility function is a good change that improves readability and addresses the deprecation warning.

Also applies to: 101-101


113-118: LGTM!

The refinement of the approval check logic based on the currency type is a good change that streamlines the approval process and reduces unnecessary checks for non-ERC20 currencies.


200-210: LGTM!

The expansion of the getNetworkIdFromNetworkName function to include more network options is a good change that broadens the component's compatibility with various blockchain networks.


462-462: LGTM!

The simplification of the unsupported network error message is a good change that improves user experience by providing a clearer indication of the issue without exposing technical details.

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

29-31: LGTM!

The changes to the import statements enhance readability and organization.


54-59: LGTM!

The changes to the activeRequest variable's type indicate a shift towards a more enriched data structure that allows for easier access to formatted currency information directly within the request object.


200-221: LGTM!

The changes to the processedRequests reactive statement centralize the logic for formatting currency and ensure that all requests are processed consistently before rendering.

…111-invoice-dashboard-download-pdf-does-not-work-on-requests-created-by-the-checkout
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.

[invoice dashboard] Download PDF does not work on requests created by the Checkout

3 participants