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: add Polkadot as currency #1581

Merged
merged 1 commit into from
Oct 6, 2024
Merged

feat: add Polkadot as currency #1581

merged 1 commit into from
Oct 6, 2024

Conversation

Nick-1979
Copy link
Member

@Nick-1979 Nick-1979 commented Oct 6, 2024

closes #1578

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced currency formatting logic to support additional currencies.
    • Added support for displaying the Polkadot currency icon in the CurrencyItem component.
    • Updated the CurrencySwitch component to display more default currencies.
  • Bug Fixes

    • Improved handling of currency data types across components for better consistency and type safety.
  • Documentation

    • Updated currency definitions to provide more descriptive information, including full names for Bitcoin and Ethereum.
  • Chores

    • Removed deprecated USD_CURRENCY constant and updated related constants for better clarity.

@Nick-1979 Nick-1979 requested a review from AMIRKHANEF October 6, 2024 07:23
Copy link
Contributor

coderabbitai bot commented Oct 6, 2024

Walkthrough

The changes in this pull request involve modifications across several components and utility files related to currency handling in the application. Key updates include the introduction of a new currency list constant, adjustments to the FormatPrice component to enhance decimal point calculations based on a broader currency list, and updates to the CurrencySwitch and Currency components to utilize a more structured currency type. Additionally, the USD_CURRENCY constant has been removed and redefined in a new utility file, reflecting a shift in how currency information is managed.

Changes

