Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix edit offer problem for payment accounts with multiple currencies #1595

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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().equals(lastSelectedPaymentAccount.getId()))) {
account = lastSelectedPaymentAccount;
} else {
account = user.findFirstPaymentAccountWithCurrency(tradeCurrency);
Expand Down Expand Up @@ -293,7 +292,6 @@ public boolean initWithData(OfferPayload.Direction direction, TradeCurrency trad
return true;
}

@Nullable
protected PaymentAccount getPreselectedPaymentAccount() {
return preferences.getSelectedPaymentAccountForCreateOffer();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
import static bisq.desktop.util.FormBuilder.*;
import static javafx.beans.binding.Bindings.createStringBinding;

public abstract class EditableOfferView<M extends EditableOfferViewModel> extends ActivatableViewAndModel<AnchorPane, M> {
public abstract class MutableOfferView<M extends MutableOfferViewModel> extends ActivatableViewAndModel<AnchorPane, M> {
protected final Navigation navigation;
private final Preferences preferences;
private final Transitions transitions;
Expand Down Expand Up @@ -173,8 +173,8 @@ public abstract class EditableOfferView<M extends EditableOfferViewModel> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@

import static javafx.beans.binding.Bindings.createStringBinding;

public abstract class EditableOfferViewModel<M extends EditableOfferDataModel> extends ActivatableWithDataModel<M> {
public abstract class MutableOfferViewModel<M extends MutableOfferDataModel> extends ActivatableWithDataModel<M> {
private final BtcValidator btcValidator;
private final BsqValidator bsqValidator;
private final SecurityDepositValidator securityDepositValidator;
Expand Down Expand Up @@ -174,20 +174,20 @@ public abstract class EditableOfferViewModel<M extends EditableOfferDataModel> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -30,7 +30,7 @@
import com.google.inject.Inject;

@FxmlView
public class CreateOfferView extends EditableOfferView<CreateOfferViewModel> {
public class CreateOfferView extends MutableOfferView<CreateOfferViewModel> {

@Inject
public CreateOfferView(CreateOfferViewModel model, Navigation navigation, Preferences preferences, Transitions transitions, OfferDetailsWindow offerDetailsWindow, BSFormatter btcFormatter, BsqFormatter bsqFormatter) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -37,7 +37,7 @@

import com.google.inject.Inject;

class CreateOfferViewModel extends EditableOfferViewModel<CreateOfferDataModel> implements ViewModel {
class CreateOfferViewModel extends MutableOfferViewModel<CreateOfferDataModel> 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) {
Expand Down
32 changes: 16 additions & 16 deletions src/main/java/bisq/desktop/main/portfolio/PortfolioView.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -64,7 +64,7 @@ public class PortfolioView extends ActivatableViewAndModel<TabPane, Activatable>
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;
Expand Down Expand Up @@ -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);

};

Expand All @@ -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
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -185,19 +185,19 @@ private void loadView(Class<? extends View> 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 {
Expand All @@ -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.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should add a comment why we clone


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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
-->

<?import javafx.scene.layout.AnchorPane?>
<AnchorPane fx:id="root" fx:controller="bisq.desktop.main.portfolio.editoffer.EditOpenOfferView"
<AnchorPane fx:id="root" fx:controller="bisq.desktop.main.portfolio.editoffer.EditOfferView"
xmlns:fx="http://javafx.com/fxml">

</AnchorPane>
Loading