Skip to content

Commit 7af55d5

Browse files
committed
qml: Hide tabs and show Select Wallet if no wallet is loaded
1 parent 989bbe0 commit 7af55d5

File tree

5 files changed

+64
-2
lines changed

5 files changed

+64
-2
lines changed

src/qml/models/walletqmlmodel.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class WalletQmlModel : public QObject
2929
Q_PROPERTY(SendRecipient* sendRecipient READ sendRecipient CONSTANT)
3030
Q_PROPERTY(WalletQmlModelTransaction* currentTransaction READ currentTransaction NOTIFY currentTransactionChanged)
3131
Q_PROPERTY(unsigned int targetBlocks READ feeTargetBlocks WRITE setFeeTargetBlocks NOTIFY feeTargetBlocksChanged)
32+
Q_PROPERTY(bool isWalletLoaded READ isWalletLoaded NOTIFY walletIsLoadedChanged)
3233

3334
public:
3435
WalletQmlModel(std::unique_ptr<interfaces::Wallet> wallet, QObject* parent = nullptr);
@@ -67,11 +68,15 @@ class WalletQmlModel : public QObject
6768
unsigned int feeTargetBlocks() const;
6869
void setFeeTargetBlocks(unsigned int target_blocks);
6970

71+
bool isWalletLoaded() const { return m_is_wallet_loaded; }
72+
void setWalletLoaded(bool loaded);
73+
7074
Q_SIGNALS:
7175
void nameChanged();
7276
void balanceChanged();
7377
void currentTransactionChanged();
7478
void feeTargetBlocksChanged();
79+
void walletIsLoadedChanged();
7580

7681
private:
7782
std::unique_ptr<interfaces::Wallet> m_wallet;
@@ -80,6 +85,7 @@ class WalletQmlModel : public QObject
8085
SendRecipient* m_current_recipient{nullptr};
8186
WalletQmlModelTransaction* m_current_transaction{nullptr};
8287
wallet::CCoinControl m_coin_control;
88+
bool m_is_wallet_loaded{false};
8389
};
8490

8591
#endif // BITCOIN_QML_MODELS_WALLETQMLMODEL_H

src/qml/pages/wallet/DesktopWallets.qml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Page {
3030
text: walletController.selectedWallet.name
3131
balance: walletController.selectedWallet.balance
3232
loading: !walletController.initialized
33+
noWalletAvailable: !walletController.isWalletLoaded
3334

3435
MouseArea {
3536
anchors.fill: parent
@@ -52,9 +53,9 @@ Page {
5253
}
5354
}
5455
centerItem: RowLayout {
56+
visible: walletController.isWalletLoaded
5557
NavigationTab {
5658
id: activityTabButton
57-
checked: true
5859
text: qsTr("Activity")
5960
property int index: 0
6061
ButtonGroup.group: navigationTabs
@@ -79,6 +80,7 @@ Page {
7980
}
8081
NavigationTab {
8182
id: blockClockTabButton
83+
checked: true
8284
Layout.preferredWidth: 30
8385
Layout.rightMargin: 10
8486
property int index: 3

src/qml/pages/wallet/WalletBadge.qml

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Button {
2323
property bool showIcon: true
2424
property string balance: "0.0 000 000"
2525
property bool loading: false
26+
property bool noWalletAvailable: false
2627

2728
checkable: true
2829
hoverEnabled: AppMode.isDesktop
@@ -32,6 +33,10 @@ Button {
3233
topPadding: 0
3334
clip: true
3435

36+
HoverHandler{
37+
cursorShape: Qt.PointingHandCursor
38+
}
39+
3540
contentItem: Item {
3641
RowLayout {
3742
visible: root.loading
@@ -65,7 +70,40 @@ Button {
6570
}
6671

6772
RowLayout {
68-
visible: !root.loading
73+
visible: !root.loading && root.noWalletAvailable
74+
75+
opacity: visible ? 1 : 0
76+
77+
Behavior on opacity {
78+
NumberAnimation { duration: 400 }
79+
}
80+
81+
anchors.leftMargin: 5
82+
anchors.rightMargin: 5
83+
anchors.centerIn: parent
84+
clip: true
85+
spacing: 5
86+
Icon {
87+
visible: root.showIcon
88+
source: "image://images/caret-down-medium-filled"
89+
color: Theme.color.neutral8
90+
size: 30
91+
Layout.minimumWidth: 30
92+
Layout.preferredWidth: 30
93+
Layout.maximumWidth: 30
94+
}
95+
CoreText {
96+
horizontalAlignment: Text.AlignLeft
97+
Layout.fillWidth: true
98+
wrap: false
99+
font.pixelSize: 15
100+
text: qsTr("Select Wallet")
101+
color: root.textColor
102+
}
103+
}
104+
105+
RowLayout {
106+
visible: !root.loading && !root.noWalletAvailable
69107

70108
opacity: visible ? 1 : 0
71109

src/qml/walletqmlcontroller.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ void WalletQmlController::handleLoadWallet(std::unique_ptr<interfaces::Wallet> w
9494
if (wallet_model->name() == name) {
9595
m_selected_wallet = wallet_model;
9696
Q_EMIT selectedWalletChanged();
97+
setWalletLoaded(true);
9798
return;
9899
}
99100
}
@@ -104,6 +105,7 @@ void WalletQmlController::handleLoadWallet(std::unique_ptr<interfaces::Wallet> w
104105
m_selected_wallet = wallet_model;
105106
m_wallets.push_back(m_selected_wallet);
106107
Q_EMIT selectedWalletChanged();
108+
setWalletLoaded(true);
107109
}
108110

109111
void WalletQmlController::initialize()
@@ -118,9 +120,18 @@ void WalletQmlController::initialize()
118120
}
119121
if (!m_wallets.empty()) {
120122
m_selected_wallet = m_wallets.front();
123+
setWalletLoaded(true);
121124
Q_EMIT selectedWalletChanged();
122125
}
123126

124127
m_initialized = true;
125128
Q_EMIT initializedChanged();
126129
}
130+
131+
void WalletQmlController::setWalletLoaded(bool loaded)
132+
{
133+
if (m_is_wallet_loaded != loaded) {
134+
m_is_wallet_loaded = loaded;
135+
Q_EMIT isWalletLoadedChanged();
136+
}
137+
}

src/qml/walletqmlcontroller.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class WalletQmlController : public QObject
2222
Q_OBJECT
2323
Q_PROPERTY(WalletQmlModel* selectedWallet READ selectedWallet NOTIFY selectedWalletChanged)
2424
Q_PROPERTY(bool initialized READ initialized NOTIFY initializedChanged)
25+
Q_PROPERTY(bool isWalletLoaded READ isWalletLoaded NOTIFY isWalletLoadedChanged)
2526

2627
public:
2728
explicit WalletQmlController(interfaces::Node& node, QObject *parent = nullptr);
@@ -33,10 +34,13 @@ class WalletQmlController : public QObject
3334
WalletQmlModel* selectedWallet() const;
3435
void unloadWallets();
3536
bool initialized() const { return m_initialized; }
37+
bool isWalletLoaded() const { return m_is_wallet_loaded; }
38+
void setWalletLoaded(bool loaded);
3639

3740
Q_SIGNALS:
3841
void selectedWalletChanged();
3942
void initializedChanged();
43+
void isWalletLoadedChanged();
4044

4145
public Q_SLOTS:
4246
void initialize();
@@ -52,6 +56,7 @@ public Q_SLOTS:
5256
QMutex m_wallets_mutex;
5357
std::vector<WalletQmlModel*> m_wallets;
5458
std::unique_ptr<interfaces::Handler> m_handler_load_wallet;
59+
bool m_is_wallet_loaded{false};
5560

5661
bilingual_str m_error_message;
5762
std::vector<bilingual_str> m_warning_messages;

0 commit comments

Comments
 (0)