-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge #417: Introduce WalletModel and loadWallet functionality
50c5f87 qml: Protect m_wallets in WalletQmlController with QMutex (johnny9) ec3e68e qml: Move setSelectedWallet work to worker QThread (johnny9) b41a0e4 qml: Introduce WalletModel and loadWallet functionality (johnny9) Pull request description: When a user selects a wallet from the WalletSelect menu the wallet controller can now load the wallet data in and the name and balance will appear in the WalletBadge The WalletQmlModel is introduced that hodes the interface to the backend wallet and provides the balance to the gui as a formatted string. The formatted string isn't quite as nice as specified in the figma. Instead it just uses the satoshi formatting currently provided by our GUI utils. The advanced formatting will be added as its own PR so that it can be reviewed separately. WalletController has been renamed to WalletQmlController to not conflict with the qt widgets controller. A function to set the selected wallet has been added. This function loads or creates the backend wallet interface and a WalletQmlModel owns the interface and is set to the controller's selectedWallet property. This is how the gui will gain access to the wallet's information. Loading encrypted wallets is not currently handled as we need additional dialogs. This will be done in a separate PR so that it can be reviewed independantly. A handler is also added to the wallet controller to handle background loading of wallet either through the rpc interface or at startup. Initial state and loading states of the wallet selector have not been implemented yet and will be done separately so it currently will just show 0 balance until a wallet is properly loaded. ACKs for top commit: jarolrod: ACK 50c5f87 Tree-SHA512: d03d3ffd37122e80b37c3e4dfb1b27910afd358b174970ba326f66ca24a8e623c758e12cf63edd7b62de6926117011e8cb8a21d69a8a8e32a1776136d892b072
- Loading branch information
Showing
13 changed files
with
254 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright (c) 2024 The Bitcoin Core developers | ||
// Distributed under the MIT software license, see the accompanying | ||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
#include <qml/models/walletqmlmodel.h> | ||
|
||
#include <qt/bitcoinunits.h> | ||
|
||
#include <QTimer> | ||
|
||
WalletQmlModel::WalletQmlModel(std::unique_ptr<interfaces::Wallet> wallet, QObject *parent) | ||
: QObject(parent) | ||
{ | ||
m_wallet = std::move(wallet); | ||
} | ||
|
||
WalletQmlModel::WalletQmlModel(QObject *parent) | ||
: QObject(parent) | ||
{ | ||
} | ||
|
||
QString WalletQmlModel::balance() const | ||
{ | ||
if (!m_wallet) { | ||
return "0"; | ||
} | ||
return BitcoinUnits::format(BitcoinUnits::Unit::BTC, m_wallet->getBalance()); | ||
} | ||
|
||
QString WalletQmlModel::name() const | ||
{ | ||
if (!m_wallet) { | ||
return QString(); | ||
} | ||
return QString::fromStdString(m_wallet->getWalletName()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright (c) 2024 The Bitcoin Core developers | ||
// Distributed under the MIT software license, see the accompanying | ||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
#ifndef BITCOIN_QML_MODELS_WALLETQMLMODEL_H | ||
#define BITCOIN_QML_MODELS_WALLETQMLMODEL_H | ||
|
||
#include <interfaces/wallet.h> | ||
|
||
#include <QObject> | ||
|
||
class WalletQmlModel : public QObject | ||
{ | ||
Q_OBJECT | ||
Q_PROPERTY(QString name READ name NOTIFY nameChanged) | ||
Q_PROPERTY(QString balance READ balance NOTIFY balanceChanged) | ||
|
||
public: | ||
WalletQmlModel(std::unique_ptr<interfaces::Wallet> wallet, QObject *parent = nullptr); | ||
WalletQmlModel(QObject *parent = nullptr); | ||
~WalletQmlModel() = default; | ||
|
||
QString name() const; | ||
QString balance() const; | ||
|
||
Q_SIGNALS: | ||
void nameChanged(); | ||
void balanceChanged(); | ||
|
||
private: | ||
std::unique_ptr<interfaces::Wallet> m_wallet; | ||
}; | ||
|
||
#endif // BITCOIN_QML_MODELS_WALLETQMLMODEL_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.