Updated on 2026-08-14
This commit is contained in:
parent
47d731ffe2
commit
d6a2d677ee
8 changed files with 50 additions and 60 deletions
|
|
@ -9,7 +9,6 @@ import com.tangem.util.BTCUtils;
|
|||
import com.tangem.util.CryptoUtil;
|
||||
import com.tangem.util.DecimalDigitsInputFilter;
|
||||
import com.tangem.util.DerEncodingUtil;
|
||||
import com.tangem.util.FormatUtil;
|
||||
import com.tangem.util.Util;
|
||||
import com.tangem.wallet.R;
|
||||
|
||||
|
|
@ -194,7 +193,7 @@ public class BtcCashEngine extends CoinEngine {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean checkNewTransactionAmountAndFee(Amount amountValue, Amount feeValue, Boolean isIncludeFee, InternalAmount minFeeInInternalUnits) {
|
||||
public boolean checkNewTransactionAmountAndFee(Amount amountValue, Amount feeValue, Boolean isIncludeFee) {
|
||||
InternalAmount fee;
|
||||
InternalAmount amount;
|
||||
|
||||
|
|
@ -308,7 +307,9 @@ public class BtcCashEngine extends CoinEngine {
|
|||
@Override
|
||||
public String getBalanceEquivalent() {
|
||||
if (coinData == null || !coinData.getAmountEquivalentDescriptionAvailable()) return "";
|
||||
return getBalance().toEquivalentString(coinData.getRate());
|
||||
Amount balance=getBalance();
|
||||
if( balance==null ) return "";
|
||||
return balance.toEquivalentString(coinData.getRate());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -3,15 +3,12 @@ package com.tangem.domain.wallet;
|
|||
import android.net.Uri;
|
||||
import android.text.InputFilter;
|
||||
|
||||
import com.tangem.domain.BitcoinNode;
|
||||
import com.tangem.domain.BitcoinNodeTestNet;
|
||||
import com.tangem.domain.cardReader.CardProtocol;
|
||||
import com.tangem.domain.cardReader.TLV;
|
||||
import com.tangem.util.BTCUtils;
|
||||
import com.tangem.util.CryptoUtil;
|
||||
import com.tangem.util.DecimalDigitsInputFilter;
|
||||
import com.tangem.util.DerEncodingUtil;
|
||||
import com.tangem.util.FormatUtil;
|
||||
import com.tangem.util.Util;
|
||||
import com.tangem.wallet.R;
|
||||
|
||||
|
|
@ -199,7 +196,7 @@ public class BtcEngine extends CoinEngine {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean checkNewTransactionAmountAndFee(Amount amountValue, Amount feeValue, Boolean isIncludeFee, InternalAmount minFeeInInternalUnits) {
|
||||
public boolean checkNewTransactionAmountAndFee(Amount amountValue, Amount feeValue, Boolean isIncludeFee) {
|
||||
InternalAmount fee;
|
||||
InternalAmount amount;
|
||||
|
||||
|
|
@ -316,7 +313,9 @@ public class BtcEngine extends CoinEngine {
|
|||
@Override
|
||||
public String getBalanceEquivalent() {
|
||||
if( coinData ==null || !coinData.getAmountEquivalentDescriptionAvailable() ) return "";
|
||||
return getBalance().toEquivalentString(coinData.getRate());
|
||||
Amount balance=getBalance();
|
||||
if( balance==null ) return "";
|
||||
return balance.toEquivalentString(coinData.getRate());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -367,7 +366,7 @@ public class BtcEngine extends CoinEngine {
|
|||
@Override
|
||||
public InternalAmount convertToInternalAmount(Amount amount) throws Exception {
|
||||
BigDecimal d=amount.multiply(new BigDecimal("100000000"));
|
||||
return new InternalAmount(d, getBalanceCurrency());
|
||||
return new InternalAmount(d, "Satoshi");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -5,9 +5,6 @@ import android.text.InputFilter;
|
|||
|
||||
import com.tangem.domain.cardReader.CardProtocol;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.math.RoundingMode;
|
||||
|
|
@ -196,7 +193,7 @@ public abstract class CoinEngine {
|
|||
public abstract boolean checkNewTransactionAmount(Amount amount);
|
||||
|
||||
// TODO - move minFeeInInternalUnits to CoinData
|
||||
public abstract boolean checkNewTransactionAmountAndFee(Amount amount, Amount fee, Boolean isFeeIncluded, InternalAmount minFeeInInternalUnits);
|
||||
public abstract boolean checkNewTransactionAmountAndFee(Amount amount, Amount fee, Boolean isFeeIncluded);
|
||||
|
||||
public abstract boolean validateBalance(BalanceValidator balanceValidator);
|
||||
|
||||
|
|
|
|||
|
|
@ -175,7 +175,9 @@ public class EthEngine extends CoinEngine {
|
|||
|
||||
@Override
|
||||
public String getBalanceEquivalent() {
|
||||
return getBalance().toEquivalentString(coinData.getRate());
|
||||
Amount balance=getBalance();
|
||||
if( balance==null ) return "";
|
||||
return balance.toEquivalentString(coinData.getRate());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -258,7 +260,7 @@ public class EthEngine extends CoinEngine {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean checkNewTransactionAmountAndFee(Amount amount, Amount fee, Boolean isFeeIncluded, InternalAmount minFeeInInternalUnits) {
|
||||
public boolean checkNewTransactionAmountAndFee(Amount amount, Amount fee, Boolean isFeeIncluded) {
|
||||
// Long fee = null;
|
||||
// Long amount = null;
|
||||
// try {
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ public class TokenData extends EthData {
|
|||
public void loadFromBundle(Bundle B) {
|
||||
super.loadFromBundle(B);
|
||||
|
||||
balanceAlter = new CoinEngine.InternalAmount(B.getString("BalanceDecimalAlter"),"ETH");
|
||||
balanceAlter = new CoinEngine.InternalAmount(B.getString("BalanceDecimalAlter"),"wei");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -172,8 +172,10 @@ public class TokenEngine extends CoinEngine {
|
|||
}
|
||||
try {
|
||||
if (coinData.getBalanceInInternalUnits().notZero()) {
|
||||
return convertToAmount(coinData.getBalanceInInternalUnits()).toEquivalentString(coinData.getRate());
|
||||
// TODO: check why Rate=EthRate
|
||||
return "";//convertToAmount(coinData.getBalanceInInternalUnits()).toEquivalentString(coinData.getRate());
|
||||
} else {
|
||||
if( coinData.getBalanceAlterInInternalUnits()==null ) return "";
|
||||
return convertToAmount(coinData.getBalanceAlterInInternalUnits()).toEquivalentString(coinData.getRateAlter());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
|
@ -318,7 +320,7 @@ public class TokenEngine extends CoinEngine {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean checkNewTransactionAmountAndFee(Amount amount, Amount fee, Boolean isFeeIncluded, InternalAmount minFeeInInternalUnits) {
|
||||
public boolean checkNewTransactionAmountAndFee(Amount amount, Amount fee, Boolean isFeeIncluded) {
|
||||
if (!hasBalanceInfo()) return false;
|
||||
|
||||
try {
|
||||
|
|
@ -330,14 +332,8 @@ public class TokenEngine extends CoinEngine {
|
|||
|
||||
if (amount.getCurrency().equals(ctx.getCard().tokenSymbol)) {
|
||||
// token transaction
|
||||
//TODO ???
|
||||
// BigDecimal tmpFee = new BigDecimal(feeValue);
|
||||
// BigDecimal tmpAmount = amount;
|
||||
// tmpAmount = tmpAmount.multiply(new BigDecimal("1000000000"));
|
||||
//
|
||||
// if (tmpFee.compareTo(tmpAmount) > 0)
|
||||
// return false;
|
||||
|
||||
if( fee.compareTo(balance)>0 )
|
||||
return false;
|
||||
} else if (amount.getCurrency().equals("ETH") && coinData.getBalanceInInternalUnits().isZero()) {
|
||||
// standart ETH transaction
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ import org.json.JSONException
|
|||
import java.io.IOException
|
||||
import java.math.BigDecimal
|
||||
import java.math.BigInteger
|
||||
import java.math.RoundingMode
|
||||
import java.text.DecimalFormat
|
||||
import java.util.*
|
||||
|
||||
|
|
@ -48,7 +49,6 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
private var maxFee: CoinEngine.Amount? = null
|
||||
private var normalFee: CoinEngine.Amount? = null
|
||||
private var isIncludeFee: Boolean = true
|
||||
private var minFeeInInternalUnits: CoinEngine.InternalAmount? = CoinEngine.InternalAmount(0, "")
|
||||
private var requestPIN2Count = 0
|
||||
private var nodeCheck = false
|
||||
private var dtVerified: Date? = null
|
||||
|
|
@ -63,9 +63,7 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
nfcManager = NfcManager(this, this)
|
||||
|
||||
ctx = TangemContext.loadFromBundle(this, intent.extras)
|
||||
// card = TangemCard(intent.getStringExtra("UID"))
|
||||
// card!!.loadFromBundle(intent.extras!!.getBundle("Card"))
|
||||
//
|
||||
|
||||
val engine = CoinEngineFactory.create(ctx)
|
||||
|
||||
val html = Html.fromHtml(engine!!.balanceHTML)
|
||||
|
|
@ -82,7 +80,7 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
else
|
||||
tvIncFee.visibility = View.VISIBLE
|
||||
|
||||
val amount=CoinEngine.Amount(intent.getStringExtra(SignPaymentActivity.EXTRA_AMOUNT), intent.getStringExtra(SignPaymentActivity.EXTRA_AMOUNT_CURRENCY))
|
||||
val amount = CoinEngine.Amount(intent.getStringExtra(SignPaymentActivity.EXTRA_AMOUNT), intent.getStringExtra(SignPaymentActivity.EXTRA_AMOUNT_CURRENCY))
|
||||
etAmount.setText(amount.toValueString())
|
||||
tvCurrency.text = engine.balanceCurrency
|
||||
tvCurrency2.text = engine.feeCurrency
|
||||
|
|
@ -180,7 +178,7 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
return@setOnClickListener
|
||||
}
|
||||
|
||||
if (!engineCoin.checkNewTransactionAmountAndFee(txAmount, txFee, isIncludeFee, minFeeInInternalUnits)) {
|
||||
if (!engineCoin.checkNewTransactionAmountAndFee(txAmount, txFee, isIncludeFee)) {
|
||||
finishWithError(Activity.RESULT_CANCELED, getString(R.string.not_enough_funds_on_your_card))
|
||||
return@setOnClickListener
|
||||
}
|
||||
|
|
@ -198,7 +196,7 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
override fun onSuccess(electrumRequest: ElectrumRequest?) {
|
||||
if (electrumRequest!!.isMethod(ElectrumRequest.METHOD_GetBalance)) {
|
||||
try {
|
||||
etFee.setText(getString(R.string.empty))
|
||||
if( etFee.text.toString().isEmpty() ) etFee.setText(getString(R.string.empty))
|
||||
val engine = CoinEngineFactory.create(ctx)
|
||||
val balance = engine.convertToAmount(CoinEngine.InternalAmount(electrumRequest.result.getLong("confirmed") + electrumRequest.result.getLong("unconfirmed"), "Satoshi"))
|
||||
val amount = CoinEngine.Amount(etAmount.text.toString(), ctx.blockchain.currency)
|
||||
|
|
@ -253,7 +251,6 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
feeRequestSuccess = true
|
||||
balanceRequestSuccess = true
|
||||
dtVerified = Date()
|
||||
minFeeInInternalUnits = weiNormalFee // TODO why not weiMinFee ???
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -287,27 +284,24 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
|
||||
progressBar.visibility = View.INVISIBLE
|
||||
|
||||
val df = DecimalFormat()
|
||||
df.maximumFractionDigits = 7
|
||||
df.minimumFractionDigits = 3
|
||||
df.isGroupingUsed = false
|
||||
fee = fee!!.setScale(8, RoundingMode.DOWN)
|
||||
|
||||
when (blockCount) {
|
||||
ServerApiHelper.ESTIMATE_FEE_MINIMAL -> {
|
||||
minFee = CoinEngine.Amount(fee, engine.feeCurrency)
|
||||
minFeeInInternalUnits = engine.convertToInternalAmount(minFee)
|
||||
if (rgFee.checkedRadioButtonId == R.id.rbMinimalFee) doSetFee(rgFee.checkedRadioButtonId)
|
||||
}
|
||||
|
||||
ServerApiHelper.ESTIMATE_FEE_NORMAL -> {
|
||||
normalFee = CoinEngine.Amount(fee, engine.feeCurrency)
|
||||
|
||||
if (rgFee.checkedRadioButtonId == R.id.rbNormalFee) doSetFee(rgFee.checkedRadioButtonId)
|
||||
}
|
||||
|
||||
ServerApiHelper.ESTIMATE_FEE_PRIORITY -> {
|
||||
maxFee = CoinEngine.Amount(fee, engine.feeCurrency)
|
||||
if (rgFee.checkedRadioButtonId == R.id.rbMaximumFee) doSetFee(rgFee.checkedRadioButtonId)
|
||||
}
|
||||
}
|
||||
doSetFee(rgFee.checkedRadioButtonId)
|
||||
|
||||
etFee.error = null
|
||||
feeRequestSuccess = true
|
||||
|
|
@ -481,21 +475,22 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
}
|
||||
|
||||
private fun doSetFee(checkedRadioButtonId: Int) {
|
||||
Log.e("DEBUG", "doSetFee")
|
||||
var txtFee = ""
|
||||
when (checkedRadioButtonId) {
|
||||
R.id.rbMinimalFee ->
|
||||
if (minFee != null)
|
||||
txtFee = minFee.toString()
|
||||
txtFee = minFee!!.toValueString()
|
||||
else
|
||||
finishWithError(Activity.RESULT_CANCELED, getString(R.string.cannot_obtain_data_from_blockchain))
|
||||
R.id.rbNormalFee ->
|
||||
if (normalFee != null)
|
||||
txtFee = normalFee.toString()
|
||||
txtFee = normalFee!!.toValueString()
|
||||
else
|
||||
finishWithError(Activity.RESULT_CANCELED, getString(R.string.cannot_obtain_data_from_blockchain))
|
||||
R.id.rbMaximumFee ->
|
||||
if (maxFee != null)
|
||||
txtFee = maxFee.toString()
|
||||
txtFee = maxFee!!.toValueString()
|
||||
else
|
||||
finishWithError(Activity.RESULT_CANCELED, getString(R.string.cannot_obtain_data_from_blockchain))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -307,7 +307,7 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
(ctx.coinData!! as EthData).balanceInInternalUnits = CoinEngine.InternalAmount(l.toBigDecimal(),"wei")
|
||||
}else{
|
||||
(ctx.coinData!! as TokenData).isBalanceReceived = true
|
||||
(ctx.coinData!! as TokenData).balanceInInternalUnits = CoinEngine.InternalAmount(l.toBigDecimal(),ctx.card.tokenSymbol)
|
||||
//(ctx.coinData!! as TokenData).balanceInInternalUnits = CoinEngine.InternalAmount(l.toBigDecimal(),ctx.card.tokenSymbol)
|
||||
(ctx.coinData!! as TokenData).balanceAlterInInternalUnits = CoinEngine.InternalAmount(l.toBigDecimal(), "wei")
|
||||
}
|
||||
|
||||
|
|
@ -339,21 +339,21 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
balanceCap = balanceCap.substring(2)
|
||||
val l = BigInteger(balanceCap, 16)
|
||||
val balance = l.toLong()
|
||||
if (l.compareTo(BigInteger.ZERO) == 0) {
|
||||
ctx.card!!.blockchainID = Blockchain.Ethereum.id
|
||||
ctx.card!!.addTokenToBlockchainName()
|
||||
|
||||
//TODO check
|
||||
//ctx.blockchain=lBlockchain.Ethereum
|
||||
|
||||
requestCounter--
|
||||
if (requestCounter == 0) srl!!.isRefreshing = false
|
||||
|
||||
requestInfura(ServerApiHelper.INFURA_ETH_GET_BALANCE, "")
|
||||
requestInfura(ServerApiHelper.INFURA_ETH_GET_TRANSACTION_COUNT, "")
|
||||
requestInfura(ServerApiHelper.INFURA_ETH_GET_PENDING_COUNT, "")
|
||||
return
|
||||
}
|
||||
// if (l.compareTo(BigInteger.ZERO) == 0) {
|
||||
// //ctx.card!!.blockchainID = Blockchain.Ethereum.id
|
||||
// ctx.card!!.addTokenToBlockchainName()
|
||||
//
|
||||
// //TODO check
|
||||
// //ctx.blockchain=lBlockchain.Ethereum
|
||||
//
|
||||
// requestCounter--
|
||||
// if (requestCounter == 0) srl!!.isRefreshing = false
|
||||
//
|
||||
// requestInfura(ServerApiHelper.INFURA_ETH_GET_BALANCE, "")
|
||||
// requestInfura(ServerApiHelper.INFURA_ETH_GET_TRANSACTION_COUNT, "")
|
||||
// requestInfura(ServerApiHelper.INFURA_ETH_GET_PENDING_COUNT, "")
|
||||
// return
|
||||
// }
|
||||
(ctx.coinData!! as EthData).balanceInInternalUnits = CoinEngine.InternalAmount(l.toBigDecimal(),ctx.card.tokenSymbol)
|
||||
|
||||
// Log.i("$TAG eth_call", balanceCap)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue