take offer view shows pending trade wallet balance

This commit is contained in:
woodser 2023-04-25 17:27:14 -04:00
parent 3f7489269f
commit 5545bcde38
3 changed files with 16 additions and 13 deletions

View File

@ -423,7 +423,6 @@ public class TradeManager implements PersistedDataHost, DecryptedDirectMessageLi
// remove trade if protocol didn't initialize // remove trade if protocol didn't initialize
if (getOpenTradeByUid(trade.getUid()).isPresent() && !trade.isDepositsPublished()) { if (getOpenTradeByUid(trade.getUid()).isPresent() && !trade.isDepositsPublished()) {
log.warn("Maybe removing persisted {} {} with uid={} because it did not finish initializing (state={})", trade.getClass().getSimpleName(), trade.getId(), trade.getUid(), trade.getState());
maybeRemoveTradeOnError(trade); maybeRemoveTradeOnError(trade);
} }
} catch (Exception e) { } catch (Exception e) {
@ -1205,7 +1204,7 @@ public class TradeManager implements PersistedDataHost, DecryptedDirectMessageLi
} }
private void removeTradeOnError(Trade trade) { private void removeTradeOnError(Trade trade) {
log.info("TradeManager.removeTradeOnError() " + trade.getId()); log.warn("TradeManager.removeTradeOnError() " + trade.getId());
synchronized (tradableList) { synchronized (tradableList) {
// unreserve taker key images // unreserve taker key images

View File

@ -65,15 +65,11 @@ public abstract class OfferDataModel extends ActivatableDataModel {
} }
protected void updateBalance() { protected void updateBalance() {
BigInteger tradeWalletBalance = xmrWalletService.getBalanceForSubaddress(addressEntry.getSubaddressIndex()); updateBalances();
if (useSavingsWallet) { if (useSavingsWallet) {
BigInteger walletBalance = xmrWalletService.getBalance();
totalBalance = walletBalance.add(tradeWalletBalance);
if (totalToPay.get() != null) { if (totalToPay.get() != null) {
balance.set(totalToPay.get().min(totalBalance)); balance.set(totalToPay.get().min(totalBalance));
} }
} else {
balance.set(tradeWalletBalance);
} }
missingCoin.set(offerUtil.getBalanceShortage(totalToPay.get(), balance.get())); missingCoin.set(offerUtil.getBalanceShortage(totalToPay.get(), balance.get()));
isXmrWalletFunded.set(offerUtil.isBalanceSufficient(totalToPay.get(), balance.get())); isXmrWalletFunded.set(offerUtil.isBalanceSufficient(totalToPay.get(), balance.get()));
@ -83,15 +79,11 @@ public abstract class OfferDataModel extends ActivatableDataModel {
} }
protected void updateAvailableBalance() { protected void updateAvailableBalance() {
BigInteger tradeWalletBalance = xmrWalletService.getAvailableBalanceForSubaddress(addressEntry.getSubaddressIndex()); updateBalances();
if (useSavingsWallet) { if (useSavingsWallet) {
BigInteger walletAvailableBalance = xmrWalletService.getAvailableBalance();
totalAvailableBalance = walletAvailableBalance.add(tradeWalletBalance);
if (totalToPay.get() != null) { if (totalToPay.get() != null) {
availableBalance.set(totalToPay.get().min(totalAvailableBalance)); availableBalance.set(totalToPay.get().min(totalAvailableBalance));
} }
} else {
availableBalance.set(tradeWalletBalance);
} }
missingCoin.set(offerUtil.getBalanceShortage(totalToPay.get(), availableBalance.get())); missingCoin.set(offerUtil.getBalanceShortage(totalToPay.get(), availableBalance.get()));
isXmrWalletFunded.set(offerUtil.isBalanceSufficient(totalToPay.get(), availableBalance.get())); isXmrWalletFunded.set(offerUtil.isBalanceSufficient(totalToPay.get(), availableBalance.get()));
@ -99,4 +91,16 @@ public abstract class OfferDataModel extends ActivatableDataModel {
showWalletFundedNotification.set(true); showWalletFundedNotification.set(true);
} }
} }
private void updateBalances() {
BigInteger tradeWalletBalance = xmrWalletService.getBalanceForSubaddress(addressEntry.getSubaddressIndex());
BigInteger tradeWalletAvailableBalance = xmrWalletService.getAvailableBalanceForSubaddress(addressEntry.getSubaddressIndex());
if (useSavingsWallet) {
totalBalance = xmrWalletService.getBalance();;
totalAvailableBalance = xmrWalletService.getAvailableBalance();
} else {
balance.set(tradeWalletBalance);
availableBalance.set(tradeWalletAvailableBalance);
}
}
} }

View File

@ -673,7 +673,7 @@ public class TakeOfferView extends ActivatableViewAndModel<AnchorPane, TakeOffer
} }
}); });
balanceSubscription = EasyBind.subscribe(model.dataModel.getAvailableBalance(), balanceTextField::setBalance); balanceSubscription = EasyBind.subscribe(model.dataModel.getBalance(), balanceTextField::setBalance);
} }
private void removeSubscriptions() { private void removeSubscriptions() {