mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-03-15 10:26:37 -04:00
Fix width problem with info component
This commit is contained in:
parent
30751b017b
commit
02b82b63ef
@ -50,7 +50,7 @@ You can generate coins on demand with the Bitcoin QT client with the following c
|
||||
**setgenerate true 101**
|
||||
101 is used only for the first start because of the coin maturity of 100 blocks. Later for mining of a single block you can use 1 as number of blocks to be created.
|
||||
|
||||
More information about the regtest mode can be found [here](https://bitcoinj.github.io/testing).
|
||||
More information about the regtest mode can be found [here](https://bitcoinj.github.io/testing) or [here](https://bitcoin.org/en/developer-examples#regtest-mode).
|
||||
|
||||
The network mode is defined in the guice module (BitSquareModule) and is default set to regtest.
|
||||
Testnet should also work, but was not tested for a while as for developing regtest is much more convenient.
|
||||
|
@ -205,6 +205,10 @@ textfield */
|
||||
-fx-font-size: 14;
|
||||
}
|
||||
|
||||
#non-clickable-icon {
|
||||
-fx-text-fill: #AAAAAA;
|
||||
}
|
||||
|
||||
#clickable-icon {
|
||||
-fx-text-fill: -bs-theme-color;
|
||||
-fx-cursor: hand;
|
||||
|
@ -20,24 +20,25 @@ package io.bitsquare.gui.components;
|
||||
import io.bitsquare.locale.BSResources;
|
||||
|
||||
import javafx.application.Platform;
|
||||
import javafx.beans.property.DoubleProperty;
|
||||
import javafx.beans.property.IntegerProperty;
|
||||
import javafx.beans.property.ObjectProperty;
|
||||
import javafx.beans.property.SimpleDoubleProperty;
|
||||
import javafx.beans.property.SimpleIntegerProperty;
|
||||
import javafx.beans.property.SimpleObjectProperty;
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
import javafx.beans.property.StringProperty;
|
||||
import javafx.beans.value.ChangeListener;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.event.EventHandler;
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.geometry.VPos;
|
||||
import javafx.scene.*;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.image.*;
|
||||
import javafx.scene.layout.*;
|
||||
import javafx.scene.text.*;
|
||||
|
||||
import de.jensd.fx.fontawesome.AwesomeDude;
|
||||
import de.jensd.fx.fontawesome.AwesomeIcon;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -53,13 +54,12 @@ public class InfoDisplay extends Parent {
|
||||
private final StringProperty text = new SimpleStringProperty();
|
||||
private final IntegerProperty rowIndex = new SimpleIntegerProperty(0);
|
||||
private final IntegerProperty columnIndex = new SimpleIntegerProperty(0);
|
||||
private final DoubleProperty prefWidth = new SimpleDoubleProperty(740);
|
||||
private final ObjectProperty<EventHandler<ActionEvent>> onAction = new SimpleObjectProperty<>();
|
||||
private final ObjectProperty<GridPane> gridPane = new SimpleObjectProperty<>();
|
||||
|
||||
private boolean useReadMore;
|
||||
|
||||
private final ImageView icon;
|
||||
private final Label icon = AwesomeDude.createIconLabel(AwesomeIcon.INFO_SIGN);
|
||||
private final TextFlow textFlow;
|
||||
private final Label label;
|
||||
private final Hyperlink link;
|
||||
@ -70,21 +70,18 @@ public class InfoDisplay extends Parent {
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public InfoDisplay() {
|
||||
|
||||
icon = new ImageView();
|
||||
icon.setId("image-info");
|
||||
icon.setPickOnBounds(true);
|
||||
icon.setPreserveRatio(true);
|
||||
icon.setId("non-clickable-icon");
|
||||
icon.visibleProperty().bind(visibleProperty());
|
||||
|
||||
GridPane.setValignment(icon, VPos.TOP);
|
||||
GridPane.setMargin(icon, new Insets(4, 2, 0, 0));
|
||||
GridPane.setMargin(icon, new Insets(-2, 0, 0, 0));
|
||||
GridPane.setRowSpan(icon, 2);
|
||||
|
||||
label = new Label();
|
||||
label.textProperty().bind(text);
|
||||
label.prefWidthProperty().bind(prefWidth);
|
||||
label.setTextOverrun(OverrunStyle.WORD_ELLIPSIS);
|
||||
// width is set a frame later so we hide it first
|
||||
label.setVisible(false);
|
||||
|
||||
link = new Hyperlink(BSResources.get("shared.readMore"));
|
||||
link.setPadding(new Insets(0, 0, 0, -2));
|
||||
@ -109,6 +106,11 @@ public class InfoDisplay extends Parent {
|
||||
Platform.runLater(() -> textFlow.getChildren().setAll(label, link));
|
||||
});
|
||||
|
||||
// update the width when the window gets resized
|
||||
ChangeListener<Number> listener = (ov2, oldValue2, windowWidth) ->
|
||||
label.setPrefWidth((double) windowWidth - localToScene(0, 0).getX() - 35);
|
||||
|
||||
|
||||
// when clicking "Read more..." we expand and change the link to the Help
|
||||
link.setOnAction(new EventHandler<ActionEvent>() {
|
||||
@Override
|
||||
@ -117,6 +119,8 @@ public class InfoDisplay extends Parent {
|
||||
|
||||
label.setWrapText(true);
|
||||
link.setText(BSResources.get("shared.openHelp"));
|
||||
getScene().getWindow().widthProperty().removeListener(listener);
|
||||
label.prefWidthProperty().unbind();
|
||||
label.prefWidthProperty().bind(textFlow.widthProperty());
|
||||
link.setVisited(false);
|
||||
// focus border is a bit confusing here so we remove it
|
||||
@ -128,6 +132,18 @@ public class InfoDisplay extends Parent {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
sceneProperty().addListener((ov, oldValue, newValue) -> {
|
||||
if (oldValue == null && newValue != null) {
|
||||
newValue.getWindow().widthProperty().addListener(listener);
|
||||
// localToScene does deliver 0 instead of the correct x position when scene propery gets set,
|
||||
// so we delay for 1 render cycle
|
||||
Platform.runLater(() -> {
|
||||
label.setVisible(true);
|
||||
label.setPrefWidth(newValue.getWindow().getWidth() - localToScene(0, 0).getX() - 35);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -139,11 +155,6 @@ public class InfoDisplay extends Parent {
|
||||
this.text.set(text);
|
||||
}
|
||||
|
||||
public void setPrefWidth(double prefWidth) {
|
||||
this.prefWidth.set(prefWidth);
|
||||
// label.setPrefWidth(getPrefWidth());
|
||||
}
|
||||
|
||||
public void setGridPane(GridPane gridPane) {
|
||||
this.gridPane.set(gridPane);
|
||||
|
||||
@ -188,14 +199,6 @@ public class InfoDisplay extends Parent {
|
||||
return text;
|
||||
}
|
||||
|
||||
public double getPrefWidth() {
|
||||
return prefWidth.get();
|
||||
}
|
||||
|
||||
public DoubleProperty prefWidthProperty() {
|
||||
return prefWidth;
|
||||
}
|
||||
|
||||
public int getColumnIndex() {
|
||||
return columnIndex.get();
|
||||
}
|
||||
|
@ -59,7 +59,7 @@
|
||||
</GridPane.margin>
|
||||
</HBox>
|
||||
|
||||
<InfoDisplay gridPane="$root" onAction="#onOpenHelp" rowIndex="4" prefWidth="570"
|
||||
<InfoDisplay gridPane="$root" onAction="#onOpenHelp" rowIndex="4"
|
||||
text="Protect your wallet with a strong password. You need to enter the password any time you withdraw Bitcoin from your trading wallets. You can change the password later in the settings. Open the help menu for more information."/>
|
||||
|
||||
<columnConstraints>
|
||||
|
@ -72,7 +72,7 @@
|
||||
visible="false" prefWidth="150.0"/>
|
||||
</HBox>
|
||||
|
||||
<InfoDisplay gridPane="$root" onAction="#onOpenSetupHelp" rowIndex="7" prefWidth="510"
|
||||
<InfoDisplay gridPane="$root" onAction="#onOpenSetupHelp" rowIndex="7"
|
||||
text="The payments account data will be saved in a encrypted form to the Bitcoin block chain and will be used in the trade process for account verification."/>
|
||||
|
||||
<HBox fx:id="buttonsHBox" GridPane.columnIndex="1" GridPane.rowIndex="8" spacing="10">
|
||||
@ -111,7 +111,7 @@
|
||||
<Button fx:id="removeBankAccountButton" text="Remove selected payments account" onAction="#onRemoveAccount"
|
||||
GridPane.columnIndex="1" GridPane.rowIndex="10" disable="true"/>
|
||||
|
||||
<InfoDisplay gridPane="$root" onAction="#onOpenManageAccountsHelp" rowIndex="11" prefWidth="510"
|
||||
<InfoDisplay gridPane="$root" onAction="#onOpenManageAccountsHelp" rowIndex="11"
|
||||
text="When you change your payments accounts later you need to do the renew the registration and pay the small registration fee."/>
|
||||
|
||||
<columnConstraints>
|
||||
|
@ -54,7 +54,7 @@
|
||||
</GridPane.margin>
|
||||
</HBox>
|
||||
|
||||
<InfoDisplay gridPane="$root" onAction="#onOpenHelp" rowIndex="3" prefWidth="570"
|
||||
<InfoDisplay gridPane="$root" onAction="#onOpenHelp" rowIndex="3"
|
||||
text="Protect your wallet with a strong password. You need to enter the password any time you withdraw Bitcoin from your trading wallets. You can change the password later in the settings. Open the help menu for more information."/>
|
||||
|
||||
<columnConstraints>
|
||||
|
@ -62,7 +62,7 @@
|
||||
</GridPane.margin>
|
||||
</BalanceTextField>
|
||||
|
||||
<InfoDisplay gridPane="$root" onAction="#onOpenHelp" rowIndex="3" prefWidth="570"
|
||||
<InfoDisplay gridPane="$root" onAction="#onOpenHelp" rowIndex="3"
|
||||
text="You need to pay a tiny registration fee which is needed for storing your encrypted account data in the blockchain. That will be used in the trade process for account verification."/>
|
||||
|
||||
<Button fx:id="payButton" text="Pay registration fee" onAction="#onPayFee" GridPane.columnIndex="1"
|
||||
|
@ -43,7 +43,7 @@
|
||||
prefWidth="150.0"/>
|
||||
|
||||
|
||||
<InfoDisplay gridPane="$root" onAction="#onOpenLanguagesHelp" rowIndex="2" prefWidth="570"
|
||||
<InfoDisplay gridPane="$root" onAction="#onOpenLanguagesHelp" rowIndex="2"
|
||||
text="Trade with users who have at least 1 shared language."/>
|
||||
|
||||
<!--
|
||||
@ -79,7 +79,7 @@
|
||||
prefWidth="150.0" visible="false"/>
|
||||
</HBox>
|
||||
|
||||
<InfoDisplay gridPane="$root" onAction="#onOpenCountriesHelp" rowIndex="5" prefWidth="570"
|
||||
<InfoDisplay gridPane="$root" onAction="#onOpenCountriesHelp" rowIndex="5"
|
||||
text="Restrict trades with these payments account countries."/>
|
||||
|
||||
|
||||
@ -107,7 +107,7 @@
|
||||
<Button text="Add arbitrator" onAction="#onOpenArbitratorScreen" GridPane.columnIndex="1"
|
||||
GridPane.rowIndex="7"/>
|
||||
|
||||
<InfoDisplay gridPane="$root" onAction="#onOpenArbitratorsHelp" rowIndex="8" prefWidth="570"
|
||||
<InfoDisplay gridPane="$root" onAction="#onOpenArbitratorsHelp" rowIndex="8"
|
||||
text="You need to choose at least 3 arbitrators."/>
|
||||
|
||||
<Button fx:id="completedButton" text="Completed" onAction="#onCompleted" disable="true" GridPane.columnIndex="1"
|
||||
|
@ -49,7 +49,7 @@
|
||||
<Insets bottom="5"/>
|
||||
</GridPane.margin>
|
||||
</Button>
|
||||
<InfoDisplay gridPane="$root" onAction="#onOpenHelp" rowIndex="3" prefWidth="570"
|
||||
<InfoDisplay gridPane="$root" onAction="#onOpenHelp" rowIndex="3"
|
||||
text="You can recreate your wallet our of these words when you lose your wallet. Backup it on paper to have better protection against online theft. Open the help menu for more information."/>
|
||||
|
||||
<columnConstraints>
|
||||
|
@ -1,102 +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.gui.main.trade;
|
||||
|
||||
import io.bitsquare.trade.Direction;
|
||||
import io.bitsquare.trade.Offer;
|
||||
|
||||
import com.google.bitcoin.core.Coin;
|
||||
import com.google.bitcoin.utils.Fiat;
|
||||
|
||||
import javafx.beans.property.ObjectProperty;
|
||||
import javafx.beans.property.SimpleObjectProperty;
|
||||
|
||||
/**
|
||||
* Holds shared data between the different trade UIs
|
||||
*/
|
||||
public class OrderBookInfo {
|
||||
|
||||
private final ObjectProperty<Direction> direction = new SimpleObjectProperty<>();
|
||||
private Coin amount;
|
||||
private Fiat price;
|
||||
private Fiat volume;
|
||||
|
||||
|
||||
private Offer offer;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Constructor
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public OrderBookInfo() {
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Setters
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public void setAmount(Coin amount) {
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
public void setPrice(Fiat price) {
|
||||
this.price = price;
|
||||
}
|
||||
|
||||
public void setVolume(Fiat volume) {
|
||||
this.volume = volume;
|
||||
}
|
||||
|
||||
public void setDirection(Direction direction) {
|
||||
this.direction.set(direction);
|
||||
}
|
||||
|
||||
public Offer getOffer() {
|
||||
return offer;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Getters
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public Coin getAmount() {
|
||||
return amount;
|
||||
}
|
||||
|
||||
public Fiat getPrice() {
|
||||
return price;
|
||||
}
|
||||
|
||||
public Fiat getVolume() {
|
||||
return volume;
|
||||
}
|
||||
|
||||
public Direction getDirection() {
|
||||
return direction.get();
|
||||
}
|
||||
|
||||
public ObjectProperty<Direction> directionProperty() {
|
||||
return direction;
|
||||
}
|
||||
|
||||
public void setOffer(Offer offer) {
|
||||
this.offer = offer;
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* 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.gui.main.trade;
|
||||
|
||||
import io.bitsquare.trade.Offer;
|
||||
|
||||
import com.google.bitcoin.core.Coin;
|
||||
import com.google.bitcoin.utils.Fiat;
|
||||
|
||||
public interface TradeNavigator {
|
||||
void createOffer(Coin amount, Fiat price);
|
||||
|
||||
void takeOffer(Coin amount, Fiat price, Offer offer);
|
||||
}
|
@ -24,8 +24,12 @@ import io.bitsquare.gui.main.trade.createoffer.CreateOfferViewCB;
|
||||
import io.bitsquare.gui.main.trade.orderbook.OrderBookViewCB;
|
||||
import io.bitsquare.gui.main.trade.takeoffer.TakeOfferViewCB;
|
||||
import io.bitsquare.trade.Direction;
|
||||
import io.bitsquare.trade.Offer;
|
||||
import io.bitsquare.util.ViewLoader;
|
||||
|
||||
import com.google.bitcoin.core.Coin;
|
||||
import com.google.bitcoin.utils.Fiat;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import java.net.URL;
|
||||
@ -42,10 +46,10 @@ import javafx.scene.control.*;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class TradeViewCB extends CachedViewCB {
|
||||
public class TradeViewCB extends CachedViewCB implements TradeNavigator {
|
||||
private static final Logger log = LoggerFactory.getLogger(TradeViewCB.class);
|
||||
|
||||
private final OrderBookInfo orderBookInfo = new OrderBookInfo();
|
||||
// private final OrderBookInfo orderBookInfo = new OrderBookInfo();
|
||||
private OrderBookViewCB orderBookViewCB;
|
||||
private CreateOfferViewCB createOfferViewCB;
|
||||
private TakeOfferViewCB takeOfferViewCB;
|
||||
@ -54,6 +58,10 @@ public class TradeViewCB extends CachedViewCB {
|
||||
private Navigation navigation;
|
||||
private Navigation.Listener listener;
|
||||
private Navigation.Item navigationItem;
|
||||
private Direction direction;
|
||||
private Coin amount;
|
||||
private Fiat price;
|
||||
private Offer offer;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -79,8 +87,8 @@ public class TradeViewCB extends CachedViewCB {
|
||||
}
|
||||
};
|
||||
|
||||
Direction direction = (this instanceof BuyViewCB) ? Direction.BUY : Direction.SELL;
|
||||
orderBookInfo.setDirection(direction);
|
||||
direction = (this instanceof BuyViewCB) ? Direction.BUY : Direction.SELL;
|
||||
// orderBookInfo.setDirection(direction);
|
||||
navigationItem = (direction == Direction.BUY) ? Navigation.Item.BUY : Navigation.Item.SELL;
|
||||
|
||||
super.initialize(url, rb);
|
||||
@ -102,8 +110,11 @@ public class TradeViewCB extends CachedViewCB {
|
||||
tabPane.getTabs().addListener((ListChangeListener<Tab>) change -> {
|
||||
change.next();
|
||||
List<? extends Tab> removedTabs = change.getRemoved();
|
||||
if (removedTabs.size() == 1 && removedTabs.get(0).getContent().equals(createOfferView)) {
|
||||
onCreateOfferViewRemoved();
|
||||
if (removedTabs.size() == 1) {
|
||||
if (removedTabs.get(0).getContent().equals(createOfferView))
|
||||
onCreateOfferViewRemoved();
|
||||
else if (removedTabs.get(0).getContent().equals(takeOfferView))
|
||||
onTakeOfferViewRemoved();
|
||||
}
|
||||
});
|
||||
|
||||
@ -124,6 +135,28 @@ public class TradeViewCB extends CachedViewCB {
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// TradeNavigator implementation
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@Override
|
||||
public void createOffer(Coin amount, Fiat price) {
|
||||
this.amount = amount;
|
||||
this.price = price;
|
||||
navigation.navigationTo(Navigation.Item.MAIN, navigationItem,
|
||||
Navigation.Item.CREATE_OFFER);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void takeOffer(Coin amount, Fiat price, Offer offer) {
|
||||
this.amount = amount;
|
||||
this.price = price;
|
||||
this.offer = offer;
|
||||
navigation.navigationTo(Navigation.Item.MAIN, navigationItem,
|
||||
Navigation.Item.TAKE_OFFER);
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Navigation
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -144,7 +177,8 @@ public class TradeViewCB extends CachedViewCB {
|
||||
tabPane.getTabs().add(tab);
|
||||
orderBookViewCB = orderBookLoader.getController();
|
||||
orderBookViewCB.setParent(this);
|
||||
orderBookViewCB.setOrderBookInfo(orderBookInfo);
|
||||
|
||||
orderBookViewCB.setDirection(direction);
|
||||
// orderBookViewCB.setNavigationListener(n -> loadView(n));
|
||||
|
||||
return orderBookViewCB;
|
||||
@ -160,7 +194,7 @@ public class TradeViewCB extends CachedViewCB {
|
||||
createOfferView = loader.load();
|
||||
createOfferViewCB = loader.getController();
|
||||
createOfferViewCB.setParent(this);
|
||||
createOfferViewCB.initWithOrderBookInfo(orderBookInfo);
|
||||
createOfferViewCB.initWithData(direction, amount, price);
|
||||
createOfferViewCB.setCloseListener(this::onCreateOfferViewRemoved);
|
||||
final Tab tab = new Tab("Create offer");
|
||||
tab.setContent(createOfferView);
|
||||
@ -172,7 +206,7 @@ public class TradeViewCB extends CachedViewCB {
|
||||
}
|
||||
}
|
||||
else if (navigationItem == Navigation.Item.TAKE_OFFER && takeOfferViewCB == null &&
|
||||
orderBookInfo.getOffer() != null) {
|
||||
offer != null) {
|
||||
// CreateOffer and TakeOffer must not be cached by ViewLoader as we cannot use a view multiple times
|
||||
// in different graphs
|
||||
ViewLoader loader = new ViewLoader(getClass().getResource(Navigation.Item.TAKE_OFFER.getFxmlUrl()), false);
|
||||
@ -180,7 +214,8 @@ public class TradeViewCB extends CachedViewCB {
|
||||
takeOfferView = loader.load();
|
||||
takeOfferViewCB = loader.getController();
|
||||
takeOfferViewCB.setParent(this);
|
||||
takeOfferViewCB.initWithOrderBookInfo(orderBookInfo);
|
||||
takeOfferViewCB.initWithData(direction, amount, offer);
|
||||
takeOfferViewCB.setCloseListener(this::onCreateOfferViewRemoved);
|
||||
final Tab tab = new Tab("Take offer");
|
||||
tab.setContent(takeOfferView);
|
||||
tabPane.getTabs().add(tab);
|
||||
@ -201,23 +236,25 @@ public class TradeViewCB extends CachedViewCB {
|
||||
// Public
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//TODO takeOfferController is not updated yet to new UI pattern
|
||||
public void onTakeOfferViewRemoved() {
|
||||
takeOfferViewCB = null;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Private
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
private void onCreateOfferViewRemoved() {
|
||||
if (createOfferViewCB != null)
|
||||
createOfferViewCB = null;
|
||||
createOfferViewCB = null;
|
||||
orderBookViewCB.enableCreateOfferButton();
|
||||
|
||||
// update the navigation state
|
||||
navigation.navigationTo(Navigation.Item.MAIN, navigationItem, Navigation.Item.ORDER_BOOK);
|
||||
}
|
||||
|
||||
private void onTakeOfferViewRemoved() {
|
||||
takeOfferViewCB = null;
|
||||
|
||||
// update the navigation state
|
||||
navigation.navigationTo(Navigation.Item.MAIN, navigationItem, Navigation.Item.ORDER_BOOK);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,6 @@ package io.bitsquare.gui.main.trade.createoffer;
|
||||
|
||||
import io.bitsquare.btc.WalletFacade;
|
||||
import io.bitsquare.gui.PresentationModel;
|
||||
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;
|
||||
@ -29,6 +28,7 @@ import io.bitsquare.trade.Direction;
|
||||
|
||||
import com.google.bitcoin.core.Address;
|
||||
import com.google.bitcoin.core.Coin;
|
||||
import com.google.bitcoin.utils.Fiat;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
@ -41,8 +41,6 @@ import javafx.beans.property.SimpleObjectProperty;
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
import javafx.beans.property.StringProperty;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -154,21 +152,21 @@ class CreateOfferPM extends PresentationModel<CreateOfferModel> {
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// setOrderBookFilter is a one time call
|
||||
void setOrderBookInfo(@NotNull OrderBookInfo orderBookInfo) {
|
||||
model.setDirection(orderBookInfo.getDirection());
|
||||
void initWithData(Direction direction, Coin amount, Fiat price) {
|
||||
model.setDirection(direction);
|
||||
directionLabel.set(model.getDirection() == Direction.BUY ? BSResources.get("shared.buy") : BSResources.get
|
||||
("shared.sell"));
|
||||
|
||||
// apply only if valid
|
||||
if (orderBookInfo.getAmount() != null && isBtcInputValid(orderBookInfo.getAmount().toPlainString())
|
||||
if (amount != null && isBtcInputValid(amount.toPlainString())
|
||||
.isValid) {
|
||||
model.amountAsCoin.set(orderBookInfo.getAmount());
|
||||
model.minAmountAsCoin.set(orderBookInfo.getAmount());
|
||||
model.amountAsCoin.set(amount);
|
||||
model.minAmountAsCoin.set(amount);
|
||||
}
|
||||
|
||||
// apply only if valid
|
||||
if (orderBookInfo.getPrice() != null && isBtcInputValid(orderBookInfo.getPrice().toPlainString()).isValid)
|
||||
model.priceAsFiat.set(parseToFiatWith2Decimals(orderBookInfo.getPrice().toPlainString()));
|
||||
if (price != null && isBtcInputValid(price.toPlainString()).isValid)
|
||||
model.priceAsFiat.set(parseToFiatWith2Decimals(price.toPlainString()));
|
||||
}
|
||||
|
||||
|
||||
@ -299,25 +297,25 @@ class CreateOfferPM extends PresentationModel<CreateOfferModel> {
|
||||
if (isBtcInputValid(newValue).isValid) {
|
||||
setAmountToModel();
|
||||
calculateVolume();
|
||||
model.calculateTotalToPay();
|
||||
model.calculateCollateral();
|
||||
model.calculateTotalToPay();
|
||||
}
|
||||
validateInput();
|
||||
updateButtonDisableState();
|
||||
});
|
||||
|
||||
minAmount.addListener((ov, oldValue, newValue) -> {
|
||||
setMinAmountToModel();
|
||||
validateInput();
|
||||
updateButtonDisableState();
|
||||
});
|
||||
|
||||
price.addListener((ov, oldValue, newValue) -> {
|
||||
if (isFiatInputValid(newValue).isValid) {
|
||||
setPriceToModel();
|
||||
calculateVolume();
|
||||
model.calculateTotalToPay();
|
||||
model.calculateCollateral();
|
||||
model.calculateTotalToPay();
|
||||
}
|
||||
validateInput();
|
||||
updateButtonDisableState();
|
||||
});
|
||||
|
||||
volume.addListener((ov, oldValue, newValue) -> {
|
||||
@ -325,14 +323,14 @@ class CreateOfferPM extends PresentationModel<CreateOfferModel> {
|
||||
setVolumeToModel();
|
||||
setPriceToModel();
|
||||
model.calculateAmount();
|
||||
model.calculateTotalToPay();
|
||||
model.calculateCollateral();
|
||||
model.calculateTotalToPay();
|
||||
}
|
||||
validateInput();
|
||||
updateButtonDisableState();
|
||||
});
|
||||
model.isWalletFunded.addListener((ov, oldValue, newValue) -> {
|
||||
if (newValue)
|
||||
validateInput();
|
||||
updateButtonDisableState();
|
||||
});
|
||||
|
||||
// Binding with Bindings.createObjectBinding does not work because of bi-directional binding
|
||||
@ -427,7 +425,7 @@ class CreateOfferPM extends PresentationModel<CreateOfferModel> {
|
||||
model.volumeAsFiat.set(parseToFiatWith2Decimals(volume.get()));
|
||||
}
|
||||
|
||||
private void validateInput() {
|
||||
private void updateButtonDisableState() {
|
||||
isPlaceOfferButtonDisabled.set(!(isBtcInputValid(amount.get()).isValid &&
|
||||
isBtcInputValid(minAmount.get()).isValid &&
|
||||
isBtcInputValid(price.get()).isValid &&
|
||||
|
@ -127,7 +127,7 @@
|
||||
</HBox>
|
||||
</VBox>
|
||||
|
||||
<InfoDisplay gridPane="$gridPane" onAction="#onOpenGeneralHelp" rowIndex="2" prefWidth="740"
|
||||
<InfoDisplay gridPane="$gridPane" onAction="#onOpenGeneralHelp" rowIndex="2"
|
||||
text="%createOffer.amountPriceBox.info"/>
|
||||
|
||||
<Button fx:id="showPaymentInfoScreenButton" text="%createOffer.amountPriceBox.next" id="show-details-button"
|
||||
@ -177,7 +177,7 @@
|
||||
</BalanceTextField>
|
||||
|
||||
<InfoDisplay fx:id="fundsBoxInfoDisplay" gridPane="$gridPane" onAction="#onOpenFundingHelp" rowIndex="7"
|
||||
text="%createOffer.fundsBox.info" visible="false" prefWidth="740"/>
|
||||
text="%createOffer.fundsBox.info" visible="false"/>
|
||||
|
||||
<HBox spacing="10" GridPane.columnIndex="1" GridPane.rowIndex="8">
|
||||
<Button fx:id="showAdvancedSettingsButton" text="%createOffer.fundsBox.showAdvanced"
|
||||
@ -245,7 +245,7 @@
|
||||
</TextField>
|
||||
|
||||
<InfoDisplay fx:id="advancedInfoDisplay" gridPane="$gridPane" onAction="#onOpenAdvancedSettingsHelp"
|
||||
rowIndex="15" visible="false" prefWidth="740"
|
||||
rowIndex="15" visible="false"
|
||||
text="%createOffer.advancedBox.info">
|
||||
</InfoDisplay>
|
||||
|
||||
|
@ -29,11 +29,13 @@ 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.OrderBookInfo;
|
||||
import io.bitsquare.gui.util.ImageUtil;
|
||||
import io.bitsquare.locale.BSResources;
|
||||
import io.bitsquare.trade.Direction;
|
||||
|
||||
import com.google.bitcoin.core.Coin;
|
||||
import com.google.bitcoin.utils.Fiat;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -147,7 +149,7 @@ public class CreateOfferViewCB extends CachedViewCB<CreateOfferPM> {
|
||||
public void terminate() {
|
||||
super.terminate();
|
||||
|
||||
// Inform parent that we gor removed.
|
||||
// Inform parent that we got removed.
|
||||
// Needed to reset disable state of createOfferButton in OrderBookController
|
||||
if (closeListener != null)
|
||||
closeListener.onClosed();
|
||||
@ -158,10 +160,10 @@ public class CreateOfferViewCB extends CachedViewCB<CreateOfferPM> {
|
||||
// Public methods (called form other views/CB)
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public void initWithOrderBookInfo(OrderBookInfo orderBookInfo) {
|
||||
presentationModel.setOrderBookInfo(orderBookInfo);
|
||||
public void initWithData(Direction direction, Coin amount, Fiat price) {
|
||||
presentationModel.initWithData(direction, amount, price);
|
||||
|
||||
if (orderBookInfo.getDirection() == Direction.BUY)
|
||||
if (direction == Direction.BUY)
|
||||
imageView.setId("image-buy-large");
|
||||
else
|
||||
imageView.setId("image-sell-large");
|
||||
|
@ -19,7 +19,6 @@ package io.bitsquare.gui.main.trade.orderbook;
|
||||
|
||||
import io.bitsquare.bank.BankAccount;
|
||||
import io.bitsquare.gui.UIModel;
|
||||
import io.bitsquare.gui.main.trade.OrderBookInfo;
|
||||
import io.bitsquare.gui.util.BSFormatter;
|
||||
import io.bitsquare.locale.Country;
|
||||
import io.bitsquare.locale.CurrencyUtil;
|
||||
@ -63,7 +62,7 @@ class OrderBookModel extends UIModel {
|
||||
|
||||
private final FilteredList<OrderBookListItem> filteredItems;
|
||||
private final SortedList<OrderBookListItem> sortedItems;
|
||||
private OrderBookInfo orderBookInfo;
|
||||
// private OrderBookInfo orderBookInfo;
|
||||
private ChangeListener<BankAccount> bankAccountChangeListener;
|
||||
|
||||
private final ObjectProperty<Coin> amountAsCoin = new SimpleObjectProperty<>();
|
||||
@ -75,6 +74,7 @@ class OrderBookModel extends UIModel {
|
||||
final StringProperty btcCode = new SimpleStringProperty();
|
||||
final ObjectProperty<Country> bankAccountCountry = new SimpleObjectProperty<>();
|
||||
final ObjectProperty<Comparator<OrderBookListItem>> comparator = new SimpleObjectProperty<>();
|
||||
private Direction direction;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -139,10 +139,6 @@ class OrderBookModel extends UIModel {
|
||||
// Public methods
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void setOrderBookInfo(OrderBookInfo orderBookInfo) {
|
||||
this.orderBookInfo = orderBookInfo;
|
||||
}
|
||||
|
||||
void removeOffer(Offer offer) {
|
||||
tradeManager.removeOffer(offer);
|
||||
}
|
||||
@ -211,21 +207,22 @@ class OrderBookModel extends UIModel {
|
||||
// Setters
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void setDirection(Direction direction) {
|
||||
this.direction = direction;
|
||||
}
|
||||
|
||||
void setAmount(Coin amount) {
|
||||
amountAsCoin.set(amount);
|
||||
orderBookInfo.setAmount(amount);
|
||||
applyFilter();
|
||||
}
|
||||
|
||||
void setPrice(Fiat price) {
|
||||
priceAsFiat.set(price);
|
||||
orderBookInfo.setPrice(price);
|
||||
applyFilter();
|
||||
}
|
||||
|
||||
void setVolume(Fiat volume) {
|
||||
volumeAsFiat.set(volume);
|
||||
orderBookInfo.setVolume(volume);
|
||||
applyFilter();
|
||||
}
|
||||
|
||||
@ -270,11 +267,10 @@ class OrderBookModel extends UIModel {
|
||||
return volumeAsFiat;
|
||||
}
|
||||
|
||||
OrderBookInfo getOrderBookInfo() {
|
||||
return orderBookInfo;
|
||||
Direction getDirection() {
|
||||
return direction;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Private methods
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -294,21 +290,23 @@ class OrderBookModel extends UIModel {
|
||||
filteredItems.setPredicate(orderBookListItem -> {
|
||||
Offer offer = orderBookListItem.getOffer();
|
||||
|
||||
boolean directionResult = offer.getDirection() != orderBookInfo.getDirection();
|
||||
boolean directionResult = offer.getDirection() != direction;
|
||||
|
||||
boolean amountResult = true;
|
||||
if (orderBookInfo.getAmount() != null && orderBookInfo.getAmount().isPositive())
|
||||
amountResult = orderBookInfo.getAmount().compareTo(offer.getAmount()) <= 0;
|
||||
if (amountAsCoin.get() != null && amountAsCoin.get().isPositive())
|
||||
amountResult = amountAsCoin.get().compareTo(offer.getAmount()) <= 0 &&
|
||||
amountAsCoin.get().compareTo(offer.getMinAmount()) >= 0;
|
||||
|
||||
boolean priceResult = true;
|
||||
if (orderBookInfo.getPrice() != null && orderBookInfo.getPrice().isPositive()) {
|
||||
if (priceAsFiat.get() != null && priceAsFiat.get().isPositive()) {
|
||||
if (offer.getDirection() == Direction.SELL)
|
||||
priceResult = orderBookInfo.getPrice().compareTo(offer.getPrice()) >= 0;
|
||||
priceResult = priceAsFiat.get().compareTo(offer.getPrice()) >= 0;
|
||||
else
|
||||
priceResult = orderBookInfo.getPrice().compareTo(offer.getPrice()) <= 0;
|
||||
priceResult = priceAsFiat.get().compareTo(offer.getPrice()) <= 0;
|
||||
}
|
||||
|
||||
return directionResult && amountResult && priceResult;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -18,7 +18,6 @@
|
||||
package io.bitsquare.gui.main.trade.orderbook;
|
||||
|
||||
import io.bitsquare.gui.PresentationModel;
|
||||
import io.bitsquare.gui.main.trade.OrderBookInfo;
|
||||
import io.bitsquare.gui.util.BSFormatter;
|
||||
import io.bitsquare.gui.util.validation.InputValidator;
|
||||
import io.bitsquare.gui.util.validation.OptionalBtcValidator;
|
||||
@ -27,6 +26,9 @@ import io.bitsquare.locale.BSResources;
|
||||
import io.bitsquare.trade.Direction;
|
||||
import io.bitsquare.trade.Offer;
|
||||
|
||||
import com.google.bitcoin.core.Coin;
|
||||
import com.google.bitcoin.utils.Fiat;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
@ -134,10 +136,6 @@ class OrderBookPM extends PresentationModel<OrderBookModel> {
|
||||
// Public methods
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void setOrderBookInfo(OrderBookInfo orderBookInfo) {
|
||||
model.setOrderBookInfo(orderBookInfo);
|
||||
}
|
||||
|
||||
void removeOffer(Offer offer) {
|
||||
model.removeOffer(offer);
|
||||
}
|
||||
@ -147,6 +145,15 @@ class OrderBookPM extends PresentationModel<OrderBookModel> {
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Setters
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void setDirection(Direction direction) {
|
||||
model.setDirection(direction);
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Getters
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -176,7 +183,8 @@ class OrderBookPM extends PresentationModel<OrderBookModel> {
|
||||
}
|
||||
|
||||
String getAmount(OrderBookListItem item) {
|
||||
return (item != null) ? BSFormatter.formatCoin(item.getOffer().getAmount()) : "";
|
||||
return (item != null) ? BSFormatter.formatCoin(item.getOffer().getAmount()) +
|
||||
" (" + BSFormatter.formatCoin(item.getOffer().getMinAmount()) + ")" : "";
|
||||
}
|
||||
|
||||
String getPrice(OrderBookListItem item) {
|
||||
@ -184,7 +192,8 @@ class OrderBookPM extends PresentationModel<OrderBookModel> {
|
||||
}
|
||||
|
||||
String getVolume(OrderBookListItem item) {
|
||||
return (item != null) ? BSFormatter.formatFiat(item.getOffer().getOfferVolume()) : "";
|
||||
return (item != null) ? BSFormatter.formatFiat(item.getOffer().getOfferVolume()) +
|
||||
" (" + BSFormatter.formatFiat(item.getOffer().getMinOfferVolume()) + ")" : "";
|
||||
}
|
||||
|
||||
String getBankAccountType(OrderBookListItem item) {
|
||||
@ -197,10 +206,17 @@ class OrderBookPM extends PresentationModel<OrderBookModel> {
|
||||
return BSFormatter.formatDirection(direction, true);
|
||||
}
|
||||
|
||||
OrderBookInfo getOrderBookInfo() {
|
||||
return model.getOrderBookInfo();
|
||||
Direction getDirection() {
|
||||
return model.getDirection();
|
||||
}
|
||||
|
||||
Coin getAmountAsCoin() {
|
||||
return model.getAmountAsCoin();
|
||||
}
|
||||
|
||||
Fiat getPriceAsCoin() {
|
||||
return model.getPriceAsFiat();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Private methods
|
||||
@ -226,5 +242,4 @@ class OrderBookPM extends PresentationModel<OrderBookModel> {
|
||||
model.setVolume(parseToFiatWith2Decimals(volume.get()));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ import io.bitsquare.gui.Navigation;
|
||||
import io.bitsquare.gui.OverlayManager;
|
||||
import io.bitsquare.gui.components.InputTextField;
|
||||
import io.bitsquare.gui.components.Popups;
|
||||
import io.bitsquare.gui.main.trade.OrderBookInfo;
|
||||
import io.bitsquare.gui.main.trade.TradeNavigator;
|
||||
import io.bitsquare.gui.util.ImageUtil;
|
||||
import io.bitsquare.gui.util.validation.OptionalBtcValidator;
|
||||
import io.bitsquare.gui.util.validation.OptionalFiatValidator;
|
||||
@ -143,7 +143,7 @@ public class OrderBookViewCB extends CachedViewCB<OrderBookPM> {
|
||||
offerList.comparatorProperty().bind(orderBookTable.comparatorProperty());
|
||||
|
||||
|
||||
priceColumn.setSortType((presentationModel.getOrderBookInfo().getDirection() == Direction.BUY) ?
|
||||
priceColumn.setSortType((presentationModel.getDirection() == Direction.BUY) ?
|
||||
TableColumn.SortType.ASCENDING : TableColumn.SortType.DESCENDING);
|
||||
orderBookTable.sort();
|
||||
}
|
||||
@ -175,10 +175,9 @@ public class OrderBookViewCB extends CachedViewCB<OrderBookPM> {
|
||||
// Setter
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public void setOrderBookInfo(OrderBookInfo orderBookInfo) {
|
||||
presentationModel.setOrderBookInfo(orderBookInfo);
|
||||
navigationItem = (orderBookInfo.getDirection() == Direction.BUY) ?
|
||||
Navigation.Item.BUY : Navigation.Item.SELL;
|
||||
public void setDirection(Direction direction) {
|
||||
presentationModel.setDirection(direction);
|
||||
navigationItem = (direction == Direction.BUY) ? Navigation.Item.BUY : Navigation.Item.SELL;
|
||||
|
||||
}
|
||||
|
||||
@ -191,8 +190,8 @@ public class OrderBookViewCB extends CachedViewCB<OrderBookPM> {
|
||||
void createOffer() {
|
||||
if (presentationModel.isRegistered()) {
|
||||
createOfferButton.setDisable(true);
|
||||
navigation.navigationTo(Navigation.Item.MAIN, navigationItem,
|
||||
Navigation.Item.CREATE_OFFER);
|
||||
((TradeNavigator) parent).createOffer(presentationModel.getAmountAsCoin(),
|
||||
presentationModel.getPriceAsCoin());
|
||||
}
|
||||
else {
|
||||
openSetupScreen();
|
||||
@ -236,12 +235,10 @@ public class OrderBookViewCB extends CachedViewCB<OrderBookPM> {
|
||||
"You don't have a trading account.", actions);
|
||||
}
|
||||
|
||||
//TODO not updated yet
|
||||
private void takeOffer(Offer offer) {
|
||||
if (presentationModel.isRegistered()) {
|
||||
presentationModel.getOrderBookInfo().setOffer(offer);
|
||||
navigation.navigationTo(Navigation.Item.MAIN, navigationItem,
|
||||
Navigation.Item.TAKE_OFFER);
|
||||
((TradeNavigator) parent).takeOffer(presentationModel.getAmountAsCoin(),
|
||||
presentationModel.getPriceAsCoin(), offer);
|
||||
}
|
||||
else {
|
||||
openSetupScreen();
|
||||
|
@ -22,8 +22,8 @@ import io.bitsquare.btc.FeePolicy;
|
||||
import io.bitsquare.btc.WalletFacade;
|
||||
import io.bitsquare.btc.listeners.BalanceListener;
|
||||
import io.bitsquare.gui.UIModel;
|
||||
import io.bitsquare.gui.main.trade.OrderBookInfo;
|
||||
import io.bitsquare.settings.Settings;
|
||||
import io.bitsquare.trade.Offer;
|
||||
import io.bitsquare.trade.Trade;
|
||||
import io.bitsquare.trade.TradeManager;
|
||||
import io.bitsquare.trade.protocol.trade.taker.SellerTakesOfferProtocol;
|
||||
@ -59,7 +59,7 @@ class TakeOfferModel extends UIModel {
|
||||
private final WalletFacade walletFacade;
|
||||
private final Settings settings;
|
||||
|
||||
private OrderBookInfo orderBookInfo;
|
||||
private Offer offer;
|
||||
private AddressEntry addressEntry;
|
||||
|
||||
final StringProperty requestTakeOfferErrorMessage = new SimpleStringProperty();
|
||||
@ -71,8 +71,6 @@ class TakeOfferModel extends UIModel {
|
||||
final BooleanProperty useMBTC = new SimpleBooleanProperty();
|
||||
|
||||
final ObjectProperty<Coin> amountAsCoin = new SimpleObjectProperty<>();
|
||||
final ObjectProperty<Coin> minAmountAsCoin = new SimpleObjectProperty<>();
|
||||
final ObjectProperty<Fiat> priceAsFiat = new SimpleObjectProperty<>();
|
||||
final ObjectProperty<Fiat> volumeAsFiat = new SimpleObjectProperty<>();
|
||||
final ObjectProperty<Coin> totalToPayAsCoin = new SimpleObjectProperty<>();
|
||||
final ObjectProperty<Coin> collateralAsCoin = new SimpleObjectProperty<>();
|
||||
@ -130,6 +128,32 @@ class TakeOfferModel extends UIModel {
|
||||
// Methods
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void initWithData(Coin amount, Offer offer) {
|
||||
this.offer = offer;
|
||||
|
||||
if (amount != null &&
|
||||
!amount.isGreaterThan(offer.getAmount()) &&
|
||||
!offer.getMinAmount().isGreaterThan(amount)) {
|
||||
amountAsCoin.set(amount);
|
||||
}
|
||||
else {
|
||||
amountAsCoin.set(offer.getAmount());
|
||||
}
|
||||
|
||||
calculateVolume();
|
||||
calculateCollateral();
|
||||
calculateTotalToPay();
|
||||
|
||||
addressEntry = walletFacade.getAddressInfoByTradeID(offer.getId());
|
||||
walletFacade.addBalanceListener(new BalanceListener(addressEntry.getAddress()) {
|
||||
@Override
|
||||
public void onBalanceChanged(@NotNull Coin balance) {
|
||||
updateBalance(balance);
|
||||
}
|
||||
});
|
||||
updateBalance(walletFacade.getBalanceForAddress(addressEntry.getAddress()));
|
||||
}
|
||||
|
||||
void takeOffer() {
|
||||
// data validation is done in the trade domain
|
||||
/*tradeManager.requestPlaceOffer(orderBookInfo.getOffer().getId(),
|
||||
@ -181,7 +205,7 @@ class TakeOfferModel extends UIModel {
|
||||
}
|
||||
};
|
||||
|
||||
tradeManager.takeOffer(amountAsCoin.get(), orderBookInfo.getOffer(), listener);
|
||||
tradeManager.takeOffer(amountAsCoin.get(), offer, listener);
|
||||
/*new SellerTakesOfferProtocolListener() {
|
||||
@Override
|
||||
public void onDepositTxPublished(String depositTxId) {
|
||||
@ -245,11 +269,11 @@ class TakeOfferModel extends UIModel {
|
||||
|
||||
void calculateVolume() {
|
||||
try {
|
||||
if (priceAsFiat.get() != null &&
|
||||
if (offer != null &&
|
||||
offer.getPrice() != null &&
|
||||
amountAsCoin.get() != null &&
|
||||
!amountAsCoin.get().isZero() &&
|
||||
!priceAsFiat.get().isZero()) {
|
||||
volumeAsFiat.set(new ExchangeRate(priceAsFiat.get()).coinToFiat(amountAsCoin.get()));
|
||||
!amountAsCoin.get().isZero()) {
|
||||
volumeAsFiat.set(new ExchangeRate(offer.getPrice()).coinToFiat(amountAsCoin.get()));
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
// Should be never reached
|
||||
@ -272,8 +296,8 @@ class TakeOfferModel extends UIModel {
|
||||
|
||||
void calculateCollateral() {
|
||||
try {
|
||||
if (amountAsCoin.get() != null && orderBookInfo != null)
|
||||
collateralAsCoin.set(amountAsCoin.get().multiply(orderBookInfo.getOffer().getCollateral()).
|
||||
if (amountAsCoin.get() != null && offer != null)
|
||||
collateralAsCoin.set(amountAsCoin.get().multiply(offer.getCollateral()).
|
||||
divide(1000L));
|
||||
} catch (Throwable t) {
|
||||
// The multiply might lead to too large numbers, we don't handle it but it should not break the app
|
||||
@ -283,8 +307,15 @@ class TakeOfferModel extends UIModel {
|
||||
|
||||
boolean isMinAmountLessOrEqualAmount() {
|
||||
//noinspection SimplifiableIfStatement
|
||||
if (minAmountAsCoin.get() != null && amountAsCoin.get() != null)
|
||||
return !minAmountAsCoin.get().isGreaterThan(amountAsCoin.get());
|
||||
if (offer != null && offer.getMinAmount() != null && amountAsCoin.get() != null)
|
||||
return !offer.getMinAmount().isGreaterThan(amountAsCoin.get());
|
||||
return true;
|
||||
}
|
||||
|
||||
boolean isAmountLargerThanOfferAmount() {
|
||||
//noinspection SimplifiableIfStatement
|
||||
if (amountAsCoin.get() != null && offer != null)
|
||||
return amountAsCoin.get().isGreaterThan(offer.getAmount());
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -293,17 +324,6 @@ class TakeOfferModel extends UIModel {
|
||||
// Setter
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void setOrderBookInfo(@NotNull OrderBookInfo orderBookInfo) {
|
||||
this.orderBookInfo = orderBookInfo;
|
||||
addressEntry = walletFacade.getAddressInfoByTradeID(orderBookInfo.getOffer().getId());
|
||||
walletFacade.addBalanceListener(new BalanceListener(addressEntry.getAddress()) {
|
||||
@Override
|
||||
public void onBalanceChanged(@NotNull Coin balance) {
|
||||
updateBalance(balance);
|
||||
}
|
||||
});
|
||||
updateBalance(walletFacade.getBalanceForAddress(addressEntry.getAddress()));
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Getter
|
||||
|
@ -19,12 +19,12 @@ package io.bitsquare.gui.main.trade.takeoffer;
|
||||
|
||||
import io.bitsquare.btc.WalletFacade;
|
||||
import io.bitsquare.gui.PresentationModel;
|
||||
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.InputValidator;
|
||||
import io.bitsquare.locale.BSResources;
|
||||
import io.bitsquare.trade.Direction;
|
||||
import io.bitsquare.trade.Offer;
|
||||
|
||||
import com.google.bitcoin.core.Address;
|
||||
import com.google.bitcoin.core.Coin;
|
||||
@ -38,8 +38,6 @@ import javafx.beans.property.SimpleObjectProperty;
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
import javafx.beans.property.StringProperty;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -52,7 +50,7 @@ class TakeOfferPM extends PresentationModel<TakeOfferModel> {
|
||||
private String offerFee;
|
||||
private String networkFee;
|
||||
private String fiatCode;
|
||||
private String minAmount;
|
||||
private String amountRange;
|
||||
private String price;
|
||||
private String directionLabel;
|
||||
private String collateralLabel;
|
||||
@ -143,42 +141,40 @@ class TakeOfferPM extends PresentationModel<TakeOfferModel> {
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// setOrderBookFilter is a one time call
|
||||
void setOrderBookInfo(@NotNull OrderBookInfo orderBookInfo) {
|
||||
model.setOrderBookInfo(orderBookInfo);
|
||||
void initWithData(Direction direction, Coin amount, Offer offer) {
|
||||
model.initWithData(amount, offer);
|
||||
|
||||
directionLabel = orderBookInfo.getDirection() == Direction.BUY ?
|
||||
directionLabel = direction == Direction.BUY ?
|
||||
BSResources.get("shared.buy") : BSResources.get("shared.sell");
|
||||
|
||||
fiatCode = orderBookInfo.getOffer().getCurrency().getCurrencyCode();
|
||||
model.priceAsFiat.set(orderBookInfo.getOffer().getPrice());
|
||||
model.minAmountAsCoin.set(orderBookInfo.getOffer().getMinAmount());
|
||||
if (orderBookInfo.getAmount() != null &&
|
||||
isBtcInputValid(orderBookInfo.getAmount().toPlainString()).isValid &&
|
||||
!orderBookInfo.getAmount().isGreaterThan(orderBookInfo.getOffer().getAmount())) {
|
||||
model.amountAsCoin.set(orderBookInfo.getAmount());
|
||||
fiatCode = offer.getCurrency().getCurrencyCode();
|
||||
if (!model.isMinAmountLessOrEqualAmount()) {
|
||||
amountValidationResult.set(new InputValidator.ValidationResult(false,
|
||||
BSResources.get("takeOffer.validation.amountSmallerThanMinAmount")));
|
||||
}
|
||||
else {
|
||||
model.amountAsCoin.set(orderBookInfo.getOffer().getAmount());
|
||||
}
|
||||
model.volumeAsFiat.set(orderBookInfo.getOffer().getVolumeByAmount(model.amountAsCoin.get()));
|
||||
|
||||
minAmount = BSFormatter.formatCoinWithCode(orderBookInfo.getOffer().getMinAmount());
|
||||
price = BSFormatter.formatFiatWithCode(orderBookInfo.getOffer().getPrice());
|
||||
updateButtonDisableState();
|
||||
|
||||
paymentLabel = BSResources.get("takeOffer.fundsBox.paymentLabel", orderBookInfo.getOffer().getId());
|
||||
//model.volumeAsFiat.set(offer.getVolumeByAmount(model.amountAsCoin.get()));
|
||||
|
||||
amountRange = BSFormatter.formatCoinWithCode(offer.getMinAmount()) + " - " +
|
||||
BSFormatter.formatCoinWithCode(offer.getAmount());
|
||||
price = BSFormatter.formatFiatWithCode(offer.getPrice());
|
||||
|
||||
paymentLabel = BSResources.get("takeOffer.fundsBox.paymentLabel", offer.getId());
|
||||
if (model.getAddressEntry() != null) {
|
||||
addressAsString = model.getAddressEntry().getAddress().toString();
|
||||
address.set(model.getAddressEntry().getAddress());
|
||||
}
|
||||
collateralLabel = BSResources.get("takeOffer.fundsBox.collateral",
|
||||
BSFormatter.formatCollateralPercent(orderBookInfo.getOffer().getCollateral()));
|
||||
BSFormatter.formatCollateralPercent(offer.getCollateral()));
|
||||
|
||||
acceptedCountries = BSFormatter.countryLocalesToString(orderBookInfo.getOffer().getAcceptedCountries());
|
||||
acceptedLanguages = BSFormatter.languageLocalesToString(orderBookInfo.getOffer().getAcceptedLanguageLocales());
|
||||
acceptedArbitrators = BSFormatter.arbitratorsToString(orderBookInfo.getOffer().getArbitrators());
|
||||
bankAccountType = BSResources.get(orderBookInfo.getOffer().getBankAccountType().toString());
|
||||
bankAccountCurrency = BSResources.get(orderBookInfo.getOffer().getCurrency().getDisplayName());
|
||||
bankAccountCounty = BSResources.get(orderBookInfo.getOffer().getBankAccountCountry().getName());
|
||||
acceptedCountries = BSFormatter.countryLocalesToString(offer.getAcceptedCountries());
|
||||
acceptedLanguages = BSFormatter.languageLocalesToString(offer.getAcceptedLanguageLocales());
|
||||
acceptedArbitrators = BSFormatter.arbitratorsToString(offer.getArbitrators());
|
||||
bankAccountType = BSResources.get(offer.getBankAccountType().toString());
|
||||
bankAccountCurrency = BSResources.get(offer.getCurrency().getDisplayName());
|
||||
bankAccountCounty = BSResources.get(offer.getBankAccountCountry().getName());
|
||||
}
|
||||
|
||||
|
||||
@ -217,6 +213,14 @@ class TakeOfferPM extends PresentationModel<TakeOfferModel> {
|
||||
amount.set(formatCoin(model.amountAsCoin.get()));
|
||||
|
||||
calculateVolume();
|
||||
|
||||
if (!model.isMinAmountLessOrEqualAmount())
|
||||
amountValidationResult.set(new InputValidator.ValidationResult(false,
|
||||
BSResources.get("takeOffer.validation.amountSmallerThanMinAmount")));
|
||||
|
||||
if (model.isAmountLargerThanOfferAmount())
|
||||
amountValidationResult.set(new InputValidator.ValidationResult(false,
|
||||
BSResources.get("takeOffer.validation.amountLargerThanOfferAmount")));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -242,8 +246,8 @@ class TakeOfferPM extends PresentationModel<TakeOfferModel> {
|
||||
return fiatCode;
|
||||
}
|
||||
|
||||
String getMinAmount() {
|
||||
return minAmount;
|
||||
String getAmountRange() {
|
||||
return amountRange;
|
||||
}
|
||||
|
||||
String getPrice() {
|
||||
@ -302,15 +306,15 @@ class TakeOfferPM extends PresentationModel<TakeOfferModel> {
|
||||
if (isBtcInputValid(newValue).isValid) {
|
||||
setAmountToModel();
|
||||
calculateVolume();
|
||||
model.calculateTotalToPay();
|
||||
model.calculateCollateral();
|
||||
model.calculateTotalToPay();
|
||||
}
|
||||
validateInput();
|
||||
updateButtonDisableState();
|
||||
});
|
||||
|
||||
model.isWalletFunded.addListener((ov, oldValue, newValue) -> {
|
||||
if (newValue)
|
||||
validateInput();
|
||||
updateButtonDisableState();
|
||||
});
|
||||
|
||||
// Binding with Bindings.createObjectBinding does not work because of bi-directional binding
|
||||
@ -349,9 +353,10 @@ class TakeOfferPM extends PresentationModel<TakeOfferModel> {
|
||||
model.amountAsCoin.set(parseToCoinWith4Decimals(amount.get()));
|
||||
}
|
||||
|
||||
private void validateInput() {
|
||||
private void updateButtonDisableState() {
|
||||
isTakeOfferButtonDisabled.set(!(isBtcInputValid(amount.get()).isValid &&
|
||||
model.isMinAmountLessOrEqualAmount() &&
|
||||
!model.isAmountLargerThanOfferAmount() &&
|
||||
model.isWalletFunded.get())
|
||||
);
|
||||
}
|
||||
|
@ -110,13 +110,12 @@
|
||||
<GridPane.margin>
|
||||
<Insets right="10.0" top="5.0" bottom="5.0"/>
|
||||
</GridPane.margin>
|
||||
<Label id="input-description-label" text="%takeOffer.amountPriceBox.minAmountDescription"
|
||||
prefWidth="170.0"/>
|
||||
<TextField fx:id="minAmountTextField" id="text-input-with-currency-text-field"
|
||||
prefWidth="170.0" editable="false"/>
|
||||
<Label id="input-description-label" text="%takeOffer.amountPriceBox.amountRangeDescription"
|
||||
prefWidth="170" textAlignment="CENTER"/>
|
||||
<Label fx:id="amountRangeTextField" id="label-with-background" prefWidth="170" textAlignment="CENTER"/>
|
||||
</VBox>
|
||||
|
||||
<InfoDisplay gridPane="$gridPane" onAction="#onOpenGeneralHelp" rowIndex="2" prefWidth="740"
|
||||
<InfoDisplay gridPane="$gridPane" onAction="#onOpenGeneralHelp" rowIndex="2"
|
||||
text="%takeOffer.amountPriceBox.info"/>
|
||||
|
||||
<Button fx:id="showPaymentInfoScreenButton" text="%takeOffer.amountPriceBox.next" id="show-details-button"
|
||||
@ -166,7 +165,7 @@
|
||||
</BalanceTextField>
|
||||
|
||||
<InfoDisplay fx:id="fundsBoxInfoDisplay" gridPane="$gridPane" onAction="#onOpenFundingHelp" rowIndex="7"
|
||||
text="%takeOffer.fundsBox.info" visible="false" prefWidth="740"/>
|
||||
text="%takeOffer.fundsBox.info" visible="false"/>
|
||||
|
||||
<HBox spacing="10" GridPane.columnIndex="1" GridPane.rowIndex="8">
|
||||
<Button fx:id="showAdvancedSettingsButton" text="%takeOffer.fundsBox.showAdvanced"
|
||||
@ -229,7 +228,7 @@
|
||||
</TextField>
|
||||
|
||||
<InfoDisplay fx:id="advancedInfoDisplay" gridPane="$gridPane" onAction="#onOpenAdvancedSettingsHelp"
|
||||
rowIndex="15" visible="false" prefWidth="740"
|
||||
rowIndex="15" visible="false"
|
||||
text="%takeOffer.advancedBox.info">
|
||||
</InfoDisplay>
|
||||
|
||||
|
@ -30,10 +30,12 @@ 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.OrderBookInfo;
|
||||
import io.bitsquare.gui.util.ImageUtil;
|
||||
import io.bitsquare.locale.BSResources;
|
||||
import io.bitsquare.trade.Direction;
|
||||
import io.bitsquare.trade.Offer;
|
||||
|
||||
import com.google.bitcoin.core.Coin;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
@ -85,7 +87,7 @@ public class TakeOfferViewCB extends CachedViewCB<TakeOfferPM> {
|
||||
@FXML ScrollPane scrollPane;
|
||||
@FXML ImageView imageView;
|
||||
@FXML TitledGroupBg priceAmountPane, payFundsPane, showDetailsPane;
|
||||
@FXML Label buyLabel, addressLabel,
|
||||
@FXML Label buyLabel, addressLabel, amountRangeTextField,
|
||||
balanceLabel, totalToPayLabel, totalToPayInfoIconLabel,
|
||||
bankAccountTypeLabel, bankAccountCurrencyLabel, bankAccountCountyLabel,
|
||||
acceptedCountriesLabel, acceptedLanguagesLabel,
|
||||
@ -94,7 +96,7 @@ public class TakeOfferViewCB extends CachedViewCB<TakeOfferPM> {
|
||||
@FXML Button showPaymentInfoScreenButton, showAdvancedSettingsButton, takeOfferButton;
|
||||
|
||||
@FXML InputTextField amountTextField;
|
||||
@FXML TextField minAmountTextField, priceTextField, volumeTextField, acceptedArbitratorsTextField,
|
||||
@FXML TextField priceTextField, volumeTextField, acceptedArbitratorsTextField,
|
||||
totalToPayTextField,
|
||||
bankAccountTypeTextField,
|
||||
bankAccountCurrencyTextField, bankAccountCountyTextField, acceptedCountriesTextField,
|
||||
@ -143,8 +145,7 @@ public class TakeOfferViewCB extends CachedViewCB<TakeOfferPM> {
|
||||
public void terminate() {
|
||||
super.terminate();
|
||||
|
||||
// Inform parent that we gor removed.
|
||||
// Needed to reset disable state of createOfferButton in OrderBookController
|
||||
// Inform parent that we got removed.
|
||||
if (closeListener != null)
|
||||
closeListener.onClosed();
|
||||
}
|
||||
@ -154,10 +155,10 @@ public class TakeOfferViewCB extends CachedViewCB<TakeOfferPM> {
|
||||
// Public methods (called form other views/CB)
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public void initWithOrderBookInfo(OrderBookInfo orderBookInfo) {
|
||||
presentationModel.setOrderBookInfo(orderBookInfo);
|
||||
public void initWithData(Direction direction, Coin amount, Offer offer) {
|
||||
presentationModel.initWithData(direction, amount, offer);
|
||||
|
||||
if (orderBookInfo.getDirection() == Direction.BUY)
|
||||
if (direction == Direction.BUY)
|
||||
imageView.setId("image-buy-large");
|
||||
else
|
||||
imageView.setId("image-sell-large");
|
||||
@ -170,7 +171,7 @@ public class TakeOfferViewCB extends CachedViewCB<TakeOfferPM> {
|
||||
balanceTextField.setup(presentationModel.getWalletFacade(), presentationModel.address.get());
|
||||
|
||||
buyLabel.setText(presentationModel.getDirectionLabel());
|
||||
minAmountTextField.setText(presentationModel.getMinAmount());
|
||||
amountRangeTextField.setText(presentationModel.getAmountRange());
|
||||
priceTextField.setText(presentationModel.getPrice());
|
||||
addressTextField.setPaymentLabel(presentationModel.getPaymentLabel());
|
||||
addressTextField.setAddress(presentationModel.getAddressAsString());
|
||||
@ -183,7 +184,6 @@ public class TakeOfferViewCB extends CachedViewCB<TakeOfferPM> {
|
||||
acceptedArbitratorsTextField.setText(presentationModel.getAcceptedArbitrators());
|
||||
}
|
||||
|
||||
//TODO not used yet
|
||||
public void setCloseListener(CloseListener closeListener) {
|
||||
this.closeListener = closeListener;
|
||||
}
|
||||
|
@ -84,12 +84,13 @@ takeOffer.amountPriceBox.subTitle=Buy Bitcoin
|
||||
takeOffer.amountPriceBox.amountDescription=Amount of Bitcoin to sell
|
||||
takeOffer.amountPriceBox.priceDescription=Price per Bitcoin in {0}
|
||||
takeOffer.amountPriceBox.volumeDescription=Receiving amount in {0}
|
||||
takeOffer.amountPriceBox.minAmountDescription=The offer requires that minimum amount of Bitcoin
|
||||
takeOffer.amountPriceBox.amountRangeDescription=Possible amount range
|
||||
takeOffer.amountPriceBox.info=Enter the amount of Bitcoin you want to sell. You can choose an amount between the minimum amount and the amount.
|
||||
takeOffer.amountPriceBox.next=Next step
|
||||
takeOffer.amountPriceBox.warning.invalidBtcDecimalPlaces=The amount you have entered exceeds the number of allowed decimal places.\nThe amount has been adjusted to 4 decimal places.
|
||||
takeOffer.amountPriceBox.error.message=An error occurred when taking the offer:\n\n {0}
|
||||
takeOffer.validation.amountSmallerThanMinAmount=Amount cannot be smaller than minimum amount.
|
||||
takeOffer.validation.amountSmallerThanMinAmount=Amount cannot be smaller than minimum amount defined in the offer.
|
||||
takeOffer.validation.amountLargerThanOfferAmount=Input amount cannot be higher than the amount defined in the offer.
|
||||
|
||||
takeOffer.fundsBox.title=Fund your trade wallet
|
||||
takeOffer.fundsBox.totalsNeeded=Funds needed for that trade:
|
||||
|
Loading…
x
Reference in New Issue
Block a user