fixes to editing offers #1011

This commit is contained in:
woodser 2024-06-09 18:23:17 -04:00
parent 57948b36fd
commit 438e8d41cb
4 changed files with 26 additions and 12 deletions

View file

@ -703,7 +703,15 @@ public abstract class MutableOfferView<M extends MutableOfferViewModel<?>> exten
marketBasedPriceTextField.clear(); marketBasedPriceTextField.clear();
volumeTextField.clear(); volumeTextField.clear();
triggerPriceInputTextField.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) -> { placeOfferCompletedListener = (o, oldValue, newValue) -> {

View file

@ -191,6 +191,9 @@ public class PortfolioView extends ActivatableView<TabPane, Void> {
} else if (view instanceof FailedTradesView) { } else if (view instanceof FailedTradesView) {
currentTab = failedTradesTab; currentTab = failedTradesTab;
} else if (view instanceof EditOfferView) { } else if (view instanceof EditOfferView) {
if (data instanceof OpenOffer) {
openOffer = (OpenOffer) data;
}
if (openOffer != null) { if (openOffer != null) {
if (editOfferView == null) { if (editOfferView == null) {
editOfferView = (EditOfferView) view; editOfferView = (EditOfferView) view;

View file

@ -18,6 +18,7 @@
package haveno.desktop.main.portfolio.openoffer; package haveno.desktop.main.portfolio.openoffer;
import com.google.inject.Inject; import com.google.inject.Inject;
import haveno.common.UserThread;
import haveno.common.handlers.ErrorMessageHandler; import haveno.common.handlers.ErrorMessageHandler;
import haveno.common.handlers.ResultHandler; import haveno.common.handlers.ResultHandler;
import haveno.core.offer.Offer; import haveno.core.offer.Offer;
@ -46,9 +47,8 @@ class OpenOffersDataModel extends ActivatableDataModel {
public OpenOffersDataModel(OpenOfferManager openOfferManager, PriceFeedService priceFeedService) { public OpenOffersDataModel(OpenOfferManager openOfferManager, PriceFeedService priceFeedService) {
this.openOfferManager = openOfferManager; this.openOfferManager = openOfferManager;
this.priceFeedService = priceFeedService; this.priceFeedService = priceFeedService;
tradesListChangeListener = change -> UserThread.execute(() -> applyList());
tradesListChangeListener = change -> applyList(); currenciesUpdateFlagPropertyListener = (observable, oldValue, newValue) -> UserThread.execute(() -> applyList());
currenciesUpdateFlagPropertyListener = (observable, oldValue, newValue) -> applyList();
} }
@Override @Override
@ -85,7 +85,7 @@ class OpenOffersDataModel extends ActivatableDataModel {
return openOfferManager.isMyOffer(offer) ? offer.getDirection() : offer.getMirroredDirection(); return openOfferManager.isMyOffer(offer) ? offer.getDirection() : offer.getMirroredDirection();
} }
private void applyList() { private synchronized void applyList() {
list.clear(); list.clear();
list.addAll(openOfferManager.getOpenOffers().stream().map(OpenOfferListItem::new).collect(Collectors.toList())); list.addAll(openOfferManager.getOpenOffers().stream().map(OpenOfferListItem::new).collect(Collectors.toList()));

View file

@ -75,8 +75,6 @@ import javafx.scene.layout.Region;
import javafx.scene.layout.VBox; import javafx.scene.layout.VBox;
import javafx.stage.Stage; import javafx.stage.Stage;
import javafx.util.Callback; import javafx.util.Callback;
import org.fxmisc.easybind.EasyBind;
import org.fxmisc.easybind.Subscription;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@FxmlView @FxmlView
@ -113,7 +111,7 @@ public class OpenOffersView extends ActivatableViewAndModel<VBox, OpenOffersView
private PortfolioView.OpenOfferActionHandler openOfferActionHandler; private PortfolioView.OpenOfferActionHandler openOfferActionHandler;
private ChangeListener<Number> widthListener; private ChangeListener<Number> widthListener;
private Map<String, Subscription> offerStateSubscriptions = new HashMap<String, Subscription>(); private Map<String, ChangeListener<OpenOffer.State>> offerStateChangeListeners = new HashMap<String, ChangeListener<OpenOffer.State>>();
@Inject @Inject
public OpenOffersView(OpenOffersViewModel model, Navigation navigation, OfferDetailsWindow offerDetailsWindow) { public OpenOffersView(OpenOffersViewModel model, Navigation navigation, OfferDetailsWindow offerDetailsWindow) {
@ -702,11 +700,16 @@ public class OpenOffersView extends ActivatableViewAndModel<VBox, OpenOffersView
super.updateItem(item, empty); super.updateItem(item, empty);
if (item != null && !empty) { if (item != null && !empty) {
OpenOffer openOffer = item.getOpenOffer(); OpenOffer openOffer = item.getOpenOffer();
if (!offerStateSubscriptions.containsKey(openOffer.getId())) {
offerStateSubscriptions.put(openOffer.getId(), EasyBind.subscribe(openOffer.stateProperty(), state -> { // refresh on state change
refresh(); if (offerStateChangeListeners.containsKey(openOffer.getId())) {
})); openOffer.stateProperty().removeListener(offerStateChangeListeners.get(openOffer.getId()));
offerStateChangeListeners.remove(openOffer.getId());
} }
ChangeListener<OpenOffer.State> listener = (observable, oldValue, newValue) -> { if (oldValue != newValue) refresh(); };
offerStateChangeListeners.put(openOffer.getId(), listener);
openOffer.stateProperty().addListener(listener);
if (openOffer.getState() == OpenOffer.State.SCHEDULED) { if (openOffer.getState() == OpenOffer.State.SCHEDULED) {
setGraphic(new AutoTooltipLabel(Res.get("shared.pending"))); setGraphic(new AutoTooltipLabel(Res.get("shared.pending")));
return; return;