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 voting power to dev #1168

Merged
merged 2 commits into from
Oct 22, 2024
Merged

Fix voting power to dev #1168

merged 2 commits into from
Oct 22, 2024

Conversation

evilpeach
Copy link
Collaborator

@evilpeach evilpeach commented Oct 21, 2024

fix(components): chart voting power

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced a new utility function to streamline the retrieval of asset information for staking.
    • Enhanced the VotingPowerChartDetails component to better represent voting power changes over time.
  • Improvements

    • Updated components to use the new asset information structure, improving clarity and maintainability.
    • Optimized performance in the VotingPowerChartDetails component through memoization.
  • Bug Fixes

    • Improved error handling related to undefined asset information in the VotingPowerOverview component.
  • Documentation

    • Updated comments and documentation to reflect changes in the asset information structure and utility functions.

fix(components): chart voting power
@evilpeach evilpeach requested a review from songwongtp October 21, 2024 09:40
Copy link

coderabbitai bot commented Oct 21, 2024

Caution

Review failed

The head commit changed during the review from a1fa610 to 2b55b80.

Walkthrough

The changes in this pull request primarily involve the introduction of a new utility function getStakingAssetInfo to streamline the retrieval of asset information across multiple components. This function replaces previous inline logic for obtaining assetInfo, enhancing code clarity and maintainability. Additionally, several components, including VotingPowerChart, VotingPowerChartDetails, VotingPowerOverview, and various table components, have been updated to utilize this new function. Other modifications include renaming variables and optimizing performance with memoization, while preserving the overall structure and functionality of the affected components.

Changes

File Change Summary
src/lib/pages/validator-details/components/bonded-token-changes/VotingPowerChart.tsx Updated to use getStakingAssetInfo for obtaining assetInfo. Maintained existing structure and functionality.
src/lib/pages/validator-details/components/bonded-token-changes/VotingPowerChartDetails.tsx Renamed currentPrice to currentVotingPower. Updated logic for voting power change calculation to use useMemo.
src/lib/pages/validator-details/components/validator-overview/VotingPowerOverview.tsx Introduced getStakingAssetInfo for asset information retrieval. Simplified assignment of assetInfo.
src/lib/pages/validators/components/validators-table/ValidatorsTableMobileCard.tsx Replaced denomToken with assetInfo in props interface. Updated internal logic to utilize assetInfo.
src/lib/pages/validators/components/validators-table/ValidatorsTableRow.tsx Changed denomToken to assetInfo in props interface and internal logic.
src/lib/pages/validators/components/validators-table/index.tsx Replaced coinToTokenWithValue with getStakingAssetInfo. Updated props for ValidatorsTableMobileCard and ValidatorsTableRow to use assetInfo.
src/lib/utils/validator.ts Added getStakingAssetInfo function. Updated import statement to include new types.

Suggested reviewers

  • songwongtp

🐰 In the meadow, changes bloom,
A chart that dances, dispels the gloom.
Asset info, now clear and bright,
With memoized magic, it takes flight!
Hopping forward, we cheer and play,
For cleaner code has come our way! 🌼✨


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

vercel bot commented Oct 21, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
celatone-frontend-staging ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 21, 2024 10:52am
6 Skipped Deployments
Name Status Preview Comments Updated (UTC)
celatone-frontend-main ⬜️ Ignored (Inspect) Visit Preview Oct 21, 2024 10:52am
initia-celatone-frontend ⬜️ Ignored (Inspect) Visit Preview Oct 21, 2024 10:52am
neutron-celatone-frontend ⬜️ Ignored (Inspect) Visit Preview Oct 21, 2024 10:52am
osmosis-celatone-frontend ⬜️ Ignored (Inspect) Visit Preview Oct 21, 2024 10:52am
sei-celatone-frontend ⬜️ Ignored (Inspect) Visit Preview Oct 21, 2024 10:52am
terra-celatone-frontend ⬜️ Ignored (Inspect) Visit Preview Oct 21, 2024 10:52am

Copy link

@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

🧹 Outside diff range and nitpick comments (6)
src/lib/utils/validator.ts (1)

34-52: LGTM: New getStakingAssetInfo function implemented correctly.

The function is well-implemented and serves its purpose of retrieving asset information based on a staking denomination. The use of optional parameters and return type is appropriate.

A couple of minor points to consider:

  1. The comment on line 39 mentions "initia case". Is this a typo for "initial case", or is it specific to your project?
  2. The default precision value is set to 6. Please verify if this is the correct default value for your project.

Consider clarifying the comment on line 39 and double-checking the default precision value to ensure it aligns with your project's requirements.