File Change Summary
packages/extension-polkagate/src/components/FormatPrice.tsx Added import for ASSETS_AS_CURRENCY_LIST and modified _decimalPoint calculation to check against this list.
packages/extension-polkagate/src/fullscreen/homeFullScreen/components/CurrencyItem.tsx Added import for chainsPolkadotCircleSVG and updated flagSVG logic to return this SVG for 'DOT' currency.
packages/extension-polkagate/src/fullscreen/homeFullScreen/components/CurrencySwitch.tsx Updated setCurrencyToShow type in Props interface, changed DEFAULT_CURRENCIES_TO_SHOW from 5 to 6, and modified changeCurrency function to align with new type.
packages/extension-polkagate/src/fullscreen/homeFullScreen/partials/Currency.tsx Changed currencyToShow state type from `string
packages/extension-polkagate/src/hooks/useCurrency.ts Updated import path for USD_CURRENCY from ../util/constants to ../util/currencyList.
packages/extension-polkagate/src/util/constants.tsx Removed USD_CURRENCY constant and updated PROXY_TYPE to include NOMINATION_POOLS.
packages/extension-polkagate/src/util/currencyList.tsx Added ASSETS_AS_CURRENCY_LIST, redefined USD_CURRENCY, and updated CURRENCY_LIST to include new entries and full currency names for BTC and ETH.

Possibly related PRs

Suggested labels

new feature

Suggested reviewers

  • AMIRKHANEF

🐰 In the land of code, where currencies play,
New logic is added, brightening the way.
From BTC to DOT, we handle with care,
Formatting prices, with love we declare.
So hop along, join the fun,
With each change made, our work is well done! 🥕


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.

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 (6)
packages/extension-polkagate/src/hooks/useCurrency.ts (1)

Line range hint 17-30: Consider Polkadot-specific logic if necessary.

The useCurrency function looks good and its logic remains unchanged. However, given that the PR objective is to add Polkadot as a currency, you might want to consider if any Polkadot-specific logic needs to be added to this hook.

If Polkadot requires special handling, you could consider:

  1. Adding a Polkadot currency constant (e.g., POLKADOT_CURRENCY) alongside USD_CURRENCY.
  2. Implementing logic to set Polkadot as the default currency in certain scenarios.

Example:

import { POLKADOT_CURRENCY, USD_CURRENCY } from '../util/currencyList';

// Inside the useEffect
getStorage('currency').then((res) => {
  setCurrency(res as CurrencyItemType || POLKADOT_CURRENCY || USD_CURRENCY);
}).catch(console.error);

Please evaluate if such changes are necessary for your use case.

packages/extension-polkagate/src/fullscreen/homeFullScreen/components/CurrencyItem.tsx (1)

32-35: LGTM: Polkadot currency handling added.

The new condition for handling the Polkadot currency (DOT) is correctly implemented and aligns with the existing pattern for other cryptocurrencies. This change fulfills the PR objective of adding Polkadot as a supported currency.

For consistency with other cryptocurrency conditions, consider removing the blank line after the new condition:

    if (currency.code === 'DOT') {
      return chainsPolkadotCircleSVG;
    }
-
    const svg = (flags as Record<string, string>)[countryCode];
packages/extension-polkagate/src/fullscreen/homeFullScreen/partials/Currency.tsx (1)

51-55: LGTM: Enhanced currency display with Infotip2

The addition of the Infotip2 component and the updated rendering logic for the currency sign are good improvements. They enhance the user experience by providing more information and handling potential undefined states.

Consider extracting the default currency sign '$' to a constant or configuration value for better maintainability. For example:

const DEFAULT_CURRENCY_SIGN = '$';

// In the render method
{currencyToShow?.sign || DEFAULT_CURRENCY_SIGN}

This makes it easier to update the default currency sign if needed in the future.

packages/extension-polkagate/src/fullscreen/homeFullScreen/components/CurrencySwitch.tsx (1)

45-45: Approve change and suggest minor optimization

The update to pass the entire currency object to setCurrencyToShow is consistent with the Props interface change and provides more flexibility to the parent component. This is a good improvement.

Consider using object destructuring in the function parameters for better readability:

-const changeCurrency = useCallback((currency: CurrencyItemType) => {
+const changeCurrency = useCallback(({ code, sign, ...rest }: CurrencyItemType) => {
   setAnchorEl(null);
-  setCurrency(currency);
-  setCurrencyToShow(currency);
+  setCurrency({ code, sign, ...rest });
+  setCurrencyToShow({ code, sign, ...rest });
-  setStorage('currency', currency).catch(console.error);
+  setStorage('currency', { code, sign, ...rest }).catch(console.error);
 }, [setAnchorEl, setCurrency, setCurrencyToShow]);

This approach makes it clear which properties of the currency object are being used and allows for easy expansion if more properties are needed in the future.

packages/extension-polkagate/src/util/currencyList.tsx (2)

4-4: LGTM! Consider adding a brief comment for clarity.

The new ASSETS_AS_CURRENCY_LIST constant is a good addition, aligning with the PR objective of adding Polkadot as a currency. It's exported, which allows for reuse in other parts of the application.

Consider adding a brief comment above the constant to explain its purpose and usage, e.g.:

// List of cryptocurrency assets that can be used as currency options
export const ASSETS_AS_CURRENCY_LIST = ['BTC', 'ETH', 'DOT'];

30-30: LGTM! Consider using a more standard symbol for Polkadot.

The changes to the CURRENCY_LIST are good:

  1. Updating Bitcoin and Ethereum to use full names improves clarity.
  2. Adding Polkadot (DOT) aligns with the PR objective and follows the established structure.

For the Polkadot entry, consider using a more standard or recognizable symbol. The current stylized 'P' (𝒫) might not be widely recognized. Options could include:

  1. Using 'DOT' as the sign (like some other cryptocurrencies in the list).
  2. Using a dot symbol (•) to represent Polkadot.
  3. If there's an official Polkadot currency symbol, use that instead.

Example:

{
  code: 'DOT',
  country: 'Polkadot',
  currency: 'Polkadot',
  sign: 'DOT'  // or '•' or the official symbol if one exists
}

Also applies to: 36-36, 39-44

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 350d1af and 18ed0ae.

📒 Files selected for processing (7)
  • packages/extension-polkagate/src/components/FormatPrice.tsx (2 hunks)
  • packages/extension-polkagate/src/fullscreen/homeFullScreen/components/CurrencyItem.tsx (2 hunks)
  • packages/extension-polkagate/src/fullscreen/homeFullScreen/components/CurrencySwitch.tsx (3 hunks)
  • packages/extension-polkagate/src/fullscreen/homeFullScreen/partials/Currency.tsx (4 hunks)
  • packages/extension-polkagate/src/hooks/useCurrency.ts (1 hunks)
  • packages/extension-polkagate/src/util/constants.tsx (0 hunks)
  • packages/extension-polkagate/src/util/currencyList.tsx (2 hunks)
💤 Files with no reviewable changes (1)
  • packages/extension-polkagate/src/util/constants.tsx
🧰 Additional context used
🔇 Additional comments (14)
packages/extension-polkagate/src/fullscreen/homeFullScreen/components/CurrencyItem.tsx (2)

9-9: LGTM: New import for Polkadot logo.

The import statement for chainsPolkadotCircleSVG is correctly placed and follows the existing naming conventions. This addition aligns with the PR objective of adding Polkadot as a currency.


Line range hint 1-63: Summary: Polkadot currency support successfully added.

The changes in this file effectively implement Polkadot (DOT) as a new supported currency in the CurrencyItem component. The implementation follows existing patterns for handling cryptocurrencies and integrates seamlessly with the current code structure. These modifications directly fulfill the PR objective of adding Polkadot as a currency.

To ensure the Polkadot logo is correctly imported and used, run the following verification:

✅ Verification successful

Verification Successful: Polkadot logo correctly implemented.

The chainsPolkadotCircleSVG is properly imported and utilized exclusively within the CurrencyItem.tsx component. This confirms that the Polkadot support has been correctly integrated without affecting other parts of the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify the Polkadot logo import and usage

# Check if the Polkadot logo file exists
fd -t f chainsPolkadotCircleSVG.ts

# Verify the usage of chainsPolkadotCircleSVG in other files
rg "chainsPolkadotCircleSVG" --type typescript

Length of output: 118


Script:

#!/bin/bash
# Verify the Polkadot logo import and usage with corrected ripgrep type

# Check if the Polkadot logo file exists
fd -t f chainsPolkadotCircleSVG.ts

# Verify the usage of chainsPolkadotCircleSVG in other files
rg "chainsPolkadotCircleSVG" --type ts

Length of output: 369

packages/extension-polkagate/src/components/FormatPrice.tsx (3)

10-10: LGTM: New import aligns with PR objective.

The addition of ASSETS_AS_CURRENCY_LIST import is consistent with the PR's goal of adding Polkadot as a currency. This list will likely include Polkadot among other assets that can be used as currencies.


Line range hint 1-108: Overall approval with a note on PR objective.

The changes in this file improve the handling of crypto assets as currencies, which aligns with the PR objective of adding Polkadot as a currency. The code is now more flexible and maintainable.

However, it's worth noting that this file doesn't explicitly add Polkadot as a currency. The actual addition should be in the ASSETS_AS_CURRENCY_LIST definition, which is likely in another file.

To ensure the PR fully meets its objective, please verify that Polkadot has been added to the ASSETS_AS_CURRENCY_LIST in the appropriate file:

#!/bin/bash
# Description: Verify that Polkadot has been added to ASSETS_AS_CURRENCY_LIST

# Test: Search for Polkadot in ASSETS_AS_CURRENCY_LIST definition
rg --type typescript 'ASSETS_AS_CURRENCY_LIST.*Polkadot' ../util/currencyList.ts

If this search doesn't yield results, please ensure that Polkadot has been added to the list in the correct file.


72-75: Approved: Improved currency handling logic.

The modification to the _decimalPoint calculation is a good improvement:

  1. It generalizes the handling of crypto assets, making it easier to add new ones like Polkadot.
  2. The use of ASSETS_AS_CURRENCY_LIST allows for centralized management of supported crypto assets.
  3. The constant DECIMAL_POINTS_FOR_CRYPTO_AS_CURRENCY improves code maintainability.

To ensure Polkadot has been properly added, please verify the contents of ASSETS_AS_CURRENCY_LIST:

✅ Verification successful

Action Required: Verify Polkadot Inclusion in ASSETS_AS_CURRENCY_LIST

The initial script encountered an error due to an unrecognized file type. Please use the updated script below to verify that "Polkadot" is included in ASSETS_AS_CURRENCY_LIST:


Action Required: Locate currencyList.ts in the Codebase

The previous script failed to locate currencyList.ts. Please use the following script to search for the correct path of currencyList.ts within the repository:


Action Required: Locate Declaration of ASSETS_AS_CURRENCY_LIST in the Codebase

To identify where ASSETS_AS_CURRENCY_LIST is defined, please execute the following script. This will search the entire repository for its declaration:


Verification Complete: Polkadot is Included in ASSETS_AS_CURRENCY_LIST

The ASSETS_AS_CURRENCY_LIST includes 'DOT', which represents Polkadot.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that Polkadot is included in ASSETS_AS_CURRENCY_LIST

# Test: Search for ASSETS_AS_CURRENCY_LIST definition
rg --type typescript 'ASSETS_AS_CURRENCY_LIST\s*=' ../util/currencyList.ts

Length of output: 117


Script:

#!/bin/bash
# Description: Verify that Polkadot is included in ASSETS_AS_CURRENCY_LIST

# Test: Search for 'Polkadot' within ASSETS_AS_CURRENCY_LIST in currencyList.ts
rg 'ASSETS_AS_CURRENCY_LIST\s*=\s*\[.*Polkadot.*\]' ./packages/extension-polkagate/src/util/currencyList.ts

Length of output: 205


Script:

#!/bin/bash
# Description: Locate the path of currencyList.ts within the repository

# Test: Search for the file currencyList.ts
fd 'currencyList\.ts$'

Length of output: 24


Script:

#!/bin/bash
# Description: Search for the declaration of ASSETS_AS_CURRENCY_LIST in the entire codebase

# Test: Use ripgrep to find where ASSETS_AS_CURRENCY_LIST is defined
rg 'ASSETS_AS_CURRENCY_LIST\s*='

Length of output: 151

packages/extension-polkagate/src/fullscreen/homeFullScreen/partials/Currency.tsx (3)

9-9: LGTM: New import for Infotip2 component

The addition of the Infotip2 import is appropriate for enhancing the currency display with additional information, which aligns with the PR objective of adding Polkadot as a currency.


23-23: LGTM: Updated state type for currencyToShow

The change in the state type from string | undefined to CurrencyItemType | undefined is a good improvement. It allows for storing more detailed currency information, which is essential for supporting multiple currencies, including Polkadot. This change aligns well with the PR objective.


Line range hint 1-84: Overall assessment: Changes align well with PR objective

The modifications to the Currency component effectively enhance its ability to handle multiple currencies, including Polkadot. The changes in state management, rendering logic, and the addition of the Infotip2 component all contribute to a more robust and informative currency display.

A few minor suggestions have been made to further improve type safety and code organization. Once these are addressed, the implementation will be even more solid.

Great job on implementing these changes to support Polkadot as a new currency!

packages/extension-polkagate/src/fullscreen/homeFullScreen/components/CurrencySwitch.tsx (4)

24-24: Verify UI impact of increased default currencies

The increase of DEFAULT_CURRENCIES_TO_SHOW from 5 to 6 is likely to accommodate the addition of Polkadot as a new currency. This change aligns with the PR objective.

Please ensure that this change doesn't negatively impact the UI layout. Consider the following:

  1. Check if the UI can comfortably accommodate 6 default currencies without overflow or layout issues.
  2. Verify that this change is consistent with any design specifications or mockups.
  3. Test the component on various screen sizes to ensure responsiveness.

If possible, please provide a screenshot of the updated UI to confirm the layout remains intact.


102-102: Approve use of constant for consistency

The use of DEFAULT_CURRENCIES_TO_SHOW in the slice method instead of a hardcoded value is a good practice. It ensures consistency with the updated default count and improves maintainability.

This change aligns well with best practices in software development by avoiding magic numbers and using meaningful constants.


Line range hint 1-114: Summary of CurrencySwitch.tsx changes

The changes in this file successfully contribute to the PR objective of adding Polkadot as a currency. Key improvements include:

  1. Enhanced type safety with the use of CurrencyItemType.
  2. Increased flexibility by passing the full currency object.
  3. Consistent use of the DEFAULT_CURRENCIES_TO_SHOW constant.

These changes improve the overall quality and maintainability of the code. Please address the suggested verifications and consider the proposed optimizations to further enhance the component.


21-21: Approve type change and verify usage

The change from string | undefined to CurrencyItemType | undefined for setCurrencyToShow improves type safety and aligns with the PR objective. This is a good improvement.

To ensure consistency, please verify that all usages of setCurrencyToShow have been updated accordingly. Run the following script to check for any remaining string-based usages:

packages/extension-polkagate/src/util/currencyList.tsx (2)

6-11: LGTM! Improved structure for USD currency representation.

The update to the USD_CURRENCY constant provides a more structured and detailed representation of USD. This change makes it consistent with other currency entries in the CURRENCY_LIST, which is a good improvement for maintainability and consistency.


Line range hint 1-44: Overall, good implementation that achieves the PR objective.

The changes successfully add Polkadot as a currency and improve the structure of currency representations. The new ASSETS_AS_CURRENCY_LIST constant, updates to USD_CURRENCY, and modifications to CURRENCY_LIST are all well-implemented and consistent.

A few minor suggestions were made for further improvement:

  1. Adding a comment to explain the purpose of ASSETS_AS_CURRENCY_LIST.
  2. Considering a more standard or recognizable symbol for Polkadot in the CURRENCY_LIST.

These changes enhance the currency handling capabilities of the application and maintain good code quality.

@Nick-1979 Nick-1979 merged commit 6435c62 into main Oct 6, 2024
8 checks passed
@Nick-1979 Nick-1979 deleted the addDotCurrency branch October 6, 2024 11:43
github-actions bot pushed a commit that referenced this pull request Oct 6, 2024
# [0.17.0](v0.16.0...v0.17.0) (2024-10-06)

### Features

* add Polkadot as currency ([#1581](#1581)) ([6435c62](6435c62)), closes [#1578](#1578)
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.

add dot in currency list
1 participant