take offer funded from available balance

This commit is contained in:
woodser 2022-12-21 22:53:37 +00:00
parent 2b7beff84e
commit 06c2ce432b
10 changed files with 105 additions and 78 deletions

View file

@ -664,7 +664,7 @@ public class XmrWalletService {
for (XmrBalanceListener balanceListener : balanceListeners) {
Coin balance;
if (balanceListener.getSubaddressIndex() != null && balanceListener.getSubaddressIndex() != 0) balance = getBalanceForSubaddress(balanceListener.getSubaddressIndex());
else balance = getAvailableConfirmedBalance();
else balance = getAvailableBalance();
UserThread.execute(new Runnable() { // TODO (woodser): don't execute on UserThread
@Override
public void run() {
@ -940,12 +940,16 @@ public class XmrWalletService {
return HavenoUtils.atomicUnitsToCoin(wallet.getBalance(0, subaddressIndex));
}
public Coin getAvailableConfirmedBalance() {
return wallet != null ? HavenoUtils.atomicUnitsToCoin(wallet.getUnlockedBalance(0)) : Coin.ZERO;
public Coin getAvailableBalanceForSubaddress(int subaddressIndex) {
return HavenoUtils.atomicUnitsToCoin(wallet.getUnlockedBalance(0, subaddressIndex));
}
public Coin getSavingWalletBalance() {
return wallet != null ? Coin.valueOf(wallet.getBalance(0).longValueExact()) : Coin.ZERO;
public Coin getBalance() {
return wallet != null ? HavenoUtils.atomicUnitsToCoin(wallet.getBalance(0)) : Coin.ZERO;
}
public Coin getAvailableBalance() {
return wallet != null ? HavenoUtils.atomicUnitsToCoin(wallet.getUnlockedBalance(0)) : Coin.ZERO;
}
public Stream<XmrAddressEntry> getAddressEntriesForAvailableBalanceStream() {

View file

@ -80,7 +80,7 @@ public class TakeOfferModel implements Model {
@Getter
private Coin totalAvailableBalance;
@Getter
private Coin balance;
private Coin availableBalance;
@Getter
private boolean isXmrWalletFunded;
@Getter
@ -154,10 +154,10 @@ public class TakeOfferModel implements Model {
}
private void updateBalance() {
totalAvailableBalance = xmrWalletService.getSavingWalletBalance();
if (totalToPayAsCoin != null) balance = minCoin(totalToPayAsCoin, totalAvailableBalance);
missingCoin = offerUtil.getBalanceShortage(totalToPayAsCoin, balance);
isXmrWalletFunded = offerUtil.isBalanceSufficient(totalToPayAsCoin, balance);
totalAvailableBalance = xmrWalletService.getAvailableBalance();
if (totalToPayAsCoin != null) availableBalance = minCoin(totalToPayAsCoin, totalAvailableBalance);
missingCoin = offerUtil.getBalanceShortage(totalToPayAsCoin, availableBalance);
isXmrWalletFunded = offerUtil.isBalanceSufficient(totalToPayAsCoin, availableBalance);
}
private long getMaxTradeLimit() {
@ -184,7 +184,7 @@ public class TakeOfferModel implements Model {
private void clearModel() {
this.addressEntry = null;
this.amount = null;
this.balance = null;
this.availableBalance = null;
this.isXmrWalletFunded = false;
this.missingCoin = ZERO;
this.offer = null;
@ -212,7 +212,7 @@ public class TakeOfferModel implements Model {
", totalToPayAsCoin=" + totalToPayAsCoin + "\n" +
", missingCoin=" + missingCoin + "\n" +
", totalAvailableBalance=" + totalAvailableBalance + "\n" +
", balance=" + balance + "\n" +
", availableBalance=" + availableBalance + "\n" +
", volume=" + volume + "\n" +
", fundsNeededForTrade=" + getFundsNeededForTrade() + "\n" +
", isXmrWalletFunded=" + isXmrWalletFunded + "\n" +