Continued progress

This commit is contained in:
Zach Fox 2018-03-05 10:01:40 -08:00
parent f53aba2a32
commit f10f9aa939
7 changed files with 50 additions and 16 deletions

View file

@ -30,6 +30,7 @@ Rectangle {
property string activeView: "initialize"; property string activeView: "initialize";
property bool ownershipStatusReceived: false; property bool ownershipStatusReceived: false;
property bool balanceReceived: false; property bool balanceReceived: false;
property bool availableUpdatesReceived: false;
property string itemName; property string itemName;
property string itemId; property string itemId;
property string itemHref; property string itemHref;
@ -130,11 +131,24 @@ Rectangle {
root.isInstalled = true; root.isInstalled = true;
} }
} }
onAvailableUpdatesResult: {
if (result.status !== 'success') {
console.log("Failed to get Available Updates", result.data.message);
} else {
root.availableUpdatesReceived = true;
if (result.data.updates.indexOf(root.itemId) > -1) {
root.isUpdating = true;
}
}
}
} }
onItemIdChanged: { onItemIdChanged: {
root.ownershipStatusReceived = false; root.ownershipStatusReceived = false;
Commerce.alreadyOwned(root.itemId); Commerce.alreadyOwned(root.itemId);
root.availableUpdatesReceived = false;
Commerce.getAvailableUpdates();
itemPreviewImage.source = "https://hifi-metaverse.s3-us-west-1.amazonaws.com/marketplace/previews/" + itemId + "/thumbnail/hifi-mp-" + itemId + ".jpg"; itemPreviewImage.source = "https://hifi-metaverse.s3-us-west-1.amazonaws.com/marketplace/previews/" + itemId + "/thumbnail/hifi-mp-" + itemId + ".jpg";
} }
@ -242,6 +256,7 @@ Rectangle {
Component.onCompleted: { Component.onCompleted: {
ownershipStatusReceived = false; ownershipStatusReceived = false;
balanceReceived = false; balanceReceived = false;
availableUpdatesReceived = false;
Commerce.getWalletStatus(); Commerce.getWalletStatus();
} }
} }
@ -318,7 +333,7 @@ Rectangle {
Rectangle { Rectangle {
id: loading; id: loading;
z: 997; z: 997;
visible: !root.ownershipStatusReceived || !root.balanceReceived; visible: !root.ownershipStatusReceived || !root.balanceReceived || !root.availableUpdatesReceived;
anchors.fill: parent; anchors.fill: parent;
color: hifi.colors.white; color: hifi.colors.white;
@ -542,7 +557,7 @@ Rectangle {
HifiControlsUit.Button { HifiControlsUit.Button {
id: buyButton; id: buyButton;
visible: !((root.itemType === "avatar" || root.itemType === "app") && viewInMyPurchasesButton.visible) visible: !((root.itemType === "avatar" || root.itemType === "app") && viewInMyPurchasesButton.visible)
enabled: (root.balanceAfterPurchase >= 0 && ownershipStatusReceived && balanceReceived) || (!root.isCertified); enabled: (root.balanceAfterPurchase >= 0 && ownershipStatusReceived && balanceReceived && availableUpdatesReceived) || (!root.isCertified);
color: viewInMyPurchasesButton.visible ? hifi.buttons.white : hifi.buttons.blue; color: viewInMyPurchasesButton.visible ? hifi.buttons.white : hifi.buttons.blue;
colorScheme: hifi.colorSchemes.light; colorScheme: hifi.colorSchemes.light;
anchors.top: viewInMyPurchasesButton.visible ? viewInMyPurchasesButton.bottom : anchors.top: viewInMyPurchasesButton.visible ? viewInMyPurchasesButton.bottom :
@ -551,7 +566,7 @@ Rectangle {
height: 50; height: 50;
anchors.left: parent.left; anchors.left: parent.left;
anchors.right: parent.right; anchors.right: parent.right;
text: root.isUpdating ? "CONFIRM UPDATE" : (((root.isCertified) ? ((ownershipStatusReceived && balanceReceived) ? text: root.isUpdating ? "CONFIRM UPDATE" : (((root.isCertified) ? ((ownershipStatusReceived && balanceReceived && availableUpdatesReceived) ?
(viewInMyPurchasesButton.visible ? "Buy It Again" : "Confirm Purchase") : "--") : "Get Item")); (viewInMyPurchasesButton.visible ? "Buy It Again" : "Confirm Purchase") : "--") : "Get Item"));
onClicked: { onClicked: {
if (root.isCertified) { if (root.isCertified) {
@ -978,7 +993,7 @@ Rectangle {
buyButton.color = hifi.buttons.red; buyButton.color = hifi.buttons.red;
root.shouldBuyWithControlledFailure = true; root.shouldBuyWithControlledFailure = true;
} else { } else {
buyButton.text = (root.isCertified ? ((ownershipStatusReceived && balanceReceived) ? (root.alreadyOwned ? "Buy Another" : "Buy"): "--") : "Get Item"); buyButton.text = (root.isCertified ? ((ownershipStatusReceived && balanceReceived && availableUpdatesReceived) ? (root.alreadyOwned ? "Buy Another" : "Buy"): "--") : "Get Item");
buyButton.color = hifi.buttons.blue; buyButton.color = hifi.buttons.blue;
root.shouldBuyWithControlledFailure = false; root.shouldBuyWithControlledFailure = false;
} }
@ -1021,7 +1036,7 @@ Rectangle {
function refreshBuyUI() { function refreshBuyUI() {
if (root.isCertified) { if (root.isCertified) {
if (root.ownershipStatusReceived && root.balanceReceived) { if (root.ownershipStatusReceived && root.balanceReceived && root.availableUpdatesReceived) {
if (root.balanceAfterPurchase < 0 && !root.isUpdating) { if (root.balanceAfterPurchase < 0 && !root.isUpdating) {
if (root.alreadyOwned) { if (root.alreadyOwned) {
buyText.text = "<b>Your Wallet does not have sufficient funds to purchase this item again.</b>"; buyText.text = "<b>Your Wallet does not have sufficient funds to purchase this item again.</b>";
@ -1075,8 +1090,10 @@ Rectangle {
} }
root.balanceReceived = false; root.balanceReceived = false;
root.ownershipStatusReceived = false; root.ownershipStatusReceived = false;
root.availableUpdatesReceived = false;
Commerce.alreadyOwned(root.itemId); Commerce.alreadyOwned(root.itemId);
Commerce.balance(); Commerce.balance();
Commerce.getAvailableUpdates();
} }
// //

View file

@ -52,6 +52,7 @@ Handler(inventory)
Handler(transferHfcToNode) Handler(transferHfcToNode)
Handler(transferHfcToUsername) Handler(transferHfcToUsername)
Handler(alreadyOwned) Handler(alreadyOwned)
Handler(availableUpdates)
void Ledger::send(const QString& endpoint, const QString& success, const QString& fail, QNetworkAccessManager::Operation method, AccountManagerAuth::Type authType, QJsonObject request) { void Ledger::send(const QString& endpoint, const QString& success, const QString& fail, QNetworkAccessManager::Operation method, AccountManagerAuth::Type authType, QJsonObject request) {
auto accountManager = DependencyManager::get<AccountManager>(); auto accountManager = DependencyManager::get<AccountManager>();
@ -363,3 +364,11 @@ void Ledger::alreadyOwned(const QString& marketplaceId) {
request["marketplace_item_id"] = marketplaceId; request["marketplace_item_id"] = marketplaceId;
send(endpoint, "alreadyOwnedSuccess", "alreadyOwnedFailure", QNetworkAccessManager::PutOperation, AccountManagerAuth::Required, request); send(endpoint, "alreadyOwnedSuccess", "alreadyOwnedFailure", QNetworkAccessManager::PutOperation, AccountManagerAuth::Required, request);
} }
void Ledger::getAvailableUpdates() {
auto wallet = DependencyManager::get<Wallet>();
QString endpoint = "available_updates";
QJsonObject request;
request["public_keys"] = QJsonArray::fromStringList(wallet->listPublicKeys());
send(endpoint, "availableUpdatesSuccess", "availableUpdatesFailure", QNetworkAccessManager::PutOperation, AccountManagerAuth::Required, request);
}

View file

@ -36,6 +36,7 @@ public:
void transferHfcToNode(const QString& hfc_key, const QString& nodeID, const int& amount, const QString& optionalMessage); void transferHfcToNode(const QString& hfc_key, const QString& nodeID, const int& amount, const QString& optionalMessage);
void transferHfcToUsername(const QString& hfc_key, const QString& username, const int& amount, const QString& optionalMessage); void transferHfcToUsername(const QString& hfc_key, const QString& username, const int& amount, const QString& optionalMessage);
void alreadyOwned(const QString& marketplaceId); void alreadyOwned(const QString& marketplaceId);
void getAvailableUpdates();
enum CertificateStatus { enum CertificateStatus {
CERTIFICATE_STATUS_UNKNOWN = 0, CERTIFICATE_STATUS_UNKNOWN = 0,
@ -57,6 +58,7 @@ signals:
void transferHfcToNodeResult(QJsonObject result); void transferHfcToNodeResult(QJsonObject result);
void transferHfcToUsernameResult(QJsonObject result); void transferHfcToUsernameResult(QJsonObject result);
void alreadyOwnedResult(QJsonObject result); void alreadyOwnedResult(QJsonObject result);
void availableUpdatesResult(QJsonObject result);
void updateCertificateStatus(const QString& certID, uint certStatus); void updateCertificateStatus(const QString& certID, uint certStatus);
@ -83,6 +85,8 @@ public slots:
void transferHfcToUsernameFailure(QNetworkReply& reply); void transferHfcToUsernameFailure(QNetworkReply& reply);
void alreadyOwnedSuccess(QNetworkReply& reply); void alreadyOwnedSuccess(QNetworkReply& reply);
void alreadyOwnedFailure(QNetworkReply& reply); void alreadyOwnedFailure(QNetworkReply& reply);
void availableUpdatesSuccess(QNetworkReply& reply);
void availableUpdatesFailure(QNetworkReply& reply);
private: private:
QJsonObject apiResponse(const QString& label, QNetworkReply& reply); QJsonObject apiResponse(const QString& label, QNetworkReply& reply);

View file

@ -38,7 +38,7 @@ QmlCommerce::QmlCommerce() {
connect(ledger.data(), &Ledger::updateCertificateStatus, this, &QmlCommerce::updateCertificateStatus); connect(ledger.data(), &Ledger::updateCertificateStatus, this, &QmlCommerce::updateCertificateStatus);
connect(ledger.data(), &Ledger::transferHfcToNodeResult, this, &QmlCommerce::transferHfcToNodeResult); connect(ledger.data(), &Ledger::transferHfcToNodeResult, this, &QmlCommerce::transferHfcToNodeResult);
connect(ledger.data(), &Ledger::transferHfcToUsernameResult, this, &QmlCommerce::transferHfcToUsernameResult); connect(ledger.data(), &Ledger::transferHfcToUsernameResult, this, &QmlCommerce::transferHfcToUsernameResult);
connect(ledger.data(), &Ledger::transferHfcToUsernameResult, this, &QmlCommerce::transferHfcToUsernameResult); connect(ledger.data(), &Ledger::availableUpdatesResult, this, &QmlCommerce::availableUpdatesResult);
auto accountManager = DependencyManager::get<AccountManager>(); auto accountManager = DependencyManager::get<AccountManager>();
connect(accountManager.data(), &AccountManager::usernameChanged, this, [&]() { connect(accountManager.data(), &AccountManager::usernameChanged, this, [&]() {
@ -344,3 +344,8 @@ bool QmlCommerce::openApp(const QString& itemHref) {
return true; return true;
} }
void QmlCommerce::getAvailableUpdates() {
auto ledger = DependencyManager::get<Ledger>();
ledger->getAvailableUpdates();
}

View file

@ -43,6 +43,7 @@ signals:
void accountResult(QJsonObject result); void accountResult(QJsonObject result);
void certificateInfoResult(QJsonObject result); void certificateInfoResult(QJsonObject result);
void alreadyOwnedResult(QJsonObject result); void alreadyOwnedResult(QJsonObject result);
void availableUpdatesResult(QJsonObject result);
void updateCertificateStatus(const QString& certID, uint certStatus); void updateCertificateStatus(const QString& certID, uint certStatus);
@ -88,6 +89,8 @@ protected:
Q_INVOKABLE bool uninstallApp(const QString& appHref); Q_INVOKABLE bool uninstallApp(const QString& appHref);
Q_INVOKABLE bool openApp(const QString& appHref); Q_INVOKABLE bool openApp(const QString& appHref);
Q_INVOKABLE void getAvailableUpdates();
private: private:
QString _appsPath; QString _appsPath;
}; };

View file

@ -445,15 +445,11 @@
purchaseButton.on('click', function () { purchaseButton.on('click', function () {
if (url.indexOf('edition=' != -1)) { if (url.indexOf('edition=' != -1)) {
if (url.indexOf('upgradeUrl=' === -1)) { updateButtonClicked(window.location.pathname.split("/")[3],
console.log("ERROR! Item is an upgrade, but no upgradeUrl was specified."); $('#top-center').find('h1').text(),
} else { $('#creator').find('.value').text(),
updateButtonClicked(window.location.pathname.split("/")[3], href,
$('#top-center').find('h1').text(), "itemPage");
$('#creator').find('.value').text(),
getParameterByName('upgradeUrl'),
"itemPage");
}
} else if ('available' === availability) { } else if ('available' === availability) {
buyButtonClicked(window.location.pathname.split("/")[3], buyButtonClicked(window.location.pathname.split("/")[3],
$('#top-center').find('h1').text(), $('#top-center').find('h1').text(),

View file

@ -561,7 +561,7 @@ var selectionDisplay = null; // for gridTool.js to ignore
tablet.gotoWebScreen(MARKETPLACE_URL_INITIAL, MARKETPLACES_INJECT_SCRIPT_URL); tablet.gotoWebScreen(MARKETPLACE_URL_INITIAL, MARKETPLACES_INJECT_SCRIPT_URL);
break; break;
case 'updateItemClicked': case 'updateItemClicked':
tablet.gotoWebScreen(MARKETPLACE_URL + '/items/' + message.itemId + "?edition=" + message.itemEdition + "&upgradeUrl=" + message.upgradeUrl, tablet.gotoWebScreen(message.upgradeUrl + "?edition=" + message.itemEdition + "&upgradeUrl=" + message.upgradeUrl,
MARKETPLACES_INJECT_SCRIPT_URL); MARKETPLACES_INJECT_SCRIPT_URL);
break; break;
case 'passphrasePopup_cancelClicked': case 'passphrasePopup_cancelClicked':