Skip to content

Commit 50f1f00

Browse files
Merge #888: [GUI] Update QR Code on address selection
7cf0778 [GUI] Update QR Code on address selection (WetOne) Pull request description: ### Problem Selection of an address on the Address Book page does not update the QR codes on the receive page or the left hand side. ### Root Cause Selection of an address on the Address Book page is isolated to the address book. ### Solution Notify the other displays to allow for updates based on the selection of an address. The update includes displaying address, QR code, name (if any). ### Issues Addressed 250: #250 136: #136 Tree-SHA512: 75bca89eba84e1f9dae5796394513e0874bf38e488d23d32985ba647918c0ad7a7b643f0e2bcf807c793fbc6d004ddb3305afc325f4aa2099573658f5b221b7f
2 parents 422ccbb + 7cf0778 commit 50f1f00

14 files changed

+183
-44
lines changed

src/qt/bitcoingui.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include <chainparams.h>
3838
#include <interfaces/handler.h>
3939
#include <interfaces/node.h>
40+
#include <key_io.h>
4041
#include <ui_interface.h>
4142
#include <util.h>
4243

@@ -260,6 +261,7 @@ BitcoinGUI::BitcoinGUI(interfaces::Node& node, const PlatformStyle *_platformSty
260261
modalOverlay = new ModalOverlay(this->centralWidget(), this);
261262
#ifdef ENABLE_WALLET
262263
if(enableWallet) {
264+
connect(walletFrame, SIGNAL(changeSelectedRcvAddress(CTxDestination*)), this, SLOT(updatedSelectedRcvAddress(CTxDestination*)));
263265
connect(walletFrame, SIGNAL(requestedSyncWarningInfo()), this, SLOT(showModalOverlay()));
264266
connect(labelBlocksIcon, SIGNAL(clicked(QPoint)), this, SLOT(showModalOverlay()));
265267
connect(progressBar, SIGNAL(clicked(QPoint)), this, SLOT(showModalOverlay()));
@@ -1516,6 +1518,13 @@ void BitcoinGUI::toggleNetworkActive()
15161518
m_node.setNetworkActive(!m_node.getNetworkActive());
15171519
}
15181520

1521+
#ifdef ENABLE_WALLET
1522+
void BitcoinGUI::updatedSelectedRcvAddress(CTxDestination* selectedRcvAddress) {
1523+
balance->setDisplayRcvAddress(selectedRcvAddress);
1524+
balance->refreshWalletStatus();
1525+
}
1526+
#endif
1527+
15191528
UnitDisplayStatusBarControl::UnitDisplayStatusBarControl(const PlatformStyle *platformStyle) :
15201529
optionsModel(0),
15211530
menu(0)

src/qt/bitcoingui.h

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#endif
1212

1313
#include <amount.h>
14+
#include <script/standard.h>
1415

1516
#include <QLabel>
1617
#include <QMainWindow>
@@ -236,6 +237,8 @@ public Q_SLOTS:
236237
*/
237238
void message(const QString &title, const QString &message, unsigned int style, bool *ret = nullptr);
238239

240+
void updatedSelectedRcvAddress(CTxDestination* selectedRcvAddress);
241+
239242
#ifdef ENABLE_WALLET
240243
void initWalletMenu(std::string& mnemonic, unsigned int& flag, bool& ret);
241244
bool setCurrentWallet(const QString& name);

src/qt/veil/addresseswidget.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030

3131
#include <iostream>
3232

33+
#include <key_io.h>
34+
3335
#define DECORATION_SIZE 54
3436
#define NUM_ITEMS 5
3537

@@ -222,6 +224,7 @@ AddressesWidget::AddressesWidget(const PlatformStyle *platformStyle, WalletView
222224
ui->lblSplit->setVisible(false);
223225
//connect(ui->btnMiningAddress,SIGNAL(clicked()),this,SLOT(onNewMinerAddressClicked()));
224226
//connect(ui->btnMiningAddress2,SIGNAL(clicked()),this,SLOT(onNewMinerAddressClicked()));
227+
225228
}
226229

227230
void AddressesWidget::setWalletModel(WalletModel *model)
@@ -240,6 +243,11 @@ void AddressesWidget::handleAddressClicked(const QModelIndex &index){
240243
listView = ui->listAddresses;
241244
type = AddressTableModel::Receive;
242245
updatedIndex = proxyModel->mapToSource(index);
246+
auto address = this->model->index(updatedIndex.row(), AddressTableModel::Address, updatedIndex);
247+
QString addressStr = this->model->data(address, Qt::DisplayRole).toString();
248+
CTxDestination selectedAddress = DecodeDestination(addressStr.toStdString());
249+
250+
Q_EMIT rcvAddressSelected(&selectedAddress);
243251
}else{
244252
listView = ui->listContacts;
245253
type = AddressTableModel::Send;
@@ -371,6 +379,7 @@ void AddressesWidget::onNewAddressClicked(){
371379
openToastDialog(QString::fromStdString(toast + " Creation Failed"), mainWindow->getGUI());
372380
}
373381
// if it's the first one created, display it without having to reload
382+
// WE NEED TO DISPLAY THE NEW ADDRESS HERE AND IN THE BALANCE AND RECEIVE WIDGETS
374383
onForeground();
375384
}
376385

src/qt/veil/addresseswidget.h

+3
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ class AddressesWidget : public QWidget
5050

5151
void refreshWalletStatus();
5252

53+
Q_SIGNALS:
54+
void rcvAddressSelected(CTxDestination *address);
55+
5356
private Q_SLOTS:
5457
void onMyAddressClicked();
5558
void onContactsClicked();

src/qt/veil/balance.cpp

+39-24
Original file line numberDiff line numberDiff line change
@@ -232,37 +232,49 @@ void Balance::refreshWalletStatus() {
232232
// Check wallet status
233233
interfaces::Wallet& wallet = walletModel->wallet();
234234
std::string strAddress;
235-
std::vector<interfaces::WalletAddress> addresses = wallet.getLabelAddress("stealth");
236-
if(!addresses.empty()) {
237-
interfaces::WalletAddress address = addresses[0];
238-
if (address.dest.type() == typeid(CStealthAddress)){
235+
std::string addressName = " ";
236+
isminetype isMine = ISMINE_NO;
237+
std::string purpose = " ";
238+
239+
if (displayAddressSet) {
240+
bool doesAddyExist = wallet.getAddress(currentDisplayAddress, &addressName, &isMine, &purpose);
241+
strAddress = EncodeDestination(currentDisplayAddress, !("receive_miner" == purpose));
242+
} else {
243+
std::vector<interfaces::WalletAddress> addresses = wallet.getLabelAddress("stealth");
244+
if(!addresses.empty()) {
245+
interfaces::WalletAddress address = addresses[0];
246+
if (address.dest.type() == typeid(CStealthAddress)){
247+
bool fBech32 = true;
248+
strAddress = EncodeDestination(address.dest,true);
249+
addressName = "stealth";
250+
}
251+
}else {
252+
ui->copyAddress->setVisible(true);
253+
ui->labelReceive->setAlignment(Qt::AlignLeft);
254+
ui->labelReceive->setText("Receiving address");
255+
// Generate a new address to associate with given label
256+
// TODO: Use only one stealth address here.
257+
CStealthAddress address;
258+
if (!walletModel->wallet().getNewStealthAddress(address)) {
259+
ui->labelQr->setText("");
260+
ui->copyAddress->setVisible(false);
261+
ui->labelReceive->setText("Wallet Locked");
262+
ui->labelReceive->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
263+
ui->labelAddress->setText("");
264+
return;
265+
}
239266
bool fBech32 = true;
240-
strAddress = EncodeDestination(address.dest,true);
267+
strAddress = address.ToString(fBech32);
268+
wallet.setAddressBook(DecodeDestination(strAddress), "stealth", "receive", fBech32);
269+
addressName = "stealth";
241270
}
242-
}else {
243-
ui->copyAddress->setVisible(true);
244-
ui->labelReceive->setAlignment(Qt::AlignLeft);
245-
ui->labelReceive->setText("Receiving address");
246-
// Generate a new address to associate with given label
247-
// TODO: Use only one stealth address here.
248-
CStealthAddress address;
249-
if (!walletModel->wallet().getNewStealthAddress(address)) {
250-
ui->labelQr->setText("");
251-
ui->copyAddress->setVisible(false);
252-
ui->labelReceive->setText("Wallet Locked");
253-
ui->labelReceive->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
254-
ui->labelAddress->setText("");
255-
return;
256-
}
257-
bool fBech32 = true;
258-
strAddress = address.ToString(fBech32);
259-
wallet.setAddressBook(DecodeDestination(strAddress), "stealth", "receive", fBech32);
260271
}
261272

262273
qAddress = QString::fromStdString(strAddress);
263274

264275
// set address
265276
ui->labelAddress->setText(qAddress.left(12) + "..." + qAddress.right(12));
277+
ui->labelAddressName->setText(QString::fromStdString(addressName));
266278

267279
SendCoinsRecipient info;
268280
info.address = qAddress;
@@ -320,4 +332,7 @@ void Balance::refreshWalletStatus() {
320332
#endif
321333
}
322334

323-
335+
void Balance::setDisplayRcvAddress(CTxDestination *displayAddress) {
336+
displayAddressSet = true;
337+
currentDisplayAddress = *displayAddress;
338+
}

src/qt/veil/balance.h

+4
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class Balance : public QWidget
3434
void setWalletModel(WalletModel *walletModel);
3535
void refreshWalletStatus();
3636
bool eventFilter(QObject *obj, QEvent *event);
37+
void setDisplayRcvAddress(CTxDestination *displayAddress);
3738

3839
public Q_SLOTS:
3940
void setBalance(const interfaces::WalletBalances& balances);
@@ -58,6 +59,9 @@ public Q_SLOTS:
5859
TooltipBalance *tooltip = nullptr;
5960

6061
void onBtnBalanceClicked(int type);
62+
63+
bool displayAddressSet = false;
64+
CTxDestination currentDisplayAddress;
6165
};
6266

6367
#endif // BALANCE_H

src/qt/veil/forms/balance.ui

+33
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,39 @@ padding-left:5px;
395395
padding-right:5px;
396396
padding-bottom:3px;
397397
font-size:11px;
398+
color:#707070;</string>
399+
</property>
400+
<property name="midLineWidth">
401+
<number>0</number>
402+
</property>
403+
<property name="text">
404+
<string>N/A</string>
405+
</property>
406+
<property name="wordWrap">
407+
<bool>false</bool>
408+
</property>
409+
<property name="margin">
410+
<number>0</number>
411+
</property>
412+
<property name="indent">
413+
<number>0</number>
414+
</property>
415+
</widget>
416+
</item>
417+
<item>
418+
<widget class="QLabel" name="labelAddressName">
419+
<property name="sizePolicy">
420+
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
421+
<horstretch>0</horstretch>
422+
<verstretch>0</verstretch>
423+
</sizepolicy>
424+
</property>
425+
<property name="styleSheet">
426+
<string notr="true">background-color: transparent;
427+
padding-left:5px;
428+
padding-right:5px;
429+
padding-bottom:3px;
430+
font-size:11px;
398431
color:#707070;</string>
399432
</property>
400433
<property name="midLineWidth">

src/qt/veil/forms/receivewidget.ui

+19-3
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ QR code to send you veil</string>
210210
</property>
211211
<layout class="QHBoxLayout" name="horizontalLayout_5">
212212
<item>
213-
<layout class="QHBoxLayout" name="horizontalLayout" stretch="1,0,1,0,1">
213+
<layout class="QHBoxLayout" name="horizontalLayout" stretch="1,0,1,1,0,1">
214214
<property name="spacing">
215215
<number>20</number>
216216
</property>
@@ -221,8 +221,8 @@ QR code to send you veil</string>
221221
</property>
222222
<property name="sizeHint" stdset="0">
223223
<size>
224-
<width>40</width>
225-
<height>20</height>
224+
<width>30</width>
225+
<height>21</height>
226226
</size>
227227
</property>
228228
</spacer>
@@ -249,6 +249,22 @@ QR code to send you veil</string>
249249
</property>
250250
</widget>
251251
</item>
252+
<item>
253+
<widget class="QLabel" name="labelAddressName">
254+
<property name="maximumSize">
255+
<size>
256+
<width>300</width>
257+
<height>16777215</height>
258+
</size>
259+
</property>
260+
<property name="styleSheet">
261+
<string notr="true">color:#707070;</string>
262+
</property>
263+
<property name="text">
264+
<string>N/A</string>
265+
</property>
266+
</widget>
267+
</item>
252268
<item>
253269
<widget class="QLabel" name="labelAddress">
254270
<property name="maximumSize">

src/qt/veil/receivewidget.cpp

+32-16
Original file line numberDiff line numberDiff line change
@@ -90,30 +90,40 @@ bool ReceiveWidget::generateNewAddress(bool isOnDemand){
9090
interfaces::Wallet& wallet = walletModel->wallet();
9191

9292
std::string strAddress;
93-
std::vector<interfaces::WalletAddress> addresses = wallet.getLabelAddress("stealth");
94-
if(!isOnDemand && !addresses.empty()) {
95-
interfaces::WalletAddress address = addresses[0];
96-
if (address.dest.type() == typeid(CStealthAddress)){
93+
std::string addressName = " ";
94+
isminetype isMine = ISMINE_NO;
95+
std::string purpose = " ";
96+
97+
if (!isOnDemand && displayAddressSet) {
98+
bool doesAddyExist = wallet.getAddress(currentDisplayAddress, &addressName, &isMine, &purpose);
99+
strAddress = EncodeDestination(currentDisplayAddress, !("receive_miner" == purpose));
100+
} else {
101+
std::vector<interfaces::WalletAddress> addresses = wallet.getLabelAddress("stealth");
102+
if(!isOnDemand && !addresses.empty()) {
103+
interfaces::WalletAddress address = addresses[0];
104+
if (address.dest.type() == typeid(CStealthAddress)){
105+
bool fBech32 = true;
106+
strAddress = EncodeDestination(address.dest,true);
107+
}
108+
}else {
109+
// Generate a new address to associate with given label
110+
CStealthAddress address;
111+
if (!wallet.getNewStealthAddress(address)) {
112+
openToastDialog("Wallet Encrypted, please unlock it first", mainWindow->getGUI());
113+
return false;
114+
}
97115
bool fBech32 = true;
98-
strAddress = EncodeDestination(address.dest,true);
116+
strAddress = address.ToString(fBech32);
117+
// Store it
118+
wallet.setAddressBook(DecodeDestination(strAddress), "", "receive", true);
99119
}
100-
}else {
101-
// Generate a new address to associate with given label
102-
CStealthAddress address;
103-
if (!wallet.getNewStealthAddress(address)) {
104-
openToastDialog("Wallet Encrypted, please unlock it first", mainWindow->getGUI());
105-
return false;
106-
}
107-
bool fBech32 = true;
108-
strAddress = address.ToString(fBech32);
109-
// Store it
110-
wallet.setAddressBook(DecodeDestination(strAddress), "", "receive", true);
111120
}
112121

113122
qAddress = QString::fromStdString(strAddress);
114123

115124
// set address
116125
ui->labelAddress->setText(qAddress.left(16) + "..." + qAddress.right(16));
126+
ui->labelAddressName->setText(QString::fromStdString(addressName));
117127

118128
SendCoinsRecipient info;
119129
info.address = qAddress;
@@ -215,3 +225,9 @@ void ReceiveWidget::refreshWalletStatus() {
215225
// TODO: Use latest address instead of generate one every time.
216226
generateNewAddress();
217227
}
228+
229+
void ReceiveWidget::setDisplayRcvAddress(CTxDestination *displayAddress) {
230+
displayAddressSet = true;
231+
currentDisplayAddress = *displayAddress;
232+
generateNewAddress(false);
233+
}

src/qt/veil/receivewidget.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class ReceiveWidget : public QWidget
2727
virtual void showEvent(QShowEvent *event) override;
2828
virtual void hideEvent(QHideEvent *event) override;
2929
void setWalletModel(WalletModel *model);
30-
30+
void setDisplayRcvAddress(CTxDestination *displayAddress);
3131

3232
void refreshWalletStatus();
3333

@@ -45,6 +45,9 @@ public Q_SLOTS:
4545
QString qAddress;
4646

4747
bool generateNewAddress(bool isOnDemand = false);
48+
49+
bool displayAddressSet = false;
50+
CTxDestination currentDisplayAddress;
4851
};
4952

5053
#endif // RECEIVEWIDGET_H

src/qt/walletframe.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ bool WalletFrame::addWallet(WalletModel *walletModel)
7676

7777
connect(walletView, SIGNAL(outOfSyncWarningClicked()), this, SLOT(outOfSyncWarningClicked()));
7878

79+
connect(walletView, SIGNAL(signalChangeSelectedAddress(CTxDestination*)), this, SLOT(notifySelectedRcvAddyChanged(CTxDestination*)));
80+
7981
return true;
8082
}
8183

@@ -98,6 +100,9 @@ bool WalletFrame::removeWallet(const QString &name)
98100

99101
WalletView *walletView = mapWalletViews.take(name);
100102
walletStack->removeWidget(walletView);
103+
104+
disconnect(walletView, SIGNAL(signalChangeSelectedAddress(CTxDestination*)), this, SLOT(notifySelectedRcvAddyChanged(CTxDestination*)));
105+
101106
delete walletView;
102107
return true;
103108
}
@@ -233,3 +238,8 @@ void WalletFrame::outOfSyncWarningClicked()
233238
{
234239
Q_EMIT requestedSyncWarningInfo();
235240
}
241+
242+
void WalletFrame::notifySelectedRcvAddyChanged(CTxDestination* selectedRcvAddress)
243+
{
244+
Q_EMIT changeSelectedRcvAddress(selectedRcvAddress);
245+
}

0 commit comments

Comments
 (0)