Updated on 2026-08-14

This commit is contained in:
Tangem 2018-10-04 12:48:07 +03:00
parent e97c936c92
commit 573101570b
15 changed files with 65 additions and 92 deletions

View file

@ -16,7 +16,7 @@ android {
minSdkVersion 21
targetSdkVersion 27
versionCode 81
versionName "0.89.2." + generateVersionName()
versionName "0.810.1." + generateVersionName()
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
androidExtensions {

View file

@ -11,6 +11,7 @@ import com.tangem.presentation.activity.ConfirmPaymentActivity;
import java.lang.ref.WeakReference;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.text.DecimalFormat;
import java.util.Date;
import java.util.List;
@ -29,15 +30,11 @@ public class ConnectFeeTask extends FeeTask {
for (FeeRequest request : requests) {
if (request.error == null) {
long minFeeRate = 0;
BigDecimal Fee = BigDecimal.ZERO;
try {
try {
String tmpAnswer = request.getAsString();
BigDecimal minFeeBD = new BigDecimal(tmpAnswer);
BigDecimal multiplicator = new BigDecimal("100000000");
minFeeBD = minFeeBD.multiply(multiplicator);
BigInteger minFeeBI = minFeeBD.toBigInteger();
minFeeRate = minFeeBI.longValue();
Fee = new BigDecimal(tmpAnswer); // BTC per 1 kb
} catch (Exception e) {
if (sharedCounter != null) {
@ -57,7 +54,7 @@ public class ConnectFeeTask extends FeeTask {
return;
}
if (minFeeRate == 0) {
if (Fee.equals(BigDecimal.ZERO)) {
confirmPaymentActivity.getProgressBar().setVisibility(View.INVISIBLE);
confirmPaymentActivity.finishActivityWithError(Activity.RESULT_CANCELED, "Cannot calculate fee! Wrong data received from the node");
return;
@ -66,9 +63,9 @@ public class ConnectFeeTask extends FeeTask {
long inputCount = request.txSize;
if (inputCount != 0) {
minFeeRate = minFeeRate * inputCount;
Fee = Fee.multiply(new BigDecimal(inputCount)).divide(new BigDecimal(1024)); // per Kb -> per byte
} else {
minFeeRate = minFeeRate * 256;
confirmPaymentActivity.finishActivityWithError(Activity.RESULT_CANCELED, "Cannot calculate fee! Tx length unknown");
}
} catch (Exception e) {
e.printStackTrace();
@ -87,17 +84,19 @@ public class ConnectFeeTask extends FeeTask {
confirmPaymentActivity.getProgressBar().setVisibility(View.INVISIBLE);
float finalFee = (float) minFeeRate / (float) 10000;
finalFee = Math.round(finalFee) / (float) 10000;
DecimalFormat df = new DecimalFormat();
df.setMaximumFractionDigits(7);
df.setMinimumFractionDigits(3);
df.setGroupingUsed(false);
String strFee = df.format(Fee);
if ((request.getBlockCount() == FeeRequest.MINIMAL) && (confirmPaymentActivity.getMinFee() == null)) {
confirmPaymentActivity.setMinFee(String.valueOf(finalFee));
confirmPaymentActivity.setMinFeeInInternalUnits(confirmPaymentActivity.getCard().internalUnitsFromString(String.valueOf(finalFee)));
confirmPaymentActivity.setMinFee(strFee);
confirmPaymentActivity.setMinFeeInInternalUnits(confirmPaymentActivity.getCard().internalUnitsFromString(strFee));
} else if ((request.getBlockCount() == FeeRequest.NORMAL) && (confirmPaymentActivity.getNormalFee() == null)) {
confirmPaymentActivity.setNormalFee(String.valueOf(finalFee));
confirmPaymentActivity.setNormalFee(strFee);
} else if ((request.getBlockCount() == FeeRequest.PRIORITY) && (confirmPaymentActivity.getMaxFee() == null)) {
confirmPaymentActivity.setMaxFee(String.valueOf(finalFee));
confirmPaymentActivity.setMaxFee(strFee);
}
confirmPaymentActivity.doSetFee(confirmPaymentActivity.getRgFee().getCheckedRadioButtonId());

View file

@ -230,7 +230,7 @@ public class BtcCashEngine extends CoinEngine {
public String getBalanceValue(TangemCard mCard) {
if (mCard.hasBalanceInfo()) {
Double balance = mCard.getBalance() / (mCard.getBlockchain().getMultiplier() / 1000.0);
Double balance = mCard.getBalance() / (mCard.getBlockchain().getMultiplier());
String output = FormatUtil.DoubleToString(balance);
//String pattern = "#0.000"; // If you like 4 zeros
@ -283,7 +283,7 @@ public class BtcCashEngine extends CoinEngine {
public String convertByteArrayToAmount(TangemCard mCard, byte[] bytes) throws Exception {
byte[] reversed = new byte[bytes.length];
for (int i = 0; i < bytes.length; i++) reversed[i] = bytes[bytes.length - i - 1];
return FormatUtil.DoubleToString(1000.0 * mCard.AmountFromInternalUnits(Util.byteArrayToLong(reversed)));
return FormatUtil.DoubleToString(mCard.AmountFromInternalUnits(Util.byteArrayToLong(reversed)));
}
@Override
@ -296,7 +296,7 @@ public class BtcCashEngine extends CoinEngine {
@Override
public String getAmountDescription(TangemCard mCard, String amount) throws Exception {
return mCard.getAmountDescription(Double.parseDouble(amount) / 1000.0);
return mCard.getAmountDescription(Double.parseDouble(amount));
}
public static String getAmountEquivalentDescriptionBTC(Double amount, float rate) {
@ -308,7 +308,7 @@ public class BtcCashEngine extends CoinEngine {
}
public String getAmountEquivalentDescriptor(TangemCard mCard, String value) {
return getAmountEquivalentDescriptionBTC(Double.parseDouble(value) / 1000.0, mCard.getRate());
return getAmountEquivalentDescriptionBTC(Double.parseDouble(value), mCard.getRate());
}
public byte[] sign(String feeValue, String amountValue, boolean IncFee, String toValue, TangemCard mCard, CardProtocol protocol) throws Exception {

View file

@ -276,7 +276,7 @@ public class BtcEngine extends CoinEngine {
}
public String getBalanceCurrency(TangemCard card) {
return "mBTC";
return "BTC";
}
public boolean checkUnspentTransaction(TangemCard mCard) {
@ -284,7 +284,7 @@ public class BtcEngine extends CoinEngine {
}
public String getFeeCurrency() {
return "mBTC";
return "BTC";
}
public boolean validateAddress(String address, TangemCard card) {
@ -413,7 +413,7 @@ public class BtcEngine extends CoinEngine {
public String getBalanceValue(TangemCard mCard) {
if (mCard.hasBalanceInfo()) {
Double balance = mCard.getBalance() / (mCard.getBlockchain().getMultiplier() / 1000.0);
Double balance = mCard.getBalance() / (mCard.getBlockchain().getMultiplier());
String output = FormatUtil.DoubleToString(balance);
//String pattern = "#0.000"; // If you like 4 zeros
@ -467,7 +467,7 @@ public class BtcEngine extends CoinEngine {
if (bytes == null) return "";
byte[] reversed = new byte[bytes.length];
for (int i = 0; i < bytes.length; i++) reversed[i] = bytes[bytes.length - i - 1];
return FormatUtil.DoubleToString(1000.0 * mCard.AmountFromInternalUnits(Util.byteArrayToLong(reversed)));
return FormatUtil.DoubleToString(mCard.AmountFromInternalUnits(Util.byteArrayToLong(reversed)));
}
@Override
@ -480,7 +480,7 @@ public class BtcEngine extends CoinEngine {
@Override
public String getAmountDescription(TangemCard mCard, String amount) throws Exception {
return mCard.getAmountDescription(Double.parseDouble(amount) / 1000.0);
return mCard.getAmountDescription(Double.parseDouble(amount));
}
public static String getAmountEquivalentDescriptionBTC(Double amount, float rate) {
@ -492,7 +492,7 @@ public class BtcEngine extends CoinEngine {
}
public String getAmountEquivalentDescriptor(TangemCard mCard, String value) {
return getAmountEquivalentDescriptionBTC(Double.parseDouble(value) / 1000.0, mCard.getRate());
return getAmountEquivalentDescriptionBTC(Double.parseDouble(value), mCard.getRate());
}
public byte[] sign(String feeValue, String amountValue, boolean IncFee, String toValue, TangemCard mCard, CardProtocol protocol) throws Exception {

View file

@ -193,23 +193,8 @@ public class TangemCard {
}
public String getAmountDescription(Double amount) {
if (amount < 10) {
amount *= 1000.0; //todo: really?
//String pattern = "#0.000"; // If you like 4 zeros
//DecimalFormat myFormatter = new DecimalFormat(pattern);
//String output = myFormatter.format(amount);
String output = FormatUtil.DoubleToString(amount);
return output + " m" + getBlockchain().getCurrency();
//return String.format("%.3f m%s", amount, getBlockchain().getCurrency());
} else {
//return String.format("%.3f %s", amount, getBlockchain().getCurrency());
String output = FormatUtil.DoubleToString(amount);
return output + " " + getBlockchain().getCurrency();
}
String output = FormatUtil.DoubleToString(amount);
return output + " " + getBlockchain().getCurrency();
}
public String getAmountEquivalentDescription(Double amount) {

View file

@ -264,7 +264,7 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
minFee = minFeeInGwei
normalFee = normalFeeInGwei
maxFee = maxFeeInGwei
etFee!!.setText(normalFeeInGwei)
etFee!!.setText(normalFeeInGwei.replace(',','.'))
etFee!!.error = null
btnSend!!.visibility = View.VISIBLE
feeRequestSuccess = true
@ -449,23 +449,25 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
}
fun doSetFee(checkedRadioButtonId: Int) {
var txtFee = ""
when (checkedRadioButtonId) {
R.id.rbMinimalFee ->
if (minFee != null)
etFee!!.setText(minFee)
txtFee = minFee.toString()
else
etFee!!.setText("?")
finishActivityWithError(Activity.RESULT_CANCELED, getString(R.string.cannot_obtain_data_from_blockchain))
R.id.rbNormalFee ->
if (normalFee != null)
etFee!!.setText(normalFee)
txtFee = normalFee.toString()
else
etFee!!.setText("?")
finishActivityWithError(Activity.RESULT_CANCELED, getString(R.string.cannot_obtain_data_from_blockchain))
R.id.rbMaximumFee ->
if (maxFee != null)
etFee!!.setText(maxFee)
txtFee = maxFee.toString()
else
etFee!!.setText("?")
finishActivityWithError(Activity.RESULT_CANCELED, getString(R.string.cannot_obtain_data_from_blockchain))
}
etFee!!.setText(txtFee.replace(',','.'))
}
}

View file

@ -30,7 +30,6 @@ class PrepareCryptonitOtherAPIWithdrawalActivity : AppCompatActivity(), NfcAdapt
private const val REQUEST_CODE_SCAN_QR_USER_ID = 3
}
private var useCurrencyX1000: Boolean = false
private var card: TangemCard? = null
private var nfcManager: NfcManager? = null
private var cryptonit: Cryptonit_OtherAPI? = null
@ -61,16 +60,12 @@ class PrepareCryptonitOtherAPIWithdrawalActivity : AppCompatActivity(), NfcAdapt
when (card!!.blockchain) {
Blockchain.Ethereum, Blockchain.EthereumTestNet -> {
tvCurrency.text = engine.getBalanceCurrency(card)
useCurrencyX1000 = false
}
Blockchain.Bitcoin, Blockchain.BitcoinTestNet, Blockchain.BitcoinCash, Blockchain.BitcoinCashTestNet -> {
tvCurrency.text = "m" + card!!.blockchain.currency
useCurrencyX1000 = true
tvCurrency.text = card!!.blockchain.currency
}
else -> {
tvCurrency.text = engine.getBalanceCurrency(card)
useCurrencyX1000 = false
}
}
@ -94,7 +89,6 @@ class PrepareCryptonitOtherAPIWithdrawalActivity : AppCompatActivity(), NfcAdapt
// if (!engine.checkAmount(card, strAmount))
// etAmount.error = getString(R.string.unknown_amount_format)
var dblAmount: Double = strAmount.toDouble()
if (useCurrencyX1000) dblAmount /= 1000.0
rlProgressBar.visibility = View.VISIBLE
tvProgressDescription.text = getString(R.string.cryptonit_request_withdrawal)

View file

@ -29,7 +29,6 @@ class PrepareCryptonitWithdrawalActivity : AppCompatActivity(), NfcAdapter.Reade
val TAG: String = PrepareCryptonitWithdrawalActivity::class.java.simpleName
}
private var useCurrencyX1000: Boolean = false
private var card: TangemCard? = null
private var nfcManager: NfcManager? = null
private var cryptonit: Cryptonit? = null
@ -60,16 +59,12 @@ class PrepareCryptonitWithdrawalActivity : AppCompatActivity(), NfcAdapter.Reade
when (card!!.blockchain) {
Blockchain.Ethereum -> {
tvCurrency.text = engine.getBalanceCurrency(card)
useCurrencyX1000 = false
}
Blockchain.Bitcoin, Blockchain.BitcoinCash -> {
tvCurrency.text = "m" + card!!.blockchain.currency
useCurrencyX1000 = true
tvCurrency.text = card!!.blockchain.currency
}
else -> {
tvCurrency.text = engine.getBalanceCurrency(card)
useCurrencyX1000 = false
}
}
tvFeeCurrency.text = tvCurrency.text
@ -109,10 +104,6 @@ class PrepareCryptonitWithdrawalActivity : AppCompatActivity(), NfcAdapter.Reade
val strFee: String = etFee.text.toString().replace(",", ".")
var dblAmount: Double = strAmount.toDouble()
var dblFee: Double = strFee.toDouble()
if (useCurrencyX1000){
dblAmount /= 1000.0
dblFee /= 1000.0
}
cryptonit!!.fee=strFee
rlProgressBar.visibility = View.VISIBLE

View file

@ -37,7 +37,6 @@ class PrepareKrakenWithdrawalActivity : AppCompatActivity(), NfcAdapter.ReaderCa
private const val REQUEST_CODE_SCAN_QR = 1
}
private var useCurrencyX1000: Boolean = false
private var card: TangemCard? = null
private var nfcManager: NfcManager? = null
private var kraken: Kraken? = null
@ -67,16 +66,13 @@ class PrepareKrakenWithdrawalActivity : AppCompatActivity(), NfcAdapter.ReaderCa
when (card!!.blockchain) {
Blockchain.Ethereum, Blockchain.EthereumTestNet -> {
tvCurrency.text = engine.getBalanceCurrency(card)
useCurrencyX1000 = false
}
Blockchain.Bitcoin, Blockchain.BitcoinTestNet, Blockchain.BitcoinCash, Blockchain.BitcoinCashTestNet -> {
tvCurrency.text = "m" + card!!.blockchain.currency
useCurrencyX1000 = true
tvCurrency.text = card!!.blockchain.currency
}
else -> {
tvCurrency.text = engine.getBalanceCurrency(card)
useCurrencyX1000 = false
}
}
@ -110,8 +106,6 @@ class PrepareKrakenWithdrawalActivity : AppCompatActivity(), NfcAdapter.ReaderCa
val strAmount: String = etAmount.text.toString().replace(",", ".")
var dblAmount: Double = strAmount.toDouble()
if (useCurrencyX1000) dblAmount /= 1000.0
rlProgressBar.visibility = View.VISIBLE
tvProgressDescription.text = getString(R.string.kraken_request_withdrawal)
@ -206,7 +200,6 @@ class PrepareKrakenWithdrawalActivity : AppCompatActivity(), NfcAdapter.ReaderCa
val strAmount: String = etAmount.text.toString().replace(",", ".")
var dblAmount: Double = strAmount.toDouble()
if (useCurrencyX1000) dblAmount /= 1000.0
dblAmount+=fee!!.toDouble()

View file

@ -72,8 +72,8 @@ class PreparePaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
// Bitcoin BitcoinTestNet
else if (card!!.blockchain == Blockchain.Bitcoin || card!!.blockchain == Blockchain.BitcoinTestNet) {
val balance = engine.getBalanceLong(card)!! / (card!!.blockchain.multiplier / 1000.0)
tvCurrency.text = "m" + card!!.blockchain.currency
val balance = engine.getBalanceLong(card)!! / (card!!.blockchain.multiplier)
tvCurrency.text = card!!.blockchain.currency
useCurrency = true
val output = FormatUtil.DoubleToString(balance)
etAmount.setText(output)
@ -81,8 +81,8 @@ class PreparePaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
// BitcoinCash BitcoinCashTestNet
else if (card!!.blockchain == Blockchain.BitcoinCash || card!!.blockchain == Blockchain.BitcoinCashTestNet) {
val balance = engine.getBalanceLong(card)!! / (card!!.blockchain.multiplier / 1000.0)
tvCurrency.text = "m" + card!!.blockchain.currency
val balance = engine.getBalanceLong(card)!! / (card!!.blockchain.multiplier)
tvCurrency.text = card!!.blockchain.currency
useCurrency = true
val output = FormatUtil.DoubleToString(balance)
} else {
@ -92,7 +92,7 @@ class PreparePaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
}
if (card!!.blockchain == Blockchain.Bitcoin)
etAmount.filters = arrayOf<InputFilter>(DecimalDigitsInputFilter(5))
etAmount.filters = arrayOf<InputFilter>(DecimalDigitsInputFilter(8))
if (card!!.blockchain == Blockchain.BitcoinCash)
etAmount.filters = arrayOf<InputFilter>(DecimalDigitsInputFilter(8))

View file

@ -726,15 +726,24 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
tvBlockchain.text = card!!.blockchainName
if (card!!.hasBalanceInfo() && (card!!.balance != 0L) ) {
btnExtract.isEnabled = true
btnExtract.backgroundTintList = activeColor
} else {
if (card!!.blockchain != Blockchain.Token) {
if (card!!.hasBalanceInfo() && (card!!.balance != 0L) ) {
btnExtract.isEnabled = true
btnExtract.backgroundTintList = activeColor
} else {
btnExtract.isEnabled = false
btnExtract.backgroundTintList = inactiveColor
}
}
else if (card!!.decimalBalanceAlter == "") {
btnExtract.isEnabled = false
btnExtract.backgroundTintList = inactiveColor
} else {
btnExtract.isEnabled = true
btnExtract.backgroundTintList = activeColor
}
card!!.error = null
card!!.error = null
card!!.message = null
} catch (e: Exception) {

View file

@ -25,7 +25,7 @@ public class FormatUtil {
DecimalFormatSymbols symbols = new DecimalFormatSymbols();
symbols.setDecimalSeparator('.');
String pattern = "#0.######";
String pattern = "#0.########";
// DecimalFormat myFormatter = new DecimalFormat(pattern, symbols);
DecimalFormat myFormatter = new DecimalFormat(pattern);
@ -77,7 +77,7 @@ public class FormatUtil {
public static long ConvertStringToLong(String caption) throws Exception {
// BigDecimal d = new BigDecimal(caption);
BigDecimal d = stringToBigDecimal(caption,Locale.US);
d = d.multiply(new BigDecimal(100000));
d = d.multiply(new BigDecimal(100000000));
d = d.setScale(5);
BigInteger b = d.toBigInteger();
long l = b.longValue();

View file

@ -75,7 +75,7 @@
android:textColor="@color/black"
android:textSize="@dimen/text_size_medium"
android:textStyle="bold"
tools:text="4.51735 mBTC" />
tools:text="4.51735 BTC" />
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
@ -275,7 +275,7 @@
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_min="150dp"/>
app:layout_constraintWidth_min="150dp" />
<TextView
android:id="@+id/tvCurrency2"

View file

@ -85,7 +85,7 @@
android:textColor="@color/black"
android:textSize="@dimen/text_size_medium"
android:textStyle="bold"
tools:text="4.51735 mBtc"/>
tools:text="4.51735 Btc"/>
</LinearLayout>

View file

@ -41,7 +41,7 @@
<string name="send_to_wallet">Send to wallet</string>
<string name="amount">Amount</string>
<!--<string name="including_fee">(including fee)</string>-->
<string name="m_btc">mBTC</string>
<string name="m_btc">BTC</string>
<string name="scan_again_to_verify_the_card">Scan again to verify the card</string>
<string name="smart_cash_ag">Smart Cash AG</string>
<string name="wallet">Wallet</string>