Skip to content

Commit 6e49a11

Browse files
committed
GUI: send screen, initialize coinControlDialog view only when it's being called.
future: move workload to a background worker thread.
1 parent 379e5f2 commit 6e49a11

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

src/qt/coincontroldialog.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ class CoinControlDialog : public QDialog
6565
void clearPayAmounts();
6666
void addPayAmount(const CAmount& amount, bool isShieldedRecipient);
6767
void setSelectionType(bool isTransparent) { fSelectTransparent = isTransparent; }
68+
bool hasModel() { return model; }
6869

6970
CCoinControl* coinControl{nullptr};
7071

src/qt/pivx/send.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,6 @@ void SendWidget::loadClientModel()
192192
void SendWidget::loadWalletModel()
193193
{
194194
if (walletModel) {
195-
coinControlDialog->setModel(walletModel);
196195
if (walletModel->getOptionsModel()) {
197196
// display unit
198197
nDisplayUnit = walletModel->getOptionsModel()->getDisplayUnit();
@@ -254,13 +253,13 @@ void SendWidget::onResetCustomOptions(bool fRefreshAmounts)
254253

255254
void SendWidget::resetCoinControl()
256255
{
257-
coinControlDialog->coinControl->SetNull();
256+
if (coinControlDialog) coinControlDialog->coinControl->SetNull();
258257
ui->btnCoinControl->setActive(false);
259258
}
260259

261260
void SendWidget::resetChangeAddress()
262261
{
263-
coinControlDialog->coinControl->destChange = CNoDestination();
262+
if (coinControlDialog) coinControlDialog->coinControl->destChange = CNoDestination();
264263
ui->btnChangeAddress->setActive(false);
265264
ui->btnChangeAddress->setVisible(isTransparent);
266265
}
@@ -343,7 +342,7 @@ void SendWidget::showHideCheckBoxDelegations()
343342
{
344343
// Show checkbox only when there is any available owned delegation and
345344
// coincontrol is not selected, and we are trying to spend transparent PIVs.
346-
const bool isCControl = coinControlDialog->coinControl->HasSelected();
345+
const bool isCControl = coinControlDialog ? coinControlDialog->coinControl->HasSelected() : false;
347346
const bool hasDel = cachedDelegatedBalance > 0;
348347

349348
const bool showCheckBox = isTransparent && !isCControl && hasDel;
@@ -471,7 +470,9 @@ OperationResult SendWidget::prepareTransparent(WalletModelTransaction* currentTr
471470
if (!walletModel) return errorOut("Error, no wallet model loaded");
472471
// prepare transaction for getting txFee earlier
473472
WalletModel::SendCoinsReturn prepareStatus;
474-
prepareStatus = walletModel->prepareTransaction(currentTransaction, coinControlDialog->coinControl, fDelegationsChecked);
473+
prepareStatus = walletModel->prepareTransaction(currentTransaction,
474+
coinControlDialog ? coinControlDialog->coinControl : nullptr,
475+
fDelegationsChecked);
475476

476477
// process prepareStatus and on error generate message shown to user
477478
CClientUIInterface::MessageBoxFlags informType;
@@ -676,6 +677,8 @@ void SendWidget::onChangeCustomFeeClicked()
676677
void SendWidget::onCoinControlClicked()
677678
{
678679
if (walletModel->getBalance() > 0) {
680+
// future: move coin control initialization and refresh to a worker thread.
681+
if (!coinControlDialog->hasModel()) coinControlDialog->setModel(walletModel);
679682
coinControlDialog->setSelectionType(isTransparent);
680683
coinControlDialog->refreshDialog();
681684
setCoinControlPayAmounts();

0 commit comments

Comments
 (0)