Merge pull request #11289 from davidkelly/dk/penniesAndStuff

Display hfc in "pennies"
This commit is contained in:
David Kelly 2017-09-01 11:39:30 -07:00 committed by GitHub
commit d8bb3c7915
4 changed files with 87 additions and 28 deletions

View file

@ -89,8 +89,8 @@ Rectangle {
console.log("Failed to get balance", result.data.message); console.log("Failed to get balance", result.data.message);
} else { } else {
root.balanceReceived = true; root.balanceReceived = true;
hfcBalanceText.text = (parseFloat(result.data.balance/100).toFixed(2)) + " HFC"; hfcBalanceText.text = result.data.balance + " HFC";
balanceAfterPurchase = parseFloat(result.data.balance/100) - root.itemPriceFull/100; balanceAfterPurchase = result.data.balance - root.itemPriceFull;
root.setBuyText(); root.setBuyText();
} }
} }
@ -199,7 +199,7 @@ Rectangle {
commerce.getLoginStatus(); commerce.getLoginStatus();
} }
} }
HifiWallet.NeedsLogIn { HifiWallet.NeedsLogIn {
id: needsLogIn; id: needsLogIn;
visible: root.activeView === "needsLogIn"; visible: root.activeView === "needsLogIn";
@ -222,7 +222,7 @@ Rectangle {
} }
// //
// "WALLET NOT SET UP" START // "WALLET NOT SET UP" START
// //
@ -233,7 +233,7 @@ Rectangle {
anchors.bottom: parent.bottom; anchors.bottom: parent.bottom;
anchors.left: parent.left; anchors.left: parent.left;
anchors.right: parent.right; anchors.right: parent.right;
RalewayRegular { RalewayRegular {
id: notSetUpText; id: notSetUpText;
text: "<b>Your wallet isn't set up.</b><br><br>Set up your Wallet (no credit card necessary) to claim your <b>free HFC</b> " + text: "<b>Your wallet isn't set up.</b><br><br>Set up your Wallet (no credit card necessary) to claim your <b>free HFC</b> " +
@ -264,7 +264,7 @@ Rectangle {
anchors.left: parent.left; anchors.left: parent.left;
anchors.bottom: parent.bottom; anchors.bottom: parent.bottom;
anchors.bottomMargin: 24; anchors.bottomMargin: 24;
// "Cancel" button // "Cancel" button
HifiControlsUit.Button { HifiControlsUit.Button {
id: cancelButton; id: cancelButton;
@ -553,7 +553,7 @@ Rectangle {
} }
RalewayRegular { RalewayRegular {
id: balanceAfterPurchaseText; id: balanceAfterPurchaseText;
text: balanceAfterPurchase.toFixed(2) + " HFC"; text: balanceAfterPurchase + " HFC";
// Text size // Text size
size: balanceAfterPurchaseTextLabel.size; size: balanceAfterPurchaseTextLabel.size;
// Anchors // Anchors
@ -648,7 +648,7 @@ Rectangle {
sendToScript({method: 'checkout_goToPurchases'}); sendToScript({method: 'checkout_goToPurchases'});
} }
} }
RalewayRegular { RalewayRegular {
id: buyText; id: buyText;
// Text size // Text size
@ -687,7 +687,7 @@ Rectangle {
anchors.bottom: root.bottom; anchors.bottom: root.bottom;
anchors.left: parent.left; anchors.left: parent.left;
anchors.right: parent.right; anchors.right: parent.right;
RalewayRegular { RalewayRegular {
id: completeText; id: completeText;
text: "<b>Purchase Complete!</b><br><br>You bought <b>" + (itemNameText.text) + "</b> by <b>" + (itemAuthorText.text) + "</b>"; text: "<b>Purchase Complete!</b><br><br>You bought <b>" + (itemNameText.text) + "</b> by <b>" + (itemAuthorText.text) + "</b>";
@ -706,7 +706,7 @@ Rectangle {
horizontalAlignment: Text.AlignHCenter; horizontalAlignment: Text.AlignHCenter;
verticalAlignment: Text.AlignVCenter; verticalAlignment: Text.AlignVCenter;
} }
Item { Item {
id: checkoutSuccessActionButtonsContainer; id: checkoutSuccessActionButtonsContainer;
// Size // Size
@ -756,7 +756,7 @@ Rectangle {
} }
} }
} }
Item { Item {
id: continueShoppingButtonContainer; id: continueShoppingButtonContainer;
// Size // Size
@ -799,7 +799,7 @@ Rectangle {
anchors.bottom: root.bottom; anchors.bottom: root.bottom;
anchors.left: parent.left; anchors.left: parent.left;
anchors.right: parent.right; anchors.right: parent.right;
RalewayRegular { RalewayRegular {
id: failureHeaderText; id: failureHeaderText;
text: "<b>Purchase Failed.</b><br>Your Purchases and HFC balance haven't changed."; text: "<b>Purchase Failed.</b><br>Your Purchases and HFC balance haven't changed.";
@ -818,7 +818,7 @@ Rectangle {
horizontalAlignment: Text.AlignHCenter; horizontalAlignment: Text.AlignHCenter;
verticalAlignment: Text.AlignVCenter; verticalAlignment: Text.AlignVCenter;
} }
RalewayRegular { RalewayRegular {
id: failureErrorText; id: failureErrorText;
// Text size // Text size
@ -836,7 +836,7 @@ Rectangle {
horizontalAlignment: Text.AlignHCenter; horizontalAlignment: Text.AlignHCenter;
verticalAlignment: Text.AlignVCenter; verticalAlignment: Text.AlignVCenter;
} }
Item { Item {
id: backToMarketplaceButtonContainer; id: backToMarketplaceButtonContainer;
// Size // Size
@ -892,7 +892,7 @@ Rectangle {
itemNameText.text = message.params.itemName; itemNameText.text = message.params.itemName;
itemAuthorText.text = message.params.itemAuthor; itemAuthorText.text = message.params.itemAuthor;
root.itemPriceFull = message.params.itemPrice; root.itemPriceFull = message.params.itemPrice;
itemPriceText.text = root.itemPriceFull === 0 ? "Free" : "<b>" + (parseFloat(root.itemPriceFull/100).toFixed(2)) + " HFC</b>"; itemPriceText.text = root.itemPriceFull === 0 ? "Free" : "<b>" + root.itemPriceFull + " HFC</b>";
itemHref = message.params.itemHref; itemHref = message.params.itemHref;
if (itemHref.indexOf('.json') === -1) { if (itemHref.indexOf('.json') === -1) {
root.itemIsJson = false; root.itemIsJson = false;

View file

@ -38,7 +38,7 @@ Item {
} }
onBalanceResult : { onBalanceResult : {
balanceText.text = parseFloat(result.data.balance/100).toFixed(2); balanceText.text = result.data.balance;
} }
onHistoryResult : { onHistoryResult : {
@ -272,7 +272,7 @@ Item {
horizontalAlignment: Text.AlignLeft; horizontalAlignment: Text.AlignLeft;
verticalAlignment: Text.AlignVCenter; verticalAlignment: Text.AlignVCenter;
} }
HifiControlsUit.Separator { HifiControlsUit.Separator {
anchors.left: parent.left; anchors.left: parent.left;
anchors.right: parent.right; anchors.right: parent.right;

View file

@ -11,6 +11,7 @@
#include <QJsonObject> #include <QJsonObject>
#include <QJsonArray> #include <QJsonArray>
#include <QTimeZone>
#include <QJsonDocument> #include <QJsonDocument>
#include "AccountManager.h" #include "AccountManager.h"
#include "Wallet.h" #include "Wallet.h"
@ -45,7 +46,6 @@ Handler(buy)
Handler(receiveAt) Handler(receiveAt)
Handler(balance) Handler(balance)
Handler(inventory) Handler(inventory)
Handler(history)
void Ledger::send(const QString& endpoint, const QString& success, const QString& fail, QNetworkAccessManager::Operation method, QJsonObject request) { void Ledger::send(const QString& endpoint, const QString& success, const QString& fail, QNetworkAccessManager::Operation method, QJsonObject request) {
auto accountManager = DependencyManager::get<AccountManager>(); auto accountManager = DependencyManager::get<AccountManager>();
@ -108,6 +108,64 @@ void Ledger::inventory(const QStringList& keys) {
keysQuery("inventory", "inventorySuccess", "inventoryFailure"); keysQuery("inventory", "inventorySuccess", "inventoryFailure");
} }
QString nameFromKey(const QString& key, const QStringList& publicKeys) {
if (key.isNull() || key.isEmpty()) {
return "<b>Marketplace</b>";
}
if (publicKeys.contains(key)) {
return "You";
}
return "<b>Someone</b>";
}
void Ledger::historySuccess(QNetworkReply& reply) {
// here we send a historyResult with some extra stuff in it
// Namely, the styled text we'd like to show. The issue is the
// QML cannot do that easily since it doesn't know what the wallet
// public key(s) are. Let's keep it that way
QByteArray response = reply.readAll();
QJsonObject data = QJsonDocument::fromJson(response).object();
// we will need the array of public keys from the wallet
auto wallet = DependencyManager::get<Wallet>();
auto keys = wallet->listPublicKeys();
// now we need to loop through the transactions and add fancy text...
auto historyArray = data.find("data").value().toObject().find("history").value().toArray();
QJsonArray newHistoryArray;
// TODO: do this with 0 copies if possible
for(auto it = historyArray.begin(); it != historyArray.end(); it++) {
auto valueObject = (*it).toObject();
QString from = nameFromKey(valueObject["sender_key"].toString(), keys);
QString to = nameFromKey(valueObject["recipient_key"].toString(), keys);
// turns out on my machine, toLocalTime convert to some weird timezone, yet the
// systemTimeZone is correct. To avoid a strange bug with other's systems too, lets
// be explicit
#ifdef Q_OS_MAC
QDateTime createdAt = QDateTime::fromTime_t(valueObject["created_at"].toInt(), Qt::UTC);
#else
QDateTime createdAt = QDateTime::fromSecsSinceEpoch(valueObject["created_at"].toInt(), Qt::UTC);
#endif
QDateTime localCreatedAt = createdAt.toTimeZone(QTimeZone::systemTimeZone());
valueObject["text"] = QString("%1 sent %2 <b>%3 %4</b> on %5 with message \"%6\"").
arg(from, to, QString::number(valueObject["quantity"].toInt()), valueObject["asset_title"].toString(), localCreatedAt.toString(Qt::SystemLocaleShortDate), valueObject["message"].toString());
newHistoryArray.push_back(valueObject);
}
// now copy the rest of the json -- this is inefficient
// TODO: try to do this without making copies
QJsonObject newData;
newData["status"] = "success";
QJsonObject newDataData;
newDataData["history"] = newHistoryArray;
newData["data"] = newDataData;
emit historyResult(newData);
}
void Ledger::historyFailure(QNetworkReply& reply) {
failResponse("history", reply);
}
void Ledger::history(const QStringList& keys) { void Ledger::history(const QStringList& keys) {
keysQuery("history", "historySuccess", "historyFailure"); keysQuery("history", "historySuccess", "historyFailure");
} }
@ -117,4 +175,4 @@ void Ledger::resetSuccess(QNetworkReply& reply) { apiResponse("reset", reply); }
void Ledger::resetFailure(QNetworkReply& reply) { failResponse("reset", reply); } void Ledger::resetFailure(QNetworkReply& reply) { failResponse("reset", reply); }
void Ledger::reset() { void Ledger::reset() {
send("reset_user_hfc_account", "resetSuccess", "resetFailure", QNetworkAccessManager::PutOperation, QJsonObject()); send("reset_user_hfc_account", "resetSuccess", "resetFailure", QNetworkAccessManager::PutOperation, QJsonObject());
} }

View file

@ -27,7 +27,7 @@
var isPreparing = false; // Explicitly track download request status. var isPreparing = false; // Explicitly track download request status.
var confirmAllPurchases = false; // Set this to "true" to cause Checkout.qml to popup for all items, even if free var confirmAllPurchases = false; // Set this to "true" to cause Checkout.qml to popup for all items, even if free
function injectCommonCode(isDirectoryPage) { function injectCommonCode(isDirectoryPage) {
// Supporting styles from marketplaces.css. // Supporting styles from marketplaces.css.
@ -122,7 +122,7 @@
function injectBuyButtonOnMainPage() { function injectBuyButtonOnMainPage() {
var cost; var cost;
$('.grid-item').find('#price-or-edit').find('a').each(function() { $('.grid-item').find('#price-or-edit').find('a').each(function() {
$(this).attr('data-href', $(this).attr('href')); $(this).attr('data-href', $(this).attr('href'));
$(this).attr('href', '#'); $(this).attr('href', '#');
@ -130,7 +130,7 @@
$(this).closest('.col-xs-3').prev().attr("class", 'col-xs-6'); $(this).closest('.col-xs-3').prev().attr("class", 'col-xs-6');
$(this).closest('.col-xs-3').attr("class", 'col-xs-6'); $(this).closest('.col-xs-3').attr("class", 'col-xs-6');
if (parseInt(cost) > 0) { if (parseInt(cost) > 0) {
var priceElement = $(this).find('.price') var priceElement = $(this).find('.price')
priceElement.css({ "width": "auto", "padding": "3px 5px", "height": "26px" }); priceElement.css({ "width": "auto", "padding": "3px 5px", "height": "26px" });
@ -138,8 +138,8 @@
priceElement.css({ "min-width": priceElement.width() + 10 }); priceElement.css({ "min-width": priceElement.width() + 10 });
} }
}); });
$('.grid-item').find('#price-or-edit').find('a').on('click', function () { $('.grid-item').find('#price-or-edit').find('a').on('click', function () {
buyButtonClicked($(this).closest('.grid-item').attr('data-item-id'), buyButtonClicked($(this).closest('.grid-item').attr('data-item-id'),
$(this).closest('.grid-item').find('.item-title').text(), $(this).closest('.grid-item').find('.item-title').text(),
@ -175,11 +175,12 @@
if (confirmAllPurchases) { if (confirmAllPurchases) {
var href = $('#side-info').find('.btn').first().attr('href'); var href = $('#side-info').find('.btn').first().attr('href');
$('#side-info').find('.btn').first().attr('href', '#'); $('#side-info').find('.btn').first().attr('href', '#');
var cost = $('.item-cost').text(); var cost = $('.item-cost').text();
if (parseInt(cost) > 0 && $('#side-info').find('#buyItemButton').size() === 0) { if (parseInt(cost) > 0 && $('#side-info').find('#buyItemButton').size() === 0) {
$('#side-info').find('.btn').first().html('<span class="glyphicon glyphicon-download" id="buyItemButton"></span>Own Item: ' + (parseFloat(cost / 100).toFixed(2)) + ' HFC'); $('#side-info').find('.btn').first().html('<span class="glyphicon glyphicon-download" id="buyItemButton"></span>Own Item: ' + cost + ' HFC');
} }
$('#side-info').find('.btn').first().on('click', function () { $('#side-info').find('.btn').first().on('click', function () {
@ -264,7 +265,7 @@
// Reference: https://clara.io/learn/sdk/api/export // Reference: https://clara.io/learn/sdk/api/export
//var XMLHTTPREQUEST_URL = "https://clara.io/api/scenes/{uuid}/export/fbx?zip=true&centerScene=true&alignSceneGround=true&fbxUnit=Meter&fbxVersion=7&fbxEmbedTextures=true&imageFormat=WebGL"; //var XMLHTTPREQUEST_URL = "https://clara.io/api/scenes/{uuid}/export/fbx?zip=true&centerScene=true&alignSceneGround=true&fbxUnit=Meter&fbxVersion=7&fbxEmbedTextures=true&imageFormat=WebGL";
// 13 Jan 2017: Specify FBX version 5 and remove some options in order to make Clara.io site more likely to // 13 Jan 2017: Specify FBX version 5 and remove some options in order to make Clara.io site more likely to
// be successful in generating zip files. // be successful in generating zip files.
var XMLHTTPREQUEST_URL = "https://clara.io/api/scenes/{uuid}/export/fbx?fbxUnit=Meter&fbxVersion=5&fbxEmbedTextures=true&imageFormat=WebGL"; var XMLHTTPREQUEST_URL = "https://clara.io/api/scenes/{uuid}/export/fbx?fbxUnit=Meter&fbxVersion=5&fbxEmbedTextures=true&imageFormat=WebGL";
@ -447,7 +448,7 @@
cancelClaraDownload(); cancelClaraDownload();
} else { } else {
var parsedJsonMessage = JSON.parse(message); var parsedJsonMessage = JSON.parse(message);
if (parsedJsonMessage.type === "marketplaces") { if (parsedJsonMessage.type === "marketplaces") {
if (parsedJsonMessage.action === "inspectionModeSetting") { if (parsedJsonMessage.action === "inspectionModeSetting") {
confirmAllPurchases = !!parsedJsonMessage.data; confirmAllPurchases = !!parsedJsonMessage.data;