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

fix: asset requested issue while currency is something other than USD #1594

Merged
merged 3 commits into from
Oct 23, 2024

Conversation

Nick-1979
Copy link
Member

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

closes #1588

Screenshot 2024-10-22 at 12 11 15

Screenshot 2024-10-22 at 12 12 01

Summary by CodeRabbit

  • New Features

    • Introduced a new custom hook, useReferendaRequested, for improved management of referendum-related data.
    • Enhanced Metadata and ReferendumDescription components to utilize the new hook for better clarity in displaying asset and currency information.
  • Bug Fixes

    • Streamlined the logic for displaying requested amounts by removing deprecated calculations and dependencies.
  • Documentation

    • Updated interfaces to include additional properties for more detailed price information.
  • Refactor

    • Reorganized state management within components to improve maintainability and performance.

@Nick-1979 Nick-1979 requested a review from AMIRKHANEF October 22, 2024 08:42
Copy link
Contributor

coderabbitai bot commented Oct 22, 2024

Walkthrough

The changes in this pull request involve the introduction of a new custom hook, useReferendaRequested, which replaces the previous logic for handling token pricing in the ReferendumDescription and Metadata components. The useTokenPrice hook has been modified to accommodate additional parameters for improved asset information handling. The Price interface has been updated to include new properties, enhancing the data structure. Overall, the modifications streamline the management of referendum-related data and improve the clarity of how financial information is represented.

Changes

File Path Change Summary
packages/extension-polkagate/src/fullscreen/governance/post/Description.tsx Removed useTokenPrice import and replaced its logic with useReferendaRequested. Updated props in ShowBalance and FormatPrice components.
packages/extension-polkagate/src/fullscreen/governance/post/Metadata.tsx Added useReferendaRequested hook and updated state variables. Minor formatting change in function signature.
packages/extension-polkagate/src/fullscreen/governance/post/useReferendaRequested.tsx Introduced new hook useReferendaRequested for managing referendum data, including an interface for its return type.
packages/extension-polkagate/src/hooks/useTokenPrice.ts Updated function signature to include new parameters and refactored internal logic to handle additional asset information.
packages/extension-polkagate/src/util/types.ts Added decimal and token properties to the Price interface.

Assessment against linked issues

