Updated on 2026-08-14

This commit is contained in:
Tangem 2019-06-18 18:53:38 +03:00
parent bd8d84a85a
commit 6259944ff1
7 changed files with 161 additions and 85 deletions

View file

@ -1,13 +1,17 @@
package com.tangem.domain.wallet.xlm;
package com.tangem.wallet.xlm;
import android.os.Bundle;
import android.util.Log;
import com.tangem.domain.wallet.CoinData;
import com.tangem.domain.wallet.CoinEngine;
import com.tangem.wallet.CoinData;
import com.tangem.wallet.CoinEngine;
import org.bitcoinj.core.Coin;
import org.stellar.sdk.KeyPair;
import org.stellar.sdk.responses.AccountResponse;
import org.stellar.sdk.responses.LedgerResponse;
import java.math.BigDecimal;
/*
* Created by dvol on 7.01.2019.
@ -16,8 +20,7 @@ import org.stellar.sdk.responses.AccountResponse;
public class XlmData extends CoinData {
public static class AccountResponseEx extends AccountResponse
{
public static class AccountResponseEx extends AccountResponse {
AccountResponseEx(String accountId, Long sequenceNumber) {
super(KeyPair.fromAccountId(accountId), sequenceNumber);
}
@ -26,7 +29,8 @@ public class XlmData extends CoinData {
private CoinEngine.Amount balance = null;
private Long sequenceNumber = 0L;
private CoinEngine.Amount baseReserve = new CoinEngine.Amount("0.5", "XLM");
private CoinEngine.Amount baseFee = new CoinEngine.Amount("0.00001", "XLM");
@Override
public void clearInfo() {
@ -34,9 +38,20 @@ public class XlmData extends CoinData {
balance = null;
}
CoinEngine.Amount getBalanceXLM() {
return balance;
CoinEngine.Amount getBalance() {
if (balance != null) {
return new CoinEngine.Amount(balance.subtract(getReserve()), "XLM");
} else {
return null;
}
}
CoinEngine.Amount getReserve() {
return new CoinEngine.Amount(baseReserve.multiply(BigDecimal.valueOf(2)), "XLM");
}
CoinEngine.Amount getBaseFee() {
return baseFee;
}
AccountResponse getAccountResponse() {
@ -44,7 +59,7 @@ public class XlmData extends CoinData {
}
void setAccountResponse(AccountResponse accountResponse) {
if( accountResponse.getBalances().length>0 ) {
if (accountResponse.getBalances().length > 0) {
AccountResponse.Balance balanceResponse = accountResponse.getBalances()[0];
balance = new CoinEngine.Amount(balanceResponse.getBalance(), "XLM");
}
@ -52,6 +67,12 @@ public class XlmData extends CoinData {
setBalanceReceived(true);
}
void setLedgerResponse(LedgerResponse ledgerResponse) {
XlmEngine xlmEngine = new XlmEngine();
baseReserve = xlmEngine.convertToAmount(new CoinEngine.InternalAmount(ledgerResponse.getBaseReserveInStroops(), "stroops"));
baseFee = xlmEngine.convertToAmount(new CoinEngine.InternalAmount(ledgerResponse.getBaseFeeInStroops(), "stroops"));
}
public void incSequenceNumber() {
sequenceNumber++;
}
@ -61,8 +82,7 @@ public class XlmData extends CoinData {
super.loadFromBundle(B);
if (B.containsKey("BalanceCurrency") && B.containsKey("BalanceDecimal")) {
String currency = B.getString("BalanceCurrency");
balance = new CoinEngine.Amount(B.getString("BalanceDecimal"), currency);
balance = new CoinEngine.Amount(B.getString("BalanceDecimal"), B.getString("BalanceCurrency"));
} else {
balance = null;
}
@ -72,6 +92,18 @@ public class XlmData extends CoinData {
} else {
sequenceNumber = 0L;
}
if (B.containsKey("BaseReserveCurrency") && B.containsKey("BaseReserveDecimal")) {
baseReserve = new CoinEngine.Amount(B.getString("BaseReserveDecimal"), B.getString("BaseReserveCurrency"));
} else {
baseReserve = new CoinEngine.Amount("0.5", "XLM");
}
if (B.containsKey("BaseFeeCurrency") && B.containsKey("BaseFeeDecimal")) {
baseFee = new CoinEngine.Amount(B.getString("BaseFeeDecimal"), B.getString("BaseFeeCurrency"));
} else {
baseFee = new CoinEngine.Amount("0.00001", "XLM");
}
}
@Override
@ -87,10 +119,19 @@ public class XlmData extends CoinData {
B.putLong("sequenceNumber", sequenceNumber);
}
if (baseReserve != null) {
B.putString("BaseReserveCurrency", baseReserve.getCurrency());
B.putString("BaseReserveDecimal", baseReserve.toValueString());
}
if (baseFee != null) {
B.putString("BaseFeeCurrency", baseFee.getCurrency());
B.putString("BaseFeeDecimal", baseFee.toValueString());
}
} catch (Exception e) {
Log.e("Can't save to bundle ", e.getMessage());
}
}
}