Skip to content

Conversation

@sstefdev
Copy link
Contributor

@sstefdev sstefdev commented Dec 6, 2024

Fixes #209

Problem

Currently, the currencies input parameter appends to the default currency list in the Invoice Dashboard and Create Invoice Form. This makes it impossible for app builders to remove a currency from the default list, limiting customization options.

Changes

BREAKING CHANGE!

  • Changed the existing currencies parameter to act like an override for the default currency list instead of appending to the currency list on both the Invoice Dashboard and Create Invoice Form components.
  • When the currencies parameter is passed, only those currencies.
  • When the currencies parameter is not passed, the default currencies list is used.

Considerations

App Builders who previously used the currencies parameter to append to the default currency list must now treat it like an override by including every currency they wish to support in their currencies argument instead of only the appended currencies.

How it looks when we don't have the right currencies in the config, but we have them in the invocies

Screenshot 2024-12-10 at 09 07 31

Summary by CodeRabbit

  • New Features

    • Introduced a new SVG icon for representing an unknown state.
    • Enhanced handling of currency display and cipher provider initialization in various components.
  • Bug Fixes

    • Improved error handling for network and request fetching processes.
  • Chores

    • Streamlined logic for currency management initialization, enhancing clarity and performance.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 6, 2024

Walkthrough

The pull request introduces several modifications across multiple files, focusing on improving the handling of currency management, network icons, and cipher providers. Key changes include updating the view-requests.svelte component to enhance decryption and currency symbol handling, adding a new unknown.svelte icon, modifying the network icon selection utility, and streamlining the currency manager initialization process. These changes aim to improve the robustness and flexibility of the application's currency and network-related functionalities.

Changes

File Change Summary
packages/invoice-dashboard/src/lib/view-requests.svelte - Updated cipherProvider reactive statement
- Modified currencySymbol to default to "-"
- Refined decryption toggle logic
shared/icons/unknown.svelte - Added new SVG icon component with 24x24 pixel dimensions
shared/utils/getNetworkIcon.ts - Imported Unknown icon
- Updated fallback icon to Unknown instead of EthereumIcon
shared/utils/initCurrencyManager.ts - Simplified initializeCurrencyManager function
- Removed duplicate filtering logic
packages/create-invoice-form/src/lib/create-invoice-form.svelte - Updated cipherProvider initialization
- Improved account retrieval logic

Assessment against linked issues

