From bc1bd3e7dc36ef8df0a8e9d2aac68bc0d6aef90b Mon Sep 17 00:00:00 2001 From: Tangem Date: Thu, 6 Sep 2018 13:31:31 +0300 Subject: [PATCH] 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) + } + } } }