-
Notifications
You must be signed in to change notification settings - Fork 5
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
Conversation
WalkthroughThe 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 Changes
Possibly related PRs
Suggested labels
Suggested reviewers
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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:
- Adding a Polkadot currency constant (e.g.,
POLKADOT_CURRENCY
) alongsideUSD_CURRENCY
.- 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 Infotip2The 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 optimizationThe update to pass the entire
currency
object tosetCurrencyToShow
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:
- Updating Bitcoin and Ethereum to use full names improves clarity.
- 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:
- Using 'DOT' as the sign (like some other cryptocurrencies in the list).
- Using a dot symbol (•) to represent Polkadot.
- 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
📒 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 theCurrencyItem.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 typescriptLength 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 tsLength 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.tsIf 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:
- It generalizes the handling of crypto assets, making it easier to add new ones like Polkadot.
- The use of
ASSETS_AS_CURRENCY_LIST
allows for centralized management of supported crypto assets.- 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 CodebaseThe previous script failed to locate
currencyList.ts
. Please use the following script to search for the correct path ofcurrencyList.ts
within the repository:
Action Required: Locate Declaration of
ASSETS_AS_CURRENCY_LIST
in the CodebaseTo 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.tsLength 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.tsLength 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 componentThe 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 currencyToShowThe change in the state type from
string | undefined
toCurrencyItemType | 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 objectiveThe 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 theInfotip2
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 currenciesThe 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:
- Check if the UI can comfortably accommodate 6 default currencies without overflow or layout issues.
- Verify that this change is consistent with any design specifications or mockups.
- 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 consistencyThe 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 changesThe changes in this file successfully contribute to the PR objective of adding Polkadot as a currency. Key improvements include:
- Enhanced type safety with the use of
CurrencyItemType
.- Increased flexibility by passing the full currency object.
- 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 usageThe change from
string | undefined
toCurrencyItemType | undefined
forsetCurrencyToShow
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 theCURRENCY_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 toUSD_CURRENCY
, and modifications toCURRENCY_LIST
are all well-implemented and consistent.A few minor suggestions were made for further improvement:
- Adding a comment to explain the purpose of
ASSETS_AS_CURRENCY_LIST
.- 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.
closes #1578
Summary by CodeRabbit
Release Notes
New Features
Bug Fixes
Documentation
Chores