Objective Addressed Explanation
Override default currencies [#209] Partial implementation visible, but full override mechanism not clearly demonstrated

Possibly related PRs

Suggested reviewers

  • MantisClone
  • aimensahnoun
  • rodrigopavezi

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fd722e5 and 18af614.

📒 Files selected for processing (2)
  • packages/create-invoice-form/src/lib/create-invoice-form.svelte (1 hunks)
  • packages/invoice-dashboard/src/lib/view-requests.svelte (2 hunks)
🔇 Additional comments (4)
packages/create-invoice-form/src/lib/create-invoice-form.svelte (1)

118-118: LGTM: Safe initialization of cipherProvider

The reactive statement safely initializes cipherProvider using optional chaining.

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

155-161: Improved type safety for cipherProvider

The explicit type definition and assertion provides better type safety by ensuring the cipherProvider has the required getSessionSignatures method.


364-364: Enhanced robustness with proper fallback for undefined currency symbols

Using the nullish coalescing operator to provide a "-" fallback improves the handling of undefined currency symbols.


364-364: Consider optimizing decryption toggle handling

The current implementation triggers enableDecryption directly from the reactive statement which could lead to unnecessary calls.

As suggested in the previous review, consider implementing debouncing:

-  $: sliderValueForDecryption, enableDecryption();
+  $: {
+    try {
+      const isEnabled = sliderValueForDecryption === 'on';
+      enableDecryption(isEnabled);
+      // Debounce request refresh to prevent unnecessary calls
+      debouncedUpdate(() => getRequests());
+    } catch (error) {
+      console.error('Failed to toggle decryption:', error);
+      toast.error('Failed to toggle decryption');
+    }
+  }

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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 changed the title feat: Add Override Parameter for Currencies and Payment Chains in Invoice Dashboard and Create Invoice Form feat: Override Parameter for Currencies and Payment Chains in Invoice Dashboard and Create Invoice Form Dec 6, 2024
@sstefdev sstefdev self-assigned this Dec 6, 2024
@sstefdev sstefdev requested review from MantisClone, aimensahnoun and rodrigopavezi and removed request for MantisClone and rodrigopavezi December 10, 2024 08:08
@sstefdev sstefdev marked this pull request as ready for review December 10, 2024 08:08
…parameter-_override_-the-default-currency-and-payment-chains-list-instead-of-append
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: 5

🧹 Outside diff range and nitpick comments (4)
shared/icons/network/network-icon.svelte (1)

13-13: LGTM! Consider i18n for the "Unknown" text.

The addition of the "Unknown" fallback text improves user experience by providing clear feedback when a network name is not available.

Consider extracting "Unknown" to a translation constant for future internationalization support:

-    <span>{capitalize(network) || "Unknown"}</span>
+    <span>{capitalize(network) || t('common.unknown')}</span>
shared/utils/initCurrencyManager.ts (1)

75-80: Consider memoizing default currencies initialization

The default currencies filtering could be expensive if called frequently.

+const memoizedDefaultCurrencies = new Map();
+
 export function initializeCurrencyManager(
   customCurrencies: CurrencyTypes.CurrencyInput[] = []
 ): CurrencyManager {
   if (customCurrencies?.length > 0) {
     return new CurrencyManager(customCurrencies, {}, formattedCurrencyConversionPairs);
   }
 
+  const cacheKey = defaultCurrencyIds.join(',');
+  if (!memoizedDefaultCurrencies.has(cacheKey)) {
+    const defaultCurrencies = CurrencyManager.getDefaultList().filter(
+      (currency) => defaultCurrencyIds.includes(currency.id)
+    );
+    memoizedDefaultCurrencies.set(cacheKey, defaultCurrencies);
+  }
+
-  const defaultCurrencies = CurrencyManager.getDefaultList().filter(
-    (currency) => defaultCurrencyIds.includes(currency.id)
-  );
-
-  return new CurrencyManager(defaultCurrencies, {}, formattedCurrencyConversionPairs);
+  return new CurrencyManager(
+    memoizedDefaultCurrencies.get(cacheKey),
+    {},
+    formattedCurrencyConversionPairs
+  );
packages/invoice-dashboard/src/lib/view-requests.svelte (2)

332-332: LGTM! Consider using nullish coalescing operator.

The fallback to "-" when currency symbol is undefined is good practice. Consider using the nullish coalescing operator for a more concise expression:

-        currencySymbol: currencyInfo?.symbol ?? "-",
+        currencySymbol: currencyInfo?.symbol ?? "-",

332-332: Consider performance optimizations for table operations.

The table implementation performs multiple array operations on each change. Consider these performance improvements:

  1. Memoize expensive computations:
    • Use memoize for sorting and filtering operations
    • Cache processed requests until relevant data changes
  2. Reduce array copies:
    • Use immutable array operations
    • Consider using a virtual scroll implementation for large datasets
  3. Optimize reactive dependencies:
    • Split large reactive statements into smaller, focused ones
    • Use computed stores for derived data

Would you like me to provide specific code examples for any of these optimizations?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between f6c3f8c and 4865648.

📒 Files selected for processing (5)
  • packages/invoice-dashboard/src/lib/view-requests.svelte (1 hunks)
  • shared/icons/network/network-icon.svelte (1 hunks)
  • shared/icons/unkown.svelte (1 hunks)
  • shared/utils/getNetworkIcon.ts (2 hunks)
  • shared/utils/initCurrencyManager.ts (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • shared/icons/unkown.svelte
🔇 Additional comments (1)
shared/utils/initCurrencyManager.ts (1)

70-80: Verify currency override behavior

Let's ensure the currency override functionality works as intended per PR objectives.

✅ Verification successful

Let me gather more specific information about the currency override functionality.


Let me check one more aspect to understand how the currency manager is being used in the application.


Currency override behavior is properly implemented

The implementation correctly handles both custom and default currency scenarios:

  • When customCurrencies are provided, it exclusively uses those currencies
  • When no custom currencies are provided, it falls back to a filtered list of default currencies (USD, EUR)
  • The initialization is properly encapsulated in the initializeCurrencyManager function
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Look for currency override usage patterns
rg -A 5 "initializeCurrencyManager|CurrencyManager" --type ts --type svelte

# Check for any currency-related test files
fd -e test.ts -e spec.ts | xargs rg -l "currency|currencies"

Length of output: 1868


Script:

#!/bin/bash
# Check the CurrencyManager class implementation and usage
ast-grep --pattern 'class CurrencyManager {
  $$$
}'

# Look for tests specifically related to currency manager initialization
rg -B2 -A5 "initCurrencyManager" shared/utils/initCurrencyManager.ts

# Check for customCurrencies usage in the codebase
rg "customCurrencies" --type ts -B2 -A2

Length of output: 791


Script:

#!/bin/bash
# Check how CurrencyManager.getDefaultList is implemented and used
ast-grep --pattern 'getDefaultList() {
  $$$
}'

# Look for actual usage of initializeCurrencyManager in the codebase
rg "initializeCurrencyManager\(" --type ts -B2 -A2

# Check the defaultCurrencyIds usage
rg "defaultCurrencyIds" --type ts -B2 -A2

Length of output: 1160

sstefdev and others added 4 commits December 10, 2024 13:17
…209-make-currencies-and-payment-chain-input-parameter-_override_-the-default-currency-and-payment-chains-list-instead-of-append
…parameter-_override_-the-default-currency-and-payment-chains-list-instead-of-append
…override_-the-default-currency-and-payment-chains-list-instead-of-append' of github.com:RequestNetwork/web-components into 209-make-currencies-and-payment-chain-input-parameter-_override_-the-default-currency-and-payment-chains-list-instead-of-append
Copy link
Member

@MantisClone MantisClone left a comment

Choose a reason for hiding this comment

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

@sstefdev Please update the description with usage examples for both the append and override behavior.

As far as I can tell - the description is incorrect. It mentions a new "append or override" parameter, but this isn't present in the code.

@sstefdev sstefdev requested a review from MantisClone December 13, 2024 13:59
sstefdev and others added 3 commits December 16, 2024 10:54
…parameter-_override_-the-default-currency-and-payment-chains-list-instead-of-append
…209-make-currencies-and-payment-chain-input-parameter-_override_-the-default-currency-and-payment-chains-list-instead-of-append
…override_-the-default-currency-and-payment-chains-list-instead-of-append' of github.com:RequestNetwork/web-components into 209-make-currencies-and-payment-chain-input-parameter-_override_-the-default-currency-and-payment-chains-list-instead-of-append
@MantisClone MantisClone changed the title feat: Override Parameter for Currencies and Payment Chains in Invoice Dashboard and Create Invoice Form feat!: Override Parameter for Currencies and Payment Chains in Invoice Dashboard and Create Invoice Form Dec 17, 2024
@MantisClone
Copy link
Member

MantisClone commented Dec 17, 2024

I added feat! to the PR title to indicate this is a BREAKING change. App Builders who previously used the currencies parameter to append to the default currency list must include every currency they wish to support in their currencies argument because it acts like an override now.

@MantisClone
Copy link
Member

MantisClone commented Dec 17, 2024

I edited the description. @sstefdev please review my edits before merging.

@sstefdev sstefdev merged commit 48ffccd into main Dec 17, 2024
2 checks passed
@sstefdev sstefdev deleted the 209-make-currencies-and-payment-chain-input-parameter-_override_-the-default-currency-and-payment-chains-list-instead-of-append branch December 17, 2024 09:47
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.

Make currencies and payment chain input parameter _override_ the default currency and payment chains list instead of append

3 participants