Skip to content

Commit c3b688f

Browse files
committed
qt: format send review amounts with display unit
WalletQmlModelTransaction previously returned raw satoshi integers from amount(), fee(), and total(), so the review page showed unformatted numbers with no unit label. Add display unit awareness to WalletQmlModelTransaction: a setDisplayUnit() method stores the active unit and re-emits the relevant changed signals, and a formatWithUnit() helper formats values using QmlBitcoinUnits with the correct "sat"/"sats"/"₿" suffix. WalletQmlModel cascades the display unit to the current transaction both when the transaction is created and when the unit changes. Also append the unit label to per-recipient amounts in MultipleSendReview.
1 parent 0253c59 commit c3b688f

4 files changed

Lines changed: 34 additions & 4 deletions

File tree

qml/models/walletqmlmodel.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ bool WalletQmlModel::prepareTransaction()
283283
m_current_transaction = new WalletQmlModelTransaction(m_send_recipients, this);
284284
m_current_transaction->setWtx(newTx);
285285
m_current_transaction->setTransactionFee(nFeeRequired);
286+
m_current_transaction->setDisplayUnit(m_display_unit);
286287
Q_EMIT currentTransactionChanged();
287288
return true;
288289
} else {
@@ -386,6 +387,9 @@ void WalletQmlModel::setDisplayUnit(int unit)
386387
if (m_activity_list_model) {
387388
m_activity_list_model->setDisplayUnit(unit);
388389
}
390+
if (m_current_transaction) {
391+
m_current_transaction->setDisplayUnit(unit);
392+
}
389393
Q_EMIT balanceChanged();
390394
Q_EMIT displayUnitChanged(unit);
391395
}

qml/models/walletqmlmodeltransaction.cpp

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include <qml/models/walletqmlmodeltransaction.h>
66

7+
#include <qml/bitcoinunits.h>
78
#include <qml/models/sendrecipient.h>
89
#include <qml/models/sendrecipientslistmodel.h>
910

@@ -14,9 +15,19 @@ WalletQmlModelTransaction::WalletQmlModelTransaction(const SendRecipientsListMod
1415
{
1516
}
1617

18+
QString WalletQmlModelTransaction::formatWithUnit(CAmount value, int display_unit)
19+
{
20+
auto unit = (display_unit == 1) ? QmlBitcoinUnits::Unit::SAT : QmlBitcoinUnits::Unit::BTC;
21+
QString num = QmlBitcoinUnits::format(unit, value, false, QmlBitcoinUnits::SeparatorStyle::STANDARD);
22+
if (display_unit == 1) {
23+
return num + " " + ((qAbs(value) == 1) ? QStringLiteral("sat") : QStringLiteral("sats"));
24+
}
25+
return num + "";
26+
}
27+
1728
QString WalletQmlModelTransaction::amount() const
1829
{
19-
return QString::number(m_amount);
30+
return formatWithUnit(m_amount, m_display_unit);
2031
}
2132

2233
QString WalletQmlModelTransaction::address() const
@@ -26,19 +37,29 @@ QString WalletQmlModelTransaction::address() const
2637

2738
QString WalletQmlModelTransaction::fee() const
2839
{
29-
return QString::number(m_fee);
40+
return formatWithUnit(m_fee, m_display_unit);
3041
}
3142

3243
QString WalletQmlModelTransaction::total() const
3344
{
34-
return QString::number(m_amount + m_fee);
45+
return formatWithUnit(m_amount + m_fee, m_display_unit);
3546
}
3647

3748
QString WalletQmlModelTransaction::label() const
3849
{
3950
return m_label;
4051
}
4152

53+
void WalletQmlModelTransaction::setDisplayUnit(int unit)
54+
{
55+
if (unit != m_display_unit) {
56+
m_display_unit = unit;
57+
Q_EMIT amountChanged();
58+
Q_EMIT feeChanged();
59+
Q_EMIT totalChanged();
60+
}
61+
}
62+
4263
CTransactionRef& WalletQmlModelTransaction::getWtx()
4364
{
4465
return m_wtx;

qml/models/walletqmlmodeltransaction.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ class WalletQmlModelTransaction : public QObject
3838

3939
CAmount getTotalTransactionAmount() const;
4040

41+
void setDisplayUnit(int unit);
42+
4143
void reassignAmounts(int nChangePosRet); // needed for the subtract-fee-from-amount feature
4244

4345
Q_SIGNALS:
@@ -48,11 +50,14 @@ class WalletQmlModelTransaction : public QObject
4850
void totalChanged();
4951

5052
private:
53+
static QString formatWithUnit(CAmount value, int display_unit);
54+
5155
QString m_address;
5256
CAmount m_amount;
5357
CAmount m_fee;
5458
QString m_label;
5559
CTransactionRef m_wtx;
60+
int m_display_unit{0};
5661
};
5762

5863
#endif // BITCOIN_QML_MODELS_WALLETQMLMODELTRANSACTION_H

qml/pages/wallet/MultipleSendReview.qml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ Page {
8282

8383
CoreText {
8484
Layout.alignment: Qt.AlignVCenter | Qt.AlignRight
85-
text: amount
85+
text: amount + (optionsModel.displayUnit === 1 ? " sats" : "")
8686
font.pixelSize: 18
8787
}
8888
}

0 commit comments

Comments
 (0)