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

feat: update identity payout address #123

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

ogabrielides
Copy link
Collaborator

@ogabrielides ogabrielides commented Dec 4, 2024

Allow Masternode/Evonode Identities to update their payout address using opened Wallet(s)

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced a new screen for updating payout addresses within the identities section.
    • Added a button labeled "Update Payout Address" in the identities table to access the new functionality.
    • Enhanced task management capabilities to process ProRegUpdate transactions.
  • Bug Fixes

    • Improved handling and display of error messages related to payout address updates.
  • Documentation

    • Updated module structure to include the new update_identity_payout_address module for better organization.

@ogabrielides ogabrielides marked this pull request as draft December 4, 2024 22:27
Copy link
Contributor

coderabbitai bot commented Dec 4, 2024

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The pull request introduces significant enhancements to the application by adding new functionality for managing identity payout addresses. It includes the addition of new enum variants in the CoreTask and CoreItem enums to handle ProRegUpdate transactions. A new screen, UpdateIdentityPayoutScreen, is introduced for updating payout addresses, integrated into the existing UI with a button in the IdentitiesScreen. The changes also involve updates to various methods and the creation of a new module to encapsulate the payout address update logic.

Changes

File Path Change Summary
src/backend_task/core/mod.rs - Added enum variant ProRegUpdateTx(String, Address, Address) to CoreTask.
- Added enum variant ProRegUpdateTx(String) to CoreItem.
- Updated PartialEq for CoreTask.
- Modified run_core_task to handle ProRegUpdateTx.
- Updated import statements for new types from dash_sdk::dashcore_rpc::dashcore.
src/ui/identities/identities_screen.rs - Added import for UpdateIdentityPayoutScreen.
- Integrated "Update Payout Address" button in render_identities_view.
src/ui/identities/mod.rs - Added new public module update_identity_payout_address.
src/ui/identities/update_identity_payout_address.rs - Introduced UpdateIdentityPayoutScreen struct with methods for UI rendering and error handling.
- Added methods for wallet and address selection.
src/ui/mod.rs - Added variant UpdatePayoutAddress(QualifiedIdentity) to ScreenType enum.
- Added variant UpdatePayoutAddressScreen(UpdateIdentityPayoutScreen) to Screen enum.
- Updated methods to handle new screen type.

Possibly related PRs

Suggested reviewers

  • QuantumExplorer

🐰 "In the garden of code, we hop and play,
New screens and tasks brighten the day.
With buttons to click and addresses to find,
Our identities flourish, all perfectly aligned!
So let’s celebrate changes, both big and small,
For in the world of code, we’re having a ball!" 🐇✨


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 generate docstrings to generate docstrings for this PR. (Experiment)
  • @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.

@ogabrielides
Copy link
Collaborator Author

@coderabbitai review

Copy link
Contributor

coderabbitai bot commented Dec 5, 2024

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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

🧹 Outside diff range and nitpick comments (4)
src/ui/identities/update_identity_payout_address.rs (4)

88-166: Consider refactoring duplicated code in address selection methods

The methods render_selected_wallet_payout_addresses and render_selected_wallet_funding_addresses contain similar logic for rendering address selection. To improve maintainability and reduce code duplication, consider refactoring these methods into a single method that accepts parameters to distinguish between payout and funding addresses.


90-91: Handle potential errors when reading wallet lock

Using wallet.read().unwrap() can cause a panic if the lock is poisoned. To enhance robustness, handle potential errors using expect with a descriptive message or by matching on the Result.

Proposed change:

- let wallet = selected_wallet.read().unwrap();
+ let wallet = match selected_wallet.read() {
+     Ok(wallet) => wallet,
+     Err(_) => {
+         self.error_message = Some("Failed to acquire wallet read lock.".to_string());
+         return;
+     }
+ };

161-163: Handle missing balance information gracefully

The code currently comments out the UI label when the balance is not found. To improve user experience, display a message indicating that the balance is not available.

Proposed change:

- //ui.label("Balance NOT FOUND DASH".to_string());
+ ui.label("Balance not available.".to_string());

189-198: Remove unnecessary parentheses in if statements

In Rust, conditions in if statements do not require parentheses. Removing them improves code readability and adherence to Rust conventions.

Proposed change:

