Skip to content

Introduce Send pages for singlesig, single input/output send #445

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/Makefile.qt.include
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,11 @@ QT_MOC_CPP = \
qml/models/moc_peerdetailsmodel.cpp \
qml/models/moc_peerlistsortproxy.cpp \
qml/models/moc_transaction.cpp \
qml/models/moc_sendrecipient.cpp \
qml/models/moc_walletlistmodel.cpp \
qml/models/moc_walletqmlmodel.cpp \
qml/models/moc_walletqmlmodel.cpp \
qml/models/moc_walletqmlmodeltransaction.cpp \
qml/moc_appmode.cpp \
qml/moc_bitcoinamount.cpp \
qml/moc_clipboard.cpp \
Expand Down Expand Up @@ -132,8 +135,10 @@ BITCOIN_QT_H = \
qml/models/peerdetailsmodel.h \
qml/models/peerlistsortproxy.h \
qml/models/transaction.h \
qml/models/sendrecipient.h \
qml/models/walletlistmodel.h \
qml/models/walletqmlmodel.h \
qml/models/walletqmlmodeltransaction.h \
qml/appmode.h \
qml/clipboard.h \
qml/bitcoin.h \
Expand Down Expand Up @@ -329,8 +334,10 @@ BITCOIN_QML_BASE_CPP = \
qml/models/peerdetailsmodel.cpp \
qml/models/peerlistsortproxy.cpp \
qml/models/transaction.cpp \
qml/models/sendrecipient.cpp \
qml/models/walletlistmodel.cpp \
qml/models/walletqmlmodel.cpp \
qml/models/walletqmlmodeltransaction.cpp \
qml/imageprovider.cpp \
qml/util.cpp \
qml/walletqmlcontroller.cpp
Expand Down Expand Up @@ -462,6 +469,9 @@ QML_RES_QML = \
qml/pages/wallet/CreateWalletWizard.qml \
qml/pages/wallet/DesktopWallets.qml \
qml/pages/wallet/RequestPayment.qml \
qml/pages/wallet/Send.qml \
qml/pages/wallet/SendResult.qml \
qml/pages/wallet/SendReview.qml \
qml/pages/wallet/WalletBadge.qml \
qml/pages/wallet/WalletSelect.qml

Expand Down
7 changes: 6 additions & 1 deletion src/qml/bitcoin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,18 @@
#include <qml/components/blockclockdial.h>
#include <qml/controls/linegraph.h>
#include <qml/guiconstants.h>
#include <qml/imageprovider.h>
#include <qml/models/activitylistmodel.h>
#include <qml/models/chainmodel.h>
#include <qml/models/networktraffictower.h>
#include <qml/models/nodemodel.h>
#include <qml/models/options_model.h>
#include <qml/models/peerdetailsmodel.h>
#include <qml/models/peerlistsortproxy.h>
#include <qml/models/sendrecipient.h>
#include <qml/models/walletlistmodel.h>
#include <qml/models/walletqmlmodel.h>
#include <qml/imageprovider.h>
#include <qml/models/walletqmlmodeltransaction.h>
#include <qml/util.h>
#include <qml/walletqmlcontroller.h>
#include <qt/guiutil.h>
Expand Down Expand Up @@ -337,10 +339,13 @@ int QmlGuiMain(int argc, char* argv[])
qmlRegisterUncreatableType<PeerDetailsModel>("org.bitcoincore.qt", 1, 0, "PeerDetailsModel", "");
qmlRegisterType<BitcoinAmount>("org.bitcoincore.qt", 1, 0, "BitcoinAmount");
qmlRegisterUncreatableType<Transaction>("org.bitcoincore.qt", 1, 0, "Transaction", "");
qmlRegisterUncreatableType<SendRecipient>("org.bitcoincore.qt", 1, 0, "SendRecipient", "");

#ifdef ENABLE_WALLET
qmlRegisterUncreatableType<WalletQmlModel>("org.bitcoincore.qt", 1, 0, "WalletQmlModel",
"WalletQmlModel cannot be instantiated from QML");
qmlRegisterUncreatableType<WalletQmlModelTransaction>("org.bitcoincore.qt", 1, 0, "WalletQmlModelTransaction",
"WalletQmlModelTransaction cannot be instantiated from QML");
#endif

