From ed1ddc2a8bd34a73bb56ef0c91c1b97689d4e43b Mon Sep 17 00:00:00 2001
From: Stephen Birarda <commit@birarda.com>
Date: Fri, 6 May 2016 11:54:49 -0700
Subject: [PATCH] remove code to update/store wallet balance

---
 interface/src/Application.cpp                 |  9 --------
 .../scripting/AccountScriptingInterface.cpp   | 16 --------------
 .../src/scripting/AccountScriptingInterface.h |  6 ------
 libraries/networking/src/AccountManager.cpp   | 20 ------------------
 libraries/networking/src/AccountManager.h     |  3 ---
 .../networking/src/DataServerAccountInfo.cpp  | 21 -------------------
 .../networking/src/DataServerAccountInfo.h    | 12 +----------
 7 files changed, 1 insertion(+), 86 deletions(-)

diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp
index c2a4088dcc..e4f8271368 100644
--- a/interface/src/Application.cpp
+++ b/interface/src/Application.cpp
@@ -161,7 +161,6 @@ extern "C" {
 using namespace std;
 
 static QTimer locationUpdateTimer;
-static QTimer balanceUpdateTimer;
 static QTimer identityPacketTimer;
 static QTimer pingTimer;
 
@@ -688,13 +687,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) :
     // connect to appropriate slots on AccountManager
     AccountManager& accountManager = AccountManager::getInstance();
 
-    const qint64 BALANCE_UPDATE_INTERVAL_MSECS = 5 * MSECS_PER_SEC;
-
-    connect(&balanceUpdateTimer, &QTimer::timeout, &accountManager, &AccountManager::updateBalance);
-    balanceUpdateTimer.start(BALANCE_UPDATE_INTERVAL_MSECS);
-
-    connect(&accountManager, &AccountManager::balanceChanged, this, &Application::updateWindowTitle);
-
     auto dialogsManager = DependencyManager::get<DialogsManager>();
     connect(&accountManager, &AccountManager::authRequired, dialogsManager.data(), &DialogsManager::showLoginDialog);
     connect(&accountManager, &AccountManager::usernameChanged, this, &Application::updateWindowTitle);
