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

Add UnlockFunds and UnlockOperator actions #572

Conversation

marc-aurele-besner
Copy link
Collaborator

@marc-aurele-besner marc-aurele-besner commented Apr 24, 2024

User description

Add UnlockFunds and UnlockOperator actions

  • Add UnlockFunds and UnlockOperator Action in dropdown (only when it's unlock ready)
  • Fix Operator status in mobile card
  • Add amount of block before unlock, or unlock ready
  • Hide deregistration when unlock ready

Related issues

Screenshot

Operator-ActionDropdown
UnlockOperator
Nominator-ActionDropdown
UnlockFunds


Type

enhancement, bug_fix


Description

  • Added new actions UnlockFunds and UnlockOperator to the operator actions modal.
  • Implemented handling functions for these new actions.
  • Enhanced UI components to support these actions and updated exclusion lists across various components.
  • Improved the display logic for operator status to handle different chain contexts.

Changes walkthrough

Relevant files
Enhancement
ActionsDropdown.tsx
Enhance text color condition in ActionsDropdown                   

explorer/src/components/Operator/ActionsDropdown.tsx

  • Modified the condition to apply 'text-red-500' class based on a new
    list ActionsInRed.
  • +4/-3     
    ActionsModal.tsx
    Add UnlockFunds and UnlockOperator actions and handlers   

    explorer/src/components/Operator/ActionsModal.tsx

  • Added new actions UnlockFunds and UnlockOperator to
    OperatorActionType.
  • Implemented new constants ActionsInRed to include actions that should
    be styled in red.
  • Added new methods handleUnlockFunds and handleUnlockOperator to handle
    these actions.
  • Updated UI components to support these new actions.
  • +80/-5   
    NominationManagement.tsx
    Update action exclusions in NominationManagement                 

    explorer/src/components/Operator/NominationManagement.tsx

    • Updated excludeActions to include UnlockOperator.
    +2/-1     
    NominatorsList.tsx
    Update action exclusions in NominatorsList                             

    explorer/src/components/Operator/NominatorsList.tsx

  • Updated excludeActions to include multiple actions including
    UnlockOperator and UnlockFunds.
  • +7/-2     
    OperatorManagement.tsx
    Update action exclusions in OperatorManagement                     

    explorer/src/components/Operator/OperatorManagement.tsx

    • Updated excludeActions to include UnlockFunds.
    +2/-0     
    OperatorsList.tsx
    Update action exclusions in OperatorsList                               

    explorer/src/components/Operator/OperatorsList.tsx

  • Updated excludeActions to include multiple actions such as UnlockFunds
    and UnlockOperator.
  • +12/-3   
    OperatorsListCard.tsx
    Enhance operator status display in OperatorsListCard         

    explorer/src/components/Operator/OperatorsListCard.tsx

  • Enhanced operator status display logic to handle different chain
    contexts.
  • +12/-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 Apr 24, 2024

    Deploy Preview for storybook-pr canceled.

    Name Link
    🔨 Latest commit 91462ea
    🔍 Latest deploy log https://app.netlify.com/sites/storybook-pr/deploys/66293d485619d00008425844

    @marc-aurele-besner marc-aurele-besner changed the base branch from main to staging April 24, 2024 17:11
    Copy link

    netlify bot commented Apr 24, 2024

    Deploy Preview for astral-prod ready!

    Name Link
    🔨 Latest commit 91462ea
    🔍 Latest deploy log https://app.netlify.com/sites/astral-prod/deploys/66293d4883856f00099db07e
    😎 Deploy Preview https://deploy-preview-572--astral-prod.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.

    @marc-aurele-besner marc-aurele-besner added the enhancement New feature or request label Apr 24, 2024
    Copy link

    PR Description updated to latest commit (91462ea)

    Copy link

    PR Review

    ⏱️ Estimated effort to review [1-5]

    4, because the PR involves multiple files and complex logic including UI changes, blockchain interactions, and conditional rendering based on operator types. The changes are spread across various components which increases the complexity and interdependencies.

    🧪 Relevant tests

    No

    🔍 Possible issues

    Possible Bug: The error message in both handleUnlockFunds and handleUnlockOperator methods is incorrect. It mentions "de-registering the operator" which is not relevant to these actions. This could lead to confusion for users and developers.

    Error Handling: The current implementation logs errors to the console but does not seem to handle them in a user-friendly way. It might be beneficial to implement a more robust error handling strategy that informs the user of what went wrong beyond just logging.

    🔒 Security concerns

    No

    Code feedback:
    relevant fileexplorer/src/components/Operator/ActionsModal.tsx
    suggestion      

    Consider updating the error messages in handleUnlockFunds and handleUnlockOperator to reflect the actual operation being performed. This change will improve clarity and maintainability of the code. [important]

    relevant linesetFormError('There was an error while de-registering the operator')


    ✨ Review tool usage guide:

    Overview:
    The review tool scans the PR code changes, and generates a PR review which includes several types of feedbacks, such as possible PR issues, security threats and relevant test in the PR. More feedbacks can be added by configuring the tool.

    The tool can be triggered automatically every time a new PR is opened, or can be invoked manually by commenting on any PR.

    • When commenting, to edit configurations related to the review tool (pr_reviewer section), use the following template:
    /review --pr_reviewer.some_config1=... --pr_reviewer.some_config2=...
    
    [pr_reviewer]
    some_config1=...
    some_config2=...
    

    See the review usage page for a comprehensive guide on using this tool.

    Copy link

    PR Code Suggestions

    CategorySuggestions                                                                                                                                                       
    Enhancement
    Improve the accuracy of error messages in unlock functions.

    Replace the hardcoded error message in handleUnlockFunds and handleUnlockOperator with a
    more specific message related to the actual action being performed.

    explorer/src/components/Operator/ActionsModal.tsx [213-233]

    -setFormError('There was an error while de-registering the operator')
    +setFormError('There was an error while unlocking the funds')
    +setFormError('There was an error while unlocking the operator')
     
    Use template literals to construct dynamic strings more cleanly.

    Use template literals for constructing strings to improve readability and maintainability.

    explorer/src/components/Operator/ActionsModal.tsx [363-364]

    -'unlock the funds in your nomination'
    -'unlock the funds in your operator'
    +`unlock the funds in your ${OperatorActionType[action.type as keyof typeof OperatorActionType] === OperatorActionType.UnlockFunds ? 'nomination' : 'operator'}`
     
    Best practice
    Enhance type safety and clarity in action type checks.

    Consider using a more specific conditional check instead of actionType as keyof typeof
    OperatorActionType for better type safety and clarity.

    explorer/src/components/Operator/ActionsDropdown.tsx [92]

    -OperatorActionType[actionType as keyof typeof OperatorActionType]
    +OperatorActionType[actionType] // Ensure `actionType` is already of type `keyof typeof OperatorActionType`
     
    Conditionally log sensitive information based on the environment to enhance security.

    Avoid using console.log for logging block and transaction hash information in production
    code. Consider using a more robust logging framework or environment-based logging.

    explorer/src/components/Operator/ActionsModal.tsx [208-209]

    -console.log('block', block)
    -console.log('hash', hash)
    +if (process.env.NODE_ENV === 'development') {
    +  console.log('block', block)
    +  console.log('hash', hash)
    +}
     
    Maintainability
    Refactor repeated conditional logic into a function for better code organization.

    Extract the repeated complex conditional logic into a separate function or variable for
    better readability and maintainability.

    explorer/src/components/Operator/ActionsDropdown.tsx [87-89]

    -ActionsInRed.includes(OperatorActionType[actionType as keyof typeof OperatorActionType])
    +const isActionInRed = (actionType: OperatorActionType) => ActionsInRed.includes(actionType);
    +isActionInRed(OperatorActionType[actionType as keyof typeof OperatorActionType])
     

    ✨ Improve tool usage guide:

    Overview:
    The improve tool scans the PR code changes, and automatically generates suggestions for improving the PR code. The tool can be triggered automatically every time a new PR is opened, or can be invoked manually by commenting on a PR.

    • When commenting, to edit configurations related to the improve tool (pr_code_suggestions section), use the following template:
    /improve --pr_code_suggestions.some_config1=... --pr_code_suggestions.some_config2=...
    
    [pr_code_suggestions]
    some_config1=...
    some_config2=...
    

    See the improve usage page for a comprehensive guide on using this tool.

    @marc-aurele-besner
    Copy link
    Collaborator Author

    I'm waiting to confirm the flow, it's likely missing a check to display the unlock operator only after deregistration, and unlock funds only after withdrawal...

    Copy link

    netlify bot commented Apr 25, 2024

    Deploy Preview for dev-astral ready!

    Name Link
    🔨 Latest commit 58a1fac
    🔍 Latest deploy log https://app.netlify.com/sites/dev-astral/deploys/662ac157c34f4b0008edc81e
    😎 Deploy Preview https://deploy-preview-572--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.

    @marc-aurele-besner
    Copy link
    Collaborator Author

    I don't believe the current squid allow us to know if a nominator has withdraw (else than his stake will have change) unlike the operatorConnection object, that has the status and the unlock at block number

    @marc-aurele-besner marc-aurele-besner marked this pull request as ready for review April 25, 2024 20:44
    Copy link
    Contributor

    @dnoishi dnoishi 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 8742fa1 into staging Apr 29, 2024
    14 checks passed
    @marc-aurele-besner marc-aurele-besner deleted the 548-operators-de-registrationwithdrawal-workflow-not-fully-captured-in-ui branch April 29, 2024 13:46
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    Development

    Successfully merging this pull request may close these issues.

    Operators de-registration/withdrawal workflow not fully captured in UI
    2 participants