From b00cbe846fd0e005bb886a72e33e6376c9ac4539 Mon Sep 17 00:00:00 2001 From: Christoph Atteneder Date: Wed, 27 Jun 2018 19:24:34 +0200 Subject: [PATCH 1/2] Rename classes to prevent confusion and add fix for payment accounts with multiple currencies when editing offers --- ...aModel.java => MutableOfferDataModel.java} | 16 ++++------ ...leOfferView.java => MutableOfferView.java} | 6 ++-- ...wModel.java => MutableOfferViewModel.java} | 30 ++++++++--------- .../createoffer/CreateOfferDataModel.java | 4 +-- .../offer/createoffer/CreateOfferView.java | 4 +-- .../createoffer/CreateOfferViewModel.java | 4 +-- .../desktop/main/portfolio/PortfolioView.java | 32 +++++++++---------- ...DataModel.java => EditOfferDataModel.java} | 29 +++++++++++------ ...tOpenOfferView.fxml => EditOfferView.fxml} | 2 +- ...tOpenOfferView.java => EditOfferView.java} | 13 ++++---- ...ViewModel.java => EditOfferViewModel.java} | 10 +++--- 11 files changed, 80 insertions(+), 70 deletions(-) rename src/main/java/bisq/desktop/main/offer/{EditableOfferDataModel.java => MutableOfferDataModel.java} (97%) rename src/main/java/bisq/desktop/main/offer/{EditableOfferView.java => MutableOfferView.java} (99%) rename src/main/java/bisq/desktop/main/offer/{EditableOfferViewModel.java => MutableOfferViewModel.java} (97%) rename src/main/java/bisq/desktop/main/portfolio/editoffer/{EditOpenOfferDataModel.java => EditOfferDataModel.java} (76%) rename src/main/java/bisq/desktop/main/portfolio/editoffer/{EditOpenOfferView.fxml => EditOfferView.fxml} (96%) rename src/main/java/bisq/desktop/main/portfolio/editoffer/{EditOpenOfferView.java => EditOfferView.java} (93%) rename src/main/java/bisq/desktop/main/portfolio/editoffer/{EditOpenOfferViewModel.java => EditOfferViewModel.java} (79%) diff --git a/src/main/java/bisq/desktop/main/offer/EditableOfferDataModel.java b/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java similarity index 97% rename from src/main/java/bisq/desktop/main/offer/EditableOfferDataModel.java rename to src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java index ca41e8c7015..4a1fd82ea4d 100644 --- a/src/main/java/bisq/desktop/main/offer/EditableOfferDataModel.java +++ b/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java @@ -95,7 +95,7 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; -public abstract class EditableOfferDataModel extends OfferDataModel implements BsqBalanceListener { +public abstract class MutableOfferDataModel extends OfferDataModel implements BsqBalanceListener { protected final OpenOfferManager openOfferManager; private final BsqWalletService bsqWalletService; private final Preferences preferences; @@ -145,11 +145,11 @@ public abstract class EditableOfferDataModel extends OfferDataModel implements B /////////////////////////////////////////////////////////////////////////////////////////// @Inject - public EditableOfferDataModel(OpenOfferManager openOfferManager, BtcWalletService btcWalletService, BsqWalletService bsqWalletService, - Preferences preferences, User user, KeyRing keyRing, P2PService p2PService, - PriceFeedService priceFeedService, FilterManager filterManager, - AccountAgeWitnessService accountAgeWitnessService, TradeWalletService tradeWalletService, - FeeService feeService, ReferralIdService referralIdService, BSFormatter formatter) { + public MutableOfferDataModel(OpenOfferManager openOfferManager, BtcWalletService btcWalletService, BsqWalletService bsqWalletService, + Preferences preferences, User user, KeyRing keyRing, P2PService p2PService, + PriceFeedService priceFeedService, FilterManager filterManager, + AccountAgeWitnessService accountAgeWitnessService, TradeWalletService tradeWalletService, + FeeService feeService, ReferralIdService referralIdService, BSFormatter formatter) { super(btcWalletService); this.openOfferManager = openOfferManager; @@ -251,11 +251,10 @@ public boolean initWithData(OfferPayload.Direction direction, TradeCurrency trad PaymentAccount account; - @Nullable PaymentAccount lastSelectedPaymentAccount = getPreselectedPaymentAccount(); if (lastSelectedPaymentAccount != null && user.getPaymentAccounts() != null && - user.getPaymentAccounts().contains(lastSelectedPaymentAccount)) { + user.getPaymentAccounts().stream().anyMatch(paymentAccount -> paymentAccount.getId() == lastSelectedPaymentAccount.getId())) { account = lastSelectedPaymentAccount; } else { account = user.findFirstPaymentAccountWithCurrency(tradeCurrency); @@ -293,7 +292,6 @@ public boolean initWithData(OfferPayload.Direction direction, TradeCurrency trad return true; } - @Nullable protected PaymentAccount getPreselectedPaymentAccount() { return preferences.getSelectedPaymentAccountForCreateOffer(); } diff --git a/src/main/java/bisq/desktop/main/offer/EditableOfferView.java b/src/main/java/bisq/desktop/main/offer/MutableOfferView.java similarity index 99% rename from src/main/java/bisq/desktop/main/offer/EditableOfferView.java rename to src/main/java/bisq/desktop/main/offer/MutableOfferView.java index 70c829a587e..0653b59a313 100644 --- a/src/main/java/bisq/desktop/main/offer/EditableOfferView.java +++ b/src/main/java/bisq/desktop/main/offer/MutableOfferView.java @@ -122,7 +122,7 @@ import static bisq.desktop.util.FormBuilder.*; import static javafx.beans.binding.Bindings.createStringBinding; -public abstract class EditableOfferView extends ActivatableViewAndModel { +public abstract class MutableOfferView extends ActivatableViewAndModel { protected final Navigation navigation; private final Preferences preferences; private final Transitions transitions; @@ -173,8 +173,8 @@ public abstract class EditableOfferView extend // Constructor, lifecycle /////////////////////////////////////////////////////////////////////////////////////////// - public EditableOfferView(M model, Navigation navigation, Preferences preferences, Transitions transitions, - OfferDetailsWindow offerDetailsWindow, BSFormatter btcFormatter, BsqFormatter bsqFormatter) { + public MutableOfferView(M model, Navigation navigation, Preferences preferences, Transitions transitions, + OfferDetailsWindow offerDetailsWindow, BSFormatter btcFormatter, BsqFormatter bsqFormatter) { super(model); this.navigation = navigation; diff --git a/src/main/java/bisq/desktop/main/offer/EditableOfferViewModel.java b/src/main/java/bisq/desktop/main/offer/MutableOfferViewModel.java similarity index 97% rename from src/main/java/bisq/desktop/main/offer/EditableOfferViewModel.java rename to src/main/java/bisq/desktop/main/offer/MutableOfferViewModel.java index ac7cbaa38d4..caa90ae9894 100644 --- a/src/main/java/bisq/desktop/main/offer/EditableOfferViewModel.java +++ b/src/main/java/bisq/desktop/main/offer/MutableOfferViewModel.java @@ -80,7 +80,7 @@ import static javafx.beans.binding.Bindings.createStringBinding; -public abstract class EditableOfferViewModel extends ActivatableWithDataModel { +public abstract class MutableOfferViewModel extends ActivatableWithDataModel { private final BtcValidator btcValidator; private final BsqValidator bsqValidator; private final SecurityDepositValidator securityDepositValidator; @@ -174,20 +174,20 @@ public abstract class EditableOfferViewModel e /////////////////////////////////////////////////////////////////////////////////////////// @Inject - public EditableOfferViewModel(M dataModel, - FiatVolumeValidator fiatVolumeValidator, - FiatPriceValidator fiatPriceValidator, - AltcoinValidator altcoinValidator, - BtcValidator btcValidator, - BsqValidator bsqValidator, - SecurityDepositValidator securityDepositValidator, - P2PService p2PService, - WalletsSetup walletsSetup, - PriceFeedService priceFeedService, - Navigation navigation, - Preferences preferences, - BSFormatter btcFormatter, - BsqFormatter bsqFormatter) { + public MutableOfferViewModel(M dataModel, + FiatVolumeValidator fiatVolumeValidator, + FiatPriceValidator fiatPriceValidator, + AltcoinValidator altcoinValidator, + BtcValidator btcValidator, + BsqValidator bsqValidator, + SecurityDepositValidator securityDepositValidator, + P2PService p2PService, + WalletsSetup walletsSetup, + PriceFeedService priceFeedService, + Navigation navigation, + Preferences preferences, + BSFormatter btcFormatter, + BsqFormatter bsqFormatter) { super(dataModel); this.fiatVolumeValidator = fiatVolumeValidator; diff --git a/src/main/java/bisq/desktop/main/offer/createoffer/CreateOfferDataModel.java b/src/main/java/bisq/desktop/main/offer/createoffer/CreateOfferDataModel.java index c34bcad8fba..e2250863431 100644 --- a/src/main/java/bisq/desktop/main/offer/createoffer/CreateOfferDataModel.java +++ b/src/main/java/bisq/desktop/main/offer/createoffer/CreateOfferDataModel.java @@ -17,7 +17,7 @@ package bisq.desktop.main.offer.createoffer; -import bisq.desktop.main.offer.EditableOfferDataModel; +import bisq.desktop.main.offer.MutableOfferDataModel; import bisq.core.btc.wallet.BsqWalletService; import bisq.core.btc.wallet.BtcWalletService; @@ -43,7 +43,7 @@ * Note that the create offer domain has a deeper scope in the application domain (TradeManager). * That model is just responsible for the domain specific parts displayed needed in that UI element. */ -class CreateOfferDataModel extends EditableOfferDataModel { +class CreateOfferDataModel extends MutableOfferDataModel { @Inject public CreateOfferDataModel(OpenOfferManager openOfferManager, BtcWalletService btcWalletService, BsqWalletService bsqWalletService, Preferences preferences, User user, KeyRing keyRing, P2PService p2PService, PriceFeedService priceFeedService, FilterManager filterManager, AccountAgeWitnessService accountAgeWitnessService, TradeWalletService tradeWalletService, FeeService feeService, ReferralIdService referralIdService, BSFormatter formatter) { diff --git a/src/main/java/bisq/desktop/main/offer/createoffer/CreateOfferView.java b/src/main/java/bisq/desktop/main/offer/createoffer/CreateOfferView.java index eb5d1a02895..f87ae6b6c1e 100644 --- a/src/main/java/bisq/desktop/main/offer/createoffer/CreateOfferView.java +++ b/src/main/java/bisq/desktop/main/offer/createoffer/CreateOfferView.java @@ -19,7 +19,7 @@ import bisq.desktop.Navigation; import bisq.desktop.common.view.FxmlView; -import bisq.desktop.main.offer.EditableOfferView; +import bisq.desktop.main.offer.MutableOfferView; import bisq.desktop.main.overlays.windows.OfferDetailsWindow; import bisq.desktop.util.Transitions; @@ -30,7 +30,7 @@ import com.google.inject.Inject; @FxmlView -public class CreateOfferView extends EditableOfferView { +public class CreateOfferView extends MutableOfferView { @Inject public CreateOfferView(CreateOfferViewModel model, Navigation navigation, Preferences preferences, Transitions transitions, OfferDetailsWindow offerDetailsWindow, BSFormatter btcFormatter, BsqFormatter bsqFormatter) { diff --git a/src/main/java/bisq/desktop/main/offer/createoffer/CreateOfferViewModel.java b/src/main/java/bisq/desktop/main/offer/createoffer/CreateOfferViewModel.java index 9013582f51c..c0c2bc3d892 100644 --- a/src/main/java/bisq/desktop/main/offer/createoffer/CreateOfferViewModel.java +++ b/src/main/java/bisq/desktop/main/offer/createoffer/CreateOfferViewModel.java @@ -19,7 +19,7 @@ import bisq.desktop.Navigation; import bisq.desktop.common.model.ViewModel; -import bisq.desktop.main.offer.EditableOfferViewModel; +import bisq.desktop.main.offer.MutableOfferViewModel; import bisq.desktop.util.validation.AltcoinValidator; import bisq.desktop.util.validation.BsqValidator; import bisq.desktop.util.validation.BtcValidator; @@ -37,7 +37,7 @@ import com.google.inject.Inject; -class CreateOfferViewModel extends EditableOfferViewModel implements ViewModel { +class CreateOfferViewModel extends MutableOfferViewModel implements ViewModel { @Inject public CreateOfferViewModel(CreateOfferDataModel dataModel, FiatVolumeValidator fiatVolumeValidator, FiatPriceValidator fiatPriceValidator, AltcoinValidator altcoinValidator, BtcValidator btcValidator, BsqValidator bsqValidator, SecurityDepositValidator securityDepositValidator, P2PService p2PService, WalletsSetup walletsSetup, PriceFeedService priceFeedService, Navigation navigation, Preferences preferences, BSFormatter btcFormatter, BsqFormatter bsqFormatter) { diff --git a/src/main/java/bisq/desktop/main/portfolio/PortfolioView.java b/src/main/java/bisq/desktop/main/portfolio/PortfolioView.java index 00ee682977d..26c06010075 100644 --- a/src/main/java/bisq/desktop/main/portfolio/PortfolioView.java +++ b/src/main/java/bisq/desktop/main/portfolio/PortfolioView.java @@ -26,7 +26,7 @@ import bisq.desktop.common.view.ViewLoader; import bisq.desktop.main.MainView; import bisq.desktop.main.portfolio.closedtrades.ClosedTradesView; -import bisq.desktop.main.portfolio.editoffer.EditOpenOfferView; +import bisq.desktop.main.portfolio.editoffer.EditOfferView; import bisq.desktop.main.portfolio.failedtrades.FailedTradesView; import bisq.desktop.main.portfolio.openoffer.OpenOffersView; import bisq.desktop.main.portfolio.pendingtrades.PendingTradesView; @@ -64,7 +64,7 @@ public class PortfolioView extends ActivatableViewAndModel private final ViewLoader viewLoader; private final Navigation navigation; private final FailedTradesManager failedTradesManager; - private EditOpenOfferView editOpenOfferView; + private EditOfferView editOfferView; private boolean editOpenOfferViewOpen; private OpenOffer openOffer; private OpenOffersView openOffersView; @@ -102,11 +102,11 @@ else if (newValue == failedTradesTab) navigation.navigateTo(MainView.class, PortfolioView.class, FailedTradesView.class); else if (newValue == editOpenOfferTab) { //noinspection unchecked - navigation.navigateTo(MainView.class, PortfolioView.class, EditOpenOfferView.class); + navigation.navigateTo(MainView.class, PortfolioView.class, EditOfferView.class); } if (oldValue != null && oldValue == editOpenOfferTab) - editOpenOfferView.onTabSelected(false); + editOfferView.onTabSelected(false); }; @@ -120,9 +120,9 @@ else if (newValue == editOpenOfferTab) { private void onEditOpenOfferRemoved() { editOpenOfferViewOpen = false; - if (editOpenOfferView != null) { - editOpenOfferView.onClose(); - editOpenOfferView = null; + if (editOfferView != null) { + editOfferView.onClose(); + editOfferView = null; } //noinspection unchecked @@ -156,8 +156,8 @@ else if (root.getSelectionModel().getSelectedItem() == failedTradesTab) navigation.navigateTo(MainView.class, PortfolioView.class, FailedTradesView.class); else if (root.getSelectionModel().getSelectedItem() == editOpenOfferTab) { //noinspection unchecked - navigation.navigateTo(MainView.class, PortfolioView.class, EditOpenOfferView.class); - if (editOpenOfferView != null) editOpenOfferView.onTabSelected(true); + navigation.navigateTo(MainView.class, PortfolioView.class, EditOfferView.class); + if (editOfferView != null) editOfferView.onTabSelected(true); } } @@ -185,19 +185,19 @@ private void loadView(Class viewClass) { currentTab = closedTradesTab; } else if (view instanceof FailedTradesView) { currentTab = failedTradesTab; - } else if (view instanceof EditOpenOfferView) { + } else if (view instanceof EditOfferView) { if (openOffer != null) { - if (editOpenOfferView == null) { - editOpenOfferView = (EditOpenOfferView) view; - editOpenOfferView.initWithData(openOffer); + if (editOfferView == null) { + editOfferView = (EditOfferView) view; + editOfferView.applyOpenOffer(openOffer); editOpenOfferTab = new Tab(Res.get("portfolio.tab.editOpenOffer")); - editOpenOfferView.setCloseHandler(() -> { + editOfferView.setCloseHandler(() -> { root.getTabs().remove(editOpenOfferTab); }); root.getTabs().add(editOpenOfferTab); } if (currentTab != editOpenOfferTab) - editOpenOfferView.onTabSelected(true); + editOfferView.onTabSelected(true); currentTab = editOpenOfferTab; } else { @@ -218,7 +218,7 @@ private void selectOpenOffersView(OpenOffersView view) { if (!editOpenOfferViewOpen) { editOpenOfferViewOpen = true; PortfolioView.this.openOffer = openOffer; - navigation.navigateTo(MainView.class, PortfolioView.this.getClass(), EditOpenOfferView.class); + navigation.navigateTo(MainView.class, PortfolioView.this.getClass(), EditOfferView.class); } else { log.error("You have already a \"Edit Offer\" tab open."); } diff --git a/src/main/java/bisq/desktop/main/portfolio/editoffer/EditOpenOfferDataModel.java b/src/main/java/bisq/desktop/main/portfolio/editoffer/EditOfferDataModel.java similarity index 76% rename from src/main/java/bisq/desktop/main/portfolio/editoffer/EditOpenOfferDataModel.java rename to src/main/java/bisq/desktop/main/portfolio/editoffer/EditOfferDataModel.java index b61e1b6ca08..56b85f6feca 100644 --- a/src/main/java/bisq/desktop/main/portfolio/editoffer/EditOpenOfferDataModel.java +++ b/src/main/java/bisq/desktop/main/portfolio/editoffer/EditOfferDataModel.java @@ -18,18 +18,21 @@ package bisq.desktop.main.portfolio.editoffer; -import bisq.desktop.main.offer.EditableOfferDataModel; +import bisq.desktop.main.offer.MutableOfferDataModel; import bisq.core.btc.wallet.BsqWalletService; import bisq.core.btc.wallet.BtcWalletService; import bisq.core.btc.wallet.TradeWalletService; import bisq.core.filter.FilterManager; +import bisq.core.locale.CurrencyUtil; +import bisq.core.locale.TradeCurrency; import bisq.core.offer.Offer; import bisq.core.offer.OfferPayload; import bisq.core.offer.OpenOffer; import bisq.core.offer.OpenOfferManager; import bisq.core.payment.AccountAgeWitnessService; import bisq.core.payment.PaymentAccount; +import bisq.core.proto.persistable.CorePersistenceProtoResolver; import bisq.core.provider.fee.FeeService; import bisq.core.provider.price.PriceFeedService; import bisq.core.trade.statistics.ReferralIdService; @@ -42,33 +45,41 @@ import bisq.common.crypto.KeyRing; import bisq.common.handlers.ErrorMessageHandler; import bisq.common.handlers.ResultHandler; +import bisq.common.proto.persistable.PersistenceProtoResolver; import com.google.inject.Inject; -import javax.annotation.Nullable; - -class EditOpenOfferDataModel extends EditableOfferDataModel { +class EditOfferDataModel extends MutableOfferDataModel { + private final CorePersistenceProtoResolver corePersistenceProtoResolver; private OpenOffer openOffer; private OpenOffer.State initialState; @Inject - EditOpenOfferDataModel(OpenOfferManager openOfferManager, BtcWalletService btcWalletService, BsqWalletService bsqWalletService, Preferences preferences, User user, KeyRing keyRing, P2PService p2PService, PriceFeedService priceFeedService, FilterManager filterManager, AccountAgeWitnessService accountAgeWitnessService, TradeWalletService tradeWalletService, FeeService feeService, ReferralIdService referralIdService, BSFormatter formatter) { + EditOfferDataModel(OpenOfferManager openOfferManager, BtcWalletService btcWalletService, BsqWalletService bsqWalletService, Preferences preferences, User user, KeyRing keyRing, P2PService p2PService, PriceFeedService priceFeedService, FilterManager filterManager, AccountAgeWitnessService accountAgeWitnessService, TradeWalletService tradeWalletService, FeeService feeService, ReferralIdService referralIdService, BSFormatter formatter, CorePersistenceProtoResolver corePersistenceProtoResolver) { super(openOfferManager, btcWalletService, bsqWalletService, preferences, user, keyRing, p2PService, priceFeedService, filterManager, accountAgeWitnessService, tradeWalletService, feeService, referralIdService, formatter); + this.corePersistenceProtoResolver = corePersistenceProtoResolver; } - public void initWithData(OpenOffer openOffer) { + public void applyOpenOffer(OpenOffer openOffer) { this.openOffer = openOffer; this.initialState = openOffer.getState(); - this.paymentAccount = user.getPaymentAccount(openOffer.getOffer().getMakerPaymentAccountId()); + final PaymentAccount tmpPaymentAccount = user.getPaymentAccount(openOffer.getOffer().getMakerPaymentAccountId()); + final TradeCurrency selectedTradeCurrency = CurrencyUtil.getTradeCurrency(openOffer.getOffer().getCurrencyCode()).get(); + + this.paymentAccount = PaymentAccount.fromProto(tmpPaymentAccount.toProtoMessage(), corePersistenceProtoResolver); + + if (paymentAccount.getSingleTradeCurrency() != null) + paymentAccount.setSingleTradeCurrency(selectedTradeCurrency); + else + paymentAccount.setSelectedTradeCurrency(selectedTradeCurrency); this.allowAmountUpdate = false; } @Override - @Nullable protected PaymentAccount getPreselectedPaymentAccount() { - return null; + return paymentAccount; } public void populateData() { diff --git a/src/main/java/bisq/desktop/main/portfolio/editoffer/EditOpenOfferView.fxml b/src/main/java/bisq/desktop/main/portfolio/editoffer/EditOfferView.fxml similarity index 96% rename from src/main/java/bisq/desktop/main/portfolio/editoffer/EditOpenOfferView.fxml rename to src/main/java/bisq/desktop/main/portfolio/editoffer/EditOfferView.fxml index 09d2714c84d..b8154a00f0b 100644 --- a/src/main/java/bisq/desktop/main/portfolio/editoffer/EditOpenOfferView.fxml +++ b/src/main/java/bisq/desktop/main/portfolio/editoffer/EditOfferView.fxml @@ -18,7 +18,7 @@ --> - diff --git a/src/main/java/bisq/desktop/main/portfolio/editoffer/EditOpenOfferView.java b/src/main/java/bisq/desktop/main/portfolio/editoffer/EditOfferView.java similarity index 93% rename from src/main/java/bisq/desktop/main/portfolio/editoffer/EditOpenOfferView.java rename to src/main/java/bisq/desktop/main/portfolio/editoffer/EditOfferView.java index 96f3a62b403..27035cb1948 100644 --- a/src/main/java/bisq/desktop/main/portfolio/editoffer/EditOpenOfferView.java +++ b/src/main/java/bisq/desktop/main/portfolio/editoffer/EditOfferView.java @@ -20,7 +20,7 @@ import bisq.desktop.Navigation; import bisq.desktop.common.view.FxmlView; import bisq.desktop.components.BusyAnimation; -import bisq.desktop.main.offer.EditableOfferView; +import bisq.desktop.main.offer.MutableOfferView; import bisq.desktop.main.overlays.popups.Popup; import bisq.desktop.main.overlays.windows.OfferDetailsWindow; import bisq.desktop.util.Transitions; @@ -46,7 +46,7 @@ import static bisq.desktop.util.FormBuilder.addButtonBusyAnimationLabelAfterGroup; @FxmlView -public class EditOpenOfferView extends EditableOfferView { +public class EditOfferView extends MutableOfferView { private BusyAnimation busyAnimation; private Button confirmButton; @@ -57,7 +57,7 @@ public class EditOpenOfferView extends EditableOfferView /////////////////////////////////////////////////////////////////////////////////////////// @Inject - private EditOpenOfferView(EditOpenOfferViewModel model, Navigation navigation, Preferences preferences, Transitions transitions, OfferDetailsWindow offerDetailsWindow, BSFormatter btcFormatter, BsqFormatter bsqFormatter) { + private EditOfferView(EditOfferViewModel model, Navigation navigation, Preferences preferences, Transitions transitions, OfferDetailsWindow offerDetailsWindow, BSFormatter btcFormatter, BsqFormatter bsqFormatter) { super(model, navigation, preferences, transitions, offerDetailsWindow, btcFormatter, bsqFormatter); } @@ -130,10 +130,11 @@ protected void deactivate() { // API /////////////////////////////////////////////////////////////////////////////////////////// - public void initWithData(OpenOffer openOffer) { - super.initWithData(openOffer.getOffer().getDirection(), + public void applyOpenOffer(OpenOffer openOffer) { + model.applyOpenOffer(openOffer); + + initWithData(openOffer.getOffer().getDirection(), CurrencyUtil.getTradeCurrency(openOffer.getOffer().getCurrencyCode()).get()); - model.initWithData(openOffer); model.onStartEditOffer(errorMessage -> { log.error(errorMessage); diff --git a/src/main/java/bisq/desktop/main/portfolio/editoffer/EditOpenOfferViewModel.java b/src/main/java/bisq/desktop/main/portfolio/editoffer/EditOfferViewModel.java similarity index 79% rename from src/main/java/bisq/desktop/main/portfolio/editoffer/EditOpenOfferViewModel.java rename to src/main/java/bisq/desktop/main/portfolio/editoffer/EditOfferViewModel.java index 6b83694d392..83c3fa05336 100644 --- a/src/main/java/bisq/desktop/main/portfolio/editoffer/EditOpenOfferViewModel.java +++ b/src/main/java/bisq/desktop/main/portfolio/editoffer/EditOfferViewModel.java @@ -18,7 +18,7 @@ package bisq.desktop.main.portfolio.editoffer; import bisq.desktop.Navigation; -import bisq.desktop.main.offer.EditableOfferViewModel; +import bisq.desktop.main.offer.MutableOfferViewModel; import bisq.desktop.util.validation.AltcoinValidator; import bisq.desktop.util.validation.BsqValidator; import bisq.desktop.util.validation.BtcValidator; @@ -40,10 +40,10 @@ import com.google.inject.Inject; -class EditOpenOfferViewModel extends EditableOfferViewModel { +class EditOfferViewModel extends MutableOfferViewModel { @Inject - public EditOpenOfferViewModel(EditOpenOfferDataModel dataModel, FiatVolumeValidator fiatVolumeValidator, FiatPriceValidator fiatPriceValidator, AltcoinValidator altcoinValidator, BtcValidator btcValidator, BsqValidator bsqValidator, SecurityDepositValidator securityDepositValidator, P2PService p2PService, WalletsSetup walletsSetup, PriceFeedService priceFeedService, Navigation navigation, Preferences preferences, BSFormatter btcFormatter, BsqFormatter bsqFormatter) { + public EditOfferViewModel(EditOfferDataModel dataModel, FiatVolumeValidator fiatVolumeValidator, FiatPriceValidator fiatPriceValidator, AltcoinValidator altcoinValidator, BtcValidator btcValidator, BsqValidator bsqValidator, SecurityDepositValidator securityDepositValidator, P2PService p2PService, WalletsSetup walletsSetup, PriceFeedService priceFeedService, Navigation navigation, Preferences preferences, BSFormatter btcFormatter, BsqFormatter bsqFormatter) { super(dataModel, fiatVolumeValidator, fiatPriceValidator, altcoinValidator, btcValidator, bsqValidator, securityDepositValidator, p2PService, walletsSetup, priceFeedService, navigation, preferences, btcFormatter, bsqFormatter); } @@ -53,8 +53,8 @@ public void activate() { dataModel.populateData(); } - public void initWithData(OpenOffer openOffer) { - dataModel.initWithData(openOffer); + public void applyOpenOffer(OpenOffer openOffer) { + dataModel.applyOpenOffer(openOffer); } public void onStartEditOffer(ErrorMessageHandler errorMessageHandler) { From a64404ef5a53a4b5508d49ebc8250635da4032dd Mon Sep 17 00:00:00 2001 From: Christoph Atteneder Date: Wed, 27 Jun 2018 22:07:11 +0200 Subject: [PATCH 2/2] Use equals --- .../java/bisq/desktop/main/offer/MutableOfferDataModel.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java b/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java index 4a1fd82ea4d..3d7e5600e68 100644 --- a/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java +++ b/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java @@ -254,7 +254,7 @@ public boolean initWithData(OfferPayload.Direction direction, TradeCurrency trad PaymentAccount lastSelectedPaymentAccount = getPreselectedPaymentAccount(); if (lastSelectedPaymentAccount != null && user.getPaymentAccounts() != null && - user.getPaymentAccounts().stream().anyMatch(paymentAccount -> paymentAccount.getId() == lastSelectedPaymentAccount.getId())) { + user.getPaymentAccounts().stream().anyMatch(paymentAccount -> paymentAccount.getId().equals(lastSelectedPaymentAccount.getId()))) { account = lastSelectedPaymentAccount; } else { account = user.findFirstPaymentAccountWithCurrency(tradeCurrency);