Updated on 2026-08-14

This commit is contained in:
Tangem 2019-01-29 09:14:21 +03:00
parent 06e972b8db
commit fa92ff45c8
11 changed files with 80 additions and 13 deletions

View file

@ -54,6 +54,7 @@ import io.reactivex.schedulers.Schedulers;
* {@link ResponseListener}.onSuccess(...) callback
*/
public class ServerApiElectrum {
public static final String ERROR_STARTS_WITH_CODE_32601 = "{\"code\":-32601,";
private static String TAG = ServerApiElectrum.class.getSimpleName();
/**
@ -248,6 +249,12 @@ public class ServerApiElectrum {
electrumRequest.port = port;
if (electrumRequest.answerData != null) {
Log.i(TAG, ">> " + electrumRequest.answerData);
if( (electrumRequest.getError()!=null && electrumRequest.getError().startsWith(ERROR_STARTS_WITH_CODE_32601)) )
{
// method unknown error???
electrumRequest.setError(App.getInstance().getString(R.string.cannot_obtain_data_from_blockchain));
electrumRequest.answerData=null;
}
} else {
electrumRequest.setError(App.getInstance().getString(R.string.cannot_obtain_data_from_blockchain_no_answer));
Log.i(TAG, ">> <NULL>");
@ -331,6 +338,12 @@ public class ServerApiElectrum {
electrumRequest.answerData = in.readLine();
if (electrumRequest.answerData != null) {
Log.i(TAG, ">> " + electrumRequest.answerData);
if( (electrumRequest.getError()!=null && electrumRequest.getError().startsWith(ERROR_STARTS_WITH_CODE_32601)) )
{
// method unknown error???
electrumRequest.setError(App.getInstance().getString(R.string.cannot_obtain_data_from_blockchain));
electrumRequest.answerData=null;
}
} else {
electrumRequest.setError(App.getInstance().getString(R.string.cannot_obtain_data_from_blockchain_no_answer));
Log.i(TAG, ">> <NULL>");

View file

@ -21,7 +21,6 @@ import java.util.Locale;
public abstract class CoinEngine {
public static class InternalAmount extends BigDecimal {
private String currency;
@ -339,4 +338,28 @@ public abstract class CoinEngine {
* @throws Exception if something goes wrong
*/
public abstract void requestSendTransaction(BlockchainRequestsCallbacks blockchainRequestsCallbacks, byte[] txForSend) throws Exception;
/**
* @return true if blockchain need multiple lines to show balance (e.g. need show additional balance information, Token count for example)
*/
public boolean needMultipleLinesForBalance() {
return false;
}
/**
* @return true to allow user select fee level - min, normal or priority
*/
public boolean allowSelectFeeLevel() {
return true;
}
/**
* @return true to allow user select include or exclude fee
*/
public boolean allowSelectFeeInclusion() {
return true;
}
}

View file

