From 032e99b3d1c7616e6b78656036b39c0e163858b0 Mon Sep 17 00:00:00 2001 From: Tangem Date: Wed, 5 Sep 2018 17:17:13 +0300 Subject: [PATCH 1/5] Updated on 2026-08-14 --- .../tangem/data/network/EstimatefeeApi.java | 9 ++++ .../com/tangem/data/network/InfuraApi.java | 4 +- .../java/com/tangem/data/network/Server.java | 13 +++++- .../tangem/data/network/ServerApiHelper.java | 46 ++++++++++++++++++- .../com/tangem/data/network/ServerURL.java | 3 +- .../com/tangem/data/network/TangemApi.java | 4 +- .../data/network/request/FeeRequest.java | 9 ++-- .../com/tangem/data/network/task/FeeTask.java | 4 ++ .../activity/ConfirmPaymentActivity.kt | 10 ++++ 9 files changed, 91 insertions(+), 11 deletions(-) create mode 100644 app/src/main/java/com/tangem/data/network/EstimatefeeApi.java diff --git a/app/src/main/java/com/tangem/data/network/EstimatefeeApi.java b/app/src/main/java/com/tangem/data/network/EstimatefeeApi.java new file mode 100644 index 0000000000..b8cc1bf146 --- /dev/null +++ b/app/src/main/java/com/tangem/data/network/EstimatefeeApi.java @@ -0,0 +1,9 @@ +package com.tangem.data.network; + +import retrofit2.Call; +import retrofit2.http.GET; + +public interface EstimatefeeApi { + @GET(Server.ApiEstimatefee.Method.N) + Call getEstimatefee(); +} \ No newline at end of file diff --git a/app/src/main/java/com/tangem/data/network/InfuraApi.java b/app/src/main/java/com/tangem/data/network/InfuraApi.java index 477ce87ba1..7cba8d3ff4 100644 --- a/app/src/main/java/com/tangem/data/network/InfuraApi.java +++ b/app/src/main/java/com/tangem/data/network/InfuraApi.java @@ -6,9 +6,11 @@ import com.tangem.data.network.model.InfuraEthGasPriceResponse; import retrofit2.Call; import retrofit2.http.Body; import retrofit2.http.Header; +import retrofit2.http.Headers; import retrofit2.http.POST; public interface InfuraApi { + @Headers("Content-Type: application/json") @POST(Server.ApiInfura.Method.MAIN) - Call ethGasPrice(@Header("Content-Type") String contentType, @Body InfuraEthGasPriceBody body); + Call ethGasPrice(@Body InfuraEthGasPriceBody body); } \ No newline at end of file diff --git a/app/src/main/java/com/tangem/data/network/Server.java b/app/src/main/java/com/tangem/data/network/Server.java index ff6ad5298f..f737d80fc7 100644 --- a/app/src/main/java/com/tangem/data/network/Server.java +++ b/app/src/main/java/com/tangem/data/network/Server.java @@ -18,7 +18,7 @@ public class Server { * https://coinmarketcap.com/api/ */ public static class ApiCoinmarket { - public static final String URL_COINMARKET = ServerURL.API_COINMARKET; + public static final String URL_COINMARKET = ServerURL.API_COINMARKETCAP; public static class Method { public static final String V1_TICKER_CONVERT = URL_COINMARKET + "v1/ticker/?convert=USD&lmit=10"; @@ -34,6 +34,17 @@ public class Server { public static class Method { public static final String MAIN = URL_INFURA + "AfWg0tmYEX5Kukn2UkKV"; } + } + + /** + * https://estimatefee.com/ + */ + public static class ApiEstimatefee { + public static final String URL_ESTIMATEFEE = ServerURL.API_ESTIMATEFEE; + + public static class Method { + public static final String N = URL_ESTIMATEFEE + "n/"; + } } diff --git a/app/src/main/java/com/tangem/data/network/ServerApiHelper.java b/app/src/main/java/com/tangem/data/network/ServerApiHelper.java index f71463f2fe..6b119ddd09 100644 --- a/app/src/main/java/com/tangem/data/network/ServerApiHelper.java +++ b/app/src/main/java/com/tangem/data/network/ServerApiHelper.java @@ -50,6 +50,48 @@ import retrofit2.converter.gson.GsonConverterFactory; public class ServerApiHelper { private static String TAG = ServerApiHelper.class.getSimpleName(); + /** + * HTTP + * Estimate fee + */ + private EstimateFeeListener estimateFeeListener; + + // + public interface EstimateFeeListener { + void onInfuraEthGasPrice(String estimateFeeResponse); + } + + public void setEstimateFee(EstimateFeeListener listener) { + estimateFeeListener = listener; + } + + public void estimateFee(String fee) { + Retrofit retrofit = new Retrofit.Builder() + .baseUrl(Server.ApiEstimatefee.Method.N + fee) + .addConverterFactory(GsonConverterFactory.create()) + .build(); + + EstimatefeeApi estimatefeeApi = retrofit.create(EstimatefeeApi.class); + + Call call = estimatefeeApi.getEstimatefee(); + + call.enqueue(new Callback() { + @Override + public void onResponse(@NonNull Call call, @NonNull Response response) { + if (response.code() == 200) { + estimateFeeListener.onInfuraEthGasPrice(response.body()); + Log.i(TAG, "estimateFee onResponse " + response.code()); + } else + Log.e(TAG, "estimateFee onResponse " + response.code()); + } + + @Override + public void onFailure(@NonNull Call call, @NonNull Throwable t) { + Log.e(TAG, "estimateFee onFailure " + t.getMessage()); + } + }); + } + /** * HTTP * InfuraEthGasPrice @@ -74,7 +116,7 @@ public class ServerApiHelper { InfuraEthGasPriceBody infuraEthGasPriceBody = new InfuraEthGasPriceBody(method, id); - Call call = infuraApi.ethGasPrice("application/json", infuraEthGasPriceBody); + Call call = infuraApi.ethGasPrice(infuraEthGasPriceBody); call.enqueue(new Callback() { @Override @@ -120,7 +162,7 @@ public class ServerApiHelper { CardVerifyBody cardVerifyBody = new CardVerifyBody(requests); - Call call = tangemApi.getCardVerify("application/json", cardVerifyBody); + Call call = tangemApi.getCardVerify(cardVerifyBody); call.enqueue(new Callback() { @Override public void onResponse(@NonNull Call call, @NonNull Response response) { diff --git a/app/src/main/java/com/tangem/data/network/ServerURL.java b/app/src/main/java/com/tangem/data/network/ServerURL.java index 9cb0569b6c..fd85ee64ab 100644 --- a/app/src/main/java/com/tangem/data/network/ServerURL.java +++ b/app/src/main/java/com/tangem/data/network/ServerURL.java @@ -2,6 +2,7 @@ package com.tangem.data.network; public class ServerURL { public static final String API_TANGEM = "https://verify.tangem.com/"; - public static final String API_COINMARKET = "https://api.coinmarketcap.com/"; + public static final String API_COINMARKETCAP = "https://api.coinmarketcap.com/"; public static final String API_INFURA = "https://mainnet.infura.io/"; + public static final String API_ESTIMATEFEE = " https://estimatefee.com/"; } \ No newline at end of file diff --git a/app/src/main/java/com/tangem/data/network/TangemApi.java b/app/src/main/java/com/tangem/data/network/TangemApi.java index 198e318ab1..d505bab224 100644 --- a/app/src/main/java/com/tangem/data/network/TangemApi.java +++ b/app/src/main/java/com/tangem/data/network/TangemApi.java @@ -6,9 +6,11 @@ import com.tangem.data.network.model.CardVerifyResponse; import retrofit2.Call; import retrofit2.http.Body; import retrofit2.http.Header; +import retrofit2.http.Headers; import retrofit2.http.POST; public interface TangemApi { + @Headers("Content-Type: application/json") @POST(Server.ApiTangem.Method.VERIFY) - Call getCardVerify(@Header("Content-Type") String contentType, @Body CardVerifyBody body); + Call getCardVerify(@Body CardVerifyBody body); } \ No newline at end of file diff --git a/app/src/main/java/com/tangem/data/network/request/FeeRequest.java b/app/src/main/java/com/tangem/data/network/request/FeeRequest.java index aaca678c3d..3bca0b5c75 100644 --- a/app/src/main/java/com/tangem/data/network/request/FeeRequest.java +++ b/app/src/main/java/com/tangem/data/network/request/FeeRequest.java @@ -47,14 +47,13 @@ public class FeeRequest { public static final int NORMAL = 3; public static final int MINIMAL = 6; private int blockCount = NORMAL; + public void setBlockCount(int count - ) - { + ) { blockCount = count; } - public int getBlockCount() - { + public int getBlockCount() { return blockCount; } @@ -77,7 +76,7 @@ public class FeeRequest { public static FeeRequest GetFee(String wallet, long txSize, int blockCount) { FeeRequest request = new FeeRequest(); - request.WalletAddress=wallet; + request.WalletAddress = wallet; request.txSize = txSize; request.setBlockCount(blockCount); return request; diff --git a/app/src/main/java/com/tangem/data/network/task/FeeTask.java b/app/src/main/java/com/tangem/data/network/task/FeeTask.java index 1214ee059b..fdf64b79ad 100644 --- a/app/src/main/java/com/tangem/data/network/task/FeeTask.java +++ b/app/src/main/java/com/tangem/data/network/task/FeeTask.java @@ -1,6 +1,7 @@ package com.tangem.data.network.task; import android.os.AsyncTask; +import android.util.Log; import com.tangem.data.network.request.FeeRequest; import com.tangem.domain.wallet.SharedData; @@ -40,6 +41,9 @@ public class FeeTask extends AsyncTask> { httpcon = (HttpURLConnection) url.openConnection(); httpcon.setRequestMethod("GET"); + + Log.i("scscsccsw222", url.toString()); + httpcon.connect(); BufferedReader in = new BufferedReader( diff --git a/app/src/main/java/com/tangem/presentation/activity/ConfirmPaymentActivity.kt b/app/src/main/java/com/tangem/presentation/activity/ConfirmPaymentActivity.kt index a30c04a577..8ae99fee04 100644 --- a/app/src/main/java/com/tangem/presentation/activity/ConfirmPaymentActivity.kt +++ b/app/src/main/java/com/tangem/presentation/activity/ConfirmPaymentActivity.kt @@ -130,6 +130,9 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback { val sharedFee = SharedData(SharedData.COUNT_REQUEST) progressBar!!.visibility = View.VISIBLE + + serverApiHelper!!.estimateFee("3/") + for (i in 0 until SharedData.COUNT_REQUEST) { val feeTask = ConnectFeeTask(this@ConfirmPaymentActivity, sharedFee) feeTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, @@ -242,6 +245,13 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback { // Log.i("eth_gas_price", feeInGwei) } + + // request estimate fee listener + serverApiHelper!!.setEstimateFee { + + + Log.i("estimate_fee", it) + } } public override fun onResume() { From a8a89549932716e4a00adf9a30e6204879c04e93 Mon Sep 17 00:00:00 2001 From: Tangem Date: Thu, 6 Sep 2018 12:24:24 +0300 Subject: [PATCH 2/5] Updated on 2026-08-14 --- .../tangem/domain/wallet/BtcCashEngine.java | 6 +++--- .../com/tangem/domain/wallet/BtcEngine.java | 6 +++--- .../com/tangem/domain/wallet/CoinEngine.java | 2 +- .../com/tangem/domain/wallet/EthEngine.java | 13 ++++++++++-- .../com/tangem/domain/wallet/TokenEngine.java | 21 +++++++------------ .../activity/ConfirmPaymentActivity.kt | 6 +++--- .../presentation/fragment/LoadedWallet.kt | 2 +- app/src/main/res/values/strings.xml | 3 +-- 8 files changed, 31 insertions(+), 28 deletions(-) diff --git a/app/src/main/java/com/tangem/domain/wallet/BtcCashEngine.java b/app/src/main/java/com/tangem/domain/wallet/BtcCashEngine.java index baafb9f01b..5f7134e31a 100644 --- a/app/src/main/java/com/tangem/domain/wallet/BtcCashEngine.java +++ b/app/src/main/java/com/tangem/domain/wallet/BtcCashEngine.java @@ -176,7 +176,7 @@ public class BtcCashEngine extends CoinEngine { return Uri.parse("bitcoincash:" + mCard.getWallet()); } - public boolean checkAmountValue(TangemCard card, String amountValue, String feeValue, Long minFeeInInternalUnits) { + public boolean checkAmountValue(TangemCard card, String amountValue, String feeValue, Long minFeeInInternalUnits, Boolean incfee) { Long fee; Long amount; try { @@ -193,10 +193,10 @@ public class BtcCashEngine extends CoinEngine { if (fee == 0 || amount == 0) return false; - if (fee > amount) + if (incfee && amount > card.getBalance()) return false; - if (fee < minFeeInInternalUnits) + if (!incfee && amount + fee > card.getBalance()) return false; return true; diff --git a/app/src/main/java/com/tangem/domain/wallet/BtcEngine.java b/app/src/main/java/com/tangem/domain/wallet/BtcEngine.java index ff7101b5b1..ded862f5ea 100644 --- a/app/src/main/java/com/tangem/domain/wallet/BtcEngine.java +++ b/app/src/main/java/com/tangem/domain/wallet/BtcEngine.java @@ -333,7 +333,7 @@ public class BtcEngine extends CoinEngine { } - public boolean checkAmountValue(TangemCard card, String amountValue, String feeValue, Long minFeeInInternalUnits) { + public boolean checkAmountValue(TangemCard card, String amountValue, String feeValue, Long minFeeInInternalUnits, Boolean incfee) { Long fee; Long amount; try { @@ -350,10 +350,10 @@ public class BtcEngine extends CoinEngine { if (fee == 0 || amount == 0) return false; - if (fee > amount) + if (incfee && amount > card.getBalance()) return false; - if (fee < minFeeInInternalUnits) + if (!incfee && amount + fee > card.getBalance()) return false; return true; diff --git a/app/src/main/java/com/tangem/domain/wallet/CoinEngine.java b/app/src/main/java/com/tangem/domain/wallet/CoinEngine.java index 398a54472f..4579ed1017 100644 --- a/app/src/main/java/com/tangem/domain/wallet/CoinEngine.java +++ b/app/src/main/java/com/tangem/domain/wallet/CoinEngine.java @@ -49,7 +49,7 @@ public abstract class CoinEngine { public abstract String evaluateFeeEquivalent(TangemCard card, String fee); - public abstract boolean checkAmountValue(TangemCard card, String amount, String fee, Long minFeeInInternalUnits); + public abstract boolean checkAmountValue(TangemCard card, String amount, String fee, Long minFeeInInternalUnits, Boolean incfee); public abstract boolean inOutPutVisible(); diff --git a/app/src/main/java/com/tangem/domain/wallet/EthEngine.java b/app/src/main/java/com/tangem/domain/wallet/EthEngine.java index 6e519b0b1d..7e1f246cd4 100644 --- a/app/src/main/java/com/tangem/domain/wallet/EthEngine.java +++ b/app/src/main/java/com/tangem/domain/wallet/EthEngine.java @@ -246,7 +246,7 @@ public class EthEngine extends CoinEngine { } - public boolean checkAmountValue(TangemCard mCard, String amountValue, String feeValue, Long minFeeInInternalUnits) { + public boolean checkAmountValue(TangemCard mCard, String amountValue, String feeValue, Long minFeeInInternalUnits, Boolean incfee) { // Long fee = null; // Long amount = null; // try { @@ -270,9 +270,18 @@ public class EthEngine extends CoinEngine { try { BigDecimal tmpFee = new BigDecimal(feeValue); BigDecimal tmpAmount = new BigDecimal(amountValue); + BigDecimal cardBalance = new BigDecimal(mCard.getDecimalBalance()); tmpAmount = tmpAmount.multiply(new BigDecimal("1000000000")); - if (tmpFee.compareTo(tmpAmount) > 0) + cardBalance = cardBalance.divide(new BigDecimal("1000000000")); + //if (tmpFee.compareTo(tmpAmount) > 0) + // return false; + + if (incfee && tmpAmount.compareTo(cardBalance) > 0 ) return false; + + if (!incfee && tmpAmount.add(tmpFee).compareTo(cardBalance) > 0) + return false; + } catch (NumberFormatException e) { e.printStackTrace(); } diff --git a/app/src/main/java/com/tangem/domain/wallet/TokenEngine.java b/app/src/main/java/com/tangem/domain/wallet/TokenEngine.java index 8e1a35f2e9..1a51ad389c 100644 --- a/app/src/main/java/com/tangem/domain/wallet/TokenEngine.java +++ b/app/src/main/java/com/tangem/domain/wallet/TokenEngine.java @@ -292,7 +292,7 @@ public class TokenEngine extends CoinEngine { return true; } - public boolean checkAmountValue(TangemCard card, String amountValue, String feeValue, Long minFeeInInternalUnits) { + public boolean checkAmountValue(TangemCard card, String amountValue, String feeValue, Long minFeeInInternalUnits, Boolean incfee) { Long fee; BigDecimal amount; try { @@ -309,17 +309,12 @@ public class TokenEngine extends CoinEngine { if (fee == 0 || amount.compareTo(BigDecimal.ZERO) == 0) return false; - - if (fee < minFeeInInternalUnits) - return false; - - - BigDecimal tmpFee = new BigDecimal(feeValue); - BigDecimal tmpAmount = amount; - tmpAmount = tmpAmount.multiply(new BigDecimal("1000000000")); - - if (tmpFee.compareTo(tmpAmount) > 0) - return false; +// BigDecimal tmpFee = new BigDecimal(feeValue); +// BigDecimal tmpAmount = amount; +// tmpAmount = tmpAmount.multiply(new BigDecimal("1000000000")); +// +// if (tmpFee.compareTo(tmpAmount) > 0) +// return false; return true; } @@ -357,7 +352,7 @@ public class TokenEngine extends CoinEngine { //amount = amount.subtract(fee); BigInteger nonce = nonceValue; - BigInteger gasPrice = fee.divide(BigInteger.valueOf(21000)); + BigInteger gasPrice = fee.divide(BigInteger.valueOf(60000)); BigInteger gasLimit = BigInteger.valueOf(60000); Integer chainId = EthTransaction.ChainEnum.Mainnet.getValue(); BigInteger amountZero = BigInteger.ZERO; diff --git a/app/src/main/java/com/tangem/presentation/activity/ConfirmPaymentActivity.kt b/app/src/main/java/com/tangem/presentation/activity/ConfirmPaymentActivity.kt index a30c04a577..f3cb1e046d 100644 --- a/app/src/main/java/com/tangem/presentation/activity/ConfirmPaymentActivity.kt +++ b/app/src/main/java/com/tangem/presentation/activity/ConfirmPaymentActivity.kt @@ -203,8 +203,8 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback { return@setOnClickListener } - if (!engineCoin.checkAmountValue(card, txAmount, txFee, minFeeInInternalUnits)) { - finishActivityWithError(Activity.RESULT_CANCELED, getString(R.string.not_enough_eth_for_transaction_fee)) + if (!engineCoin.checkAmountValue(card, txAmount, txFee, minFeeInInternalUnits, incFee)) { + finishActivityWithError(Activity.RESULT_CANCELED, getString(R.string.not_enough_funds_or_incorrect_amount)) return@setOnClickListener } @@ -223,7 +223,7 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback { gasPrice = gasPrice.substring(2) var l = BigInteger(gasPrice, 16) - val m = if (card!!.blockchain == Blockchain.Token) BigInteger.valueOf(55000) else BigInteger.valueOf(21000) + val m = if (card!!.blockchain == Blockchain.Token) BigInteger.valueOf(60000) else BigInteger.valueOf(21000) l = l.multiply(m) val minFeeInGwei = card!!.getAmountInGwei(l.toString()) val normalFeeInGwei = card!!.getAmountInGwei(l.multiply(BigInteger.valueOf(12)).divide(BigInteger.valueOf(10)).toString()) diff --git a/app/src/main/java/com/tangem/presentation/fragment/LoadedWallet.kt b/app/src/main/java/com/tangem/presentation/fragment/LoadedWallet.kt index e78e9dfe37..20e5718675 100644 --- a/app/src/main/java/com/tangem/presentation/fragment/LoadedWallet.kt +++ b/app/src/main/java/com/tangem/presentation/fragment/LoadedWallet.kt @@ -201,7 +201,7 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific } else if (!engine.isBalanceNotZero(card)) showSingleToast(R.string.wallet_empty) else if (!engine.isBalanceAlterNotZero(card)) - showSingleToast(R.string.not_enough_funds) + showSingleToast(R.string.not_enough_funds_or_incorrect_amount) else if (engine.awaitingConfirmation(card)) showSingleToast(R.string.please_wait_while_previous) else if (!engine.checkUnspentTransaction(card)) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 96f84edc90..98ada212d8 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -92,7 +92,6 @@ The wallet is empty No compatible wallet installed - Not enough funds for transaction fee (gas)! Please wait while previous transaction is confirmed in blockchain Could not obtain all inputs. Swipe down to refresh. Card has no remaining signature! @@ -180,7 +179,7 @@ Cannot check balance! No connection with blockchain nodes The wallet is empty Please wait for confirmation of incoming transaction - Not enough ETH for transaction fee + Not enough funds or incorrect amount PIN2 is required to sign the payment From bc1bd3e7dc36ef8df0a8e9d2aac68bc0d6aef90b Mon Sep 17 00:00:00 2001 From: Tangem Date: Thu, 6 Sep 2018 13:31:31 +0300 Subject: [PATCH 3/5] Updated on 2026-08-14 --- .../tangem/data/network/EstimatefeeApi.java | 10 ++++-- .../java/com/tangem/data/network/Server.java | 5 +-- .../tangem/data/network/ServerApiHelper.java | 36 ++++++++++++------- .../com/tangem/data/network/task/FeeTask.java | 2 +- .../activity/ConfirmPaymentActivity.kt | 18 ++++++++-- 5 files changed, 51 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/com/tangem/data/network/EstimatefeeApi.java b/app/src/main/java/com/tangem/data/network/EstimatefeeApi.java index b8cc1bf146..a004db3864 100644 --- a/app/src/main/java/com/tangem/data/network/EstimatefeeApi.java +++ b/app/src/main/java/com/tangem/data/network/EstimatefeeApi.java @@ -4,6 +4,12 @@ import retrofit2.Call; import retrofit2.http.GET; public interface EstimatefeeApi { - @GET(Server.ApiEstimatefee.Method.N) - Call getEstimatefee(); + @GET(Server.ApiEstimatefee.Method.N_2) + Call getEstimateFeePriority(); + + @GET(Server.ApiEstimatefee.Method.N_3) + Call getEstimateFeeNormal(); + + @GET(Server.ApiEstimatefee.Method.N_6) + Call getEstimateFeeMinimal(); } \ No newline at end of file diff --git a/app/src/main/java/com/tangem/data/network/Server.java b/app/src/main/java/com/tangem/data/network/Server.java index f737d80fc7..83d70ba239 100644 --- a/app/src/main/java/com/tangem/data/network/Server.java +++ b/app/src/main/java/com/tangem/data/network/Server.java @@ -43,9 +43,10 @@ public class Server { public static final String URL_ESTIMATEFEE = ServerURL.API_ESTIMATEFEE; public static class Method { - public static final String N = URL_ESTIMATEFEE + "n/"; + public static final String N_2 = URL_ESTIMATEFEE + "n/2"; + public static final String N_3 = URL_ESTIMATEFEE + "n/3"; + public static final String N_6 = URL_ESTIMATEFEE + "n/6"; } - } } \ No newline at end of file diff --git a/app/src/main/java/com/tangem/data/network/ServerApiHelper.java b/app/src/main/java/com/tangem/data/network/ServerApiHelper.java index 6b119ddd09..773fe789fc 100644 --- a/app/src/main/java/com/tangem/data/network/ServerApiHelper.java +++ b/app/src/main/java/com/tangem/data/network/ServerApiHelper.java @@ -4,9 +4,6 @@ import android.annotation.SuppressLint; import android.support.annotation.NonNull; import android.util.Log; -import com.google.gson.Gson; -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; import com.jakewharton.retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; import com.tangem.data.network.model.CardVerify; import com.tangem.data.network.model.CardVerifyBody; @@ -21,9 +18,6 @@ import com.tangem.domain.wallet.Blockchain; import com.tangem.domain.wallet.TangemCard; import com.tangem.util.Util; -import org.json.JSONException; -import org.json.JSONObject; - import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; @@ -54,32 +48,50 @@ public class ServerApiHelper { * HTTP * Estimate fee */ + public static final int ESTIMATE_FEE_PRIORITY = 2; + public static final int ESTIMATE_FEE_NORMAL = 3; + public static final int ESTIMATE_FEE_MINIMAL = 6; private EstimateFeeListener estimateFeeListener; - // public interface EstimateFeeListener { - void onInfuraEthGasPrice(String estimateFeeResponse); + void onInfuraEthGasPrice(int blockCount, String estimateFeeResponse); } public void setEstimateFee(EstimateFeeListener listener) { estimateFeeListener = listener; } - public void estimateFee(String fee) { + public void estimateFee(int blockCount) { Retrofit retrofit = new Retrofit.Builder() - .baseUrl(Server.ApiEstimatefee.Method.N + fee) + .baseUrl(Server.ApiEstimatefee.URL_ESTIMATEFEE) .addConverterFactory(GsonConverterFactory.create()) .build(); EstimatefeeApi estimatefeeApi = retrofit.create(EstimatefeeApi.class); - Call call = estimatefeeApi.getEstimatefee(); + Call call; + switch (blockCount) { + case ESTIMATE_FEE_PRIORITY: + call = estimatefeeApi.getEstimateFeePriority(); + break; + + case ESTIMATE_FEE_NORMAL: + call = estimatefeeApi.getEstimateFeeNormal(); + break; + + case ESTIMATE_FEE_MINIMAL: + call = estimatefeeApi.getEstimateFeeMinimal(); + break; + + default: + call = estimatefeeApi.getEstimateFeeNormal(); + } call.enqueue(new Callback() { @Override public void onResponse(@NonNull Call call, @NonNull Response response) { if (response.code() == 200) { - estimateFeeListener.onInfuraEthGasPrice(response.body()); + estimateFeeListener.onInfuraEthGasPrice(blockCount, response.body()); Log.i(TAG, "estimateFee onResponse " + response.code()); } else Log.e(TAG, "estimateFee onResponse " + response.code()); diff --git a/app/src/main/java/com/tangem/data/network/task/FeeTask.java b/app/src/main/java/com/tangem/data/network/task/FeeTask.java index fdf64b79ad..1f6563906b 100644 --- a/app/src/main/java/com/tangem/data/network/task/FeeTask.java +++ b/app/src/main/java/com/tangem/data/network/task/FeeTask.java @@ -42,7 +42,7 @@ public class FeeTask extends AsyncTask> { httpcon.setRequestMethod("GET"); - Log.i("scscsccsw222", url.toString()); + Log.i("scscsccsw222", String.valueOf(request.getBlockCount())); httpcon.connect(); diff --git a/app/src/main/java/com/tangem/presentation/activity/ConfirmPaymentActivity.kt b/app/src/main/java/com/tangem/presentation/activity/ConfirmPaymentActivity.kt index 8ae99fee04..9b9eced2ca 100644 --- a/app/src/main/java/com/tangem/presentation/activity/ConfirmPaymentActivity.kt +++ b/app/src/main/java/com/tangem/presentation/activity/ConfirmPaymentActivity.kt @@ -131,7 +131,9 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback { progressBar!!.visibility = View.VISIBLE - serverApiHelper!!.estimateFee("3/") +// serverApiHelper!!.estimateFee(ServerApiHelper.ESTIMATE_FEE_PRIORITY) +// serverApiHelper!!.estimateFee(ServerApiHelper.ESTIMATE_FEE_NORMAL) +// serverApiHelper!!.estimateFee(ServerApiHelper.ESTIMATE_FEE_MINIMAL) for (i in 0 until SharedData.COUNT_REQUEST) { val feeTask = ConnectFeeTask(this@ConfirmPaymentActivity, sharedFee) @@ -247,10 +249,20 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback { } // request estimate fee listener - serverApiHelper!!.setEstimateFee { + serverApiHelper!!.setEstimateFee { blockCount, estimateFeeResponse -> + when (blockCount) { + ServerApiHelper.ESTIMATE_FEE_PRIORITY -> { +// Log.i("estimate_fee_PRIORITY", estimateFeeResponse) + } + ServerApiHelper.ESTIMATE_FEE_NORMAL -> { +// Log.i("estimate_fee_NORMAL", estimateFeeResponse) + } - Log.i("estimate_fee", it) + ServerApiHelper.ESTIMATE_FEE_MINIMAL -> { +// Log.i("estimate_fee_MINIMAL", estimateFeeResponse) + } + } } } From 1fe704da314c8c1892ca654c0e67d8182254a66b Mon Sep 17 00:00:00 2001 From: Tangem Date: Thu, 6 Sep 2018 15:04:50 +0300 Subject: [PATCH 4/5] Updated on 2026-08-14 --- app/build.gradle | 2 +- .../data/network/task/ElectrumTask.java | 3 +- .../presentation/fragment/LoadedWallet.kt | 36 +++++++++++++------ 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 6fb42da94e..452904f4c7 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -15,7 +15,7 @@ android { applicationId "com.tangem.wallet" minSdkVersion 21 targetSdkVersion 27 - versionCode 71 + versionCode 72 versionName "0.88.1." + generateVersionName() testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } diff --git a/app/src/main/java/com/tangem/data/network/task/ElectrumTask.java b/app/src/main/java/com/tangem/data/network/task/ElectrumTask.java index 2d1855c16d..eb8f5e063d 100644 --- a/app/src/main/java/com/tangem/data/network/task/ElectrumTask.java +++ b/app/src/main/java/com/tangem/data/network/task/ElectrumTask.java @@ -60,7 +60,8 @@ public class ElectrumTask extends AsyncTask { if (resultCode == Activity.RESULT_OK) { - srlLoadedWallet!!.postDelayed({ this.refresh() }, 10000) - srlLoadedWallet!!.isRefreshing = true +// srlLoadedWallet!!.postDelayed({ refresh() }, 10000) +// srlLoadedWallet!!.isRefreshing = true card!!.clearInfo() - updateViews() + repeatRefresh() +// updateViews() } if (data != null && data.extras != null) { From 4caba0bc8a56fe2c239ae289cba9f5f8435e257c Mon Sep 17 00:00:00 2001 From: Tangem Date: Thu, 6 Sep 2018 16:57:09 +0300 Subject: [PATCH 5/5] Updated on 2026-08-14 --- app/build.gradle | 2 +- .../com/tangem/presentation/fragment/LoadedWallet.kt | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 452904f4c7..8b9e416b5c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -15,7 +15,7 @@ android { applicationId "com.tangem.wallet" minSdkVersion 21 targetSdkVersion 27 - versionCode 72 + versionCode 73 versionName "0.88.1." + generateVersionName() testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } diff --git a/app/src/main/java/com/tangem/presentation/fragment/LoadedWallet.kt b/app/src/main/java/com/tangem/presentation/fragment/LoadedWallet.kt index a20d14a99a..abf2c374d6 100644 --- a/app/src/main/java/com/tangem/presentation/fragment/LoadedWallet.kt +++ b/app/src/main/java/com/tangem/presentation/fragment/LoadedWallet.kt @@ -121,7 +121,9 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific // srlLoadedWallet!!.postDelayed({ refresh() }, 1000) // } - repeatRefresh() +// repeatRefresh() + + refresh() startVerify(lastTag) @@ -266,7 +268,12 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific override fun onPause() { super.onPause() nfcManager!!.onPause() - timerRepeatRefresh.cancel() + + try { + timerRepeatRefresh.cancel() + } catch (e: IllegalStateException) { + e.printStackTrace() + } } override fun onStop() {