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

Fix go private window behavior for exchange address #1426

Closed
wants to merge 4 commits into from

Conversation

levoncrypto
Copy link
Contributor

@levoncrypto levoncrypto commented Apr 2, 2024

Summary by CodeRabbit

  • New Features

    • Added a new checkbox widget in the options dialog to disable the "Go To Private" functionality with corresponding tooltip and text.
    • Extended the OptionsModel functionality to handle the state of the "Disable Go To Private" feature in settings.
  • Bug Fixes

    • Improved the logic for handling recipients in the send coins dialog to ensure private transactions are correctly initiated.

Copy link

coderabbitai bot commented Apr 2, 2024

Walkthrough

The changes involve refining recipient handling in the SendCoinsDialog class to ensure no CExchangeKeyID addresses are present before proceeding to display the SendGoPrivateDialog. This enhancement aims to streamline user experience and reinforce address verification.

Changes

File Change Summary
src/qt/sendcoinsdialog.cpp Updated recipient handling in on_sendButton_clicked() to check for CExchangeKeyID addresses before showing SendGoPrivateDialog.

🐇✨
In the realm of coins and keys,
A rabbit hopped, with utmost ease.
"No CExchangeKeyID shall pass," it said,
Before the private dialog is spread.
With every hop, a fix in place,
Ensuring privacy, in this digital space. 🌟
🐇✨

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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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/coderabbit-overrides.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

@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: 1

Review Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 17aab98 and e254498.
Files selected for processing (1)
  • src/qt/sendcoinsdialog.cpp (1 hunks)

Comment on lines 344 to 362
bool openPageTag = true;
for(int i = 0; i < recipients.size(); ++i){
std::string address = recipients[i].address.toStdString();
CBitcoinAddress add(address);
CTxDestination dest = add.Get();

if (boost::get<CExchangeKeyID>(&dest)) {
openPageTag = false;
}
}

if (openPageTag) {
SendGoPrivateDialog goPrivateDialog;
bool clickedButton = goPrivateDialog.getClickedButton();
if (!clickedButton) {
setAnonymizeMode(true);
fNewRecipientAllowed = true;
return;
}
Copy link

Choose a reason for hiding this comment

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

The logic to check for CExchangeKeyID type addresses and conditionally display the SendGoPrivateDialog is a crucial addition for enhancing the application's handling of private transactions. However, there are a few considerations and potential improvements:

  1. Error Handling and User Feedback: When the openPageTag is set to false due to the presence of a CExchangeKeyID type address, the function returns without any user feedback. It might be beneficial to inform the user why the operation cannot proceed in this case.

  2. Code Duplication: The pattern of iterating over recipients to perform checks appears multiple times in this function. Consider refactoring this pattern into a separate method to improve code maintainability and reduce duplication.

  3. Performance Consideration: The current implementation iterates over all recipients for each condition check. If the list of recipients is large, this could impact performance. Consider optimizing this by breaking early if possible or consolidating checks.

  4. User Experience: The decision to block the transaction entirely if any recipient address is of the CExchangeKeyID type might be too restrictive. It could be worth exploring alternatives that allow the user to proceed with the transaction for non-exchange addresses or provide a clear path to rectify the issue.

-                    setAnonymizeMode(true);
-                    fNewRecipientAllowed = true;
+                    // Consider providing user feedback here to explain why the transaction cannot proceed.
+                    QMessageBox::warning(this, tr("Incompatible Address"), tr("One or more recipient addresses are exchange addresses, which are not compatible with private transactions."));

Consider refactoring the recipient address type checks into a separate method to improve code readability and maintainability.


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.

Suggested change
bool openPageTag = true;
for(int i = 0; i < recipients.size(); ++i){
std::string address = recipients[i].address.toStdString();
CBitcoinAddress add(address);
CTxDestination dest = add.Get();
if (boost::get<CExchangeKeyID>(&dest)) {
openPageTag = false;
}
}
if (openPageTag) {
SendGoPrivateDialog goPrivateDialog;
bool clickedButton = goPrivateDialog.getClickedButton();
if (!clickedButton) {
setAnonymizeMode(true);
fNewRecipientAllowed = true;
return;
}
bool openPageTag = true;
for(int i = 0; i < recipients.size(); ++i){
std::string address = recipients[i].address.toStdString();
CBitcoinAddress add(address);
CTxDestination dest = add.Get();
if (boost::get<CExchangeKeyID>(&dest)) {
openPageTag = false;
}
}
if (openPageTag) {
SendGoPrivateDialog goPrivateDialog;
bool clickedButton = goPrivateDialog.getClickedButton();
if (!clickedButton) {
// Consider providing user feedback here to explain why the transaction cannot proceed.
QMessageBox::warning(this, tr("Incompatible Address"), tr("One or more recipient addresses are exchange addresses, which are not compatible with private transactions."));
return;
}

Copy link

@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

Review Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between e254498 and 98dacc3.
Files selected for processing (5)
  • src/qt/forms/optionsdialog.ui (1 hunks)
  • src/qt/optionsdialog.cpp (2 hunks)
  • src/qt/optionsmodel.cpp (3 hunks)
  • src/qt/optionsmodel.h (4 hunks)
  • src/qt/sendcoinsdialog.cpp (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/qt/sendcoinsdialog.cpp
Additional comments not posted (7)
src/qt/optionsmodel.h (2)

49-49: The addition of the DisableGoToPrivate member variable is correctly implemented and follows the naming conventions and structure of the existing code.


112-112: The addition of the disableGoToPrivateChanged signal is correctly implemented and follows Qt's best practices for notifying changes to properties.

src/qt/optionsdialog.cpp (2)

168-168: The connection of the disableGoToPrivateWindow checkbox to the showRestartWarning method is correctly implemented and follows the established pattern for settings that require a restart.


188-188: The mapping of the disableGoToPrivateWindow checkbox to the OptionsModel::DisableGoToPrivate is correctly implemented, ensuring the setting is properly saved and loaded.

src/qt/optionsmodel.cpp (3)

84-87: The handling of the DisableGoToPrivate setting in the Init method is correctly implemented, following the established pattern for initializing settings with default values.


433-437: The handling of the DisableGoToPrivate setting in the setData method is correctly implemented, ensuring the setting is properly saved when changed.


436-436: The emission of the disableGoToPrivateChanged signal upon changing the DisableGoToPrivate setting is correctly implemented, following best practices for Qt models.

Comment on lines 166 to 174
<item>
<widget class="QCheckBox" name="disableGoToPrivateWindow">
<property name="toolTip">
<string>Disable go to private window.</string>
</property>
<property name="text">
<string>&amp;Disable go to private window</string>
</property>
</widget>
Copy link

Choose a reason for hiding this comment

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

Consider enhancing the tooltip text for the disableGoToPrivateWindow checkbox for better clarity. For example, explain what the "go to private window" functionality is and why a user might want to disable it. This will improve user understanding and experience.

- <string>Disable go to private window.</string>
+ <string>Disable the 'Go Private' window feature, which is used for... [provide a brief explanation]. This option can be useful if... [provide a reason or scenario].</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.

Suggested change
<item>
<widget class="QCheckBox" name="disableGoToPrivateWindow">
<property name="toolTip">
<string>Disable go to private window.</string>
</property>
<property name="text">
<string>&amp;Disable go to private window</string>
</property>
</widget>
<item>
<widget class="QCheckBox" name="disableGoToPrivateWindow">
<property name="toolTip">
<string>Disable the 'Go Private' window feature, which is used for... [provide a brief explanation]. This option can be useful if... [provide a reason or scenario].</string>
</property>
<property name="text">
<string>&amp;Disable go to private window</string>
</property>
</widget>

@@ -73,6 +74,7 @@ class OptionsModel : public QAbstractListModel
bool getRapAddresses() { return fenableRapAddresses; }
const QString& getOverriddenByCommandLine() { return strOverriddenByCommandLine; }
bool getAutoAnonymize() { return fAutoAnonymize; }
bool getGoPrivateWindow() {return fDisableGoToPrivate;}
Copy link

Choose a reason for hiding this comment

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

Rename the getter method to accurately reflect the variable it accesses for clarity. Consider renaming it to getDisableGoToPrivate to match the variable name.

- bool getGoPrivateWindow() {return fDisableGoToPrivate;}
+ bool getDisableGoToPrivate() {return fDisableGoToPrivate;}

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.

Suggested change
bool getGoPrivateWindow() {return fDisableGoToPrivate;}
bool getDisableGoToPrivate() {return fDisableGoToPrivate;}

@reubenyap reubenyap changed the title Fix go private window behavore for exchange address Fix go private window behavior for exchange address Apr 5, 2024
Copy link

@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

Review Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 98dacc3 and 7ca765c.
Files selected for processing (2)
  • src/qt/optionsmodel.h (4 hunks)
  • src/qt/sendcoinsdialog.cpp (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • src/qt/optionsmodel.h
  • src/qt/sendcoinsdialog.cpp

Copy link

@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

Review Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 7ca765c and f897199.
Files selected for processing (1)
  • src/qt/forms/optionsdialog.ui (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/qt/forms/optionsdialog.ui

@levonpetrosyan93
Copy link
Contributor

We don't need this anymore, as we removed the popup window in #1434 .

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.

2 participants