Updated on 2026-08-14

This commit is contained in:
Tangem 2018-09-05 17:17:13 +03:00
parent faa1cd750c
commit 032e99b3d1
9 changed files with 91 additions and 11 deletions

View file

@ -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<String> getEstimatefee();
}

View file

@ -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<InfuraEthGasPriceResponse> ethGasPrice(@Header("Content-Type") String contentType, @Body InfuraEthGasPriceBody body);
Call<InfuraEthGasPriceResponse> ethGasPrice(@Body InfuraEthGasPriceBody body);
}

View file

@ -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/";
}
}

View file

@ -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<String> call = estimatefeeApi.getEstimatefee();
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());
Log.i(TAG, "estimateFee onResponse " + response.code());
} else
Log.e(TAG, "estimateFee onResponse " + response.code());
}
@Override
public void onFailure(@NonNull Call<String> 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<InfuraEthGasPriceResponse> call = infuraApi.ethGasPrice("application/json", infuraEthGasPriceBody);
Call<InfuraEthGasPriceResponse> call = infuraApi.ethGasPrice(infuraEthGasPriceBody);
call.enqueue(new Callback<InfuraEthGasPriceResponse>() {
@Override
@ -120,7 +162,7 @@ public class ServerApiHelper {
CardVerifyBody cardVerifyBody = new CardVerifyBody(requests);
Call<CardVerifyResponse> call = tangemApi.getCardVerify("application/json", cardVerifyBody);
Call<CardVerifyResponse> call = tangemApi.getCardVerify(cardVerifyBody);
call.enqueue(new Callback<CardVerifyResponse>() {
@Override
public void onResponse(@NonNull Call<CardVerifyResponse> call, @NonNull Response<CardVerifyResponse> response) {

View file

@ -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/";
}

View file

@ -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<CardVerifyResponse> getCardVerify(@Header("Content-Type") String contentType, @Body CardVerifyBody body);
Call<CardVerifyResponse> getCardVerify(@Body CardVerifyBody body);
}

View file

@ -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;

View file

@ -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<FeeRequest, Void, List<FeeRequest>> {
httpcon = (HttpURLConnection) url.openConnection();
httpcon.setRequestMethod("GET");
Log.i("scscsccsw222", url.toString());
httpcon.connect();
BufferedReader in = new BufferedReader(

View file

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