src/lib/pages/validator-details/components/bonded-token-changes/VotingPowerChartDetails.tsx (1)

50-61: LGTM: Improved performance and precision with useMemo

The implementation of useMemo for compareVotingPower calculation is a good optimization. The new logic accurately considers 24 hours of historical data when available, with a safe fallback to zero.

Consider adding a check for the array length before accessing the 25th last item to prevent potential errors with shorter historical data:

const yesterdayVotingPower =
  historicalPowers.items.length >= 25
    ? historicalPowers.items[historicalPowers.items.length - 25].votingPower
    : big(0);

This change would make the code more robust against potential edge cases with limited historical data.

src/lib/pages/validators/components/validators-table/ValidatorsTableRow.tsx (2)

30-30: LGTM: Props interface updated correctly.

The change from denomToken: Option<TokenWithValue> to assetInfo: Option<AssetInfo> is consistent with the overall refactoring. This update improves type safety and aligns with the new asset information handling approach.

Consider adding a comment explaining the purpose of assetInfo for better code documentation:

/** Information about the asset used for voting power calculations */
assetInfo: Option<AssetInfo>;

96-101: LGTM: JSX updated correctly to use assetInfo.

The changes in the JSX are consistent with the shift from denomToken to assetInfo. The use of optional chaining is maintained, which is good for handling potential null values. The getTokenLabel function now correctly receives assetInfo.id and assetInfo.symbol.

For consistency, consider using optional chaining for assetInfo.symbol as well:

? ` ${getTokenLabel(assetInfo.id, assetInfo?.symbol)}`

This ensures that the code handles cases where symbol might be undefined, maintaining consistency with how id is accessed.

src/lib/pages/validators/components/validators-table/ValidatorsTableMobileCard.tsx (1)

27-27: LGTM: Props interface updated correctly.

The change from denomToken: Option<TokenWithValue> to assetInfo: Option<AssetInfo> is consistent with the overall refactoring. This update improves type safety and aligns with the new asset information structure.

Consider adding a comment explaining the AssetInfo type for better code documentation:

/** Asset information including precision, symbol, and other relevant details */
assetInfo: Option<AssetInfo>;
src/lib/pages/validator-details/components/validator-overview/VotingPowerOverview.tsx (1)

102-102: LGTM: Improved asset info retrieval.

The use of getStakingAssetInfo simplifies the code and potentially improves error handling. This change aligns with the goal of streamlining asset information retrieval across components.

Consider adding a comment explaining the purpose of getStakingAssetInfo for better code documentation:

// Retrieve staking asset info using the new utility function
const assetInfo = getStakingAssetInfo(singleStakingDenom, assetInfos);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 59a7e5b and 58ebaad.

📒 Files selected for processing (7)
  • src/lib/pages/validator-details/components/bonded-token-changes/VotingPowerChart.tsx (2 hunks)
  • src/lib/pages/validator-details/components/bonded-token-changes/VotingPowerChartDetails.tsx (4 hunks)
  • src/lib/pages/validator-details/components/validator-overview/VotingPowerOverview.tsx (2 hunks)
  • src/lib/pages/validators/components/validators-table/ValidatorsTableMobileCard.tsx (3 hunks)
  • src/lib/pages/validators/components/validators-table/ValidatorsTableRow.tsx (4 hunks)
  • src/lib/pages/validators/components/validators-table/index.tsx (4 hunks)
  • src/lib/utils/validator.ts (2 hunks)
🧰 Additional context used
🔇 Additional comments (22)
src/lib/utils/validator.ts (2)

4-4: LGTM: Import statement updated correctly.

The import statement has been properly updated to include the new types (AssetInfo, AssetInfos, and Option) required for the new getStakingAssetInfo function. This change is consistent with the function's implementation and improves type safety.


Line range hint 1-52: Overall, the changes in this file are well-implemented and improve code reusability.

The introduction of the getStakingAssetInfo function centralizes asset information retrieval, which aligns with the PR's objective of fixing voting power-related issues. This change will likely improve maintainability and reduce code duplication across the project.

The implementation is type-safe, handles edge cases appropriately, and doesn't modify existing code, minimizing the risk of introducing new bugs. These changes provide a solid foundation for addressing the voting power issues mentioned in the PR description.

src/lib/pages/validator-details/components/bonded-token-changes/VotingPowerChartDetails.tsx (3)

3-3: LGTM: Import of useMemo added

The addition of useMemo import is appropriate for the performance optimization implemented in this component.


Line range hint 40-47: LGTM: Variable renamed for clarity