Objective Addressed Explanation
Align currency sign with selected currency in Governance Requested (#1588)

Possibly related PRs

Suggested labels

bug

Suggested reviewers

  • AMIRKHANEF

Poem

In the governance land, oh what a sight,
A new hook appears, making things right.
Currency signs dance, no longer a bore,
With prices aligned, we’ll ask for more!
Hopping through changes, we cheer with glee,
For a brighter future, just wait and see! 🐰✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between ffe3bce and 14c8416.

📒 Files selected for processing (1)
  • packages/extension-polkagate/src/fullscreen/governance/post/useReferendaRequested.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/extension-polkagate/src/fullscreen/governance/post/useReferendaRequested.tsx

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: 3

🧹 Outside diff range and nitpick comments (5)
packages/extension-polkagate/src/fullscreen/governance/post/Metadata.tsx (1)

78-79: LGTM: Implemented currency-specific values using new hook.

The introduction of useReferendaRequested and the use of rDecimal and rToken align well with the PR objectives to fix currency display issues. This change should ensure that the correct currency sign is displayed for the referendum.

Consider adding explicit type annotations for improved type safety:

const { rDecimal, rToken }: { rDecimal: number, rToken: string } = useReferendaRequested(address, referendum);

Also applies to: 186-188

packages/extension-polkagate/src/util/types.ts (1)

617-618: LGTM! Consider adding JSDoc comments for clarity.

The additions of decimal and token properties to the Price interface are appropriate and align well with the PR objectives. These changes will enable more accurate handling of different currencies.

Consider adding JSDoc comments to explain the purpose of these new properties:

export interface Price {
  price: number;
  /** The number of decimal places for the price */
  decimal: number;
  /** The currency symbol or identifier */
  token: string;
  priceChainName: string;
  priceDate: number;
}
packages/extension-polkagate/src/fullscreen/governance/post/useReferendaRequested.tsx (1)

11-14: Enhance property names for better readability

The properties rAssetInCurrency, rCurrencySign, rDecimal, and rToken could be more descriptive without the r prefix. Renaming them improves clarity and aligns with common naming conventions.

Apply this diff to rename the properties:

 interface ReferendaRequested {
-  rAssetInCurrency?: number,
-  rCurrencySign?: string,
-  rDecimal?: number,
-  rToken?: string
+  assetInCurrency?: number,
+  currencySign?: string,
+  decimal?: number,
+  token?: string
 }

Remember to update all occurrences of these property names throughout the code to reflect the changes.

packages/extension-polkagate/src/hooks/useTokenPrice.ts (2)

28-29: Improve JSDoc comments for assetId and assetChainName parameters

The descriptions for the parameters can be clarified for better understanding.

Suggested changes:

 * @param assetId : asset ID on multi-asset chains
- * @param assetChainName : chain name to fetch asset id price from
+ * @param assetChainName : name of the chain to fetch the asset price from

68-68: Consider using toLowerCase() instead of toLocaleLowerCase() for priceChainName

Using toLowerCase() provides consistent lowercasing without locale-specific variations, which is suitable for chain names.

Suggested change:

-          priceChainName: _chainName?.toLocaleLowerCase(),
+          priceChainName: _chainName?.toLowerCase(),
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between b2ca99d and ffe3bce.

📒 Files selected for processing (5)
  • packages/extension-polkagate/src/fullscreen/governance/post/Description.tsx (4 hunks)
  • packages/extension-polkagate/src/fullscreen/governance/post/Metadata.tsx (3 hunks)
  • packages/extension-polkagate/src/fullscreen/governance/post/useReferendaRequested.tsx (1 hunks)
  • packages/extension-polkagate/src/hooks/useTokenPrice.ts (2 hunks)
  • packages/extension-polkagate/src/util/types.ts (1 hunks)
🧰 Additional context used
🔇 Additional comments (19)
packages/extension-polkagate/src/fullscreen/governance/post/Metadata.tsx (3)

24-24: LGTM: New hook import added.

The import of useReferendaRequested is correctly placed and aligns with the PR objectives to address currency display issues.


26-26: LGTM: Minor formatting improvement.

The addition of a space after the function name in hexAddressToFormatted improves code readability and consistency.


24-24: Overall assessment: Changes effectively address the PR objectives.

The introduction of the useReferendaRequested hook and the use of rDecimal and rToken in the Metadata component successfully address the currency display issue mentioned in the PR objectives. These changes ensure that the correct currency sign is displayed for the referendum, improving the accuracy of financial representations in the application.

The implementation is consistent with updates in other components, as mentioned in the AI summary, indicating a cohesive approach to solving the issue across the application.

Also applies to: 26-26, 78-79, 186-188

packages/extension-polkagate/src/util/types.ts (1)

617-618: Verify usage of updated Price interface across the codebase

While the changes to the Price interface are non-breaking, it's important to ensure that other parts of the codebase are updated to utilize these new properties for improved currency handling.

Let's check the usage of the Price interface across the codebase:

✅ Verification successful

Regenerate search scripts for Price interface usage

The previous search encountered issues recognizing the typescript file type. Please use the following updated shell scripts to accurately search for the Price interface and its new properties:


Usage of updated Price interface is correctly handled

All instances of the Price interface have been checked, and no existing code utilizes the new decimal or token properties. This indicates that the changes are non-breaking and do not affect the current codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for usages of the Price interface
echo "Searching for Price interface usage:"
rg --type typescript "Price(\s*[:{]|\[\])" -g '!**/types.ts'

# Search for places where price.decimal or price.token might be needed
echo "\nSearching for potential places to use new Price properties:"
rg --type typescript "price\.(price|priceChainName|priceDate)" -g '!**/types.ts'

Length of output: 431


Script:

# Search for usages of the Price interface in TypeScript files
rg "Price(\s*[:{]|\[\])" -g "*.ts" -g "*.tsx"

# Search for places where price.decimal or price.token might be needed in TypeScript files
rg "price\.(decimal|token)" -g "*.ts" -g "*.tsx"

Length of output: 1773

packages/extension-polkagate/src/hooks/useTokenPrice.ts (8)

16-20: Addition of new properties to DEFAULT_PRICE enhances clarity

The inclusion of decimal, priceDate, and token in the DEFAULT_PRICE object ensures that all expected properties are explicitly defined, improving code readability and preventing potential undefined property access.


32-32: Function signature updated appropriately to include assetChainName

The addition of the assetChainName parameter enhances the flexibility of the useTokenPrice hook by allowing price retrieval based on a specified chain name.


33-33: Destructuring of useInfo results is appropriate

The destructuring correctly retrieves addressChainName, decimal, genesisHash, and token from useInfo(address).


36-36: Assignment of _chainName prioritizes assetChainName appropriately

Setting _chainName to assetChainName if provided, otherwise falling back to addressChainName, ensures that the correct chain name is used for price retrieval.


50-50: Inclusion of _chainName in null-check condition ensures robustness

Adding _chainName to the condition prevents potential errors when chain information is missing, enhancing the reliability of the function.


59-59: Correct determination of priceId

The logic prioritizes maybeAssetInfo?.priceId, falling back to userAddedPriceId or getPriceIdByChainName(_chainName), which is appropriate for accurate price identification.


62-63: Appropriate assignment of _decimal and _token

Using maybeAssetInfo to obtain _decimal and _token enhances accuracy when asset-specific information is available, while defaulting to existing values ensures reliability.


69-70: Inclusion of priceDate and token in returned object

Adding priceDate and token to the return value ensures that consumers have access to the most recent price information and the token symbol.

packages/extension-polkagate/src/fullscreen/governance/post/Description.tsx (7)

18-18: Imports are appropriate and necessary.

The useInfo and useTranslation hooks are correctly imported from '../../../hooks' for use within this component.


24-24: New hook useReferendaRequested imported successfully.

The useReferendaRequested hook is imported from './useReferendaRequested', which is necessary for retrieving referendum-related data.


39-39: Proper utilization of useInfo hook.

Destructuring api and chain from useInfo(address) ensures that the component has access to necessary blockchain information based on the provided address.


41-41: Destructuring values from useReferendaRequested hook.

The variables rAssetInCurrency, rCurrencySign, rDecimal, and rToken are correctly obtained from the useReferendaRequested hook, which streamlines data management for the referendum.


130-132: Updated ShowBalance component props for consistency.

The decimal and token props now use rDecimal and rToken, ensuring that the displayed balance aligns with the selected currency and decimal precision.


151-153: Validate status color mappings and display labels.

Ensure that all possible values of referendum.status have corresponding entries in STATUS_COLOR and that the displayed status labels are correctly formatted for user clarity.

Run the following script to verify that all statuses are properly handled:

#!/bin/bash
# Description: Check that STATUS_COLOR includes all statuses used by referendum.status.

# Test: List all keys in STATUS_COLOR.
rg 'const STATUS_COLOR = {(.*)}' --type=tsx --only-matching --replace '$1'

# List all unique statuses used in the codebase.
rg 'referendum\?\.status' --type=tsx --only-matching --replace '$&'

# Expected: All statuses from referendum?.status should be keys in STATUS_COLOR.

142-143: Ensure currency sign and value reflect the selected currency.

The FormatPrice component now uses rAssetInCurrency and rCurrencySign, which should display the correct price and currency sign based on the user's selection. Please verify that these values update appropriately with different currency settings.

Run the following script to confirm that rCurrencySign and rAssetInCurrency are correctly set according to the selected currency:

@Nick-1979 Nick-1979 self-assigned this Oct 23, 2024
@Nick-1979 Nick-1979 merged commit 9083e0b into main Oct 23, 2024
8 checks passed
@Nick-1979 Nick-1979 deleted the assetRequestIssueOnGov branch October 23, 2024 05:07
github-actions bot pushed a commit that referenced this pull request Oct 23, 2024
## [0.19.4](v0.19.3...v0.19.4) (2024-10-23)

### Bug Fixes

* asset requested issue while currency is something other than USD ([#1594](#1594)) ([9083e0b](9083e0b))
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.

currency sign on Governance Requested is always $, needs to be aligned with selected currency
1 participant