Updated on 2026-08-14

This commit is contained in:
Tangem 2018-09-07 10:51:35 +03:00
commit 5c6ea5ca04
18 changed files with 195 additions and 57 deletions

View file

@ -15,7 +15,7 @@ android {
applicationId "com.tangem.wallet"
minSdkVersion 21
targetSdkVersion 27
versionCode 71
versionCode 73
versionName "0.88.1." + generateVersionName()
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

View file

@ -0,0 +1,15 @@
package com.tangem.data.network;
import retrofit2.Call;
import retrofit2.http.GET;
public interface EstimatefeeApi {
@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();
}

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

@ -28,7 +28,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";
@ -44,7 +44,19 @@ 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_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";
}
}
}

View file

@ -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.IOException;
import java.io.InputStream;
@ -54,6 +48,66 @@ import retrofit2.converter.gson.GsonConverterFactory;
public class ServerApiHelper {
private static String TAG = ServerApiHelper.class.getSimpleName();
/**
* 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(int blockCount, String estimateFeeResponse);
}
public void setEstimateFee(EstimateFeeListener listener) {
estimateFeeListener = listener;
}
public void estimateFee(int blockCount) {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(Server.ApiEstimatefee.URL_ESTIMATEFEE)
.addConverterFactory(GsonConverterFactory.create())
.build();
EstimatefeeApi estimatefeeApi = retrofit.create(EstimatefeeApi.class);
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(blockCount, 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
@ -78,7 +132,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
@ -124,7 +178,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,7 +2,8 @@ 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/";
public static final String API_UPDATE_VERSION = "https://raw.githubusercontent.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

@ -60,7 +60,8 @@ public class ElectrumTask extends AsyncTask<ElectrumRequest, Integer, List<Elect
Log.v(logTag, "Connecting..." + Host);
// Socket socket = new Socket(serverAddress, port);
Socket socket = new Socket();
socket.setSoTimeout(5000);
// socket.setSoTimeout(5000);
socket.setSoTimeout(10000);
socket.bind(new InetSocketAddress(0));
socket.connect(new InetSocketAddress(serverAddress, Port));
// Log.i("effefefe", host);

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", String.valueOf(request.getBlockCount()));
httpcon.connect();
BufferedReader in = new BufferedReader(

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -130,6 +130,11 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
val sharedFee = SharedData(SharedData.COUNT_REQUEST)
progressBar!!.visibility = View.VISIBLE
// 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)
feeTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR,
@ -203,8 +208,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 +228,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())
@ -242,6 +247,23 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
// Log.i("eth_gas_price", feeInGwei)
}
// request estimate fee listener
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)
}
ServerApiHelper.ESTIMATE_FEE_MINIMAL -> {
// Log.i("estimate_fee_MINIMAL", estimateFeeResponse)
}
}
}
}
public override fun onResume() {

View file

@ -73,6 +73,8 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
private val inactiveColor: ColorStateList by lazy { resources.getColorStateList(R.color.primary) }
private val activeColor: ColorStateList by lazy { resources.getColorStateList(R.color.colorAccent) }
private val timerRepeatRefresh = Timer()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
nfcManager = NfcManager(activity, this)
@ -112,21 +114,23 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
btnExtract.backgroundTintList = inactiveColor
updateViews()
// updateViews()
if (!card!!.hasBalanceInfo()) {
srlLoadedWallet!!.isRefreshing = true
srlLoadedWallet!!.postDelayed({ this.refresh() }, 1000)
}
// if (!card!!.hasBalanceInfo()) {
// srlLoadedWallet!!.isRefreshing = true
// srlLoadedWallet!!.postDelayed({ refresh() }, 1000)
// }
// requestCardVerify()
// repeatRefresh()
refresh()
startVerify(lastTag)
tvWallet.text = card!!.wallet
// set listeners
srlLoadedWallet!!.setOnRefreshListener { this.refresh() }
srlLoadedWallet!!.setOnRefreshListener { refresh() }
btnLookup.setOnClickListener {
val engineClick = CoinEngineFactory.create(card!!.blockchain)
val browserIntent = Intent(Intent.ACTION_VIEW, engineClick.getShareWalletUriExplorer(card))
@ -201,7 +205,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))
@ -249,9 +253,27 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
nfcManager!!.onResume()
}
private fun repeatRefresh() {
val getBalance = object : TimerTask() {
override fun run() {
activity!!.runOnUiThread {
refresh()
// Log.i("efgrgegsdfgsd", "repeatRefresh")
}
}
}
timerRepeatRefresh.schedule(getBalance, 0, 5000)
}
override fun onPause() {
super.onPause()
nfcManager!!.onPause()
try {
timerRepeatRefresh.cancel()
} catch (e: IllegalStateException) {
e.printStackTrace()
}
}
override fun onStop() {
@ -397,10 +419,11 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
}
REQUEST_CODE_SEND_PAYMENT, REQUEST_CODE_RECEIVE_PAYMENT -> {
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) {

View file

@ -92,7 +92,6 @@
<!-- LoadedWalletActivity, LoadedWallet -->
<string name="wallet_empty">The wallet is empty</string>
<string name="no_compatible_wallet">No compatible wallet installed</string>
<string name="not_enough_funds">Not enough funds for transaction fee (gas)!</string>
<string name="please_wait_while_previous">Please wait while previous transaction is confirmed in blockchain</string>
<string name="please_wait_for_confirmation">Could not obtain all inputs. Swipe down to refresh.</string>
<string name="card_has_no_remaining_signature">Card has no remaining signature!</string>
@ -180,7 +179,7 @@
<string name="cannot_check_balance_no_connection_with_blockchain_nodes">Cannot check balance! No connection with blockchain nodes</string>
<string name="the_wallet_is_empty">The wallet is empty</string>
<string name="please_wait_for_confirmation_of_incoming_transaction">Please wait for confirmation of incoming transaction</string>
<string name="not_enough_eth_for_transaction_fee">Not enough ETH for transaction fee</string>
<string name="not_enough_funds_or_incorrect_amount">Not enough funds or incorrect amount</string>
<string name="pin_2_is_required_to_sign_the_payment">PIN2 is required to sign the payment</string>
<!-- EmptyWalletActivity -->