Skip to content

Commit

Permalink
qt: Disable 'Verify Address On Hardware Wallet' when wallet is not li…
Browse files Browse the repository at this point in the history
…nked to a hw device.
  • Loading branch information
tecnovert committed Feb 26, 2020
1 parent 388e826 commit 888a84f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
14 changes: 10 additions & 4 deletions src/qt/addressbookpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,25 +116,25 @@ AddressBookPage::AddressBookPage(const PlatformStyle *platformStyle, Mode _mode,
QAction *copyAddressAction = new QAction(tr("&Copy Address"), this);
QAction *copyLabelAction = new QAction(tr("Copy &Label"), this);
QAction *editAction = new QAction(tr("&Edit"), this);
QAction *verifyAddressOnHWAction = new QAction(tr("&Verify Address On Hardware Wallet"), this);
hwVerifyAction = new QAction(tr("&Verify Address On Hardware Wallet"), this);
deleteAction = new QAction(ui->deleteAddress->text(), this);

// Build context menu
contextMenu = new QMenu(this);
contextMenu->addAction(copyAddressAction);
contextMenu->addAction(copyLabelAction);
contextMenu->addAction(editAction);
if(tab == SendingTab)
if(tab == SendingTab)
contextMenu->addAction(deleteAction);
else if(tab == ReceivingTab)
contextMenu->addAction(verifyAddressOnHWAction);
contextMenu->addAction(hwVerifyAction);
contextMenu->addSeparator();

// Connect signals for context menu actions
connect(copyAddressAction, &QAction::triggered, this, &AddressBookPage::on_copyAddress_clicked);
connect(copyLabelAction, &QAction::triggered, this, &AddressBookPage::onCopyLabelAction);
connect(editAction, &QAction::triggered, this, &AddressBookPage::onEditAction);
connect(verifyAddressOnHWAction, &QAction::triggered, this, &AddressBookPage::onVerifyAddressOnHWAction);
connect(hwVerifyAction, &QAction::triggered, this, &AddressBookPage::onVerifyAddressOnHWAction);
connect(deleteAction, &QAction::triggered, this, &AddressBookPage::on_deleteAddress_clicked);

connect(ui->tableView, &QWidget::customContextMenuRequested, this, &AddressBookPage::contextualMenu);
Expand Down Expand Up @@ -285,6 +285,12 @@ void AddressBookPage::selectionChanged()
ui->deleteAddress->setEnabled(false);
ui->copyAddress->setEnabled(false);
}

if (model && model->isHardwareLinked()) {
hwVerifyAction->setEnabled(true);
} else {
hwVerifyAction->setEnabled(false);
}
}

void AddressBookPage::done(int retval)
Expand Down
1 change: 1 addition & 0 deletions src/qt/addressbookpage.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public Q_SLOTS:
AddressBookSortFilterProxyModel *proxyModel;
QMenu *contextMenu;
QAction *deleteAction; // to be able to explicitly disable it
QAction *hwVerifyAction; // to be able to explicitly disable it
QString newAddressToSelect;

private Q_SLOTS:
Expand Down
10 changes: 7 additions & 3 deletions src/qt/addresstablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ void AddressTableModel::emitDataChanged(int idx)

void AddressTableModel::verifyOnHardwareDevice(QString path)
{
if (walletModel->isHardwareLinkedWallet()) {
if (isHardwareLinked()) {
// Clean up the path, remove the m/ in front of it.
path.remove(0, 2);

Expand All @@ -491,6 +491,10 @@ void AddressTableModel::verifyOnHardwareDevice(QString path)
if (!walletModel->tryCallRpc(sCommandDisplay, rv)) {
return;
}

}
}
}

bool AddressTableModel::isHardwareLinked()
{
return walletModel && walletModel->isHardwareLinkedWallet();
};
1 change: 1 addition & 0 deletions src/qt/addresstablemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ class AddressTableModel : public QAbstractTableModel

OutputType GetDefaultAddressType() const;
void verifyOnHardwareDevice(QString address);
bool isHardwareLinked();

private:
WalletModel* const walletModel;
Expand Down

0 comments on commit 888a84f

Please sign in to comment.