Updated on 2026-08-14
This commit is contained in:
parent
f403e50309
commit
8eeda55d9d
12 changed files with 183 additions and 153 deletions
|
|
@ -120,6 +120,7 @@ public class ServerApiHelper {
|
|||
*/
|
||||
public static final String INFURA_ETH_GET_BALANCE = "eth_getBalance";
|
||||
public static final String INFURA_ETH_GET_TRANSACTION_COUNT = "eth_getTransactionCount";
|
||||
public static final String INFURA_ETH_GET_PENDING_COUNT = "eth_getPendingCount";
|
||||
public static final String INFURA_ETH_CALL = "eth_call";
|
||||
public static final String INFURA_ETH_SEND_RAW_TRANSACTION = "eth_sendRawTransaction";
|
||||
public static final String INFURA_ETH_GAS_PRICE = "eth_gasPrice";
|
||||
|
|
@ -150,7 +151,9 @@ public class ServerApiHelper {
|
|||
case INFURA_ETH_GET_TRANSACTION_COUNT:
|
||||
infuraBody = new InfuraBody(method, new String[]{wallet, "latest"}, id);
|
||||
break;
|
||||
|
||||
case INFURA_ETH_GET_PENDING_COUNT:
|
||||
infuraBody = new InfuraBody(INFURA_ETH_GET_TRANSACTION_COUNT, new String[]{wallet, "pending"}, id);
|
||||
break;
|
||||
case INFURA_ETH_CALL:
|
||||
String address = wallet.substring(2);
|
||||
infuraBody = new InfuraBody(method, new Object[]{new InfuraBody.EthCallParams("0x70a08231000000000000000000000000" + address, contract), "latest"}, id);
|
||||
|
|
|
|||
|
|
@ -37,20 +37,19 @@ public class ETHRequestTask extends InfuraTask {
|
|||
if (request.isMethod(InfuraRequest.METHOD_ETH_GetGasPrice)) {
|
||||
try {
|
||||
String gasPrice = request.getResultString();
|
||||
Log.i("sjjoefeff", gasPrice);
|
||||
Log.i("Gas Price 1", gasPrice);
|
||||
gasPrice = gasPrice.substring(2);
|
||||
BigInteger l = new BigInteger(gasPrice, 16);
|
||||
|
||||
|
||||
Log.i("sjjoefeff", gasPrice);
|
||||
Log.i("Gas Price 2", gasPrice);
|
||||
|
||||
BigInteger m = confirmPaymentActivity.getCard().getBlockchain() == Blockchain.Token ? BigInteger.valueOf(55000) : BigInteger.valueOf(21000);
|
||||
l = l.multiply(m);
|
||||
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))));
|
||||
BigInteger GasLimit = confirmPaymentActivity.getCard().getBlockchain() == Blockchain.Token ? BigInteger.valueOf(60000) : BigInteger.valueOf(21000);
|
||||
String MinFeeInGwei = confirmPaymentActivity.getCard().getAmountInGwei(String.valueOf(l.multiply(GasLimit)));
|
||||
String NormalFeeInGwei = confirmPaymentActivity.getCard().getAmountInGwei(String.valueOf(l.multiply(BigInteger.valueOf(12)).divide(BigInteger.valueOf(10).multiply(GasLimit))));
|
||||
String MaxFeeInGwei = confirmPaymentActivity.getCard().getAmountInGwei(String.valueOf(l.multiply(BigInteger.valueOf(15)).divide(BigInteger.valueOf(10).multiply(GasLimit))));
|
||||
|
||||
Log.i("sjjoefeff", MinFeeInGwei);
|
||||
Log.i("Min Fee Gwei", MinFeeInGwei);
|
||||
|
||||
confirmPaymentActivity.setMinFee(MinFeeInGwei);
|
||||
confirmPaymentActivity.setNormalFee(NormalFeeInGwei);
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ public class ETHRequestTask extends InfuraTask {
|
|||
nonce = nonce.substring(2);
|
||||
BigInteger count = new BigInteger(nonce, 16);
|
||||
|
||||
loadedWallet.getCard().setConfirmTXCount(count);
|
||||
loadedWallet.getCard().setConfirmedTXCount(count);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
@ -105,9 +105,9 @@ public class ETHRequestTask extends InfuraTask {
|
|||
Log.e("TX_RESULT", hashTX);
|
||||
|
||||
|
||||
BigInteger nonce = loadedWallet.getCard().GetConfirmTXCount();
|
||||
BigInteger nonce = loadedWallet.getCard().getConfirmedTXCount();
|
||||
nonce.add(BigInteger.valueOf(1));
|
||||
loadedWallet.getCard().setConfirmTXCount(nonce);
|
||||
loadedWallet.getCard().setConfirmedTXCount(nonce);
|
||||
Log.e("TX_RESULT", hashTX);
|
||||
|
||||
} catch (Exception e) {
|
||||
|
|
|
|||
|
|
@ -54,9 +54,9 @@ public class ETHRequestTask extends InfuraTask {
|
|||
BigInteger bigInt = new BigInteger(hashTX, 16); //TODO: очень плохой способ
|
||||
LastSignStorage.setTxWasSend(sendTransactionActivity.getCard().getWallet());
|
||||
LastSignStorage.setLastMessage(sendTransactionActivity.getCard().getWallet(), "");
|
||||
BigInteger nonce = sendTransactionActivity.getCard().GetConfirmTXCount();
|
||||
BigInteger nonce = sendTransactionActivity.getCard().getConfirmedTXCount();
|
||||
nonce.add(BigInteger.valueOf(1));
|
||||
sendTransactionActivity.getCard().setConfirmTXCount(nonce);
|
||||
sendTransactionActivity.getCard().setConfirmedTXCount(nonce);
|
||||
Log.e("TX_RESULT", hashTX);
|
||||
sendTransactionActivity.finishWithSuccess();
|
||||
} catch (Exception e) {
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ package com.tangem.domain.wallet;
|
|||
|
||||
import com.tangem.wallet.R;
|
||||
|
||||
import java.math.BigInteger;
|
||||
|
||||
public class BalanceValidator {
|
||||
private String firstLine;
|
||||
private String secondLine;
|
||||
|
|
@ -11,7 +13,8 @@ public class BalanceValidator {
|
|||
return firstLine;
|
||||
}
|
||||
|
||||
public String getSecondLine() {
|
||||
public String getSecondLine(Boolean recommend) {
|
||||
if (!recommend) return secondLine;
|
||||
if (score > 89) {
|
||||
return "Safe to accept. " + secondLine;
|
||||
} else if (score > 74) {
|
||||
|
|
@ -35,77 +38,45 @@ public class BalanceValidator {
|
|||
}
|
||||
}
|
||||
|
||||
public void Check(TangemCard card) {
|
||||
public void Check(TangemCard card, Boolean attest) {
|
||||
firstLine = "Verification failed";
|
||||
secondLine = "";
|
||||
|
||||
// rule 1
|
||||
if ((!CheckOfflineBalance(card) && !CheckOnlineBalance(card)) || (!CheckOnlineBalance(card) && HasEverSigned(card))) {
|
||||
score = 0;
|
||||
firstLine = "Unknown balance";
|
||||
secondLine = "Balance cannot be verified. Swipe down to refresh.";
|
||||
return;
|
||||
}
|
||||
if (card.getBlockchain() == Blockchain.Bitcoin) {
|
||||
|
||||
// Workaround before new back-end
|
||||
// if (!HasEverSigned(card)) {
|
||||
if (((card.getOfflineBalance() == null) && !card.isBalanceReceived()) || (!card.isBalanceReceived() && (card.getRemainingSignatures() != card.getMaxSignatures()))) {
|
||||
score = 0;
|
||||
firstLine = "Unknown balance";
|
||||
secondLine = "Balance cannot be verified. Swipe down to refresh.";
|
||||
return;
|
||||
}
|
||||
|
||||
// Workaround before new back-end
|
||||
// if (card.getRemainingSignatures() == card.getMaxSignatures()) {
|
||||
// firstLine = "Verified balance";
|
||||
// secondLine = "Balance confirmed in blockchain. ";
|
||||
// secondLine += "Verified note identity. ";
|
||||
// return;
|
||||
// }
|
||||
|
||||
// rule 2.a
|
||||
if (!VerificationWalletKey(card)) {
|
||||
score = 0;
|
||||
firstLine = "Verification failed";
|
||||
secondLine = "Wallet verification failed. Tap again.";
|
||||
return;
|
||||
}
|
||||
|
||||
// rule 2.c
|
||||
if (!CheckAttestationServiceResult(card) && CheckAttestationServiceAvailable(card)) {
|
||||
score = 0;
|
||||
firstLine = "Not genuine banknote";
|
||||
secondLine = "Tangem Attestation service says the banknote is not genuine.";
|
||||
return;
|
||||
}
|
||||
|
||||
// rule 6
|
||||
if (NotConfirmTransaction(card)) {
|
||||
score = 0;
|
||||
firstLine = "Unguaranted balance";
|
||||
secondLine = "Loading in progress. Wait for full confirmation in blockchain. ";
|
||||
return;
|
||||
}
|
||||
|
||||
// rule 5
|
||||
if (!isCodeConfirmed(card)) {
|
||||
score = 0;
|
||||
firstLine = "Not genuine banknote";
|
||||
secondLine = "Firmware binary code verification failed";
|
||||
return;
|
||||
}
|
||||
|
||||
// rule 5
|
||||
if (card.PIN2 == TangemCard.PIN2_Mode.CustomPIN2) {
|
||||
score = 0;
|
||||
firstLine = "Locked with PIN2";
|
||||
secondLine = "Ask the holder to disable PIN2 before accepting";
|
||||
return;
|
||||
}
|
||||
|
||||
if (card.isBalanceReceived() && card.isBalanceEqual()) {
|
||||
score = 100;
|
||||
firstLine = "Verified balance";
|
||||
secondLine = "Balance confirmed in blockchain. ";
|
||||
if (card.getBalance() == 0) {
|
||||
firstLine = "";
|
||||
if (card.getBalanceUnconfirmed() != 0) {
|
||||
score = 0;
|
||||
firstLine = "Unguaranted balance";
|
||||
secondLine = "Loading in progress. Wait for full confirmation in blockchain. ";
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// rule 4 TODO: need to check SignedHashed against number of outputs in blockchain
|
||||
// if(HasEverSigned(card) && card.getBalance() != 0)
|
||||
if (card.isBalanceReceived() && card.isBalanceEqual()) {
|
||||
score = 100;
|
||||
firstLine = "Verified balance";
|
||||
secondLine = "Balance confirmed in blockchain. ";
|
||||
if (card.getBalance() == 0) {
|
||||
firstLine = "";
|
||||
}
|
||||
}
|
||||
|
||||
// rule 4 TODO: need to check SignedHashed against number of outputs in blockchain
|
||||
// if((card.getRemainingSignatures() != card.getMaxSignatures()) && card.getBalance() != 0)
|
||||
// {
|
||||
// score = 80;
|
||||
// firstLine = "Unguaranteed balance";
|
||||
|
|
@ -113,20 +84,11 @@ public class BalanceValidator {
|
|||
// return;
|
||||
// }
|
||||
|
||||
// rule 7
|
||||
if (CheckOfflineBalance(card) && !CheckOnlineBalance(card) && !HasEverSigned(card) && card.getBalance() != 0) {
|
||||
score = 80;
|
||||
firstLine = "Verified offline balance";
|
||||
secondLine = "Can't obtain balance from blockchain. Restore internet connection to be more confident. ";
|
||||
}
|
||||
|
||||
// rule 2.b
|
||||
if (CheckAttestationServiceAvailable(card)) {
|
||||
secondLine += "Verified note identity. ";
|
||||
} else {
|
||||
score = 80;
|
||||
secondLine += "Card identity was not verified. Cannot reach Tangem attestation service. ";
|
||||
}
|
||||
if ((card.getOfflineBalance() != null) && !card.isBalanceReceived() && (card.getRemainingSignatures() == card.getMaxSignatures()) && card.getBalance() != 0) {
|
||||
score = 80;
|
||||
firstLine = "Verified offline balance";
|
||||
secondLine = "Can't obtain balance from blockchain. Restore internet connection to be more confident. ";
|
||||
}
|
||||
|
||||
// if(card.getFailedBalanceRequestCounter()!=0) {
|
||||
// score -= 5 * card.getFailedBalanceRequestCounter();
|
||||
|
|
@ -135,47 +97,84 @@ public class BalanceValidator {
|
|||
// return;
|
||||
// }
|
||||
|
||||
//
|
||||
//
|
||||
// if(card.isBalanceReceived() && !card.isBalanceEqual()) {
|
||||
// score = 0;
|
||||
// firstLine = "Disputed balance";
|
||||
// secondLine += " Cannot obtain trusted balance at the moment. Try to tap and check this banknote later.";
|
||||
// return;
|
||||
// }
|
||||
} else if ((card.getBlockchain() == Blockchain.Ethereum) || (card.getBlockchain() == Blockchain.Token)) {
|
||||
|
||||
if (card.getBalance() == null) {
|
||||
score = 0;
|
||||
firstLine = "Unknown balance";
|
||||
secondLine = "Balance cannot be verified. Swipe down to refresh.";
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
if (!card.getUnconfirmedTXCount().equals(card.getConfirmedTXCount())) {
|
||||
score = 0;
|
||||
firstLine = "Unguaranteed balance";
|
||||
secondLine = "Transaction is in progress. Wait for confirmation in blockchain. ";
|
||||
return;
|
||||
}
|
||||
|
||||
boolean CheckOfflineBalance(TangemCard card) {
|
||||
return card.getOfflineBalance() != null;
|
||||
}
|
||||
if (card.isBalanceReceived()) {
|
||||
score = 100;
|
||||
firstLine = "Verified balance";
|
||||
secondLine = "Balance confirmed in blockchain. ";
|
||||
if (card.getBalance() == 0) {
|
||||
firstLine = "";
|
||||
}
|
||||
}
|
||||
|
||||
boolean CheckOnlineBalance(TangemCard card) {
|
||||
return card.isBalanceReceived();
|
||||
}
|
||||
if ((card.getOfflineBalance() != null) && !card.isBalanceReceived() && (card.getRemainingSignatures() == card.getMaxSignatures()) && card.getBalance() != 0) {
|
||||
score = 80;
|
||||
firstLine = "Verified offline balance";
|
||||
secondLine = "Can't obtain balance from blockchain. Restore internet connection to be more confident. ";
|
||||
}
|
||||
}
|
||||
|
||||
boolean VerificationWalletKey(TangemCard card) {
|
||||
return card.isWalletPublicKeyValid();
|
||||
}
|
||||
// Verify card?
|
||||
if (attest) {
|
||||
|
||||
boolean HasEverSigned(TangemCard card) {
|
||||
// return card.getSignedHashes() != 0 || card.getRemainingSignatures() != card.getMaxSignatures();
|
||||
return card.getRemainingSignatures() != card.getMaxSignatures();
|
||||
}
|
||||
if (!card.isWalletPublicKeyValid()) {
|
||||
score = 0;
|
||||
firstLine = "Verification failed";
|
||||
secondLine = "Wallet verification failed. Tap again.";
|
||||
return;
|
||||
}
|
||||
|
||||
boolean CheckAttestationServiceAvailable(TangemCard card) {
|
||||
return card.isOnlineVerified() != null;
|
||||
}
|
||||
if (card.isOnlineVerified() != null && !card.isOnlineVerified()) {
|
||||
score = 0;
|
||||
firstLine = "Not genuine banknote";
|
||||
secondLine = "Tangem Attestation service says the banknote is not genuine.";
|
||||
return;
|
||||
}
|
||||
|
||||
boolean CheckAttestationServiceResult(TangemCard card) {
|
||||
return card.isOnlineVerified() != null && card.isOnlineVerified() == true;
|
||||
}
|
||||
if (card.isCodeConfirmed() != null && !card.isCodeConfirmed()) {
|
||||
score = 0;
|
||||
firstLine = "Not genuine banknote";
|
||||
secondLine = "Firmware binary code verification failed";
|
||||
return;
|
||||
}
|
||||
|
||||
boolean NotConfirmTransaction(TangemCard card) {
|
||||
return card.getBalanceUnconfirmed() != 0;
|
||||
}
|
||||
if (card.PIN2 == TangemCard.PIN2_Mode.CustomPIN2) {
|
||||
score = 0;
|
||||
firstLine = "Locked with PIN2";
|
||||
secondLine = "Ask the holder to disable PIN2 before accepting";
|
||||
return;
|
||||
}
|
||||
|
||||
// rule 2.b
|
||||
if (card.isOnlineVerified()) {
|
||||
secondLine += "Verified note identity. ";
|
||||
} else {
|
||||
score = 80;
|
||||
secondLine += "Card identity was not verified. Cannot reach Tangem attestation service. ";
|
||||
}
|
||||
}
|
||||
|
||||
boolean isCodeConfirmed(TangemCard card) {
|
||||
return card.isCodeConfirmed() == null || card.isCodeConfirmed();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -318,7 +318,7 @@ public class EthEngine extends CoinEngine {
|
|||
|
||||
public byte[] sign(String feeValue, String amountValue, boolean IncFee, String toValue, TangemCard mCard, CardProtocol protocol) throws Exception {
|
||||
|
||||
BigInteger nonceValue = mCard.GetConfirmTXCount();
|
||||
BigInteger nonceValue = mCard.getConfirmedTXCount();
|
||||
byte[] pbKey = mCard.getWalletPublicKey();
|
||||
boolean flag = (mCard.getSigningMethod() == TangemCard.SigningMethod.Sign_Hash_Validated_By_Issuer);
|
||||
Issuer issuer = mCard.getIssuer();
|
||||
|
|
|
|||
|
|
@ -47,19 +47,27 @@ public class TangemCard {
|
|||
private float rate = 0;
|
||||
private float rateAlter = 0;
|
||||
|
||||
private BigInteger countConfirmTX = null;
|
||||
private BigInteger countConfirmedTX = null;
|
||||
private BigInteger countUnconfirmedTX = BigInteger.valueOf(0);
|
||||
|
||||
public BigInteger GetConfirmTXCount() {
|
||||
if (countConfirmTX == null) {
|
||||
countConfirmTX = BigInteger.valueOf(0);
|
||||
public BigInteger getConfirmedTXCount() {
|
||||
if (countConfirmedTX == null) {
|
||||
countConfirmedTX = BigInteger.valueOf(0);
|
||||
}
|
||||
return countConfirmTX;
|
||||
return countConfirmedTX;
|
||||
}
|
||||
|
||||
public void setConfirmTXCount(BigInteger count) {
|
||||
countConfirmTX = count;
|
||||
public void setConfirmedTXCount(BigInteger count) {
|
||||
countConfirmedTX = count;
|
||||
}
|
||||
public BigInteger getUnconfirmedTXCount() {
|
||||
if (countUnconfirmedTX == null) {
|
||||
countUnconfirmedTX = BigInteger.valueOf(0);
|
||||
}
|
||||
return countUnconfirmedTX;
|
||||
}
|
||||
public void setUnconfirmedTXCount(BigInteger count) {
|
||||
countUnconfirmedTX = count;
|
||||
}
|
||||
|
||||
public float getRate() {
|
||||
return rate;
|
||||
}
|
||||
|
|
@ -1114,7 +1122,12 @@ public class TangemCard {
|
|||
}
|
||||
|
||||
public Long getBalance() {
|
||||
return balanceConfirmed + balanceUnconfirmed;
|
||||
if (this.getBlockchain() == Blockchain.Bitcoin || this.getBlockchain() == Blockchain.BitcoinCash || this.getBlockchain() == Blockchain.BitcoinTestNet || this.getBlockchain() == Blockchain.BitcoinCashTestNet) {
|
||||
return balanceConfirmed + balanceUnconfirmed;
|
||||
} else if (this.getBlockchain() == Blockchain.Ethereum || this.getBlockchain() == Blockchain.EthereumTestNet) {
|
||||
return 1L; // Todo: Workaround for eth, need to return BigDecimal everywhere
|
||||
}
|
||||
return 0L;
|
||||
}
|
||||
|
||||
public Long getBalanceUnconfirmed() {
|
||||
|
|
@ -1329,7 +1342,8 @@ public class TangemCard {
|
|||
}
|
||||
B.putFloat("rate", rate);
|
||||
B.putFloat("rateAlter", rateAlter);
|
||||
B.putString("confirmTx", GetConfirmTXCount().toString(16));
|
||||
B.putString("confirmTx", getConfirmedTXCount().toString(16));
|
||||
B.putString("unconfirmTx", getUnconfirmedTXCount().toString(16));
|
||||
|
||||
if (codeConfirmed != null)
|
||||
B.putBoolean("codeConfirmed", codeConfirmed);
|
||||
|
|
@ -1484,7 +1498,9 @@ public class TangemCard {
|
|||
if (B.containsKey("rateAlter"))
|
||||
rateAlter = B.getFloat("rateAlter");
|
||||
if (B.containsKey("confirmTx"))
|
||||
countConfirmTX = new BigInteger(B.getString("confirmTx"), 16);
|
||||
countConfirmedTX = new BigInteger(B.getString("confirmTx"), 16);
|
||||
if (B.containsKey("unconfirmTx"))
|
||||
countUnconfirmedTX = new BigInteger(B.getString("unconfirmTx"), 16);
|
||||
|
||||
if (B.containsKey("codeConfirmed"))
|
||||
codeConfirmed = B.getBoolean("codeConfirmed");
|
||||
|
|
|
|||
|
|
@ -329,7 +329,7 @@ public class TokenEngine extends CoinEngine {
|
|||
|
||||
public byte[] sign(String feeValue, String amountValue, boolean IncFee, String toValue, TangemCard mCard, CardProtocol protocol) throws Exception {
|
||||
|
||||
BigInteger nonceValue = mCard.GetConfirmTXCount();
|
||||
BigInteger nonceValue = mCard.getConfirmedTXCount();
|
||||
byte[] pbKey = mCard.getWalletPublicKey();
|
||||
boolean flag = (mCard.getSigningMethod() == TangemCard.SigningMethod.Sign_Hash_Validated_By_Issuer);
|
||||
Issuer issuer = mCard.getIssuer();
|
||||
|
|
|
|||
|
|
@ -253,13 +253,13 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
ServerApiHelper.INFURA_ETH_GAS_PRICE -> {
|
||||
var gasPrice = infuraResponse.result
|
||||
gasPrice = gasPrice.substring(2)
|
||||
var l = BigInteger(gasPrice, 16)
|
||||
// Rounding gas price to integer gweis
|
||||
var l = BigInteger(gasPrice, 16).divide(BigInteger.valueOf(1000000000L)).multiply(BigInteger.valueOf(1000000000L))
|
||||
|
||||
val m = if (card!!.blockchain == Blockchain.Token) BigInteger.valueOf(60000) else BigInteger.valueOf(21000)
|
||||
l = l.multiply(m)
|
||||
val minFeeInGwei = card!!.getAmountInGwei(l.toString())
|
||||
val normalFeeInGwei = card!!.getAmountInGwei(l.multiply(BigInteger.valueOf(12)).divide(BigInteger.valueOf(10)).toString())
|
||||
val maxFeeInGwei = card!!.getAmountInGwei(l.multiply(BigInteger.valueOf(15)).divide(BigInteger.valueOf(10)).toString())
|
||||
val minFeeInGwei = card!!.getAmountInGwei(l.multiply(m).toString())
|
||||
val normalFeeInGwei = card!!.getAmountInGwei(l.multiply(BigInteger.valueOf(12)).divide(BigInteger.valueOf(10)).multiply(m).toString())
|
||||
val maxFeeInGwei = card!!.getAmountInGwei(l.multiply(BigInteger.valueOf(15)).divide(BigInteger.valueOf(10)).multiply(m).toString())
|
||||
|
||||
minFee = minFeeInGwei
|
||||
normalFee = normalFeeInGwei
|
||||
|
|
|
|||
|
|
@ -96,9 +96,9 @@ class SendTransactionActivity : AppCompatActivity() {
|
|||
Log.e("TX_RESULT", hashTX)
|
||||
|
||||
|
||||
val nonce = card!!.GetConfirmTXCount()
|
||||
val nonce = card!!.getConfirmedTXCount()
|
||||
nonce.add(BigInteger.valueOf(1))
|
||||
card!!.setConfirmTXCount(nonce)
|
||||
card!!.setConfirmedTXCount(nonce)
|
||||
Log.e("TX_RESULT", hashTX)
|
||||
|
||||
finishWithSuccess()
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@ import com.tangem.wallet.R
|
|||
import kotlinx.android.synthetic.main.fr_loaded_wallet.*
|
||||
import org.json.JSONException
|
||||
import java.math.BigInteger
|
||||
import java.time.Instant
|
||||
import java.util.*
|
||||
import kotlin.concurrent.fixedRateTimer
|
||||
|
||||
|
|
@ -74,7 +75,7 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
private var newPIN2 = ""
|
||||
private var cardProtocol: CardProtocol? = null
|
||||
private var sp: SharedPreferences? = null
|
||||
private val inactiveColor: ColorStateList by lazy { resources.getColorStateList(R.color.primary) }
|
||||
private val inactiveColor: ColorStateList by lazy { resources.getColorStateList(R.color.btn_dark) }
|
||||
private val activeColor: ColorStateList by lazy { resources.getColorStateList(R.color.colorAccent) }
|
||||
|
||||
private var timerRepeatRefresh: Timer? = null
|
||||
|
|
@ -87,7 +88,7 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
|
||||
sp = PreferenceManager.getDefaultSharedPreferences(activity)
|
||||
|
||||
card = TangemCard(activity!!.intent.getStringExtra(TangemCard.EXTRA_CARD))
|
||||
card = TangemCard(activity!!.intent.getStringExtra(TangemCard.EXTRA_UID))
|
||||
card!!.loadFromBundle(activity!!.intent.extras.getBundle(TangemCard.EXTRA_CARD))
|
||||
|
||||
lastTag = activity!!.intent.getParcelableExtra(MainActivity.EXTRA_LAST_DISCOVERED_TAG)
|
||||
|
|
@ -245,6 +246,7 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
|
||||
card!!.setBalanceConfirmed(balance)
|
||||
card!!.balanceUnconfirmed = 0L
|
||||
card!!.isBalanceReceived = true
|
||||
if (card!!.blockchain != Blockchain.Token)
|
||||
card!!.decimalBalance = l.toString(10)
|
||||
card!!.decimalBalanceAlter = l.toString(10)
|
||||
|
|
@ -256,11 +258,20 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
var nonce = infuraResponse.result
|
||||
nonce = nonce.substring(2)
|
||||
val count = BigInteger(nonce, 16)
|
||||
card!!.setConfirmTXCount(count)
|
||||
card!!.setConfirmedTXCount(count)
|
||||
|
||||
Log.i("$TAG eth_getTransCount", nonce)
|
||||
}
|
||||
|
||||
ServerApiHelper.INFURA_ETH_GET_PENDING_COUNT -> {
|
||||
var pending = infuraResponse.result
|
||||
pending = pending.substring(2)
|
||||
val count = BigInteger(pending, 16)
|
||||
card!!.setUnconfirmedTXCount(count)
|
||||
|
||||
Log.i("$TAG eth_getPendingTxCount", pending)
|
||||
}
|
||||
|
||||
ServerApiHelper.INFURA_ETH_CALL -> {
|
||||
try {
|
||||
var balanceCap = infuraResponse.result
|
||||
|
|
@ -275,6 +286,7 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
// refresh()
|
||||
requestInfura(ServerApiHelper.INFURA_ETH_GET_BALANCE, "")
|
||||
requestInfura(ServerApiHelper.INFURA_ETH_GET_TRANSACTION_COUNT, "")
|
||||
requestInfura(ServerApiHelper.INFURA_ETH_GET_PENDING_COUNT, "")
|
||||
return@onInfuraSuccess
|
||||
}
|
||||
card!!.setBalanceConfirmed(balance)
|
||||
|
|
@ -285,6 +297,7 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
|
||||
requestInfura(ServerApiHelper.INFURA_ETH_GET_BALANCE, "")
|
||||
requestInfura(ServerApiHelper.INFURA_ETH_GET_TRANSACTION_COUNT, "")
|
||||
requestInfura(ServerApiHelper.INFURA_ETH_GET_PENDING_COUNT, "")
|
||||
} catch (e: JSONException) {
|
||||
e.printStackTrace()
|
||||
} catch (e: NumberFormatException) {
|
||||
|
|
@ -315,9 +328,9 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
|
||||
Log.e("$TAG TX_RESULT", hashTX)
|
||||
|
||||
val nonce = card!!.GetConfirmTXCount()
|
||||
val nonce = card!!.getConfirmedTXCount()
|
||||
nonce.add(BigInteger.valueOf(1))
|
||||
card!!.setConfirmTXCount(nonce)
|
||||
card!!.setConfirmedTXCount(nonce)
|
||||
|
||||
Log.e("$TAG TX_RESULT", hashTX)
|
||||
|
||||
|
|
@ -654,13 +667,11 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
|
||||
val engine = CoinEngineFactory.create(card!!.blockchain)
|
||||
|
||||
if (card!!.blockchain == Blockchain.Bitcoin || card!!.blockchain == Blockchain.BitcoinTestNet) {
|
||||
val validator = BalanceValidator()
|
||||
validator.Check(card)
|
||||
tvBalanceLine1.text = validator.firstLine
|
||||
tvBalanceLine2.text = validator.secondLine
|
||||
tvBalanceLine1.setTextColor(ContextCompat.getColor(context!!, validator.color))
|
||||
}
|
||||
val validator = BalanceValidator()
|
||||
validator.Check(card, false)
|
||||
tvBalanceLine1.text = validator.firstLine
|
||||
tvBalanceLine2.text = validator.getSecondLine(false)
|
||||
tvBalanceLine1.setTextColor(ContextCompat.getColor(context!!, validator.color))
|
||||
|
||||
if (engine!!.hasBalanceInfo(card) || card!!.offlineBalance == null) {
|
||||
if (card!!.blockchain == Blockchain.Token) {
|
||||
|
|
@ -681,7 +692,7 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
|
||||
tvBlockchain.text = card!!.blockchainName
|
||||
|
||||
if (card!!.hasBalanceInfo()) {
|
||||
if (card!!.hasBalanceInfo() && (card!!.balance != 0L) ) {
|
||||
btnExtract.isEnabled = true
|
||||
btnExtract.backgroundTintList = activeColor
|
||||
} else {
|
||||
|
|
@ -777,6 +788,7 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
|
||||
requestInfura(ServerApiHelper.INFURA_ETH_GET_BALANCE, "")
|
||||
requestInfura(ServerApiHelper.INFURA_ETH_GET_TRANSACTION_COUNT, "")
|
||||
requestInfura(ServerApiHelper.INFURA_ETH_GET_PENDING_COUNT, "")
|
||||
|
||||
requestRateInfo("ethereum")
|
||||
}
|
||||
|
|
@ -923,12 +935,15 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
startActivityForResult(intent, REQUEST_CODE_SWAP_PIN)
|
||||
}
|
||||
|
||||
var showTime: Date= Date()
|
||||
|
||||
private fun showSingleToast(text: Int) {
|
||||
if (singleToast == null || !singleToast!!.view.isShown) {
|
||||
if (singleToast == null || !singleToast!!.view.isShown || showTime.time+2000<Date().time ) {
|
||||
if (singleToast != null)
|
||||
singleToast!!.cancel()
|
||||
singleToast = Toast.makeText(context, text, Toast.LENGTH_LONG)
|
||||
singleToast!!.show()
|
||||
showTime=Date()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue