mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 04:44:11 +02:00
blance and inventory stubs
This commit is contained in:
parent
cb02ff4026
commit
ca13d58b0b
5 changed files with 48 additions and 3 deletions
|
@ -33,6 +33,11 @@ bool Ledger::buy(const QString& hfc_key, int cost, const QString& asset_id, cons
|
|||
request["signature"] = signature;
|
||||
|
||||
qCInfo(commerce) << "Transaction:" << QJsonDocument(request).toJson(QJsonDocument::Compact);
|
||||
// FIXME: talk to server instead
|
||||
QStringList keySet{ hfc_key };
|
||||
if (initializedBalance() < cost) return false;
|
||||
_balance -= cost;
|
||||
_inventory.push_back(asset_id);
|
||||
return true; // FIXME send to server.
|
||||
}
|
||||
|
||||
|
@ -45,4 +50,16 @@ bool Ledger::receiveAt(const QString& hfc_key) {
|
|||
auto username = accountManager->getAccountInfo().getUsername();
|
||||
qCInfo(commerce) << "Setting default receiving key for" << username;
|
||||
return true; // FIXME send to server.
|
||||
}
|
||||
|
||||
int Ledger::balance(const QStringList& keys) {
|
||||
// FIXME: talk to server instead
|
||||
qCInfo(commerce) << "Balance:" << initializedBalance();
|
||||
return _balance;
|
||||
}
|
||||
|
||||
QStringList Ledger::inventory(const QStringList& keys) {
|
||||
// FIXME: talk to server instead
|
||||
qCInfo(commerce) << "Inventory:" << _inventory;
|
||||
return _inventory;
|
||||
}
|
|
@ -23,6 +23,14 @@ class Ledger : public QObject, public Dependency {
|
|||
public:
|
||||
bool buy(const QString& hfc_key, int cost, const QString& asset_id, const QString& inventory_key, const QString& buyerUsername = "");
|
||||
bool receiveAt(const QString& hfc_key);
|
||||
int balance(const QStringList& keys);
|
||||
QStringList inventory(const QStringList& keys);
|
||||
|
||||
private:
|
||||
// These in-memory caches is temporary, until we start sending things to the server.
|
||||
int _balance{ -1 };
|
||||
QStringList _inventory{};
|
||||
int initializedBalance() { if (_balance < 0) _balance = 100; return _balance; }
|
||||
};
|
||||
|
||||
#endif // hifi_Ledger_h
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
HIFI_QML_DEF(QmlCommerce)
|
||||
|
||||
bool QmlCommerce::buy(const QString& assetId, int cost, const QString& buyerUsername) {
|
||||
void QmlCommerce::buy(const QString& assetId, int cost, const QString& buyerUsername) {
|
||||
auto ledger = DependencyManager::get<Ledger>();
|
||||
auto wallet = DependencyManager::get<Wallet>();
|
||||
QStringList keys = wallet->listPublicKeys();
|
||||
|
@ -26,5 +26,20 @@ bool QmlCommerce::buy(const QString& assetId, int cost, const QString& buyerUser
|
|||
}
|
||||
QString key = keys[0];
|
||||
// For now, we receive at the same key that pays for it.
|
||||
return ledger->buy(key, cost, assetId, key, buyerUsername);
|
||||
bool success = ledger->buy(key, cost, assetId, key, buyerUsername);
|
||||
// FIXME: until we start talking to server, report post-transaction balance and inventory so we can see log for testing.
|
||||
balance();
|
||||
inventory();
|
||||
return success;
|
||||
}
|
||||
|
||||
int QmlCommerce::balance() {
|
||||
auto ledger = DependencyManager::get<Ledger>();
|
||||
auto wallet = DependencyManager::get<Wallet>();
|
||||
return ledger->balance(wallet->listPublicKeys());
|
||||
}
|
||||
QStringList QmlCommerce::inventory() {
|
||||
auto ledger = DependencyManager::get<Ledger>();
|
||||
auto wallet = DependencyManager::get<Wallet>();
|
||||
return ledger->inventory(wallet->listPublicKeys());
|
||||
}
|
|
@ -21,8 +21,13 @@ class QmlCommerce : public OffscreenQmlDialog {
|
|||
Q_OBJECT
|
||||
HIFI_QML_DECL
|
||||
|
||||
signals:
|
||||
void buyResult(const QString& failureMessage);
|
||||
|
||||
protected:
|
||||
Q_INVOKABLE bool buy(const QString& assetId, int cost, const QString& buyerUsername = "");
|
||||
Q_INVOKABLE int balance();
|
||||
Q_INVOKABLE QStringList inventory();
|
||||
};
|
||||
|
||||
#endif // hifi_QmlCommerce_h
|
||||
|
|
|
@ -131,8 +131,8 @@
|
|||
} else {
|
||||
var parsedJsonMessage = JSON.parse(message);
|
||||
if (parsedJsonMessage.type === "CHECKOUT") {
|
||||
tablet.sendToQml({ method: 'updateCheckoutQML', params: parsedJsonMessage });
|
||||
tablet.pushOntoStack(MARKETPLACE_CHECKOUT_QML_PATH);
|
||||
tablet.sendToQml({ method: 'updateCheckoutQML', params: parsedJsonMessage });
|
||||
} else if (parsedJsonMessage.type === "REQUEST_SETTING") {
|
||||
tablet.emitScriptEvent(JSON.stringify({
|
||||
type: "marketplaces",
|
||||
|
|
Loading…
Reference in a new issue