Updated on 2026-08-14
This commit is contained in:
parent
8afcc6fbdf
commit
608753d937
10 changed files with 100 additions and 83 deletions
|
|
@ -52,19 +52,19 @@ public class ServerApiHelper {
|
|||
|
||||
/**
|
||||
* HTTP
|
||||
* Infura
|
||||
* InfuraEthGasPrice
|
||||
*/
|
||||
private InfuraListener infuraListener;
|
||||
private InfuraEthGasPriceBodyListener infuraEthGasPriceBodyListener;
|
||||
|
||||
public interface InfuraListener {
|
||||
void onInfura(CardVerifyResponse cardVerifyResponse);
|
||||
public interface InfuraEthGasPriceBodyListener {
|
||||
void onInfuraEthGasPrice(InfuraEthGasPriceResponse cardVerifyResponse);
|
||||
}
|
||||
|
||||
public void setInfura(InfuraListener listener) {
|
||||
infuraListener = listener;
|
||||
public void setInfuraEthGasPrice(InfuraEthGasPriceBodyListener listener) {
|
||||
infuraEthGasPriceBodyListener = listener;
|
||||
}
|
||||
|
||||
public void infura(String method, int id) {
|
||||
public void infuraEthGasPrice(String method, int id) {
|
||||
Retrofit retrofit = new Retrofit.Builder()
|
||||
.baseUrl(Server.ApiInfura.URL_INFURA)
|
||||
.addConverterFactory(GsonConverterFactory.create())
|
||||
|
|
@ -80,15 +80,15 @@ public class ServerApiHelper {
|
|||
@Override
|
||||
public void onResponse(@NonNull Call<InfuraEthGasPriceResponse> call, @NonNull Response<InfuraEthGasPriceResponse> response) {
|
||||
if (response.code() == 200) {
|
||||
Log.i(TAG, "infura onResponse " + response.code());
|
||||
Log.i(TAG, "infura onResponse " + response.body().getResult());
|
||||
infuraEthGasPriceBodyListener.onInfuraEthGasPrice(response.body());
|
||||
Log.i(TAG, "infuraEthGasPrice onResponse " + response.code());
|
||||
} else
|
||||
Log.e(TAG, "infura onResponse " + response.code());
|
||||
Log.e(TAG, "infuraEthGasPrice onResponse " + response.code());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<InfuraEthGasPriceResponse> call, @NonNull Throwable t) {
|
||||
Log.e(TAG, "infura onFailure " + t.getMessage());
|
||||
Log.e(TAG, "infuraEthGasPrice onFailure " + t.getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -93,7 +93,7 @@ public class ConnectFeeTask extends FeeTask {
|
|||
|
||||
if ((request.getBlockCount() == FeeRequest.MINIMAL) && (confirmPaymentActivity.getMinFee() == null)) {
|
||||
confirmPaymentActivity.setMinFee(String.valueOf(finalFee));
|
||||
confirmPaymentActivity.setMinFeeInInternalUnits(confirmPaymentActivity.getCard().InternalUnitsFromString(String.valueOf(finalFee)));
|
||||
confirmPaymentActivity.setMinFeeInInternalUnits(confirmPaymentActivity.getCard().internalUnitsFromString(String.valueOf(finalFee)));
|
||||
} else if ((request.getBlockCount() == FeeRequest.NORMAL) && (confirmPaymentActivity.getNormalFee() == null)) {
|
||||
confirmPaymentActivity.setNormalFee(String.valueOf(finalFee));
|
||||
} else if ((request.getBlockCount() == FeeRequest.PRIORITY) && (confirmPaymentActivity.getMaxFee() == null)) {
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ public class ETHRequestTask extends InfuraTask {
|
|||
confirmPaymentActivity.setFeeRequestSuccess(true);
|
||||
confirmPaymentActivity.setBalanceRequestSuccess(true);
|
||||
confirmPaymentActivity.setDtVerified(new Date());
|
||||
confirmPaymentActivity.setMinFeeInInternalUnits(confirmPaymentActivity.getCard().InternalUnitsFromString(feeInGwei));
|
||||
confirmPaymentActivity.setMinFeeInInternalUnits(confirmPaymentActivity.getCard().internalUnitsFromString(feeInGwei));
|
||||
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
|
|
|
|||
|
|
@ -176,12 +176,12 @@ public class BtcCashEngine extends CoinEngine {
|
|||
return Uri.parse("bitcoincash:" + mCard.getWallet());
|
||||
}
|
||||
|
||||
public boolean checkAmountValue(TangemCard mCard, String amountValue, String feeValue, Long minFeeInInternalUnits) {
|
||||
Long fee = null;
|
||||
Long amount = null;
|
||||
public boolean checkAmountValue(TangemCard card, String amountValue, String feeValue, Long minFeeInInternalUnits) {
|
||||
Long fee;
|
||||
Long amount;
|
||||
try {
|
||||
amount = mCard.InternalUnitsFromString(amountValue);
|
||||
fee = mCard.InternalUnitsFromString(feeValue);
|
||||
amount = card.internalUnitsFromString(amountValue);
|
||||
fee = card.internalUnitsFromString(feeValue);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
|
|
@ -287,8 +287,8 @@ public class BtcCashEngine extends CoinEngine {
|
|||
}
|
||||
|
||||
@Override
|
||||
public byte[] convertAmountToByteArray(TangemCard mCard, String amount) throws Exception {
|
||||
byte[] bytes = Util.longToByteArray(mCard.InternalUnitsFromString(amount));
|
||||
public byte[] convertAmountToByteArray(TangemCard card, String amount) throws Exception {
|
||||
byte[] bytes = Util.longToByteArray(card.internalUnitsFromString(amount));
|
||||
byte[] reversed = new byte[bytes.length];
|
||||
for (int i = 0; i < bytes.length; i++) reversed[i] = bytes[bytes.length - i - 1];
|
||||
return reversed;
|
||||
|
|
|
|||
|
|
@ -333,12 +333,12 @@ public class BtcEngine extends CoinEngine {
|
|||
}
|
||||
|
||||
|
||||
public boolean checkAmountValue(TangemCard mCard, String amountValue, String feeValue, Long minFeeInInternalUnits) {
|
||||
Long fee = null;
|
||||
Long amount = null;
|
||||
public boolean checkAmountValue(TangemCard card, String amountValue, String feeValue, Long minFeeInInternalUnits) {
|
||||
Long fee;
|
||||
Long amount;
|
||||
try {
|
||||
amount = mCard.InternalUnitsFromString(amountValue);
|
||||
fee = mCard.InternalUnitsFromString(feeValue);
|
||||
amount = card.internalUnitsFromString(amountValue);
|
||||
fee = card.internalUnitsFromString(feeValue);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
|
|
@ -445,7 +445,7 @@ public class BtcEngine extends CoinEngine {
|
|||
|
||||
@Override
|
||||
public byte[] convertAmountToByteArray(TangemCard mCard, String amount) throws Exception {
|
||||
byte[] bytes = Util.longToByteArray(mCard.InternalUnitsFromString(amount));
|
||||
byte[] bytes = Util.longToByteArray(mCard.internalUnitsFromString(amount));
|
||||
byte[] reversed = new byte[bytes.length];
|
||||
for (int i = 0; i < bytes.length; i++) reversed[i] = bytes[bytes.length - i - 1];
|
||||
return reversed;
|
||||
|
|
|
|||
|
|
@ -246,8 +246,8 @@ public class EthEngine extends CoinEngine {
|
|||
// Long fee = null;
|
||||
// Long amount = null;
|
||||
// try {
|
||||
// amount = mCard.InternalUnitsFromString(amountValue);
|
||||
// fee = mCard.InternalUnitsFromString(feeValue);
|
||||
// amount = mCard.internalUnitsFromString(amountValue);
|
||||
// fee = mCard.internalUnitsFromString(feeValue);
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// return false;
|
||||
|
|
|
|||
|
|
@ -207,7 +207,7 @@ public class TangemCard {
|
|||
}
|
||||
|
||||
// TODO разобраться с балансами, привести к единому интерфейсу
|
||||
public Long InternalUnitsFromString(String caption) {
|
||||
public Long internalUnitsFromString(String caption) {
|
||||
try {
|
||||
return FormatUtil.ConvertStringToLong(caption);
|
||||
} catch (Exception e) {
|
||||
|
|
|
|||
|
|
@ -113,8 +113,8 @@ public class TokenEngine extends CoinEngine {
|
|||
return output;
|
||||
}
|
||||
|
||||
public BigDecimal GetBalanceAlterValueBigDecimal(TangemCard mCard) {
|
||||
String dec = mCard.getDecimalBalanceAlter();
|
||||
public BigDecimal getBalanceAlterValueBigDecimal(TangemCard card) {
|
||||
String dec = card.getDecimalBalanceAlter();
|
||||
BigDecimal d = convertToEth(dec);
|
||||
// String s = d.toString();
|
||||
|
||||
|
|
@ -271,9 +271,9 @@ public class TokenEngine extends CoinEngine {
|
|||
return EthEngine.getAmountEquivalentDescriptionETH(d, mCard.getRate());
|
||||
}
|
||||
|
||||
public String GetFeeEqualentDescriptor(TangemCard mCard, String value) {
|
||||
public String getFeeEquivalentDescriptor(TangemCard card, String value) {
|
||||
BigDecimal d = new BigDecimal(value);
|
||||
return EthEngine.getAmountEquivalentDescriptionETH(d, mCard.getRateAlter());
|
||||
return EthEngine.getAmountEquivalentDescriptionETH(d, card.getRateAlter());
|
||||
}
|
||||
|
||||
public Uri getShareWalletUriExplorer(TangemCard mCard) {
|
||||
|
|
@ -288,12 +288,12 @@ public class TokenEngine extends CoinEngine {
|
|||
return true;
|
||||
}
|
||||
|
||||
public boolean checkAmountValue(TangemCard mCard, String amountValue, String feeValue, Long minFeeInInternalUnits) {
|
||||
Long fee = null;
|
||||
BigDecimal amount = null;
|
||||
public boolean checkAmountValue(TangemCard card, String amountValue, String feeValue, Long minFeeInInternalUnits) {
|
||||
Long fee;
|
||||
BigDecimal amount;
|
||||
try {
|
||||
amount = GetBalanceAlterValueBigDecimal(mCard);//mCard.InternalUnitsFromString(amountValue);
|
||||
fee = mCard.InternalUnitsFromString(feeValue);
|
||||
amount = getBalanceAlterValueBigDecimal(card);//card.internalUnitsFromString(amountValue);
|
||||
fee = card.internalUnitsFromString(feeValue);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
|
|
@ -324,7 +324,7 @@ public class TokenEngine extends CoinEngine {
|
|||
BigDecimal gweFee = new BigDecimal(fee);
|
||||
gweFee = gweFee.divide(new BigDecimal("1000000000"));
|
||||
gweFee = gweFee.setScale(18, RoundingMode.DOWN);
|
||||
return GetFeeEqualentDescriptor(mCard, gweFee.toString());
|
||||
return getFeeEquivalentDescriptor(mCard, gweFee.toString());
|
||||
}
|
||||
|
||||
public byte[] sign(String feeValue, String amountValue, String toValue, TangemCard mCard, CardProtocol protocol) throws Exception {
|
||||
|
|
|
|||
|
|
@ -14,12 +14,11 @@ import android.util.Log
|
|||
import android.view.KeyEvent
|
||||
import android.view.View
|
||||
import android.widget.*
|
||||
import com.tangem.data.network.ServerApiHelper
|
||||
import com.tangem.data.network.request.ElectrumRequest
|
||||
import com.tangem.data.network.request.FeeRequest
|
||||
import com.tangem.data.network.request.InfuraRequest
|
||||
import com.tangem.data.network.task.confirm_payment.ConnectFeeTask
|
||||
import com.tangem.data.network.task.confirm_payment.ConnectTask
|
||||
import com.tangem.data.network.task.confirm_payment.ETHRequestTask
|
||||
import com.tangem.domain.cardReader.NfcManager
|
||||
import com.tangem.domain.wallet.*
|
||||
import com.tangem.util.BTCUtils
|
||||
|
|
@ -39,18 +38,16 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
}
|
||||
|
||||
private var nfcManager: NfcManager? = null
|
||||
private var serverApiHelper: ServerApiHelper? = null
|
||||
var card: TangemCard? = null
|
||||
|
||||
var feeRequestSuccess = false
|
||||
var balanceRequestSuccess = false
|
||||
|
||||
private var tvFeeEquivalent: TextView? = null
|
||||
var etAmount: EditText? = null
|
||||
var etFee: EditText? = null
|
||||
var rgFee: RadioGroup? = null
|
||||
var progressBar: ProgressBar? = null
|
||||
var btnSend: Button? = null
|
||||
|
||||
var minFee: String? = null
|
||||
var maxFee: String? = null
|
||||
var normalFee: String? = null
|
||||
|
|
@ -67,6 +64,8 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
|
||||
nfcManager = NfcManager(this, this)
|
||||
|
||||
serverApiHelper = ServerApiHelper()
|
||||
|
||||
card = TangemCard(intent.getStringExtra("UID"))
|
||||
card!!.loadFromBundle(intent.extras!!.getBundle("Card"))
|
||||
|
||||
|
|
@ -98,6 +97,42 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
feeRequestSuccess = false
|
||||
balanceRequestSuccess = false
|
||||
|
||||
if (card!!.blockchain == Blockchain.Ethereum || card!!.blockchain == Blockchain.EthereumTestNet || card!!.blockchain == Blockchain.Token) {
|
||||
rgFee!!.isEnabled = false
|
||||
serverApiHelper!!.infuraEthGasPrice("eth_gasPrice", 67)
|
||||
|
||||
} else {
|
||||
rgFee!!.isEnabled = true
|
||||
val data = SharedData(SharedData.COUNT_REQUEST)
|
||||
val engineCoin = CoinEngineFactory.create(card!!.blockchain)
|
||||
|
||||
for (i in 0 until data.allRequest) {
|
||||
val nodeAddress = engineCoin!!.getNextNode(card)
|
||||
val nodePort = engineCoin.getNextNodePort(card)
|
||||
val connectTaskEx = ConnectTask(this@ConfirmPaymentActivity, nodeAddress, nodePort, data)
|
||||
connectTaskEx.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, ElectrumRequest.checkBalance(card!!.wallet))
|
||||
}
|
||||
|
||||
var calcSize = 256
|
||||
try {
|
||||
calcSize = buildSize(etWallet!!.text.toString(), "0.00", etAmount!!.text.toString())
|
||||
} catch (ex: Exception) {
|
||||
Log.e("Build Fee error", ex.message)
|
||||
}
|
||||
|
||||
card!!.resetFailedBalanceRequestCounter()
|
||||
val sharedFee = SharedData(SharedData.COUNT_REQUEST)
|
||||
|
||||
progressBar!!.visibility = View.VISIBLE
|
||||
for (i in 0 until SharedData.COUNT_REQUEST) {
|
||||
val feeTask = ConnectFeeTask(this@ConfirmPaymentActivity, sharedFee)
|
||||
feeTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR,
|
||||
FeeRequest.GetFee(card!!.wallet, calcSize.toLong(), FeeRequest.NORMAL),
|
||||
FeeRequest.GetFee(card!!.wallet, calcSize.toLong(), FeeRequest.MINIMAL),
|
||||
FeeRequest.GetFee(card!!.wallet, calcSize.toLong(), FeeRequest.PRIORITY))
|
||||
}
|
||||
}
|
||||
|
||||
// set listeners
|
||||
rgFee!!.setOnCheckedChangeListener { _, checkedId -> doSetFee(checkedId) }
|
||||
etFee!!.addTextChangedListener(object : TextWatcher {
|
||||
|
|
@ -171,44 +206,27 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
startActivityForResult(intent, REQUEST_CODE_REQUEST_PIN2)
|
||||
}
|
||||
|
||||
if (card!!.blockchain == Blockchain.Ethereum || card!!.blockchain == Blockchain.EthereumTestNet || card!!.blockchain == Blockchain.Token) {
|
||||
val task = ETHRequestTask(this@ConfirmPaymentActivity, card!!.blockchain)
|
||||
val req = InfuraRequest.GetGasPrise(card!!.wallet)
|
||||
req.id = 67
|
||||
req.setBlockchain(card!!.blockchain)
|
||||
rgFee!!.isEnabled = false
|
||||
task.execute(req)
|
||||
// request eth gas price listener
|
||||
serverApiHelper!!.setInfuraEthGasPrice {
|
||||
var gasPrice = it.result
|
||||
gasPrice = gasPrice.substring(2)
|
||||
var l = BigInteger(gasPrice, 16)
|
||||
val m = if (card!!.blockchain == Blockchain.Token) BigInteger.valueOf(55000) else BigInteger.valueOf(21000)
|
||||
l = l.multiply(m)
|
||||
val feeInGwei = card!!.getAmountInGwei(l.toString())
|
||||
|
||||
} else {
|
||||
rgFee!!.isEnabled = true
|
||||
val data = SharedData(SharedData.COUNT_REQUEST)
|
||||
val engineCoin = CoinEngineFactory.create(card!!.blockchain)
|
||||
minFee = feeInGwei
|
||||
maxFee = feeInGwei
|
||||
normalFee = feeInGwei
|
||||
etFee!!.setText(feeInGwei)
|
||||
etFee!!.error = null
|
||||
btnSend!!.visibility = View.VISIBLE
|
||||
feeRequestSuccess = true
|
||||
balanceRequestSuccess = true
|
||||
dtVerified = Date()
|
||||
minFeeInInternalUnits = card!!.internalUnitsFromString(feeInGwei)
|
||||
|
||||
for (i in 0 until data.allRequest) {
|
||||
val nodeAddress = engineCoin!!.getNextNode(card)
|
||||
val nodePort = engineCoin.getNextNodePort(card)
|
||||
val connectTaskEx = ConnectTask(this@ConfirmPaymentActivity, nodeAddress, nodePort, data)
|
||||
connectTaskEx.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, ElectrumRequest.checkBalance(card!!.wallet))
|
||||
}
|
||||
|
||||
var calcSize = 256
|
||||
try {
|
||||
calcSize = buildSize(etWallet!!.text.toString(), "0.00", etAmount!!.text.toString())
|
||||
} catch (ex: Exception) {
|
||||
Log.e("Build Fee error", ex.message)
|
||||
}
|
||||
|
||||
card!!.resetFailedBalanceRequestCounter()
|
||||
val sharedFee = SharedData(SharedData.COUNT_REQUEST)
|
||||
|
||||
progressBar!!.visibility = View.VISIBLE
|
||||
for (i in 0 until SharedData.COUNT_REQUEST) {
|
||||
val feeTask = ConnectFeeTask(this@ConfirmPaymentActivity, sharedFee)
|
||||
feeTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR,
|
||||
FeeRequest.GetFee(card!!.wallet, calcSize.toLong(), FeeRequest.NORMAL),
|
||||
FeeRequest.GetFee(card!!.wallet, calcSize.toLong(), FeeRequest.MINIMAL),
|
||||
FeeRequest.GetFee(card!!.wallet, calcSize.toLong(), FeeRequest.PRIORITY))
|
||||
}
|
||||
// Log.i("eth_gas_price", feeInGwei)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -72,11 +72,12 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
sp = PreferenceManager.getDefaultSharedPreferences(activity)
|
||||
nfcManager = NfcManager(activity, this)
|
||||
|
||||
serverApiHelper = ServerApiHelper()
|
||||
|
||||
sp = PreferenceManager.getDefaultSharedPreferences(activity)
|
||||
|
||||
card = TangemCard(activity!!.intent.getStringExtra(TangemCard.EXTRA_CARD))
|
||||
card!!.loadFromBundle(activity!!.intent.extras.getBundle(TangemCard.EXTRA_CARD))
|
||||
|
||||
|
|
@ -171,8 +172,6 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
}
|
||||
}
|
||||
|
||||
// serverApiHelper!!.infura("eth_gasPrice", 67)
|
||||
|
||||
// request card verify listener
|
||||
serverApiHelper!!.setCardVerify {
|
||||
card!!.isOnlineVerified = it.results!![0].passed
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue