From 07ff9be91ee12ad62c0e0b15db03aef9c75af7a2 Mon Sep 17 00:00:00 2001 From: Dario Date: Mon, 29 Jun 2020 14:20:53 +0200 Subject: [PATCH] add balance also to new User, for replacing old user model in CheckTransactionPage --- src/cpp/JSONInterface/JsonTransaction.cpp | 4 ++++ src/cpp/controller/User.cpp | 2 +- src/cpp/controller/User.h | 7 +++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/cpp/JSONInterface/JsonTransaction.cpp b/src/cpp/JSONInterface/JsonTransaction.cpp index ede524b03..777fca295 100644 --- a/src/cpp/JSONInterface/JsonTransaction.cpp +++ b/src/cpp/JSONInterface/JsonTransaction.cpp @@ -37,6 +37,10 @@ Poco::JSON::Object* JsonTransaction::handle(Poco::Dynamic::Var params) if (u) { u->setBalance(balance); } + auto nu = session->getNewUser(); + if (!nu.isNull()) { + nu->setBalance(balance); + } } } diff --git a/src/cpp/controller/User.cpp b/src/cpp/controller/User.cpp index 045be46a0..500441b5d 100644 --- a/src/cpp/controller/User.cpp +++ b/src/cpp/controller/User.cpp @@ -16,7 +16,7 @@ namespace controller { User::User(model::table::User* dbModel) - : mPassword(nullptr), mGradidoKeyPair(nullptr), mCanDecryptPrivateKey(false) + : mPassword(nullptr), mGradidoKeyPair(nullptr), mCanDecryptPrivateKey(false), mGradidoCurrentBalance(0) { mDBModel = dbModel; } diff --git a/src/cpp/controller/User.h b/src/cpp/controller/User.h index 2dd247dab..30242025c 100644 --- a/src/cpp/controller/User.h +++ b/src/cpp/controller/User.h @@ -108,6 +108,9 @@ namespace controller { std::shared_lock _lock(mSharedMutex); return mGradidoKeyPair; } + + inline void setBalance(int gradidoBalance) { std::unique_lock _lock(mSharedMutex); mGradidoCurrentBalance = gradidoBalance; } + inline int getBalance() { std::shared_lock _lock(mSharedMutex); return mGradidoCurrentBalance; } protected: @@ -120,6 +123,10 @@ namespace controller { bool mCanDecryptPrivateKey; + //! get this from community-server, later maybe from gradido-node + //! use it for showing balance in menu in check transaction + int mGradidoCurrentBalance; + mutable std::shared_mutex mSharedMutex; }; }