@ -84,6 +84,9 @@ public class TangemContext {
public void setError(String error) {
this.error = error;
}
public void setError(int valueId) {
this.error = getString(valueId);
}
public String getError() {
return error;

View file

@ -780,4 +780,8 @@ public class BtcCashEngine extends CoinEngine {
}
@Override
public boolean allowSelectFeeLevel() {
return false;
}
}

View file

@ -609,6 +609,7 @@ public class BtcEngine extends CoinEngine {
public void onFail(ElectrumRequest electrumRequest) {
Log.i(TAG, "onFail: "+electrumRequest.getMethod()+" "+electrumRequest.getError());
ctx.setError(electrumRequest.getError());
// ctx.setError(R.string.cannot_obtain_data_from_blockchain);
if (serverApiElectrum.isRequestsSequenceCompleted()) {
blockchainRequestsCallbacks.onComplete(false);//serverApiElectrum.isErrorOccurred(), serverApiElectrum.getError());
}else{

View file

@ -557,4 +557,9 @@ public class LtcEngine extends BtcEngine {
serverApiElectrum.requestData(ctx, ElectrumRequest.getFee());
}
@Override
public boolean allowSelectFeeLevel() {
return false;
}
}

View file

@ -238,4 +238,13 @@ public class RskTokenEngine extends TokenEngine {
}
@Override
public boolean needMultipleLinesForBalance() {
return true;
}
@Override
public boolean allowSelectFeeInclusion() {
return getBalance().getCurrency().equals(Blockchain.Rootstock.getCurrency());
}
}

View file

@ -812,4 +812,13 @@ public class TokenEngine extends CoinEngine {
}
@Override
public boolean needMultipleLinesForBalance() {
return true;
}
@Override
public boolean allowSelectFeeInclusion() {
return getBalance().getCurrency().equals(Blockchain.Ethereum.getCurrency());
}
}

View file

@ -61,10 +61,10 @@ class ConfirmTransactionActivity : AppCompatActivity(), NfcAdapter.ReaderCallbac
amount = CoinEngine.Amount(intent.getStringExtra(Constant.EXTRA_AMOUNT), intent.getStringExtra(Constant.EXTRA_AMOUNT_CURRENCY))
if (ctx.blockchain == Blockchain.Token && amount.currency != Blockchain.Ethereum.currency)
tvIncFee.visibility = View.INVISIBLE
else
if (engine.allowSelectFeeInclusion())
tvIncFee.visibility = View.VISIBLE
else
tvIncFee.visibility = View.INVISIBLE
etAmount.setText(amount.toValueString())
tvCurrency.text = engine.balanceCurrency
@ -74,8 +74,9 @@ class ConfirmTransactionActivity : AppCompatActivity(), NfcAdapter.ReaderCallbac
btnSend.visibility = View.INVISIBLE
val allowFeeLevelSelection = engine!!.allowSelectFeeLevel()
for (lol in rgFee.touchables) {
lol.isEnabled = !(ctx.blockchain == Blockchain.Ethereum || ctx.blockchain == Blockchain.EthereumTestNet || ctx.blockchain == Blockchain.Token || ctx.blockchain == Blockchain.BitcoinCash || ctx.blockchain == Blockchain.Litecoin)
lol.isEnabled = allowFeeLevelSelection
}
// set listeners

View file

@ -55,16 +55,15 @@ class PrepareTransactionActivity : AppCompatActivity(), NfcAdapter.ReaderCallbac
@Suppress("DEPRECATION") val html = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
Html.fromHtml(engine!!.balanceHTML, Html.FROM_HTML_MODE_LEGACY)
else
else
Html.fromHtml(engine!!.balanceHTML)
tvBalance.text = html
//TODO - to engine
if ((ctx.blockchain == Blockchain.Token && engine.balance.currency!=Blockchain.Ethereum.currency) ||
((ctx.blockchain == Blockchain.RootstockToken && engine.balance.currency!=Blockchain.Rootstock.currency))){
if (!engine.allowSelectFeeInclusion()) {
rgIncFee.visibility = View.INVISIBLE
} else
} else {
rgIncFee.visibility = View.VISIBLE
}
if (ctx.card!!.remainingSignatures < 2)
etAmount.isEnabled = false

View file

@ -1,6 +1,5 @@
package com.tangem.presentation.fragment
import android.annotation.SuppressLint
import android.app.Activity
import android.app.AlertDialog
import android.content.*
@ -112,8 +111,9 @@ class LoadedWallet : androidx.fragment.app.Fragment(), NfcAdapter.ReaderCallback
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
if (ctx.blockchain == Blockchain.Token || ctx.blockchain == Blockchain.RootstockToken)
tvBalance.setSingleLine(false)
val engine=CoinEngineFactory.create(ctx)
tvBalance.setSingleLine(!engine!!.needMultipleLinesForBalance())
ivTangemCard.setImageBitmap(App.localStorage.getCardArtworkBitmap(ctx.card))