mirror of
https://github.com/bisq-network/bisq.git
synced 2025-02-20 13:54:32 +01:00
Refactor OrderBookInfo (renamed from OrderBookFilter)
This commit is contained in:
parent
f20fe3a22b
commit
870cd062f5
10 changed files with 66 additions and 100 deletions
|
@ -30,7 +30,7 @@ public class BuyViewCB extends TradeViewCB {
|
|||
|
||||
@Override
|
||||
protected void initOrderBook() {
|
||||
orderBookViewCB.initOrderBook(Direction.BUY);
|
||||
orderBookViewCB.initOrderBook(Direction.BUY, presentationModel.getOrderBookInfo());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -22,16 +22,18 @@ import io.bitsquare.trade.Direction;
|
|||
import com.google.bitcoin.core.Coin;
|
||||
import com.google.bitcoin.utils.Fiat;
|
||||
|
||||
import javafx.beans.property.SimpleBooleanProperty;
|
||||
import javafx.beans.property.ObjectProperty;
|
||||
import javafx.beans.property.SimpleObjectProperty;
|
||||
|
||||
//TODO move to OrderBookModel when converted to new UI structure
|
||||
public class OrderBookFilter {
|
||||
// TODO use ObjectProperty<Direction> instead
|
||||
private final SimpleBooleanProperty directionChangedProperty = new SimpleBooleanProperty();
|
||||
/**
|
||||
* Shared data between the different trade UIs
|
||||
*/
|
||||
public class OrderBookInfo {
|
||||
|
||||
private final ObjectProperty<Direction> direction = new SimpleObjectProperty<>();
|
||||
|
||||
private Fiat price;
|
||||
private Coin amount;
|
||||
private Direction direction;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -46,8 +48,8 @@ public class OrderBookFilter {
|
|||
this.amount = amount;
|
||||
}
|
||||
|
||||
public Direction getDirection() {
|
||||
return direction;
|
||||
public void setDirection(Direction direction) {
|
||||
this.direction.set(direction);
|
||||
}
|
||||
|
||||
|
||||
|
@ -55,11 +57,6 @@ public class OrderBookFilter {
|
|||
// Getters
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public void setDirection(Direction direction) {
|
||||
this.direction = direction;
|
||||
directionChangedProperty.set(!directionChangedProperty.get());
|
||||
}
|
||||
|
||||
public Fiat getPrice() {
|
||||
return price;
|
||||
}
|
||||
|
@ -68,7 +65,13 @@ public class OrderBookFilter {
|
|||
this.price = price;
|
||||
}
|
||||
|
||||
public SimpleBooleanProperty getDirectionChangedProperty() {
|
||||
return directionChangedProperty;
|
||||
public Direction getDirection() {
|
||||
return direction.get();
|
||||
}
|
||||
|
||||
public ObjectProperty<Direction> directionProperty() {
|
||||
return direction;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -30,7 +30,7 @@ public class SellViewCB extends TradeViewCB {
|
|||
|
||||
@Override
|
||||
protected void initOrderBook() {
|
||||
orderBookViewCB.initOrderBook(Direction.SELL);
|
||||
orderBookViewCB.initOrderBook(Direction.SELL, presentationModel.getOrderBookInfo());
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -27,33 +27,23 @@ import org.slf4j.LoggerFactory;
|
|||
public class TradeModel extends UIModel {
|
||||
private static final Logger log = LoggerFactory.getLogger(TradeModel.class);
|
||||
|
||||
private OrderBookInfo orderBookInfo;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Constructor
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@Inject
|
||||
public TradeModel() {
|
||||
public TradeModel(OrderBookInfo orderBookInfo) {
|
||||
this.orderBookInfo = orderBookInfo;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Public methods
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Getters
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Setters
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Private methods
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
public OrderBookInfo getOrderBookInfo() {
|
||||
return orderBookInfo;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,29 +37,11 @@ public class TradePM extends PresentationModel<TradeModel> {
|
|||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Public methods
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Interface implementation: Initializable
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Getters
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Setters
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Private methods
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
public OrderBookInfo getOrderBookInfo() {
|
||||
return model.getOrderBookInfo();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,8 +47,8 @@ public abstract class TradeViewCB extends CachedViewCB<TradePM> {
|
|||
private static final Logger log = LoggerFactory.getLogger(TradeViewCB.class);
|
||||
|
||||
protected OrderBookViewCB orderBookViewCB;
|
||||
protected CreateOfferViewCB createOfferViewCB;
|
||||
protected TakeOfferController takeOfferController;
|
||||
private CreateOfferViewCB createOfferViewCB;
|
||||
private TakeOfferController takeOfferController;
|
||||
private Node createOfferView;
|
||||
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ package io.bitsquare.gui.main.trade.createoffer;
|
|||
|
||||
import io.bitsquare.btc.WalletFacade;
|
||||
import io.bitsquare.gui.PresentationModel;
|
||||
import io.bitsquare.gui.main.trade.OrderBookFilter;
|
||||
import io.bitsquare.gui.main.trade.OrderBookInfo;
|
||||
import io.bitsquare.gui.util.BSFormatter;
|
||||
import io.bitsquare.gui.util.validation.BtcValidator;
|
||||
import io.bitsquare.gui.util.validation.FiatValidator;
|
||||
|
@ -154,21 +154,21 @@ public class CreateOfferPM extends PresentationModel<CreateOfferModel> {
|
|||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// setOrderBookFilter is a one time call
|
||||
public void setOrderBookFilter(@NotNull OrderBookFilter orderBookFilter) {
|
||||
model.setDirection(orderBookFilter.getDirection());
|
||||
public void setOrderBookFilter(@NotNull OrderBookInfo orderBookInfo) {
|
||||
model.setDirection(orderBookInfo.getDirection());
|
||||
directionLabel.set(model.getDirection() == Direction.BUY ? BSResources.get("shared.buy") : BSResources.get
|
||||
("shared.sell"));
|
||||
|
||||
// apply only if valid
|
||||
if (orderBookFilter.getAmount() != null && isBtcInputValid(orderBookFilter.getAmount().toPlainString())
|
||||
if (orderBookInfo.getAmount() != null && isBtcInputValid(orderBookInfo.getAmount().toPlainString())
|
||||
.isValid) {
|
||||
model.amountAsCoin.set(orderBookFilter.getAmount());
|
||||
model.minAmountAsCoin.set(orderBookFilter.getAmount());
|
||||
model.amountAsCoin.set(orderBookInfo.getAmount());
|
||||
model.minAmountAsCoin.set(orderBookInfo.getAmount());
|
||||
}
|
||||
|
||||
// apply only if valid
|
||||
if (orderBookFilter.getPrice() != null && isBtcInputValid(orderBookFilter.getPrice().toPlainString()).isValid)
|
||||
model.priceAsFiat.set(parseToFiatWith2Decimals(orderBookFilter.getPrice().toPlainString()));
|
||||
if (orderBookInfo.getPrice() != null && isBtcInputValid(orderBookInfo.getPrice().toPlainString()).isValid)
|
||||
model.priceAsFiat.set(parseToFiatWith2Decimals(orderBookInfo.getPrice().toPlainString()));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ import io.bitsquare.gui.components.btc.AddressTextField;
|
|||
import io.bitsquare.gui.components.btc.BalanceTextField;
|
||||
import io.bitsquare.gui.main.help.Help;
|
||||
import io.bitsquare.gui.main.help.HelpId;
|
||||
import io.bitsquare.gui.main.trade.OrderBookFilter;
|
||||
import io.bitsquare.gui.main.trade.OrderBookInfo;
|
||||
import io.bitsquare.gui.util.ImageUtil;
|
||||
import io.bitsquare.locale.BSResources;
|
||||
|
||||
|
@ -162,8 +162,8 @@ public class CreateOfferViewCB extends CachedViewCB<CreateOfferPM> {
|
|||
// Public methods (called form other views/CB)
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public void setOrderBookFilter(OrderBookFilter orderBookFilter) {
|
||||
presentationModel.setOrderBookFilter(orderBookFilter);
|
||||
public void setOrderBookFilter(OrderBookInfo orderBookInfo) {
|
||||
presentationModel.setOrderBookFilter(orderBookInfo);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ package io.bitsquare.gui.main.trade.orderbook;
|
|||
|
||||
import io.bitsquare.arbitrator.Arbitrator;
|
||||
import io.bitsquare.bank.BankAccount;
|
||||
import io.bitsquare.gui.main.trade.OrderBookFilter;
|
||||
import io.bitsquare.gui.main.trade.OrderBookInfo;
|
||||
import io.bitsquare.locale.Country;
|
||||
import io.bitsquare.locale.CurrencyUtil;
|
||||
import io.bitsquare.msg.MessageFacade;
|
||||
|
@ -106,12 +106,12 @@ public class OrderBook implements OrderBookListener {
|
|||
tradeManager.removeOffer(offer);
|
||||
}
|
||||
|
||||
public void applyFilter(OrderBookFilter orderBookFilter) {
|
||||
public void applyFilter(OrderBookInfo orderBookInfo) {
|
||||
filteredList.setPredicate(orderBookListItem -> {
|
||||
Offer offer = orderBookListItem.getOffer();
|
||||
BankAccount currentBankAccount = user.getCurrentBankAccount();
|
||||
|
||||
if (orderBookFilter == null || currentBankAccount == null || orderBookFilter.getDirection() == null) {
|
||||
if (orderBookInfo == null || currentBankAccount == null || orderBookInfo.getDirection() == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -128,19 +128,19 @@ public class OrderBook implements OrderBookListener {
|
|||
// Apply applyFilter only if there is a valid value set
|
||||
// The requested amount must be lower or equal then the offer amount
|
||||
boolean amountResult = true;
|
||||
if (orderBookFilter.getAmount() != null)
|
||||
amountResult = orderBookFilter.getAmount().compareTo(offer.getAmount()) <= 0;
|
||||
if (orderBookInfo.getAmount() != null)
|
||||
amountResult = orderBookInfo.getAmount().compareTo(offer.getAmount()) <= 0;
|
||||
|
||||
// The requested trade direction must be opposite of the offerList trade direction
|
||||
boolean directionResult = !orderBookFilter.getDirection().equals(offer.getDirection());
|
||||
boolean directionResult = !orderBookInfo.getDirection().equals(offer.getDirection());
|
||||
|
||||
// Apply applyFilter only if there is a valid value set
|
||||
boolean priceResult = true;
|
||||
if (orderBookFilter.getPrice() != null) {
|
||||
if (orderBookInfo.getPrice() != null) {
|
||||
if (offer.getDirection() == Direction.SELL)
|
||||
priceResult = orderBookFilter.getPrice().compareTo(offer.getPrice()) >= 0;
|
||||
priceResult = orderBookInfo.getPrice().compareTo(offer.getPrice()) >= 0;
|
||||
else
|
||||
priceResult = orderBookFilter.getPrice().compareTo(offer.getPrice()) <= 0;
|
||||
priceResult = orderBookInfo.getPrice().compareTo(offer.getPrice()) <= 0;
|
||||
}
|
||||
|
||||
// The arbitrator defined in the offer must match one of the accepted arbitrators defined in the settings
|
||||
|
|
|
@ -26,7 +26,7 @@ import io.bitsquare.gui.OverlayController;
|
|||
import io.bitsquare.gui.ViewCB;
|
||||
import io.bitsquare.gui.ViewController;
|
||||
import io.bitsquare.gui.components.Popups;
|
||||
import io.bitsquare.gui.main.trade.OrderBookFilter;
|
||||
import io.bitsquare.gui.main.trade.OrderBookInfo;
|
||||
import io.bitsquare.gui.main.trade.createoffer.CreateOfferViewCB;
|
||||
import io.bitsquare.gui.main.trade.takeoffer.TakeOfferController;
|
||||
import io.bitsquare.gui.util.BSFormatter;
|
||||
|
@ -88,7 +88,7 @@ public class OrderBookViewCB extends CachedViewCB<OrderBookPM> {
|
|||
private NavigationController navigationController;
|
||||
private OverlayController overlayController;
|
||||
private final OrderBook orderBook;
|
||||
private final OrderBookFilter orderBookFilter;
|
||||
private OrderBookInfo orderBookInfo;
|
||||
private final User user;
|
||||
private final MessageFacade messageFacade;
|
||||
private final WalletFacade walletFacade;
|
||||
|
@ -130,8 +130,6 @@ public class OrderBookViewCB extends CachedViewCB<OrderBookPM> {
|
|||
this.walletFacade = walletFacade;
|
||||
this.settings = settings;
|
||||
this.persistence = persistence;
|
||||
|
||||
this.orderBookFilter = new OrderBookFilter();
|
||||
}
|
||||
|
||||
|
||||
|
@ -186,11 +184,13 @@ public class OrderBookViewCB extends CachedViewCB<OrderBookPM> {
|
|||
}
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Private
|
||||
// Public methods
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
private void init() {
|
||||
public void initOrderBook(Direction direction, OrderBookInfo orderBookInfo) {
|
||||
this.orderBookInfo = orderBookInfo;
|
||||
orderBook.init();
|
||||
offerList = orderBook.getOfferList();
|
||||
offerList.comparatorProperty().bind(orderBookTable.comparatorProperty());
|
||||
|
@ -202,16 +202,16 @@ public class OrderBookViewCB extends CachedViewCB<OrderBookPM> {
|
|||
|
||||
// handlers
|
||||
amount.textProperty().addListener((observable, oldValue, newValue) -> {
|
||||
orderBookFilter.setAmount(BSFormatter.parseToCoin(newValue));
|
||||
orderBookInfo.setAmount(BSFormatter.parseToCoin(newValue));
|
||||
updateVolume();
|
||||
});
|
||||
|
||||
price.textProperty().addListener((observable, oldValue, newValue) -> {
|
||||
orderBookFilter.setPrice(BSFormatter.parseToFiat(newValue));
|
||||
orderBookInfo.setPrice(BSFormatter.parseToFiat(newValue));
|
||||
updateVolume();
|
||||
});
|
||||
|
||||
orderBookFilter.getDirectionChangedProperty().addListener((observable) -> applyOffers());
|
||||
orderBookInfo.directionProperty().addListener((observable) -> applyOffers());
|
||||
|
||||
user.currentBankAccountProperty().addListener((ov) -> orderBook.loadOffers());
|
||||
|
||||
|
@ -219,18 +219,9 @@ public class OrderBookViewCB extends CachedViewCB<OrderBookPM> {
|
|||
|
||||
//TODO do polling until broadcast works
|
||||
setupPolling();
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Public methods
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public void initOrderBook(Direction direction) {
|
||||
init();
|
||||
orderBookTable.getSelectionModel().clearSelection();
|
||||
price.setText("");
|
||||
orderBookFilter.setDirection(direction);
|
||||
this.orderBookInfo.setDirection(direction);
|
||||
}
|
||||
|
||||
|
||||
|
@ -255,7 +246,7 @@ public class OrderBookViewCB extends CachedViewCB<OrderBookPM> {
|
|||
}
|
||||
|
||||
if (nextController != null)
|
||||
((CreateOfferViewCB) nextController).setOrderBookFilter(orderBookFilter);
|
||||
((CreateOfferViewCB) nextController).setOrderBookFilter(orderBookInfo);
|
||||
}
|
||||
else {
|
||||
openSetupScreen();
|
||||
|
@ -358,9 +349,9 @@ public class OrderBookViewCB extends CachedViewCB<OrderBookPM> {
|
|||
}
|
||||
|
||||
private void applyOffers() {
|
||||
orderBook.applyFilter(orderBookFilter);
|
||||
orderBook.applyFilter(orderBookInfo);
|
||||
|
||||
priceColumn.setSortType((orderBookFilter.getDirection() == Direction.BUY) ?
|
||||
priceColumn.setSortType((orderBookInfo.getDirection() == Direction.BUY) ?
|
||||
TableColumn.SortType.ASCENDING : TableColumn.SortType.DESCENDING);
|
||||
orderBookTable.sort();
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue