Updated on 2026-08-14

This commit is contained in:
Tangem 2019-10-14 13:35:01 +00:00
commit ffa5189a37
5 changed files with 57 additions and 26 deletions

View file

@ -117,9 +117,9 @@ public class ServerApiStellar {
return Observable.just(stellarRequest1);
}
)
.retryWhen(errors -> errors
.filter(throwable -> (throwable instanceof IOException) || (throwable instanceof ErrorResponse))
.zipWith(Observable.range(1, 4), (n, i) -> i))
// .retryWhen(errors -> errors
// .filter(throwable -> (throwable instanceof IOException) || (throwable instanceof ErrorResponse))
// .zipWith(Observable.range(1, 4), (n, i) -> i))
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread());
@ -136,8 +136,8 @@ public class ServerApiStellar {
LOG.e(TAG, "requestData " + stellarRequest.getClass().getSimpleName() + " onError " + e.getMessage());
LOG.e(TAG, String.format("%d requests left in processing", requestsCount));
if (isRetry) {
stellarRequest.setError(ctx.getString(R.string.loaded_wallet_error_obtaining_blockchain_data));
if (isRetry || stellarRequest.errorResponse.getCode() == 404) {
stellarRequest.setError(e.getMessage());
//setErrorOccurred(e.getMessage());//;
listener.onFail(stellarRequest);
} else {

View file

@ -2,7 +2,6 @@ package com.tangem.wallet.bch
enum class BitcoinCashNode(val host: String, val port: Int, val proto: String) {
N_001("electrumx.hillsideinternet.com", 50002, "ssl"),
N_002("electron.coinucopia.io", 50002, "ssl"),
N_003("blackie.c3-soft.com", 50002, "ssl"),
N_004("electrum.imaginary.cash", 50002, "ssl"),
N_002("blackie.c3-soft.com", 50002, "ssl"),
N_003("electrum.imaginary.cash", 50002, "ssl"),
}

View file

@ -30,13 +30,14 @@ public class XlmData extends CoinData {
private Long sequenceNumber = 0L;
private CoinEngine.Amount baseReserve = new CoinEngine.Amount("0.5", "XLM");
private CoinEngine.Amount baseFee = new CoinEngine.Amount("0.00001", "XLM");
private boolean error404 = false;
private boolean error404, targetAccountCreated = false;
@Override
public void clearInfo() {
super.clearInfo();
balance = null;
error404 = false;
targetAccountCreated = false;
}
CoinEngine.Amount getBalance() {
@ -86,6 +87,14 @@ public class XlmData extends CoinData {
this.error404 = error404;
}
public boolean isTargetAccountCreated() {
return targetAccountCreated;
}
public void setTargetAccountCreated(boolean targetAccountCreated) {
this.targetAccountCreated = targetAccountCreated;
}
@Override
public void loadFromBundle(Bundle B) {
super.loadFromBundle(B);
@ -116,6 +125,9 @@ public class XlmData extends CoinData {
if (B.containsKey("Error404")) error404 = B.getBoolean("Error404");
else error404 = false;
if (B.containsKey("TargetAccountCreated")) targetAccountCreated = B.getBoolean("TargetAccountCreated");
else targetAccountCreated = false;
}
@Override
@ -143,6 +155,8 @@ public class XlmData extends CoinData {
if (error404) B.putBoolean("Error404", true);
if (targetAccountCreated) B.putBoolean("TargetAccountCreated", true);
} catch (Exception e) {
Log.e("Can't save to bundle ", e.getMessage());
}

View file

@ -361,7 +361,7 @@ public class XlmEngine extends CoinEngine {
}
Operation operation;
if (isAccountCreated(targetAddress))
if (coinData.isTargetAccountCreated())
operation = new PaymentOperation.Builder(KeyPair.fromAccountId(targetAddress), new AssetTypeNative(), amountValue.toValueString()).build();
else
operation = new CreateAccountOperation.Builder(KeyPair.fromAccountId(targetAddress), amountValue.toValueString()).build();
@ -414,24 +414,41 @@ public class XlmEngine extends CoinEngine {
};
}
// network call inside, don't use on main thread
private boolean isAccountCreated(String address) {
private void checkTargetAccountCreated(BlockchainRequestsCallbacks blockchainRequestsCallbacks, String targetAddress, Amount amount) {
final ServerApiStellar serverApi = new ServerApiStellar(ctx.getBlockchain());
StellarRequest.Balance request = new StellarRequest.Balance(address);
ServerApiStellar.Listener listener = new ServerApiStellar.Listener() {
@Override
public void onSuccess(StellarRequest.Base request) {
coinData.setTargetAccountCreated(true);
blockchainRequestsCallbacks.onComplete(true);
}
try {
serverApi.doStellarRequest(ctx, request);
} catch (IOException e) {
Log.e(TAG, e.getMessage());
return true; // suppose account is created if anything goes wrong TODO:check
}
if (request.errorResponse != null && request.errorResponse.getCode() == 404)
return false;
else
return true;
@Override
public void onFail(StellarRequest.Base request) {
Log.i(TAG, "onFail: " + request.getClass().getSimpleName() + " " + request.getError());
if (request.errorResponse.getCode() == 404) {
coinData.setTargetAccountCreated(false);
if (amount.compareTo(coinData.getReserve()) >= 0) { //TODO: take fee inclusion in account, now 1 XLM with fee included will fail after transaction is sent
blockchainRequestsCallbacks.onComplete(true);
} else {
ctx.setError(R.string.confirm_transaction_error_not_enough_xlm_for_create);
blockchainRequestsCallbacks.onComplete(false);
}
} else { // suppose account is created if anything goes wrong
coinData.setTargetAccountCreated(true);
blockchainRequestsCallbacks.onComplete(true);
}
}
};
serverApi.setListener(listener);
serverApi.requestData(ctx, new StellarRequest.Balance(targetAddress));
}
@Override
@ -501,9 +518,8 @@ public class XlmEngine extends CoinEngine {
@Override
public void requestFee(BlockchainRequestsCallbacks blockchainRequestsCallbacks, String targetAddress, Amount amount) throws Exception {
// TODO: get fee stats?
coinData.minFee = coinData.normalFee = coinData.maxFee = coinData.getBaseFee();
blockchainRequestsCallbacks.onComplete(true);
checkTargetAccountCreated(blockchainRequestsCallbacks, targetAddress, amount); //TODO: move?
}
@Override

View file

@ -205,10 +205,12 @@
<string name="confirm_transaction_error_incoming_transaction_unconfirmed">Please wait for confirmation of incoming transaction</string>
<string name="confirm_transaction_error_not_enough_eth_for_fee">Not enough ETH funds for fee</string>
<string name="confirm_transaction_error_not_enough_rbtc_for_fee">Not enough RBTC funds for fee</string>
<string name="confirm_transaction_error_not_enough_xlm_for_create">Target account is not created! Send 1+ XLM to create it</string>
<string name="confirm_transaction_error_pin_2_is_required">PIN2 is required to sign the payment</string>
<string name="confirm_transaction_error_service_unavailable">Service unavailable</string>
<string name="confirm_transaction_warning_risk_delaying">You have a risk of delaying transaction</string>
<!-- EmptyWallet -->
<string name="empty_wallet_not_created">Wallet hasn\'t been yet created</string>
<string name="empty_wallet_btn_create">Create Wallet</string>