- if (self.identity.identity_type == IdentityType::User) {
+ if self.identity.identity_type == IdentityType::User {

Apply similar changes to other if statements.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 465883e and 549e555.

📒 Files selected for processing (5)
  • src/backend_task/core/mod.rs (5 hunks)
  • src/ui/identities/identities_screen.rs (2 hunks)
  • src/ui/identities/mod.rs (1 hunks)
  • src/ui/identities/update_identity_payout_address.rs (1 hunks)
  • src/ui/mod.rs (12 hunks)
🔇 Additional comments (7)
src/ui/identities/mod.rs (1)

8-8: Module addition looks good

The addition of the update_identity_payout_address module is appropriate and integrates well with the existing structure.

src/backend_task/core/mod.rs (1)

144-158: Verify parameters passed to get_protx_update_registrar

The method get_protx_update_registrar is called with an empty string for one of the parameters. Confirm that passing an empty string is intentional and aligns with the expected usage of this method.

Ensure that this does not lead to unintended behavior or errors in the ProRegUpdate transaction.

src/ui/mod.rs (3)

14-14: Import statement for new screen is correct

The import of UpdateIdentityPayoutScreen integrates the new screen into the UI module appropriately.


Line range hint 128-187: New screen variants added consistently

The additions of UpdatePayoutAddress to ScreenType and UpdatePayoutAddressScreen to Screen enums are consistent and maintain the integrity of the application's navigation system.


259-259: change_context method updated correctly

The change_context method now correctly handles UpdatePayoutAddressScreen, ensuring that the application context is updated when this screen is active.

src/ui/identities/identities_screen.rs (2)

19-19: Import of UpdateIdentityPayoutScreen is appropriate

The import statement for UpdateIdentityPayoutScreen correctly brings in the new functionality needed for the identities screen.


458-465: Integration of 'Update Payout Address' button

The addition of the "Update Payout Address" button and its associated action is implemented correctly, enhancing the user interface by providing direct access to the payout address update functionality.

Comment on lines 225 to 231
if self.error_message.is_some() {
ui.add_space(20.0);
ui.colored_label(
egui::Color32::RED,
self.error_message.as_ref().unwrap(),
);
}
Copy link
Contributor

@coderabbitai coderabbitai bot Dec 5, 2024

Choose a reason for hiding this comment

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

⚠️ Potential issue

Reset error message after displaying it

The error message is displayed but not reset, which may cause it to persist longer than intended. Reset self.error_message after displaying it to ensure it's shown appropriately.

Proposed change:

if self.error_message.is_some() {
    ui.add_space(20.0);
    ui.colored_label(
        egui::Color32::RED,
        self.error_message.as_ref().unwrap(),
    );
+   self.error_message = None;
}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if self.error_message.is_some() {
ui.add_space(20.0);
ui.colored_label(
egui::Color32::RED,
self.error_message.as_ref().unwrap(),
);
}
if self.error_message.is_some() {
ui.add_space(20.0);
ui.colored_label(
egui::Color32::RED,
self.error_message.as_ref().unwrap(),
);
self.error_message = None;
}

Copy link
Member

Choose a reason for hiding this comment

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

I'm pretty sure this will just make the error message flash for a millisecond

Copy link
Contributor

Choose a reason for hiding this comment

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

@pauldelucia

You're absolutely right. Resetting the error message immediately after displaying it would cause it to disappear too quickly, preventing the user from reading it. Thank you for pointing that out.


✏️ Learnings added
Learnt from: pauldelucia
PR: dashpay/dash-evo-tool#123
File: src/ui/identities/update_identity_payout_address.rs:225-231
Timestamp: 2024-12-09T10:29:01.778Z
Learning: Avoid resetting error messages immediately after displaying them in the UI, as this may cause them to disappear before the user has time to read them.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

Comment on lines 216 to 224
if ui.button("Update Payout Address").clicked() {
action |= AppAction::BackendTask(BackendTask::CoreTask(
CoreTask::ProRegUpdateTx(
self.identity.identity.id().to_string(Encoding::Hex),
self.selected_payout_address.clone().unwrap(),
self.selected_funding_address.clone().unwrap(),
),
));
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Ensure required fields are selected before proceeding

When the "Update Payout Address" button is clicked, the code assumes that both selected_payout_address and selected_funding_address are Some. To prevent potential unwrap() on None values, check that both fields are selected before proceeding.

Proposed change:

if ui.button("Update Payout Address").clicked() {
+   if let (Some(payout_address), Some(funding_address)) = (
+       self.selected_payout_address.clone(),
+       self.selected_funding_address.clone(),
+   ) {
        action |= AppAction::BackendTask(BackendTask::CoreTask(
            CoreTask::ProRegUpdateTx(
                self.identity.identity.id().to_string(Encoding::Hex),
-               self.selected_payout_address.clone().unwrap(),
-               self.selected_funding_address.clone().unwrap(),
+               payout_address,
+               funding_address,
            ),
        ));
+   } else {
+       self.error_message = Some("Please select both payout and funding addresses.".to_string());
+   }
}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if ui.button("Update Payout Address").clicked() {
action |= AppAction::BackendTask(BackendTask::CoreTask(
CoreTask::ProRegUpdateTx(
self.identity.identity.id().to_string(Encoding::Hex),
self.selected_payout_address.clone().unwrap(),
self.selected_funding_address.clone().unwrap(),
),
));
}
if ui.button("Update Payout Address").clicked() {
if let (Some(payout_address), Some(funding_address)) = (
self.selected_payout_address.clone(),
self.selected_funding_address.clone(),
) {
action |= AppAction::BackendTask(BackendTask::CoreTask(
CoreTask::ProRegUpdateTx(
self.identity.identity.id().to_string(Encoding::Hex),
payout_address,
funding_address,
),
));
} else {
self.error_message = Some("Please select both payout and funding addresses.".to_string());
}
}

@ogabrielides ogabrielides marked this pull request as ready for review December 5, 2024 14:49
Copy link
Member

@pauldelucia pauldelucia left a comment

Choose a reason for hiding this comment

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

I suggest to only display the button for MN/HPMN identities, and move to Actions column rather than Balance column. Since it's a large button "Update Payout Address", maybe it makes sense to have a "..." button in Actions that opens a pop-up with more actions

@thephez
Copy link
Contributor

thephez commented Dec 10, 2024

This will only work for MNs that have their owner key in Dash Core (vs DMT) and in the specific wallet they connect to DET, correct?

Copy link
Member

@pauldelucia pauldelucia left a comment

Choose a reason for hiding this comment

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

LGTM

I can't really test it though - I'm afraid to do anything with the testnet MNs/HPMNs. Did you test it?

Also, preferably I think we should add a success screen (for example like after creating an identity) rather than just PopScreenAndRefresh.

@ogabrielides
Copy link
Collaborator Author

This will only work for MNs that have their owner key in Dash Core (vs DMT) and in the specific wallet they connect to DET, correct?

@thephez Correct!

Base automatically changed from v0.6-dev to master December 13, 2024 10:10
@pauldelucia pauldelucia changed the base branch from master to v0.7-dev December 16, 2024 10:32
Base automatically changed from v0.7-dev to master January 7, 2025 08:23
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.

3 participants