basic "send money" functionality implemented in GUI

This commit is contained in:
Ilya Kitaev 2016-06-16 17:13:46 +03:00
parent 3ddd9bed72
commit eaf59243b2
9 changed files with 82 additions and 6 deletions

View File

@ -56,6 +56,7 @@ Rectangle {
width: 260 width: 260
color: "#FFFFFF" color: "#FFFFFF"
// Item with monero logo
Item { Item {
id: logoItem id: logoItem
anchors.left: parent.left anchors.left: parent.left
@ -85,6 +86,7 @@ Rectangle {
} }
} }
Column { Column {
id: column1 id: column1
anchors.left: parent.left anchors.left: parent.left

View File

@ -30,6 +30,7 @@ import QtQuick 2.2
Rectangle { Rectangle {
color: "#F0EEEE" color: "#F0EEEE"
signal paymentClicked(string address, string paymentId, double amount, double fee, int privacyLevel)
states: [ states: [
State { State {
@ -72,6 +73,19 @@ Rectangle {
anchors.right: parent.right anchors.right: parent.right
anchors.top: styledRow.bottom anchors.top: styledRow.bottom
anchors.bottom: parent.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 { Rectangle {

View File

@ -31,7 +31,9 @@ import QtQuick 2.0
Item { Item {
property alias placeholderText: input.placeholderText property alias placeholderText: input.placeholderText
property alias text: input.text property alias text: input.text
property alias validator: input.validator
property int fontSize: 18 property int fontSize: 18
height: 37 height: 37
Rectangle { Rectangle {
@ -54,5 +56,6 @@ Item {
anchors.leftMargin: 4 anchors.leftMargin: 4
anchors.rightMargin: 4 anchors.rightMargin: 4
font.pixelSize: parent.fontSize font.pixelSize: parent.fontSize
} }
} }

View File

@ -36,6 +36,7 @@
#include "oshelper.h" #include "oshelper.h"
#include "WalletManager.h" #include "WalletManager.h"
#include "Wallet.h" #include "Wallet.h"
#include "PendingTransaction.h"
@ -53,6 +54,8 @@ int main(int argc, char *argv[])
qmlRegisterType<clipboardAdapter>("moneroComponents", 1, 0, "Clipboard"); qmlRegisterType<clipboardAdapter>("moneroComponents", 1, 0, "Clipboard");
qmlRegisterUncreatableType<Wallet>("Bitmonero.Wallet", 1, 0, "Wallet", "Wallet can't be instantiated directly"); qmlRegisterUncreatableType<Wallet>("Bitmonero.Wallet", 1, 0, "Wallet", "Wallet can't be instantiated directly");
qmlRegisterUncreatableType<PendingTransaction>("Bitmonero.PendingTransaction", 1, 0, "PendingTransaction",
"PendingTransaction can't be instantiated directly");
QQmlApplicationEngine engine; QQmlApplicationEngine engine;

View File

@ -32,6 +32,7 @@ import QtQuick.Controls 1.1
import QtQuick.Controls.Styles 1.1 import QtQuick.Controls.Styles 1.1
import Qt.labs.settings 1.0 import Qt.labs.settings 1.0
import Bitmonero.Wallet 1.0 import Bitmonero.Wallet 1.0
import Bitmonero.PendingTransaction 1.0
import "components" import "components"
import "wizard" import "wizard"
@ -120,6 +121,8 @@ ApplicationWindow {
function initialize() { function initialize() {
middlePanel.paymentClicked.connect(handlePayment);
if (typeof wizard.settings['wallet'] !== 'undefined') { if (typeof wizard.settings['wallet'] !== 'undefined') {
wallet = wizard.settings['wallet']; wallet = wizard.settings['wallet'];
} else { } else {
@ -157,6 +160,27 @@ ApplicationWindow {
return wallets.length > 0; 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 visible: true
width: rightPanelExpanded ? 1269 : 1269 - 300 width: rightPanelExpanded ? 1269 : 1269 - 300
height: 800 height: 800
@ -423,6 +447,7 @@ ApplicationWindow {
} }
property var previousPosition property var previousPosition
onPressed: { onPressed: {
previousPosition = globalCursor.getPosition() previousPosition = globalCursor.getPosition()
} }

View File

@ -30,8 +30,11 @@ import QtQuick 2.0
import "../components" import "../components"
Rectangle { Rectangle {
signal paymentClicked(string address, string paymentId, double amount, double fee, int privacyLevel)
color: "#F0EEEE" color: "#F0EEEE"
Label { Label {
id: amountLabel id: amountLabel
anchors.left: parent.left anchors.left: parent.left
@ -67,8 +70,9 @@ Rectangle {
source: "../images/moneroIcon.png" source: "../images/moneroIcon.png"
} }
} }
// Amount input
LineEdit { LineEdit {
id: amountLine
placeholderText: qsTr("Amount...") placeholderText: qsTr("Amount...")
width: parent.width - 37 - 17 width: parent.width - 37 - 17
} }
@ -133,7 +137,7 @@ Rectangle {
onLinkActivated: appWindow.showPageRequest("AddressBook") onLinkActivated: appWindow.showPageRequest("AddressBook")
} }
// recipient address input
LineEdit { LineEdit {
id: addressLine id: addressLine
anchors.left: parent.left anchors.left: parent.left
@ -142,10 +146,11 @@ Rectangle {
anchors.leftMargin: 17 anchors.leftMargin: 17
anchors.rightMargin: 17 anchors.rightMargin: 17
anchors.topMargin: 5 anchors.topMargin: 5
// validator: RegExpValidator { regExp: /[0-9A-Fa-f]{95}/g }
} }
Label { Label {
id: paymentLabel id: paymentIdLabel
anchors.left: parent.left anchors.left: parent.left
anchors.right: parent.right anchors.right: parent.right
anchors.top: addressLine.bottom anchors.top: addressLine.bottom
@ -156,21 +161,23 @@ Rectangle {
text: qsTr("Payment ID <font size='2'>( Optional )</font>") text: qsTr("Payment ID <font size='2'>( Optional )</font>")
} }
// payment id input
LineEdit { LineEdit {
id: paymentLine id: paymentIdLine
anchors.left: parent.left anchors.left: parent.left
anchors.right: parent.right anchors.right: parent.right
anchors.top: paymentLabel.bottom anchors.top: paymentIdLabel.bottom
anchors.leftMargin: 17 anchors.leftMargin: 17
anchors.rightMargin: 17 anchors.rightMargin: 17
anchors.topMargin: 5 anchors.topMargin: 5
// validator: DoubleValidator { top: 0.0 }
} }
Label { Label {
id: descriptionLabel id: descriptionLabel
anchors.left: parent.left anchors.left: parent.left
anchors.right: parent.right anchors.right: parent.right
anchors.top: paymentLine.bottom anchors.top: paymentIdLine.bottom
anchors.leftMargin: 17 anchors.leftMargin: 17
anchors.rightMargin: 17 anchors.rightMargin: 17
anchors.topMargin: 17 anchors.topMargin: 17
@ -200,5 +207,13 @@ Rectangle {
shadowPressedColor: "#B32D00" shadowPressedColor: "#B32D00"
releasedColor: "#FF6C3C" releasedColor: "#FF6C3C"
pressedColor: "#FF4304" 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)
}
}
} }
} }

View File

@ -24,6 +24,8 @@ public:
Status_Error = Bitmonero::PendingTransaction::Status_Error Status_Error = Bitmonero::PendingTransaction::Status_Error
}; };
Q_ENUM(Status)
Status status() const; Status status() const;
QString errorString() const; QString errorString() const;
Q_INVOKABLE bool commit(); Q_INVOKABLE bool commit();

View File

@ -92,6 +92,15 @@ QString WalletManager::displayAmount(quint64 amount)
return QString::fromStdString(Bitmonero::Wallet::displayAmount(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) WalletManager::WalletManager(QObject *parent) : QObject(parent)
{ {

View File

@ -45,6 +45,9 @@ public:
//! since we can't call static method from QML, move it to this class //! since we can't call static method from QML, move it to this class
Q_INVOKABLE QString displayAmount(quint64 amount); Q_INVOKABLE QString displayAmount(quint64 amount);
Q_INVOKABLE quint64 amountFromString(const QString &amount);
Q_INVOKABLE quint64 amountFromDouble(double amount);
signals: signals:
public slots: public slots: