[GUI] Transfers now work!
This commit is contained in:
parent
99d6450473
commit
eda4bae359
5 changed files with 76 additions and 23 deletions
|
|
@ -88,6 +88,10 @@ Asset* ChainDataModel::getAsset(QString symbol)
|
||||||
return *itr;
|
return *itr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QDateTime ChainDataModel::chainTime() const {
|
||||||
|
return QDateTime::fromTime_t(m_dynamic_global_properties.time.sec_since_epoch());
|
||||||
|
}
|
||||||
|
|
||||||
void ChainDataModel::processUpdatedObject(const fc::variant& update)
|
void ChainDataModel::processUpdatedObject(const fc::variant& update)
|
||||||
{
|
{
|
||||||
if (update.is_null())
|
if (update.is_null())
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@
|
||||||
#include "Asset.hpp"
|
#include "Asset.hpp"
|
||||||
#include "Account.hpp"
|
#include "Account.hpp"
|
||||||
|
|
||||||
|
#include <QDateTime>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
using graphene::chain::by_id;
|
using graphene::chain::by_id;
|
||||||
|
|
@ -37,6 +38,7 @@ typedef multi_index_container<
|
||||||
class Transaction;
|
class Transaction;
|
||||||
class ChainDataModel : public QObject {
|
class ChainDataModel : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(QDateTime chainTime READ chainTime NOTIFY blockReceived)
|
||||||
|
|
||||||
void processUpdatedObject(const fc::variant& update);
|
void processUpdatedObject(const fc::variant& update);
|
||||||
|
|
||||||
|
|
@ -49,6 +51,8 @@ public:
|
||||||
Q_INVOKABLE Asset* getAsset(ObjectId id);
|
Q_INVOKABLE Asset* getAsset(ObjectId id);
|
||||||
Q_INVOKABLE Asset* getAsset(QString symbol);
|
Q_INVOKABLE Asset* getAsset(QString symbol);
|
||||||
|
|
||||||
|
QDateTime chainTime() const;
|
||||||
|
|
||||||
ChainDataModel(){}
|
ChainDataModel(){}
|
||||||
ChainDataModel(fc::thread& t, QObject* parent = nullptr);
|
ChainDataModel(fc::thread& t, QObject* parent = nullptr);
|
||||||
|
|
||||||
|
|
@ -64,6 +68,7 @@ public Q_SLOTS:
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void queueExecute(const std::function<void()>&);
|
void queueExecute(const std::function<void()>&);
|
||||||
void exceptionThrown(QString message);
|
void exceptionThrown(QString message);
|
||||||
|
void blockReceived();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
fc::thread* m_rpc_thread = nullptr;
|
fc::thread* m_rpc_thread = nullptr;
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,10 @@
|
||||||
|
|
||||||
#include <graphene/chain/protocol/transaction.hpp>
|
#include <graphene/chain/protocol/transaction.hpp>
|
||||||
|
|
||||||
|
#include <QDateTime>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QQmlListProperty>
|
#include <QQmlListProperty>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
class OperationBase;
|
class OperationBase;
|
||||||
class Transaction : public QObject {
|
class Transaction : public QObject {
|
||||||
|
|
@ -26,13 +28,19 @@ public:
|
||||||
return m_transaction;
|
return m_transaction;
|
||||||
}
|
}
|
||||||
|
|
||||||
public slots:
|
QDateTime expiration() const
|
||||||
|
{
|
||||||
|
return QDateTime::fromTime_t(m_transaction.expiration.sec_since_epoch());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Q_SLOTS:
|
||||||
void setStatus(Status status)
|
void setStatus(Status status)
|
||||||
{
|
{
|
||||||
if (status == m_status)
|
if (status == m_status)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_status = status;
|
m_status = status;
|
||||||
|
qDebug() << status;
|
||||||
emit statusChanged(status);
|
emit statusChanged(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -46,13 +54,26 @@ public slots:
|
||||||
Q_EMIT operationsChanged();
|
Q_EMIT operationsChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setExpiration(QDateTime expiration)
|
||||||
|
{
|
||||||
|
fc::time_point_sec exp(expiration.toTime_t());
|
||||||
|
if (exp == m_transaction.expiration)
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_transaction.expiration = exp;
|
||||||
|
emit expirationChanged(expiration);
|
||||||
|
}
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void statusChanged(Status status);
|
void statusChanged(Status status);
|
||||||
void operationsChanged();
|
void operationsChanged();
|
||||||
|
|
||||||
|
void expirationChanged(QDateTime expiration);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Q_PROPERTY(Status status READ status WRITE setStatus NOTIFY statusChanged)
|
Q_PROPERTY(Status status READ status WRITE setStatus NOTIFY statusChanged)
|
||||||
Q_PROPERTY(QQmlListProperty<OperationBase> operations READ operations NOTIFY operationsChanged)
|
Q_PROPERTY(QQmlListProperty<OperationBase> operations READ operations NOTIFY operationsChanged)
|
||||||
|
Q_PROPERTY(QDateTime expiration READ expiration WRITE setExpiration NOTIFY expirationChanged)
|
||||||
|
|
||||||
Status m_status = Unbroadcasted;
|
Status m_status = Unbroadcasted;
|
||||||
graphene::chain::signed_transaction m_transaction;
|
graphene::chain::signed_transaction m_transaction;
|
||||||
|
|
|
||||||
|
|
@ -56,6 +56,12 @@ int main(int argc, char *argv[])
|
||||||
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
|
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
|
||||||
#else
|
#else
|
||||||
engine.load(QUrl(QStringLiteral("qml/main.qml")));
|
engine.load(QUrl(QStringLiteral("qml/main.qml")));
|
||||||
|
QFileSystemWatcher watcher;
|
||||||
|
qDebug() << watcher.addPath("qml/");
|
||||||
|
QObject::connect(&watcher, &QFileSystemWatcher::directoryChanged, &engine, [&](QString path) {
|
||||||
|
qDebug() << "Changed file" << path;
|
||||||
|
engine.clearComponentCache();
|
||||||
|
});
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return app.exec();
|
return app.exec();
|
||||||
|
|
|
||||||
|
|
@ -28,27 +28,25 @@ FormBase {
|
||||||
trx.appendOperation(arg[op])
|
trx.appendOperation(arg[op])
|
||||||
}
|
}
|
||||||
|
|
||||||
Component {
|
Rectangle {
|
||||||
id: transactionDelegate
|
width: Scaling.cm(10)
|
||||||
|
height: childrenRect.height + Scaling.cm(1)
|
||||||
|
radius: Scaling.mm(3)
|
||||||
|
color: "#EEEEEE"
|
||||||
|
border.width: Scaling.mm(.25)
|
||||||
|
border.color: "black"
|
||||||
|
|
||||||
Rectangle {
|
Column {
|
||||||
width: Scaling.cm(10)
|
y: Scaling.cm(.5)
|
||||||
height: childrenRect.height + Scaling.cm(1)
|
x: y
|
||||||
radius: Scaling.mm(3)
|
width: parent.width - Scaling.cm(1)
|
||||||
color: "#EEEEEE"
|
Repeater {
|
||||||
border.width: Scaling.mm(.25)
|
model: trx? trx.operations : []
|
||||||
border.color: "black"
|
Label {
|
||||||
|
property Asset transferAsset: app.model.getAsset(modelData.amountType)
|
||||||
Column {
|
property Asset feeAsset: app.model.getAsset(modelData.feeType)
|
||||||
y: Scaling.cm(.5)
|
text: {
|
||||||
x: y
|
return qsTr("Transfer %1 %2 from %3 to %4\nFee: %5 %6").arg(transferAsset.formatAmount(modelData.amount))
|
||||||
width: parent.width - Scaling.cm(1)
|
|
||||||
Repeater {
|
|
||||||
model: trx.operations
|
|
||||||
Label {
|
|
||||||
property Asset transferAsset: app.model.getAsset(modelData.amountType)
|
|
||||||
property Asset feeAsset: app.model.getAsset(modelData.feeType)
|
|
||||||
text: qsTr("Transfer %1 %2 from %3 to %4\nFee: %5 %6").arg(transferAsset.formatAmount(modelData.amount))
|
|
||||||
.arg(transferAsset.symbol)
|
.arg(transferAsset.symbol)
|
||||||
.arg(app.model.getAccount(modelData.sender).name)
|
.arg(app.model.getAccount(modelData.sender).name)
|
||||||
.arg(app.model.getAccount(modelData.receiver).name)
|
.arg(app.model.getAccount(modelData.receiver).name)
|
||||||
|
|
@ -59,8 +57,26 @@ FormBase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loader {
|
Item { width: 1; height: 1 }
|
||||||
sourceComponent: trx && Array.prototype.slice.call(trx.operations).length > 0? transactionDelegate : undefined
|
RowLayout {
|
||||||
|
Label {
|
||||||
|
text: qsTr("Transaction expires in")
|
||||||
|
}
|
||||||
|
ComboBox {
|
||||||
|
id: expirationSelector
|
||||||
|
model: [qsTr("five seconds"), qsTr("thirty seconds"), qsTr("a minute"), qsTr("an hour"), qsTr("a month"), qsTr("a year")]
|
||||||
|
|
||||||
|
function getExpiration() {
|
||||||
|
switch(expirationSelector.currentIndex) {
|
||||||
|
case 0: return new Date(app.model.chainTime.getTime() + 1000*5)
|
||||||
|
case 1: return new Date(app.model.chainTime.getTime() + 1000*30)
|
||||||
|
case 2: return new Date(app.model.chainTime.getTime() + 1000*60)
|
||||||
|
case 3: return new Date(app.model.chainTime.getTime() + 1000*60*60)
|
||||||
|
case 4: return new Date(app.model.chainTime.getTime() + 1000*60*60*24*30)
|
||||||
|
case 5: return new Date(app.model.chainTime.getTime() + 1000*60*60*24*365)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
UnlockingFinishButtons {
|
UnlockingFinishButtons {
|
||||||
app: base.app
|
app: base.app
|
||||||
|
|
@ -74,6 +90,7 @@ FormBase {
|
||||||
if (app.wallet.isLocked)
|
if (app.wallet.isLocked)
|
||||||
app.wallet.unlock(passwordField.text)
|
app.wallet.unlock(passwordField.text)
|
||||||
else {
|
else {
|
||||||
|
trx.setExpiration(expirationSelector.getExpiration())
|
||||||
app.signTransaction(trx)
|
app.signTransaction(trx)
|
||||||
app.model.broadcast(trx)
|
app.model.broadcast(trx)
|
||||||
completed(trx)
|
completed(trx)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue