From 9cacb7a380b0b5d8a4cdf4a7cc6030df47bea6e5 Mon Sep 17 00:00:00 2001 From: Tanguy Herbron Date: Wed, 28 Feb 2018 11:44:10 +0100 Subject: [PATCH] Fix invalid API keys crash --- .../coinfolio/Activities/HomeActivity.java | 19 +++++++++++++-- .../DataManagers/BalanceManager.java | 6 ++--- .../ExchangeManager/BinanceManager.java | 23 +++++++++++-------- app/src/main/res/values/strings.xml | 1 + 4 files changed, 34 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivity.java b/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivity.java index b6bd62b..f7ca4ed 100644 --- a/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivity.java +++ b/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivity.java @@ -27,6 +27,7 @@ import android.view.View; import android.view.ViewGroup; import android.view.Window; import android.view.WindowManager; +import android.widget.FrameLayout; import android.widget.ImageButton; import android.widget.LinearLayout; import android.widget.ProgressBar; @@ -729,7 +730,12 @@ public class HomeActivity extends AppCompatActivity { } else { - countCoins(false, false); + runOnUiThread(new Runnable() { + @Override + public void run() { + countCoins(false, false); + } + }); } } @@ -739,12 +745,21 @@ public class HomeActivity extends AppCompatActivity { { case "com.android.volley.AuthFailureError": preferencesManager.disableHitBTC(); - Snackbar.make(findViewById(R.id.currencyListLayout), "HitBTC synchronization error : Invalid keys", Snackbar.LENGTH_LONG) + Snackbar.make(findViewById(R.id.viewFlipperSummary), "HitBTC synchronization error : Invalid keys", Snackbar.LENGTH_LONG) .show(); refreshLayout.setRefreshing(false); updateAll(true); break; + case "API-key format invalid.": + preferencesManager.disableBinance(); + Snackbar.make(findViewById(R.id.viewFlipperSummary), "Binance synchronization error : Invalid keys", Snackbar.LENGTH_LONG) + .show(); + updateAll(true); + break; default: + Snackbar.make(findViewById(R.id.viewFlipperSummary), "Unexpected error", Snackbar.LENGTH_LONG) + .show(); + Log.d("coinfolio", error); updateAll(true); } } diff --git a/app/src/main/java/com/nauk/coinfolio/DataManagers/BalanceManager.java b/app/src/main/java/com/nauk/coinfolio/DataManagers/BalanceManager.java index 5c05f78..1121550 100644 --- a/app/src/main/java/com/nauk/coinfolio/DataManagers/BalanceManager.java +++ b/app/src/main/java/com/nauk/coinfolio/DataManagers/BalanceManager.java @@ -185,7 +185,7 @@ public class BalanceManager { @Override public void onError(String error) { - + callBack.onError(error); } }); } @@ -205,7 +205,7 @@ public class BalanceManager { @Override public void onError(String error) { - + callBack.onError(error); } }); } @@ -240,8 +240,6 @@ public class BalanceManager { for(int i = 0; i < binanceManagers.size(); i++) { - Log.d("coinfolio", "Merging binance " + i); - mergeBalanceTotal(binanceManagers.get(i).getBalance()); } diff --git a/app/src/main/java/com/nauk/coinfolio/DataManagers/ExchangeManager/BinanceManager.java b/app/src/main/java/com/nauk/coinfolio/DataManagers/ExchangeManager/BinanceManager.java index 8bf5f58..4c1a2df 100644 --- a/app/src/main/java/com/nauk/coinfolio/DataManagers/ExchangeManager/BinanceManager.java +++ b/app/src/main/java/com/nauk/coinfolio/DataManagers/ExchangeManager/BinanceManager.java @@ -7,6 +7,7 @@ import com.binance.api.client.BinanceApiClientFactory; import com.binance.api.client.BinanceApiRestClient; import com.binance.api.client.domain.account.Account; import com.binance.api.client.domain.account.AssetBalance; +import com.binance.api.client.exception.BinanceApiException; import com.nauk.coinfolio.DataManagers.CurrencyData.Currency; import java.util.ArrayList; @@ -38,20 +39,24 @@ public class BinanceManager { BinanceApiClientFactory factory = BinanceApiClientFactory.newInstance(publicKey, privateKey); BinanceApiRestClient client = factory.newRestClient(); - Account account = client.getAccount(); - List assets = account.getBalances(); + try { + Account account = client.getAccount(); + List assets = account.getBalances(); - balance = new ArrayList<>(); + balance = new ArrayList<>(); - for(int i = 0; i < assets.size(); i++) - { - if(Double.parseDouble(assets.get(i).getFree()) > 0) + for(int i = 0; i < assets.size(); i++) { - balance.add(new Currency(assets.get(i).getAsset(), Double.parseDouble(assets.get(i).getFree()))); + if(Double.parseDouble(assets.get(i).getFree()) > 0) + { + balance.add(new Currency(assets.get(i).getAsset(), Double.parseDouble(assets.get(i).getFree()))); + } } - } - callBack.onSuccess(); + callBack.onSuccess(); + } catch (BinanceApiException e) { + callBack.onError(e.getMessage()); + } } public void setPublicKey(String publicKey) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5d9741b..bd86948 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -82,6 +82,7 @@ Exchanges settings + Touch ID Enable synchronization