Skip to content

Commit 82e5e98

Browse files
committed
qml: fix sent activity amount sign
1 parent e994b39 commit 82e5e98

6 files changed

Lines changed: 60 additions & 6 deletions

File tree

qml/models/activitylistmodel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ QVariant ActivityListModel::data(const QModelIndex &index, int role) const
9696
case RequestIdRole:
9797
return tx->requestId;
9898
case NetAmountSatRole:
99-
return QVariant::fromValue<qlonglong>(tx->credit + tx->debit);
99+
return QVariant::fromValue<qlonglong>(tx->netAmount());
100100
default:
101101
return QVariant();
102102
}

qml/models/transaction.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,15 @@ Transaction::Transaction(uint256 hash, qint64 time)
4848
{
4949
}
5050

51+
CAmount Transaction::netAmount() const
52+
{
53+
return credit + debit;
54+
}
55+
5156
QString Transaction::prettyAmount(int display_unit) const
5257
{
53-
CAmount net = credit - debit;
54-
bool plus_sign = (net > 0);
58+
const CAmount net = netAmount();
59+
const bool plus_sign = (net > 0);
5560
QmlBitcoinUnits::Unit unit = (display_unit == 1)
5661
? QmlBitcoinUnits::Unit::SAT
5762
: QmlBitcoinUnits::Unit::BTC;

qml/models/transaction.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class Transaction : public QObject
4747

4848
Transaction(uint256 hash, qint64 time);
4949

50+
CAmount netAmount() const;
5051
QString prettyAmount(int display_unit = 0) const;
5152
QString dateTimeString() const;
5253
void updateStatus(const interfaces::WalletTxStatus& wtx, int num_blocks, int64_t block_time);

qml/pages/wallet/SendResult.qml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ Page {
9292
}
9393

9494
ContinueButton {
95+
objectName: "sendResultDoneButton"
9596
Layout.fillWidth: true
9697
Layout.preferredWidth: 1
9798
Layout.minimumWidth: 150

test/functional/qml_test_send_receive.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def has_text():
131131

132132

133133
def btc_text_to_sats(text):
134-
match = re.search(r"([0-9]+(?:\.[0-9]+)?)", text.replace(",", ""))
134+
match = re.search(r"(-?[0-9]+(?:\.[0-9]+)?)", text.replace(",", ""))
135135
if match is None:
136136
raise AssertionError(f"Could not parse BTC amount from {text!r}")
137137
try:
@@ -220,7 +220,7 @@ def run_test(*, save_screenshots=False, screenshot_root=None):
220220
)
221221
checkpoints.checkpoint("gui wallet funded", gui)
222222

223-
gui.click("desktopWalletsSendTab")
223+
gui.click("sendTabButton")
224224
gui.wait_for_page("sendPage", timeout_ms=10000)
225225
checkpoints.checkpoint("send page opened", gui)
226226

@@ -318,9 +318,31 @@ def run_test(*, save_screenshots=False, screenshot_root=None):
318318
)
319319
checkpoints.checkpoint("broadcast fee verified", gui)
320320

321+
gui.wait_for_page("sendResultPopup", timeout_ms=10000)
322+
gui.click("sendResultDoneButton")
323+
gui.wait_for_property("activityTabButton", "visible", True, timeout_ms=10000)
324+
gui.click("activityTabButton")
325+
gui.wait_for_property("activitySearchToggle", "visible", True, timeout_ms=10000)
326+
gui.click("activitySearchToggle")
327+
gui.wait_for_property("activitySearchToggle", "checked", True, timeout_ms=5000)
328+
gui.click("activityTypeFilterButton")
329+
gui.click("activityTypeSent")
330+
gui.wait_for_property("activityFilterProxyModel", "count", 1, timeout_ms=20000)
331+
activity_amount_text = gui.get_list_item_property("activityListView", 0, "amount")
332+
activity_amount_sats = amount_text_to_sats(activity_amount_text)
333+
assert activity_amount_text.startswith("-"), (
334+
f"Expected sent Activity amount to display with a minus sign, got {activity_amount_text!r}"
335+
)
336+
assert activity_amount_sats < 0, (
337+
f"Expected sent Activity amount to parse as negative sats, got "
338+
f"{activity_amount_text!r} ({activity_amount_sats} sats)"
339+
)
340+
checkpoints.checkpoint("sent Activity amount sign verified", gui)
341+
321342
print(
322343
"Send flow passed: preview totals were correct with include-fee off and on, "
323-
"and the broadcast fee matched the subtract-fee preview."
344+
"the broadcast fee matched the subtract-fee preview, and Activity showed the "
345+
"sent amount as negative."
324346
)
325347
return 0
326348
except Exception as err: # noqa: BLE001 - preserve failure context for functional test output

test/test_transaction.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class TransactionTests : public QObject
6868
private Q_SLOTS:
6969
void initTestCase();
7070
void fromWalletTx_hidesSenderChangeOutput();
71+
void fromWalletTx_mixedDebitKeepsNegativeNetAmount();
7172
void fromWalletTx_showsIncomingPaymentToChangeAddress();
7273
};
7374

@@ -92,6 +93,28 @@ void TransactionTests::fromWalletTx_hidesSenderChangeOutput()
9293
QCOMPARE(parts.at(0)->idx, 0);
9394
QCOMPARE(parts.at(0)->debit, -71 * COIN_VALUE);
9495
QCOMPARE(parts.at(0)->credit, 0);
96+
QCOMPARE(parts.at(0)->netAmount(), -71 * COIN_VALUE);
97+
QCOMPARE(parts.at(0)->prettyAmount(), QStringLiteral("-71.00000000"));
98+
}
99+
100+
void TransactionTests::fromWalletTx_mixedDebitKeepsNegativeNetAmount()
101+
{
102+
const interfaces::WalletTx wtx = MakeWalletTx(
103+
/*txin_is_mine=*/{ISMINE_SPENDABLE, ISMINE_NO},
104+
/*output_values=*/{80 * COIN_VALUE},
105+
/*txout_is_mine=*/{ISMINE_NO},
106+
/*txout_is_change=*/{false},
107+
/*debit=*/100 * COIN_VALUE);
108+
109+
const auto parts = Transaction::fromWalletTx(wtx);
110+
111+
QCOMPARE(parts.size(), 1);
112+
QCOMPARE(parts.at(0)->type, Transaction::Other);
113+
QCOMPARE(parts.at(0)->idx, 0);
114+
QCOMPARE(parts.at(0)->debit, -100 * COIN_VALUE);
115+
QCOMPARE(parts.at(0)->credit, 0);
116+
QCOMPARE(parts.at(0)->netAmount(), -100 * COIN_VALUE);
117+
QCOMPARE(parts.at(0)->prettyAmount(), QStringLiteral("-100.00000000"));
95118
}
96119

97120
void TransactionTests::fromWalletTx_showsIncomingPaymentToChangeAddress()
@@ -111,6 +134,8 @@ void TransactionTests::fromWalletTx_showsIncomingPaymentToChangeAddress()
111134
QCOMPARE(parts.at(0)->idx, 0);
112135
QCOMPARE(parts.at(0)->debit, 0);
113136
QCOMPARE(parts.at(0)->credit, 5 * COIN_VALUE);
137+
QCOMPARE(parts.at(0)->netAmount(), 5 * COIN_VALUE);
138+
QCOMPARE(parts.at(0)->prettyAmount(), QStringLiteral("+5.00000000"));
114139
}
115140

116141
#ifdef BITCOINQML_NO_TEST_MAIN

0 commit comments

Comments
 (0)