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() {