-
Notifications
You must be signed in to change notification settings - Fork 4
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
base: master
Are you sure you want to change the base?
Conversation
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughThe 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 Changes
Possibly related PRs
Suggested reviewers
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this 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 methodsThe methods
render_selected_wallet_payout_addresses
andrender_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 lockUsing
wallet.read().unwrap()
can cause a panic if the lock is poisoned. To enhance robustness, handle potential errors usingexpect
with a descriptive message or by matching on theResult
.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 gracefullyThe 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 inif
statementsIn 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
📒 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.
if self.error_message.is_some() { | ||
ui.add_space(20.0); | ||
ui.colored_label( | ||
egui::Color32::RED, | ||
self.error_message.as_ref().unwrap(), | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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; | |
} |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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(), | ||
), | ||
)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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()); | |
} | |
} |
There was a problem hiding this 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
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? |
There was a problem hiding this 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.
@thephez Correct! |
Allow Masternode/Evonode Identities to update their payout address using opened Wallet(s)
Summary by CodeRabbit
Release Notes
New Features
Bug Fixes
Documentation
update_identity_payout_address
module for better organization.