Skip to content

fix: disable manage validators if the account is already a validator #1634

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

Merged
merged 1 commit into from
Nov 9, 2024

Conversation

Nick-1979
Copy link
Member

@Nick-1979 Nick-1979 commented Nov 9, 2024

Screenshot 2024-11-09 at 12 28 47

Summary by CodeRabbit

Release Notes

  • New Features

    • The StakedSolo component now includes validator status checks, enhancing the user experience by providing relevant information about account validation.
    • The ActiveValidators and CommonTasks components have been updated to utilize the new validator status prop, improving rendering logic and user feedback.
  • Bug Fixes

    • Adjusted button states and visual feedback in CommonTasks based on the validator status, ensuring accurate representation of user actions.

@Nick-1979 Nick-1979 requested a review from AMIRKHANEF November 9, 2024 08:59
Copy link
Contributor

coderabbitai bot commented Nov 9, 2024

Walkthrough

The changes in this pull request involve modifications to the StakedSolo, ActiveValidators, and CommonTasks components. The primary update includes the integration of a new prop, isValidator, which is derived from the useIsValidator hook in StakedSolo and passed down to the other components. The changes streamline the logic for determining validator status, enhancing the components' rendering behavior based on whether the account is a validator.

Changes

File Path Change Summary
packages/extension-polkagate/src/fullscreen/stake/solo/StakedSolo.tsx - Added isValidator variable from useIsValidator(address).
- Updated function signature for consistency.
- Passed isValidator prop to ActiveValidators and CommonTasks.
packages/extension-polkagate/src/fullscreen/stake/solo/partials/ActiveValidators.tsx - Added isValidator to Props interface.
- Updated function signature to accept isValidator.
- Removed internal useIsValidator call, using prop instead.
packages/extension-polkagate/src/fullscreen/stake/solo/partials/CommonTasks.tsx - Added isValidator to Props interface.
- Updated function signature to include isValidator.
- Modified button logic to consider isValidator.

Possibly related PRs

Suggested reviewers

  • AMIRKHANEF

🐰 In the meadow where bunnies play,
A validator's status lights the way.
With props and hooks, we dance and twirl,
Enhancing our world, watch it unfurl!
Hops of joy as we stake and cheer,
For every change, our vision is clear! 🌼


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

🧹 Outside diff range and nitpick comments (2)
packages/extension-polkagate/src/fullscreen/stake/solo/partials/CommonTasks.tsx (1)

83-84: Consider simplifying the conditional logic

The bounce and color conditions share the same logic (!!stakedButNoValidators && !isValidator). Consider extracting this to a variable for better maintainability.

+ const shouldHighlight = !!stakedButNoValidators && !isValidator;
  <FontAwesomeIcon
-   bounce={!!stakedButNoValidators && !isValidator}
-   color={stakedButNoValidators && !isValidator ? `${theme.palette.warning.main}` : `${iconColor}`}
+   bounce={shouldHighlight}
+   color={shouldHighlight ? `${theme.palette.warning.main}` : `${iconColor}`}
    fontSize='22px'
    icon={faHand}
  />
packages/extension-polkagate/src/fullscreen/stake/solo/partials/ActiveValidators.tsx (1)

Line range hint 108-121: Consider refining the loading state logic.

The current condition activeValidators === undefined || isValidator === undefined might show loading skeletons in cases where only one of these values is undefined. Consider handling these states separately for more precise user feedback.

Here's a suggested improvement:

-          : activeValidators === undefined || isValidator === undefined
+          : activeValidators === undefined
             ? <Grid container>
                 <Skeleton
                   animation='wave'
                   height='20px'
                   sx={{ display: 'inline-block', fontWeight: 'bold', my: '5px', transform: 'none', width: '100%' }}
                 />
               </Grid>
+            : isValidator === undefined
+              ? <Typography color='text.primary' fontSize='16px' fontWeight={400}>
+                  {t('Checking validator status...')}
+                </Typography>
             : isValidator
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 6825130 and b49f1fa.

📒 Files selected for processing (3)
  • packages/extension-polkagate/src/fullscreen/stake/solo/StakedSolo.tsx (3 hunks)
  • packages/extension-polkagate/src/fullscreen/stake/solo/partials/ActiveValidators.tsx (1 hunks)
  • packages/extension-polkagate/src/fullscreen/stake/solo/partials/CommonTasks.tsx (2 hunks)
🔇 Additional comments (9)
packages/extension-polkagate/src/fullscreen/stake/solo/partials/CommonTasks.tsx (3)

22-22: LGTM: Well-typed prop addition

The isValidator prop type appropriately handles all possible states (true/false/null/undefined) for validator status.


25-25: LGTM: Component signature properly updated

The function signature correctly includes the new isValidator prop while maintaining the existing structure.


80-80: LGTM: Validator management correctly disabled

The disabled condition properly implements the PR objective by preventing validator management for existing validators while maintaining the original staking-related checks.

packages/extension-polkagate/src/fullscreen/stake/solo/partials/ActiveValidators.tsx (3)

16-16: LGTM! Clean interface update.