The renaming of currentPrice to currentVotingPower improves code readability by more accurately reflecting the nature of the stored data. The calculation logic remains correct and consistent with the previous implementation.


76-76: LGTM: Consistent variable usage in component output

The update from currentPrice to currentVotingPower in the component's output is consistent with the earlier variable renaming, ensuring that the correct value is displayed in the UI.

src/lib/pages/validators/components/validators-table/ValidatorsTableRow.tsx (3)

9-9: LGTM: Import statement updated correctly.

The addition of AssetInfo to the import statement is consistent with the changes in the component's props and aligns with the overall refactoring to use AssetInfo instead of TokenWithValue.


40-40: LGTM: Component parameter updated correctly.

The change from denomToken to assetInfo in the destructured parameters is consistent with the updated props interface. This ensures that the component function signature matches the new props structure.


Line range hint 1-134: Summary: Successful refactoring to use assetInfo instead of denomToken.

The changes in this file successfully refactor the ValidatorsTableRow component to use assetInfo instead of denomToken. This modification aligns with the PR objectives and the changes described in the AI-generated summary. The refactoring improves the component by using a more appropriate data structure for asset information, which should enhance maintainability and consistency across the application.

Key points:

  1. Import statements, props interface, and component parameters have been updated correctly.
  2. JSX changes are consistent with the new assetInfo structure.
  3. Type safety is maintained through the use of optional chaining and nullish coalescing.

The suggested minor improvements (adding a comment for assetInfo prop and using optional chaining for assetInfo.symbol) would further enhance code quality and consistency.

Overall, these changes contribute positively to the "Fix voting power to dev" objective of the pull request.

src/lib/pages/validators/components/validators-table/index.tsx (5)

14-14: LGTM: New import statement is appropriate.

The addition of the getStakingAssetInfo import is consistent with the changes in the component logic and follows good practices by importing utility functions from a centralized location.


69-69: Great refactoring: Improved code clarity and maintainability.

The introduction of assetInfo using the getStakingAssetInfo function is a positive change. It encapsulates the logic for obtaining asset information, simplifying the component and improving code readability. This refactoring aligns well with the principle of keeping components focused on their primary responsibilities.


Line range hint 1-126: Overall: Excellent refactoring that improves code quality.

The changes in this file significantly improve code clarity and maintainability by introducing the getStakingAssetInfo utility function and consistently updating its usage across the component and its children. These modifications align well with the PR objectives of fixing the voting power in the chart component.

To ensure full compatibility:

  1. Verify that the ValidatorsTableMobileCard component has been updated to use assetInfo.
  2. Verify that the ValidatorsTableRow component has been updated to use assetInfo.

Great job on this refactoring!


108-108: Prop update is consistent: Verify ValidatorsTableRow implementation.

The change from denomToken to assetInfo in the ValidatorsTableRow props is consistent with the earlier modifications. This ensures that the table row component receives the correct data structure.

To ensure full compatibility, please verify that the ValidatorsTableRow component has been updated to use assetInfo instead of denomToken. Run the following script to check the implementation:

#!/bin/bash
# Description: Verify ValidatorsTableRow implementation
# Test: Check if ValidatorsTableRow uses assetInfo prop
rg -A 5 'interface ValidatorsTableRowProps' src/lib/pages/validators/components/validators-table/ValidatorsTableRow.tsx
rg 'assetInfo:' src/lib/pages/validators/components/validators-table/ValidatorsTableRow.tsx

83-83: Prop update is consistent: Verify ValidatorsTableMobileCard implementation.

The change from denomToken to assetInfo in the ValidatorsTableMobileCard props is consistent with the earlier modifications. This ensures that the mobile card component receives the correct data structure.

To ensure full compatibility, please verify that the ValidatorsTableMobileCard component has been updated to use assetInfo instead of denomToken. Run the following script to check the implementation:

✅ Verification successful

Validation Successful: ValidatorsTableMobileCard uses assetInfo prop.

The assetInfo prop in ValidatorsTableMobileCard.tsx is correctly implemented, ensuring the component receives the appropriate data structure.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify ValidatorsTableMobileCard implementation
# Test: Check if ValidatorsTableMobileCard uses assetInfo prop
rg -A 5 'interface ValidatorsTableMobileCardProps' src/lib/pages/validators/components/validators-table/ValidatorsTableMobileCard.tsx
rg 'assetInfo:' src/lib/pages/validators/components/validators-table/ValidatorsTableMobileCard.tsx

Length of output: 580


Script:

#!/bin/bash
# Description: Verify ValidatorsTableMobileCard implementation with corrected file path
# Test 1: Check if ValidatorsTableMobileCard.tsx exists
if [ -f src/lib/pages/validators/components/validators-table/ValidatorsTableMobileCard.tsx ]; then
  echo "ValidatorsTableMobileCard.tsx exists."
else
  echo "ValidatorsTableMobileCard.tsx does not exist."
  exit 1
fi

# Test 2: Check if ValidatorsTableMobileCard uses assetInfo prop
rg 'assetInfo:' src/lib/pages/validators/components/validators-table/ValidatorsTableMobileCard.tsx

Length of output: 311

src/lib/pages/validators/components/validators-table/ValidatorsTableMobileCard.tsx (4)

8-8: LGTM: Import statement updated correctly.

The addition of AssetInfo to the import statement is consistent with the changes in the component props and aligns with the overall refactoring to use AssetInfo instead of TokenWithValue.


35-35: LGTM: Props destructuring updated correctly.

The change from denomToken to assetInfo in the props destructuring is consistent with the interface update and ensures that the component uses the new assetInfo prop correctly.


Line range hint 1-160: Overall: Changes look good, with minor suggestions for improvement.

The modifications to ValidatorsTableMobileCard.tsx are consistent with the PR objectives and the AI-generated summary. The changes successfully refactor the component to use AssetInfo instead of TokenWithValue, improving consistency across the application.

Key points:

  1. Import statements, props interface, and component implementation are all updated correctly.
  2. Type safety and null-safety are maintained throughout the changes.
  3. The refactoring aligns well with the broader changes mentioned in the AI-generated summary.

Minor suggestions:

  1. Consider adding a comment to explain the AssetInfo type in the props interface.
  2. Verify that the getTokenLabel function correctly handles the new assetInfo.id and assetInfo.symbol arguments.

These changes contribute to a more consistent and maintainable codebase.


95-101: LGTM: JSX updated correctly, but verify getTokenLabel usage.

The changes from denomToken to assetInfo in the JSX are consistent with the overall refactoring. The null-safety is maintained with the use of optional chaining.

Please verify that the getTokenLabel function correctly handles assetInfo.id and assetInfo.symbol as arguments, as they might have different semantics than the previous denomToken.denom and denomToken.symbol.

✅ Verification successful

LGTM: getTokenLabel is consistently used with assetInfo.id and assetInfo.symbol across the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of getTokenLabel function

# Test: Search for the getTokenLabel function definition
rg -A 10 'function getTokenLabel'

# Test: Search for other usages of getTokenLabel in the codebase
rg 'getTokenLabel\('

Length of output: 4696

src/lib/pages/validator-details/components/bonded-token-changes/VotingPowerChart.tsx (3)

17-17: LGTM: New utility function import.

The import of getStakingAssetInfo from 'lib/utils' is correctly placed and seems relevant to the component's functionality.


45-45: LGTM: Improved asset info retrieval.

The use of getStakingAssetInfo simplifies the code and improves maintainability by centralizing the logic for obtaining asset information. This change is consistent with the component's previous behavior and doesn't require any further adjustments in the component.


Line range hint 1-180: Summary: Improved asset info retrieval in VotingPowerChart

The changes in this file enhance the VotingPowerChart component by introducing the getStakingAssetInfo utility function. This modification improves code maintainability and readability without altering the component's core functionality. The change aligns with the PR objective of addressing voting power in the chart component by refining the asset information retrieval process.

Some suggestions for further improvement:

  1. Consider adding a comment explaining the purpose of getStakingAssetInfo for better documentation.
  2. Ensure that error handling in getStakingAssetInfo is robust, as the component relies on its output.

To ensure the changes don't introduce any regressions, please run the following verification script:

src/lib/pages/validator-details/components/validator-overview/VotingPowerOverview.tsx (2)

22-22: LGTM: New utility function import added.

The addition of getStakingAssetInfo to the import list is consistent with the changes described in the AI summary. This new utility function will help streamline the retrieval of asset information across components.


Line range hint 1-224: Overall assessment: Positive improvement in code quality.

The changes in this file successfully introduce the new getStakingAssetInfo utility function and integrate it into the VotingPowerOverview component. This modification enhances code clarity and maintainability by centralizing the logic for retrieving asset information.

Key points:

  1. The changes align with the PR objectives of addressing voting power-related issues.
  2. The core functionality of the component remains intact.
  3. Code readability and potential error handling have been improved.

No potential issues or regressions are apparent from these changes. The refactoring appears to be a solid improvement to the codebase.

@songwongtp songwongtp merged commit 3fbee85 into develop Oct 22, 2024
16 checks passed
@songwongtp songwongtp deleted the fix/voting-power-dev branch October 22, 2024 07:17
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.

2 participants