@@ -1197,7 +1189,6 @@ void Application::cleanupBeforeQuit() {
     // first stop all timers directly or by invokeMethod
     // depending on what thread they run in
     locationUpdateTimer.stop();
-    balanceUpdateTimer.stop();
     identityPacketTimer.stop();
     pingTimer.stop();
     QMetaObject::invokeMethod(&_settingsTimer, "stop", Qt::BlockingQueuedConnection);
diff --git a/interface/src/scripting/AccountScriptingInterface.cpp b/interface/src/scripting/AccountScriptingInterface.cpp
index 126cd53003..1b6d52ac2a 100644
--- a/interface/src/scripting/AccountScriptingInterface.cpp
+++ b/interface/src/scripting/AccountScriptingInterface.cpp
@@ -13,32 +13,16 @@
 
 #include "AccountScriptingInterface.h"
 
-AccountScriptingInterface::AccountScriptingInterface() {
-    AccountManager& accountManager = AccountManager::getInstance();
-    connect(&accountManager, &AccountManager::balanceChanged, this,
-            &AccountScriptingInterface::updateBalance);
-}
-
 AccountScriptingInterface* AccountScriptingInterface::getInstance() {
     static AccountScriptingInterface sharedInstance;
     return &sharedInstance;
 }
 
-float AccountScriptingInterface::getBalance() {
-    AccountManager& accountManager = AccountManager::getInstance();
-    return accountManager.getAccountInfo().getBalanceInSatoshis();
-}
-
 bool AccountScriptingInterface::isLoggedIn() {
     AccountManager& accountManager = AccountManager::getInstance();
     return accountManager.isLoggedIn();
 }
 
-void AccountScriptingInterface::updateBalance() {
-    AccountManager& accountManager = AccountManager::getInstance();
-    emit balanceChanged(accountManager.getAccountInfo().getBalanceInSatoshis());
-}
-
 QString AccountScriptingInterface::getUsername() {
     AccountManager& accountManager = AccountManager::getInstance();
     if (accountManager.isLoggedIn()) {
diff --git a/interface/src/scripting/AccountScriptingInterface.h b/interface/src/scripting/AccountScriptingInterface.h
index 578a9d6728..888149b836 100644
--- a/interface/src/scripting/AccountScriptingInterface.h
+++ b/interface/src/scripting/AccountScriptingInterface.h
@@ -16,17 +16,11 @@
 
 class AccountScriptingInterface : public QObject {
     Q_OBJECT
-    AccountScriptingInterface();
 
-signals:
-    void balanceChanged(float newBalance);
-    
 public slots:
     static AccountScriptingInterface* getInstance();
-    float getBalance();
     QString getUsername();
     bool isLoggedIn();
-    void updateBalance();
 };
 
 #endif // hifi_AccountScriptingInterface_h
diff --git a/libraries/networking/src/AccountManager.cpp b/libraries/networking/src/AccountManager.cpp
index 407d7fc605..8c23844f4e 100644
--- a/libraries/networking/src/AccountManager.cpp
+++ b/libraries/networking/src/AccountManager.cpp
@@ -95,8 +95,6 @@ AccountManager::AccountManager() :
     qRegisterMetaType<QHttpMultiPart*>("QHttpMultiPart*");
 
     qRegisterMetaType<AccountManagerAuth::Type>();
-
-    connect(&_accountInfo, &DataServerAccountInfo::balanceChanged, this, &AccountManager::accountInfoBalanceChanged);
 }
 
 const QString DOUBLE_SLASH_SUBSTITUTE = "slashslash";
@@ -105,9 +103,6 @@ void AccountManager::logout() {
     // a logout means we want to delete the DataServerAccountInfo we currently have for this URL, in-memory and in file
     _accountInfo = DataServerAccountInfo();
 
-    emit balanceChanged(0);
-    connect(&_accountInfo, &DataServerAccountInfo::balanceChanged, this, &AccountManager::accountInfoBalanceChanged);
-
     // remove this account from the account settings file
     removeAccountFromFile();
 
@@ -116,21 +111,6 @@ void AccountManager::logout() {
     emit usernameChanged(QString());
 }
 
-void AccountManager::updateBalance() {
-    if (hasValidAccessToken()) {
-        // ask our auth endpoint for our balance
-        JSONCallbackParameters callbackParameters;
-        callbackParameters.jsonCallbackReceiver = &_accountInfo;
-        callbackParameters.jsonCallbackMethod = "setBalanceFromJSON";
-
-        sendRequest("/api/v1/wallets/mine", AccountManagerAuth::Required, QNetworkAccessManager::GetOperation, callbackParameters);
-    }
-}
-
-void AccountManager::accountInfoBalanceChanged(qint64 newBalance) {
-    emit balanceChanged(newBalance);
-}
-
 QString accountFileDir() {
     return QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
 }
diff --git a/libraries/networking/src/AccountManager.h b/libraries/networking/src/AccountManager.h
index c374a62515..108b49f678 100644
--- a/libraries/networking/src/AccountManager.h
+++ b/libraries/networking/src/AccountManager.h
@@ -87,8 +87,6 @@ public slots:
     void requestAccessTokenError(QNetworkReply::NetworkError error);
     void requestProfileError(QNetworkReply::NetworkError error);
     void logout();
-    void updateBalance();
-    void accountInfoBalanceChanged(qint64 newBalance);
     void generateNewUserKeypair() { generateNewKeypair(); }
     void generateNewDomainKeypair(const QUuid& domainID) { generateNewKeypair(false, domainID); }
 
@@ -100,7 +98,6 @@ signals:
     void loginComplete(const QUrl& authURL);
     void loginFailed();
     void logoutComplete();
-    void balanceChanged(qint64 newBalance);
     void newKeypair();
 
 private slots:
diff --git a/libraries/networking/src/DataServerAccountInfo.cpp b/libraries/networking/src/DataServerAccountInfo.cpp
index 9455fb1b88..211bfdccfa 100644
--- a/libraries/networking/src/DataServerAccountInfo.cpp
+++ b/libraries/networking/src/DataServerAccountInfo.cpp
@@ -31,8 +31,6 @@ DataServerAccountInfo::DataServerAccountInfo(const DataServerAccountInfo& otherI
     _xmppPassword = otherInfo._xmppPassword;
     _discourseApiKey = otherInfo._discourseApiKey;
     _walletID = otherInfo._walletID;
-    _balance = otherInfo._balance;
-    _hasBalance = otherInfo._hasBalance;
     _privateKey = otherInfo._privateKey;
     _domainID = otherInfo._domainID;
 }
@@ -51,8 +49,6 @@ void DataServerAccountInfo::swap(DataServerAccountInfo& otherInfo) {
     swap(_xmppPassword, otherInfo._xmppPassword);
     swap(_discourseApiKey, otherInfo._discourseApiKey);
     swap(_walletID, otherInfo._walletID);
-    swap(_balance, otherInfo._balance);
-    swap(_hasBalance, otherInfo._hasBalance);
     swap(_privateKey, otherInfo._privateKey);
     swap(_domainID, otherInfo._domainID);
 }
@@ -87,23 +83,6 @@ void DataServerAccountInfo::setWalletID(const QUuid& walletID) {
     }
 }
 
-void DataServerAccountInfo::setBalance(qint64 balance) {
-    if (!_hasBalance || _balance != balance) {
-        _balance = balance;
-        _hasBalance = true;
-
-        emit balanceChanged(_balance);
-    }
-}
-
-void DataServerAccountInfo::setBalanceFromJSON(QNetworkReply& requestReply) {
-    QJsonObject jsonObject = QJsonDocument::fromJson(requestReply.readAll()).object();
-    if (jsonObject["status"].toString() == "success") {
-        qint64 balanceInSatoshis = jsonObject["data"].toObject()["wallet"].toObject()["balance"].toDouble();
-        setBalance(balanceInSatoshis);
-    }
-}
-
 bool DataServerAccountInfo::hasProfile() const {
     return _username.length() > 0;
 }
diff --git a/libraries/networking/src/DataServerAccountInfo.h b/libraries/networking/src/DataServerAccountInfo.h
index 6223bc008e..6ee726efde 100644
--- a/libraries/networking/src/DataServerAccountInfo.h
+++ b/libraries/networking/src/DataServerAccountInfo.h
@@ -43,13 +43,6 @@ public:
     const QUuid& getWalletID() const { return _walletID; }
     void setWalletID(const QUuid& walletID);
 
-    qint64 getBalance() const { return _balance; }
-    float getBalanceInSatoshis() const { return _balance / SATOSHIS_PER_CREDIT; }
-    void setBalance(qint64 balance);
-    bool hasBalance() const { return _hasBalance; }
-    void setHasBalance(bool hasBalance) { _hasBalance = hasBalance; }
-    Q_INVOKABLE void setBalanceFromJSON(QNetworkReply& requestReply);
-
     QByteArray getUsernameSignature(const QUuid& connectionToken);
     bool hasPrivateKey() const { return !_privateKey.isEmpty(); }
     void setPrivateKey(const QByteArray& privateKey) { _privateKey = privateKey; }
@@ -65,8 +58,7 @@ public:
 
     friend QDataStream& operator<<(QDataStream &out, const DataServerAccountInfo& info);
     friend QDataStream& operator>>(QDataStream &in, DataServerAccountInfo& info);
-signals:
-    qint64 balanceChanged(qint64 newBalance);
+
 private:
     void swap(DataServerAccountInfo& otherInfo);
 
@@ -75,8 +67,6 @@ private:
     QString _xmppPassword;
     QString _discourseApiKey;
     QUuid _walletID;
-    qint64 _balance { 0 };
-    bool _hasBalance { false };
     QUuid _domainID; // if this holds account info for a domain, this holds the ID of that domain
     QByteArray _privateKey;