mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-19 09:52:23 +01:00
Add support to duplicate bsq swap offers
This commit is contained in:
parent
9aad4d6a40
commit
1606439144
@ -25,6 +25,7 @@ import bisq.core.btc.wallet.BsqWalletService;
|
||||
import bisq.core.btc.wallet.BtcWalletService;
|
||||
import bisq.core.monetary.Price;
|
||||
import bisq.core.monetary.Volume;
|
||||
import bisq.core.offer.Offer;
|
||||
import bisq.core.offer.OfferDirection;
|
||||
import bisq.core.offer.OfferUtil;
|
||||
import bisq.core.payment.payload.PaymentMethod;
|
||||
@ -124,10 +125,20 @@ public class BsqSwapOfferModel {
|
||||
// API
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public void init(OfferDirection direction, boolean isMaker) {
|
||||
public void init(OfferDirection direction, boolean isMaker, Offer offer) {
|
||||
this.direction = direction;
|
||||
this.isMaker = isMaker;
|
||||
|
||||
if (offer != null) {
|
||||
setPrice(offer.getPrice());
|
||||
|
||||
setBtcAmount(Coin.valueOf(Math.min(offer.getAmount().value, getMaxTradeLimit())));
|
||||
calculateVolumeForAmount(getBtcAmount());
|
||||
|
||||
setMinAmount(offer.getMinAmount());
|
||||
calculateMinVolume();
|
||||
}
|
||||
|
||||
createListeners();
|
||||
applyTxFeePerVbyte();
|
||||
|
||||
|
@ -67,17 +67,9 @@ public class BsqSwapTakeOfferModel extends BsqSwapOfferModel {
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public void initWithData(Offer offer) {
|
||||
super.init(offer.getDirection(), false);
|
||||
super.init(offer.getDirection(), false, offer);
|
||||
|
||||
this.offer = offer;
|
||||
setPrice(offer.getPrice());
|
||||
|
||||
setBtcAmount(Coin.valueOf(Math.min(offer.getAmount().value, getMaxTradeLimit())));
|
||||
calculateVolumeForAmount(getBtcAmount());
|
||||
|
||||
setMinAmount(offer.getMinAmount());
|
||||
calculateMinVolume();
|
||||
|
||||
offer.resetState();
|
||||
}
|
||||
|
||||
|
@ -37,6 +37,7 @@ import bisq.core.locale.Res;
|
||||
import bisq.core.locale.TradeCurrency;
|
||||
import bisq.core.offer.Offer;
|
||||
import bisq.core.offer.OfferDirection;
|
||||
import bisq.core.offer.bsq_swap.BsqSwapOfferPayload;
|
||||
import bisq.core.payment.payload.PaymentMethod;
|
||||
import bisq.core.support.dispute.arbitration.arbitrator.ArbitratorManager;
|
||||
import bisq.core.user.Preferences;
|
||||
@ -56,6 +57,8 @@ import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public abstract class OfferView extends ActivatableView<TabPane, Void> {
|
||||
|
||||
private OfferBookView offerBookView;
|
||||
@ -102,7 +105,7 @@ public abstract class OfferView extends ActivatableView<TabPane, Void> {
|
||||
protected void initialize() {
|
||||
navigationListener = (viewPath, data) -> {
|
||||
if (viewPath.size() == 3 && viewPath.indexOf(this.getClass()) == 1)
|
||||
loadView(viewPath.tip());
|
||||
loadView(viewPath.tip(), data);
|
||||
};
|
||||
tabChangeListener = (observableValue, oldValue, newValue) -> {
|
||||
if (newValue != null) {
|
||||
@ -198,7 +201,7 @@ public abstract class OfferView extends ActivatableView<TabPane, Void> {
|
||||
return Res.get("offerbook.takeOffer").toUpperCase();
|
||||
}
|
||||
|
||||
private void loadView(Class<? extends View> viewClass) {
|
||||
private void loadView(Class<? extends View> viewClass, @Nullable Object data) {
|
||||
TabPane tabPane = root;
|
||||
tabPane.setTabClosingPolicy(TabPane.TabClosingPolicy.ALL_TABS);
|
||||
View view;
|
||||
@ -237,7 +240,7 @@ public abstract class OfferView extends ActivatableView<TabPane, Void> {
|
||||
} else if (viewClass == BsqSwapCreateOfferView.class && bsqSwapCreateOfferView == null) {
|
||||
view = viewLoader.load(viewClass);
|
||||
bsqSwapCreateOfferView = (BsqSwapCreateOfferView) view;
|
||||
bsqSwapCreateOfferView.initWithData(direction, offerActionHandler);
|
||||
bsqSwapCreateOfferView.initWithData(direction, offerActionHandler, (BsqSwapOfferPayload) data);
|
||||
createOfferPane = bsqSwapCreateOfferView.getRoot();
|
||||
createOfferTab = new Tab(getCreateOfferTabName(viewClass));
|
||||
createOfferTab.setClosable(true);
|
||||
|
@ -28,6 +28,7 @@ import bisq.core.offer.Offer;
|
||||
import bisq.core.offer.OfferDirection;
|
||||
import bisq.core.offer.OfferUtil;
|
||||
import bisq.core.offer.bsq_swap.BsqSwapOfferModel;
|
||||
import bisq.core.offer.bsq_swap.BsqSwapOfferPayload;
|
||||
import bisq.core.offer.bsq_swap.OpenBsqSwapOfferService;
|
||||
import bisq.core.payment.PaymentAccount;
|
||||
import bisq.core.user.User;
|
||||
@ -91,8 +92,8 @@ class BsqSwapCreateOfferDataModel extends BsqSwapOfferDataModel {
|
||||
// API
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void initWithData(OfferDirection direction) {
|
||||
bsqSwapOfferModel.init(direction, true);
|
||||
void initWithData(OfferDirection direction, BsqSwapOfferPayload offerPayload) {
|
||||
bsqSwapOfferModel.init(direction, true, offerPayload != null ? new Offer(offerPayload) : null);
|
||||
|
||||
fillPaymentAccounts();
|
||||
applyPaymentAccount();
|
||||
|
@ -37,6 +37,7 @@ import bisq.desktop.util.Layout;
|
||||
import bisq.core.locale.CurrencyUtil;
|
||||
import bisq.core.locale.Res;
|
||||
import bisq.core.offer.OfferDirection;
|
||||
import bisq.core.offer.bsq_swap.BsqSwapOfferPayload;
|
||||
import bisq.core.payment.PaymentAccount;
|
||||
import bisq.core.user.DontShowAgainLookup;
|
||||
|
||||
@ -159,9 +160,12 @@ public class BsqSwapCreateOfferView extends BsqSwapOfferView<BsqSwapCreateOfferV
|
||||
// API
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public void initWithData(OfferDirection direction, OfferView.OfferActionHandler offerActionHandler) {
|
||||
public void initWithData(OfferDirection direction,
|
||||
OfferView.OfferActionHandler offerActionHandler,
|
||||
BsqSwapOfferPayload offerPayload) {
|
||||
this.offerActionHandler = offerActionHandler;
|
||||
model.initWithData(direction);
|
||||
|
||||
model.initWithData(offerPayload != null ? offerPayload.getDirection() : direction, offerPayload);
|
||||
|
||||
if (model.dataModel.isBuyOffer()) {
|
||||
actionButton.setId("buy-button-big");
|
||||
|
@ -31,6 +31,7 @@ import bisq.core.monetary.Price;
|
||||
import bisq.core.monetary.Volume;
|
||||
import bisq.core.offer.OfferDirection;
|
||||
import bisq.core.offer.OfferRestrictions;
|
||||
import bisq.core.offer.bsq_swap.BsqSwapOfferPayload;
|
||||
import bisq.core.payment.payload.PaymentMethod;
|
||||
import bisq.core.util.FormattingUtils;
|
||||
import bisq.core.util.VolumeUtil;
|
||||
@ -144,6 +145,8 @@ class BsqSwapCreateOfferViewModel extends BsqSwapOfferViewModel<BsqSwapCreateOff
|
||||
addBindings();
|
||||
addListeners();
|
||||
|
||||
maybeInitializeWithData();
|
||||
|
||||
updateButtonDisableState();
|
||||
}
|
||||
|
||||
@ -159,8 +162,8 @@ class BsqSwapCreateOfferViewModel extends BsqSwapOfferViewModel<BsqSwapCreateOff
|
||||
// API
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void initWithData(OfferDirection direction) {
|
||||
dataModel.initWithData(direction);
|
||||
void initWithData(OfferDirection direction, BsqSwapOfferPayload offerPayload) {
|
||||
dataModel.initWithData(direction, offerPayload);
|
||||
|
||||
btcValidator.setMaxValue(PaymentMethod.BSQ_SWAP.getMaxTradeLimitAsCoin(BSQ));
|
||||
btcValidator.setMaxTradeLimit(Coin.valueOf(dataModel.getMaxTradeLimit()));
|
||||
@ -572,6 +575,33 @@ class BsqSwapCreateOfferViewModel extends BsqSwapOfferViewModel<BsqSwapCreateOff
|
||||
isPlaceOfferButtonDisabled.set(createOfferRequested || !inputDataValid || miningPoW.get());
|
||||
}
|
||||
|
||||
private void maybeInitializeWithData() {
|
||||
ObjectProperty<Coin> btcMinAmount = dataModel.getMinAmount();
|
||||
if (btcMinAmount.get() != null) {
|
||||
minAmountAsCoinListener.changed(btcMinAmount, null, btcMinAmount.get());
|
||||
}
|
||||
|
||||
ObjectProperty<Coin> btcAmount = dataModel.getBtcAmount();
|
||||
|
||||
if (btcAmount.get() != null && btcAmount.get() != null) {
|
||||
syncMinAmountWithAmount = btcMinAmount.get().equals(dataModel.getBtcAmount().get());
|
||||
}
|
||||
|
||||
if (btcAmount.get() != null) {
|
||||
amountAsCoinListener.changed(btcAmount, null, btcAmount.get());
|
||||
}
|
||||
|
||||
ObjectProperty<Price> price = dataModel.getPrice();
|
||||
if (price.get() != null) {
|
||||
priceListener.changed(price, null, price.get());
|
||||
}
|
||||
|
||||
ObjectProperty<Volume> volume = dataModel.getVolume();
|
||||
if (volume.get() != null) {
|
||||
volumeListener.changed(volume, null, volume.get());
|
||||
}
|
||||
}
|
||||
|
||||
private void stopTimeoutTimer() {
|
||||
if (timeoutTimer != null) {
|
||||
timeoutTimer.stop();
|
||||
|
@ -23,6 +23,9 @@ import bisq.desktop.common.view.CachingViewLoader;
|
||||
import bisq.desktop.common.view.FxmlView;
|
||||
import bisq.desktop.common.view.View;
|
||||
import bisq.desktop.main.MainView;
|
||||
import bisq.desktop.main.offer.BuyOfferView;
|
||||
import bisq.desktop.main.offer.SellOfferView;
|
||||
import bisq.desktop.main.offer.bsq_swap.create_offer.BsqSwapCreateOfferView;
|
||||
import bisq.desktop.main.portfolio.bsqswaps.UnconfirmedBsqSwapsView;
|
||||
import bisq.desktop.main.portfolio.closedtrades.ClosedTradesView;
|
||||
import bisq.desktop.main.portfolio.duplicateoffer.DuplicateOfferView;
|
||||
@ -32,8 +35,10 @@ import bisq.desktop.main.portfolio.openoffer.OpenOffersView;
|
||||
import bisq.desktop.main.portfolio.pendingtrades.PendingTradesView;
|
||||
|
||||
import bisq.core.locale.Res;
|
||||
import bisq.core.offer.OfferDirection;
|
||||
import bisq.core.offer.OfferPayloadBase;
|
||||
import bisq.core.offer.OpenOffer;
|
||||
import bisq.core.offer.bisq_v1.OfferPayload;
|
||||
import bisq.core.offer.bsq_swap.BsqSwapOfferPayload;
|
||||
import bisq.core.trade.bisq_v1.FailedTradesManager;
|
||||
import bisq.core.trade.model.bisq_v1.Trade;
|
||||
|
||||
@ -228,11 +233,18 @@ public class PortfolioView extends ActivatableView<TabPane, Void> {
|
||||
selectOpenOffersView((OpenOffersView) view);
|
||||
}
|
||||
} else if (view instanceof DuplicateOfferView) {
|
||||
if (duplicateOfferView == null && data instanceof OfferPayload) {
|
||||
if (duplicateOfferView == null && data instanceof OfferPayloadBase) {
|
||||
// Switch to create BSQ swap offer
|
||||
if (data instanceof BsqSwapOfferPayload) {
|
||||
var offerViewClass = ((BsqSwapOfferPayload) data).getDirection() == OfferDirection.BUY ? BuyOfferView.class : SellOfferView.class;
|
||||
navigation.navigateToWithData(data, MainView.class, offerViewClass, BsqSwapCreateOfferView.class);
|
||||
return;
|
||||
}
|
||||
|
||||
viewLoader.removeFromCache(viewClass); // remove cached dialog
|
||||
view = viewLoader.load(viewClass); // and load a fresh one
|
||||
duplicateOfferView = (DuplicateOfferView) view;
|
||||
duplicateOfferView.initWithData((OfferPayload) data);
|
||||
duplicateOfferView.initWithData((OfferPayloadBase) data);
|
||||
duplicateOfferTab = new Tab(Res.get("portfolio.tab.duplicateOffer").toUpperCase());
|
||||
duplicateOfferView.setCloseHandler(() -> {
|
||||
root.getTabs().remove(duplicateOfferTab);
|
||||
|
@ -23,7 +23,7 @@ import bisq.desktop.main.offer.bisq_v1.MutableOfferView;
|
||||
import bisq.desktop.main.overlays.windows.OfferDetailsWindow;
|
||||
|
||||
import bisq.core.locale.CurrencyUtil;
|
||||
import bisq.core.offer.bisq_v1.OfferPayload;
|
||||
import bisq.core.offer.OfferPayloadBase;
|
||||
import bisq.core.user.Preferences;
|
||||
import bisq.core.util.FormattingUtils;
|
||||
import bisq.core.util.coin.BsqFormatter;
|
||||
@ -61,7 +61,7 @@ public class DuplicateOfferView extends MutableOfferView<DuplicateOfferViewModel
|
||||
onPaymentAccountsComboBoxSelected();
|
||||
}
|
||||
|
||||
public void initWithData(OfferPayload offerPayload) {
|
||||
public void initWithData(OfferPayloadBase offerPayload) {
|
||||
initWithData(offerPayload.getDirection(),
|
||||
CurrencyUtil.getTradeCurrency(offerPayload.getCurrencyCode()).get(),
|
||||
null);
|
||||
|
@ -26,8 +26,8 @@ import bisq.desktop.util.validation.SecurityDepositValidator;
|
||||
|
||||
import bisq.core.account.witness.AccountAgeWitnessService;
|
||||
import bisq.core.offer.Offer;
|
||||
import bisq.core.offer.OfferPayloadBase;
|
||||
import bisq.core.offer.OfferUtil;
|
||||
import bisq.core.offer.bisq_v1.OfferPayload;
|
||||
import bisq.core.provider.price.PriceFeedService;
|
||||
import bisq.core.user.Preferences;
|
||||
import bisq.core.util.FormattingUtils;
|
||||
@ -77,7 +77,7 @@ class DuplicateOfferViewModel extends MutableOfferViewModel<DuplicateOfferDataMo
|
||||
syncMinAmountWithAmount = false;
|
||||
}
|
||||
|
||||
public void initWithData(OfferPayload offerPayload) {
|
||||
public void initWithData(OfferPayloadBase offerPayload) {
|
||||
this.offer = new Offer(offerPayload);
|
||||
offer.setPriceFeedService(priceFeedService);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user