The removal of the useIsValidator hook and addition of the isValidator prop aligns well with the component's new responsibility model. The type definition properly handles all possible states.

Also applies to: 21-22


25-25: LGTM! Clean function signature update.

The component signature has been properly updated to match the Props interface while maintaining good TypeScript practices.


Line range hint 1-143: Verify consistent usage of isValidator prop.

The implementation successfully handles validator status through props, but let's verify that all parent components are passing the prop correctly.

✅ Verification successful

Props usage is consistent and properly implemented

The verification shows that:

  • ActiveValidators component is used in StakedSolo.tsx with the isValidator prop correctly passed
  • The isValidator value comes from a dedicated hook useIsValidator which properly handles all states (boolean | null | undefined)
  • The implementation matches the component's prop interface and handling logic
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for consistent usage of isValidator prop in parent components

# Search for components that render ActiveValidators
rg -l "ActiveValidators" --type tsx

# Check the prop usage in those files
rg -A 5 "<ActiveValidators" --type tsx

Length of output: 132


Script:

#!/bin/bash
# Let's try without file type filtering since tsx extension is not recognized
# First find files containing ActiveValidators
rg -l "ActiveValidators"

# Then check usage patterns
rg -A 5 "<ActiveValidators"

Length of output: 901


Script:

#!/bin/bash
# Let's check how isValidator is determined in the parent component
rg -B 10 -A 5 "isValidator.*=.*" packages/extension-polkagate/src/fullscreen/stake/solo/StakedSolo.tsx

Length of output: 1445


Script:

#!/bin/bash
# Let's check the implementation of useIsValidator hook
rg -A 10 "useIsValidator" packages/extension-polkagate/src/hooks/

Length of output: 2286

packages/extension-polkagate/src/fullscreen/stake/solo/StakedSolo.tsx (3)

6-7: LGTM! Clean import organization.

The import changes are well-structured, with types properly separated and the new useIsValidator hook correctly imported.

Also applies to: 15-15


40-40: LGTM! Proper hook integration.

The useIsValidator hook is correctly implemented and follows React hooks best practices.


152-152: Verify prop handling in child components.

The isValidator prop is correctly passed to both components. However, let's verify that ActiveValidators and CommonTasks components properly handle this prop to disable validator management functionality.

Also applies to: 156-156

✅ Verification successful

Let me analyze the usage of isValidator prop in both components to ensure proper handling.


Based on the comprehensive code analysis, I can now generate the final response:

The isValidator prop is properly handled in both components

Both ActiveValidators and CommonTasks components correctly implement and use the isValidator prop:

  • In CommonTasks:

    • Disables validator management button when isValidator === true
    • Uses prop to control warning indicators for non-validator accounts
    • Properly typed as boolean | null | undefined
  • In ActiveValidators:

    • Shows appropriate UI states based on validator status
    • Displays "This account is a validator!" message when isValidator === true
    • Properly typed as boolean | null | undefined
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of isValidator prop in child components

# Check ActiveValidators implementation
echo "Checking ActiveValidators implementation:"
ast-grep --pattern 'interface Props {
  $$$
  isValidator?: boolean;
  $$$
}' packages/extension-polkagate/src/fullscreen/stake/solo/partials/ActiveValidators.tsx

# Check CommonTasks implementation
echo "Checking CommonTasks implementation:"
ast-grep --pattern 'interface Props {
  $$$
  isValidator?: boolean;
  $$$
}' packages/extension-polkagate/src/fullscreen/stake/solo/partials/CommonTasks.tsx

# Check how isValidator is used in these components
echo "Checking isValidator usage:"
rg "isValidator" packages/extension-polkagate/src/fullscreen/stake/solo/partials/

Length of output: 2015


Script:

#!/bin/bash
# Get more context around the isValidator usage in CommonTasks
echo "CommonTasks isValidator usage context:"
rg "isValidator" -B 2 -A 2 packages/extension-polkagate/src/fullscreen/stake/solo/partials/CommonTasks.tsx

# Get more context around the isValidator usage in ActiveValidators
echo "ActiveValidators isValidator usage context:"
rg "isValidator" -B 2 -A 2 packages/extension-polkagate/src/fullscreen/stake/solo/partials/ActiveValidators.tsx

# Check if there are any validator-related functions or conditions
echo "Checking validator-related logic:"
rg "validator|Validator" -B 2 -A 2 packages/extension-polkagate/src/fullscreen/stake/solo/partials/

Length of output: 65709

@Nick-1979 Nick-1979 merged commit 89d56c4 into main Nov 9, 2024
8 checks passed
github-actions bot pushed a commit that referenced this pull request Nov 9, 2024
## [0.23.1](v0.23.0...v0.23.1) (2024-11-09)

### Bug Fixes

* disable manage validators if the account is already a validator ([#1634](#1634)) ([89d56c4](89d56c4))
@coderabbitai coderabbitai bot mentioned this pull request Nov 9, 2024
@Nick-1979 Nick-1979 deleted the disableManageValidatorsForValidator branch December 30, 2024 09:15
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.

1 participant