Skip to content

Commit 5893fd5

Browse files
committed
qml: Split amount and display updating for Bitcoin amount input
1 parent 8a6b593 commit 5893fd5

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

src/qml/bitcoinamount.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ void BitcoinAmount::setUnit(const Unit unit)
6666
{
6767
m_unit = unit;
6868
Q_EMIT unitChanged();
69+
Q_EMIT displayChanged();
6970
}
7071

7172
QString BitcoinAmount::unitLabel() const
@@ -85,7 +86,7 @@ void BitcoinAmount::flipUnit()
8586
m_unit = Unit::BTC;
8687
}
8788
Q_EMIT unitChanged();
88-
Q_EMIT amountChanged();
89+
Q_EMIT displayChanged();
8990
}
9091

9192
QString BitcoinAmount::satsToBtcString(qint64 sat)
@@ -151,3 +152,8 @@ void BitcoinAmount::fromDisplay(const QString& text)
151152
}
152153
setSatoshi(newSat);
153154
}
155+
156+
void BitcoinAmount::format()
157+
{
158+
Q_EMIT displayChanged();
159+
}

src/qml/bitcoinamount.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class BitcoinAmount : public QObject
1515
Q_OBJECT
1616
Q_PROPERTY(Unit unit READ unit WRITE setUnit NOTIFY unitChanged)
1717
Q_PROPERTY(QString unitLabel READ unitLabel NOTIFY unitChanged)
18-
Q_PROPERTY(QString display READ toDisplay WRITE fromDisplay NOTIFY amountChanged)
18+
Q_PROPERTY(QString display READ toDisplay WRITE fromDisplay NOTIFY displayChanged)
1919
Q_PROPERTY(qint64 satoshi READ satoshi WRITE setSatoshi NOTIFY amountChanged)
2020

2121
public:
@@ -36,6 +36,10 @@ class BitcoinAmount : public QObject
3636
qint64 satoshi() const;
3737
void setSatoshi(qint64 new_amount);
3838

39+
bool isSet() const { return m_isSet; }
40+
41+
Q_INVOKABLE void format();
42+
3943
static QString satsToBtcString(qint64 sat);
4044

4145
public Q_SLOTS:
@@ -45,6 +49,7 @@ public Q_SLOTS:
4549
Q_SIGNALS:
4650
void unitChanged();
4751
void amountChanged();
52+
void displayChanged();
4853

4954
private:
5055
QString sanitize(const QString& text);

src/qml/pages/wallet/Send.qml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,8 @@ PageStack {
194194
placeholderText: "0.00000000"
195195
selectByMouse: true
196196
text: root.recipient.amount.display
197-
onEditingFinished: root.recipient.amount.display = text
197+
onTextEdited: root.recipient.amount.display = text
198+
onEditingFinished: root.recipient.amount.format()
198199
onActiveFocusChanged: {
199200
if (!activeFocus) {
200201
root.recipient.amount.display = text

0 commit comments

Comments
 (0)