@@ -145,6 +145,7 @@ void SendWidget::refreshAmounts()
145145 nDisplayUnit = walletModel->getOptionsModel ()->getDisplayUnit ();
146146
147147 CAmount totalAmount = 0 ;
148+ CAmount delegatedBalance = 0 ;
148149 QString titleTotalRemaining;
149150 if (coinControlDialog->coinControl ->HasSelected ()) {
150151 // Set remaining balance to the sum of the coinControl selected inputs
@@ -157,9 +158,17 @@ void SendWidget::refreshAmounts()
157158 totalAmount = selectedBalance - total;
158159 titleTotalRemaining = tr (" Total remaining from the selected UTXO" );
159160 } else {
160- // Wallet's unlocked balance.
161- totalAmount = isTransparent ? (walletModel->getUnlockedBalance (nullptr , fDelegationsChecked , false ) - total)
162- : (walletModel->GetWalletBalances ().shielded_balance - total);
161+ interfaces::WalletBalances balances = walletModel->GetWalletBalances ();
162+ if (isTransparent) {
163+ totalAmount = balances.balance - balances.shielded_balance - walletModel->getLockedBalance () - total;
164+ if (!fDelegationsChecked ) {
165+ totalAmount -= balances.delegate_balance ;
166+ }
167+ // show delegated balance if exist
168+ delegatedBalance = balances.delegate_balance ;
169+ } else {
170+ totalAmount = balances.shielded_balance - total;
171+ }
163172 titleTotalRemaining = tr (" Unlocked remaining" );
164173 }
165174
@@ -168,16 +177,20 @@ void SendWidget::refreshAmounts()
168177 QMetaObject::invokeMethod (this , " updateAmounts" , Qt::QueuedConnection,
169178 Q_ARG (QString, titleTotalRemaining),
170179 Q_ARG (QString, GUIUtil::formatBalance (total, nDisplayUnit, false )),
171- Q_ARG (QString, labelAmountRemaining));
180+ Q_ARG (QString, labelAmountRemaining),
181+ Q_ARG (CAmount, delegatedBalance));
172182}
173183
174- void SendWidget::updateAmounts (const QString& _titleTotalRemaining, const QString& _labelAmountSend, const QString& _labelAmountRemaining)
184+ void SendWidget::updateAmounts (const QString& _titleTotalRemaining,
185+ const QString& _labelAmountSend,
186+ const QString& _labelAmountRemaining,
187+ CAmount _delegationBalance)
175188{
176189 ui->labelTitleTotalRemaining ->setText (_titleTotalRemaining);
177190 ui->labelAmountSend ->setText (_labelAmountSend);
178191 ui->labelAmountRemaining ->setText (_labelAmountRemaining);
179192 // show or hide delegations checkbox if need be
180- showHideCheckBoxDelegations ();
193+ showHideCheckBoxDelegations (_delegationBalance );
181194}
182195
183196void SendWidget::loadClientModel ()
@@ -338,19 +351,19 @@ void SendWidget::setFocusOnLastEntry()
338351 if (!entries.isEmpty ()) entries.last ()->setFocus ();
339352}
340353
341- void SendWidget::showHideCheckBoxDelegations ()
354+ void SendWidget::showHideCheckBoxDelegations (CAmount delegationBalance )
342355{
343356 // Show checkbox only when there is any available owned delegation and
344357 // coincontrol is not selected, and we are trying to spend transparent PIVs.
345358 const bool isCControl = coinControlDialog ? coinControlDialog->coinControl ->HasSelected () : false ;
346- const bool hasDel = cachedDelegatedBalance > 0 ;
359+ const bool hasDel = delegationBalance > 0 ;
347360
348361 const bool showCheckBox = isTransparent && !isCControl && hasDel;
349362 ui->checkBoxDelegations ->setVisible (showCheckBox);
350363 if (showCheckBox)
351364 ui->checkBoxDelegations ->setToolTip (
352365 tr (" Possibly spend coins delegated for cold-staking (currently available: %1" ).arg (
353- GUIUtil::formatBalance (cachedDelegatedBalance , nDisplayUnit, false ))
366+ GUIUtil::formatBalance (delegationBalance , nDisplayUnit, false ))
354367 );
355368}
356369
@@ -521,9 +534,6 @@ bool SendWidget::sendFinalStep()
521534 );
522535
523536 if (sendStatus.status == WalletModel::OK) {
524- // if delegations were spent, update cachedBalance
525- if (fStakeDelegationVoided )
526- cachedDelegatedBalance = walletModel->getDelegatedBalance ();
527537 clearAll (false );
528538 inform (tr (" Transaction sent" ));
529539 dialog->deleteLater ();
0 commit comments