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