engine.load(QUrl(QStringLiteral("qrc:///qml/pages/main.qml")));
Expand Down
4 changes: 3 additions & 1 deletion src/qml/bitcoin_qml.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
<file>controls/ContinueButton.qml</file>
<file>controls/CoreText.qml</file>
<file>controls/CoreTextField.qml</file>
<file>controls/LabeledTextInput.qml</file>
<file>controls/ExternalLink.qml</file>
<file>controls/FocusBorder.qml</file>
<file>controls/Header.qml</file>
Expand Down Expand Up @@ -83,6 +82,9 @@
<file>pages/wallet/CreateWalletWizard.qml</file>
<file>pages/wallet/DesktopWallets.qml</file>
<file>pages/wallet/RequestPayment.qml</file>
<file>pages/wallet/Send.qml</file>
<file>pages/wallet/SendResult.qml</file>
<file>pages/wallet/SendReview.qml</file>
<file>pages/wallet/WalletBadge.qml</file>
<file>pages/wallet/WalletSelect.qml</file>
</qresource>
Expand Down
31 changes: 29 additions & 2 deletions src/qml/bitcoinamount.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,28 @@ QString BitcoinAmount::amount() const
return m_amount;
}

QString BitcoinAmount::satoshiAmount() const
{
return toSatoshis(m_amount);
}

void BitcoinAmount::setAmount(const QString& new_amount)
{
m_amount = sanitize(new_amount);
Q_EMIT amountChanged();
}

long long BitcoinAmount::toSatoshis(QString& amount, const Unit unit)
QString BitcoinAmount::toSatoshis(const QString& text) const
{
if (m_unit == Unit::SAT) {
return text;
} else {
return convert(text, m_unit);
}
}

long long BitcoinAmount::toSatoshis(QString& amount, const Unit unit)
{
int num_decimals = decimals(unit);

QStringList parts = amount.remove(' ').split(".");
Expand All @@ -93,7 +106,7 @@ long long BitcoinAmount::toSatoshis(QString& amount, const Unit unit)
return str.toLongLong();
}

QString BitcoinAmount::convert(const QString &amount, Unit unit)
QString BitcoinAmount::convert(const QString& amount, Unit unit) const
{
if (amount == "") {
return amount;
Expand All @@ -113,6 +126,10 @@ QString BitcoinAmount::convert(const QString &amount, Unit unit)
result.append(QString(8 - numDigitsAfterDecimal, '0'));
}
result.remove(decimalPosition, 1);

while (result.startsWith('0') && result.length() > 1) {
result.remove(0, 1);
}
} else if (unit == Unit::SAT) {
result.remove(decimalPosition, 1);
int newDecimalPosition = decimalPosition - 8;
Expand All @@ -121,6 +138,16 @@ QString BitcoinAmount::convert(const QString &amount, Unit unit)
newDecimalPosition = 0;
}
result.insert(newDecimalPosition, ".");

while (result.endsWith('0') && result.contains('.')) {
result.chop(1);
}
if (result.endsWith('.')) {
result.chop(1);
}
if (result.startsWith('.')) {
result.insert(0, "0");
}
}

return result;
Expand Down
10 changes: 7 additions & 3 deletions src/qml/bitcoinamount.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@
#ifndef BITCOIN_QML_BITCOINAMOUNT_H
#define BITCOIN_QML_BITCOINAMOUNT_H

#include <consensus/amount.h>

#include <QObject>
#include <QString>
#include <qobjectdefs.h>

