My Item certificates

This commit is contained in:
Zach Fox 2017-10-10 14:56:17 -07:00
parent 702528a8cc
commit 5e383e2b1c
2 changed files with 63 additions and 19 deletions

View file

@ -32,6 +32,7 @@ Rectangle {
property string itemEdition: "--"; property string itemEdition: "--";
property string dateOfPurchase: "--"; property string dateOfPurchase: "--";
property bool isLightbox: false; property bool isLightbox: false;
property bool isMyCert: false;
// Style // Style
color: hifi.colors.faintGray; color: hifi.colors.faintGray;
Hifi.QmlCommerce { Hifi.QmlCommerce {
@ -42,7 +43,9 @@ Rectangle {
console.log("Failed to get certificate info", result.message); console.log("Failed to get certificate info", result.message);
} else { } else {
root.marketplaceUrl = result.data.marketplace_item_url; root.marketplaceUrl = result.data.marketplace_item_url;
root.itemOwner = "\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022"; root.isMyCert = result.isMyCert ? result.isMyCert : false;
root.itemOwner = root.isMyCert ? Account.username :
"\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022";
root.itemEdition = result.data.edition_number + "/" + (result.data.limited_run === -1 ? "\u221e" : result.data.limited_run); root.itemEdition = result.data.edition_number + "/" + (result.data.limited_run === -1 ? "\u221e" : result.data.limited_run);
root.dateOfPurchase = getFormattedDate(result.data.transfer_created_at * 1000); root.dateOfPurchase = getFormattedDate(result.data.transfer_created_at * 1000);
root.itemName = result.data.marketplace_item_name; root.itemName = result.data.marketplace_item_name;
@ -80,6 +83,7 @@ Rectangle {
root.itemEdition = "--"; root.itemEdition = "--";
root.dateOfPurchase = "--"; root.dateOfPurchase = "--";
root.marketplaceUrl = ""; root.marketplaceUrl = "";
root.isMyCert = false;
errorText.text = ""; errorText.text = "";
} }
} }
@ -162,7 +166,7 @@ Rectangle {
size: 28; size: 28;
// Anchors // Anchors
anchors.top: itemNameHeader.bottom; anchors.top: itemNameHeader.bottom;
anchors.topMargin: 4; anchors.topMargin: 8;
anchors.left: itemNameHeader.left; anchors.left: itemNameHeader.left;
anchors.right: itemNameHeader.right; anchors.right: itemNameHeader.right;
height: paintedHeight; height: paintedHeight;
@ -187,14 +191,20 @@ Rectangle {
size: 16; size: 16;
// Anchors // Anchors
anchors.top: itemName.bottom; anchors.top: itemName.bottom;
anchors.topMargin: 20; anchors.topMargin: 28;
anchors.left: parent.left; anchors.left: parent.left;
anchors.leftMargin: 45; anchors.leftMargin: 45;
anchors.right: parent.right; anchors.right: parent.right;
anchors.rightMargin: 16; anchors.rightMargin: 16;
height: paintedHeight; height: paintedHeight;
// Style // Style
color: hifi.colors.baseGray; color: hifi.colors.lightGray;
}
FontLoader { id: ralewayRegular; source: "../../../../fonts/Raleway-Regular.ttf"; }
TextMetrics {
id: textMetrics;
font.family: ralewayRegular.name
text: root.itemOwner;
} }
RalewayRegular { RalewayRegular {
id: ownedBy; id: ownedBy;
@ -203,14 +213,31 @@ Rectangle {
size: 22; size: 22;
// Anchors // Anchors
anchors.top: ownedByHeader.bottom; anchors.top: ownedByHeader.bottom;
anchors.topMargin: 4; anchors.topMargin: 8;
anchors.left: ownedByHeader.left; anchors.left: ownedByHeader.left;
anchors.right: ownedByHeader.right; height: textMetrics.height;
height: paintedHeight; width: root.isMyCert ? textMetrics.width + 25 : ownedByHeader.width;
// Style // Style
color: hifi.colors.darkGray; color: hifi.colors.darkGray;
elide: Text.ElideRight; elide: Text.ElideRight;
} }
AnonymousProRegular {
id: isMyCertText;
visible: root.isMyCert;
text: "(Private)";
size: 18;
// Anchors
anchors.top: ownedBy.top;
anchors.topMargin: 4;
anchors.bottom: ownedBy.bottom;
anchors.left: ownedBy.right;
anchors.leftMargin: 4;
anchors.right: ownedByHeader.right;
// Style
color: hifi.colors.lightGray;
elide: Text.ElideRight;
verticalAlignment: Text.AlignVCenter;
}
RalewayRegular { RalewayRegular {
id: editionHeader; id: editionHeader;
@ -219,23 +246,23 @@ Rectangle {
size: 16; size: 16;
// Anchors // Anchors
anchors.top: ownedBy.bottom; anchors.top: ownedBy.bottom;
anchors.topMargin: 20; anchors.topMargin: 28;
anchors.left: parent.left; anchors.left: parent.left;
anchors.leftMargin: 45; anchors.leftMargin: 45;
anchors.right: parent.right; anchors.right: parent.right;
anchors.rightMargin: 16; anchors.rightMargin: 16;
height: paintedHeight; height: paintedHeight;
// Style // Style
color: hifi.colors.baseGray; color: hifi.colors.lightGray;
} }
AnonymousProRegular { AnonymousProRegular {
id: edition; id: edition;
text: root.itemEdition; text: root.itemEdition;
// Text size // Text size
size: 22; size: 18;
// Anchors // Anchors
anchors.top: editionHeader.bottom; anchors.top: editionHeader.bottom;
anchors.topMargin: 4; anchors.topMargin: 8;
anchors.left: editionHeader.left; anchors.left: editionHeader.left;
anchors.right: editionHeader.right; anchors.right: editionHeader.right;
height: paintedHeight; height: paintedHeight;
@ -250,23 +277,23 @@ Rectangle {
size: 16; size: 16;
// Anchors // Anchors
anchors.top: edition.bottom; anchors.top: edition.bottom;
anchors.topMargin: 20; anchors.topMargin: 28;
anchors.left: parent.left; anchors.left: parent.left;
anchors.leftMargin: 45; anchors.leftMargin: 45;
anchors.right: parent.right; anchors.right: parent.right;
anchors.rightMargin: 16; anchors.rightMargin: 16;
height: paintedHeight; height: paintedHeight;
// Style // Style
color: hifi.colors.baseGray; color: hifi.colors.lightGray;
} }
AnonymousProRegular { AnonymousProRegular {
id: dateOfPurchase; id: dateOfPurchase;
text: root.dateOfPurchase; text: root.dateOfPurchase;
// Text size // Text size
size: 22; size: 18;
// Anchors // Anchors
anchors.top: dateOfPurchaseHeader.bottom; anchors.top: dateOfPurchaseHeader.bottom;
anchors.topMargin: 4; anchors.topMargin: 8;
anchors.left: dateOfPurchaseHeader.left; anchors.left: dateOfPurchaseHeader.left;
anchors.right: dateOfPurchaseHeader.right; anchors.right: dateOfPurchaseHeader.right;
height: paintedHeight; height: paintedHeight;
@ -280,7 +307,7 @@ Rectangle {
size: 20; size: 20;
// Anchors // Anchors
anchors.top: dateOfPurchase.bottom; anchors.top: dateOfPurchase.bottom;
anchors.topMargin: 40; anchors.topMargin: 36;
anchors.left: dateOfPurchase.left; anchors.left: dateOfPurchase.left;
anchors.right: dateOfPurchase.right; anchors.right: dateOfPurchase.right;
anchors.bottom: parent.bottom; anchors.bottom: parent.bottom;
@ -297,7 +324,7 @@ Rectangle {
Item { Item {
id: buttonsContainer; id: buttonsContainer;
anchors.bottom: parent.bottom; anchors.bottom: parent.bottom;
anchors.bottomMargin: 50; anchors.bottomMargin: 30;
anchors.left: parent.left; anchors.left: parent.left;
anchors.right: parent.right; anchors.right: parent.right;
height: 50; height: 50;
@ -386,7 +413,7 @@ Rectangle {
var min = a.getMinutes(); var min = a.getMinutes();
var sec = a.getSeconds(); var sec = a.getSeconds();
return year + '-' + month + '-' + day + ' ' + drawnHour + ':' + min + amOrPm; return year + '-' + month + '-' + day + '<br>' + drawnHour + ':' + min + amOrPm;
} }
// //
// FUNCTION DEFINITIONS END // FUNCTION DEFINITIONS END

View file

@ -46,7 +46,6 @@ Handler(buy)
Handler(receiveAt) Handler(receiveAt)
Handler(balance) Handler(balance)
Handler(inventory) Handler(inventory)
Handler(certificateInfo)
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>();
@ -235,6 +234,24 @@ void Ledger::updateLocation(const QString& asset_id, const QString location, con
signedSend("transaction", transactionString, key, "location", "updateLocationSuccess", "updateLocationFailure", controlledFailure); signedSend("transaction", transactionString, key, "location", "updateLocationSuccess", "updateLocationFailure", controlledFailure);
} }
void Ledger::certificateInfoSuccess(QNetworkReply& reply) {
auto wallet = DependencyManager::get<Wallet>();
auto accountManager = DependencyManager::get<AccountManager>();
QByteArray response = reply.readAll();
QJsonObject replyObject = QJsonDocument::fromJson(response).object();
QStringList keys = wallet->listPublicKeys();
if (keys.count() != 0) {
QJsonObject data = replyObject["data"].toObject();
if (data["transfer_recipient_key"].toString() == keys[0]) {
replyObject.insert("isMyCert", true);
}
}
qInfo(commerce) << "certificateInfo" << "response" << QJsonDocument(replyObject).toJson(QJsonDocument::Compact);
emit certificateInfoResult(replyObject);
}
void Ledger::certificateInfoFailure(QNetworkReply& reply) { failResponse("certificateInfo", reply); }
void Ledger::certificateInfo(const QString& certificateId) { void Ledger::certificateInfo(const QString& certificateId) {
QString endpoint = "proof_of_purchase_status/transfer/" + certificateId; QString endpoint = "proof_of_purchase_status/transfer/" + certificateId;
QJsonObject request; QJsonObject request;