From f015ac3c68d3115c96f30b0e257443f8d6de022e Mon Sep 17 00:00:00 2001 From: David Kelly Date: Fri, 25 Aug 2017 13:55:38 -0700 Subject: [PATCH 1/3] get transaction history into qml --- .../qml/hifi/commerce/wallet/WalletHome.qml | 8 ++++++++ interface/src/commerce/Ledger.cpp | 4 ++++ interface/src/commerce/Ledger.h | 4 ++++ interface/src/commerce/QmlCommerce.cpp | 13 +++++++++++++ interface/src/commerce/QmlCommerce.h | 2 ++ 5 files changed, 31 insertions(+) diff --git a/interface/resources/qml/hifi/commerce/wallet/WalletHome.qml b/interface/resources/qml/hifi/commerce/wallet/WalletHome.qml index 88f939d393..6424fe861a 100644 --- a/interface/resources/qml/hifi/commerce/wallet/WalletHome.qml +++ b/interface/resources/qml/hifi/commerce/wallet/WalletHome.qml @@ -39,6 +39,12 @@ Item { onBalanceResult : { balanceText.text = parseFloat(result.data.balance/100).toFixed(2); } + + onHistoryResult : { + if (result.status == 'success') { + transactionHistory.text = result.data.history; + } + } } SecurityImageModel { @@ -105,6 +111,7 @@ Item { onVisibleChanged: { if (visible) { commerce.balance(); + commerce.history(); } } } @@ -228,6 +235,7 @@ Item { // some placeholder stuff RalewayRegular { + id: transactionHistoryText; text: homeMessage.visible ? "you CANNOT scroll through this." : "you CAN scroll through this"; // Text size size: 16; diff --git a/interface/src/commerce/Ledger.cpp b/interface/src/commerce/Ledger.cpp index 55ee0e16e9..dddfae6455 100644 --- a/interface/src/commerce/Ledger.cpp +++ b/interface/src/commerce/Ledger.cpp @@ -45,6 +45,7 @@ Handler(buy) Handler(receiveAt) Handler(balance) Handler(inventory) +Handler(history) void Ledger::send(const QString& endpoint, const QString& success, const QString& fail, QNetworkAccessManager::Operation method, QJsonObject request) { auto accountManager = DependencyManager::get(); @@ -107,3 +108,6 @@ void Ledger::inventory(const QStringList& keys) { keysQuery("inventory", "inventorySuccess", "inventoryFailure"); } +void Ledger::history(const QStringList& keys) { + keysQuery("history", "historySuccess", "historyFailure"); +} diff --git a/interface/src/commerce/Ledger.h b/interface/src/commerce/Ledger.h index e43b8453b9..7d3fdef0c0 100644 --- a/interface/src/commerce/Ledger.h +++ b/interface/src/commerce/Ledger.h @@ -28,12 +28,14 @@ public: bool receiveAt(const QString& hfc_key, const QString& old_key); void balance(const QStringList& keys); void inventory(const QStringList& keys); + void history(const QStringList& keys); signals: void buyResult(QJsonObject result); void receiveAtResult(QJsonObject result); void balanceResult(QJsonObject result); void inventoryResult(QJsonObject result); + void historyResult(QJsonObject result); public slots: void buySuccess(QNetworkReply& reply); @@ -44,6 +46,8 @@ public slots: void balanceFailure(QNetworkReply& reply); void inventorySuccess(QNetworkReply& reply); void inventoryFailure(QNetworkReply& reply); + void historySuccess(QNetworkReply& reply); + void historyFailure(QNetworkReply& reply); private: QJsonObject apiResponse(const QString& label, QNetworkReply& reply); diff --git a/interface/src/commerce/QmlCommerce.cpp b/interface/src/commerce/QmlCommerce.cpp index f1e9fa139e..c2103c89ce 100644 --- a/interface/src/commerce/QmlCommerce.cpp +++ b/interface/src/commerce/QmlCommerce.cpp @@ -26,6 +26,7 @@ QmlCommerce::QmlCommerce(QQuickItem* parent) : OffscreenQmlDialog(parent) { connect(ledger.data(), &Ledger::inventoryResult, this, &QmlCommerce::inventoryResult); connect(wallet.data(), &Wallet::securityImageResult, this, &QmlCommerce::securityImageResult); connect(wallet.data(), &Wallet::keyFilePathResult, this, &QmlCommerce::keyFilePathResult); + connect(ledger.data(), &Ledger::historyResult, this, &QmlCommerce::historyResult); } void QmlCommerce::buy(const QString& assetId, int cost, const QString& buyerUsername) { @@ -46,29 +47,41 @@ void QmlCommerce::balance() { auto wallet = DependencyManager::get(); ledger->balance(wallet->listPublicKeys()); } + void QmlCommerce::inventory() { auto ledger = DependencyManager::get(); auto wallet = DependencyManager::get(); ledger->inventory(wallet->listPublicKeys()); } +void QmlCommerce::history() { + auto ledger = DependencyManager::get(); + auto wallet = DependencyManager::get(); + ledger->history(wallet->listPublicKeys()); +} + void QmlCommerce::chooseSecurityImage(const QString& imageFile) { auto wallet = DependencyManager::get(); wallet->chooseSecurityImage(imageFile); } + void QmlCommerce::getSecurityImage() { auto wallet = DependencyManager::get(); wallet->getSecurityImage(); } + void QmlCommerce::getLoginStatus() { emit loginStatusResult(DependencyManager::get()->isLoggedIn()); } + void QmlCommerce::setPassphrase(const QString& passphrase) { emit passphraseSetupStatusResult(true); } + void QmlCommerce::getPassphraseSetupStatus() { emit passphraseSetupStatusResult(false); } + void QmlCommerce::getKeyFilePath() { auto wallet = DependencyManager::get(); wallet->getKeyFilePath(); diff --git a/interface/src/commerce/QmlCommerce.h b/interface/src/commerce/QmlCommerce.h index d7a892cf1f..9438d4f696 100644 --- a/interface/src/commerce/QmlCommerce.h +++ b/interface/src/commerce/QmlCommerce.h @@ -37,11 +37,13 @@ signals: void loginStatusResult(bool isLoggedIn); void passphraseSetupStatusResult(bool passphraseIsSetup); void keyFilePathResult(const QString& path); + void historyResult(QJsonObject result); protected: Q_INVOKABLE void buy(const QString& assetId, int cost, const QString& buyerUsername = ""); Q_INVOKABLE void balance(); Q_INVOKABLE void inventory(); + Q_INVOKABLE void history(); Q_INVOKABLE void chooseSecurityImage(const QString& imageFile); Q_INVOKABLE void getSecurityImage(); Q_INVOKABLE void getLoginStatus(); From a7af1141442271fe830d1c1f690864e998015a4f Mon Sep 17 00:00:00 2001 From: David Kelly Date: Mon, 28 Aug 2017 17:02:53 -0700 Subject: [PATCH 2/3] fix wallet, use text from server in history (for now) --- .../qml/hifi/commerce/wallet/WalletHome.qml | 20 +++++++++---------- interface/src/commerce/Wallet.cpp | 2 +- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/interface/resources/qml/hifi/commerce/wallet/WalletHome.qml b/interface/resources/qml/hifi/commerce/wallet/WalletHome.qml index 6424fe861a..55f65d15d7 100644 --- a/interface/resources/qml/hifi/commerce/wallet/WalletHome.qml +++ b/interface/resources/qml/hifi/commerce/wallet/WalletHome.qml @@ -42,7 +42,8 @@ Item { onHistoryResult : { if (result.status == 'success') { - transactionHistory.text = result.data.history; + var txt = result.data.history.map(function(h) { return h.text; }).join("
"); + transactionHistoryText.text = txt; } } } @@ -234,18 +235,14 @@ Item { anchors.right: parent.right; // some placeholder stuff - RalewayRegular { + TextArea { id: transactionHistoryText; - text: homeMessage.visible ? "you CANNOT scroll through this." : "you CAN scroll through this"; - // Text size - size: 16; - // Anchors + text: "
history unavailable
"; + textFormat: TextEdit.AutoText; + font.pointSize: 10; anchors.fill: parent; - // Style - color: hifi.colors.darkGray; - // Alignment - horizontalAlignment: Text.AlignHCenter; - verticalAlignment: Text.AlignVCenter; + horizontalAlignment: Text.AlignLeft; + verticalAlignment: Text.AlignTop; } } @@ -359,6 +356,7 @@ Item { } } signal sendSignalToWallet(var msg); + // // FUNCTION DEFINITIONS END // diff --git a/interface/src/commerce/Wallet.cpp b/interface/src/commerce/Wallet.cpp index 1d64733f49..abb4b78710 100644 --- a/interface/src/commerce/Wallet.cpp +++ b/interface/src/commerce/Wallet.cpp @@ -347,7 +347,7 @@ bool Wallet::createIfNeeded() { qCDebug(commerce) << "read private key"; RSA_free(key); // K -- add the public key since we have a legit private key associated with it - _publicKeys.push_back(QUrl::toPercentEncoding(publicKey.toBase64())); + _publicKeys.push_back(publicKey.toBase64()); return false; } } From 84126d8f956b80a04a3d6b3a68ca6e684d33a441 Mon Sep 17 00:00:00 2001 From: David Kelly Date: Tue, 29 Aug 2017 08:46:13 -0700 Subject: [PATCH 3/3] cr feedback --- interface/resources/qml/hifi/commerce/wallet/WalletHome.qml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/interface/resources/qml/hifi/commerce/wallet/WalletHome.qml b/interface/resources/qml/hifi/commerce/wallet/WalletHome.qml index 55f65d15d7..33faacd0ab 100644 --- a/interface/resources/qml/hifi/commerce/wallet/WalletHome.qml +++ b/interface/resources/qml/hifi/commerce/wallet/WalletHome.qml @@ -41,8 +41,8 @@ Item { } onHistoryResult : { - if (result.status == 'success') { - var txt = result.data.history.map(function(h) { return h.text; }).join("
"); + if (result.status === 'success') { + var txt = result.data.history.map(function (h) { return h.text; }).join("
"); transactionHistoryText.text = txt; } }