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

Its possible to nominate a slashed or deregistered op #838

Conversation

marc-aurele-besner
Copy link
Collaborator

@marc-aurele-besner marc-aurele-besner commented Aug 28, 2024

User description

Its possible to nominate a slashed or deregistered op

Following some change in status the logic was broken, I improved the logic


PR Type

enhancement, bug fix


Description

  • Enhanced the logic for excluding actions in the NominationsTable and OperatorsList components by using enums for operator status and pending actions.
  • Added pending_action field to the operator type in GraphQL queries to improve data handling.
  • Introduced new enums in constants/staking.ts to standardize operator and nominator statuses and actions.
  • Updated filter options in constants/tables.ts to use the new OperatorStatus enum.
  • Bumped the storage version for table states to ensure compatibility with the updated logic.

Changes walkthrough 📝

Relevant files
Enhancement
staking.ts
Add pending_action field to operator type                               

explorer/gql/types/staking.ts

  • Added pending_action field to the operator type in
    NominationsListQuery.
  • +1/-1     
    NominationsTable.tsx
    Update action exclusion logic using enums                               

    explorer/src/components/Staking/NominationsTable.tsx

  • Updated logic to exclude actions based on operator status and pending
    actions.
  • Replaced string literals with OperatorStatus and OperatorPendingAction
    enums.
  • +7/-12   
    OperatorsList.tsx
    Enhance operator action logic with enums                                 

    explorer/src/components/Staking/OperatorsList.tsx

  • Updated logic to exclude actions based on operator status and pending
    actions.
  • Replaced string literals with OperatorStatus and OperatorPendingAction
    enums.
  • +4/-8     
    staking.query.ts
    Include pending_action in operator GraphQL query                 

    explorer/src/components/Staking/staking.query.ts

  • Added pending_action field to the operator type in GraphQL query.
  • +1/-0     
    staking.ts
    Define enums for staking statuses and actions                       

    explorer/src/constants/staking.ts

  • Introduced new enums for operator and nominator statuses and pending
    actions.
  • +44/-0   
    tables.ts
    Use OperatorStatus enum for filter options                             

    explorer/src/constants/tables.ts

    • Updated status filter options to use OperatorStatus enum.
    +3/-1     
    Configuration changes
    tables.ts
    Update storage version for table states                                   

    explorer/src/states/tables.ts

    • Bumped storage version from 2 to 3.
    +1/-1     

    💡 PR-Agent usage:
    Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    Copy link

    netlify bot commented Aug 28, 2024

    Deploy Preview for dev-astral ready!

    Name Link
    🔨 Latest commit feb2ee0
    🔍 Latest deploy log https://app.netlify.com/sites/dev-astral/deploys/66d0517b4357d8000828e214
    😎 Deploy Preview https://deploy-preview-838--dev-astral.netlify.app
    📱 Preview on mobile
    Toggle QR Code...

    QR Code

    Use your smartphone camera to open QR code link.

    To edit notification comments on pull requests, go to your Netlify site configuration.

    Copy link

    PR Reviewer Guide 🔍

    ⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Key issues to review

    Possible Bug
    The condition if (nominator.operator?.status === OperatorStatus.SLASHED) return <></> may prevent further rendering of components or actions even if there are other valid conditions or data to be processed. This could lead to missing UI elements or functionality.

    Possible Bug
    Similar to the issue in NominationsTable.tsx, the condition if (row.original.status === OperatorStatus.SLASHED) return <></> might prematurely stop rendering of components, potentially hiding necessary UI elements or actions.

    Copy link

    github-actions bot commented Aug 28, 2024

    PR Code Suggestions ✨

    CategorySuggestion                                                                                                                                    Score
    Possible issue
    Add null checks for nested properties in the NominationsListQuery type

    Consider adding null checks for nested properties in the NominationsListQuery type
    to prevent runtime errors when accessing deeply nested properties.

    explorer/gql/types/staking.ts [7571]

    -export type NominationsListQuery = { __typename?: 'query_root', nominator_aggregate: { __typename?: 'nominator_aggregate', aggregate?: { __typename?: 'nominator_aggregate_fields', count: number } | null }, nominator: Array<{ __typename?: 'nominator', id: string, account_id: string, domain_id: string, operator_id: string, known_shares: any, known_storage_fee_deposit: any, pending_amount: any, pending_storage_fee_deposit: any, pending_effective_domain_epoch: number, total_withdrawal_amounts: any, total_storage_fee_refund: any, unlock_at_confirmed_domain_block_number: Array<number>, pending_shares: any, pending_storage_fee_refund: any, total_deposits: any, status: string, pending_action: string, created_at: number, updated_at: number, domain?: { __typename?: 'domain', id: string, name: string } | null, operator?: { __typename?: 'operator', id: string, account_id: string, status: string, pending_action: string, current_total_shares: any } | null, deposits: Array<{ __typename?: 'deposit', id: string, amount: any, storage_fee_deposit: any, timestamp: any, extrinsic_hash: string, status: string, created_at: number, staked_at: number, updated_at: number }>, withdrawals: Array<{ __typename?: 'withdrawal', id: string, shares: any, estimated_amount: any, unlocked_amount: any, unlocked_storage_fee: any, timestamp: any, withdraw_extrinsic_hash: string, unlock_extrinsic_hash: string, status: string, created_at: number, ready_at: number, unlocked_at: number, updated_at: number }> }>
    +export type NominationsListQuery = { __typename?: 'query_root', nominator_aggregate: { __typename?: 'nominator_aggregate', aggregate?: { __typename?: 'nominator_aggregate_fields', count: number } | null }, nominator: Array<{ __typename?: 'nominator', id: string, account_id: string, domain_id: string, operator_id: string, known_shares: any, known_storage_fee_deposit: any, pending_amount: any, pending_storage_fee_deposit: any, pending_effective_domain_epoch: number, total_withdrawal_amounts: any, total_storage_fee_refund: any, unlock_at_confirmed_domain_block_number: Array<number>, pending_shares: any, pending_storage_fee_refund: any, total_deposits: any, status: string, pending_action: string, created_at: number, updated_at: number, domain?: { __typename?: 'domain', id: string, name: string } | null, operator?: { __typename?: 'operator', id: string, account_id: string, status: string, pending_action: string, current_total_shares: any } | null, deposits: Array<{ __typename?: 'deposit', id: string, amount: any, storage_fee_deposit: any, timestamp: any, extrinsic_hash: string, status: string, created_at: number, staked_at: number, updated_at: number }>, withdrawals: Array<{ __typename?: 'withdrawal', id: string, shares: any, estimated_amount: any, unlocked_amount: any, unlocked_storage_fee: any, timestamp: any, withdraw_extrinsic_hash: string, unlock_extrinsic_hash: string, status: string, created_at: number, ready_at: number, unlocked_at: number, updated_at: number }> } | null }
     
    Suggestion importance[1-10]: 7

    Why: Adding null checks for nested properties in the NominationsListQuery type can help prevent runtime errors when accessing deeply nested properties. This is a good practice for improving code robustness, but it is not addressing a critical issue, hence a moderate score.

    7

    Copy link
    Contributor

    @clostao clostao left a comment

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    lgtm

    @marc-aurele-besner marc-aurele-besner merged commit 1acac3a into main Aug 29, 2024
    13 checks passed
    @marc-aurele-besner marc-aurele-besner deleted the 837-its-possible-to-nominate-a-slashed-or-deregistered-op branch August 29, 2024 11:46
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    It's possible to nominate a slashed or deregistered Op
    2 participants