From eaf59243b2cbe3d7ea6de1d8dcd18493df9f365d Mon Sep 17 00:00:00 2001 From: Ilya Kitaev Date: Thu, 16 Jun 2016 17:13:46 +0300 Subject: [PATCH] basic "send money" functionality implemented in GUI --- LeftPanel.qml | 2 ++ MiddlePanel.qml | 14 ++++++++++++++ components/LineEdit.qml | 3 +++ main.cpp | 3 +++ main.qml | 25 +++++++++++++++++++++++++ pages/Transfer.qml | 27 +++++++++++++++++++++------ src/libwalletqt/PendingTransaction.h | 2 ++ src/libwalletqt/WalletManager.cpp | 9 +++++++++ src/libwalletqt/WalletManager.h | 3 +++ 9 files changed, 82 insertions(+), 6 deletions(-) diff --git a/LeftPanel.qml b/LeftPanel.qml index 1eddf019..95b5aa6f 100644 --- a/LeftPanel.qml +++ b/LeftPanel.qml @@ -56,6 +56,7 @@ Rectangle { width: 260 color: "#FFFFFF" + // Item with monero logo Item { id: logoItem anchors.left: parent.left @@ -85,6 +86,7 @@ Rectangle { } } + Column { id: column1 anchors.left: parent.left diff --git a/MiddlePanel.qml b/MiddlePanel.qml index 62072af9..28d6f137 100644 --- a/MiddlePanel.qml +++ b/MiddlePanel.qml @@ -30,6 +30,7 @@ import QtQuick 2.2 Rectangle { color: "#F0EEEE" + signal paymentClicked(string address, string paymentId, double amount, double fee, int privacyLevel) states: [ State { @@ -72,6 +73,19 @@ Rectangle { anchors.right: parent.right anchors.top: styledRow.bottom anchors.bottom: parent.bottom + onLoaded: { + console.log("Loaded " + item); + } + + } + + Connections { + ignoreUnknownSignals: false + target: loader.item + onPaymentClicked : { + console.log("MiddlePanel: paymentClicked") + paymentClicked(address, paymentId, amount, fee, privacyLevel) + } } Rectangle { diff --git a/components/LineEdit.qml b/components/LineEdit.qml index 6994b75f..37c2390d 100644 --- a/components/LineEdit.qml +++ b/components/LineEdit.qml @@ -31,7 +31,9 @@ import QtQuick 2.0 Item { property alias placeholderText: input.placeholderText property alias text: input.text + property alias validator: input.validator property int fontSize: 18 + height: 37 Rectangle { @@ -54,5 +56,6 @@ Item { anchors.leftMargin: 4 anchors.rightMargin: 4 font.pixelSize: parent.fontSize + } } diff --git a/main.cpp b/main.cpp index 7331a4e4..70390a80 100644 --- a/main.cpp +++ b/main.cpp @@ -36,6 +36,7 @@ #include "oshelper.h" #include "WalletManager.h" #include "Wallet.h" +#include "PendingTransaction.h" @@ -53,6 +54,8 @@ int main(int argc, char *argv[]) qmlRegisterType("moneroComponents", 1, 0, "Clipboard"); qmlRegisterUncreatableType("Bitmonero.Wallet", 1, 0, "Wallet", "Wallet can't be instantiated directly"); + qmlRegisterUncreatableType("Bitmonero.PendingTransaction", 1, 0, "PendingTransaction", + "PendingTransaction can't be instantiated directly"); QQmlApplicationEngine engine; diff --git a/main.qml b/main.qml index 3b79d1ec..d6109339 100644 --- a/main.qml +++ b/main.qml @@ -32,6 +32,7 @@ import QtQuick.Controls 1.1 import QtQuick.Controls.Styles 1.1 import Qt.labs.settings 1.0 import Bitmonero.Wallet 1.0 +import Bitmonero.PendingTransaction 1.0 import "components" import "wizard" @@ -120,6 +121,8 @@ ApplicationWindow { function initialize() { + middlePanel.paymentClicked.connect(handlePayment); + if (typeof wizard.settings['wallet'] !== 'undefined') { wallet = wizard.settings['wallet']; } else { @@ -157,6 +160,27 @@ ApplicationWindow { return wallets.length > 0; } + function handlePayment(address, paymentId, amount, fee, privacyLevel) { + console.log("Process payment here: ", address, paymentId, amount, fee, privacyLevel) + // TODO: handle payment id + // TODO: handle fee; + // TODO: handle mixins + var amountxmr = walletManager.amountFromString(amount); + + console.log("integer amount: ", amountxmr); + var pendingTransaction = wallet.createTransaction(address, amountxmr); + if (pendingTransaction.status !== PendingTransaction.Status_Ok) { + console.error("Can't create transaction: ", pendingTransaction.errorString); + } else { + console.log("Transaction created, amount: " + walletManager.displayAmount(pendingTransaction.amount) + + ", fee: " + walletManager.displayAmount(pendingTransaction.fee)); + if (!pendingTransaction.commit()) { + console.log("Error committing transaction: " + pendingTransaction.errorString); + } + } + wallet.disposeTransaction(pendingTransaction); + } + visible: true width: rightPanelExpanded ? 1269 : 1269 - 300 height: 800 @@ -423,6 +447,7 @@ ApplicationWindow { } property var previousPosition + onPressed: { previousPosition = globalCursor.getPosition() } diff --git a/pages/Transfer.qml b/pages/Transfer.qml index 2535b8fe..df0a5b20 100644 --- a/pages/Transfer.qml +++ b/pages/Transfer.qml @@ -30,8 +30,11 @@ import QtQuick 2.0 import "../components" Rectangle { + signal paymentClicked(string address, string paymentId, double amount, double fee, int privacyLevel) + color: "#F0EEEE" + Label { id: amountLabel anchors.left: parent.left @@ -67,8 +70,9 @@ Rectangle { source: "../images/moneroIcon.png" } } - + // Amount input LineEdit { + id: amountLine placeholderText: qsTr("Amount...") width: parent.width - 37 - 17 } @@ -133,7 +137,7 @@ Rectangle { onLinkActivated: appWindow.showPageRequest("AddressBook") } - + // recipient address input LineEdit { id: addressLine anchors.left: parent.left @@ -142,10 +146,11 @@ Rectangle { anchors.leftMargin: 17 anchors.rightMargin: 17 anchors.topMargin: 5 + // validator: RegExpValidator { regExp: /[0-9A-Fa-f]{95}/g } } Label { - id: paymentLabel + id: paymentIdLabel anchors.left: parent.left anchors.right: parent.right anchors.top: addressLine.bottom @@ -156,21 +161,23 @@ Rectangle { text: qsTr("Payment ID ( Optional )") } + // payment id input LineEdit { - id: paymentLine + id: paymentIdLine anchors.left: parent.left anchors.right: parent.right - anchors.top: paymentLabel.bottom + anchors.top: paymentIdLabel.bottom anchors.leftMargin: 17 anchors.rightMargin: 17 anchors.topMargin: 5 + // validator: DoubleValidator { top: 0.0 } } Label { id: descriptionLabel anchors.left: parent.left anchors.right: parent.right - anchors.top: paymentLine.bottom + anchors.top: paymentIdLine.bottom anchors.leftMargin: 17 anchors.rightMargin: 17 anchors.topMargin: 17 @@ -200,5 +207,13 @@ Rectangle { shadowPressedColor: "#B32D00" releasedColor: "#FF6C3C" pressedColor: "#FF4304" + onClicked: { + // do more smart validation + + if (addressLine.text.length > 0 && amountLine.text.length > 0) { + console.log("paymentClicked") + paymentClicked(addressLine.text, paymentIdLine.text, amountLine.text, 0.0002, 1) + } + } } } diff --git a/src/libwalletqt/PendingTransaction.h b/src/libwalletqt/PendingTransaction.h index 29fa7cb4..d8c4ec1e 100644 --- a/src/libwalletqt/PendingTransaction.h +++ b/src/libwalletqt/PendingTransaction.h @@ -24,6 +24,8 @@ public: Status_Error = Bitmonero::PendingTransaction::Status_Error }; + Q_ENUM(Status) + Status status() const; QString errorString() const; Q_INVOKABLE bool commit(); diff --git a/src/libwalletqt/WalletManager.cpp b/src/libwalletqt/WalletManager.cpp index 6ad81e2a..a7742bca 100644 --- a/src/libwalletqt/WalletManager.cpp +++ b/src/libwalletqt/WalletManager.cpp @@ -92,6 +92,15 @@ QString WalletManager::displayAmount(quint64 amount) return QString::fromStdString(Bitmonero::Wallet::displayAmount(amount)); } +quint64 WalletManager::amountFromString(const QString &amount) +{ + return Bitmonero::Wallet::amountFromString(amount.toStdString()); +} + +quint64 WalletManager::amountFromDouble(double amount) +{ + return Bitmonero::Wallet::amountFromDouble(amount); +} WalletManager::WalletManager(QObject *parent) : QObject(parent) { diff --git a/src/libwalletqt/WalletManager.h b/src/libwalletqt/WalletManager.h index 30e6b02a..29df9048 100644 --- a/src/libwalletqt/WalletManager.h +++ b/src/libwalletqt/WalletManager.h @@ -45,6 +45,9 @@ public: //! since we can't call static method from QML, move it to this class Q_INVOKABLE QString displayAmount(quint64 amount); + Q_INVOKABLE quint64 amountFromString(const QString &amount); + Q_INVOKABLE quint64 amountFromDouble(double amount); + signals: public slots: