Updated on 2026-08-14
This commit is contained in:
parent
1d0e1c276e
commit
a6e6ffab96
13 changed files with 103 additions and 390 deletions
|
|
@ -372,7 +372,7 @@ public class ServerApiHelper {
|
|||
.observeOn(AndroidSchedulers.mainThread());
|
||||
checkBalanceObserver.subscribe(new DefaultObserver<ElectrumRequest>() {
|
||||
@Override
|
||||
public void onNext(ElectrumRequest electrumRequest) {
|
||||
public void onNext(ElectrumRequest v) {
|
||||
if (electrumRequest.answerData != null) {
|
||||
electrumRequestDataListener.onElectrumRequestData(electrumRequest);
|
||||
Log.i(TAG, "electrumRequestData " + electrumRequest.getMethod() + " onNext != null");
|
||||
|
|
@ -390,6 +390,7 @@ public class ServerApiHelper {
|
|||
public void onComplete() {
|
||||
Log.i(TAG, "electrumRequestData " + electrumRequest.getMethod() + " onComplete");
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -104,8 +104,6 @@ public class SignPaymentTask extends Thread {
|
|||
txStr = String.format("0x%s", txStr);
|
||||
}
|
||||
|
||||
//LastSignStorage.setLastTX(mCard.getWallet(), txStr);
|
||||
|
||||
Intent intent = new Intent(mContext, SendTransactionActivity.class);
|
||||
intent.putExtra(SendTransactionActivity.EXTRA_UID, mCard.getUID());
|
||||
intent.putExtra(SendTransactionActivity.EXTRA_CARD, mCard.getAsBundle());
|
||||
|
|
|
|||
|
|
@ -517,17 +517,17 @@ public class CardProtocol {
|
|||
// substitutions for card, that was produced with wrong blockchain data (for example token contract was unknown)
|
||||
// this method must be called after set issuer because substitution is verified by issuer data key
|
||||
try {
|
||||
// if( mCard.getBatch().equals("0017") )
|
||||
// {
|
||||
// mCard.setContractAddress("0x9Eef75bA8e81340da9D8d1fd06B2f313DB88839c");
|
||||
// }
|
||||
// else if( mCard.getBatch().equals("0019") )
|
||||
// {
|
||||
// mCard.setContractAddress("0x0c056b0cda0763cc14b8b2d6c02465c91e33ec72");
|
||||
// }else {
|
||||
if( mCard.getBatch().equals("0017") )
|
||||
{
|
||||
mCard.setContractAddress("0x9Eef75bA8e81340da9D8d1fd06B2f313DB88839c");
|
||||
}
|
||||
else if( mCard.getBatch().equals("0019") )
|
||||
{
|
||||
mCard.setContractAddress("0x0c056b0cda0763cc14b8b2d6c02465c91e33ec72");
|
||||
} else {
|
||||
LocalStorage localStorage = new LocalStorage(mContext);
|
||||
localStorage.applySubstitution(mCard);
|
||||
// }
|
||||
}
|
||||
}catch(Exception e)
|
||||
{
|
||||
Log.e(logTag, "Can't apply card data substitution");
|
||||
|
|
|
|||
|
|
@ -71,7 +71,8 @@ public class BalanceValidator {
|
|||
firstLine = "Verified balance";
|
||||
secondLine = "Balance confirmed in blockchain. ";
|
||||
if (card.getBalance() == 0) {
|
||||
firstLine = "";
|
||||
firstLine = "Empty wallet";
|
||||
secondLine = "";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -125,14 +126,15 @@ public class BalanceValidator {
|
|||
firstLine = "Verified balance";
|
||||
secondLine = "Balance confirmed in blockchain. ";
|
||||
if (card.getBalance() == 0) {
|
||||
firstLine = "";
|
||||
firstLine = "Empty wallet";
|
||||
secondLine = "";
|
||||
}
|
||||
}
|
||||
|
||||
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. ";
|
||||
secondLine = "Restore internet connection to obtain trusted balance from blockchain";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -215,7 +215,7 @@ public class BtcCashEngine extends CoinEngine {
|
|||
Double balance = mCard.AmountFromInternalUnits(mCard.getBalance());
|
||||
return mCard.getAmountDescription(balance);
|
||||
} else {
|
||||
return "-- -- -- " + mCard.getBlockchain().getCurrency();
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -262,7 +262,7 @@ public class BtcEngine extends CoinEngine {
|
|||
Double balance = mCard.AmountFromInternalUnits(mCard.getBalance());
|
||||
return mCard.getAmountDescription(balance);
|
||||
} else {
|
||||
return "-- -- -- " + mCard.getBlockchain().getCurrency();
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -138,7 +138,7 @@ public class EthEngine extends CoinEngine {
|
|||
@Override
|
||||
public String getBalance(TangemCard mCard) {
|
||||
if (!hasBalanceInfo(mCard)) {
|
||||
return "-- -- -- " + getBalanceCurrency(mCard);
|
||||
return "";
|
||||
}
|
||||
|
||||
String output = getBalanceValue(mCard);
|
||||
|
|
|
|||
|
|
@ -3,12 +3,14 @@ package com.tangem.domain.wallet;
|
|||
import android.os.Bundle;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.tangem.data.network.Kraken;
|
||||
import com.tangem.domain.cardReader.SettingsMask;
|
||||
import com.tangem.util.BTCUtils;
|
||||
import com.tangem.util.FormatUtil;
|
||||
import com.tangem.util.Util;
|
||||
import com.tangem.wallet.R;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
|
|
@ -270,149 +272,6 @@ public class TangemCard {
|
|||
this.remainingSignatures = remainingSignatures;
|
||||
}
|
||||
|
||||
public String getTransactionList() {
|
||||
try {
|
||||
StringBuffer result = new StringBuffer();
|
||||
if (hasUnspentInfo()) {
|
||||
if (mUnspentTransactions.size() > 0) {
|
||||
|
||||
for (int i = 0; i < mUnspentTransactions.size(); ++i) {
|
||||
if (i != 0) {
|
||||
result.append(" \n");
|
||||
}
|
||||
result.append(String.valueOf(i + 1));
|
||||
result.append(": ");
|
||||
long unix_time = GetTimestamp(mUnspentTransactions.get(i).Height);
|
||||
|
||||
if (unix_time < UNIX_TIME_2017_01_01)
|
||||
return "-- -- --";
|
||||
unix_time = unix_time * 1000L;
|
||||
|
||||
Date dt = new Date(unix_time);
|
||||
//java.util.Calendar cd = Calendar.getInstance();
|
||||
//cd.setTimeInMillis(unix_time);
|
||||
|
||||
//result.append(String.format("%02d/%02d/%04d", cd.get(Calendar.DAY_OF_MONTH), cd.get(Calendar.MONTH) + 1, cd.get(Calendar.YEAR)));
|
||||
|
||||
result.append(Util.formatDate(dt));
|
||||
|
||||
|
||||
result.append(" - Amount: ");
|
||||
result.append(getAmountDescription(AmountFromInternalUnits(mUnspentTransactions.get(i).Amount)));
|
||||
//result.append(String.valueOf((double) mUnspentTransactions.get(i).Amount / 100000));
|
||||
//result.append(",\nTx: "); This is only for developers
|
||||
//result.append(String.valueOf(mUnspentTransactions.get(i).txID));
|
||||
|
||||
}
|
||||
|
||||
// if (hasHistoryInfo()) {
|
||||
// for (int i = 0; i < mHistoryTransactions.size(); ++i) {
|
||||
// result.append(" \n");
|
||||
// result.append("O");
|
||||
// result.append(String.valueOf(i + 1));
|
||||
// result.append(": ");
|
||||
// long unix_time = GetTimestamp(mHistoryTransactions.get(i).Height);
|
||||
// unix_time = unix_time * 1000L;
|
||||
//
|
||||
// java.util.Calendar cd = Calendar.getInstance();
|
||||
// cd.setTimeInMillis(unix_time);
|
||||
//
|
||||
// result.append(String.format("%02d/%02d/%04d", cd.get(Calendar.DAY_OF_MONTH), cd.get(Calendar.MONTH) + 1, cd.get(Calendar.YEAR)));
|
||||
//
|
||||
//
|
||||
// }
|
||||
// }
|
||||
} else {
|
||||
result.append("-- -- --");
|
||||
}
|
||||
} else {
|
||||
result.append("-- -- --");
|
||||
}
|
||||
if (balanceUnconfirmed != 0) {
|
||||
result.append("awaiting confirmation...");
|
||||
}
|
||||
return result.toString();
|
||||
} catch (Exception e) {
|
||||
return "?";
|
||||
}
|
||||
}
|
||||
|
||||
public String getInputsDescription() {
|
||||
|
||||
try {
|
||||
StringBuffer result = new StringBuffer();
|
||||
if (hasUnspentInfo()) {
|
||||
if (mUnspentTransactions.size() == 1) {
|
||||
//
|
||||
if (balanceUnconfirmed != 0) {
|
||||
result.append(getAmountDescription(AmountFromInternalUnits(mUnspentTransactions.get(0).Amount)));
|
||||
} else {
|
||||
result.append("1 unspent");
|
||||
}
|
||||
long unix_time = GetTimestamp(mUnspentTransactions.get(0).Height);
|
||||
|
||||
if (unix_time < UNIX_TIME_2017_01_01) {
|
||||
|
||||
} else {
|
||||
result.append(", ");
|
||||
unix_time = unix_time * 1000L;
|
||||
result.append(Util.formatDateTime(new Date(unix_time)));
|
||||
}
|
||||
|
||||
|
||||
// java.util.Calendar cd = Calendar.getInstance();
|
||||
// cd.setTimeInMillis(unix_time);
|
||||
|
||||
//result.append(String.format(" at %02d/%02d/%04d %02d:%02d:%02d", cd.get(Calendar.DAY_OF_MONTH), cd.get(Calendar.MONTH) + 1, cd.get(Calendar.YEAR), cd.get(Calendar.HOUR), cd.get(Calendar.MINUTE), cd.get(Calendar.SECOND)));
|
||||
|
||||
|
||||
if (balanceUnconfirmed != 0) {
|
||||
result.append("\nawaiting confirmation...");
|
||||
}
|
||||
} else if (mUnspentTransactions.size() > 0) {
|
||||
long minDate = GetTimestamp(mUnspentTransactions.get(0).Height) * 1000L;
|
||||
long maxDate = minDate;
|
||||
int unspentAmount = mUnspentTransactions.get(0).Amount;
|
||||
|
||||
for (int i = 1; i < mUnspentTransactions.size(); ++i) {
|
||||
long unix_time = GetTimestamp(mUnspentTransactions.get(i).Height);
|
||||
unix_time = unix_time * 1000L;
|
||||
|
||||
if (unix_time < minDate) minDate = unix_time;
|
||||
if (unix_time > maxDate) maxDate = unix_time;
|
||||
unspentAmount += mUnspentTransactions.get(i).Amount;
|
||||
}
|
||||
|
||||
Calendar cd = Calendar.getInstance();
|
||||
cd.setTimeInMillis(minDate);
|
||||
if (balanceUnconfirmed != 0) {
|
||||
result.append(getAmountDescription(AmountFromInternalUnits(unspentAmount)));
|
||||
result.append(" in ");
|
||||
}
|
||||
result.append(String.valueOf(mUnspentTransactions.size()));
|
||||
result.append(" unspents\n");
|
||||
|
||||
result.append(String.format("between %s\n", Util.formatDateTime(new Date(minDate))));
|
||||
|
||||
cd.setTimeInMillis(maxDate);
|
||||
result.append(String.format("and %s", Util.formatDateTime(new Date(maxDate))));
|
||||
|
||||
if (balanceUnconfirmed != 0) {
|
||||
result.append("\nawaiting confirmation...");
|
||||
}
|
||||
} else if (balanceUnconfirmed == 0) {
|
||||
result.append("-- -- --");
|
||||
} else if (balanceUnconfirmed != 0) {
|
||||
result.append("awaiting confirmation...");
|
||||
}
|
||||
} else {
|
||||
result.append("-- -- --");
|
||||
}
|
||||
return result.toString();
|
||||
} catch (Exception e) {
|
||||
return "?";
|
||||
}
|
||||
}
|
||||
|
||||
public int getCountOutputs() {
|
||||
int count = 0;
|
||||
|
|
@ -424,16 +283,6 @@ public class TangemCard {
|
|||
return count;
|
||||
}
|
||||
|
||||
public String getOutputsDescription() {
|
||||
if (hasUnspentInfo() && hasHistoryInfo() && mHistoryTransactions.size() - mUnspentTransactions.size() > 0) {
|
||||
return String.valueOf(mHistoryTransactions.size() - mUnspentTransactions.size());
|
||||
} else if (hasUnspentInfo() && hasHistoryInfo()) {
|
||||
return "-- -- --";
|
||||
} else {
|
||||
return "-- -- --";
|
||||
}
|
||||
}
|
||||
|
||||
static int UNIX_TIME_2017_01_01 = 1483228800;
|
||||
|
||||
public String getLastInputDescription() {
|
||||
|
|
@ -481,39 +330,6 @@ public class TangemCard {
|
|||
|
||||
}
|
||||
|
||||
public String getLastOutputDescription() {
|
||||
if (hasUnspentInfo() && hasHistoryInfo()) {
|
||||
if (mHistoryTransactions.size() - mUnspentTransactions.size() > 0) {
|
||||
long maxUDT = 0;
|
||||
|
||||
for (int i = 0; i < mHistoryTransactions.size(); ++i) {
|
||||
if (!mHistoryTransactions.get(i).isInput)
|
||||
continue;
|
||||
if (indexfOfUnspentTransaction(mHistoryTransactions.get(i).txID) != -1)
|
||||
continue;
|
||||
long unix_time = GetTimestamp(mHistoryTransactions.get(i).Height);
|
||||
if (unix_time == 1296688602L)
|
||||
unix_time = 0;
|
||||
if (unix_time < UNIX_TIME_2017_01_01)
|
||||
return "-- -- --";
|
||||
unix_time = unix_time * 1000L;
|
||||
if (unix_time > maxUDT) maxUDT = unix_time;
|
||||
}
|
||||
|
||||
if (maxUDT == 0) {
|
||||
return "-- -- --";
|
||||
} else {
|
||||
return Util.formatDateTime(new Date(maxUDT));
|
||||
}
|
||||
|
||||
} else {
|
||||
return "-- -- --";
|
||||
}
|
||||
} else {
|
||||
return "-- -- --";
|
||||
}
|
||||
}
|
||||
|
||||
private int indexfOfUnspentTransaction(String txID) {
|
||||
if (hasUnspentInfo()) {
|
||||
for (int i = 0; i < mUnspentTransactions.size(); i++) {
|
||||
|
|
@ -546,6 +362,9 @@ public class TangemCard {
|
|||
balanceUnconfirmed = null;
|
||||
mUnspentTransactions = null;
|
||||
mHistoryTransactions = null;
|
||||
balanceDecimal = null;
|
||||
balanceDecimalAlter = null;
|
||||
setIsBalanceEqual(false);
|
||||
}
|
||||
|
||||
public Date getPersonalizationDateTime() {
|
||||
|
|
@ -1118,12 +937,24 @@ public class TangemCard {
|
|||
}
|
||||
|
||||
public Long getBalance() {
|
||||
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
|
||||
|
||||
BigDecimal balance = null;
|
||||
|
||||
if ((this.getBlockchain() == Blockchain.Bitcoin || this.getBlockchain() == Blockchain.BitcoinCash || this.getBlockchain() == Blockchain.BitcoinTestNet || this.getBlockchain() == Blockchain.BitcoinCashTestNet) && balanceConfirmed != null && balanceUnconfirmed != null) {
|
||||
balance = BigDecimal.valueOf(balanceConfirmed + balanceUnconfirmed);
|
||||
} else if (this.getBlockchain() == Blockchain.Ethereum || this.getBlockchain() == Blockchain.EthereumTestNet || this.getBlockchain() == Blockchain.Token) {
|
||||
if (balanceDecimal != null) {
|
||||
balance = new BigDecimal(balanceDecimal); // Returns ETH / token balance
|
||||
} else if (balanceDecimalAlter != null) {
|
||||
balance = new BigDecimal(balanceDecimalAlter); // or ETH balance if there're no tokens on Token card
|
||||
}
|
||||
}
|
||||
|
||||
if (balance != null) {
|
||||
return balance.longValue(); // Will leave only lower 64 bits for ETH and Tokens
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
return 0L;
|
||||
}
|
||||
|
||||
public Long getBalanceUnconfirmed() {
|
||||
|
|
@ -1139,7 +970,7 @@ public class TangemCard {
|
|||
}
|
||||
|
||||
public boolean hasBalanceInfo() {
|
||||
return balanceConfirmed != null && balanceUnconfirmed != null;
|
||||
return balanceConfirmed != null || balanceUnconfirmed != null || balanceDecimal != "" || balanceDecimalAlter != "";
|
||||
}
|
||||
|
||||
public String getDecimalBalance() {
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ public class TokenEngine extends CoinEngine {
|
|||
|
||||
public String GetBalanceAlterValue(TangemCard mCard) {
|
||||
String dec = mCard.getDecimalBalanceAlter();
|
||||
if(dec.isEmpty()) return "-- -- --";
|
||||
if(dec == null || dec.isEmpty()) return "";
|
||||
BigDecimal d = convertToEth(dec);
|
||||
String s = d.toString();
|
||||
|
||||
|
|
@ -120,7 +120,7 @@ public class TokenEngine extends CoinEngine {
|
|||
|
||||
public String getBalanceValue(TangemCard mCard) {
|
||||
if (!hasBalanceInfo(mCard))
|
||||
return "-- -- -- " + getBalanceCurrency(mCard);
|
||||
return "";
|
||||
|
||||
String dec = mCard.getDecimalBalance();
|
||||
BigDecimal d = new BigDecimal(dec);
|
||||
|
|
@ -200,7 +200,7 @@ public class TokenEngine extends CoinEngine {
|
|||
@Override
|
||||
public String getBalanceEquivalent(TangemCard mCard) {
|
||||
if (!hasBalanceInfo(mCard)) {
|
||||
return "-- -- -- ";
|
||||
return "";
|
||||
}
|
||||
String dec = mCard.getDecimalBalance();
|
||||
BigDecimal d = convertToEth(dec);
|
||||
|
|
@ -210,7 +210,7 @@ public class TokenEngine extends CoinEngine {
|
|||
@Override
|
||||
public String getBalance(TangemCard mCard) {
|
||||
if (!hasBalanceInfo(mCard)) {
|
||||
return "-- -- -- " + getBalanceCurrency(mCard);
|
||||
return "";
|
||||
}
|
||||
|
||||
String output = getBalanceValue(mCard);
|
||||
|
|
@ -221,7 +221,11 @@ public class TokenEngine extends CoinEngine {
|
|||
|
||||
public String getBalanceWithAlter(TangemCard mCard) {
|
||||
//return getBalance(mCard) + "\n(" + GetBalanceAlterValue(mCard) + " ETH)";
|
||||
return " " + getBalance(mCard) + " <br><small><small> + " + GetBalanceAlterValue(mCard) + " ETH for gas</small></small>";
|
||||
if (GetBalanceAlterValue(mCard) != "") {
|
||||
return " " + getBalance(mCard) + " <br><small><small> + " + GetBalanceAlterValue(mCard) + " ETH for gas</small></small>";
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public String calculateAddress(TangemCard mCard, byte[] pkUncompressed) throws NoSuchProviderException, NoSuchAlgorithmException {
|
||||
|
|
|
|||
|
|
@ -108,7 +108,7 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
|
||||
etWallet.setText(intent.getStringExtra("Wallet"))
|
||||
|
||||
etFee!!.setText("?")
|
||||
etFee!!.setText("")
|
||||
|
||||
btnSend!!.visibility = View.INVISIBLE
|
||||
feeRequestSuccess = false
|
||||
|
|
|
|||
|
|
@ -51,27 +51,14 @@ class SendTransactionActivity : AppCompatActivity(), NfcAdapter.ReaderCallback
|
|||
|
||||
val engine = CoinEngineFactory.create(card!!.blockchain)
|
||||
if (card!!.blockchain == Blockchain.Ethereum || card!!.blockchain == Blockchain.EthereumTestNet || card!!.blockchain == Blockchain.Token) {
|
||||
// val task = ETHRequestTask(this@SendTransactionActivity, card!!.blockchain)
|
||||
// val req = InfuraRequest.SendTransaction(card!!.wallet, tx)
|
||||
// req.id = 67
|
||||
// req.setBlockchain(card!!.blockchain)
|
||||
// task.execute(req)
|
||||
|
||||
requestInfura(ServerApiHelper.INFURA_ETH_SEND_RAW_TRANSACTION, "")
|
||||
|
||||
} else if (card!!.blockchain == Blockchain.Bitcoin || card!!.blockchain == Blockchain.BitcoinTestNet) {
|
||||
// val nodeAddress = engine!!.getNode(card)
|
||||
// val nodePort = engine.getNodePort(card)
|
||||
// val connectTask = ConnectTask(this@SendTransactionActivity, nodeAddress, nodePort, 3)
|
||||
// connectTask.execute(ElectrumRequest.broadcast(card!!.wallet, tx))
|
||||
|
||||
requestElectrum(card!!, ElectrumRequest.broadcast(card!!.wallet, tx))
|
||||
|
||||
} else if (card!!.blockchain == Blockchain.BitcoinCash || card!!.blockchain == Blockchain.BitcoinCashTestNet) {
|
||||
// val nodeAddress = engine!!.getNode(card)
|
||||
// val nodePort = engine.getNodePort(card)
|
||||
// val connectTask = ConnectTask(this@SendTransactionActivity, nodeAddress, nodePort, 3)
|
||||
// connectTask.execute(ElectrumRequest.broadcast(card!!.wallet, tx))
|
||||
|
||||
requestElectrum(card!!, ElectrumRequest.broadcast(card!!.wallet, tx))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -72,6 +72,7 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
private var sp: SharedPreferences? = null
|
||||
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 requestCounter = 0
|
||||
|
||||
private var timerRepeatRefresh: Timer? = null
|
||||
|
||||
|
|
@ -118,6 +119,7 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
e.printStackTrace()
|
||||
}
|
||||
|
||||
btnExtract.isEnabled = false
|
||||
btnExtract.backgroundTintList = inactiveColor
|
||||
|
||||
refresh()
|
||||
|
|
@ -218,6 +220,10 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
|
||||
// request electrum listener
|
||||
serverApiHelper!!.setElectrumRequestData {
|
||||
|
||||
requestCounter--
|
||||
if (requestCounter == 0) srlLoadedWallet!!.isRefreshing = false
|
||||
|
||||
if (it.isMethod(ElectrumRequest.METHOD_GetBalance)) {
|
||||
try {
|
||||
val walletAddress = it.params.getString(0)
|
||||
|
|
@ -257,13 +263,6 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
val height = jsUnspent.getInt("height")
|
||||
val hash = jsUnspent.getString("tx_hash")
|
||||
if (height != -1) {
|
||||
// val nodeAddress = engine.getNode(card)
|
||||
// val nodePort = engine.getNodePort(card)
|
||||
// val updateWalletInfoTask = UpdateWalletInfoTask(this, nodeAddress, nodePort)
|
||||
// // loadedWallet.updateTasks.add(updateWalletInfoTask);
|
||||
// updateWalletInfoTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, ElectrumRequest.getHeader(mWalletAddress, height.toString()), ElectrumRequest.getTransaction(mWalletAddress, hash))
|
||||
|
||||
|
||||
requestElectrum(card!!, ElectrumRequest.getHeader(walletAddress, height.toString()))
|
||||
requestElectrum(card!!, ElectrumRequest.getTransaction(walletAddress, hash))
|
||||
}
|
||||
|
|
@ -338,12 +337,17 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
if (requestCounter == 0) updateViews()
|
||||
|
||||
}
|
||||
|
||||
// request card verify listener
|
||||
serverApiHelper!!.setCardVerifyAndGetInfoListener {
|
||||
srlLoadedWallet!!.isRefreshing = false
|
||||
updateViews()
|
||||
|
||||
requestCounter--
|
||||
if (requestCounter == 0) srlLoadedWallet!!.isRefreshing = false
|
||||
|
||||
val result = it.results!![0]
|
||||
if (result.error != null) {
|
||||
card!!.isOnlineVerified = false
|
||||
|
|
@ -351,6 +355,8 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
}
|
||||
card!!.isOnlineVerified = result.passed
|
||||
|
||||
if (requestCounter == 0) updateViews()
|
||||
|
||||
if (!result.passed) return@setCardVerifyAndGetInfoListener
|
||||
|
||||
if (localStorage.checkBatchInfoChanged(card!!, result)) {
|
||||
|
|
@ -358,10 +364,8 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
ivTangemCard.setImageBitmap(localStorage.getCardArtworkBitmap(card!!))
|
||||
localStorage.applySubstitution(card!!)
|
||||
if (card!!.blockchain == Blockchain.Token || card!!.blockchain == Blockchain.Ethereum) {
|
||||
//TODO: change this very bad code - it need because we have switch to token from ethereum if token symbol specified
|
||||
card!!.setBlockchainIDFromCard(Blockchain.Ethereum.id)
|
||||
}
|
||||
updateViews()
|
||||
refresh()
|
||||
}
|
||||
if (result.artwork != null && localStorage.checkNeedUpdateArtwork(result.artwork)) {
|
||||
|
|
@ -383,8 +387,12 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
val rate = it.priceUsd.toFloat()
|
||||
card!!.rate = rate
|
||||
card!!.rateAlter = rate
|
||||
srlLoadedWallet!!.isRefreshing = false
|
||||
updateViews()
|
||||
|
||||
requestCounter--
|
||||
if (requestCounter == 0) {
|
||||
srlLoadedWallet!!.isRefreshing = false
|
||||
updateViews()
|
||||
}
|
||||
// Log.i(TAG, "setRateInfoData $rate")
|
||||
}
|
||||
|
||||
|
|
@ -436,8 +444,10 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
if (l.compareTo(BigInteger.ZERO) == 0) {
|
||||
card!!.blockchainID = Blockchain.Ethereum.id
|
||||
card!!.addTokenToBlockchainName()
|
||||
srlLoadedWallet!!.isRefreshing = false
|
||||
updateViews()
|
||||
|
||||
requestCounter--
|
||||
if (requestCounter == 0) srlLoadedWallet!!.isRefreshing = false
|
||||
|
||||
requestInfura(ServerApiHelper.INFURA_ETH_GET_BALANCE, "")
|
||||
requestInfura(ServerApiHelper.INFURA_ETH_GET_TRANSACTION_COUNT, "")
|
||||
requestInfura(ServerApiHelper.INFURA_ETH_GET_PENDING_COUNT, "")
|
||||
|
|
@ -468,10 +478,6 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
val tmp = infuraResponse.result
|
||||
hashTX = tmp
|
||||
} catch (e: JSONException) {
|
||||
// val msg = request.getAnswer()
|
||||
// val err = msg!!.getJSONObject("error")
|
||||
// hashTX = err.getString("message")
|
||||
// LastSignStorage.setLastMessage(card!!.wallet, hashTX)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -500,12 +506,19 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
}
|
||||
}
|
||||
|
||||
updateViews()
|
||||
requestCounter--
|
||||
if (requestCounter == 0) {
|
||||
srlLoadedWallet!!.isRefreshing = false
|
||||
updateViews()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onInfuraFail(method: String, message: String) {
|
||||
srlLoadedWallet!!.isRefreshing = false
|
||||
updateViews()
|
||||
requestCounter--
|
||||
if (requestCounter == 0) {
|
||||
srlLoadedWallet!!.isRefreshing = false
|
||||
updateViews()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -513,19 +526,24 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
}
|
||||
|
||||
private fun requestElectrum(card: TangemCard, electrumRequest: ElectrumRequest) {
|
||||
requestCounter++
|
||||
serverApiHelper!!.electrumRequestData(card, electrumRequest)
|
||||
}
|
||||
|
||||
private fun requestInfura(method: String, contract: String) {
|
||||
requestCounter++
|
||||
serverApiHelper!!.infura(method, 67, card!!.wallet, contract, LastSignStorage.getTxForSend(card!!.wallet))
|
||||
}
|
||||
|
||||
private fun requestCardVerify() {
|
||||
if ((card!!.isOnlineVerified == null || !card!!.isOnlineVerified))
|
||||
serverApiHelper!!.cardVerifyAndGetInfo(card) //serverApiHelper!!.cardVerify(card)
|
||||
if ((card!!.isOnlineVerified == null || !card!!.isOnlineVerified)) {
|
||||
requestCounter++
|
||||
serverApiHelper!!.cardVerifyAndGetInfo(card)
|
||||
}
|
||||
}
|
||||
|
||||
private fun requestRateInfo(cryptoId: String) {
|
||||
requestCounter++
|
||||
serverApiHelper!!.rateInfoData(cryptoId)
|
||||
}
|
||||
|
||||
|
|
@ -683,25 +701,11 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
updateViews()
|
||||
}
|
||||
REQUEST_CODE_SEND_PAYMENT, REQUEST_CODE_RECEIVE_PAYMENT -> {
|
||||
// if (resultCode == Activity.RESULT_OK) {
|
||||
//// srlLoadedWallet!!.postDelayed({ refresh() }, 10000)
|
||||
//// srlLoadedWallet!!.isRefreshing = true
|
||||
//
|
||||
// timerRepeatRefresh = fixedRateTimer(name = "refresh", initialDelay = 2000, period = 5000) {
|
||||
// activity!!.runOnUiThread {
|
||||
// refresh()
|
||||
// Log.i("sfsf", "refresh")
|
||||
// }
|
||||
// }
|
||||
// card!!.clearInfo()
|
||||
//
|
||||
//// updateViews()
|
||||
// }
|
||||
|
||||
if (resultCode == Activity.RESULT_OK) {
|
||||
card!!.clearInfo()
|
||||
srlLoadedWallet!!.postDelayed({ this.refresh() }, 5000)
|
||||
srlLoadedWallet!!.isRefreshing = true
|
||||
card!!.clearInfo()
|
||||
updateViews()
|
||||
}
|
||||
|
||||
|
|
@ -811,18 +815,11 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
tvError.text = card!!.error
|
||||
}
|
||||
|
||||
val needResendTX = LastSignStorage.getNeedTxSend(card!!.wallet)
|
||||
|
||||
if ((card!!.message == null || card!!.message.isEmpty()) && !needResendTX) {
|
||||
if (card!!.message == null || card!!.message.isEmpty()) {
|
||||
tvMessage!!.text = ""
|
||||
tvMessage!!.visibility = View.GONE
|
||||
} else {
|
||||
if (needResendTX) {
|
||||
|
||||
} else {
|
||||
tvMessage!!.text = card!!.message
|
||||
}
|
||||
|
||||
tvMessage!!.text = card!!.message
|
||||
tvMessage!!.visibility = View.VISIBLE
|
||||
}
|
||||
|
||||
|
|
@ -841,7 +838,7 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
}
|
||||
|
||||
if (engine!!.hasBalanceInfo(card) || card!!.offlineBalance == null) {
|
||||
if (card!!.blockchain == Blockchain.Token) {
|
||||
if ((card!!.blockchain == Blockchain.Token) && (engine.getBalanceWithAlter(card) != null)) {
|
||||
val html = Html.fromHtml(engine.getBalanceWithAlter(card))
|
||||
tvBalance.text = html
|
||||
} else
|
||||
|
|
@ -859,7 +856,7 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
|
||||
tvBlockchain.text = card!!.blockchainName
|
||||
|
||||
if (card!!.hasBalanceInfo() && (card!!.balance != 0L)) {
|
||||
if (card!!.hasBalanceInfo() && (card!!.balance != 0L) && (card!!.balance != null)) {
|
||||
btnExtract.isEnabled = true
|
||||
btnExtract.backgroundTintList = activeColor
|
||||
} else {
|
||||
|
|
@ -876,13 +873,14 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
}
|
||||
|
||||
fun refresh() {
|
||||
|
||||
// Clear all card data and request again
|
||||
|
||||
srlLoadedWallet!!.isRefreshing = true
|
||||
card!!.clearInfo()
|
||||
card!!.error = null
|
||||
card!!.message = null
|
||||
card!!.isBalanceReceived = false
|
||||
|
||||
val needResendTX = LastSignStorage.getNeedTxSend(card!!.wallet)
|
||||
requestCounter = 0
|
||||
|
||||
updateViews()
|
||||
|
||||
|
|
@ -892,114 +890,38 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
|
||||
// Bitcoin
|
||||
if (card!!.blockchain == Blockchain.Bitcoin || card!!.blockchain == Blockchain.BitcoinTestNet) {
|
||||
// val data = SharedData(SharedData.COUNT_REQUEST)
|
||||
|
||||
card!!.resetFailedBalanceRequestCounter()
|
||||
card!!.setIsBalanceEqual(true)
|
||||
|
||||
requestElectrum(card!!, ElectrumRequest.checkBalance(card!!.wallet))
|
||||
requestElectrum(card!!, ElectrumRequest.listUnspent(card!!.wallet))
|
||||
|
||||
// for (i in 0 until data.allRequest) {
|
||||
// val nodeAddress = engine!!.getNextNode(card)
|
||||
// val nodePort = engine.getNextNodePort(card)
|
||||
//
|
||||
//// Log.i(TAG, nodeAddress)
|
||||
//// Log.i(TAG, nodePort.toString())
|
||||
//// Log.i(TAG, i.toString())
|
||||
//
|
||||
// // check balance
|
||||
// val connectTaskEx = UpdateWalletInfoTask(this@LoadedWallet, nodeAddress, nodePort, data)
|
||||
// connectTaskEx.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, ElectrumRequest.checkBalance(card!!.wallet))
|
||||
//
|
||||
// // list unspent input
|
||||
// val updateWalletInfoTask = UpdateWalletInfoTask(this@LoadedWallet, nodeAddress, nodePort, data)
|
||||
// updateWalletInfoTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, ElectrumRequest.listUnspent(card!!.wallet))
|
||||
// }
|
||||
|
||||
requestRateInfo("bitcoin")
|
||||
}
|
||||
|
||||
// BitcoinCash
|
||||
else if (card!!.blockchain == Blockchain.BitcoinCash || card!!.blockchain == Blockchain.BitcoinCashTestNet) {
|
||||
// val data = SharedData(SharedData.COUNT_REQUEST)
|
||||
|
||||
card!!.resetFailedBalanceRequestCounter()
|
||||
card!!.setIsBalanceEqual(true)
|
||||
|
||||
requestElectrum(card!!, ElectrumRequest.checkBalance(card!!.wallet))
|
||||
requestElectrum(card!!, ElectrumRequest.listUnspent(card!!.wallet))
|
||||
|
||||
// for (i in 0 until data.allRequest) {
|
||||
// val nodeAddress = engine!!.getNextNode(card)
|
||||
// val nodePort = engine.getNextNodePort(card)
|
||||
//
|
||||
// // check balance
|
||||
// val connectTaskEx = UpdateWalletInfoTask(this@LoadedWallet, nodeAddress, nodePort, data)
|
||||
// connectTaskEx.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, ElectrumRequest.checkBalance(card!!.wallet))
|
||||
// }
|
||||
//
|
||||
// val nodeAddress = engine!!.getNode(card)
|
||||
// val nodePort = engine.getNodePort(card)
|
||||
//
|
||||
// // list unspent input
|
||||
// val updateWalletInfoTask = UpdateWalletInfoTask(this@LoadedWallet, nodeAddress, nodePort, data)
|
||||
// updateWalletInfoTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, ElectrumRequest.listUnspent(card!!.wallet))
|
||||
|
||||
requestRateInfo("bitcoin-cash")
|
||||
}
|
||||
|
||||
// Ethereum
|
||||
else if (card!!.blockchain == Blockchain.Ethereum || card!!.blockchain == Blockchain.EthereumTestNet) {
|
||||
// val updateETH = ETHRequestTask(this@LoadedWallet, card!!.blockchain)
|
||||
//
|
||||
// val reqETH = InfuraRequest.GetBalance(card!!.wallet)
|
||||
// reqETH.id = 67
|
||||
// reqETH.setBlockchain(card!!.blockchain)
|
||||
//
|
||||
// val reqNonce = InfuraRequest.GetOutTransactionCount(card!!.wallet)
|
||||
// reqNonce.id = 67
|
||||
// reqNonce.setBlockchain(card!!.blockchain)
|
||||
//
|
||||
// updateETH.execute(reqETH, reqNonce)
|
||||
|
||||
requestInfura(ServerApiHelper.INFURA_ETH_GET_BALANCE, "")
|
||||
requestInfura(ServerApiHelper.INFURA_ETH_GET_TRANSACTION_COUNT, "")
|
||||
requestInfura(ServerApiHelper.INFURA_ETH_GET_PENDING_COUNT, "")
|
||||
|
||||
requestRateInfo("ethereum")
|
||||
}
|
||||
|
||||
// Token
|
||||
else if (card!!.blockchain == Blockchain.Token) {
|
||||
|
||||
// val updateETH = ETHRequestTask(this@LoadedWallet, card!!.blockchain)
|
||||
//
|
||||
// val reqETH = InfuraRequest.GetTokenBalance(card!!.wallet, engine!!.getContractAddress(card), engine.getTokenDecimals(card))
|
||||
// reqETH.id = 67
|
||||
// reqETH.setBlockchain(card!!.blockchain)
|
||||
//
|
||||
// val reqBalance = InfuraRequest.GetBalance(card!!.wallet)
|
||||
// reqBalance.id = 67
|
||||
// reqBalance.setBlockchain(card!!.blockchain)
|
||||
//
|
||||
// val reqNonce = InfuraRequest.GetOutTransactionCount(card!!.wallet)
|
||||
// reqNonce.id = 67
|
||||
// reqNonce.setBlockchain(card!!.blockchain)
|
||||
//
|
||||
// updateETH.execute(reqETH, reqNonce, reqBalance)
|
||||
|
||||
requestInfura(ServerApiHelper.INFURA_ETH_CALL, engine.getContractAddress(card))
|
||||
|
||||
requestRateInfo("ethereum")
|
||||
}
|
||||
|
||||
//if (needResendTX)
|
||||
//sendTransaction(LastSignStorage.getTxForSend(card!!.wallet))
|
||||
|
||||
// if (btnExtract.isEnabled)
|
||||
|
||||
|
||||
}
|
||||
|
||||
fun prepareResultIntent(): Intent {
|
||||
|
|
@ -1077,37 +999,6 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
}
|
||||
}
|
||||
|
||||
private fun sendTransaction(tx: String) {
|
||||
val engine = CoinEngineFactory.create(card!!.blockchain)
|
||||
if (card!!.blockchain == Blockchain.Ethereum || card!!.blockchain == Blockchain.EthereumTestNet || card!!.blockchain == Blockchain.Token) {
|
||||
// val task = ETHRequestTask(this@LoadedWallet, card!!.blockchain)
|
||||
// val req = InfuraRequest.SendTransaction(card!!.wallet, tx)
|
||||
// req.id = 67
|
||||
// req.setBlockchain(card!!.blockchain)
|
||||
// task.execute(req)
|
||||
|
||||
requestInfura(ServerApiHelper.INFURA_ETH_SEND_RAW_TRANSACTION, "")
|
||||
|
||||
} else if (card!!.blockchain == Blockchain.Bitcoin || card!!.blockchain == Blockchain.BitcoinTestNet) {
|
||||
// val nodeAddress = engine!!.getNode(card)
|
||||
// val nodePort = engine.getNodePort(card)
|
||||
//
|
||||
// val connectTask = UpdateWalletInfoTask(this@LoadedWallet, nodeAddress, nodePort)
|
||||
// connectTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, ElectrumRequest.broadcast(card!!.wallet, tx))
|
||||
|
||||
requestElectrum(card!!, ElectrumRequest.broadcast(card!!.wallet, tx))
|
||||
|
||||
} else if (card!!.blockchain == Blockchain.BitcoinCash || card!!.blockchain == Blockchain.BitcoinCashTestNet) {
|
||||
// val nodeAddress = engine!!.getNode(card)
|
||||
// val nodePort = engine.getNodePort(card)
|
||||
//
|
||||
// val connectTask = UpdateWalletInfoTask(this@LoadedWallet, nodeAddress, nodePort)
|
||||
// connectTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, ElectrumRequest.broadcast(card!!.wallet, tx))
|
||||
|
||||
requestElectrum(card!!, ElectrumRequest.broadcast(card!!.wallet, tx))
|
||||
}
|
||||
}
|
||||
|
||||
private fun startSwapPINActivity() {
|
||||
val intent = Intent(context, PinSwapActivity::class.java)
|
||||
intent.putExtra("UID", card!!.uid)
|
||||
|
|
|
|||
|
|
@ -289,7 +289,6 @@ class VerifyCard : Fragment(), NfcAdapter.ReaderCallback {
|
|||
tvCardRegistredDate.text = card!!.personalizationDateTimeDescription
|
||||
tvBlockchain.text = card!!.blockchainName
|
||||
tvValidationNode.text = card!!.validationNodeDescription
|
||||
tvInputs.text = card!!.inputsDescription
|
||||
|
||||
when {
|
||||
card!!.lastInputDescription.contains("awaiting") -> tvInputs.setTextColor(ContextCompat.getColor(context!!, R.color.not_confirmed))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue