Updated on 2026-08-14
This commit is contained in:
commit
0a2272b01d
7 changed files with 142 additions and 100 deletions
|
|
@ -157,7 +157,7 @@ public class ServerApiElectrum {
|
||||||
Log.e(TAG, "electrumRequestData " + electrumRequest.getMethod() + " onComplete, answerData==null");
|
Log.e(TAG, "electrumRequestData " + electrumRequest.getMethod() + " onComplete, answerData==null");
|
||||||
}
|
}
|
||||||
Log.e(TAG, String.format("%d requests left in processing",requestsCount));
|
Log.e(TAG, String.format("%d requests left in processing",requestsCount));
|
||||||
if (electrumRequest.answerData != null) {
|
if (electrumRequest.answerData != null && electrumRequest.getError()==null) {
|
||||||
electrumRequestDataListener.onSuccess(electrumRequest);
|
electrumRequestDataListener.onSuccess(electrumRequest);
|
||||||
} else {
|
} else {
|
||||||
// if( error==null || error.isEmpty() ) setErrorOccurred(ctx.getString(R.string.cannot_obtain_data_from_blockchain));
|
// if( error==null || error.isEmpty() ) setErrorOccurred(ctx.getString(R.string.cannot_obtain_data_from_blockchain));
|
||||||
|
|
@ -172,6 +172,7 @@ public class ServerApiElectrum {
|
||||||
String host;
|
String host;
|
||||||
int port;
|
int port;
|
||||||
String proto;
|
String proto;
|
||||||
|
electrumRequest.setError(null);
|
||||||
// todo - get available URL list from coinEngine, remove if( ctx.getBlockchain()==...)
|
// todo - get available URL list from coinEngine, remove if( ctx.getBlockchain()==...)
|
||||||
if (ctx.getBlockchain() == Blockchain.BitcoinTestNet) {
|
if (ctx.getBlockchain() == Blockchain.BitcoinTestNet) {
|
||||||
BitcoinNodeTestNet bitcoinNodeTestNet = BitcoinNodeTestNet.values()[new Random().nextInt(BitcoinNodeTestNet.values().length)];
|
BitcoinNodeTestNet bitcoinNodeTestNet = BitcoinNodeTestNet.values()[new Random().nextInt(BitcoinNodeTestNet.values().length)];
|
||||||
|
|
|
||||||
|
|
@ -18,11 +18,19 @@ public class BtcData extends CoinData {
|
||||||
private Long balanceConfirmed, balanceUnconfirmed;
|
private Long balanceConfirmed, balanceUnconfirmed;
|
||||||
|
|
||||||
public String getUnspentInputsDescription() {
|
public String getUnspentInputsDescription() {
|
||||||
int gatheredUnspents = 0;
|
try {
|
||||||
for (int i=0; i<unspentTransactions.size(); i++) {
|
int gatheredUnspents = 0;
|
||||||
if (unspentTransactions.get(i).Raw.length() > 1) gatheredUnspents++;
|
if( unspentTransactions==null ) return "";
|
||||||
|
for (int i = 0; i < unspentTransactions.size(); i++) {
|
||||||
|
if (unspentTransactions.get(i).Raw != null && unspentTransactions.get(i).Raw.length() > 1) gatheredUnspents++;
|
||||||
|
}
|
||||||
|
return String.valueOf(unspentTransactions.size()) + " unspents (" + String.valueOf(gatheredUnspents) + " received)";
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
return String.valueOf(unspentTransactions.size()) + " unspents (" + String.valueOf(gatheredUnspents) + " received)";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class UnspentTransaction {
|
public static class UnspentTransaction {
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,7 @@ public class EthEngine extends CoinEngine {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getBalanceCurrency() {
|
public String getBalanceCurrency() {
|
||||||
return "ETH";
|
return Blockchain.Ethereum.getCurrency();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -101,7 +101,7 @@ public class EthEngine extends CoinEngine {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getFeeCurrency() {
|
public String getFeeCurrency() {
|
||||||
return "ETH";
|
return Blockchain.Ethereum.getCurrency();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isNeedCheckNode() {
|
public boolean isNeedCheckNode() {
|
||||||
|
|
@ -445,11 +445,11 @@ public class EthEngine extends CoinEngine {
|
||||||
tx.signature = new ECDSASignatureETH(r, s);
|
tx.signature = new ECDSASignatureETH(r, s);
|
||||||
int v = tx.BruteRecoveryID2(tx.signature, for_hash, pbKey);
|
int v = tx.BruteRecoveryID2(tx.signature, for_hash, pbKey);
|
||||||
if (v != 27 && v != 28) {
|
if (v != 27 && v != 28) {
|
||||||
Log.e("ETH", "invalid v");
|
Log.e(TAG, "invalid v");
|
||||||
throw new Exception("Error in EthEngine - invalid v");
|
throw new Exception("Error in EthEngine - invalid v");
|
||||||
}
|
}
|
||||||
tx.signature.v = (byte) v;
|
tx.signature.v = (byte) v;
|
||||||
Log.e("ETH_v", String.valueOf(v));
|
Log.e(TAG, "ETH_v: " +String.valueOf(v));
|
||||||
|
|
||||||
byte[] txForSend = tx.getEncoded();
|
byte[] txForSend = tx.getEncoded();
|
||||||
notifyOnNeedSendPayment(txForSend);
|
notifyOnNeedSendPayment(txForSend);
|
||||||
|
|
|
||||||
|
|
@ -109,7 +109,7 @@ public class TokenEngine extends CoinEngine {
|
||||||
if (coinData.getBalanceInInternalUnits().notZero()) {
|
if (coinData.getBalanceInInternalUnits().notZero()) {
|
||||||
return currency;
|
return currency;
|
||||||
} else {
|
} else {
|
||||||
return "ETH";
|
return Blockchain.Ethereum.getCurrency();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return currency;
|
return currency;
|
||||||
|
|
@ -128,7 +128,7 @@ public class TokenEngine extends CoinEngine {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getFeeCurrency() {
|
public String getFeeCurrency() {
|
||||||
return "ETH";
|
return Blockchain.Ethereum.getCurrency();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -227,7 +227,7 @@ public class TokenEngine extends CoinEngine {
|
||||||
public Amount convertToAmount(InternalAmount internalAmount) throws Exception {
|
public Amount convertToAmount(InternalAmount internalAmount) throws Exception {
|
||||||
if (internalAmount.getCurrency().equals("wei")) {
|
if (internalAmount.getCurrency().equals("wei")) {
|
||||||
BigDecimal d = internalAmount.divide(new BigDecimal("1000000000000000000"), getEthDecimals(), RoundingMode.DOWN);
|
BigDecimal d = internalAmount.divide(new BigDecimal("1000000000000000000"), getEthDecimals(), RoundingMode.DOWN);
|
||||||
return new Amount(d, "ETH");
|
return new Amount(d, Blockchain.Ethereum.getCurrency());
|
||||||
} else if (internalAmount.getCurrency().equals(ctx.getCard().getTokenSymbol())) {
|
} else if (internalAmount.getCurrency().equals(ctx.getCard().getTokenSymbol())) {
|
||||||
BigDecimal p = new BigDecimal(10);
|
BigDecimal p = new BigDecimal(10);
|
||||||
p = p.pow(getTokenDecimals());
|
p = p.pow(getTokenDecimals());
|
||||||
|
|
@ -244,7 +244,7 @@ public class TokenEngine extends CoinEngine {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InternalAmount convertToInternalAmount(Amount amount) throws Exception {
|
public InternalAmount convertToInternalAmount(Amount amount) throws Exception {
|
||||||
if (amount.getCurrency().equals("ETH")) {
|
if (amount.getCurrency().equals(Blockchain.Ethereum.getCurrency())) {
|
||||||
BigDecimal d = amount.multiply(new BigDecimal("1000000000000000000"));
|
BigDecimal d = amount.multiply(new BigDecimal("1000000000000000000"));
|
||||||
return new InternalAmount(d, "wei");
|
return new InternalAmount(d, "wei");
|
||||||
} else if (amount.getCurrency().equals(ctx.getCard().getTokenSymbol())) {
|
} else if (amount.getCurrency().equals(ctx.getCard().getTokenSymbol())) {
|
||||||
|
|
@ -325,7 +325,7 @@ public class TokenEngine extends CoinEngine {
|
||||||
try {
|
try {
|
||||||
if (amount.getCurrency().equals(ctx.getCard().tokenSymbol)) {
|
if (amount.getCurrency().equals(ctx.getCard().tokenSymbol)) {
|
||||||
balance = convertToAmount(coinData.getBalanceInInternalUnits());
|
balance = convertToAmount(coinData.getBalanceInInternalUnits());
|
||||||
} else if (amount.getCurrency().equals("ETH") && coinData.getBalanceInInternalUnits().isZero()) {
|
} else if (amount.getCurrency().equals(Blockchain.Ethereum.getCurrency()) && coinData.getBalanceInInternalUnits().isZero()) {
|
||||||
balance = convertToAmount(coinData.getBalanceAlterInInternalUnits());
|
balance = convertToAmount(coinData.getBalanceAlterInInternalUnits());
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -342,7 +342,7 @@ public class TokenEngine extends CoinEngine {
|
||||||
if (!hasBalanceInfo()) return false;
|
if (!hasBalanceInfo()) return false;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Amount balance = convertToAmount(coinData.getBalanceAlterInInternalUnits());
|
Amount balanceETH = convertToAmount(coinData.getBalanceAlterInInternalUnits());
|
||||||
|
|
||||||
if (fee == null || amount == null || fee.isZero() || amount.isZero())
|
if (fee == null || amount == null || fee.isZero() || amount.isZero())
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -350,22 +350,20 @@ public class TokenEngine extends CoinEngine {
|
||||||
|
|
||||||
if (amount.getCurrency().equals(ctx.getCard().tokenSymbol)) {
|
if (amount.getCurrency().equals(ctx.getCard().tokenSymbol)) {
|
||||||
// token transaction
|
// token transaction
|
||||||
if (fee.compareTo(balance) > 0)
|
if (fee.compareTo(balanceETH) > 0)
|
||||||
return false;
|
return false;
|
||||||
} else if (amount.getCurrency().equals("ETH") && coinData.getBalanceInInternalUnits().isZero()) {
|
} else if (amount.getCurrency().equals(Blockchain.Ethereum.getCurrency()) && coinData.getBalanceInInternalUnits().isZero()) {
|
||||||
// standard ETH transaction
|
// standard ETH transaction
|
||||||
try {
|
// try {
|
||||||
BigDecimal cardBalance = getBalance();
|
if (isFeeIncluded && (amount.compareTo(balanceETH) > 0 || fee.compareTo(balanceETH) > 0))
|
||||||
|
|
||||||
if (isFeeIncluded && amount.compareTo(cardBalance) > 0)
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!isFeeIncluded && amount.add(fee).compareTo(cardBalance) > 0)
|
if (!isFeeIncluded && amount.add(fee).compareTo(balanceETH) > 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
} catch (NumberFormatException e) {
|
// } catch (NumberFormatException e) {
|
||||||
e.printStackTrace();
|
// e.printStackTrace();
|
||||||
}
|
// }
|
||||||
} else
|
} else
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
@ -434,7 +432,7 @@ public class TokenEngine extends CoinEngine {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SignTask.PaymentToSign constructPayment(Amount amountValue, Amount feeValue, boolean IncFee, String targetAddress) throws Exception {
|
public SignTask.PaymentToSign constructPayment(Amount amountValue, Amount feeValue, boolean IncFee, String targetAddress) throws Exception {
|
||||||
if (amountValue.getCurrency().equals("ETH")) {
|
if (amountValue.getCurrency().equals(Blockchain.Ethereum.getCurrency())) {
|
||||||
return constructPaymentETH(feeValue, amountValue, IncFee, targetAddress);
|
return constructPaymentETH(feeValue, amountValue, IncFee, targetAddress);
|
||||||
} else {
|
} else {
|
||||||
return constructPaymentToken(feeValue, amountValue, IncFee, targetAddress);
|
return constructPaymentToken(feeValue, amountValue, IncFee, targetAddress);
|
||||||
|
|
@ -511,11 +509,11 @@ public class TokenEngine extends CoinEngine {
|
||||||
tx.signature = new ECDSASignatureETH(r, s);
|
tx.signature = new ECDSASignatureETH(r, s);
|
||||||
int v = tx.BruteRecoveryID2(tx.signature, for_hash, pbKey);
|
int v = tx.BruteRecoveryID2(tx.signature, for_hash, pbKey);
|
||||||
if (v != 27 && v != 28) {
|
if (v != 27 && v != 28) {
|
||||||
Log.e("ETH", "invalid v");
|
Log.e(TAG, "invalid v");
|
||||||
throw new Exception("Error in EthEngine - invalid v");
|
throw new Exception("Error in EthEngine - invalid v");
|
||||||
}
|
}
|
||||||
tx.signature.v = (byte) v;
|
tx.signature.v = (byte) v;
|
||||||
Log.e("ETH_v", String.valueOf(v));
|
Log.e(TAG,"ETH_v "+ String.valueOf(v));
|
||||||
|
|
||||||
byte[] txForSend = tx.getEncoded();
|
byte[] txForSend = tx.getEncoded();
|
||||||
notifyOnNeedSendPayment(txForSend);
|
notifyOnNeedSendPayment(txForSend);
|
||||||
|
|
@ -619,11 +617,11 @@ public class TokenEngine extends CoinEngine {
|
||||||
tx.signature = new ECDSASignatureETH(r, s);
|
tx.signature = new ECDSASignatureETH(r, s);
|
||||||
int v = tx.BruteRecoveryID2(tx.signature, for_hash, pbKey);
|
int v = tx.BruteRecoveryID2(tx.signature, for_hash, pbKey);
|
||||||
if (v != 27 && v != 28) {
|
if (v != 27 && v != 28) {
|
||||||
Log.e("ETH", "invalid v");
|
Log.e(TAG, "invalid v");
|
||||||
throw new Exception("Error in EthEngine - invalid v");
|
throw new Exception("Error in EthEngine - invalid v");
|
||||||
}
|
}
|
||||||
tx.signature.v = (byte) v;
|
tx.signature.v = (byte) v;
|
||||||
Log.e("ETH_v", String.valueOf(v));
|
Log.e(TAG,"ETH_v: "+ String.valueOf(v));
|
||||||
|
|
||||||
byte[] txForSend = tx.getEncoded();
|
byte[] txForSend = tx.getEncoded();
|
||||||
notifyOnNeedSendPayment(txForSend);
|
notifyOnNeedSendPayment(txForSend);
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,7 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
||||||
|
|
||||||
amount = CoinEngine.Amount(intent.getStringExtra(Constant.EXTRA_AMOUNT), intent.getStringExtra(Constant.EXTRA_AMOUNT_CURRENCY))
|
amount = CoinEngine.Amount(intent.getStringExtra(Constant.EXTRA_AMOUNT), intent.getStringExtra(Constant.EXTRA_AMOUNT_CURRENCY))
|
||||||
|
|
||||||
if (ctx.blockchain == Blockchain.Token && amount.currency != "ETH")
|
if (ctx.blockchain == Blockchain.Token && amount.currency != Blockchain.Ethereum.currency)
|
||||||
tvIncFee.visibility = View.INVISIBLE
|
tvIncFee.visibility = View.INVISIBLE
|
||||||
else
|
else
|
||||||
tvIncFee.visibility = View.VISIBLE
|
tvIncFee.visibility = View.VISIBLE
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ class PreparePaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
||||||
tvBalance.text = html
|
tvBalance.text = html
|
||||||
|
|
||||||
//TODO - to engine
|
//TODO - to engine
|
||||||
if (ctx.blockchain == Blockchain.Token && engine.balance.currency!="ETH") {
|
if (ctx.blockchain == Blockchain.Token && engine.balance.currency!=Blockchain.Ethereum.currency) {
|
||||||
rgIncFee!!.visibility = View.INVISIBLE
|
rgIncFee!!.visibility = View.INVISIBLE
|
||||||
} else {
|
} else {
|
||||||
rgIncFee!!.visibility = View.VISIBLE
|
rgIncFee!!.visibility = View.VISIBLE
|
||||||
|
|
|
||||||
|
|
@ -55,6 +55,7 @@ import org.greenrobot.eventbus.EventBus
|
||||||
import org.greenrobot.eventbus.Subscribe
|
import org.greenrobot.eventbus.Subscribe
|
||||||
import java.io.InputStream
|
import java.io.InputStream
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
import kotlin.concurrent.timerTask
|
||||||
|
|
||||||
class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notifications, SharedPreferences.OnSharedPreferenceChangeListener {
|
class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notifications, SharedPreferences.OnSharedPreferenceChangeListener {
|
||||||
companion object {
|
companion object {
|
||||||
|
|
@ -83,14 +84,12 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
||||||
set(value) {
|
set(value) {
|
||||||
field = value
|
field = value
|
||||||
LOG.i(TAG, "requestCounter, set $field")
|
LOG.i(TAG, "requestCounter, set $field")
|
||||||
if (field <= 0 && srl != null && srl.isRefreshing) {
|
if (field <= 0) {
|
||||||
LOG.e(TAG, "+++++++++++ FINISH REFRESH")
|
LOG.e(TAG, "+++++++++++ FINISH REFRESH")
|
||||||
if (srl != null) srl!!.isRefreshing = false
|
if (srl != null && srl.isRefreshing) srl.isRefreshing = false
|
||||||
//updateViews()
|
//updateViews()
|
||||||
}
|
} else if (srl != null && !srl.isRefreshing) srl.isRefreshing = true
|
||||||
}
|
}
|
||||||
private var timerRepeatRefresh: Timer? = null
|
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
nfcManager = NfcManager(activity, this)
|
nfcManager = NfcManager(activity, this)
|
||||||
|
|
@ -279,8 +278,10 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
||||||
override fun onPause() {
|
override fun onPause() {
|
||||||
super.onPause()
|
super.onPause()
|
||||||
nfcManager.onPause()
|
nfcManager.onPause()
|
||||||
if (timerRepeatRefresh != null)
|
if (timerHideErrorAndMessage != null) {
|
||||||
timerRepeatRefresh!!.cancel()
|
timerHideErrorAndMessage!!.cancel()
|
||||||
|
timerHideErrorAndMessage = null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onStart() {
|
override fun onStart() {
|
||||||
|
|
@ -302,7 +303,10 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
||||||
@Subscribe
|
@Subscribe
|
||||||
fun onTransactionFinishWithSuccess(transactionFinishWithSuccess: TransactionFinishWithSuccess) {
|
fun onTransactionFinishWithSuccess(transactionFinishWithSuccess: TransactionFinishWithSuccess) {
|
||||||
ctx.message = transactionFinishWithSuccess.message
|
ctx.message = transactionFinishWithSuccess.message
|
||||||
|
ctx.coinData.clearInfo()
|
||||||
updateViews()
|
updateViews()
|
||||||
|
srl?.isRefreshing=true
|
||||||
|
srl?.postDelayed({ refresh() }, 5000)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
|
|
@ -512,7 +516,7 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updateViews() {
|
fun updateViews() {
|
||||||
if (activity == null || !UtilHelper.isOnline(activity!!)) return
|
if (activity == null) return
|
||||||
|
|
||||||
if (timerHideErrorAndMessage != null) {
|
if (timerHideErrorAndMessage != null) {
|
||||||
timerHideErrorAndMessage!!.cancel()
|
timerHideErrorAndMessage!!.cancel()
|
||||||
|
|
@ -535,6 +539,21 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
||||||
tvMessage.visibility = View.VISIBLE
|
tvMessage.visibility = View.VISIBLE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (tvError.visibility == View.VISIBLE || tvMessage.visibility == View.VISIBLE) {
|
||||||
|
timerHideErrorAndMessage = Timer()
|
||||||
|
timerHideErrorAndMessage!!.schedule(
|
||||||
|
timerTask {
|
||||||
|
activity?.runOnUiThread {
|
||||||
|
tvMessage?.visibility = View.GONE
|
||||||
|
tvError?.visibility = View.GONE
|
||||||
|
// clear only already viewed messages
|
||||||
|
if (tvMessage.text == ctx.message) ctx.message = null
|
||||||
|
if (tvError.text == ctx.error) ctx.error = null
|
||||||
|
}
|
||||||
|
},
|
||||||
|
5000)
|
||||||
|
}
|
||||||
|
|
||||||
if (srl!!.isRefreshing) {
|
if (srl!!.isRefreshing) {
|
||||||
tvBalanceLine1.setTextColor(resources.getColor(R.color.primary))
|
tvBalanceLine1.setTextColor(resources.getColor(R.color.primary))
|
||||||
tvBalanceLine1.text = getString(R.string.verifying_in_blockchain)
|
tvBalanceLine1.text = getString(R.string.verifying_in_blockchain)
|
||||||
|
|
@ -599,63 +618,61 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
||||||
|
|
||||||
updateViews()
|
updateViews()
|
||||||
|
|
||||||
|
// Bitcoin
|
||||||
|
// Litecoin
|
||||||
|
// BitcoinCash
|
||||||
|
if (ctx.blockchain == Blockchain.Bitcoin || ctx.blockchain == Blockchain.BitcoinTestNet ||
|
||||||
|
ctx.blockchain == Blockchain.Litecoin || ctx.blockchain == Blockchain.BitcoinCash) {
|
||||||
|
ctx.coinData.setIsBalanceEqual(true)
|
||||||
|
}
|
||||||
|
|
||||||
requestVerifyAndGetInfo()
|
requestVerifyAndGetInfo()
|
||||||
|
|
||||||
val coinEngine = CoinEngineFactory.create(ctx)
|
requestBalanceAndUnspentTransactions()
|
||||||
requestCounter++
|
|
||||||
coinEngine!!.requestBalanceAndUnspentTransactions(
|
requestRateInfo()
|
||||||
object : CoinEngine.BlockchainRequestsCallbacks {
|
|
||||||
override fun onComplete(success: Boolean) {
|
if( requestCounter==0 )
|
||||||
LOG.i(TAG, "requestBalanceAndUnspentTransactions onComplete: " + success.toString() + ", request counter " + requestCounter.toString())
|
{
|
||||||
if (activity == null || !UtilHelper.isOnline(activity!!)) return
|
// if no connection and no requests posted
|
||||||
requestCounter--
|
srl?.isRefreshing = false
|
||||||
if (!success) {
|
updateViews()
|
||||||
LOG.e(TAG, "ctx.error: " + ctx.error)
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun requestBalanceAndUnspentTransactions() {
|
||||||
|
if (UtilHelper.isOnline(context as Activity)) {
|
||||||
|
val coinEngine = CoinEngineFactory.create(ctx)
|
||||||
|
requestCounter++
|
||||||
|
coinEngine!!.requestBalanceAndUnspentTransactions(
|
||||||
|
object : CoinEngine.BlockchainRequestsCallbacks {
|
||||||
|
override fun onComplete(success: Boolean) {
|
||||||
|
LOG.i(TAG, "requestBalanceAndUnspentTransactions onComplete: " + success.toString() + ", request counter " + requestCounter.toString())
|
||||||
|
if (activity == null) return
|
||||||
|
requestCounter--
|
||||||
|
if (!success) {
|
||||||
|
LOG.e(TAG, "requestBalanceAndUnspentTransactions ctx.error: " + ctx.error)
|
||||||
|
}
|
||||||
|
// if (!UtilHelper.isOnline(activity!!)) {
|
||||||
|
// ctx.error = getString(R.string.no_connection)
|
||||||
|
// }
|
||||||
|
updateViews()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onProgress() {
|
||||||
|
if (activity == null) return
|
||||||
|
LOG.i(TAG, "requestBalanceAndUnspentTransactions onProgress")
|
||||||
|
updateViews()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun allowAdvance(): Boolean {
|
||||||
|
return UtilHelper.isOnline(context as Activity)
|
||||||
}
|
}
|
||||||
updateViews()
|
|
||||||
}
|
}
|
||||||
|
)
|
||||||
override fun onProgress() {
|
} else {
|
||||||
if (activity == null || !UtilHelper.isOnline(activity!!)) return
|
ctx.error = getString(R.string.no_connection)
|
||||||
LOG.i(TAG, "requestBalanceAndUnspentTransactions onProgress")
|
updateViews()
|
||||||
updateViews()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun allowAdvance(): Boolean {
|
|
||||||
return UtilHelper.isOnline(context as Activity)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
// TODO - move requestRateInfo to CoinEngine
|
|
||||||
// Bitcoin
|
|
||||||
if (ctx.blockchain == Blockchain.Bitcoin || ctx.blockchain == Blockchain.BitcoinTestNet) {
|
|
||||||
ctx.coinData.setIsBalanceEqual(true)
|
|
||||||
|
|
||||||
requestRateInfo("bitcoin")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Litecoin
|
|
||||||
if (ctx.blockchain == Blockchain.Litecoin) {
|
|
||||||
ctx.coinData.setIsBalanceEqual(true)
|
|
||||||
|
|
||||||
requestRateInfo("litecoin")
|
|
||||||
}
|
|
||||||
|
|
||||||
// BitcoinCash
|
|
||||||
else if (ctx.blockchain == Blockchain.BitcoinCash) {
|
|
||||||
ctx.coinData.setIsBalanceEqual(true)
|
|
||||||
requestRateInfo("bitcoin-cash")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ethereum
|
|
||||||
else if (ctx.blockchain == Blockchain.Ethereum || ctx.blockchain == Blockchain.EthereumTestNet) {
|
|
||||||
requestRateInfo("ethereum")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Token
|
|
||||||
else if (ctx.blockchain == Blockchain.Token) {
|
|
||||||
requestRateInfo("ethereum")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -667,20 +684,38 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
||||||
serverApiTangem.cardVerifyAndGetInfo(ctx.card)
|
serverApiTangem.cardVerifyAndGetInfo(ctx.card)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(activity, getString(R.string.no_connection), Toast.LENGTH_SHORT).show()
|
ctx.error = getString(R.string.no_connection)
|
||||||
LOG.e(TAG, "+++++++++++ Hide refresh 1")
|
updateViews()
|
||||||
srl?.isRefreshing = false
|
//Toast.makeText(activity, getString(R.string.no_connection), Toast.LENGTH_SHORT).show()
|
||||||
|
//LOG.e(TAG, "+++++++++++ Hide refresh 1")
|
||||||
|
//srl?.isRefreshing = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun requestRateInfo(cryptoId: String) {
|
private fun requestRateInfo() {
|
||||||
if (UtilHelper.isOnline(context as Activity)) {
|
if (UtilHelper.isOnline(context as Activity)) {
|
||||||
LOG.i(TAG, "requestRateInfo")
|
LOG.i(TAG, "requestRateInfo")
|
||||||
|
|
||||||
|
// TODO - move requestRateInfo to CoinEngine
|
||||||
|
val cryptoId: String = when (ctx.blockchain) {
|
||||||
|
Blockchain.Bitcoin -> "bitcoin"
|
||||||
|
Blockchain.BitcoinTestNet -> "bitcoin"
|
||||||
|
Blockchain.Ethereum -> "ethereum"
|
||||||
|
Blockchain.EthereumTestNet -> "ethereum"
|
||||||
|
Blockchain.Token -> "ethereum"
|
||||||
|
Blockchain.BitcoinCash -> "bitcoin-cash"
|
||||||
|
Blockchain.Litecoin -> "litecoin"
|
||||||
|
else -> {
|
||||||
|
throw Exception("Can''t get rate for blockchain " + ctx.blockchainName)
|
||||||
|
}
|
||||||
|
}
|
||||||
serverApiCommon.rateInfoData(cryptoId)
|
serverApiCommon.rateInfoData(cryptoId)
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(activity, getString(R.string.no_connection), Toast.LENGTH_SHORT).show()
|
ctx.error = getString(R.string.no_connection)
|
||||||
LOG.e(TAG, "+++++++++++ Hide refresh 2")
|
updateViews()
|
||||||
srl?.isRefreshing = false
|
// Toast.makeText(activity, getString(R.string.no_connection), Toast.LENGTH_SHORT).show()
|
||||||
|
// LOG.e(TAG, "+++++++++++ Hide refresh 2")
|
||||||
|
// srl?.isRefreshing = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue