Updated on 2026-08-14
This commit is contained in:
parent
032e99b3d1
commit
bc1bd3e7dc
5 changed files with 51 additions and 20 deletions
|
|
@ -4,6 +4,12 @@ import retrofit2.Call;
|
|||
import retrofit2.http.GET;
|
||||
|
||||
public interface EstimatefeeApi {
|
||||
@GET(Server.ApiEstimatefee.Method.N)
|
||||
Call<String> getEstimatefee();
|
||||
@GET(Server.ApiEstimatefee.Method.N_2)
|
||||
Call<String> getEstimateFeePriority();
|
||||
|
||||
@GET(Server.ApiEstimatefee.Method.N_3)
|
||||
Call<String> getEstimateFeeNormal();
|
||||
|
||||
@GET(Server.ApiEstimatefee.Method.N_6)
|
||||
Call<String> getEstimateFeeMinimal();
|
||||
}
|
||||
|
|
@ -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";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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<String> call = estimatefeeApi.getEstimatefee();
|
||||
Call<String> 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<String>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> 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());
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ public class FeeTask extends AsyncTask<FeeRequest, Void, List<FeeRequest>> {
|
|||
httpcon.setRequestMethod("GET");
|
||||
|
||||
|
||||
Log.i("scscsccsw222", url.toString());
|
||||
Log.i("scscsccsw222", String.valueOf(request.getBlockCount()));
|
||||
|
||||
httpcon.connect();
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue