Updated on 2026-08-14
This commit is contained in:
parent
d6062e2184
commit
cc12aaf593
4 changed files with 55 additions and 23 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue