Updated on 2026-08-14

This commit is contained in:
Tangem 2019-07-26 13:06:20 +00:00
commit 004e409ff6
3 changed files with 36 additions and 5 deletions

View file

@ -36,8 +36,8 @@ android {
flavorDimensions ""
productFlavors {
tangemAccess {
versionCode 112
versionName "0.907.1." + generateVersionName()
versionCode 113
versionName "0.907.2." + generateVersionName()
applicationId "com.tangem.wallet"
signingConfig signingConfigs.debug
}

View file

@ -138,7 +138,7 @@ public class ServerApiStellar {
});
}
private void doStellarRequest(TangemContext ctx, StellarRequest.Base stellarRequest) throws IOException {
public void doStellarRequest(TangemContext ctx, StellarRequest.Base stellarRequest) throws IOException {
stellarRequest.setError(null);
try {
Server server;

View file

@ -18,7 +18,9 @@ import com.tangem.wallet.R;
import com.tangem.wallet.TangemContext;
import org.stellar.sdk.AssetTypeNative;
import org.stellar.sdk.CreateAccountOperation;
import org.stellar.sdk.KeyPair;
import org.stellar.sdk.Operation;
import org.stellar.sdk.PaymentOperation;
import org.stellar.sdk.Transaction;
import org.stellar.sdk.TransactionEx;
@ -361,7 +363,14 @@ public class XlmEngine extends CoinEngine {
amountValue = new Amount(amountValue.subtract(feeValue), amountValue.getCurrency());
}
TransactionEx transaction = TransactionEx.buildEx(60, coinData.getAccountResponse(), new PaymentOperation.Builder(KeyPair.fromAccountId(targetAddress), new AssetTypeNative(), amountValue.toValueString()).build());
Operation operation;
if (isAccountCreated(targetAddress))
operation = new PaymentOperation.Builder(KeyPair.fromAccountId(targetAddress), new AssetTypeNative(), amountValue.toValueString()).build();
else
operation = new CreateAccountOperation.Builder(KeyPair.fromAccountId(targetAddress), amountValue.toValueString()).build();
TransactionEx transaction = TransactionEx.buildEx(60, coinData.getAccountResponse(), operation);
if (transaction.getFee() != convertToInternalAmount(feeValue).intValueExact()) {
throw new Exception("Invalid fee!");
@ -408,6 +417,26 @@ public class XlmEngine extends CoinEngine {
};
}
// network call inside, don't use on main thread
private boolean isAccountCreated(String address) {
final ServerApiStellar serverApi = new ServerApiStellar();
StellarRequest.Balance request = new StellarRequest.Balance(address);
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 requestBalanceAndUnspentTransactions(BlockchainRequestsCallbacks blockchainRequestsCallbacks) {
final ServerApiStellar serverApi = new ServerApiStellar();
@ -539,6 +568,8 @@ public class XlmEngine extends CoinEngine {
return false;
}
public int pendingTransactionTimeoutInSeconds() { return 10; }
public int pendingTransactionTimeoutInSeconds() {
return 10;
}
}