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

refactor: Pass WalletModel object to the WalletView constructor #398

Merged
merged 4 commits into from
Sep 7, 2021

Conversation

hebasto
Copy link
Member

@hebasto hebasto commented Aug 7, 2021

An instance of the WalletView class without the walletModel data member being set is invalid. So, it is better to set it in the constructor.

Establishing one more WalletView class's invariant in constructor:

  • allows to drop all of checks of thewalletModel in member functions
  • makes reasoning about the code that uses instances of the WalletView class easier

Possible follow ups could extend this approach to other classes, e.g., OverviewPage, TransactionView, ReceiveCoinsDialog, SendCoinsDialog, AddressBookPage.

@Talkless
Copy link

Concept ACK

src/qt/walletview.cpp Outdated Show resolved Hide resolved
src/qt/walletview.h Outdated Show resolved Hide resolved
Copy link

@Talkless Talkless left a comment

Choose a reason for hiding this comment

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

Wrong tab, sorry, deletec ack.

@hebasto
Copy link
Member Author

hebasto commented Aug 11, 2021

@Talkless

I don't see this signal being emmited in new code. It's because initialization in the constructor, as there's no "change" per se?

#403 could make things simpler.

So labeling this PR as a draft for now, and begging to review #403 first.

@hebasto hebasto marked this pull request as draft August 11, 2021 17:34
hebasto added a commit that referenced this pull request Aug 26, 2021
…tatuses simpler

b8aa84b qt, refactor: Replace `if` check with `assert` (Hennadii Stepanov)
fcdc8b0 qt, refactor: Drop redundant signalling in WalletView::setWalletModel (Hennadii Stepanov)
37dcf16 qt, refactor: Emit WalletView::encryptionStatusChanged signal directly (Hennadii Stepanov)
7d0d4c0 qt: Add WalletFrame::currentWalletSet signal (Hennadii Stepanov)

Pull request description:

  This PR makes signal-slot paths to reach `setHDStatus` and `setEncryptionStatus` functions shorter and easier to reason about them.

  Required to simplify #398 (see #398 (comment)).

  ---

  **Note for reviewers.** Please verify that "Encrypt Wallet..." menu item, and the following icons

  ![DeepinScreenshot_select-area_20210811202120](https://user-images.githubusercontent.com/32963518/129074601-13fa998a-ac47-4ad2-be00-ba400b12c18a.png)

  and updated properly in each and every possible scenario.

ACKs for top commit:
  jarolrod:
    tACK b8aa84b
  Talkless:
    Code review ACK b8aa84b. Did build on Debian Sid with Qt 5.15.2 but no actual testing performed.
  ryanofsky:
    Code review ACK b8aa84b. Only change since last review was rebase

Tree-SHA512: 275737cdba02baff71049df41bc24089e916f96326dd2dea26ec607c7949cb3aae368eeabbe3ad5a0a27651503a1d65536873726de854c5f6af259bcc29727e7
An instance of the WalletView class without walletModel data member
being set is invalid. So, it is better to set it in the constructor.
The walletModel member is set in the WalletView constructor now.
@hebasto hebasto marked this pull request as ready for review August 26, 2021 13:30
@hebasto
Copy link
Member Author

hebasto commented Aug 26, 2021

Updated 210b67b -> 92ddc02 (pr398.01 -> pr398.02):

@Talkless
Copy link

Code review ACK 92ddc02

src/qt/bitcoingui.cpp Outdated Show resolved Hide resolved
No need to pass an instance of the WalletModel class to this method.

Co-authored-by: João Barbosa <joao.paulo.barbosa@gmail.com>
@hebasto
Copy link
Member Author

hebasto commented Sep 2, 2021

Updated 92ddc02 -> d319c4d (pr398.02 -> pr398.03, diff):

Copy link
Contributor

@shaavan shaavan left a comment

Choose a reason for hiding this comment

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

Code review ACK d319c4d

These changes seem to simplify the code a great bit. Thanks for this amazing work!

I have compiled some notes regarding the changes made in each of the commits in this PR. However, @hebasto has very clearly mentioned the details in the commit message of each commit. I still think my notes might be of some help to fellow reviewers.

NOTES:

  • qt, refactor: Pass WalletModel object to WalletView constructor
    • The process of creating walletmodel has been moved under the constructor of the WalletView class.
    • The redundant function of creating a walletmodel has been removed.
    • walletview.h file has been appropriately modified to account for all the changes made in the walletview.cpp file.
  • qt, refactor: Drop redundant checks of walletModel
    • As the name suggests, all the redundant checks of walletModel in the walletview.cpp file have been removed, as the walletmodel is now constructed during the construction of the walletview object itself.
  • qt, refactor: Declare getWalletModel with const and noexcept qualifiers
    • This is done to ensure that the function is not changing a member variable’s value. And the given function will not throw an exception (since the walletmodel is generated with the constructor itself).
  • qt, refactor: Replace WalletFrame::addWallet with WalletFrame::addView
    • Modified the addWallet function such that it now doesn’t need to take walletmodel as an argument. And also removed the need to check for the existence of a walletmodel inside this function.

If some of my observation is erroneous or lacking thorough observation, please do inform me.

Copy link
Contributor

@promag promag left a comment

Choose a reason for hiding this comment

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

Code review ACK d319c4d.

@hebasto
Copy link
Member Author

hebasto commented Sep 6, 2021

@Talkless @jarolrod

Do you mind having another look into this PR?

Copy link
Member

@jarolrod jarolrod left a comment

Choose a reason for hiding this comment

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

ACK d319c4d

I did light testing with different wallets and switching between them. I also ran the qt tests locally. Performed identical testing steps on macOS and on Ubuntu.

This is a nice simplification of the WalletModel/WalletView logic. It ties up nicely at the end with the last commit where we now only need to pass the WalletView object; not both a WalletModel and WalletView object.

@ShaMan239 your notes on the PR are excellent and I looked at them before beginning my review. Thanks for posting them!

@hebasto hebasto merged commit 503194d into bitcoin-core:master Sep 7, 2021
@hebasto hebasto deleted the 210807-model branch September 7, 2021 05:49
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Sep 7, 2021
domob1812 added a commit to domob1812/namecoin-core that referenced this pull request Sep 13, 2021
@bitcoin-core bitcoin-core locked as resolved and limited conversation to collaborators Sep 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants