diff --git a/core/src/main/java/bisq/core/api/CoreTradesService.java b/core/src/main/java/bisq/core/api/CoreTradesService.java index c010e845b3e..7c472074549 100644 --- a/core/src/main/java/bisq/core/api/CoreTradesService.java +++ b/core/src/main/java/bisq/core/api/CoreTradesService.java @@ -124,6 +124,12 @@ void takeBsqSwapOffer(Offer offer, bsqSwapTakeOfferModel.initWithData(offer); bsqSwapTakeOfferModel.applyAmount(offer.getAmount()); + // Block attempt to take swap offer if there are insufficient funds for the trade. + var missingCoin = bsqSwapTakeOfferModel.getMissingFundsAsCoin(); + if (missingCoin.value > 0) + throw new NotAvailableException( + format("wallet has insufficient funds to take offer with id '%s'", offer.getId())); + log.info("Initiating take {} offer, {}", offer.isBuyOffer() ? "buy" : "sell", bsqSwapTakeOfferModel); @@ -155,6 +161,7 @@ void takeOffer(Offer offer, offer.isBuyOffer() ? "buy" : "sell", takeOfferModel); + // Block attempt to take swap offer if there are insufficient funds for the trade. if (!takeOfferModel.isBtcWalletFunded()) throw new NotAvailableException( format("wallet has insufficient btc to take offer with id '%s'", offer.getId())); diff --git a/core/src/main/java/bisq/core/offer/bsq_swap/BsqSwapOfferModel.java b/core/src/main/java/bisq/core/offer/bsq_swap/BsqSwapOfferModel.java index 0d8776392f8..afd81c4d872 100644 --- a/core/src/main/java/bisq/core/offer/bsq_swap/BsqSwapOfferModel.java +++ b/core/src/main/java/bisq/core/offer/bsq_swap/BsqSwapOfferModel.java @@ -54,6 +54,8 @@ import javax.annotation.Nullable; +import static org.bitcoinj.core.Coin.ZERO; + @Slf4j public class BsqSwapOfferModel { public final static String BSQ = "BSQ"; @@ -90,7 +92,7 @@ public class BsqSwapOfferModel { @Getter private final ObjectProperty payoutAmountAsCoin = new SimpleObjectProperty<>(); @Getter - private final ObjectProperty missingFunds = new SimpleObjectProperty<>(Coin.ZERO); + private final ObjectProperty missingFunds = new SimpleObjectProperty<>(ZERO); @Nullable private Coin txFee; @Getter @@ -380,6 +382,10 @@ public long getMaxTradeLimit() { return PaymentMethod.BSQ_SWAP.getMaxTradeLimitAsCoin(BSQ).getValue(); } + public Coin getMissingFundsAsCoin() { + // This extra getter is needed for API CoreTradesService, which avoids importing JFX dependencies. + return missingFunds.get().isPositive() ? missingFunds.get() : ZERO; + } /////////////////////////////////////////////////////////////////////////////////////////// // Utils @@ -398,6 +404,6 @@ private void applyTxFeePerVbyte() { private void resetTxFeeAndMissingFunds() { txFee = null; - missingFunds.set(Coin.ZERO); + missingFunds.set(ZERO); } }