Updated on 2026-08-14
This commit is contained in:
parent
90636a0e6a
commit
cfaaa3205f
13 changed files with 98 additions and 47 deletions
|
|
@ -46,20 +46,22 @@ public class ETHRequestTask extends InfuraTask {
|
|||
|
||||
BigInteger m = confirmPaymentActivity.getCard().getBlockchain() == Blockchain.Token ? BigInteger.valueOf(55000) : BigInteger.valueOf(21000);
|
||||
l = l.multiply(m);
|
||||
String feeInGwei = confirmPaymentActivity.getCard().getAmountInGwei(String.valueOf(l));
|
||||
String MinFeeInGwei = confirmPaymentActivity.getCard().getAmountInGwei(String.valueOf(l));
|
||||
String NormalFeeInGwei = confirmPaymentActivity.getCard().getAmountInGwei(String.valueOf(l.multiply(BigInteger.valueOf(12)).divide(BigInteger.valueOf(10))));
|
||||
String MaxFeeInGwei = confirmPaymentActivity.getCard().getAmountInGwei(String.valueOf(l.multiply(BigInteger.valueOf(15)).divide(BigInteger.valueOf(10))));
|
||||
|
||||
Log.i("sjjoefeff", feeInGwei);
|
||||
Log.i("sjjoefeff", MinFeeInGwei);
|
||||
|
||||
confirmPaymentActivity.setMinFee(feeInGwei);
|
||||
confirmPaymentActivity.setMaxFee(feeInGwei);
|
||||
confirmPaymentActivity.setNormalFee(feeInGwei);
|
||||
confirmPaymentActivity.getEtFee().setText(feeInGwei);
|
||||
confirmPaymentActivity.setMinFee(MinFeeInGwei);
|
||||
confirmPaymentActivity.setNormalFee(NormalFeeInGwei);
|
||||
confirmPaymentActivity.setMaxFee(MaxFeeInGwei);
|
||||
confirmPaymentActivity.getEtFee().setText(NormalFeeInGwei);
|
||||
confirmPaymentActivity.getEtFee().setError(null);
|
||||
confirmPaymentActivity.getBtnSend().setVisibility(View.VISIBLE);
|
||||
confirmPaymentActivity.setFeeRequestSuccess(true);
|
||||
confirmPaymentActivity.setBalanceRequestSuccess(true);
|
||||
confirmPaymentActivity.setDtVerified(new Date());
|
||||
confirmPaymentActivity.setMinFeeInInternalUnits(confirmPaymentActivity.getCard().InternalUnitsFromString(feeInGwei));
|
||||
confirmPaymentActivity.setMinFeeInInternalUnits(confirmPaymentActivity.getCard().InternalUnitsFromString(NormalFeeInGwei));
|
||||
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
|
|
|
|||
|
|
@ -20,10 +20,12 @@ public class SignPaymentTask extends Thread {
|
|||
|
||||
private String txAmount = "";
|
||||
private String txFee = "";
|
||||
private Boolean txIncFee = true;
|
||||
|
||||
public void SetTransactionValue(String amount, String fee) {
|
||||
public void SetTransactionValue(String amount, String fee, Boolean incfee) {
|
||||
txAmount = amount;
|
||||
txFee = fee;
|
||||
txIncFee = incfee;
|
||||
}
|
||||
|
||||
private String txOutAddress;
|
||||
|
|
@ -34,14 +36,14 @@ public class SignPaymentTask extends Thread {
|
|||
private CardProtocol.Notifications mNotifications;
|
||||
private boolean isCancelled = false;
|
||||
|
||||
public SignPaymentTask(Activity context, TangemCard card, NfcManager nfcManager, IsoDep isoDep, CardProtocol.Notifications notifications, String amount, String fee, String outAddress) {
|
||||
public SignPaymentTask(Activity context, TangemCard card, NfcManager nfcManager, IsoDep isoDep, CardProtocol.Notifications notifications, String amount, String fee, Boolean IncFee, String outAddress) {
|
||||
mCard = card;
|
||||
mContext = context;
|
||||
mNfcManager = nfcManager;
|
||||
mIsoDep = isoDep;
|
||||
mNotifications = notifications;
|
||||
txOutAddress = outAddress;
|
||||
SetTransactionValue(amount, fee);
|
||||
SetTransactionValue(amount, fee, IncFee);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -90,7 +92,7 @@ public class SignPaymentTask extends Thread {
|
|||
|
||||
byte[] tx;
|
||||
// try {
|
||||
tx = engine.sign(txFee, txAmount, txOutAddress, mCard, protocol);
|
||||
tx = engine.sign(txFee, txAmount, txIncFee, txOutAddress, mCard, protocol);
|
||||
// }
|
||||
// finally {
|
||||
// mNotifications.onReadWait(0);
|
||||
|
|
|
|||
|
|
@ -311,7 +311,7 @@ public class BtcCashEngine extends CoinEngine {
|
|||
return getAmountEquivalentDescriptionBTC(Double.parseDouble(value) / 1000.0, mCard.getRate());
|
||||
}
|
||||
|
||||
public byte[] sign(String feeValue, String amountValue, String toValue, TangemCard mCard, CardProtocol protocol) throws Exception {
|
||||
public byte[] sign(String feeValue, String amountValue, boolean IncFee, String toValue, TangemCard mCard, CardProtocol protocol) throws Exception {
|
||||
|
||||
String myAddress = mCard.getWallet();
|
||||
byte[] pbKey = mCard.getWalletPublicKeyRar(); //ALWAYS USING COMPRESS KEY
|
||||
|
|
@ -333,9 +333,12 @@ public class BtcCashEngine extends CoinEngine {
|
|||
|
||||
long fees = FormatUtil.ConvertStringToLong(feeValue);
|
||||
long amount = FormatUtil.ConvertStringToLong(amountValue);
|
||||
amount = amount - fees;
|
||||
|
||||
long change = fullAmount - fees - amount;
|
||||
long change = fullAmount - amount;
|
||||
if (IncFee) {
|
||||
amount = amount - fees;
|
||||
} else {
|
||||
change = change - fees;
|
||||
}
|
||||
|
||||
if (amount + fees > fullAmount) {
|
||||
throw new Exception(String.format("Balance (%d) < amount (%d) + (%d)", fullAmount, change, amount));
|
||||
|
|
|
|||
|
|
@ -468,7 +468,7 @@ public class BtcEngine extends CoinEngine {
|
|||
return getAmountEquivalentDescriptionBTC(Double.parseDouble(value) / 1000.0, mCard.getRate());
|
||||
}
|
||||
|
||||
public byte[] sign(String feeValue, String amountValue, String toValue, TangemCard mCard, CardProtocol protocol) throws Exception {
|
||||
public byte[] sign(String feeValue, String amountValue, boolean IncFee, String toValue, TangemCard mCard, CardProtocol protocol) throws Exception {
|
||||
|
||||
String myAddress = mCard.getWallet();
|
||||
byte[] pbKey = mCard.getWalletPublicKey();
|
||||
|
|
@ -490,9 +490,12 @@ public class BtcEngine extends CoinEngine {
|
|||
|
||||
long fees = FormatUtil.ConvertStringToLong(feeValue);
|
||||
long amount = FormatUtil.ConvertStringToLong(amountValue);
|
||||
amount = amount - fees;
|
||||
|
||||
long change = fullAmount - fees - amount;
|
||||
long change = fullAmount - amount;
|
||||
if (IncFee) {
|
||||
amount = amount - fees;
|
||||
} else {
|
||||
change = change - fees;
|
||||
}
|
||||
|
||||
if (amount + fees > fullAmount) {
|
||||
throw new Exception(String.format("Balance (%d) < amount (%d) + (%d)", fullAmount, change, amount));
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ public abstract class CoinEngine {
|
|||
|
||||
public abstract String getContractAddress(TangemCard card);
|
||||
|
||||
public abstract byte[] sign(String feeValue, String amountValue, String toValue, TangemCard mCard, CardProtocol protocol) throws Exception;
|
||||
public abstract byte[] sign(String feeValue, String amountValue, boolean IncFee, String toValue, TangemCard mCard, CardProtocol protocol) throws Exception;
|
||||
|
||||
public abstract boolean checkUnspentTransaction(TangemCard card);
|
||||
|
||||
|
|
|
|||
|
|
@ -227,7 +227,11 @@ public class EthEngine extends CoinEngine {
|
|||
}
|
||||
|
||||
public Uri getShareWalletUri(TangemCard mCard) {
|
||||
return Uri.parse("" + mCard.getWallet());
|
||||
if (mCard.getDenomination() != null) {
|
||||
return Uri.parse("ethereum:" + mCard.getWallet());// + "?value=" + mCard.getDenomination() +"e18");
|
||||
} else {
|
||||
return Uri.parse("ethereum:" + mCard.getWallet());
|
||||
}
|
||||
}
|
||||
|
||||
public Uri getShareWalletUriExplorer(TangemCard mCard) {
|
||||
|
|
@ -303,7 +307,7 @@ public class EthEngine extends CoinEngine {
|
|||
return String.format("0x%s", BTCUtils.toHex(address));
|
||||
}
|
||||
|
||||
public byte[] sign(String feeValue, String amountValue, String toValue, TangemCard mCard, CardProtocol protocol) throws Exception {
|
||||
public byte[] sign(String feeValue, String amountValue, boolean IncFee, String toValue, TangemCard mCard, CardProtocol protocol) throws Exception {
|
||||
|
||||
BigInteger nonceValue = mCard.GetConfirmTXCount();
|
||||
byte[] pbKey = mCard.getWalletPublicKey();
|
||||
|
|
@ -318,7 +322,9 @@ public class EthEngine extends CoinEngine {
|
|||
|
||||
|
||||
BigInteger amount = amountDec.toBigInteger(); //new BigInteger(amountValue, 10);
|
||||
amount = amount.subtract(fee);
|
||||
if (IncFee) {
|
||||
amount = amount.subtract(fee);
|
||||
}
|
||||
|
||||
BigInteger nonce = nonceValue;
|
||||
BigInteger gasPrice = fee.divide(BigInteger.valueOf(21000));
|
||||
|
|
|
|||
|
|
@ -281,7 +281,11 @@ public class TokenEngine extends CoinEngine {
|
|||
}
|
||||
|
||||
public Uri getShareWalletUri(TangemCard mCard) {
|
||||
return Uri.parse("" + mCard.getWallet());
|
||||
if (mCard.getDenomination() != null) {
|
||||
return Uri.parse("ethereum:" + mCard.getWallet());// + "?value=" + mCard.getDenomination() +"e18");
|
||||
} else {
|
||||
return Uri.parse("ethereum:" + mCard.getWallet());
|
||||
}
|
||||
}
|
||||
|
||||
public boolean checkUnspentTransaction(TangemCard mCard) {
|
||||
|
|
@ -327,7 +331,7 @@ public class TokenEngine extends CoinEngine {
|
|||
return GetFeeEqualentDescriptor(mCard, gweFee.toString());
|
||||
}
|
||||
|
||||
public byte[] sign(String feeValue, String amountValue, String toValue, TangemCard mCard, CardProtocol protocol) throws Exception {
|
||||
public byte[] sign(String feeValue, String amountValue, boolean IncFee, String toValue, TangemCard mCard, CardProtocol protocol) throws Exception {
|
||||
|
||||
BigInteger nonceValue = mCard.GetConfirmTXCount();
|
||||
byte[] pbKey = mCard.getWalletPublicKey();
|
||||
|
|
|
|||
|
|
@ -75,7 +75,6 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
etAmount = findViewById(R.id.etAmount)
|
||||
etFee = findViewById(R.id.etFee)
|
||||
tvFeeEquivalent = findViewById(R.id.tvFeeEquivalent)
|
||||
rgFee = findViewById(R.id.rgFee)
|
||||
|
||||
val engine = CoinEngineFactory.create(card!!.blockchain)
|
||||
if (card!!.blockchain == Blockchain.Token) {
|
||||
|
|
@ -84,6 +83,12 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
} else
|
||||
tvBalance.text = engine!!.getBalanceWithAlter(card)
|
||||
|
||||
if(intent.getBooleanExtra("IncFee", true)) {
|
||||
tvIncFee!!.setText(R.string.feein);
|
||||
} else {
|
||||
tvIncFee!!.setText(R.string.feeout);
|
||||
}
|
||||
|
||||
etAmount!!.setText(intent.getStringExtra(SignPaymentActivity.EXTRA_AMOUNT))
|
||||
tvCurrency.text = engine.getBalanceCurrency(card)
|
||||
tvCurrency2.text = engine.feeCurrency
|
||||
|
|
@ -176,7 +181,7 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
val req = InfuraRequest.GetGasPrise(card!!.wallet)
|
||||
req.id = 67
|
||||
req.setBlockchain(card!!.blockchain)
|
||||
rgFee!!.isEnabled = false
|
||||
rgFee!!.isEnabled = true
|
||||
task.execute(req)
|
||||
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import android.support.v7.app.AppCompatActivity
|
|||
import android.text.Html
|
||||
import android.text.InputFilter
|
||||
import android.util.Log
|
||||
import android.view.View
|
||||
import android.widget.Toast
|
||||
import com.tangem.domain.cardReader.NfcManager
|
||||
import com.tangem.domain.wallet.Blockchain
|
||||
|
|
@ -52,8 +53,11 @@ class PreparePaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
if (card!!.blockchain == Blockchain.Token) {
|
||||
val html = Html.fromHtml(engine!!.getBalanceWithAlter(card))
|
||||
tvBalance.text = html
|
||||
} else
|
||||
rgIncFee!!.visibility = View.INVISIBLE
|
||||
} else {
|
||||
tvBalance.text = engine!!.getBalanceWithAlter(card)
|
||||
rgIncFee!!.visibility = View.VISIBLE
|
||||
}
|
||||
|
||||
if (card!!.remainingSignatures < 2)
|
||||
etAmount.isEnabled = false
|
||||
|
|
@ -80,11 +84,7 @@ class PreparePaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
tvCurrency.text = "m" + card!!.blockchain.currency
|
||||
useCurrency = true
|
||||
val output = FormatUtil.DoubleToString(balance)
|
||||
etAmount.setText(output)
|
||||
}
|
||||
|
||||
// Default
|
||||
else {
|
||||
} else {
|
||||
tvCurrency.text = engine.getBalanceCurrency(card)
|
||||
useCurrency = false
|
||||
etAmount.setText(engine.getBalanceValue(card))
|
||||
|
|
@ -137,6 +137,7 @@ class PreparePaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
intent.putExtra("UID", card!!.uid)
|
||||
intent.putExtra("Card", card!!.asBundle)
|
||||
intent.putExtra("Wallet", etWallet!!.text.toString())
|
||||
intent.putExtra("IncFee", (rgIncFee!!.checkedRadioButtonId == R.id.rbFeeIn))
|
||||
intent.putExtra(SignPaymentActivity.EXTRA_AMOUNT, strAmount)
|
||||
startActivityForResult(intent, REQUEST_CODE_SEND_PAYMENT)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ class SignPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, Card
|
|||
|
||||
private var amountStr: String? = null
|
||||
private var feeStr: String? = null
|
||||
private var incfeeBool = true
|
||||
private var outAddressStr: String? = null
|
||||
private var lastReadSuccess = true
|
||||
|
||||
|
|
@ -58,6 +59,7 @@ class SignPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, Card
|
|||
|
||||
amountStr = intent.getStringExtra(EXTRA_AMOUNT)
|
||||
feeStr = intent.getStringExtra("Fee")
|
||||
incfeeBool = intent.getBooleanExtra("IncFee", true)
|
||||
outAddressStr = intent.getStringExtra("Wallet")
|
||||
|
||||
tvCardID.text = card!!.cidDescription
|
||||
|
|
@ -82,7 +84,7 @@ class SignPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, Card
|
|||
} else {
|
||||
isoDep.timeout = card!!.pauseBeforePIN2 + 65000
|
||||
}
|
||||
signPaymentTask = SignPaymentTask(this, card, nfcManager, isoDep, this, amountStr, feeStr, outAddressStr)
|
||||
signPaymentTask = SignPaymentTask(this, card, nfcManager, isoDep, this, amountStr, feeStr,incfeeBool, outAddressStr)
|
||||
signPaymentTask!!.start()
|
||||
} else {
|
||||
// Log.d(TAG, "Mismatch card UID (" + sUID + " instead of " + card!!.uid + ")")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue