From dca0c93f477f66da22f6eeba2532fffb844dde90 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Wed, 20 Oct 2021 12:20:53 +0200 Subject: [PATCH] Cleanups --- .../src/main/java/bisq/core/offer/OfferUtil.java | 2 +- .../src/main/java/bisq/core/offer/OpenOffer.java | 9 ++++++--- .../java/bisq/core/offer/OpenOfferManager.java | 16 ++++------------ .../offer/bisq_v1/MutableOfferDataModel.java | 2 +- .../main/offer/bisq_v1/MutableOfferView.java | 2 +- .../main/offer/bisq_v1/OfferViewUtil.java | 4 +--- .../bisq_v1/takeoffer/TakeOfferDataModel.java | 1 - .../offer/bisq_v1/takeoffer/TakeOfferView.java | 2 +- .../bisq_v1/takeoffer/TakeOfferViewModel.java | 12 ++++++------ .../desktop/main/offer/offerbook/OfferBook.java | 3 ++- 10 files changed, 23 insertions(+), 30 deletions(-) diff --git a/core/src/main/java/bisq/core/offer/OfferUtil.java b/core/src/main/java/bisq/core/offer/OfferUtil.java index 9696d76e02..5a998627c7 100644 --- a/core/src/main/java/bisq/core/offer/OfferUtil.java +++ b/core/src/main/java/bisq/core/offer/OfferUtil.java @@ -484,7 +484,7 @@ public class OfferUtil { } } else { errorMsg = "The maker fee tx is invalid as it does not has at least 2 outputs." + extraString + - "\nMakerFeeTx=" + makerFeeTx.toString(); + "\nMakerFeeTx=" + makerFeeTx; } if (errorMsg == null) { diff --git a/core/src/main/java/bisq/core/offer/OpenOffer.java b/core/src/main/java/bisq/core/offer/OpenOffer.java index 51c1ba1b44..3142755a12 100644 --- a/core/src/main/java/bisq/core/offer/OpenOffer.java +++ b/core/src/main/java/bisq/core/offer/OpenOffer.java @@ -131,9 +131,8 @@ public final class OpenOffer implements Tradable { proto.getTriggerPrice()); } - /////////////////////////////////////////////////////////////////////////////////////////// - // Getters + // Tradable /////////////////////////////////////////////////////////////////////////////////////////// @Override @@ -151,6 +150,11 @@ public final class OpenOffer implements Tradable { return offer.getShortId(); } + + /////////////////////////////////////////////////////////////////////////////////////////// + // Misc + /////////////////////////////////////////////////////////////////////////////////////////// + public void setState(State state) { this.state = state; @@ -185,7 +189,6 @@ public final class OpenOffer implements Tradable { } } - @Override public String toString() { return "OpenOffer{" + diff --git a/core/src/main/java/bisq/core/offer/OpenOfferManager.java b/core/src/main/java/bisq/core/offer/OpenOfferManager.java index 3d62d4fd1f..9109725401 100644 --- a/core/src/main/java/bisq/core/offer/OpenOfferManager.java +++ b/core/src/main/java/bisq/core/offer/OpenOfferManager.java @@ -88,19 +88,15 @@ import java.util.Set; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import lombok.Getter; - -import org.jetbrains.annotations.NotNull; +import lombok.extern.slf4j.Slf4j; import javax.annotation.Nullable; import static com.google.common.base.Preconditions.checkNotNull; +@Slf4j public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMessageListener, PersistedDataHost { - private static final Logger log = LoggerFactory.getLogger(OpenOfferManager.class); private static final long RETRY_REPUBLISH_DELAY_SEC = 10; private static final long REPUBLISH_AGAIN_AT_STARTUP_DELAY_SEC = 30; @@ -546,7 +542,7 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe } } - private void onRemoved(@NotNull OpenOffer openOffer, ResultHandler resultHandler, Offer offer) { + private void onRemoved(OpenOffer openOffer, ResultHandler resultHandler, Offer offer) { offer.setState(Offer.State.REMOVED); openOffer.setState(OpenOffer.State.CANCELED); openOffers.remove(openOffer); @@ -926,10 +922,6 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe // messages in one go or to spread it over a delay. With power users who have 100-200 offers that can have // some significant impact to user experience and the network republishOffer(openOffer, () -> processListForRepublishOffers(list)); - - /* republishOffer(openOffer, - () -> UserThread.runAfter(() -> processListForRepublishOffers(list), - 30, TimeUnit.MILLISECONDS));*/ } else { // If the offer was removed in the meantime or if its deactivated we skip and call // processListForRepublishOffers again with the list where we removed the offer already. @@ -1032,7 +1024,7 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe startPeriodicRepublishOffersTimer(); } - private void requestPersistence() { + public void requestPersistence() { persistenceManager.requestPersistence(); } diff --git a/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/MutableOfferDataModel.java b/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/MutableOfferDataModel.java index 1788a6a697..7ea37c3547 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/MutableOfferDataModel.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/MutableOfferDataModel.java @@ -353,7 +353,7 @@ public abstract class MutableOfferDataModel extends OfferDataModel implements Bs } // Get average historic prices over for the prior trade period equaling the lock time var blocksRange = Restrictions.getLockTime(paymentAccount.getPaymentMethod().isAsset()); - var startDate = new Date(System.currentTimeMillis() - blocksRange * 10 * 60000); + var startDate = new Date(System.currentTimeMillis() - blocksRange * 10L * 60000); var sortedRangeData = tradeStatisticsManager.getObservableTradeStatisticsSet().stream() .filter(e -> e.getCurrency().equals(getTradeCurrency().getCode())) .filter(e -> e.getDate().compareTo(startDate) >= 0) diff --git a/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/MutableOfferView.java b/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/MutableOfferView.java index 2d57fe70ce..a06f756ae4 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/MutableOfferView.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/MutableOfferView.java @@ -171,7 +171,7 @@ public abstract class MutableOfferView> exten protected int gridRow = 0; private final List editOfferElements = new ArrayList<>(); - private HashMap paymentAccountWarningDisplayed = new HashMap<>(); + private final HashMap paymentAccountWarningDisplayed = new HashMap<>(); private boolean clearXchangeWarningDisplayed, fasterPaymentsWarningDisplayed, isActivated; private InfoInputTextField marketBasedPriceInfoInputTextField, volumeInfoInputTextField, buyerSecurityDepositInfoInputTextField, triggerPriceInfoInputTextField; diff --git a/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/OfferViewUtil.java b/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/OfferViewUtil.java index 9f08eb5fba..f5aff0937d 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/OfferViewUtil.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/OfferViewUtil.java @@ -21,9 +21,7 @@ import javafx.scene.control.Label; import javafx.geometry.Insets; -/** - * Reusable methods for CreateOfferView, TakeOfferView or other related views - */ +// Shared utils for Views public class OfferViewUtil { public static Label createPopOverLabel(String text) { final Label label = new Label(text); diff --git a/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/takeoffer/TakeOfferDataModel.java b/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/takeoffer/TakeOfferDataModel.java index f357105036..0766669e14 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/takeoffer/TakeOfferDataModel.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/takeoffer/TakeOfferDataModel.java @@ -590,7 +590,6 @@ class TakeOfferDataModel extends OfferDataModel { } boolean wouldCreateDustForMaker() { - //noinspection SimplifiableIfStatement boolean result; if (amount.get() != null && offer != null) { Coin customAmount = offer.getAmount().subtract(amount.get()); diff --git a/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/takeoffer/TakeOfferView.java b/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/takeoffer/TakeOfferView.java index c7964806ab..c4264644a9 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/takeoffer/TakeOfferView.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/takeoffer/TakeOfferView.java @@ -163,7 +163,7 @@ public class TakeOfferView extends ActivatableViewAndModel paymentAccountWarningDisplayed = new HashMap<>(); + private final HashMap paymentAccountWarningDisplayed = new HashMap<>(); private boolean offerDetailsWindowDisplayed, clearXchangeWarningDisplayed, fasterPaymentsWarningDisplayed, takeOfferFromUnsignedAccountWarningDisplayed, cashByMailWarningDisplayed; private SimpleBooleanProperty errorPopupDisplayed; diff --git a/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/takeoffer/TakeOfferViewModel.java b/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/takeoffer/TakeOfferViewModel.java index 6604b32c63..d3ac7f78af 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/takeoffer/TakeOfferViewModel.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/bisq_v1/takeoffer/TakeOfferViewModel.java @@ -264,8 +264,8 @@ class TakeOfferViewModel extends ActivatableWithDataModel im return true; } else { new Popup().warning(Res.get("shared.notEnoughFunds", - btcFormatter.formatCoinWithCode(dataModel.getTotalToPayAsCoin().get()), - btcFormatter.formatCoinWithCode(dataModel.getTotalAvailableBalance()))) + btcFormatter.formatCoinWithCode(dataModel.getTotalToPayAsCoin().get()), + btcFormatter.formatCoinWithCode(dataModel.getTotalAvailableBalance()))) .actionButtonTextWithGoTo("navigation.funds.depositFunds") .onAction(() -> navigation.navigateTo(MainView.class, FundsView.class, DepositView.class)) .show(); @@ -350,14 +350,14 @@ class TakeOfferViewModel extends ActivatableWithDataModel im } else if (btcValidator.getMaxTradeLimit() != null && btcValidator.getMaxTradeLimit().value == OfferRestrictions.TOLERATED_SMALL_TRADE_AMOUNT.value) { if (dataModel.getDirection() == OfferPayload.Direction.BUY) { new Popup().information(Res.get("popup.warning.tradeLimitDueAccountAgeRestriction.seller", - btcFormatter.formatCoinWithCode(OfferRestrictions.TOLERATED_SMALL_TRADE_AMOUNT), - Res.get("offerbook.warning.newVersionAnnouncement"))) + btcFormatter.formatCoinWithCode(OfferRestrictions.TOLERATED_SMALL_TRADE_AMOUNT), + Res.get("offerbook.warning.newVersionAnnouncement"))) .width(900) .show(); } else { new Popup().information(Res.get("popup.warning.tradeLimitDueAccountAgeRestriction.buyer", - btcFormatter.formatCoinWithCode(OfferRestrictions.TOLERATED_SMALL_TRADE_AMOUNT), - Res.get("offerbook.warning.newVersionAnnouncement"))) + btcFormatter.formatCoinWithCode(OfferRestrictions.TOLERATED_SMALL_TRADE_AMOUNT), + Res.get("offerbook.warning.newVersionAnnouncement"))) .width(900) .show(); } diff --git a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBook.java b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBook.java index a7f7b5bf5c..b9cdbe595b 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBook.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBook.java @@ -57,6 +57,7 @@ public class OfferBook { private final Map sellOfferCountMap = new HashMap<>(); private final FilterManager filterManager; + /////////////////////////////////////////////////////////////////////////////////////////// // Constructor /////////////////////////////////////////////////////////////////////////////////////////// @@ -201,7 +202,7 @@ public class OfferBook { // Investigate why.... offerBookListItems.clear(); offerBookListItems.addAll(offerBookService.getOffers().stream() - .filter(o -> isOfferAllowed(o)) + .filter(this::isOfferAllowed) .map(OfferBookListItem::new) .collect(Collectors.toList()));