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
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

View File

@ -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 {

View File

@ -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
}
}

View File

@ -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<clipboardAdapter>("moneroComponents", 1, 0, "Clipboard");
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;

View File

@ -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()
}

View File

@ -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 <font size='2'>( Optional )</font>")
}
// 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)
}
}
}
}

View File

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

View File

@ -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)
{

View File

@ -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: