mirror of
https://github.com/bisq-network/bisq.git
synced 2025-02-24 23:18:17 +01:00
Move Direction enum to Offer
This commit is contained in:
parent
af5949540d
commit
7750ae6e00
16 changed files with 36 additions and 67 deletions
|
@ -19,7 +19,6 @@ package io.bitsquare.gui.main.portfolio.closed;
|
|||
|
||||
import io.bitsquare.common.viewfx.model.Activatable;
|
||||
import io.bitsquare.common.viewfx.model.DataModel;
|
||||
import io.bitsquare.offer.Direction;
|
||||
import io.bitsquare.offer.Offer;
|
||||
import io.bitsquare.trade.Trade;
|
||||
import io.bitsquare.trade.TradeManager;
|
||||
|
@ -64,7 +63,7 @@ class ClosedTradesDataModel implements Activatable, DataModel {
|
|||
return list;
|
||||
}
|
||||
|
||||
public Direction getDirection(Offer offer) {
|
||||
public Offer.Direction getDirection(Offer offer) {
|
||||
return offer.getP2PSigPubKey().equals(user.getP2PSigPubKey()) ?
|
||||
offer.getDirection() : offer.getMirroredDirection();
|
||||
}
|
||||
|
|
|
@ -21,7 +21,6 @@ import io.bitsquare.common.handlers.ErrorMessageHandler;
|
|||
import io.bitsquare.common.handlers.ResultHandler;
|
||||
import io.bitsquare.common.viewfx.model.Activatable;
|
||||
import io.bitsquare.common.viewfx.model.DataModel;
|
||||
import io.bitsquare.offer.Direction;
|
||||
import io.bitsquare.offer.Offer;
|
||||
import io.bitsquare.trade.Trade;
|
||||
import io.bitsquare.trade.TradeManager;
|
||||
|
@ -75,7 +74,7 @@ class OffersDataModel implements Activatable, DataModel {
|
|||
return list;
|
||||
}
|
||||
|
||||
public Direction getDirection(Offer offer) {
|
||||
public Offer.Direction getDirection(Offer offer) {
|
||||
return offer.getP2PSigPubKey().equals(user.getP2PSigPubKey()) ?
|
||||
offer.getDirection() : offer.getMirroredDirection();
|
||||
}
|
||||
|
|
|
@ -22,7 +22,6 @@ import io.bitsquare.btc.FeePolicy;
|
|||
import io.bitsquare.btc.WalletService;
|
||||
import io.bitsquare.common.viewfx.model.Activatable;
|
||||
import io.bitsquare.common.viewfx.model.DataModel;
|
||||
import io.bitsquare.offer.Direction;
|
||||
import io.bitsquare.offer.Offer;
|
||||
import io.bitsquare.trade.Trade;
|
||||
import io.bitsquare.trade.TradeManager;
|
||||
|
@ -233,7 +232,7 @@ class PendingTradesDataModel implements Activatable, DataModel {
|
|||
return selectedItem.getTrade().getOffer().getCurrency().getCurrencyCode();
|
||||
}
|
||||
|
||||
public Direction getDirection(Offer offer) {
|
||||
public Offer.Direction getDirection(Offer offer) {
|
||||
return offer.getP2PSigPubKey().equals(user.getP2PSigPubKey()) ?
|
||||
offer.getDirection() : offer.getMirroredDirection();
|
||||
}
|
||||
|
|
|
@ -27,7 +27,6 @@ import io.bitsquare.gui.main.MainView;
|
|||
import io.bitsquare.gui.main.trade.createoffer.CreateOfferView;
|
||||
import io.bitsquare.gui.main.trade.offerbook.OfferBookView;
|
||||
import io.bitsquare.gui.main.trade.takeoffer.TakeOfferView;
|
||||
import io.bitsquare.offer.Direction;
|
||||
import io.bitsquare.offer.Offer;
|
||||
|
||||
import org.bitcoinj.core.Coin;
|
||||
|
@ -54,12 +53,12 @@ public abstract class TradeView extends ActivatableView<TabPane, Void> {
|
|||
|
||||
private final ViewLoader viewLoader;
|
||||
private final Navigation navigation;
|
||||
private final Direction direction;
|
||||
private final Offer.Direction direction;
|
||||
|
||||
protected TradeView(ViewLoader viewLoader, Navigation navigation) {
|
||||
this.viewLoader = viewLoader;
|
||||
this.navigation = navigation;
|
||||
this.direction = (this instanceof BuyView) ? Direction.BUY : Direction.SELL;
|
||||
this.direction = (this instanceof BuyView) ? Offer.Direction.BUY : Offer.Direction.SELL;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -120,7 +119,7 @@ public abstract class TradeView extends ActivatableView<TabPane, Void> {
|
|||
if (viewClass == OfferBookView.class && offerBookView == null) {
|
||||
view = viewLoader.load(viewClass);
|
||||
// Offerbook must not be cached by ViewLoader as we use 2 instances for sell and buy screens.
|
||||
final Tab tab = new Tab(direction == Direction.BUY ? "Buy Bitcoin" : "Sell Bitcoin");
|
||||
final Tab tab = new Tab(direction == Offer.Direction.BUY ? "Buy Bitcoin" : "Sell Bitcoin");
|
||||
tab.setClosable(false);
|
||||
tab.setContent(view.getRoot());
|
||||
tabPane.getTabs().add(tab);
|
||||
|
|
|
@ -27,7 +27,7 @@ import io.bitsquare.common.viewfx.model.DataModel;
|
|||
import io.bitsquare.fiat.FiatAccount;
|
||||
import io.bitsquare.gui.util.BSFormatter;
|
||||
import io.bitsquare.locale.Country;
|
||||
import io.bitsquare.offer.Direction;
|
||||
import io.bitsquare.offer.Offer;
|
||||
import io.bitsquare.trade.TradeManager;
|
||||
import io.bitsquare.user.AccountSettings;
|
||||
import io.bitsquare.user.Preferences;
|
||||
|
@ -75,7 +75,7 @@ class CreateOfferDataModel implements Activatable, DataModel {
|
|||
|
||||
private final String offerId;
|
||||
|
||||
@Nullable private Direction direction = null;
|
||||
@Nullable private Offer.Direction direction = null;
|
||||
private AddressEntry addressEntry;
|
||||
|
||||
final StringProperty requestPlaceOfferErrorMessage = new SimpleStringProperty();
|
||||
|
@ -231,12 +231,12 @@ class CreateOfferDataModel implements Activatable, DataModel {
|
|||
|
||||
|
||||
@Nullable
|
||||
Direction getDirection() {
|
||||
Offer.Direction getDirection() {
|
||||
return direction;
|
||||
}
|
||||
|
||||
@SuppressWarnings("NullableProblems")
|
||||
void setDirection(Direction direction) {
|
||||
void setDirection(Offer.Direction direction) {
|
||||
// direction can not be changed once it is initially set
|
||||
checkNotNull(direction);
|
||||
this.direction = direction;
|
||||
|
|
|
@ -38,7 +38,7 @@ import io.bitsquare.gui.main.portfolio.pending.PendingTradesView;
|
|||
import io.bitsquare.gui.main.trade.TradeView;
|
||||
import io.bitsquare.gui.util.ImageUtil;
|
||||
import io.bitsquare.locale.BSResources;
|
||||
import io.bitsquare.offer.Direction;
|
||||
import io.bitsquare.offer.Offer;
|
||||
|
||||
import org.bitcoinj.core.Coin;
|
||||
import org.bitcoinj.utils.Fiat;
|
||||
|
@ -126,10 +126,10 @@ public class CreateOfferView extends ActivatableViewAndModel<AnchorPane, CreateO
|
|||
|
||||
}
|
||||
|
||||
public void initWithData(Direction direction, Coin amount, Fiat price) {
|
||||
public void initWithData(Offer.Direction direction, Coin amount, Fiat price) {
|
||||
model.initWithData(direction, amount, price);
|
||||
|
||||
if (direction == Direction.BUY)
|
||||
if (direction == Offer.Direction.BUY)
|
||||
imageView.setId("image-buy-large");
|
||||
else
|
||||
imageView.setId("image-sell-large");
|
||||
|
|
|
@ -25,7 +25,7 @@ import io.bitsquare.gui.util.validation.BtcValidator;
|
|||
import io.bitsquare.gui.util.validation.FiatValidator;
|
||||
import io.bitsquare.gui.util.validation.InputValidator;
|
||||
import io.bitsquare.locale.BSResources;
|
||||
import io.bitsquare.offer.Direction;
|
||||
import io.bitsquare.offer.Offer;
|
||||
|
||||
import org.bitcoinj.core.Address;
|
||||
import org.bitcoinj.core.Coin;
|
||||
|
@ -112,9 +112,9 @@ class CreateOfferViewModel extends ActivatableWithDataModel<CreateOfferDataModel
|
|||
}
|
||||
|
||||
// setOfferBookFilter is a one time call
|
||||
void initWithData(Direction direction, Coin amount, Fiat price) {
|
||||
void initWithData(Offer.Direction direction, Coin amount, Fiat price) {
|
||||
dataModel.setDirection(direction);
|
||||
directionLabel.set(dataModel.getDirection() == Direction.BUY ? BSResources.get("shared.buy") : BSResources.get
|
||||
directionLabel.set(dataModel.getDirection() == Offer.Direction.BUY ? BSResources.get("shared.buy") : BSResources.get
|
||||
("shared.sell"));
|
||||
|
||||
// apply only if valid
|
||||
|
|
|
@ -25,7 +25,6 @@ import io.bitsquare.fiat.FiatAccount;
|
|||
import io.bitsquare.gui.util.BSFormatter;
|
||||
import io.bitsquare.locale.Country;
|
||||
import io.bitsquare.locale.CurrencyUtil;
|
||||
import io.bitsquare.offer.Direction;
|
||||
import io.bitsquare.offer.Offer;
|
||||
import io.bitsquare.offer.OfferBook;
|
||||
import io.bitsquare.trade.TradeManager;
|
||||
|
@ -75,7 +74,7 @@ class OfferBookDataModel implements Activatable, DataModel {
|
|||
final StringProperty fiatCode = new SimpleStringProperty();
|
||||
final StringProperty btcCode = new SimpleStringProperty();
|
||||
final ObjectProperty<Country> bankAccountCountry = new SimpleObjectProperty<>();
|
||||
private Direction direction;
|
||||
private Offer.Direction direction;
|
||||
|
||||
|
||||
@Inject
|
||||
|
@ -184,7 +183,7 @@ class OfferBookDataModel implements Activatable, DataModel {
|
|||
}
|
||||
|
||||
|
||||
void setDirection(Direction direction) {
|
||||
void setDirection(Offer.Direction direction) {
|
||||
this.direction = direction;
|
||||
}
|
||||
|
||||
|
@ -240,7 +239,7 @@ class OfferBookDataModel implements Activatable, DataModel {
|
|||
return volumeAsFiat;
|
||||
}
|
||||
|
||||
Direction getDirection() {
|
||||
Offer.Direction getDirection() {
|
||||
return direction;
|
||||
}
|
||||
|
||||
|
@ -268,7 +267,7 @@ class OfferBookDataModel implements Activatable, DataModel {
|
|||
|
||||
boolean priceResult = true;
|
||||
if (priceAsFiat.get() != null && priceAsFiat.get().isPositive()) {
|
||||
if (offer.getDirection() == Direction.SELL)
|
||||
if (offer.getDirection() == Offer.Direction.SELL)
|
||||
priceResult = priceAsFiat.get().compareTo(offer.getPrice()) >= 0;
|
||||
else
|
||||
priceResult = priceAsFiat.get().compareTo(offer.getPrice()) <= 0;
|
||||
|
|
|
@ -33,7 +33,6 @@ import io.bitsquare.gui.util.ImageUtil;
|
|||
import io.bitsquare.gui.util.validation.OptionalBtcValidator;
|
||||
import io.bitsquare.gui.util.validation.OptionalFiatValidator;
|
||||
import io.bitsquare.locale.BSResources;
|
||||
import io.bitsquare.offer.Direction;
|
||||
import io.bitsquare.offer.Offer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -141,7 +140,7 @@ public class OfferBookView extends ActivatableViewAndModel<GridPane, OfferBookVi
|
|||
SortedList<OfferBookListItem> offerList = model.getOfferList();
|
||||
table.setItems(offerList);
|
||||
offerList.comparatorProperty().bind(table.comparatorProperty());
|
||||
priceColumn.setSortType((model.getDirection() == Direction.BUY) ?
|
||||
priceColumn.setSortType((model.getDirection() == Offer.Direction.BUY) ?
|
||||
TableColumn.SortType.ASCENDING : TableColumn.SortType.DESCENDING);
|
||||
table.sort();
|
||||
|
||||
|
@ -160,7 +159,7 @@ public class OfferBookView extends ActivatableViewAndModel<GridPane, OfferBookVi
|
|||
createOfferButton.setDisable(false);
|
||||
}
|
||||
|
||||
public void setDirection(Direction direction) {
|
||||
public void setDirection(Offer.Direction direction) {
|
||||
model.setDirection(direction);
|
||||
}
|
||||
|
||||
|
@ -224,7 +223,7 @@ public class OfferBookView extends ActivatableViewAndModel<GridPane, OfferBookVi
|
|||
|
||||
private void takeOffer(Offer offer) {
|
||||
if (model.isRegistered()) {
|
||||
if (offer.getDirection() == Direction.BUY) {
|
||||
if (offer.getDirection() == Offer.Direction.BUY) {
|
||||
offerActionHandler.takeOffer(model.getAmountAsCoin(), model.getPriceAsCoin(), offer);
|
||||
}
|
||||
else {
|
||||
|
@ -474,7 +473,7 @@ public class OfferBookView extends ActivatableViewAndModel<GridPane, OfferBookVi
|
|||
button.setOnAction(event -> model.cancelOpenOffer(item.getOffer()));
|
||||
}
|
||||
else {
|
||||
if (offer.getDirection() == Direction.SELL)
|
||||
if (offer.getDirection() == Offer.Direction.SELL)
|
||||
iconView.setId("image-buy");
|
||||
else
|
||||
iconView.setId("image-sell");
|
||||
|
|
|
@ -25,7 +25,6 @@ import io.bitsquare.gui.util.validation.InputValidator;
|
|||
import io.bitsquare.gui.util.validation.OptionalBtcValidator;
|
||||
import io.bitsquare.gui.util.validation.OptionalFiatValidator;
|
||||
import io.bitsquare.locale.BSResources;
|
||||
import io.bitsquare.offer.Direction;
|
||||
import io.bitsquare.offer.Offer;
|
||||
|
||||
import org.bitcoinj.core.Coin;
|
||||
|
@ -120,7 +119,7 @@ class OfferBookViewModel extends ActivatableWithDataModel<OfferBookDataModel> im
|
|||
}
|
||||
|
||||
|
||||
void setDirection(Direction direction) {
|
||||
void setDirection(Offer.Direction direction) {
|
||||
dataModel.setDirection(direction);
|
||||
}
|
||||
|
||||
|
@ -159,7 +158,7 @@ class OfferBookViewModel extends ActivatableWithDataModel<OfferBookDataModel> im
|
|||
return formatter.formatDirection(offer.getMirroredDirection());
|
||||
}
|
||||
|
||||
Direction getDirection() {
|
||||
Offer.Direction getDirection() {
|
||||
return dataModel.getDirection();
|
||||
}
|
||||
|
||||
|
|
|
@ -36,7 +36,6 @@ import io.bitsquare.gui.main.portfolio.pending.PendingTradesView;
|
|||
import io.bitsquare.gui.main.trade.TradeView;
|
||||
import io.bitsquare.gui.util.ImageUtil;
|
||||
import io.bitsquare.locale.BSResources;
|
||||
import io.bitsquare.offer.Direction;
|
||||
import io.bitsquare.offer.Offer;
|
||||
|
||||
import org.bitcoinj.core.Coin;
|
||||
|
@ -119,10 +118,10 @@ public class TakeOfferView extends ActivatableViewAndModel<AnchorPane, TakeOffer
|
|||
model.errorMessage.removeListener(errorMessageChangeListener);
|
||||
}
|
||||
|
||||
public void initWithData(Direction direction, Coin amount, Offer offer) {
|
||||
public void initWithData(Offer.Direction direction, Coin amount, Offer offer) {
|
||||
model.initWithData(direction, amount, offer);
|
||||
|
||||
if (direction == Direction.BUY)
|
||||
if (direction == Offer.Direction.BUY)
|
||||
imageView.setId("image-buy-large");
|
||||
else
|
||||
imageView.setId("image-sell-large");
|
||||
|
|
|
@ -24,7 +24,6 @@ import io.bitsquare.gui.util.BSFormatter;
|
|||
import io.bitsquare.gui.util.validation.BtcValidator;
|
||||
import io.bitsquare.gui.util.validation.InputValidator;
|
||||
import io.bitsquare.locale.BSResources;
|
||||
import io.bitsquare.offer.Direction;
|
||||
import io.bitsquare.offer.Offer;
|
||||
|
||||
import org.bitcoinj.core.Address;
|
||||
|
@ -115,10 +114,10 @@ class TakeOfferViewModel extends ActivatableWithDataModel<TakeOfferDataModel> im
|
|||
}
|
||||
|
||||
// setOfferBookFilter is a one time call
|
||||
void initWithData(Direction direction, Coin amount, Offer offer) {
|
||||
void initWithData(Offer.Direction direction, Coin amount, Offer offer) {
|
||||
dataModel.initWithData(amount, offer);
|
||||
|
||||
directionLabel = direction == Direction.BUY ?
|
||||
directionLabel = direction == Offer.Direction.BUY ?
|
||||
BSResources.get("shared.buy") : BSResources.get("shared.sell");
|
||||
|
||||
fiatCode = offer.getCurrency().getCurrencyCode();
|
||||
|
|
|
@ -21,7 +21,6 @@ import io.bitsquare.arbitration.Arbitrator;
|
|||
import io.bitsquare.locale.BSResources;
|
||||
import io.bitsquare.locale.Country;
|
||||
import io.bitsquare.locale.CurrencyUtil;
|
||||
import io.bitsquare.offer.Direction;
|
||||
import io.bitsquare.offer.Offer;
|
||||
import io.bitsquare.user.User;
|
||||
|
||||
|
@ -288,12 +287,12 @@ public class BSFormatter {
|
|||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
public String formatDirection(Direction direction) {
|
||||
public String formatDirection(Offer.Direction direction) {
|
||||
return formatDirection(direction, true);
|
||||
}
|
||||
|
||||
public String formatDirection(Direction direction, boolean allUpperCase) {
|
||||
String result = (direction == Direction.BUY) ? "Buy" : "Sell";
|
||||
public String formatDirection(Offer.Direction direction, boolean allUpperCase) {
|
||||
String result = (direction == Offer.Direction.BUY) ? "Buy" : "Sell";
|
||||
if (allUpperCase) {
|
||||
result = result.toUpperCase();
|
||||
}
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
/*
|
||||
* This file is part of Bitsquare.
|
||||
*
|
||||
* Bitsquare is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* Bitsquare is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package io.bitsquare.offer;
|
||||
|
||||
public enum Direction {
|
||||
BUY, SELL
|
||||
}
|
|
@ -47,6 +47,8 @@ public class Offer implements Serializable {
|
|||
private static final long serialVersionUID = -971164804305475826L;
|
||||
private transient static final Logger log = LoggerFactory.getLogger(Offer.class);
|
||||
|
||||
public enum Direction {BUY, SELL}
|
||||
|
||||
public enum State {
|
||||
UNKNOWN,
|
||||
AVAILABLE,
|
||||
|
|
|
@ -24,7 +24,6 @@ import io.bitsquare.common.handlers.ResultHandler;
|
|||
import io.bitsquare.crypto.EncryptionService;
|
||||
import io.bitsquare.crypto.SignatureService;
|
||||
import io.bitsquare.fiat.FiatAccount;
|
||||
import io.bitsquare.offer.Direction;
|
||||
import io.bitsquare.offer.Offer;
|
||||
import io.bitsquare.offer.OfferBookService;
|
||||
import io.bitsquare.p2p.AddressService;
|
||||
|
@ -156,7 +155,7 @@ public class TradeManager {
|
|||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public void placeOffer(String id,
|
||||
Direction direction,
|
||||
Offer.Direction direction,
|
||||
Fiat price,
|
||||
Coin amount,
|
||||
Coin minAmount,
|
||||
|
|
Loading…
Add table
Reference in a new issue