mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-30 14:22:56 +02:00
Merge pull request #11854 from howard-stearns/consolidated-blockchain-history-log
consolidated blockchain history log
This commit is contained in:
commit
89425ca210
1 changed files with 20 additions and 27 deletions
|
@ -111,14 +111,23 @@ void Ledger::inventory(const QStringList& keys) {
|
||||||
keysQuery("inventory", "inventorySuccess", "inventoryFailure");
|
keysQuery("inventory", "inventorySuccess", "inventoryFailure");
|
||||||
}
|
}
|
||||||
|
|
||||||
QString nameFromKey(const QString& key, const QStringList& publicKeys) {
|
QString amountString(const QString& label, const QString&color, const QJsonValue& moneyValue, const QJsonValue& certsValue) {
|
||||||
if (key.isNull() || key.isEmpty()) {
|
int money = moneyValue.toInt();
|
||||||
return "Marketplace";
|
int certs = certsValue.toInt();
|
||||||
|
if (money <= 0 && certs <= 0) {
|
||||||
|
return QString();
|
||||||
}
|
}
|
||||||
if (publicKeys.contains(key)) {
|
QString result(QString("<font color='#%1'> %2").arg(color, label));
|
||||||
return "You";
|
if (money > 0) {
|
||||||
|
result += QString(" %1 HFC").arg(money);
|
||||||
}
|
}
|
||||||
return "Someone";
|
if (certs > 0) {
|
||||||
|
if (money > 0) {
|
||||||
|
result += QString(",");
|
||||||
|
}
|
||||||
|
result += QString((certs == 1) ? " %1 certificate" : " %1 certificates").arg(certs);
|
||||||
|
}
|
||||||
|
return result + QString("</font>");
|
||||||
}
|
}
|
||||||
|
|
||||||
static const QString MARKETPLACE_ITEMS_BASE_URL = NetworkingConstants::METAVERSE_SERVER_URL.toString() + "/marketplace/items/";
|
static const QString MARKETPLACE_ITEMS_BASE_URL = NetworkingConstants::METAVERSE_SERVER_URL.toString() + "/marketplace/items/";
|
||||||
|
@ -129,6 +138,7 @@ void Ledger::historySuccess(QNetworkReply& reply) {
|
||||||
// public key(s) are. Let's keep it that way
|
// public key(s) are. Let's keep it that way
|
||||||
QByteArray response = reply.readAll();
|
QByteArray response = reply.readAll();
|
||||||
QJsonObject data = QJsonDocument::fromJson(response).object();
|
QJsonObject data = QJsonDocument::fromJson(response).object();
|
||||||
|
qInfo(commerce) << "history" << "response" << QJsonDocument(data).toJson(QJsonDocument::Compact);
|
||||||
|
|
||||||
// we will need the array of public keys from the wallet
|
// we will need the array of public keys from the wallet
|
||||||
auto wallet = DependencyManager::get<Wallet>();
|
auto wallet = DependencyManager::get<Wallet>();
|
||||||
|
@ -141,32 +151,15 @@ void Ledger::historySuccess(QNetworkReply& reply) {
|
||||||
// TODO: do this with 0 copies if possible
|
// TODO: do this with 0 copies if possible
|
||||||
for (auto it = historyArray.begin(); it != historyArray.end(); it++) {
|
for (auto it = historyArray.begin(); it != historyArray.end(); it++) {
|
||||||
auto valueObject = (*it).toObject();
|
auto valueObject = (*it).toObject();
|
||||||
QString from = nameFromKey(valueObject["sender_key"].toString(), keys);
|
QString sent = amountString("sent", "EA4C5F", valueObject["sent_money"], valueObject["sent_certs"]);
|
||||||
QString to = nameFromKey(valueObject["recipient_key"].toString(), keys);
|
QString received = amountString("received", "1FC6A6", valueObject["received_money"], valueObject["received_certs"]);
|
||||||
bool isHfc = valueObject["asset_title"].toString() == "HFC";
|
|
||||||
bool iAmReceiving = to == "You";
|
|
||||||
QString coloredQuantityAndAssetTitle = QString::number(valueObject["quantity"].toInt()) + " " + valueObject["asset_title"].toString();
|
|
||||||
if (isHfc) {
|
|
||||||
if (iAmReceiving) {
|
|
||||||
coloredQuantityAndAssetTitle = QString("<font color='#1FC6A6'>") + coloredQuantityAndAssetTitle + QString("</font>");
|
|
||||||
} else {
|
|
||||||
coloredQuantityAndAssetTitle = QString("<font color='#EA4C5F'>") + coloredQuantityAndAssetTitle + QString("</font>");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
coloredQuantityAndAssetTitle = QString("\"<font color='#0093C5'><a href='") +
|
|
||||||
MARKETPLACE_ITEMS_BASE_URL +
|
|
||||||
valueObject["asset_id"].toString() +
|
|
||||||
QString("'>") +
|
|
||||||
coloredQuantityAndAssetTitle +
|
|
||||||
QString("</a></font>\"");
|
|
||||||
}
|
|
||||||
// turns out on my machine, toLocalTime convert to some weird timezone, yet the
|
// 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
|
// systemTimeZone is correct. To avoid a strange bug with other's systems too, lets
|
||||||
// be explicit
|
// be explicit
|
||||||
QDateTime createdAt = QDateTime::fromSecsSinceEpoch(valueObject["created_at"].toInt(), Qt::UTC);
|
QDateTime createdAt = QDateTime::fromSecsSinceEpoch(valueObject["created_at"].toInt(), Qt::UTC);
|
||||||
QDateTime localCreatedAt = createdAt.toTimeZone(QTimeZone::systemTimeZone());
|
QDateTime localCreatedAt = createdAt.toTimeZone(QTimeZone::systemTimeZone());
|
||||||
valueObject["text"] = QString("%1 sent %2 %3 with message \"%4\"").
|
valueObject["text"] = QString("%1%2%3").arg(valueObject["message"].toString(), sent, received);
|
||||||
arg(from, to, coloredQuantityAndAssetTitle, valueObject["message"].toString());
|
|
||||||
newHistoryArray.push_back(valueObject);
|
newHistoryArray.push_back(valueObject);
|
||||||
}
|
}
|
||||||
// now copy the rest of the json -- this is inefficient
|
// now copy the rest of the json -- this is inefficient
|
||||||
|
|
Loading…
Reference in a new issue