Updated on 2026-08-14
This commit is contained in:
commit
222be205ec
12 changed files with 90 additions and 38 deletions
|
|
@ -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 getFeeEquivalentDescriptor(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();
|
||||
|
|
|
|||
|
|
@ -17,8 +17,10 @@ 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
|
||||
|
|
@ -81,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
|
||||
|
|
|
|||
|
|
@ -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 + ")")
|
||||
|
|
|
|||
|
|
@ -129,7 +129,7 @@
|
|||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView12"
|
||||
android:id="@+id/tvIncFee"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="1dp"
|
||||
|
|
|
|||
|
|
@ -170,18 +170,6 @@
|
|||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView13"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="1dp"
|
||||
android:layout_marginStart="4dp"
|
||||
android:fontFamily="@font/maax"
|
||||
android:text="@string/including_fee"
|
||||
android:textColor="@color/primary"
|
||||
android:textSize="@dimen/text_size_1_small"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/textView3"
|
||||
app:layout_constraintLeft_toRightOf="@+id/textView3"/>
|
||||
</android.support.constraint.ConstraintLayout>
|
||||
|
||||
<android.support.constraint.ConstraintLayout
|
||||
|
|
@ -221,6 +209,39 @@
|
|||
|
||||
</android.support.constraint.ConstraintLayout>
|
||||
|
||||
<info.hoang8f.android.segmented.SegmentedGroup
|
||||
android:id="@+id/rgIncFee"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="10dp"
|
||||
android:checkedButton="@+id/rbFeeIn"
|
||||
android:gravity="center"
|
||||
android:orientation="horizontal"
|
||||
app:sc_border_width="2dp"
|
||||
app:sc_corner_radius="10dp"
|
||||
app:sc_tint_color="@color/colorPrimary"
|
||||
tools:layout_editor_absoluteX="10dp">
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/rbFeeIn"
|
||||
style="@style/RadioButton"
|
||||
android:layout_width="150dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:fontFamily="@font/saira_condensed_bold"
|
||||
android:text="@string/feein"
|
||||
android:textSize="@dimen/text_size_medium" />
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/rbFeeOut"
|
||||
style="@style/RadioButton"
|
||||
android:layout_width="150dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:fontFamily="@font/saira_condensed_bold"
|
||||
android:text="@string/feeout"
|
||||
android:textSize="@dimen/text_size_medium" />
|
||||
|
||||
</info.hoang8f.android.segmented.SegmentedGroup>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<android.support.v7.widget.AppCompatButton
|
||||
|
|
|
|||
|
|
@ -164,6 +164,8 @@
|
|||
<string name="minimal">Minimal</string>
|
||||
<string name="normal">Normal</string>
|
||||
<string name="priority">Priority</string>
|
||||
<string name="feein">Including fee</string>
|
||||
<string name="feeout">Not including fee</string>
|
||||
<string name="the_obtained_data_is_outdated_try_again">The obtained data is outdated! Try again</string>
|
||||
<string name="cannot_reach_current_active_blockchain_node_try_again">Cannot reach current active blockchain node. Try again</string>
|
||||
<string name="cannot_check_balance_no_connection_with_blockchain_nodes">Cannot check balance! No connection with blockchain nodes</string>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue