Skip to content

Commit 47f7fe1

Browse files
committed
[GUI] Update QR Code on address selection
1 parent 422ccbb commit 47f7fe1

14 files changed

+186
-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

+14
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,16 @@ 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+
std::string* addyname = new std::string();
250+
isminetype* isMine;
251+
std::string* purpose;
252+
253+
bool doesAddyExist = this->walletModel->wallet().getAddress(selectedAddress, addyname,isMine,purpose);
254+
255+
Q_EMIT rcvAddressSelected(&selectedAddress);
243256
}else{
244257
listView = ui->listContacts;
245258
type = AddressTableModel::Send;
@@ -371,6 +384,7 @@ void AddressesWidget::onNewAddressClicked(){
371384
openToastDialog(QString::fromStdString(toast + " Creation Failed"), mainWindow->getGUI());
372385
}
373386
// if it's the first one created, display it without having to reload
387+
// WE NEED TO DISPLAY THE NEW ADDRESS HERE AND IN THE BALANCE AND RECEIVE WIDGETS
374388
onForeground();
375389
}
376390

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

+38-24
Original file line numberDiff line numberDiff line change
@@ -232,37 +232,48 @@ 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;
237+
std::string* purpose;
238+
if (displayAddressSet) {
239+
strAddress = EncodeDestination(currentDisplayAddress, true);
240+
bool doesAddyExist = wallet.getAddress(currentDisplayAddress, &addressName, isMine, purpose);
241+
} else {
242+
std::vector<interfaces::WalletAddress> addresses = wallet.getLabelAddress("stealth");
243+
if(!addresses.empty()) {
244+
interfaces::WalletAddress address = addresses[0];
245+
if (address.dest.type() == typeid(CStealthAddress)){
246+
bool fBech32 = true;
247+
strAddress = EncodeDestination(address.dest,true);
248+
addressName = "stealth";
249+
}
250+
}else {
251+
ui->copyAddress->setVisible(true);
252+
ui->labelReceive->setAlignment(Qt::AlignLeft);
253+
ui->labelReceive->setText("Receiving address");
254+
// Generate a new address to associate with given label
255+
// TODO: Use only one stealth address here.
256+
CStealthAddress address;
257+
if (!walletModel->wallet().getNewStealthAddress(address)) {
258+
ui->labelQr->setText("");
259+
ui->copyAddress->setVisible(false);
260+
ui->labelReceive->setText("Wallet Locked");
261+
ui->labelReceive->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
262+
ui->labelAddress->setText("");
263+
return;
264+
}
239265
bool fBech32 = true;
240-
strAddress = EncodeDestination(address.dest,true);
266+
strAddress = address.ToString(fBech32);
267+
wallet.setAddressBook(DecodeDestination(strAddress), "stealth", "receive", fBech32);
268+
addressName = "stealth";
241269
}
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);
260270
}
261271

262272
qAddress = QString::fromStdString(strAddress);
263273

264274
// set address
265275
ui->labelAddress->setText(qAddress.left(12) + "..." + qAddress.right(12));
276+
ui->labelAddressName->setText(QString::fromStdString(addressName));
266277

267278
SendCoinsRecipient info;
268279
info.address = qAddress;
@@ -320,4 +331,7 @@ void Balance::refreshWalletStatus() {
320331
#endif
321332
}
322333

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

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

+31-16
Original file line numberDiff line numberDiff line change
@@ -90,30 +90,39 @@ 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;
95+
std::string* purpose;
96+
if (!isOnDemand && displayAddressSet) {
97+
strAddress = EncodeDestination(currentDisplayAddress, true);
98+
bool doesAddyExist = wallet.getAddress(currentDisplayAddress, &addressName, isMine, purpose);
99+
} else {
100+
std::vector<interfaces::WalletAddress> addresses = wallet.getLabelAddress("stealth");
101+
if(!isOnDemand && !addresses.empty()) {
102+
interfaces::WalletAddress address = addresses[0];
103+
if (address.dest.type() == typeid(CStealthAddress)){
104+
bool fBech32 = true;
105+
strAddress = EncodeDestination(address.dest,true);
106+
}
107+
}else {
108+
// Generate a new address to associate with given label
109+
CStealthAddress address;
110+
if (!wallet.getNewStealthAddress(address)) {
111+
openToastDialog("Wallet Encrypted, please unlock it first", mainWindow->getGUI());
112+
return false;
113+
}
97114
bool fBech32 = true;
98-
strAddress = EncodeDestination(address.dest,true);
115+
strAddress = address.ToString(fBech32);
116+
// Store it
117+
wallet.setAddressBook(DecodeDestination(strAddress), "", "receive", true);
99118
}
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);
111119
}
112120

113121
qAddress = QString::fromStdString(strAddress);
114122

115123
// set address
116124
ui->labelAddress->setText(qAddress.left(16) + "..." + qAddress.right(16));
125+
ui->labelAddressName->setText(QString::fromStdString(addressName));
117126

118127
SendCoinsRecipient info;
119128
info.address = qAddress;
@@ -215,3 +224,9 @@ void ReceiveWidget::refreshWalletStatus() {
215224
// TODO: Use latest address instead of generate one every time.
216225
generateNewAddress();
217226
}
227+
228+
void ReceiveWidget::setDisplayRcvAddress(CTxDestination *displayAddress) {
229+
displayAddressSet = true;
230+
currentDisplayAddress = *displayAddress;
231+
generateNewAddress(false);
232+
}

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)