class BitcoinAmount : public QObject
{
Q_OBJECT
Q_PROPERTY(Unit unit READ unit WRITE setUnit NOTIFY unitChanged)
Q_PROPERTY(QString unitLabel READ unitLabel NOTIFY unitChanged)
Q_PROPERTY(QString amount READ amount WRITE setAmount NOTIFY amountChanged)
Q_PROPERTY(QString satoshiAmount READ satoshiAmount NOTIFY amountChanged)

public:
enum class Unit {
Expand All @@ -30,10 +32,12 @@ class BitcoinAmount : public QObject
QString unitLabel() const;
QString amount() const;
void setAmount(const QString& new_amount);
QString satoshiAmount() const;

public Q_SLOTS:
QString sanitize(const QString &text);
QString convert(const QString &text, Unit unit);
QString sanitize(const QString& text);
QString convert(const QString& text, Unit unit) const;
QString toSatoshis(const QString& text) const;

Q_SIGNALS:
void unitChanged();
Expand Down
5 changes: 5 additions & 0 deletions src/qml/imageprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,5 +206,10 @@ QPixmap ImageProvider::requestPixmap(const QString& id, QSize* size, const QSize
*size = requested_size;
return QIcon(":/icons/plus").pixmap(requested_size);
}

if (id == "flip-vertical") {
*size = requested_size;
return QIcon(":/icons/flip-vertical").pixmap(requested_size);
}
return {};
}
87 changes: 87 additions & 0 deletions src/qml/models/sendrecipient.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// Copyright (c) 2025 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <qml/models/sendrecipient.h>
#include <qobjectdefs.h>

SendRecipient::SendRecipient(QObject* parent)
: QObject(parent), m_address(""), m_label(""), m_amount(""), m_message("")
{
}

QString SendRecipient::address() const
{
return m_address;
}

void SendRecipient::setAddress(const QString& address)
{
if (m_address != address) {
m_address = address;
Q_EMIT addressChanged();
}
}

QString SendRecipient::label() const
{
return m_label;
}

void SendRecipient::setLabel(const QString& label)
{
if (m_label != label) {
m_label = label;
Q_EMIT labelChanged();
}
}

QString SendRecipient::amount() const
{
return m_amount;
}

void SendRecipient::setAmount(const QString& amount)
{
if (m_amount != amount) {
m_amount = amount;
Q_EMIT amountChanged();
}
}

QString SendRecipient::message() const
{
return m_message;
}

void SendRecipient::setMessage(const QString& message)
{
if (m_message != message) {
m_message = message;
Q_EMIT messageChanged();
}
}

bool SendRecipient::subtractFeeFromAmount() const
{
return m_subtractFeeFromAmount;
}

CAmount SendRecipient::cAmount() const
{
// TODO: Figure out who owns the parsing of SendRecipient::amount to CAmount
return m_amount.toLongLong();
}

void SendRecipient::clear()
{
m_address = "";
m_label = "";
m_amount = "";
m_message = "";
m_subtractFeeFromAmount = false;
Q_EMIT addressChanged();
Q_EMIT labelChanged();
Q_EMIT amountChanged();
Q_EMIT messageChanged();
}
55 changes: 55 additions & 0 deletions src/qml/models/sendrecipient.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright (c) 2025 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#ifndef BITCOIN_QML_MODELS_SENDRECIPIENT_H
#define BITCOIN_QML_MODELS_SENDRECIPIENT_H

#include <QObject>
#include <QString>
#include <qml/bitcoinamount.h>

class SendRecipient : public QObject
{
Q_OBJECT
Q_PROPERTY(QString address READ address WRITE setAddress NOTIFY addressChanged)
Q_PROPERTY(QString label READ label WRITE setLabel NOTIFY labelChanged)
Q_PROPERTY(QString amount READ amount WRITE setAmount NOTIFY amountChanged)
Q_PROPERTY(QString message READ message WRITE setMessage NOTIFY messageChanged)

public:
explicit SendRecipient(QObject* parent = nullptr);

QString address() const;
void setAddress(const QString& address);

QString label() const;
void setLabel(const QString& label);

QString amount() const;
void setAmount(const QString& amount);

QString message() const;
void setMessage(const QString& message);

CAmount cAmount() const;

bool subtractFeeFromAmount() const;

Q_INVOKABLE void clear();

Q_SIGNALS:
void addressChanged();
void labelChanged();
void amountChanged();
void messageChanged();

private:
QString m_address;
QString m_label;
QString m_amount;
QString m_message;
bool m_subtractFeeFromAmount{false};
};

#endif // BITCOIN_QML_MODELS_SENDRECIPIENT_H
Loading
Loading