From 438e8d41cb9c1970f013e8239e45ca4cf68a1611 Mon Sep 17 00:00:00 2001 From: woodser Date: Sun, 9 Jun 2024 18:23:17 -0400 Subject: [PATCH] fixes to editing offers #1011 --- .../desktop/main/offer/MutableOfferView.java | 10 +++++++++- .../desktop/main/portfolio/PortfolioView.java | 3 +++ .../openoffer/OpenOffersDataModel.java | 8 ++++---- .../portfolio/openoffer/OpenOffersView.java | 17 ++++++++++------- 4 files changed, 26 insertions(+), 12 deletions(-) diff --git a/desktop/src/main/java/haveno/desktop/main/offer/MutableOfferView.java b/desktop/src/main/java/haveno/desktop/main/offer/MutableOfferView.java index afa84d58..53df033e 100644 --- a/desktop/src/main/java/haveno/desktop/main/offer/MutableOfferView.java +++ b/desktop/src/main/java/haveno/desktop/main/offer/MutableOfferView.java @@ -703,7 +703,15 @@ public abstract class MutableOfferView> exten marketBasedPriceTextField.clear(); volumeTextField.clear(); triggerPriceInputTextField.clear(); - initWithData(model.dataModel.direction, model.getTradeCurrency(), offerActionHandler); + if (!CurrencyUtil.isTraditionalCurrency(newValue)) { + if (model.isShownAsBuyOffer()) { + placeOfferButton.updateText(Res.get("createOffer.placeOfferButtonCrypto", Res.get("shared.buy"), + model.getTradeCurrency().getCode())); + } else { + placeOfferButton.updateText(Res.get("createOffer.placeOfferButtonCrypto", Res.get("shared.sell"), + model.getTradeCurrency().getCode())); + } + } }; placeOfferCompletedListener = (o, oldValue, newValue) -> { diff --git a/desktop/src/main/java/haveno/desktop/main/portfolio/PortfolioView.java b/desktop/src/main/java/haveno/desktop/main/portfolio/PortfolioView.java index 9af43f06..acfaf6bd 100644 --- a/desktop/src/main/java/haveno/desktop/main/portfolio/PortfolioView.java +++ b/desktop/src/main/java/haveno/desktop/main/portfolio/PortfolioView.java @@ -191,6 +191,9 @@ public class PortfolioView extends ActivatableView { } else if (view instanceof FailedTradesView) { currentTab = failedTradesTab; } else if (view instanceof EditOfferView) { + if (data instanceof OpenOffer) { + openOffer = (OpenOffer) data; + } if (openOffer != null) { if (editOfferView == null) { editOfferView = (EditOfferView) view; diff --git a/desktop/src/main/java/haveno/desktop/main/portfolio/openoffer/OpenOffersDataModel.java b/desktop/src/main/java/haveno/desktop/main/portfolio/openoffer/OpenOffersDataModel.java index 14dccd6b..c1f255d9 100644 --- a/desktop/src/main/java/haveno/desktop/main/portfolio/openoffer/OpenOffersDataModel.java +++ b/desktop/src/main/java/haveno/desktop/main/portfolio/openoffer/OpenOffersDataModel.java @@ -18,6 +18,7 @@ package haveno.desktop.main.portfolio.openoffer; import com.google.inject.Inject; +import haveno.common.UserThread; import haveno.common.handlers.ErrorMessageHandler; import haveno.common.handlers.ResultHandler; import haveno.core.offer.Offer; @@ -46,9 +47,8 @@ class OpenOffersDataModel extends ActivatableDataModel { public OpenOffersDataModel(OpenOfferManager openOfferManager, PriceFeedService priceFeedService) { this.openOfferManager = openOfferManager; this.priceFeedService = priceFeedService; - - tradesListChangeListener = change -> applyList(); - currenciesUpdateFlagPropertyListener = (observable, oldValue, newValue) -> applyList(); + tradesListChangeListener = change -> UserThread.execute(() -> applyList()); + currenciesUpdateFlagPropertyListener = (observable, oldValue, newValue) -> UserThread.execute(() -> applyList()); } @Override @@ -85,7 +85,7 @@ class OpenOffersDataModel extends ActivatableDataModel { return openOfferManager.isMyOffer(offer) ? offer.getDirection() : offer.getMirroredDirection(); } - private void applyList() { + private synchronized void applyList() { list.clear(); list.addAll(openOfferManager.getOpenOffers().stream().map(OpenOfferListItem::new).collect(Collectors.toList())); diff --git a/desktop/src/main/java/haveno/desktop/main/portfolio/openoffer/OpenOffersView.java b/desktop/src/main/java/haveno/desktop/main/portfolio/openoffer/OpenOffersView.java index f0b1f1fc..d3f2d787 100644 --- a/desktop/src/main/java/haveno/desktop/main/portfolio/openoffer/OpenOffersView.java +++ b/desktop/src/main/java/haveno/desktop/main/portfolio/openoffer/OpenOffersView.java @@ -75,8 +75,6 @@ import javafx.scene.layout.Region; import javafx.scene.layout.VBox; import javafx.stage.Stage; import javafx.util.Callback; -import org.fxmisc.easybind.EasyBind; -import org.fxmisc.easybind.Subscription; import org.jetbrains.annotations.NotNull; @FxmlView @@ -113,7 +111,7 @@ public class OpenOffersView extends ActivatableViewAndModel widthListener; - private Map offerStateSubscriptions = new HashMap(); + private Map> offerStateChangeListeners = new HashMap>(); @Inject public OpenOffersView(OpenOffersViewModel model, Navigation navigation, OfferDetailsWindow offerDetailsWindow) { @@ -702,11 +700,16 @@ public class OpenOffersView extends ActivatableViewAndModel { - refresh(); - })); + + // refresh on state change + if (offerStateChangeListeners.containsKey(openOffer.getId())) { + openOffer.stateProperty().removeListener(offerStateChangeListeners.get(openOffer.getId())); + offerStateChangeListeners.remove(openOffer.getId()); } + ChangeListener listener = (observable, oldValue, newValue) -> { if (oldValue != newValue) refresh(); }; + offerStateChangeListeners.put(openOffer.getId(), listener); + openOffer.stateProperty().addListener(listener); + if (openOffer.getState() == OpenOffer.State.SCHEDULED) { setGraphic(new AutoTooltipLabel(Res.get("shared.pending"))); return;