diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 033a88b840..b24b163742 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -99,17 +99,17 @@ android:theme="@style/AppTheme.NoActionBar" /> diff --git a/app/src/main/java/com/tangem/Constant.kt b/app/src/main/java/com/tangem/Constant.kt index 57bb685c8c..433d912aa0 100644 --- a/app/src/main/java/com/tangem/Constant.kt +++ b/app/src/main/java/com/tangem/Constant.kt @@ -13,7 +13,7 @@ object Constant { const val EXTRA_MODIFICATION_UPDATE = "update" // LoadedWallet, VerifyCard - const val REQUEST_CODE_SEND_PAYMENT = 1 + const val REQUEST_CODE_SEND_TRANSACTION = 1 const val REQUEST_CODE_PURGE = 2 const val REQUEST_CODE_REQUEST_PIN2_FOR_PURGE = 3 const val REQUEST_CODE_VERIFY_CARD = 4 @@ -21,7 +21,7 @@ object Constant { const val REQUEST_CODE_ENTER_NEW_PIN2 = 6 const val REQUEST_CODE_REQUEST_PIN2_FOR_SWAP_PIN = 7 const val REQUEST_CODE_SWAP_PIN = 8 - const val REQUEST_CODE_RECEIVE_PAYMENT = 9 + const val REQUEST_CODE_RECEIVE_TRANSACTION = 9 // MainActivity const val REQUEST_CODE_SHOW_CARD_ACTIVITY = 1 @@ -57,26 +57,26 @@ object Constant { const val REQUEST_CODE_CREATE_NEW_WALLET_ACTIVITY = 2 const val REQUEST_CODE_REQUEST_PIN2 = 3 - // ConfirmPaymentActivity - const val REQUEST_CODE_SIGN_PAYMENT = 1 + // ConfirmTransactionActivity + const val REQUEST_CODE_SIGN_TRANSACTION = 1 const val REQUEST_CODE_REQUEST_PIN2_ = 2 // SendTransactionActivity const val EXTRA_TX: String = "TX" - // SignPaymentActivity + // SignTransactionActivity const val EXTRA_AMOUNT = "Amount" const val EXTRA_AMOUNT_CURRENCY = "AmountCurrency" const val EXTRA_FEE = "Fee" const val EXTRA_FEE_CURRENCY = "FeeCurrency" const val EXTRA_FEE_INCLUDED = "FeeIncluded" const val EXTRA_TARGET_ADDRESS = "TargetAddress" - const val REQUEST_CODE_SEND_PAYMENT_ = 1 + const val REQUEST_CODE_SEND_TRANSACTION_ = 1 const val RESULT_INVALID_PIN_ = Activity.RESULT_FIRST_USER - // PreparePaymentActivity + // PrepareTransactionActivity const val REQUEST_CODE_SCAN_QR = 1 - const val REQUEST_CODE_SEND_PAYMENT__ = 2 + const val REQUEST_CODE_SEND_TRANSACTION__ = 2 // PrepareCryptonitOtherApiWithdrawalActivity const val REQUEST_CODE_SCAN_QR_KEY = 1 diff --git a/app/src/main/java/com/tangem/data/network/ServerApiCommon.java b/app/src/main/java/com/tangem/data/network/ServerApiCommon.java index 7ab8fe42e0..c10d274cbc 100644 --- a/app/src/main/java/com/tangem/data/network/ServerApiCommon.java +++ b/app/src/main/java/com/tangem/data/network/ServerApiCommon.java @@ -24,18 +24,18 @@ public class ServerApiCommon { public static final int ESTIMATE_FEE_PRIORITY = 2; public static final int ESTIMATE_FEE_NORMAL = 3; public static final int ESTIMATE_FEE_MINIMAL = 6; - private EstimateFeeListener estimateFeeListener; + private EstimatedFeeListener estimatedFeeListener; - public interface EstimateFeeListener { + public interface EstimatedFeeListener { void onSuccess(int blockCount, String estimateFeeResponse); void onFail(int blockCount, String message); } - public void setEstimateFee(EstimateFeeListener listener) { - estimateFeeListener = listener; + public void setBtcEstimatedFeeListener(EstimatedFeeListener listener) { + estimatedFeeListener = listener; } - public void estimateFee(int blockCount) { + public void requestBtcEstimatedFee(int blockCount) { EstimatefeeApi estimatefeeApi = App.getNetworkComponent().getRetrofitEstimatefee().create(EstimatefeeApi.class); Call call; @@ -60,17 +60,17 @@ public class ServerApiCommon { @Override public void onResponse(@NonNull Call call, @NonNull Response response) { if (response.code() == 200) { - estimateFeeListener.onSuccess(blockCount, response.body()); - Log.i(TAG, "estimateFee onResponse " + response.code() + " " + response.body()); + estimatedFeeListener.onSuccess(blockCount, response.body()); + Log.i(TAG, "requestBtcEstimatedFee onResponse " + response.code() + " " + response.body()); } else - estimateFeeListener.onFail(blockCount, response.body()); - Log.e(TAG, "estimateFee onResponse " + response.code()); + estimatedFeeListener.onFail(blockCount, response.body()); + Log.e(TAG, "requestBtcEstimatedFee onResponse " + response.code()); } @Override public void onFailure(@NonNull Call call, @NonNull Throwable t) { - estimateFeeListener.onFail(blockCount, t.getMessage()); - Log.e(TAG, "estimateFee onFailure " + t.getMessage()); + estimatedFeeListener.onFail(blockCount, t.getMessage()); + Log.e(TAG, "requestBtcEstimatedFee onFailure " + t.getMessage()); } }); } @@ -79,18 +79,18 @@ public class ServerApiCommon { * HTTP * Used in Crypto-currency course */ - private RateInfoDataListener rateInfoDataListener; + private RateInfoListener rateInfoListener; - public interface RateInfoDataListener { + public interface RateInfoListener { void onSuccess(RateInfoResponse rateInfoResponse); } - public void setRateInfoData(RateInfoDataListener listener) { - rateInfoDataListener = listener; + public void setRateInfoListener(RateInfoListener listener) { + rateInfoListener = listener; } @SuppressLint("CheckResult") - public void rateInfoData(String cryptoId) { + public void requestRateInfo(String cryptoId) { CoinmarketApi coinmarketApi = App.getNetworkComponent().getRetrofitCoinmarketcap().create(CoinmarketApi.class); coinmarketApi.getRateInfoList() @@ -100,12 +100,12 @@ public class ServerApiCommon { if (!rateInfoModelList.isEmpty()) { for (RateInfoResponse rateInfoMode : rateInfoModelList) { if (rateInfoMode.getId().equals(cryptoId)) { - rateInfoDataListener.onSuccess(rateInfoMode); - Log.i(TAG, "rateInfoData " + cryptoId + " onResponse " + "200"); + rateInfoListener.onSuccess(rateInfoMode); + Log.i(TAG, "requestRateInfo " + cryptoId + " onResponse " + "200"); } } } else - Log.e(TAG, "rateInfoData " + cryptoId + " onResponse " + "Empty"); + Log.e(TAG, "requestRateInfo " + cryptoId + " onResponse " + "Empty"); }, // handle error Throwable::printStackTrace); diff --git a/app/src/main/java/com/tangem/data/network/ServerApiElectrum.java b/app/src/main/java/com/tangem/data/network/ServerApiElectrum.java index 53b250d78b..deb6e49560 100644 --- a/app/src/main/java/com/tangem/data/network/ServerApiElectrum.java +++ b/app/src/main/java/com/tangem/data/network/ServerApiElectrum.java @@ -9,7 +9,6 @@ import com.tangem.domain.wallet.bch.BitcoinCashNode; import com.tangem.domain.wallet.btc.BitcoinNode; import com.tangem.domain.wallet.btc.BitcoinNodeTestNet; import com.tangem.domain.wallet.ltc.LitecoinNode; -import com.tangem.tangemcard.reader.CardProtocol; import com.tangem.wallet.R; import java.io.BufferedReader; @@ -24,7 +23,6 @@ import java.net.InetSocketAddress; import java.net.Socket; import java.security.KeyManagementException; import java.security.NoSuchAlgorithmException; -import java.security.cert.CertificateException; import java.security.cert.X509Certificate; import java.util.ArrayList; import java.util.Collections; @@ -47,13 +45,13 @@ import io.reactivex.schedulers.Schedulers; /** * Request processor for Electrum Api * Every request live cycle: - * 1. In application create request and call {@link ServerApiElectrum}.electrumRequestData(..) + * 1. In application create request and call {@link ServerApiElectrum}.requestData(..) * 2. Try send every request for max 4 times, - * 3. If all 4 times fail call DefaultObserver.onError (defined in .electrumRequestData(..)) and than - * {@link ElectrumRequestDataListener}.onFail(...) callback + * 3. If all 4 times fail call DefaultObserver.onError (defined in .requestData(..)) and than + * {@link ResponseListener}.onFail(...) callback * Error can be acquired with {@link ElectrumRequest}.getError() method - * 4. If request network communication finished successfully then call DefaultObserver.onComplete (defined in .electrumRequestData) and than - * {@link ElectrumRequestDataListener}.onSuccess(...) callback + * 4. If request network communication finished successfully then call DefaultObserver.onComplete (defined in .requestData) and than + * {@link ResponseListener}.onSuccess(...) callback */ public class ServerApiElectrum { private static String TAG = ServerApiElectrum.class.getSimpleName(); @@ -62,7 +60,7 @@ public class ServerApiElectrum { * TCP, SSL * Used in BTC, BCH */ - private ElectrumRequestDataListener electrumRequestDataListener; + private ResponseListener responseListener; private String host; private int port; @@ -76,7 +74,7 @@ public class ServerApiElectrum { /** * Interface for notification every request result */ - public interface ElectrumRequestDataListener { + public interface ResponseListener { /** * Notify that request processing was successful @@ -94,8 +92,8 @@ public class ServerApiElectrum { * Set notificaion listener * @param listener */ - public void setElectrumRequestData(ElectrumRequestDataListener listener) { - electrumRequestDataListener = listener; + public void setResponseListener(ResponseListener listener) { + responseListener = listener; } @@ -104,7 +102,7 @@ public class ServerApiElectrum { * @param ctx * @param electrumRequest */ - public void electrumRequestData(TangemContext ctx, ElectrumRequest electrumRequest) { + public void requestData(TangemContext ctx, ElectrumRequest electrumRequest) { requestsCount++; Log.i(TAG, String.format("New request[%d]: %s", requestsCount,electrumRequest.getMethod())); Observable checkElectrumDataObserver = Observable.just(electrumRequest) @@ -129,20 +127,20 @@ public class ServerApiElectrum { @Override public void onNext(ElectrumRequest v) { if (electrumRequest.answerData != null) { - Log.i(TAG, "electrumRequestData " + electrumRequest.getMethod() + " onNext != null"); + Log.i(TAG, "requestData " + electrumRequest.getMethod() + " onNext != null"); } else { - Log.e(TAG, "electrumRequestData " + electrumRequest.getMethod() + " onNext == null"); + Log.e(TAG, "requestData " + electrumRequest.getMethod() + " onNext == null"); } } @Override public void onError(Throwable e) { requestsCount--; - Log.e(TAG, "electrumRequestData " + electrumRequest.getMethod() + " onError " + e.getMessage()); + Log.e(TAG, "requestData " + electrumRequest.getMethod() + " onError " + e.getMessage()); Log.e(TAG, String.format("%d requests left in processing",requestsCount)); electrumRequest.setError(ctx.getString(R.string.cannot_obtain_data_from_blockchain)); //setErrorOccurred(e.getMessage());//; - electrumRequestDataListener.onFail(electrumRequest); + responseListener.onFail(electrumRequest); } /** @@ -152,16 +150,16 @@ public class ServerApiElectrum { public void onComplete() { requestsCount--; if (electrumRequest.answerData != null) { - Log.i(TAG, "electrumRequestData " + electrumRequest.getMethod() + " onComplete, answerData!=null"); + Log.i(TAG, "requestData " + electrumRequest.getMethod() + " onComplete, answerData!=null"); } else { - Log.e(TAG, "electrumRequestData " + electrumRequest.getMethod() + " onComplete, answerData==null"); + Log.e(TAG, "requestData " + electrumRequest.getMethod() + " onComplete, answerData==null"); } Log.e(TAG, String.format("%d requests left in processing",requestsCount)); if (electrumRequest.answerData != null && electrumRequest.getError()==null) { - electrumRequestDataListener.onSuccess(electrumRequest); + responseListener.onSuccess(electrumRequest); } else { // if( error==null || error.isEmpty() ) setErrorOccurred(ctx.getString(R.string.cannot_obtain_data_from_blockchain)); - electrumRequestDataListener.onFail(electrumRequest); + responseListener.onFail(electrumRequest); } } @@ -257,7 +255,7 @@ public class ServerApiElectrum { } catch (ConnectException e) { //e.printStackTrace(); - //electrumRequestDataListener.onFail(e.getMessage()); + //responseListener.onFail(e.getMessage()); electrumRequest.setError(App.getInstance().getString(R.string.cannot_obtain_data_from_blockchain_no_connection)); Log.e(TAG, "doElectrumRequestTcp " + electrumRequest.getMethod() + " ConnectException " + e.getMessage()); } finally { @@ -274,7 +272,7 @@ public class ServerApiElectrum { } } catch (IOException e) { //e.printStackTrace(); - //electrumRequestDataListener.onFail(e.getMessage()); + //responseListener.onFail(e.getMessage()); electrumRequest.setError(App.getInstance().getString(R.string.cannot_obtain_data_from_blockchain_communication_error)); Log.e(TAG, "doElectrumRequestTcp " + electrumRequest.getMethod() + " IOException " + e.getMessage()); } diff --git a/app/src/main/java/com/tangem/data/network/ServerApiInfura.java b/app/src/main/java/com/tangem/data/network/ServerApiInfura.java index 34b2f33f3f..977518fd29 100644 --- a/app/src/main/java/com/tangem/data/network/ServerApiInfura.java +++ b/app/src/main/java/com/tangem/data/network/ServerApiInfura.java @@ -38,19 +38,19 @@ public class ServerApiInfura { return requestsCount <= 0; } - private InfuraBodyListener infuraBodyListener; + private ResponseListener responseListener; - public interface InfuraBodyListener { + public interface ResponseListener { void onSuccess(String method, InfuraResponse infuraResponse); void onFail(String method, String message); } - public void setInfuraResponse(InfuraBodyListener listener) { - infuraBodyListener = listener; + public void setResponseListener(ResponseListener listener) { + responseListener = listener; } - public void infura(String method, int id, String wallet, String contract, String tx) { + public void requestData(String method, int id, String wallet, String contract, String tx) { requestsCount++; InfuraApi infuraApi = App.getNetworkComponent().getRetrofitInfura().create(InfuraApi.class); @@ -86,18 +86,18 @@ public class ServerApiInfura { public void onResponse(@NonNull Call call, @NonNull Response response) { if (response.code() == 200) { requestsCount--; - infuraBodyListener.onSuccess(method, response.body()); - Log.i(TAG, "infura " + method + " onResponse " + response.code()); + responseListener.onSuccess(method, response.body()); + Log.i(TAG, "requestData " + method + " onResponse " + response.code()); } else { - infuraBodyListener.onFail(method, String.valueOf(response.code())); - Log.e(TAG, "infura " + method + " onResponse " + response.code()); + responseListener.onFail(method, String.valueOf(response.code())); + Log.e(TAG, "requestData " + method + " onResponse " + response.code()); } } @Override public void onFailure(@NonNull Call call, @NonNull Throwable t) { - infuraBodyListener.onFail(method, String.valueOf(t.getMessage())); - Log.e(TAG, "infura " + method + " onFailure " + t.getMessage()); + responseListener.onFail(method, String.valueOf(t.getMessage())); + Log.e(TAG, "requestData " + method + " onFailure " + t.getMessage()); } }); } diff --git a/app/src/main/java/com/tangem/data/network/ServerApiInsight.java b/app/src/main/java/com/tangem/data/network/ServerApiInsight.java index fc7de6214c..ac24f5b532 100644 --- a/app/src/main/java/com/tangem/data/network/ServerApiInsight.java +++ b/app/src/main/java/com/tangem/data/network/ServerApiInsight.java @@ -32,21 +32,21 @@ public class ServerApiInsight { return requestsCount <= 0; } - private InsightBodyListener insightBodyListener; + private ResponseListener responseListener; - public interface InsightBodyListener { + public interface ResponseListener { void onSuccess(String method, InsightResponse insightResponse); void onSuccess(String method, List utxoList); void onFail(String method, String message); } - public void setInsightResponse(InsightBodyListener listener) { - insightBodyListener = listener; + public void setResponseListener(ResponseListener listener) { + responseListener = listener; } - public void insight(String method, String wallet, String tx) { + public void requestData(String method, String wallet, String tx) { requestsCount++; - String insightURL = "http://130.185.109.17:3001/insight-api"; //TODO: make random selection + String insightURL = "http://130.185.109.17:3001/requestData-api"; //TODO: make random selection this.lastNode = insightURL; //TODO: show node instead of URL Retrofit retrofitInsight = new Retrofit.Builder() //TODO: move to NetworkModule+NetworkComponent if possible @@ -64,18 +64,18 @@ public class ServerApiInsight { public void onResponse(@NonNull Call> call, @NonNull Response> response) { if (response.code() == 200) { requestsCount--; - insightBodyListener.onSuccess(method, response.body()); - Log.i(TAG, "insight " + method + " onResponse " + response.code()); + responseListener.onSuccess(method, response.body()); + Log.i(TAG, "requestData " + method + " onResponse " + response.code()); } else { - insightBodyListener.onFail(method, String.valueOf(response.code())); - Log.e(TAG, "insight " + method + " onResponse " + response.code()); + responseListener.onFail(method, String.valueOf(response.code())); + Log.e(TAG, "requestData " + method + " onResponse " + response.code()); } } @Override public void onFailure(@NonNull Call> call, @NonNull Throwable t) { - insightBodyListener.onFail(method, String.valueOf(t.getMessage())); - Log.e(TAG, "insight " + method + " onFailure " + t.getMessage()); + responseListener.onFail(method, String.valueOf(t.getMessage())); + Log.e(TAG, "requestData " + method + " onFailure " + t.getMessage()); } }); @@ -112,18 +112,18 @@ public class ServerApiInsight { public void onResponse(@NonNull Call call, @NonNull Response response) { if (response.code() == 200) { requestsCount--; - insightBodyListener.onSuccess(method, response.body()); - Log.i(TAG, "insight " + method + " onResponse " + response.code()); + responseListener.onSuccess(method, response.body()); + Log.i(TAG, "requestData " + method + " onResponse " + response.code()); } else { - insightBodyListener.onFail(method, String.valueOf(response.code())); - Log.e(TAG, "insight " + method + " onResponse " + response.code()); + responseListener.onFail(method, String.valueOf(response.code())); + Log.e(TAG, "requestData " + method + " onResponse " + response.code()); } } @Override public void onFailure(@NonNull Call call, @NonNull Throwable t) { - insightBodyListener.onFail(method, String.valueOf(t.getMessage())); - Log.e(TAG, "insight " + method + " onFailure " + t.getMessage()); + responseListener.onFail(method, String.valueOf(t.getMessage())); + Log.e(TAG, "requestData " + method + " onFailure " + t.getMessage()); } }); } diff --git a/app/src/main/java/com/tangem/data/network/ServerApiRootstock.java b/app/src/main/java/com/tangem/data/network/ServerApiRootstock.java index 988c383639..5d19e3225c 100644 --- a/app/src/main/java/com/tangem/data/network/ServerApiRootstock.java +++ b/app/src/main/java/com/tangem/data/network/ServerApiRootstock.java @@ -38,19 +38,19 @@ public class ServerApiRootstock { return requestsCount <= 0; } - private RootstockBodyListener rootstockBodyListener; + private ResponseListener responseListener; - public interface RootstockBodyListener { + public interface ResponseListener { void onSuccess(String method, InfuraResponse infuraResponse); void onFail(String method, String message); } - public void setRootstockResponse(RootstockBodyListener listener) { - rootstockBodyListener = listener; + public void setResponseListener(ResponseListener listener) { + responseListener = listener; } - public void rootstock(String method, int id, String wallet, String contract, String tx) { + public void requestData(String method, int id, String wallet, String contract, String tx) { requestsCount++; RootstockApi rootstockApi = App.getNetworkComponent().getRetrofitRootstock().create(RootstockApi.class); @@ -86,18 +86,18 @@ public class ServerApiRootstock { public void onResponse(@NonNull Call call, @NonNull Response response) { if (response.code() == 200) { requestsCount--; - rootstockBodyListener.onSuccess(method, response.body()); - Log.i(TAG, "rootstock " + method + " onResponse " + response.code()); + responseListener.onSuccess(method, response.body()); + Log.i(TAG, "requestData " + method + " onResponse " + response.code()); } else { - rootstockBodyListener.onFail(method, String.valueOf(response.code())); - Log.e(TAG, "rootstock " + method + " onResponse " + response.code()); + responseListener.onFail(method, String.valueOf(response.code())); + Log.e(TAG, "requestData " + method + " onResponse " + response.code()); } } @Override public void onFailure(@NonNull Call call, @NonNull Throwable t) { - rootstockBodyListener.onFail(method, String.valueOf(t.getMessage())); - Log.e(TAG, "rootstock " + method + " onFailure " + t.getMessage()); + responseListener.onFail(method, String.valueOf(t.getMessage())); + Log.e(TAG, "requestData " + method + " onFailure " + t.getMessage()); } }); } diff --git a/app/src/main/java/com/tangem/data/network/ServerURL.java b/app/src/main/java/com/tangem/data/network/ServerURL.java index b33d4c4ba4..45cad24be7 100644 --- a/app/src/main/java/com/tangem/data/network/ServerURL.java +++ b/app/src/main/java/com/tangem/data/network/ServerURL.java @@ -3,7 +3,7 @@ package com.tangem.data.network; class ServerURL { static final String API_TANGEM = "https://verify.tangem.com/"; static final String API_COINMARKETCAP = "https://api.coinmarketcap.com/"; - static final String API_INFURA = "https://mainnet.infura.io/"; + static final String API_INFURA = "https://mainnet.requestData.io/"; static final String API_ESTIMATEFEE = "https://estimatefee.com/"; static final String API_UPDATE_VERSION = "https://raw.githubusercontent.com/"; static final String API_ROOTSTOCK = "https://public-node.rsk.co/"; diff --git a/app/src/main/java/com/tangem/di/Navigator.kt b/app/src/main/java/com/tangem/di/Navigator.kt index 3a620229c4..bc486fbfb5 100644 --- a/app/src/main/java/com/tangem/di/Navigator.kt +++ b/app/src/main/java/com/tangem/di/Navigator.kt @@ -68,8 +68,8 @@ class Navigator { context.startActivityForResult(PurgeActivity.callingIntent(context, ctx), Constant.REQUEST_CODE_PURGE) } - fun showPreparePayment(context: Activity, ctx: TangemContext) { - context.startActivityForResult(PreparePaymentActivity.callingIntent(context, ctx), Constant.REQUEST_CODE_SEND_PAYMENT) + fun showPrepareTransaction(context: Activity, ctx: TangemContext) { + context.startActivityForResult(PrepareTransactionActivity.callingIntent(context, ctx), Constant.REQUEST_CODE_SEND_TRANSACTION) } fun showCreateNewWallet(context: Activity, ctx: TangemContext) { diff --git a/app/src/main/java/com/tangem/di/NavigatorComponent.java b/app/src/main/java/com/tangem/di/NavigatorComponent.java index 23bd390f21..3c2e043645 100644 --- a/app/src/main/java/com/tangem/di/NavigatorComponent.java +++ b/app/src/main/java/com/tangem/di/NavigatorComponent.java @@ -6,7 +6,7 @@ import com.tangem.presentation.activity.LogoActivity; import com.tangem.presentation.activity.MainActivity; import com.tangem.presentation.activity.PrepareCryptonitOtherApiWithdrawalActivity; import com.tangem.presentation.activity.PrepareKrakenWithdrawalActivity; -import com.tangem.presentation.activity.PreparePaymentActivity; +import com.tangem.presentation.activity.PrepareTransactionActivity; import com.tangem.presentation.activity.VerifyCardActivity; import javax.inject.Singleton; @@ -23,7 +23,7 @@ public interface NavigatorComponent { void inject(MainActivity activity); - void inject(PreparePaymentActivity activity); + void inject(PrepareTransactionActivity activity); void inject(PrepareCryptonitOtherApiWithdrawalActivity activity); diff --git a/app/src/main/java/com/tangem/domain/wallet/CoinEngine.java b/app/src/main/java/com/tangem/domain/wallet/CoinEngine.java index 83b0f987bf..c09c9043ee 100644 --- a/app/src/main/java/com/tangem/domain/wallet/CoinEngine.java +++ b/app/src/main/java/com/tangem/domain/wallet/CoinEngine.java @@ -181,12 +181,10 @@ public abstract class CoinEngine { public abstract boolean isBalanceNotZero(); -// public abstract byte[] sign(Amount feeValue, Amount amountValue, boolean IncFee, String targetAddress, CardProtocol protocol) throws Exception; - - // TODO - change isExtractPossible to isExtractPossible and if not - return string message + // TODO - return string message public abstract boolean isExtractPossible(); - public abstract Uri getShareWalletUriExplorer(); + public abstract Uri getWalletExplorerUri(); public abstract Uri getShareWalletUri(); @@ -245,14 +243,14 @@ public abstract class CoinEngine { } /** - * Create instance of {@link SignTask.PaymentToSign} used for transaction signing and sending + * Create instance of {@link SignTask.TransactionToSign} used for transaction signing and sending * * Transaction processing sequence: * 1. User enter transaction attributes - * 2. Application create instance of {@link SignTask.PaymentToSign} by call {@see constructPayment} - * 3. Application set notification when transaction were prepared {@see setOnNeedSendPayment} and start {@link SignTask} + * 2. Application create instance of {@link SignTask.TransactionToSign} by call {@see constructTransaction} + * 3. Application set notification when transaction were prepared {@see setOnNeedSendTransaction} and start {@link SignTask} * 4. User tap card and card sign transaction - * 5. Application receive {@link CoinEngine.OnNeedSendPayment} notification with prepared raw transaction + * 5. Application receive {@link OnNeedSendTransaction} notification with prepared raw transaction * 6. Application show user information that transaction ready for sending and start sending procedure by call {@see requestSendTransaction} * 7. Application receive notification of sending result through {@link CoinEngine.BlockchainRequestsCallbacks} and show result to user * @@ -260,32 +258,32 @@ public abstract class CoinEngine { * @param feeValue - fee amount of desired transaction * @param IncFee - true if fee amount is included in amountValue (amountValue is total amount of transaction) * @param targetAddress - target address of transaction - * @return instance of {@link SignTask.PaymentToSign} + * @return instance of {@link SignTask.TransactionToSign} * @throws Exception if something goes wrong */ - public abstract SignTask.PaymentToSign constructPayment(Amount amountValue, Amount feeValue, boolean IncFee, String targetAddress) throws Exception; + public abstract SignTask.TransactionToSign constructTransaction(Amount amountValue, Amount feeValue, boolean IncFee, String targetAddress) throws Exception; /** * Interface used to notify main application when new transaction is prepared to send */ - public interface OnNeedSendPayment { - void onPaymentPrepared(byte[] txForSend); + public interface OnNeedSendTransaction { + void onTransactionPrepared(byte[] txForSend); } - protected OnNeedSendPayment onNeedSendPayment; + protected OnNeedSendTransaction onNeedSendTransaction; /** * Set notification callback when new transaction is prepared to send */ - public void setOnNeedSendPayment(OnNeedSendPayment onNeedSendPayment) { - this.onNeedSendPayment = onNeedSendPayment; + public void setOnNeedSendTransaction(OnNeedSendTransaction onNeedSendTransaction) { + this.onNeedSendTransaction = onNeedSendTransaction; } - protected void notifyOnNeedSendPayment(byte[] txForSend) throws Exception { - if (onNeedSendPayment == null) - throw new Exception("Payment signed but no callback defined to send!"); - onNeedSendPayment.onPaymentPrepared(txForSend); + protected void notifyOnNeedSendTransaction(byte[] txForSend) throws Exception { + if (onNeedSendTransaction == null) + throw new Exception("Transaction was signed but no callback defined to send!"); + onNeedSendTransaction.onTransactionPrepared(txForSend); } /** diff --git a/app/src/main/java/com/tangem/domain/wallet/bch/BtcCashEngine.java b/app/src/main/java/com/tangem/domain/wallet/bch/BtcCashEngine.java index bca4b4cb3d..146145b2a5 100644 --- a/app/src/main/java/com/tangem/domain/wallet/bch/BtcCashEngine.java +++ b/app/src/main/java/com/tangem/domain/wallet/bch/BtcCashEngine.java @@ -185,7 +185,7 @@ public class BtcCashEngine extends CoinEngine { } @Override - public Uri getShareWalletUriExplorer() { + public Uri getWalletExplorerUri() { return Uri.parse("https://bch.btc.com/" + ctx.getCoinData().getWallet()); } @@ -454,7 +454,7 @@ public class BtcCashEngine extends CoinEngine { @Override - public SignTask.PaymentToSign constructPayment(Amount amountValue, Amount feeValue, boolean IncFee, String targetAddress) throws Exception { + public SignTask.TransactionToSign constructTransaction(Amount amountValue, Amount feeValue, boolean IncFee, String targetAddress) throws Exception { checkBlockchainDataExists(); String srcLegacyAddress = convertToLegacyAddress(ctx.getCoinData().getWallet()); @@ -500,7 +500,7 @@ public class BtcCashEngine extends CoinEngine { bodyDoubleHash[i] = Util.calculateSHA256(bodyHash[i]); } - return new SignTask.PaymentToSign() { + return new SignTask.TransactionToSign() { @Override public boolean isSigningMethodSupported(TangemCard.SigningMethod signingMethod) { @@ -551,7 +551,7 @@ public class BtcCashEngine extends CoinEngine { byte[] txForSend = BCHUtils.buildTXForSend(destLegacyAddress, srcLegacyAddress, unspentOutputs, amountFinal, changeFinal); - notifyOnNeedSendPayment(txForSend); + notifyOnNeedSendTransaction(txForSend); return txForSend; } }; @@ -561,7 +561,7 @@ public class BtcCashEngine extends CoinEngine { public void requestBalanceAndUnspentTransactions(BlockchainRequestsCallbacks blockchainRequestsCallbacks) throws Exception { final ServerApiElectrum serverApiElectrum = new ServerApiElectrum(); - ServerApiElectrum.ElectrumRequestDataListener electrumBodyListener = new ServerApiElectrum.ElectrumRequestDataListener() { + ServerApiElectrum.ResponseListener electrumBodyListener = new ServerApiElectrum.ResponseListener() { @Override public void onSuccess(ElectrumRequest electrumRequest) { if (electrumRequest.isMethod(ElectrumRequest.METHOD_GetBalance)) { @@ -606,7 +606,7 @@ public class BtcCashEngine extends CoinEngine { String hash = jsUnspent.getString("tx_hash"); if (height != -1) { if (blockchainRequestsCallbacks.allowAdvance()) { - serverApiElectrum.electrumRequestData(ctx, ElectrumRequest.getTransaction(walletAddress, hash)); + serverApiElectrum.requestData(ctx, ElectrumRequest.getTransaction(walletAddress, hash)); } else { ctx.setError("Terminated by user"); } @@ -649,22 +649,22 @@ public class BtcCashEngine extends CoinEngine { } }; - serverApiElectrum.setElectrumRequestData(electrumBodyListener); + serverApiElectrum.setResponseListener(electrumBodyListener); - serverApiElectrum.electrumRequestData(ctx, ElectrumRequest.checkBalance(convertToLegacyAddress(coinData.getWallet()))); - serverApiElectrum.electrumRequestData(ctx, ElectrumRequest.listUnspent(convertToLegacyAddress(coinData.getWallet()))); + serverApiElectrum.requestData(ctx, ElectrumRequest.checkBalance(convertToLegacyAddress(coinData.getWallet()))); + serverApiElectrum.requestData(ctx, ElectrumRequest.listUnspent(convertToLegacyAddress(coinData.getWallet()))); } private Integer calculateEstimatedTransactionSize(String outputAddress, String outAmount) { try { - SignTask.PaymentToSign ps=constructPayment(new Amount(outAmount, getBalanceCurrency()),new Amount("0.00",getFeeCurrency()), true, outputAddress ); - OnNeedSendPayment onNeedSendPaymentBackup=onNeedSendPayment; - onNeedSendPayment=(tx)->{}; // empty function to bypass exception + SignTask.TransactionToSign ps= constructTransaction(new Amount(outAmount, getBalanceCurrency()),new Amount("0.00",getFeeCurrency()), true, outputAddress ); + OnNeedSendTransaction onNeedSendTransactionBackup = onNeedSendTransaction; + onNeedSendTransaction =(tx)->{}; // empty function to bypass exception byte[][] hashesToSign=ps.getHashesToSign(); byte[] signFromCard = new byte[64 * hashesToSign.length]; byte[] txForSend=ps.onSignCompleted(signFromCard); - onNeedSendPayment=onNeedSendPaymentBackup; + onNeedSendTransaction = onNeedSendTransactionBackup; Log.e(TAG,"txForSend.length="+String.valueOf(txForSend.length)); return txForSend.length; } catch (Exception e) { @@ -686,7 +686,7 @@ public class BtcCashEngine extends CoinEngine { final ServerApiElectrum serverApiElectrum = new ServerApiElectrum(); - final ServerApiElectrum.ElectrumRequestDataListener electrumListener = new ServerApiElectrum.ElectrumRequestDataListener () { + final ServerApiElectrum.ResponseListener electrumListener = new ServerApiElectrum.ResponseListener() { @Override public void onSuccess(ElectrumRequest electrumRequest) { BigDecimal fee; @@ -695,13 +695,13 @@ public class BtcCashEngine extends CoinEngine { fee = new BigDecimal(electrumRequest.getResultString()); //fee per KB if (fee.equals(BigDecimal.ZERO)) { - serverApiElectrum.electrumRequestData(ctx, ElectrumRequest.getFee()); + serverApiElectrum.requestData(ctx, ElectrumRequest.getFee()); } // if (calcSize != 0) { fee = fee.multiply(new BigDecimal(calcSize)).divide(new BigDecimal(1024)); // (per KB -> per byte)*size // } else { -// serverApiElectrum.electrumRequestData(ctx, ElectrumRequest.getFee()); +// serverApiElectrum.requestData(ctx, ElectrumRequest.getFee()); // } //compare fee to usual relay fee @@ -732,9 +732,9 @@ public class BtcCashEngine extends CoinEngine { blockchainRequestsCallbacks.onComplete(false); } }; - serverApiElectrum.setElectrumRequestData(electrumListener); + serverApiElectrum.setResponseListener(electrumListener); - serverApiElectrum.electrumRequestData(ctx, ElectrumRequest.getFee()); + serverApiElectrum.requestData(ctx, ElectrumRequest.getFee()); } @Override @@ -742,7 +742,7 @@ public class BtcCashEngine extends CoinEngine { final ServerApiElectrum serverApiElectrum = new ServerApiElectrum(); final String txStr = BTCUtils.toHex(txForSend); - ServerApiElectrum.ElectrumRequestDataListener electrumBodyListener = new ServerApiElectrum.ElectrumRequestDataListener() { + ServerApiElectrum.ResponseListener electrumBodyListener = new ServerApiElectrum.ResponseListener() { @Override public void onSuccess(ElectrumRequest electrumRequest) { if (electrumRequest.isMethod(ElectrumRequest.METHOD_SendTransaction)) { @@ -773,10 +773,10 @@ public class BtcCashEngine extends CoinEngine { blockchainRequestsCallbacks.onComplete(false); } }; - serverApiElectrum.setElectrumRequestData(electrumBodyListener); + serverApiElectrum.setResponseListener(electrumBodyListener); - serverApiElectrum.electrumRequestData(ctx, ElectrumRequest.broadcast(ctx.getCoinData().getWallet(), txStr)); + serverApiElectrum.requestData(ctx, ElectrumRequest.broadcast(ctx.getCoinData().getWallet(), txStr)); } diff --git a/app/src/main/java/com/tangem/domain/wallet/btc/BtcEngine.java b/app/src/main/java/com/tangem/domain/wallet/btc/BtcEngine.java index 42b0073218..8cab4364e7 100644 --- a/app/src/main/java/com/tangem/domain/wallet/btc/BtcEngine.java +++ b/app/src/main/java/com/tangem/domain/wallet/btc/BtcEngine.java @@ -189,7 +189,7 @@ public class BtcEngine extends CoinEngine { } @Override - public Uri getShareWalletUriExplorer() { + public Uri getWalletExplorerUri() { return Uri.parse((ctx.getBlockchain() == Blockchain.Bitcoin ? "https://blockchain.info/address/" : "https://testnet.blockchain.info/address/") + ctx.getCoinData().getWallet()); } @@ -422,7 +422,7 @@ public class BtcEngine extends CoinEngine { } @Override - public SignTask.PaymentToSign constructPayment(Amount amountValue, Amount feeValue, boolean IncFee, String targetAddress) throws Exception { + public SignTask.TransactionToSign constructTransaction(Amount amountValue, Amount feeValue, boolean IncFee, String targetAddress) throws Exception { final ArrayList unspentOutputs; checkBlockchainDataExists(); @@ -467,7 +467,7 @@ public class BtcEngine extends CoinEngine { bodyDoubleHash[i] = Util.calculateSHA256(bodyHash[i]); } - return new SignTask.PaymentToSign() { + return new SignTask.TransactionToSign() { @Override public boolean isSigningMethodSupported(TangemCard.SigningMethod signingMethod) { @@ -517,7 +517,7 @@ public class BtcEngine extends CoinEngine { } byte[] txForSend = BTCUtils.buildTXForSend(targetAddress, myAddress, unspentOutputs, amountFinal, changeFinal); - notifyOnNeedSendPayment(txForSend); + notifyOnNeedSendTransaction(txForSend); return txForSend; } }; @@ -527,7 +527,7 @@ public class BtcEngine extends CoinEngine { public void requestBalanceAndUnspentTransactions(BlockchainRequestsCallbacks blockchainRequestsCallbacks) { final ServerApiElectrum serverApiElectrum = new ServerApiElectrum(); - ServerApiElectrum.ElectrumRequestDataListener electrumListener = new ServerApiElectrum.ElectrumRequestDataListener() { + ServerApiElectrum.ResponseListener electrumListener = new ServerApiElectrum.ResponseListener() { @Override public void onSuccess(ElectrumRequest electrumRequest) { Log.i(TAG, "onSuccess: "+electrumRequest.getMethod()); @@ -576,7 +576,7 @@ public class BtcEngine extends CoinEngine { String hash = jsUnspent.getString("tx_hash"); if (height != -1) { if (blockchainRequestsCallbacks.allowAdvance()) { - serverApiElectrum.electrumRequestData(ctx, ElectrumRequest.getTransaction(walletAddress, hash)); + serverApiElectrum.requestData(ctx, ElectrumRequest.getTransaction(walletAddress, hash)); } else { ctx.setError("Terminated by user"); } @@ -617,14 +617,14 @@ public class BtcEngine extends CoinEngine { } }; - serverApiElectrum.setElectrumRequestData(electrumListener); + serverApiElectrum.setResponseListener(electrumListener); - serverApiElectrum.electrumRequestData(ctx, ElectrumRequest.checkBalance(coinData.getWallet())); - serverApiElectrum.electrumRequestData(ctx, ElectrumRequest.listUnspent(coinData.getWallet())); + serverApiElectrum.requestData(ctx, ElectrumRequest.checkBalance(coinData.getWallet())); + serverApiElectrum.requestData(ctx, ElectrumRequest.listUnspent(coinData.getWallet())); } protected Integer calculateEstimatedTransactionSize(String outputAddress, String outAmount) { - //todo - правильней было бы использовать constructPayment + //todo - правильней было бы использовать constructTransaction try { // String myAddress = coinData.getWallet(); // byte[] pbKey = ctx.getCard().getWalletPublicKey(); @@ -685,14 +685,14 @@ public class BtcEngine extends CoinEngine { // // byte[] realTX = BTCUtils.buildTXForSend(outputAddress, myAddress, unspentOutputs, amount, change); - SignTask.PaymentToSign ps=constructPayment(new Amount(outAmount, getBalanceCurrency()),new Amount("0.00",getFeeCurrency()), true, outputAddress ); - OnNeedSendPayment onNeedSendPaymentBackup=onNeedSendPayment; - onNeedSendPayment=(tx)->{}; // empty function to bypass exception + SignTask.TransactionToSign ps= constructTransaction(new Amount(outAmount, getBalanceCurrency()),new Amount("0.00",getFeeCurrency()), true, outputAddress ); + OnNeedSendTransaction onNeedSendTransactionBackup = onNeedSendTransaction; + onNeedSendTransaction =(tx)->{}; // empty function to bypass exception byte[][] hashesToSign=ps.getHashesToSign(); byte[] signFromCard = new byte[64 * hashesToSign.length]; byte[] txForSend=ps.onSignCompleted(signFromCard); - onNeedSendPayment=onNeedSendPaymentBackup; + onNeedSendTransaction = onNeedSendTransactionBackup; Log.e(TAG,"txForSend.length="+String.valueOf(txForSend.length)); return txForSend.length; @@ -717,14 +717,14 @@ public class BtcEngine extends CoinEngine { final ServerApiCommon serverApiCommon = new ServerApiCommon(); - final ServerApiCommon.EstimateFeeListener estimateFeeListener = new ServerApiCommon.EstimateFeeListener() { + final ServerApiCommon.EstimatedFeeListener estimatedFeeListener = new ServerApiCommon.EstimatedFeeListener() { @Override public void onSuccess(int blockCount, String estimateFeeResponse) { BigDecimal fee = new BigDecimal(estimateFeeResponse); // BTC per 1 kb if (fee.equals(BigDecimal.ZERO)) { if (blockchainRequestsCallbacks.allowAdvance()) { - serverApiCommon.estimateFee(blockCount); + serverApiCommon.requestBtcEstimatedFee(blockCount); } return; } @@ -733,7 +733,7 @@ public class BtcEngine extends CoinEngine { fee = fee.multiply(new BigDecimal(calcSize)).divide(new BigDecimal(1024), BigDecimal.ROUND_DOWN); // per Kb -> per byte } else { if (blockchainRequestsCallbacks.allowAdvance()) { - serverApiCommon.estimateFee(blockCount); + serverApiCommon.requestBtcEstimatedFee(blockCount); } return; } @@ -763,18 +763,18 @@ public class BtcEngine extends CoinEngine { public void onFail(int blockCount, String message) { // TODO - add fail counter to terminate after NNN tries if (blockchainRequestsCallbacks.allowAdvance()) { - serverApiCommon.estimateFee(blockCount); + serverApiCommon.requestBtcEstimatedFee(blockCount); return; } ctx.setError(ctx.getContext().getString(R.string.cannot_calculate_fee_wrong_data_received_from_node)); blockchainRequestsCallbacks.onComplete(false); } }; - serverApiCommon.setEstimateFee(estimateFeeListener); + serverApiCommon.setBtcEstimatedFeeListener(estimatedFeeListener); - serverApiCommon.estimateFee(ServerApiCommon.ESTIMATE_FEE_PRIORITY); - serverApiCommon.estimateFee(ServerApiCommon.ESTIMATE_FEE_NORMAL); - serverApiCommon.estimateFee(ServerApiCommon.ESTIMATE_FEE_MINIMAL); + serverApiCommon.requestBtcEstimatedFee(ServerApiCommon.ESTIMATE_FEE_PRIORITY); + serverApiCommon.requestBtcEstimatedFee(ServerApiCommon.ESTIMATE_FEE_NORMAL); + serverApiCommon.requestBtcEstimatedFee(ServerApiCommon.ESTIMATE_FEE_MINIMAL); } @@ -783,7 +783,7 @@ public class BtcEngine extends CoinEngine { final ServerApiElectrum serverApiElectrum = new ServerApiElectrum(); final String txStr = BTCUtils.toHex(txForSend); - ServerApiElectrum.ElectrumRequestDataListener electrumListener = new ServerApiElectrum.ElectrumRequestDataListener() { + ServerApiElectrum.ResponseListener electrumListener = new ServerApiElectrum.ResponseListener() { @Override public void onSuccess(ElectrumRequest electrumRequest) { if (electrumRequest.isMethod(ElectrumRequest.METHOD_SendTransaction)) { @@ -814,10 +814,10 @@ public class BtcEngine extends CoinEngine { blockchainRequestsCallbacks.onComplete(false); } }; - serverApiElectrum.setElectrumRequestData(electrumListener); + serverApiElectrum.setResponseListener(electrumListener); - serverApiElectrum.electrumRequestData(ctx, ElectrumRequest.broadcast(ctx.getCoinData().getWallet(), txStr)); + serverApiElectrum.requestData(ctx, ElectrumRequest.broadcast(ctx.getCoinData().getWallet(), txStr)); } diff --git a/app/src/main/java/com/tangem/domain/wallet/ducatus/DucatusEngine.java b/app/src/main/java/com/tangem/domain/wallet/ducatus/DucatusEngine.java index 682d62ac33..32261ff2c9 100644 --- a/app/src/main/java/com/tangem/domain/wallet/ducatus/DucatusEngine.java +++ b/app/src/main/java/com/tangem/domain/wallet/ducatus/DucatusEngine.java @@ -4,8 +4,6 @@ import android.net.Uri; import android.text.InputFilter; import android.util.Log; -import com.tangem.data.network.ElectrumRequest; -import com.tangem.data.network.InsightApi; import com.tangem.data.network.ServerApiInsight; import com.tangem.data.network.model.InsightResponse; import com.tangem.domain.wallet.BTCUtils; @@ -26,10 +24,6 @@ import com.tangem.util.DecimalDigitsInputFilter; import com.tangem.util.DerEncodingUtil; import com.tangem.wallet.R; -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; - import java.io.ByteArrayOutputStream; import java.math.BigDecimal; import java.math.BigInteger; @@ -179,7 +173,7 @@ public class DucatusEngine extends BtcEngine { } @Override - public Uri getShareWalletUriExplorer() { + public Uri getWalletExplorerUri() { return Uri.parse("https://live.blockcypher.com/ltc/address/" + ctx.getCoinData().getWallet()); } @@ -397,7 +391,7 @@ public class DucatusEngine extends BtcEngine { } @Override - public SignTask.PaymentToSign constructPayment(Amount amountValue, Amount feeValue, boolean IncFee, String targetAddress) throws Exception { + public SignTask.TransactionToSign constructTransaction(Amount amountValue, Amount feeValue, boolean IncFee, String targetAddress) throws Exception { final ArrayList unspentOutputs; checkBlockchainDataExists(); @@ -442,7 +436,7 @@ public class DucatusEngine extends BtcEngine { bodyDoubleHash[i] = Util.calculateSHA256(bodyHash[i]); } - return new SignTask.PaymentToSign() { + return new SignTask.TransactionToSign() { @Override public boolean isSigningMethodSupported(TangemCard.SigningMethod signingMethod) { @@ -492,7 +486,7 @@ public class DucatusEngine extends BtcEngine { } byte[] txForSend=BTCUtils.buildTXForSend(targetAddress, myAddress, unspentOutputs, amountFinal, changeFinal); - notifyOnNeedSendPayment(txForSend); + notifyOnNeedSendTransaction(txForSend); return txForSend; } }; @@ -502,7 +496,7 @@ public class DucatusEngine extends BtcEngine { public void requestBalanceAndUnspentTransactions(BlockchainRequestsCallbacks blockchainRequestsCallbacks) { final ServerApiInsight serverApiInsight = new ServerApiInsight(); - ServerApiInsight.InsightBodyListener insightBodyListener = new ServerApiInsight.InsightBodyListener() { + ServerApiInsight.ResponseListener responseListener = new ServerApiInsight.ResponseListener() { @Override public void onSuccess(String method, InsightResponse insightResponse) { switch (method) { @@ -562,7 +556,7 @@ public class DucatusEngine extends BtcEngine { for (InsightResponse utxo : utxoList) { //if (height != -1) { TODO: check if (blockchainRequestsCallbacks.allowAdvance()) { - serverApiInsight.insight(ServerApiInsight.INSIGHT_TRANSACTION, "", utxo.getTxid()); + serverApiInsight.requestData(ServerApiInsight.INSIGHT_TRANSACTION, "", utxo.getTxid()); } else { ctx.setError("Terminated by user"); } @@ -582,10 +576,10 @@ public class DucatusEngine extends BtcEngine { } }; - serverApiInsight.setInsightResponse(insightBodyListener); + serverApiInsight.setResponseListener(responseListener); - serverApiInsight.insight(ServerApiInsight.INSIGHT_ADDRESS, coinData.getWallet(), ""); - serverApiInsight.insight(ServerApiInsight.INSIGHT_UNSPENT_OUTPUTS, coinData.getWallet(), ""); + serverApiInsight.requestData(ServerApiInsight.INSIGHT_ADDRESS, coinData.getWallet(), ""); + serverApiInsight.requestData(ServerApiInsight.INSIGHT_UNSPENT_OUTPUTS, coinData.getWallet(), ""); } // private final static BigDecimal relayFee = new BigDecimal(0.00001); @@ -600,7 +594,7 @@ public class DucatusEngine extends BtcEngine { final ServerApiInsight serverApiInsight = new ServerApiInsight(); - final ServerApiInsight.InsightBodyListener insightBodyListener = new ServerApiInsight.InsightBodyListener () { + final ServerApiInsight.ResponseListener responseListener = new ServerApiInsight.ResponseListener() { @Override public void onSuccess(String method, InsightResponse insightResponse) { if ( method.equals(ServerApiInsight.INSIGHT_FEE)) { @@ -610,7 +604,7 @@ public class DucatusEngine extends BtcEngine { BigDecimal maxFee = new BigDecimal(insightResponse.getFee6()); if (minFee.equals(BigDecimal.ZERO) || normalFee.equals(BigDecimal.ZERO) || maxFee.equals(BigDecimal.ZERO)) { - serverApiInsight.insight(ServerApiInsight.INSIGHT_FEE, "",""); + serverApiInsight.requestData(ServerApiInsight.INSIGHT_FEE, "",""); } minFee = minFee.multiply(new BigDecimal(calcSize)).divide(new BigDecimal(1024)); // (per KB -> per byte)*size @@ -650,9 +644,9 @@ public class DucatusEngine extends BtcEngine { } } }; - serverApiInsight.setInsightResponse(insightBodyListener); + serverApiInsight.setResponseListener(responseListener); - serverApiInsight.insight(ServerApiInsight.INSIGHT_FEE, "", ""); + serverApiInsight.requestData(ServerApiInsight.INSIGHT_FEE, "", ""); } @Override @@ -660,7 +654,7 @@ public class DucatusEngine extends BtcEngine { final ServerApiInsight serverApiInsight = new ServerApiInsight(); final String txStr = BTCUtils.toHex(txForSend); - final ServerApiInsight.InsightBodyListener insightBodyListener = new ServerApiInsight.InsightBodyListener () { + final ServerApiInsight.ResponseListener responseListener = new ServerApiInsight.ResponseListener() { @Override public void onSuccess(String method, InsightResponse insightResponse) { if (method.equals(ServerApiInsight.INSIGHT_SEND)) { @@ -700,8 +694,8 @@ public class DucatusEngine extends BtcEngine { } } }; - serverApiInsight.setInsightResponse(insightBodyListener); + serverApiInsight.setResponseListener(responseListener); - serverApiInsight.insight(ServerApiInsight.INSIGHT_SEND, "", txStr); + serverApiInsight.requestData(ServerApiInsight.INSIGHT_SEND, "", txStr); } } \ No newline at end of file diff --git a/app/src/main/java/com/tangem/domain/wallet/eth/EthEngine.java b/app/src/main/java/com/tangem/domain/wallet/eth/EthEngine.java index c885e8fb85..19e5c3d1fc 100644 --- a/app/src/main/java/com/tangem/domain/wallet/eth/EthEngine.java +++ b/app/src/main/java/com/tangem/domain/wallet/eth/EthEngine.java @@ -236,7 +236,7 @@ public class EthEngine extends CoinEngine { } @Override - public Uri getShareWalletUriExplorer() { + public Uri getWalletExplorerUri() { if (ctx.getBlockchain() == Blockchain.EthereumTestNet) return Uri.parse("https://rinkeby.etherscan.io/address/" + ctx.getCoinData().getWallet()); else @@ -379,9 +379,9 @@ public class EthEngine extends CoinEngine { } @Override - public SignTask.PaymentToSign constructPayment(Amount amountValue, Amount feeValue, boolean IncFee, String targetAddress) { + public SignTask.TransactionToSign constructTransaction(Amount amountValue, Amount feeValue, boolean IncFee, String targetAddress) { - Log.e(TAG, "Construct payment " + amountValue.toString() + " with fee " + feeValue.toString() + (IncFee ? " including" : " excluding")); + Log.e(TAG, "Construct transaction " + amountValue.toString() + " with fee " + feeValue.toString() + (IncFee ? " including" : " excluding")); BigInteger nonceValue = coinData.getConfirmedTXCount(); byte[] pbKey = ctx.getCard().getWalletPublicKey(); @@ -404,7 +404,7 @@ public class EthEngine extends CoinEngine { final EthTransaction tx = EthTransaction.create(to, weiAmount, nonceValue, gasPrice, gasLimit, this.getChainId()); - return new SignTask.PaymentToSign() { + return new SignTask.TransactionToSign() { @Override public boolean isSigningMethodSupported(TangemCard.SigningMethod signingMethod) { return signingMethod == TangemCard.SigningMethod.Sign_Hash; @@ -455,7 +455,7 @@ public class EthEngine extends CoinEngine { Log.e(TAG, "ETH_v: " +String.valueOf(v)); byte[] txForSend = tx.getEncoded(); - notifyOnNeedSendPayment(txForSend); + notifyOnNeedSendTransaction(txForSend); return txForSend; } }; @@ -464,8 +464,8 @@ public class EthEngine extends CoinEngine { @Override public void requestBalanceAndUnspentTransactions(BlockchainRequestsCallbacks blockchainRequestsCallbacks) { final ServerApiInfura serverApiInfura = new ServerApiInfura(); - // request infura listener - ServerApiInfura.InfuraBodyListener infuraBodyListener = new ServerApiInfura.InfuraBodyListener() { + // request requestData listener + ServerApiInfura.ResponseListener responseListener = new ServerApiInfura.ResponseListener() { @Override public void onSuccess(String method, InfuraResponse infuraResponse) { switch (method) { @@ -517,18 +517,18 @@ public class EthEngine extends CoinEngine { } } }; - serverApiInfura.setInfuraResponse(infuraBodyListener); + serverApiInfura.setResponseListener(responseListener); - serverApiInfura.infura(ServerApiInfura.INFURA_ETH_GET_BALANCE, 67, coinData.getWallet(), "", ""); - serverApiInfura.infura(ServerApiInfura.INFURA_ETH_GET_TRANSACTION_COUNT, 67, coinData.getWallet(), "", ""); - serverApiInfura.infura(ServerApiInfura.INFURA_ETH_GET_PENDING_COUNT, 67, coinData.getWallet(), "", ""); + serverApiInfura.requestData(ServerApiInfura.INFURA_ETH_GET_BALANCE, 67, coinData.getWallet(), "", ""); + serverApiInfura.requestData(ServerApiInfura.INFURA_ETH_GET_TRANSACTION_COUNT, 67, coinData.getWallet(), "", ""); + serverApiInfura.requestData(ServerApiInfura.INFURA_ETH_GET_PENDING_COUNT, 67, coinData.getWallet(), "", ""); } @Override public void requestFee(BlockchainRequestsCallbacks blockchainRequestsCallbacks, String targetAddress, Amount amount) { ServerApiInfura serverApiInfura = new ServerApiInfura(); - // request infura eth gasPrice listener - ServerApiInfura.InfuraBodyListener infuraBodyListener = new ServerApiInfura.InfuraBodyListener() { + // request requestData eth gasPrice listener + ServerApiInfura.ResponseListener responseListener = new ServerApiInfura.ResponseListener() { @Override public void onSuccess(String method, InfuraResponse infuraResponse) { String gasPrice = infuraResponse.getResult(); @@ -566,9 +566,9 @@ public class EthEngine extends CoinEngine { blockchainRequestsCallbacks.onComplete(false); } }; - serverApiInfura.setInfuraResponse(infuraBodyListener); + serverApiInfura.setResponseListener(responseListener); - serverApiInfura.infura(ServerApiInfura.INFURA_ETH_GAS_PRICE, 67, coinData.getWallet(), "", ""); + serverApiInfura.requestData(ServerApiInfura.INFURA_ETH_GAS_PRICE, 67, coinData.getWallet(), "", ""); } @Override @@ -577,8 +577,8 @@ public class EthEngine extends CoinEngine { String txStr = String.format("0x%s", BTCUtils.toHex(txForSend)); ServerApiInfura serverApiInfura = new ServerApiInfura(); - // request infura eth gasPrice listener - ServerApiInfura.InfuraBodyListener infuraBodyListener = new ServerApiInfura.InfuraBodyListener() { + // request requestData eth gasPrice listener + ServerApiInfura.ResponseListener responseListener = new ServerApiInfura.ResponseListener() { @Override public void onSuccess(String method, InfuraResponse infuraResponse) { if (method.equals(ServerApiInfura.INFURA_ETH_SEND_RAW_TRANSACTION)) { @@ -604,9 +604,9 @@ public class EthEngine extends CoinEngine { } }; - serverApiInfura.setInfuraResponse(infuraBodyListener); + serverApiInfura.setResponseListener(responseListener); - serverApiInfura.infura(ServerApiInfura.INFURA_ETH_SEND_RAW_TRANSACTION, 67, coinData.getWallet(), "", txStr); + serverApiInfura.requestData(ServerApiInfura.INFURA_ETH_SEND_RAW_TRANSACTION, 67, coinData.getWallet(), "", txStr); } } diff --git a/app/src/main/java/com/tangem/domain/wallet/ltc/LtcEngine.java b/app/src/main/java/com/tangem/domain/wallet/ltc/LtcEngine.java index 4ab77928ef..a0c3eb7dc3 100644 --- a/app/src/main/java/com/tangem/domain/wallet/ltc/LtcEngine.java +++ b/app/src/main/java/com/tangem/domain/wallet/ltc/LtcEngine.java @@ -176,7 +176,7 @@ public class LtcEngine extends BtcEngine { } @Override - public Uri getShareWalletUriExplorer() { + public Uri getWalletExplorerUri() { return Uri.parse("https://live.blockcypher.com/ltc/address/" + ctx.getCoinData().getWallet()); } @@ -394,7 +394,7 @@ public class LtcEngine extends BtcEngine { } @Override - public SignTask.PaymentToSign constructPayment(Amount amountValue, Amount feeValue, boolean IncFee, String targetAddress) throws Exception { + public SignTask.TransactionToSign constructTransaction(Amount amountValue, Amount feeValue, boolean IncFee, String targetAddress) throws Exception { final ArrayList unspentOutputs; checkBlockchainDataExists(); @@ -439,7 +439,7 @@ public class LtcEngine extends BtcEngine { bodyDoubleHash[i] = Util.calculateSHA256(bodyHash[i]); } - return new SignTask.PaymentToSign() { + return new SignTask.TransactionToSign() { @Override public boolean isSigningMethodSupported(TangemCard.SigningMethod signingMethod) { @@ -489,7 +489,7 @@ public class LtcEngine extends BtcEngine { } byte[] txForSend=BTCUtils.buildTXForSend(targetAddress, myAddress, unspentOutputs, amountFinal, changeFinal); - notifyOnNeedSendPayment(txForSend); + notifyOnNeedSendTransaction(txForSend); return txForSend; } }; @@ -507,7 +507,7 @@ public class LtcEngine extends BtcEngine { final ServerApiElectrum serverApiElectrum = new ServerApiElectrum(); - final ServerApiElectrum.ElectrumRequestDataListener electrumListener = new ServerApiElectrum.ElectrumRequestDataListener () { + final ServerApiElectrum.ResponseListener electrumListener = new ServerApiElectrum.ResponseListener() { @Override public void onSuccess(ElectrumRequest electrumRequest) { BigDecimal fee; @@ -516,13 +516,13 @@ public class LtcEngine extends BtcEngine { fee = new BigDecimal(electrumRequest.getResultString()); //fee per KB if (fee.equals(BigDecimal.ZERO)) { - serverApiElectrum.electrumRequestData(ctx, ElectrumRequest.getFee()); + serverApiElectrum.requestData(ctx, ElectrumRequest.getFee()); } // if (calcSize != 0) { fee = fee.multiply(new BigDecimal(calcSize)).divide(new BigDecimal(1024)); // (per KB -> per byte)*size // } else { -// serverApiElectrum.electrumRequestData(ctx, ElectrumRequest.getFee()); +// serverApiElectrum.requestData(ctx, ElectrumRequest.getFee()); // } //compare fee to usual relay fee @@ -553,8 +553,8 @@ public class LtcEngine extends BtcEngine { blockchainRequestsCallbacks.onComplete(false); } }; - serverApiElectrum.setElectrumRequestData(electrumListener); + serverApiElectrum.setResponseListener(electrumListener); - serverApiElectrum.electrumRequestData(ctx, ElectrumRequest.getFee()); + serverApiElectrum.requestData(ctx, ElectrumRequest.getFee()); } } \ No newline at end of file diff --git a/app/src/main/java/com/tangem/domain/wallet/rsk/RskEngine.java b/app/src/main/java/com/tangem/domain/wallet/rsk/RskEngine.java index 3d381f5b5f..e63e41a529 100644 --- a/app/src/main/java/com/tangem/domain/wallet/rsk/RskEngine.java +++ b/app/src/main/java/com/tangem/domain/wallet/rsk/RskEngine.java @@ -66,12 +66,12 @@ public class RskEngine extends EthEngine { public Uri getShareWalletUri() { return Uri.parse(ctx.getCoinData().getWallet()); } @Override - public Uri getShareWalletUriExplorer() { return Uri.parse("https://explorer.rsk.co/address/" + ctx.getCoinData().getWallet()); } + public Uri getWalletExplorerUri() { return Uri.parse("https://explorer.rsk.co/address/" + ctx.getCoinData().getWallet()); } @Override - public SignTask.PaymentToSign constructPayment(Amount amountValue, Amount feeValue, boolean IncFee, String targetAddress) { + public SignTask.TransactionToSign constructTransaction(Amount amountValue, Amount feeValue, boolean IncFee, String targetAddress) { - Log.e(TAG, "Construct payment " + amountValue.toString() + " with fee " + feeValue.toString() + (IncFee ? " including" : " excluding")); + Log.e(TAG, "Construct transaction " + amountValue.toString() + " with fee " + feeValue.toString() + (IncFee ? " including" : " excluding")); BigInteger nonceValue = coinData.getConfirmedTXCount(); byte[] pbKey = ctx.getCard().getWalletPublicKey(); @@ -95,7 +95,7 @@ public class RskEngine extends EthEngine { final EthTransaction tx = EthTransaction.create(to, weiAmount, nonceValue, gasPrice, gasLimit, chainId); - return new SignTask.PaymentToSign() { + return new SignTask.TransactionToSign() { @Override public boolean isSigningMethodSupported(TangemCard.SigningMethod signingMethod) { return signingMethod == TangemCard.SigningMethod.Sign_Hash; @@ -146,7 +146,7 @@ public class RskEngine extends EthEngine { Log.e(TAG, "RSK_v: " +String.valueOf(v)); byte[] txForSend = tx.getEncoded(); - notifyOnNeedSendPayment(txForSend); + notifyOnNeedSendTransaction(txForSend); return txForSend; } }; @@ -155,8 +155,8 @@ public class RskEngine extends EthEngine { @Override public void requestBalanceAndUnspentTransactions(BlockchainRequestsCallbacks blockchainRequestsCallbacks) { final ServerApiRootstock serverApiRootstock = new ServerApiRootstock(); - // request rootstock listener - ServerApiRootstock.RootstockBodyListener rootstockBodyListener = new ServerApiRootstock.RootstockBodyListener() { + // request requestData listener + ServerApiRootstock.ResponseListener responseListener = new ServerApiRootstock.ResponseListener() { @Override public void onSuccess(String method, InfuraResponse rootstockResponse) { switch (method) { @@ -208,18 +208,18 @@ public class RskEngine extends EthEngine { } } }; - serverApiRootstock.setRootstockResponse(rootstockBodyListener); + serverApiRootstock.setResponseListener(responseListener); - serverApiRootstock.rootstock(ServerApiRootstock.ROOTSTOCK_ETH_GET_BALANCE, 67, coinData.getWallet(), "", ""); - serverApiRootstock.rootstock(ServerApiRootstock.ROOTSTOCK_ETH_GET_TRANSACTION_COUNT, 67, coinData.getWallet(), "", ""); - serverApiRootstock.rootstock(ServerApiRootstock.ROOTSTOCK_ETH_GET_PENDING_COUNT, 67, coinData.getWallet(), "", ""); + serverApiRootstock.requestData(ServerApiRootstock.ROOTSTOCK_ETH_GET_BALANCE, 67, coinData.getWallet(), "", ""); + serverApiRootstock.requestData(ServerApiRootstock.ROOTSTOCK_ETH_GET_TRANSACTION_COUNT, 67, coinData.getWallet(), "", ""); + serverApiRootstock.requestData(ServerApiRootstock.ROOTSTOCK_ETH_GET_PENDING_COUNT, 67, coinData.getWallet(), "", ""); } @Override public void requestFee(BlockchainRequestsCallbacks blockchainRequestsCallbacks, String targetAddress, Amount amount) { ServerApiRootstock serverApiRootstock = new ServerApiRootstock(); - // request rootstock gasPrice listener - ServerApiRootstock.RootstockBodyListener rootstockBodyListener = new ServerApiRootstock.RootstockBodyListener() { + // request requestData gasPrice listener + ServerApiRootstock.ResponseListener responseListener = new ServerApiRootstock.ResponseListener() { @Override public void onSuccess(String method, InfuraResponse rootstockResponse) { String gasPrice = rootstockResponse.getResult(); @@ -257,9 +257,9 @@ public class RskEngine extends EthEngine { blockchainRequestsCallbacks.onComplete(false); } }; - serverApiRootstock.setRootstockResponse(rootstockBodyListener); + serverApiRootstock.setResponseListener(responseListener); - serverApiRootstock.rootstock(ServerApiRootstock.ROOTSTOCK_ETH_GAS_PRICE, 67, coinData.getWallet(), "", ""); + serverApiRootstock.requestData(ServerApiRootstock.ROOTSTOCK_ETH_GAS_PRICE, 67, coinData.getWallet(), "", ""); } @Override @@ -268,7 +268,7 @@ public class RskEngine extends EthEngine { String txStr = String.format("0x%s", BTCUtils.toHex(txForSend)); ServerApiRootstock serverApiRootstock = new ServerApiRootstock(); - ServerApiRootstock.RootstockBodyListener rootstockBodyListener = new ServerApiRootstock.RootstockBodyListener() { + ServerApiRootstock.ResponseListener responseListener = new ServerApiRootstock.ResponseListener() { @Override public void onSuccess(String method, InfuraResponse rootstockResponse) { if (method.equals(ServerApiRootstock.ROOTSTOCK_ETH_SEND_RAW_TRANSACTION)) { @@ -294,9 +294,9 @@ public class RskEngine extends EthEngine { } }; - serverApiRootstock.setRootstockResponse(rootstockBodyListener); + serverApiRootstock.setResponseListener(responseListener); - serverApiRootstock.rootstock(ServerApiRootstock.ROOTSTOCK_ETH_SEND_RAW_TRANSACTION, 67, coinData.getWallet(), "", txStr); + serverApiRootstock.requestData(ServerApiRootstock.ROOTSTOCK_ETH_SEND_RAW_TRANSACTION, 67, coinData.getWallet(), "", txStr); } diff --git a/app/src/main/java/com/tangem/domain/wallet/rsk/RskTokenEngine.java b/app/src/main/java/com/tangem/domain/wallet/rsk/RskTokenEngine.java index f571505f4b..89e6e362ce 100644 --- a/app/src/main/java/com/tangem/domain/wallet/rsk/RskTokenEngine.java +++ b/app/src/main/java/com/tangem/domain/wallet/rsk/RskTokenEngine.java @@ -105,7 +105,7 @@ public class RskTokenEngine extends TokenEngine { } @Override - public Uri getShareWalletUriExplorer() { return Uri.parse("https://explorer.rsk.co/address/" + ctx.getCoinData().getWallet()); } // Only RSK explorer for now + public Uri getWalletExplorerUri() { return Uri.parse("https://explorer.rsk.co/address/" + ctx.getCoinData().getWallet()); } // Only RSK explorer for now @Override public Uri getShareWalletUri() { return Uri.parse(ctx.getCoinData().getWallet()); } @@ -186,16 +186,16 @@ public class RskTokenEngine extends TokenEngine { } @Override - public SignTask.PaymentToSign constructPayment(Amount amountValue, Amount feeValue, boolean IncFee, String targetAddress) throws Exception { + public SignTask.TransactionToSign constructTransaction(Amount amountValue, Amount feeValue, boolean IncFee, String targetAddress) throws Exception { if (amountValue.getCurrency().equals(Blockchain.Rootstock.getCurrency())) { - return constructPaymentRBTC(feeValue, amountValue, IncFee, targetAddress); + return constructTransactionRBTC(feeValue, amountValue, IncFee, targetAddress); } else { - return constructPaymentToken(feeValue, amountValue, IncFee, targetAddress); + return constructTransactionToken(feeValue, amountValue, IncFee, targetAddress); } } - private SignTask.PaymentToSign constructPaymentRBTC(Amount feeValue, Amount amountValue, boolean IncFee, String targetAddress) throws Exception { - Log.e(TAG, "Construct RBTC payment "+amountValue.toString()+" with fee "+feeValue.toString()+(IncFee?" including":" excluding")); + private SignTask.TransactionToSign constructTransactionRBTC(Amount feeValue, Amount amountValue, boolean IncFee, String targetAddress) throws Exception { + Log.e(TAG, "Construct RBTC transaction "+amountValue.toString()+" with fee "+feeValue.toString()+(IncFee?" including":" excluding")); BigInteger nonceValue = coinData.getConfirmedTXCount(); byte[] pbKey = ctx.getCard().getWalletPublicKey(); @@ -219,7 +219,7 @@ public class RskTokenEngine extends TokenEngine { final EthTransaction tx = EthTransaction.create(to, weiAmount, nonceValue, gasPrice, gasLimit, chainId); - return new SignTask.PaymentToSign() { + return new SignTask.TransactionToSign() { @Override public boolean isSigningMethodSupported(TangemCard.SigningMethod signingMethod) { return signingMethod == TangemCard.SigningMethod.Sign_Hash; @@ -270,14 +270,14 @@ public class RskTokenEngine extends TokenEngine { Log.e(TAG,"RSK_v "+ String.valueOf(v)); byte[] txForSend = tx.getEncoded(); - notifyOnNeedSendPayment(txForSend); + notifyOnNeedSendTransaction(txForSend); return txForSend; } }; } - private SignTask.PaymentToSign constructPaymentToken(Amount feeValue, Amount amountValue, boolean IncFee, String targetAddress) throws Exception { - Log.e(TAG, "Construct TOKEN payment "+amountValue.toString()+" with fee "+feeValue.toString()+(IncFee?" including":" excluding")); + private SignTask.TransactionToSign constructTransactionToken(Amount feeValue, Amount amountValue, boolean IncFee, String targetAddress) throws Exception { + Log.e(TAG, "Construct TOKEN transaction "+amountValue.toString()+" with fee "+feeValue.toString()+(IncFee?" including":" excluding")); BigInteger nonceValue = coinData.getConfirmedTXCount(); byte[] pbKey = ctx.getCard().getWalletPublicKey(); @@ -327,7 +327,7 @@ public class RskTokenEngine extends TokenEngine { byte[] data = BTCUtils.fromHex(cmd); EthTransaction tx = EthTransaction.create(contractAddress, amountZero, nonceValue, gasPrice, gasLimit, chainId, data); - return new SignTask.PaymentToSign() { + return new SignTask.TransactionToSign() { @Override public boolean isSigningMethodSupported(TangemCard.SigningMethod signingMethod) { return signingMethod == TangemCard.SigningMethod.Sign_Hash; @@ -378,7 +378,7 @@ public class RskTokenEngine extends TokenEngine { Log.e(TAG,"RSK_v: "+ String.valueOf(v)); byte[] txForSend = tx.getEncoded(); - notifyOnNeedSendPayment(txForSend); + notifyOnNeedSendTransaction(txForSend); return txForSend; } @@ -389,8 +389,8 @@ public class RskTokenEngine extends TokenEngine { @Override public void requestBalanceAndUnspentTransactions(BlockchainRequestsCallbacks blockchainRequestsCallbacks) { final ServerApiRootstock serverApiRootstock = new ServerApiRootstock(); - // request rootstock listener - ServerApiRootstock.RootstockBodyListener rootstockBodyListener = new ServerApiRootstock.RootstockBodyListener() { + // request requestData listener + ServerApiRootstock.ResponseListener responseListener = new ServerApiRootstock.ResponseListener() { @Override public void onSuccess(String method, InfuraResponse rootstockResponse) { switch (method) { @@ -436,9 +436,9 @@ public class RskTokenEngine extends TokenEngine { // Log.i("$TAG eth_call", balanceCap) if (blockchainRequestsCallbacks.allowAdvance()) { - serverApiRootstock.rootstock(ServerApiRootstock.ROOTSTOCK_ETH_GET_BALANCE, 67, coinData.getWallet(), "", ""); - serverApiRootstock.rootstock(ServerApiRootstock.ROOTSTOCK_ETH_GET_TRANSACTION_COUNT, 67, coinData.getWallet(), "", ""); - serverApiRootstock.rootstock(ServerApiRootstock.ROOTSTOCK_ETH_GET_PENDING_COUNT, 67, coinData.getWallet(), "", ""); + serverApiRootstock.requestData(ServerApiRootstock.ROOTSTOCK_ETH_GET_BALANCE, 67, coinData.getWallet(), "", ""); + serverApiRootstock.requestData(ServerApiRootstock.ROOTSTOCK_ETH_GET_TRANSACTION_COUNT, 67, coinData.getWallet(), "", ""); + serverApiRootstock.requestData(ServerApiRootstock.ROOTSTOCK_ETH_GET_PENDING_COUNT, 67, coinData.getWallet(), "", ""); } else { ctx.setError("Terminated by user"); } @@ -465,16 +465,16 @@ public class RskTokenEngine extends TokenEngine { } } }; - serverApiRootstock.setRootstockResponse(rootstockBodyListener); + serverApiRootstock.setResponseListener(responseListener); - serverApiRootstock.rootstock(ServerApiRootstock.ROOTSTOCK_ETH_CALL, 67, coinData.getWallet(), getContractAddress(ctx.getCard()), ""); + serverApiRootstock.requestData(ServerApiRootstock.ROOTSTOCK_ETH_CALL, 67, coinData.getWallet(), getContractAddress(ctx.getCard()), ""); } @Override public void requestFee(BlockchainRequestsCallbacks blockchainRequestsCallbacks, String targetAddress, Amount amount) { ServerApiRootstock serverApiRootstock = new ServerApiRootstock(); - // request rootstock gasPrice listener - ServerApiRootstock.RootstockBodyListener rootstockBodyListener = new ServerApiRootstock.RootstockBodyListener() { + // request requestData gasPrice listener + ServerApiRootstock.ResponseListener responseListener = new ServerApiRootstock.ResponseListener() { @Override public void onSuccess(String method, InfuraResponse rootstockResponse) { String gasPrice = rootstockResponse.getResult(); @@ -516,9 +516,9 @@ public class RskTokenEngine extends TokenEngine { blockchainRequestsCallbacks.onComplete(false); } }; - serverApiRootstock.setRootstockResponse(rootstockBodyListener); + serverApiRootstock.setResponseListener(responseListener); - serverApiRootstock.rootstock(ServerApiRootstock.ROOTSTOCK_ETH_GAS_PRICE, 67, coinData.getWallet(), "", ""); + serverApiRootstock.requestData(ServerApiRootstock.ROOTSTOCK_ETH_GAS_PRICE, 67, coinData.getWallet(), "", ""); } @Override @@ -527,8 +527,8 @@ public class RskTokenEngine extends TokenEngine { String txStr = String.format("0x%s", BTCUtils.toHex(txForSend)); ServerApiRootstock serverApiRootstock = new ServerApiRootstock(); - // request rootstock listener - ServerApiRootstock.RootstockBodyListener rootstockBodyListener = new ServerApiRootstock.RootstockBodyListener() { + // request requestData listener + ServerApiRootstock.ResponseListener responseListener = new ServerApiRootstock.ResponseListener() { @Override public void onSuccess(String method, InfuraResponse infuraResponse) { if (method.equals(ServerApiRootstock.ROOTSTOCK_ETH_SEND_RAW_TRANSACTION)) { @@ -554,9 +554,9 @@ public class RskTokenEngine extends TokenEngine { } }; - serverApiRootstock.setRootstockResponse(rootstockBodyListener); + serverApiRootstock.setResponseListener(responseListener); - serverApiRootstock.rootstock(ServerApiRootstock.ROOTSTOCK_ETH_SEND_RAW_TRANSACTION, 67, coinData.getWallet(), "", txStr); + serverApiRootstock.requestData(ServerApiRootstock.ROOTSTOCK_ETH_SEND_RAW_TRANSACTION, 67, coinData.getWallet(), "", txStr); } diff --git a/app/src/main/java/com/tangem/domain/wallet/token/TokenEngine.java b/app/src/main/java/com/tangem/domain/wallet/token/TokenEngine.java index dd6e5fb76f..24d6604619 100644 --- a/app/src/main/java/com/tangem/domain/wallet/token/TokenEngine.java +++ b/app/src/main/java/com/tangem/domain/wallet/token/TokenEngine.java @@ -289,7 +289,7 @@ public class TokenEngine extends CoinEngine { @Override - public Uri getShareWalletUriExplorer() { + public Uri getWalletExplorerUri() { return Uri.parse("https://etherscan.io/token/" + getContractAddress(ctx.getCard()) + "?a=" + ctx.getCoinData().getWallet()); } @@ -431,16 +431,16 @@ public class TokenEngine extends CoinEngine { } @Override - public SignTask.PaymentToSign constructPayment(Amount amountValue, Amount feeValue, boolean IncFee, String targetAddress) throws Exception { + public SignTask.TransactionToSign constructTransaction(Amount amountValue, Amount feeValue, boolean IncFee, String targetAddress) throws Exception { if (amountValue.getCurrency().equals(Blockchain.Ethereum.getCurrency())) { - return constructPaymentETH(feeValue, amountValue, IncFee, targetAddress); + return constructTransactionETH(feeValue, amountValue, IncFee, targetAddress); } else { - return constructPaymentToken(feeValue, amountValue, IncFee, targetAddress); + return constructTransactionToken(feeValue, amountValue, IncFee, targetAddress); } } - private SignTask.PaymentToSign constructPaymentETH(Amount feeValue, Amount amountValue, boolean IncFee, String targetAddress) throws Exception { - Log.e(TAG, "Construct ETH payment "+amountValue.toString()+" with fee "+feeValue.toString()+(IncFee?" including":" excluding")); + private SignTask.TransactionToSign constructTransactionETH(Amount feeValue, Amount amountValue, boolean IncFee, String targetAddress) throws Exception { + Log.e(TAG, "Construct ETH transaction "+amountValue.toString()+" with fee "+feeValue.toString()+(IncFee?" including":" excluding")); BigInteger nonceValue = coinData.getConfirmedTXCount(); byte[] pbKey = ctx.getCard().getWalletPublicKey(); @@ -465,7 +465,7 @@ public class TokenEngine extends CoinEngine { final EthTransaction tx = EthTransaction.create(to, weiAmount, nonceValue, gasPrice, gasLimit, chainId); - return new SignTask.PaymentToSign() { + return new SignTask.TransactionToSign() { @Override public boolean isSigningMethodSupported(TangemCard.SigningMethod signingMethod) { return signingMethod == TangemCard.SigningMethod.Sign_Hash; @@ -516,14 +516,14 @@ public class TokenEngine extends CoinEngine { Log.e(TAG,"ETH_v "+ String.valueOf(v)); byte[] txForSend = tx.getEncoded(); - notifyOnNeedSendPayment(txForSend); + notifyOnNeedSendTransaction(txForSend); return txForSend; } }; } - private SignTask.PaymentToSign constructPaymentToken(Amount feeValue, Amount amountValue, boolean IncFee, String targetAddress) throws Exception { - Log.e(TAG, "Construct TOKEN payment "+amountValue.toString()+" with fee "+feeValue.toString()+(IncFee?" including":" excluding")); + private SignTask.TransactionToSign constructTransactionToken(Amount feeValue, Amount amountValue, boolean IncFee, String targetAddress) throws Exception { + Log.e(TAG, "Construct TOKEN transaction "+amountValue.toString()+" with fee "+feeValue.toString()+(IncFee?" including":" excluding")); BigInteger nonceValue = coinData.getConfirmedTXCount(); byte[] pbKey = ctx.getCard().getWalletPublicKey(); @@ -573,7 +573,7 @@ public class TokenEngine extends CoinEngine { byte[] data = BTCUtils.fromHex(cmd); EthTransaction tx = EthTransaction.create(contractAddress, amountZero, nonceValue, gasPrice, gasLimit, chainId, data); - return new SignTask.PaymentToSign() { + return new SignTask.TransactionToSign() { @Override public boolean isSigningMethodSupported(TangemCard.SigningMethod signingMethod) { return signingMethod == TangemCard.SigningMethod.Sign_Hash; @@ -624,7 +624,7 @@ public class TokenEngine extends CoinEngine { Log.e(TAG,"ETH_v: "+ String.valueOf(v)); byte[] txForSend = tx.getEncoded(); - notifyOnNeedSendPayment(txForSend); + notifyOnNeedSendTransaction(txForSend); return txForSend; } @@ -635,8 +635,8 @@ public class TokenEngine extends CoinEngine { @Override public void requestBalanceAndUnspentTransactions(BlockchainRequestsCallbacks blockchainRequestsCallbacks) { final ServerApiInfura serverApiInfura = new ServerApiInfura(); - // request infura listener - ServerApiInfura.InfuraBodyListener infuraBodyListener = new ServerApiInfura.InfuraBodyListener() { + // request requestData listener + ServerApiInfura.ResponseListener responseListener = new ServerApiInfura.ResponseListener() { @Override public void onSuccess(String method, InfuraResponse infuraResponse) { switch (method) { @@ -682,9 +682,9 @@ public class TokenEngine extends CoinEngine { // Log.i("$TAG eth_call", balanceCap) if (blockchainRequestsCallbacks.allowAdvance()) { - serverApiInfura.infura(ServerApiInfura.INFURA_ETH_GET_BALANCE, 67, coinData.getWallet(), "", ""); - serverApiInfura.infura(ServerApiInfura.INFURA_ETH_GET_TRANSACTION_COUNT, 67, coinData.getWallet(), "", ""); - serverApiInfura.infura(ServerApiInfura.INFURA_ETH_GET_PENDING_COUNT, 67, coinData.getWallet(), "", ""); + serverApiInfura.requestData(ServerApiInfura.INFURA_ETH_GET_BALANCE, 67, coinData.getWallet(), "", ""); + serverApiInfura.requestData(ServerApiInfura.INFURA_ETH_GET_TRANSACTION_COUNT, 67, coinData.getWallet(), "", ""); + serverApiInfura.requestData(ServerApiInfura.INFURA_ETH_GET_PENDING_COUNT, 67, coinData.getWallet(), "", ""); } else { ctx.setError("Terminated by user"); } @@ -711,16 +711,16 @@ public class TokenEngine extends CoinEngine { } } }; - serverApiInfura.setInfuraResponse(infuraBodyListener); + serverApiInfura.setResponseListener(responseListener); - serverApiInfura.infura(ServerApiInfura.INFURA_ETH_CALL, 67, coinData.getWallet(), getContractAddress(ctx.getCard()), ""); + serverApiInfura.requestData(ServerApiInfura.INFURA_ETH_CALL, 67, coinData.getWallet(), getContractAddress(ctx.getCard()), ""); } @Override public void requestFee(BlockchainRequestsCallbacks blockchainRequestsCallbacks, String targetAddress, Amount amount) { ServerApiInfura serverApiInfura = new ServerApiInfura(); - // request infura eth gasPrice listener - ServerApiInfura.InfuraBodyListener infuraBodyListener = new ServerApiInfura.InfuraBodyListener() { + // request requestData eth gasPrice listener + ServerApiInfura.ResponseListener responseListener = new ServerApiInfura.ResponseListener() { @Override public void onSuccess(String method, InfuraResponse infuraResponse) { String gasPrice = infuraResponse.getResult(); @@ -762,9 +762,9 @@ public class TokenEngine extends CoinEngine { blockchainRequestsCallbacks.onComplete(false); } }; - serverApiInfura.setInfuraResponse(infuraBodyListener); + serverApiInfura.setResponseListener(responseListener); - serverApiInfura.infura(ServerApiInfura.INFURA_ETH_GAS_PRICE, 67, coinData.getWallet(), "", ""); + serverApiInfura.requestData(ServerApiInfura.INFURA_ETH_GAS_PRICE, 67, coinData.getWallet(), "", ""); } @Override @@ -773,8 +773,8 @@ public class TokenEngine extends CoinEngine { String txStr = String.format("0x%s", BTCUtils.toHex(txForSend)); ServerApiInfura serverApiInfura = new ServerApiInfura(); - // request infura eth gasPrice listener - ServerApiInfura.InfuraBodyListener infuraBodyListener = new ServerApiInfura.InfuraBodyListener() { + // request requestData eth gasPrice listener + ServerApiInfura.ResponseListener responseListener = new ServerApiInfura.ResponseListener() { @Override public void onSuccess(String method, InfuraResponse infuraResponse) { if (method.equals(ServerApiInfura.INFURA_ETH_SEND_RAW_TRANSACTION)) { @@ -800,9 +800,9 @@ public class TokenEngine extends CoinEngine { } }; - serverApiInfura.setInfuraResponse(infuraBodyListener); + serverApiInfura.setResponseListener(responseListener); - serverApiInfura.infura(ServerApiInfura.INFURA_ETH_SEND_RAW_TRANSACTION, 67, coinData.getWallet(), "", txStr); + serverApiInfura.requestData(ServerApiInfura.INFURA_ETH_SEND_RAW_TRANSACTION, 67, coinData.getWallet(), "", txStr); } diff --git a/app/src/main/java/com/tangem/presentation/activity/ConfirmPaymentActivity.kt b/app/src/main/java/com/tangem/presentation/activity/ConfirmTransactionActivity.kt similarity index 93% rename from app/src/main/java/com/tangem/presentation/activity/ConfirmPaymentActivity.kt rename to app/src/main/java/com/tangem/presentation/activity/ConfirmTransactionActivity.kt index 03d704f3ef..8c66aee396 100644 --- a/app/src/main/java/com/tangem/presentation/activity/ConfirmPaymentActivity.kt +++ b/app/src/main/java/com/tangem/presentation/activity/ConfirmTransactionActivity.kt @@ -23,12 +23,12 @@ import com.tangem.tangemcard.data.TangemCard import com.tangem.tangemcard.data.loadFromBundle import com.tangem.util.UtilHelper import com.tangem.wallet.R -import kotlinx.android.synthetic.main.activity_confirm_payment.* +import kotlinx.android.synthetic.main.activity_confirm_transaction.* import org.greenrobot.eventbus.EventBus import java.io.IOException import java.util.* -class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback { +class ConfirmTransactionActivity : AppCompatActivity(), NfcAdapter.ReaderCallback { private lateinit var nfcManager: NfcManager private lateinit var ctx: TangemContext @@ -41,7 +41,7 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - setContentView(R.layout.activity_confirm_payment) + setContentView(R.layout.activity_confirm_transaction) nfcManager = NfcManager(this, this) @@ -74,7 +74,9 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback { btnSend.visibility = View.INVISIBLE - rgFee.isEnabled = !(ctx.blockchain == Blockchain.Ethereum || ctx.blockchain == Blockchain.EthereumTestNet || ctx.blockchain == Blockchain.Token || ctx.blockchain == Blockchain.BitcoinCash || ctx.blockchain == Blockchain.Litecoin) + 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) + } // set listeners rgFee.setOnCheckedChangeListener { _, checkedId -> doSetFee(checkedId) } @@ -175,7 +177,7 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback { } override fun allowAdvance(): Boolean { - return UtilHelper.isOnline(this@ConfirmPaymentActivity) + return UtilHelper.isOnline(this@ConfirmTransactionActivity) } }, etWallet.text.toString(), @@ -199,7 +201,7 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback { override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data) - if (requestCode == Constant.REQUEST_CODE_SIGN_PAYMENT) { + if (requestCode == Constant.REQUEST_CODE_SIGN_TRANSACTION) { if (data != null && data.extras != null) { if (data.extras!!.containsKey("UID") && data.extras!!.containsKey("Card")) { val updatedCard = TangemCard(data.getStringExtra("UID")) @@ -222,7 +224,7 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback { finish() } else if (requestCode == Constant.REQUEST_CODE_REQUEST_PIN2_) { if (resultCode == Activity.RESULT_OK) { - val intent = Intent(baseContext, SignPaymentActivity::class.java) + val intent = Intent(baseContext, SignTransactionActivity::class.java) ctx.saveToIntent(intent) intent.putExtra(Constant.EXTRA_TARGET_ADDRESS, etWallet!!.text.toString()) intent.putExtra(Constant.EXTRA_AMOUNT, etAmount.text.toString()) @@ -230,9 +232,9 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback { intent.putExtra(Constant.EXTRA_FEE, etFee.text.toString()) intent.putExtra(Constant.EXTRA_FEE_CURRENCY, tvCurrency2.text.toString()) intent.putExtra(Constant.EXTRA_FEE_INCLUDED, isIncludeFee) - startActivityForResult(intent, Constant.REQUEST_CODE_SIGN_PAYMENT) + startActivityForResult(intent, Constant.REQUEST_CODE_SIGN_TRANSACTION) } else - Toast.makeText(baseContext, R.string.pin_2_is_required_to_sign_the_payment, Toast.LENGTH_LONG).show() + Toast.makeText(baseContext, R.string.pin_2_is_required_to_sign_the_transaction, Toast.LENGTH_LONG).show() } } diff --git a/app/src/main/java/com/tangem/presentation/activity/PreparePaymentActivity.kt b/app/src/main/java/com/tangem/presentation/activity/PrepareTransactionActivity.kt similarity index 92% rename from app/src/main/java/com/tangem/presentation/activity/PreparePaymentActivity.kt rename to app/src/main/java/com/tangem/presentation/activity/PrepareTransactionActivity.kt index 23808e6232..aa73d48659 100644 --- a/app/src/main/java/com/tangem/presentation/activity/PreparePaymentActivity.kt +++ b/app/src/main/java/com/tangem/presentation/activity/PrepareTransactionActivity.kt @@ -20,16 +20,16 @@ import com.tangem.domain.wallet.CoinEngineFactory import com.tangem.domain.wallet.TangemContext import com.tangem.tangemcard.android.reader.NfcManager import com.tangem.wallet.R -import kotlinx.android.synthetic.main.activity_prepare_payment.* +import kotlinx.android.synthetic.main.activity_prepare_transaction.* import java.io.IOException import javax.inject.Inject -class PreparePaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback { +class PrepareTransactionActivity : AppCompatActivity(), NfcAdapter.ReaderCallback { companion object { - val TAG: String = PreparePaymentActivity::class.java.simpleName + val TAG: String = PrepareTransactionActivity::class.java.simpleName fun callingIntent(context: Context, ctx: TangemContext): Intent { - val intent = Intent(context, PreparePaymentActivity::class.java) + val intent = Intent(context, PrepareTransactionActivity::class.java) ctx.saveToIntent(intent) return intent } @@ -45,7 +45,7 @@ class PreparePaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback { @SuppressLint("SetTextI18n") override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - setContentView(R.layout.activity_prepare_payment) + setContentView(R.layout.activity_prepare_transaction) App.getNavigatorComponent().inject(this) @@ -118,13 +118,13 @@ class PreparePaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback { return@setOnClickListener } - val intent = Intent(baseContext, ConfirmPaymentActivity::class.java) + val intent = Intent(baseContext, ConfirmTransactionActivity::class.java) ctx.saveToIntent(intent) intent.putExtra(Constant.EXTRA_TARGET_ADDRESS, etWallet!!.text.toString()) intent.putExtra(Constant.EXTRA_FEE_INCLUDED, (rgIncFee!!.checkedRadioButtonId == R.id.rbFeeIn)) intent.putExtra(Constant.EXTRA_AMOUNT, strAmount) intent.putExtra(Constant.EXTRA_AMOUNT_CURRENCY, tvCurrency.text.toString()) - startActivityForResult(intent, Constant.REQUEST_CODE_SEND_PAYMENT__) + startActivityForResult(intent, Constant.REQUEST_CODE_SEND_TRANSACTION__) } ivCamera.setOnClickListener { navigator.showQrScanActivity(this, Constant.REQUEST_CODE_SCAN_QR) } @@ -169,7 +169,7 @@ class PreparePaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback { } } etWallet!!.setText(code) - } else if (requestCode == Constant.REQUEST_CODE_SEND_PAYMENT__) { + } else if (requestCode == Constant.REQUEST_CODE_SEND_TRANSACTION__) { setResult(resultCode, data) finish() } diff --git a/app/src/main/java/com/tangem/presentation/activity/SendTransactionActivity.kt b/app/src/main/java/com/tangem/presentation/activity/SendTransactionActivity.kt index d3465e1d28..f2de42ee6b 100644 --- a/app/src/main/java/com/tangem/presentation/activity/SendTransactionActivity.kt +++ b/app/src/main/java/com/tangem/presentation/activity/SendTransactionActivity.kt @@ -43,7 +43,7 @@ class SendTransactionActivity : AppCompatActivity(), NfcAdapter.ReaderCallback { if (success) finishWithSuccess() else - finishWithError(this@SendTransactionActivity.getString(R.string.try_again_failed_to_send_transaction)) + finishWithError(ctx.error) } override fun onProgress() { diff --git a/app/src/main/java/com/tangem/presentation/activity/SignPaymentActivity.kt b/app/src/main/java/com/tangem/presentation/activity/SignTransactionActivity.kt similarity index 90% rename from app/src/main/java/com/tangem/presentation/activity/SignPaymentActivity.kt rename to app/src/main/java/com/tangem/presentation/activity/SignTransactionActivity.kt index 3258c8e3f4..9591aa7857 100644 --- a/app/src/main/java/com/tangem/presentation/activity/SignPaymentActivity.kt +++ b/app/src/main/java/com/tangem/presentation/activity/SignTransactionActivity.kt @@ -28,18 +28,18 @@ import com.tangem.tangemcard.tasks.SignTask import com.tangem.tangemcard.util.Util import com.tangem.util.LOG import com.tangem.wallet.R -import kotlinx.android.synthetic.main.activity_sign_payment.* +import kotlinx.android.synthetic.main.activity_sign_transaction.* -class SignPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, CardProtocol.Notifications { +class SignTransactionActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, CardProtocol.Notifications { companion object { - val TAG: String = SignPaymentActivity::class.java.simpleName + val TAG: String = SignTransactionActivity::class.java.simpleName } private lateinit var nfcManager: NfcManager private lateinit var ctx: TangemContext - private var signPaymentTask: SignTask? = null + private var signTransactionTask: SignTask? = null private lateinit var amount: CoinEngine.Amount private lateinit var fee: CoinEngine.Amount @@ -51,7 +51,7 @@ class SignPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, Card override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - setContentView(R.layout.activity_sign_payment) + setContentView(R.layout.activity_sign_transaction) nfcManager = NfcManager(this, this) @@ -76,21 +76,21 @@ class SignPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, Card public override fun onPause() { nfcManager.onPause() - if (signPaymentTask != null) - signPaymentTask!!.cancel(true) + if (signTransactionTask != null) + signTransactionTask!!.cancel(true) super.onPause() } public override fun onStop() { // dismiss enable NFC dialog nfcManager.onStop() - if (signPaymentTask != null) - signPaymentTask!!.cancel(true) + if (signTransactionTask != null) + signTransactionTask!!.cancel(true) super.onStop() } override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { - if (requestCode == Constant.REQUEST_CODE_SEND_PAYMENT_) { + if (requestCode == Constant.REQUEST_CODE_SEND_TRANSACTION_) { setResult(resultCode, data) finish() return @@ -127,18 +127,18 @@ class SignPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, Card val coinEngine = CoinEngineFactory.create(ctx) ?: throw CardProtocol.TangemException("Can't create CoinEngine!") - coinEngine.setOnNeedSendPayment { tx -> + coinEngine.setOnNeedSendTransaction { tx -> if (tx != null) { val intent = Intent(this, SendTransactionActivity::class.java) ctx.saveToIntent(intent) intent.putExtra(Constant.EXTRA_TX, tx) - startActivityForResult(intent, Constant.REQUEST_CODE_SEND_PAYMENT_) + startActivityForResult(intent, Constant.REQUEST_CODE_SEND_TRANSACTION_) } } - val paymentToSign = coinEngine.constructPayment(amount, fee, isIncludeFee, outAddressStr) + val transactionToSign = coinEngine.constructTransaction(amount, fee, isIncludeFee, outAddressStr) - signPaymentTask = SignTask(ctx.card, NfcReader(nfcManager, isoDep), App.localStorage, App.pinStorage, this, paymentToSign) - signPaymentTask!!.start() + signTransactionTask = SignTask(ctx.card, NfcReader(nfcManager, isoDep), App.localStorage, App.pinStorage, this, transactionToSign) + signTransactionTask!!.start() } else nfcManager.ignoreTag(isoDep.tag) @@ -170,7 +170,7 @@ class SignPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, Card } override fun onReadFinish(cardProtocol: CardProtocol?) { - signPaymentTask = null + signTransactionTask = null if (cardProtocol != null) { if (cardProtocol.error == null) { progressBar!!.post { @@ -240,7 +240,7 @@ class SignPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, Card } override fun onReadCancel() { - signPaymentTask = null + signTransactionTask = null progressBar!!.postDelayed({ try { diff --git a/app/src/main/java/com/tangem/presentation/dialog/WaitSecurityDelayDialogNew.kt b/app/src/main/java/com/tangem/presentation/dialog/WaitSecurityDelayDialogNew.kt index 7a29f8f39b..b9429449fb 100644 --- a/app/src/main/java/com/tangem/presentation/dialog/WaitSecurityDelayDialogNew.kt +++ b/app/src/main/java/com/tangem/presentation/dialog/WaitSecurityDelayDialogNew.kt @@ -6,11 +6,9 @@ import android.app.Dialog import android.os.Bundle import android.support.v7.app.AppCompatDialogFragment import android.widget.ProgressBar -import com.tangem.presentation.activity.SignPaymentActivity import com.tangem.presentation.event.ReadAfterRequest import com.tangem.presentation.event.ReadBeforeRequest import com.tangem.presentation.event.ReadWait -import com.tangem.presentation.event.TransactionFinishWithSuccess import com.tangem.util.LOG import com.tangem.wallet.R import org.greenrobot.eventbus.EventBus diff --git a/app/src/main/java/com/tangem/presentation/fragment/LoadedWallet.kt b/app/src/main/java/com/tangem/presentation/fragment/LoadedWallet.kt index b8fd021fe8..a11fcf6d77 100644 --- a/app/src/main/java/com/tangem/presentation/fragment/LoadedWallet.kt +++ b/app/src/main/java/com/tangem/presentation/fragment/LoadedWallet.kt @@ -124,7 +124,7 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific btnExplore.setOnClickListener { val engine = CoinEngineFactory.create(ctx) - startActivity(Intent(Intent.ACTION_VIEW, engine?.shareWalletUriExplorer)) + startActivity(Intent(Intent.ACTION_VIEW, engine?.walletExplorerUri)) } btnCopy.setOnClickListener { doShareWallet(false) } @@ -157,13 +157,13 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific getString(R.string.via_cryptonit) -> { val intent = Intent(activity, PrepareCryptonitWithdrawalActivity::class.java) ctx.saveToIntent(intent) - startActivityForResult(intent, Constant.REQUEST_CODE_RECEIVE_PAYMENT) + startActivityForResult(intent, Constant.REQUEST_CODE_RECEIVE_TRANSACTION) } getString(R.string.via_kraken) -> { val intent = Intent(activity, PrepareKrakenWithdrawalActivity::class.java) ctx.saveToIntent(intent) - startActivityForResult(intent, Constant.REQUEST_CODE_RECEIVE_PAYMENT) + startActivityForResult(intent, Constant.REQUEST_CODE_RECEIVE_TRANSACTION) } else -> { } @@ -183,7 +183,7 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific else if (ctx.card!!.remainingSignatures == 0) UtilHelper.showSingleToast(context, getString(R.string.card_has_no_remaining_signature)) else - (activity as LoadedWalletActivity).navigator.showPreparePayment(context as Activity, ctx) + (activity as LoadedWalletActivity).navigator.showPrepareTransaction(context as Activity, ctx) else Toast.makeText(activity, getString(R.string.no_connection), Toast.LENGTH_SHORT).show() } @@ -259,8 +259,8 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific serverApiTangem.setArtworkListener(artworkListener) // request rate info listener - serverApiCommon.setRateInfoData { - if (activity == null || !UtilHelper.isOnline(activity!!)) return@setRateInfoData + serverApiCommon.setRateInfoListener { + if (activity == null || !UtilHelper.isOnline(activity!!)) return@setRateInfoListener val rate = it.priceUsd.toFloat() ctx.coinData!!.rate = rate ctx.coinData!!.rateAlter = rate @@ -417,7 +417,7 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific updateViews() } - Constant.REQUEST_CODE_SEND_PAYMENT, Constant.REQUEST_CODE_RECEIVE_PAYMENT -> { + Constant.REQUEST_CODE_SEND_TRANSACTION, Constant.REQUEST_CODE_RECEIVE_TRANSACTION -> { if (resultCode == Activity.RESULT_OK) { ctx.coinData?.clearInfo() srl?.postDelayed({ this.refresh() }, 5000) @@ -712,7 +712,7 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific throw Exception("Can''t get rate for blockchain " + ctx.blockchainName) } } - serverApiCommon.rateInfoData(cryptoId) + serverApiCommon.requestRateInfo(cryptoId) } else { ctx.error = getString(R.string.no_connection) updateViews() diff --git a/app/src/main/res/layout/activity_confirm_payment.xml b/app/src/main/res/layout/activity_confirm_transaction.xml similarity index 95% rename from app/src/main/res/layout/activity_confirm_payment.xml rename to app/src/main/res/layout/activity_confirm_transaction.xml index b5304e28e4..0004113e61 100644 --- a/app/src/main/res/layout/activity_confirm_payment.xml +++ b/app/src/main/res/layout/activity_confirm_transaction.xml @@ -1,338 +1,338 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -