use bindings in create offer controller

This commit is contained in:
Manfred Karrer 2014-08-07 18:14:52 +02:00
parent daecafa3c1
commit a9be983caa
11 changed files with 154 additions and 191 deletions

View file

@ -155,7 +155,7 @@ public class WithdrawalController implements Initializable, ChildController, Hib
BitSquareValidator.textFieldsNotEmpty(amountTextField, withdrawFromTextField, withdrawToTextField, changeAddressTextField); BitSquareValidator.textFieldsNotEmpty(amountTextField, withdrawFromTextField, withdrawToTextField, changeAddressTextField);
BitSquareValidator.textFieldsHasDoubleValueWithReset(amountTextField); BitSquareValidator.textFieldsHasDoubleValueWithReset(amountTextField);
Coin amount = BitSquareFormatter.parseBtcToCoin(amountTextField.getText()); Coin amount = BitSquareFormatter.parseToCoin(amountTextField.getText());
if (BtcValidator.isMinSpendableAmount(amount)) if (BtcValidator.isMinSpendableAmount(amount))
{ {
FutureCallback<Transaction> callback = new FutureCallback<Transaction>() FutureCallback<Transaction> callback = new FutureCallback<Transaction>()
@ -181,8 +181,8 @@ public class WithdrawalController implements Initializable, ChildController, Hib
"Amount: " + amountTextField.getText() + " BTC\n" + "Amount: " + amountTextField.getText() + " BTC\n" +
"Sending address: " + withdrawFromTextField.getText() + "\n" + "Sending address: " + withdrawFromTextField.getText() + "\n" +
"Receiving address: " + withdrawToTextField.getText() + "\n" + "Receiving address: " + withdrawToTextField.getText() + "\n" +
"Transaction fee: " + BitSquareFormatter.formatCoinToBtcWithCode(FeePolicy.TX_FEE) + "\n" + "Transaction fee: " + BitSquareFormatter.formatCoinWithCode(FeePolicy.TX_FEE) + "\n" +
"You receive in total: " + BitSquareFormatter.formatCoinToBtcWithCode(amount.subtract(FeePolicy.TX_FEE)) + " BTC\n\n" + "You receive in total: " + BitSquareFormatter.formatCoinWithCode(amount.subtract(FeePolicy.TX_FEE)) + " BTC\n\n" +
"Are you sure you withdraw that amount?"); "Are you sure you withdraw that amount?");
if (response == Dialog.Actions.OK) if (response == Dialog.Actions.OK)
{ {

View file

@ -16,17 +16,20 @@ import io.bitsquare.gui.components.confidence.ConfidenceProgressIndicator;
import io.bitsquare.gui.popups.Popups; import io.bitsquare.gui.popups.Popups;
import io.bitsquare.gui.util.BitSquareConverter; import io.bitsquare.gui.util.BitSquareConverter;
import io.bitsquare.gui.util.BitSquareFormatter; import io.bitsquare.gui.util.BitSquareFormatter;
import io.bitsquare.gui.util.BitSquareValidator;
import io.bitsquare.locale.Localisation; import io.bitsquare.locale.Localisation;
import io.bitsquare.settings.Settings; import io.bitsquare.settings.Settings;
import io.bitsquare.trade.Direction; import io.bitsquare.trade.Direction;
import io.bitsquare.trade.TradeManager; import io.bitsquare.trade.TradeManager;
import io.bitsquare.trade.orderbook.OrderBookFilter; import io.bitsquare.trade.orderbook.OrderBookFilter;
import io.bitsquare.user.Arbitrator;
import io.bitsquare.user.User; import io.bitsquare.user.User;
import java.net.URL; import java.net.URL;
import java.util.Random; import java.util.Random;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import javafx.beans.binding.DoubleBinding;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.fxml.Initializable; import javafx.fxml.Initializable;
import javafx.scene.control.Button; import javafx.scene.control.Button;
@ -38,6 +41,26 @@ import javax.inject.Inject;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import static javafx.beans.binding.Bindings.createDoubleBinding;
import static javafx.beans.binding.Bindings.createStringBinding;
/**
* Represents the visible state of he view
*/
class ViewModel
{
StringProperty amount = new SimpleStringProperty();
StringProperty minAmount = new SimpleStringProperty();
StringProperty price = new SimpleStringProperty();
StringProperty volume = new SimpleStringProperty();
StringProperty collateral = new SimpleStringProperty();
StringProperty totals = new SimpleStringProperty();
StringProperty direction = new SimpleStringProperty();
BooleanProperty isOfferPlacedScreen = new SimpleBooleanProperty();
}
public class CreateOfferController implements Initializable, ChildController, Hibernate public class CreateOfferController implements Initializable, ChildController, Hibernate
{ {
private static final Logger log = LoggerFactory.getLogger(CreateOfferController.class); private static final Logger log = LoggerFactory.getLogger(CreateOfferController.class);
@ -46,19 +69,17 @@ public class CreateOfferController implements Initializable, ChildController, Hi
private final WalletFacade walletFacade; private final WalletFacade walletFacade;
private final Settings settings; private final Settings settings;
private final User user; private final User user;
private final ViewModel viewModel = new ViewModel();
private Direction direction;
private NavigationController navigationController; private NavigationController navigationController;
private Direction direction;
// private Offer offer;
private AddressEntry addressEntry;
@FXML @FXML
private AnchorPane rootContainer; private AnchorPane rootContainer;
@FXML @FXML
private Label buyLabel, confirmationLabel, txTitleLabel, collateralLabel; private Label buyLabel, confirmationLabel, txTitleLabel, collateralLabel;
@FXML @FXML
private TextField volumeTextField, amountTextField, priceTextField, totalTextField; private TextField volumeTextField, amountTextField, priceTextField, totalsTextField;
@FXML @FXML
private Button placeOfferButton, closeButton; private Button placeOfferButton, closeButton;
@FXML @FXML
@ -69,6 +90,7 @@ public class CreateOfferController implements Initializable, ChildController, Hi
@FXML private AddressTextField addressTextField; @FXML private AddressTextField addressTextField;
@FXML private BalanceTextField balanceTextField; @FXML private BalanceTextField balanceTextField;
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
// Constructor // Constructor
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
@ -80,7 +102,6 @@ public class CreateOfferController implements Initializable, ChildController, Hi
this.walletFacade = walletFacade; this.walletFacade = walletFacade;
this.settings = settings; this.settings = settings;
this.user = user; this.user = user;
} }
@ -91,38 +112,27 @@ public class CreateOfferController implements Initializable, ChildController, Hi
public void setOrderBookFilter(OrderBookFilter orderBookFilter) public void setOrderBookFilter(OrderBookFilter orderBookFilter)
{ {
direction = orderBookFilter.getDirection(); direction = orderBookFilter.getDirection();
//TODO
amountTextField.setText(BitSquareFormatter.formatPrice(orderBookFilter.getAmount()));
//TODO
minAmountTextField.setText(BitSquareFormatter.formatPrice(orderBookFilter.getAmount()));
priceTextField.setText(BitSquareFormatter.formatPrice(orderBookFilter.getPrice())); viewModel.direction.set(BitSquareFormatter.formatDirection(direction, false));
buyLabel.setText(BitSquareFormatter.formatDirection(direction, false) + ":"); viewModel.amount.set(BitSquareFormatter.formatCoin(orderBookFilter.getAmount()));
collateralLabel.setText("Collateral (" + getCollateralAsPercent() + "):"); viewModel.minAmount.set(BitSquareFormatter.formatCoin(orderBookFilter.getAmount()));
viewModel.price.set(BitSquareFormatter.formatPrice(orderBookFilter.getPrice()));
updateVolume(); buyLabel.setText(viewModel.direction.get() + ":");
updateTotals(); collateralLabel.setText("Collateral (" + BitSquareFormatter.formatCollateralPercent(settings.getCollateral()) + "):");
//TODO //TODO just for dev testing
if (BitSquare.fillFormsWithDummyData) if (BitSquare.fillFormsWithDummyData)
{ {
//amountTextField.setText("" + (int) (new Random().nextDouble() * 100 / 10 + 1)); if (orderBookFilter.getAmount() != null)
{
amountTextField.setText("1"); amountTextField.setText("1");
priceTextField.setText("" + (int) (499 - new Random().nextDouble() * 1000 / 100));
minAmountTextField.setText("0.1"); minAmountTextField.setText("0.1");
} }
updateVolume(); if (orderBookFilter.getPrice() != 0)
updateTotals(); priceTextField.setText("" + (int) (499 - new Random().nextDouble() * 1000 / 100));
applyCollateral(); }
amountTextField.textProperty().addListener((observable, oldValue, newValue) -> {
updateVolume();
updateTotals();
applyCollateral();
});
priceTextField.textProperty().addListener((observable, oldValue, newValue) -> updateVolume());
} }
@ -133,6 +143,7 @@ public class CreateOfferController implements Initializable, ChildController, Hi
@Override @Override
public void initialize(URL url, ResourceBundle rb) public void initialize(URL url, ResourceBundle rb)
{ {
// static data
BankAccount currentBankAccount = user.getCurrentBankAccount(); BankAccount currentBankAccount = user.getCurrentBankAccount();
if (currentBankAccount != null) if (currentBankAccount != null)
{ {
@ -142,13 +153,48 @@ public class CreateOfferController implements Initializable, ChildController, Hi
} }
acceptedCountriesTextField.setText(BitSquareFormatter.countryLocalesToString(settings.getAcceptedCountries())); acceptedCountriesTextField.setText(BitSquareFormatter.countryLocalesToString(settings.getAcceptedCountries()));
acceptedLanguagesTextField.setText(BitSquareFormatter.languageLocalesToString(settings.getAcceptedLanguageLocales())); acceptedLanguagesTextField.setText(BitSquareFormatter.languageLocalesToString(settings.getAcceptedLanguageLocales()));
feeLabel.setText(BitSquareFormatter.formatCoinToBtcWithCode(FeePolicy.CREATE_OFFER_FEE.add(FeePolicy.TX_FEE)));
addressEntry = walletFacade.getUnusedTradeAddressInfo(); feeLabel.setText(BitSquareFormatter.formatCoinWithCode(FeePolicy.CREATE_OFFER_FEE.add(FeePolicy.TX_FEE)));
AddressEntry addressEntry = walletFacade.getUnusedTradeAddressInfo();
addressTextField.setAddress(addressEntry.getAddress().toString()); addressTextField.setAddress(addressEntry.getAddress().toString());
balanceTextField.setAddress(addressEntry.getAddress()); balanceTextField.setAddress(addressEntry.getAddress());
balanceTextField.setWalletFacade(walletFacade); balanceTextField.setWalletFacade(walletFacade);
// setup bindings
DoubleBinding amountBinding = createDoubleBinding(() -> BitSquareConverter.stringToDouble(viewModel.amount.get()), viewModel.amount);
DoubleBinding priceBinding = createDoubleBinding(() -> BitSquareConverter.stringToDouble(viewModel.price.get()), viewModel.price);
viewModel.volume.bind(createStringBinding(() -> BitSquareFormatter.formatVolume(amountBinding.get() * priceBinding.get()), amountBinding, priceBinding));
viewModel.collateral.bind(createStringBinding(() -> {
Coin amountAsCoin = BitSquareFormatter.parseToCoin(viewModel.amount.get());
Coin collateralAsCoin = amountAsCoin.divide((long) (1d / settings.getCollateral()));
return BitSquareFormatter.formatCoinWithCode(collateralAsCoin);
}, amountBinding));
viewModel.totals.bind(createStringBinding(() -> {
Coin amountAsCoin = BitSquareFormatter.parseToCoin(viewModel.amount.get());
Coin collateralAsCoin = amountAsCoin.divide((long) (1d / settings.getCollateral()));
Coin totals = FeePolicy.CREATE_OFFER_FEE.add(collateralAsCoin).add(FeePolicy.TX_FEE);
return BitSquareFormatter.formatCoinWithCode(totals);
}, amountBinding, priceBinding));
// apply bindings to controls
amountTextField.textProperty().bindBidirectional(viewModel.amount);
priceTextField.textProperty().bindBidirectional(viewModel.price);
minAmountTextField.textProperty().bindBidirectional(viewModel.minAmount);
volumeTextField.textProperty().bind(viewModel.volume);
collateralTextField.textProperty().bind(viewModel.collateral);
totalsTextField.textProperty().bind(viewModel.totals);
placeOfferButton.visibleProperty().bind(viewModel.isOfferPlacedScreen.not());
progressIndicator.visibleProperty().bind(viewModel.isOfferPlacedScreen);
confirmationLabel.visibleProperty().bind(viewModel.isOfferPlacedScreen);
txTitleLabel.visibleProperty().bind(viewModel.isOfferPlacedScreen);
txTextField.visibleProperty().bind(viewModel.isOfferPlacedScreen);
closeButton.visibleProperty().bind(viewModel.isOfferPlacedScreen);
} }
@ -187,45 +233,6 @@ public class CreateOfferController implements Initializable, ChildController, Hi
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
// UI Handlers // UI Handlers
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
public boolean inputsValid()
{
boolean inputFieldsValid;
double priceAsDouble = BitSquareConverter.stringToDouble(priceTextField.getText());
double minAmountAsDouble = BitSquareConverter.stringToDouble(minAmountTextField.getText());
double amountAsDouble = BitSquareConverter.stringToDouble(getAmountString());
double collateralAsDouble = BitSquareConverter.stringToDouble(collateralTextField.getText());
inputFieldsValid = priceAsDouble > 0 &&
amountAsDouble > 0 &&
minAmountAsDouble > 0 &&
minAmountAsDouble <= amountAsDouble/* &&
collateralAsDouble >= settings.getMinCollateral() &&
collateralAsDouble <= settings.getMaxCollateral()*/;
if (!inputFieldsValid)
{
Popups.openWarningPopup("Invalid input", "Your input is invalid");
return false;
}
Arbitrator arbitrator = settings.getRandomArbitrator(getAmountAsCoin());
if (arbitrator == null)
{
Popups.openWarningPopup("No arbitrator available", "No arbitrator from your arbitrator list does match the collateral and amount value.");
return false;
}
if (user.getCurrentBankAccount() == null)
{
log.error("Must never happen!");
Popups.openWarningPopup("No bank account selected", "No bank account selected.");
return false;
}
return true;
}
@FXML @FXML
public void onPlaceOffer() public void onPlaceOffer()
{ {
@ -233,15 +240,18 @@ public class CreateOfferController implements Initializable, ChildController, Hi
{ {
placeOfferButton.setDisable(true); placeOfferButton.setDisable(true);
double price = BitSquareConverter.stringToDouble(priceTextField.getText()); double price = BitSquareConverter.stringToDouble(viewModel.price.get());
Coin amount = BitSquareFormatter.parseBtcToCoin(getAmountString()); Coin amount = BitSquareFormatter.parseToCoin(viewModel.amount.get());
Coin minAmount = BitSquareFormatter.parseBtcToCoin(getMinAmountString()); Coin minAmount = BitSquareFormatter.parseToCoin(viewModel.minAmount.get());
tradeManager.requestPlaceOffer(direction, tradeManager.requestPlaceOffer(direction,
price, price,
amount, amount,
minAmount, minAmount,
(transaction) -> setupSuccessScreen(transaction.getHashAsString()), (transaction) -> {
viewModel.isOfferPlacedScreen.set(true);
txTextField.setText(transaction.getHashAsString());
},
errorMessage -> { errorMessage -> {
Popups.openErrorPopup("An error occurred", errorMessage); Popups.openErrorPopup("An error occurred", errorMessage);
placeOfferButton.setDisable(false); placeOfferButton.setDisable(false);
@ -249,6 +259,7 @@ public class CreateOfferController implements Initializable, ChildController, Hi
} }
} }
@FXML
public void onClose() public void onClose()
{ {
TabPane tabPane = ((TabPane) (rootContainer.getParent().getParent())); TabPane tabPane = ((TabPane) (rootContainer.getParent().getParent()));
@ -262,91 +273,42 @@ public class CreateOfferController implements Initializable, ChildController, Hi
// Private methods // Private methods
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
private void setupSuccessScreen(String transactionId) private boolean inputsValid()
{ {
placeOfferButton.setVisible(false); //TODO
boolean inputFieldsValid;
double amount = BitSquareConverter.stringToDouble(viewModel.amount.get());
double minAmount = BitSquareConverter.stringToDouble(viewModel.minAmount.get());
double price = BitSquareConverter.stringToDouble(viewModel.price.get());
progressIndicator.setVisible(true); inputFieldsValid = price > 0 &&
confirmationLabel.setVisible(true); amount > 0 &&
txTitleLabel.setVisible(true); minAmount > 0 &&
txTextField.setVisible(true); minAmount <= amount/* &&
closeButton.setVisible(true); viewModel.collateral >= settings.getMinCollateral() &&
viewModel.collateral <= settings.getMaxCollateral()*/;
txTextField.setText(transactionId); if (!inputFieldsValid)
{
Popups.openWarningPopup("Invalid input", "Your input is invalid");
return false;
} }
private void updateTotals() /* Arbitrator arbitrator = settings.getRandomArbitrator(getAmountAsCoin());
if (arbitrator == null)
{ {
Coin amountAsCoin = BitSquareFormatter.parseBtcToCoin(getAmountString()); Popups.openWarningPopup("No arbitrator available", "No arbitrator from your arbitrator list does match the collateral and amount value.");
Coin collateral = amountAsCoin.divide((long) (1d / getCollateral())); return false;
Coin totals = FeePolicy.CREATE_OFFER_FEE.add(collateral).add(FeePolicy.TX_FEE); }*/
totalTextField.setText(BitSquareFormatter.formatCoinToBtcWithCode(totals));
if (user.getCurrentBankAccount() == null)
{
log.error("Must never happen!");
Popups.openWarningPopup("No bank account selected", "No bank account selected.");
return false;
} }
private void updateVolume() return true;
{
volumeTextField.setText(BitSquareFormatter.formatVolume(getVolume()));
} }
private double getVolume()
{
double amountAsDouble = BitSquareConverter.stringToDouble(getAmountString());
double priceAsDouble = BitSquareConverter.stringToDouble(priceTextField.getText());
return amountAsDouble * priceAsDouble;
}
private void applyCollateral()
{
collateralTextField.setText(getFormattedCollateralAsBtc());
}
private String getFormattedCollateralAsBtc()
{
Coin amountAsCoin = BitSquareFormatter.parseBtcToCoin(getAmountString());
Coin collateralAsCoin = amountAsCoin.divide((long) (1d / getCollateral()));
return BitSquareFormatter.formatCoinToBtc(collateralAsCoin);
}
private String getCollateralAsPercent()
{
return BitSquareFormatter.formatCollateralPercent(getCollateral());
}
private Coin getAmountAsCoin()
{
return BitSquareFormatter.parseBtcToCoin(getAmountString());
}
private String getAmountString()
{
try
{
BitSquareValidator.textFieldsHasPositiveDoubleValueWithReset(amountTextField);
return amountTextField.getText();
} catch (BitSquareValidator.ValidationException e)
{
return "0";
}
}
private String getMinAmountString()
{
try
{
BitSquareValidator.textFieldsHasPositiveDoubleValueWithReset(minAmountTextField);
return minAmountTextField.getText();
} catch (BitSquareValidator.ValidationException e)
{
return "0";
}
}
private double getCollateral()
{
// TODO
return settings.getCollateral();
}
} }

View file

@ -34,7 +34,7 @@
<TextField fx:id="feeLabel" editable="false" GridPane.columnIndex="1" GridPane.rowIndex="4"/> <TextField fx:id="feeLabel" editable="false" GridPane.columnIndex="1" GridPane.rowIndex="4"/>
<Label text="Total funds needed:" GridPane.rowIndex="5"/> <Label text="Total funds needed:" GridPane.rowIndex="5"/>
<TextField fx:id="totalTextField" editable="false" GridPane.columnIndex="1" GridPane.rowIndex="5"/> <TextField fx:id="totalsTextField" editable="false" GridPane.columnIndex="1" GridPane.rowIndex="5"/>
<Label text="BTC address for deposit:" GridPane.rowIndex="6"/> <Label text="BTC address for deposit:" GridPane.rowIndex="6"/>
<AddressTextField fx:id="addressTextField" GridPane.columnIndex="1" GridPane.rowIndex="6"/> <AddressTextField fx:id="addressTextField" GridPane.columnIndex="1" GridPane.rowIndex="6"/>

View file

@ -128,7 +128,7 @@ public class OrderBookController implements Initializable, ChildController
// handlers // handlers
amount.textProperty().addListener((observable, oldValue, newValue) -> { amount.textProperty().addListener((observable, oldValue, newValue) -> {
orderBookFilter.setAmount(textInputToNumber(oldValue, newValue)); orderBookFilter.setAmount(BitSquareFormatter.parseToCoin(newValue));
updateVolume(); updateVolume();
}); });
@ -230,7 +230,7 @@ public class OrderBookController implements Initializable, ChildController
else else
{ {
Action response = Popups.openErrorPopup("Missing registration fee", Action response = Popups.openErrorPopup("Missing registration fee",
"You have not funded the full registration fee of " + BitSquareFormatter.formatCoinToBtcWithCode(FeePolicy.ACCOUNT_REGISTRATION_FEE) + " BTC."); "You have not funded the full registration fee of " + BitSquareFormatter.formatCoinWithCode(FeePolicy.ACCOUNT_REGISTRATION_FEE) + " BTC.");
if (response == Dialog.Actions.OK) if (response == Dialog.Actions.OK)
{ {
MainController.GET_INSTANCE().navigateToView(NavigationItem.FUNDS); MainController.GET_INSTANCE().navigateToView(NavigationItem.FUNDS);
@ -344,7 +344,7 @@ public class OrderBookController implements Initializable, ChildController
Coin requestedAmount; Coin requestedAmount;
if (!"".equals(amount.getText())) if (!"".equals(amount.getText()))
{ {
requestedAmount = BitSquareFormatter.parseBtcToCoin(amount.getText()); requestedAmount = BitSquareFormatter.parseToCoin(amount.getText());
} }
else else
{ {
@ -550,6 +550,7 @@ public class OrderBookController implements Initializable, ChildController
// Utils // Utils
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
private double textInputToNumber(String oldValue, String newValue) private double textInputToNumber(String oldValue, String newValue)
{ {
//TODO use regex.... or custom textfield component //TODO use regex.... or custom textfield component

View file

@ -19,7 +19,7 @@ public class OrderBookListItem
{ {
this.offer = offer; this.offer = offer;
this.price.set(BitSquareFormatter.formatPrice(offer.getPrice())); this.price.set(BitSquareFormatter.formatPrice(offer.getPrice()));
this.amount.set(BitSquareFormatter.formatCoinToBtc(offer.getAmount()) + " (" + BitSquareFormatter.formatCoinToBtc(offer.getMinAmount()) + ")"); this.amount.set(BitSquareFormatter.formatCoin(offer.getAmount()) + " (" + BitSquareFormatter.formatCoin(offer.getMinAmount()) + ")");
this.volume.set(BitSquareFormatter.formatVolumeWithMinVolume(offer.getOfferVolume(), offer.getMinOfferVolume())); this.volume.set(BitSquareFormatter.formatVolumeWithMinVolume(offer.getOfferVolume(), offer.getMinOfferVolume()));
} }

View file

@ -102,13 +102,13 @@ public class TakerOfferController implements Initializable, ChildController
public void applyData() public void applyData()
{ {
amountTextField.setText(requestedAmount.toPlainString()); amountTextField.setText(requestedAmount.toPlainString());
amountTextField.setPromptText(BitSquareFormatter.formatCoinToBtcWithCode(offer.getMinAmount()) + " - " + BitSquareFormatter.formatCoinToBtcWithCode(offer.getAmount())); amountTextField.setPromptText(BitSquareFormatter.formatCoinWithCode(offer.getMinAmount()) + " - " + BitSquareFormatter.formatCoinWithCode(offer.getAmount()));
priceTextField.setText(BitSquareFormatter.formatPrice(offer.getPrice())); priceTextField.setText(BitSquareFormatter.formatPrice(offer.getPrice()));
applyVolume(); applyVolume();
collateralLabel.setText("Collateral (" + getCollateralAsPercent() + "):"); collateralLabel.setText("Collateral (" + getCollateralAsPercent() + "):");
applyCollateral(); applyCollateral();
applyTotal(); applyTotal();
feeTextField.setText(BitSquareFormatter.formatCoinToBtcWithCode(getFee())); feeTextField.setText(BitSquareFormatter.formatCoinWithCode(getFee()));
totalTextField.setText(getFormattedTotal()); totalTextField.setText(getFormattedTotal());
bankAccountTypeTextField.setText(offer.getBankAccountType().toString()); bankAccountTypeTextField.setText(offer.getBankAccountType().toString());
@ -152,7 +152,7 @@ public class TakerOfferController implements Initializable, ChildController
public void onTakeOffer() public void onTakeOffer()
{ {
AddressEntry addressEntry = walletFacade.getAddressInfoByTradeID(offer.getId()); AddressEntry addressEntry = walletFacade.getAddressInfoByTradeID(offer.getId());
Coin amount = BitSquareFormatter.parseBtcToCoin(getAmountString()); Coin amount = BitSquareFormatter.parseToCoin(getAmountString());
// TODO more validation (fee payment, blacklist,...) // TODO more validation (fee payment, blacklist,...)
if (amountTextField.isInvalid()) if (amountTextField.isInvalid())
{ {
@ -201,10 +201,10 @@ public class TakerOfferController implements Initializable, ChildController
{ {
accordion.setExpandedPane(summaryTitledPane); accordion.setExpandedPane(summaryTitledPane);
summaryPaidTextField.setText(BitSquareFormatter.formatCoinToBtcWithCode(trade.getTradeAmount())); summaryPaidTextField.setText(BitSquareFormatter.formatCoinWithCode(trade.getTradeAmount()));
summaryReceivedTextField.setText(BitSquareFormatter.formatVolume(trade.getTradeVolume())); summaryReceivedTextField.setText(BitSquareFormatter.formatVolume(trade.getTradeVolume()));
summaryFeesTextField.setText(BitSquareFormatter.formatCoinToBtcWithCode(FeePolicy.TAKE_OFFER_FEE.add(FeePolicy.TX_FEE))); summaryFeesTextField.setText(BitSquareFormatter.formatCoinWithCode(FeePolicy.TAKE_OFFER_FEE.add(FeePolicy.TX_FEE)));
summaryCollateralTextField.setText(BitSquareFormatter.formatCoinToBtcWithCode(trade.getCollateralAmount())); summaryCollateralTextField.setText(BitSquareFormatter.formatCoinWithCode(trade.getCollateralAmount()));
summaryDepositTxIdTextField.setText(depositTxId); summaryDepositTxIdTextField.setText(depositTxId);
summaryPayoutTxIdTextField.setText(payoutTxId); summaryPayoutTxIdTextField.setText(payoutTxId);
} }
@ -283,7 +283,7 @@ public class TakerOfferController implements Initializable, ChildController
private String getFormattedTotal() private String getFormattedTotal()
{ {
return BitSquareFormatter.formatCoinToBtcWithCode(getTotal()); return BitSquareFormatter.formatCoinWithCode(getTotal());
} }
@ -295,7 +295,7 @@ public class TakerOfferController implements Initializable, ChildController
private Coin getAmountInSatoshis() private Coin getAmountInSatoshis()
{ {
return BitSquareFormatter.parseBtcToCoin(getAmountString()); return BitSquareFormatter.parseToCoin(getAmountString());
} }
private String getAmountString() private String getAmountString()
@ -327,15 +327,15 @@ public class TakerOfferController implements Initializable, ChildController
private Coin getCollateralAsCoin() private Coin getCollateralAsCoin()
{ {
Coin amountAsCoin = BitSquareFormatter.parseBtcToCoin(getAmountString()); Coin amountAsCoin = BitSquareFormatter.parseToCoin(getAmountString());
return amountAsCoin.divide((long) (1d / offer.getCollateral())); return amountAsCoin.divide((long) (1d / offer.getCollateral()));
} }
private String getFormattedCollateralAsBtc() private String getFormattedCollateralAsBtc()
{ {
Coin amountAsCoin = BitSquareFormatter.parseBtcToCoin(getAmountString()); Coin amountAsCoin = BitSquareFormatter.parseToCoin(getAmountString());
Coin collateralAsCoin = amountAsCoin.divide((long) (1d / getCollateral())); Coin collateralAsCoin = amountAsCoin.divide((long) (1d / getCollateral()));
return BitSquareFormatter.formatCoinToBtc(collateralAsCoin); return BitSquareFormatter.formatCoin(collateralAsCoin);
} }
private String getCollateralAsPercent() private String getCollateralAsPercent()

View file

@ -22,7 +22,7 @@ public class OfferListItem
this.date.set(BitSquareFormatter.formatDateTime(offer.getCreationDate())); this.date.set(BitSquareFormatter.formatDateTime(offer.getCreationDate()));
this.price.set(BitSquareFormatter.formatPrice(offer.getPrice())); this.price.set(BitSquareFormatter.formatPrice(offer.getPrice()));
this.amount.set(BitSquareFormatter.formatCoinToBtc(offer.getAmount()) + " (" + BitSquareFormatter.formatCoinToBtc(offer.getMinAmount()) + ")"); this.amount.set(BitSquareFormatter.formatCoin(offer.getAmount()) + " (" + BitSquareFormatter.formatCoin(offer.getMinAmount()) + ")");
this.volume.set(BitSquareFormatter.formatVolumeWithMinVolume(offer.getOfferVolume(), offer.getMinOfferVolume())); this.volume.set(BitSquareFormatter.formatVolumeWithMinVolume(offer.getOfferVolume(), offer.getMinOfferVolume()));
this.offerId = offer.getId(); this.offerId = offer.getId();
} }

View file

@ -297,10 +297,10 @@ public class PendingTradeController implements Initializable, ChildController, H
primaryBankAccountIDTitleLabel.setText("Total fees (offer fee + tx fee):"); primaryBankAccountIDTitleLabel.setText("Total fees (offer fee + tx fee):");
secondaryBankAccountIDTitleLabel.setText("Refunded collateral:"); secondaryBankAccountIDTitleLabel.setText("Refunded collateral:");
bankAccountTypeTextField.setText(BitSquareFormatter.formatCoinToBtcWithCode(trade.getTradeAmount())); bankAccountTypeTextField.setText(BitSquareFormatter.formatCoinWithCode(trade.getTradeAmount()));
holderNameTextField.setText(BitSquareFormatter.formatVolume(trade.getTradeVolume())); holderNameTextField.setText(BitSquareFormatter.formatVolume(trade.getTradeVolume()));
primaryBankAccountIDTextField.setText(BitSquareFormatter.formatCoinToBtcWithCode(FeePolicy.CREATE_OFFER_FEE.add(FeePolicy.TX_FEE))); primaryBankAccountIDTextField.setText(BitSquareFormatter.formatCoinWithCode(FeePolicy.CREATE_OFFER_FEE.add(FeePolicy.TX_FEE)));
secondaryBankAccountIDTextField.setText(BitSquareFormatter.formatCoinToBtcWithCode(trade.getCollateralAmount())); secondaryBankAccountIDTextField.setText(BitSquareFormatter.formatCoinWithCode(trade.getCollateralAmount()));
holderNameCopyIcon.setVisible(false); holderNameCopyIcon.setVisible(false);
primaryBankAccountIDCopyIcon.setVisible(false); primaryBankAccountIDCopyIcon.setVisible(false);

View file

@ -22,19 +22,20 @@ public class BitSquareFormatter
// BTC // BTC
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
public static String formatCoinToBtc(Coin coin) public static String formatCoin(Coin coin)
{ {
return coin.toFriendlyString(); return coin != null ? coin.toPlainString() : "";
} }
/* public static String formatCoinToBtcWithSymbol(Coin coin)
/* public static String formatCoinToWithSymbol(Coin coin)
{ {
return "฿ " + coin.toPlainString(); return "฿ " + coin.toPlainString();
} */ } */
public static String formatCoinToBtcWithCode(Coin coin) public static String formatCoinWithCode(Coin coin)
{ {
return coin.toFriendlyString(); return coin != null ? coin.toFriendlyString() : "";
} }
/** /**
@ -42,7 +43,7 @@ public class BitSquareFormatter
* If input has an incorrect format it returns a zero value coin. * If input has an incorrect format it returns a zero value coin.
* @return * @return
*/ */
public static Coin parseBtcToCoin(String input) public static Coin parseToCoin(String input)
{ {
try try
{ {
@ -62,6 +63,7 @@ public class BitSquareFormatter
// FIAT // FIAT
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
public static String formatPrice(double price) public static String formatPrice(double price)
{ {
return formatDouble(price); return formatDouble(price);

View file

@ -113,11 +113,8 @@ public class OrderBook implements OrderBookListener
// Apply applyFilter only if there is a valid value set // Apply applyFilter only if there is a valid value set
// The requested amount must be lower or equal then the offer amount // The requested amount must be lower or equal then the offer amount
boolean amountResult = true; boolean amountResult = true;
if (orderBookFilter.getAmount() > 0) if (orderBookFilter.getAmount() != null)
{ amountResult = orderBookFilter.getAmount().compareTo(offer.getAmount()) <= 0;
//TODO
amountResult = orderBookFilter.getAmount() <= offer.getAmount().value;
}
// The requested trade direction must be opposite of the offerList trade direction // The requested trade direction must be opposite of the offerList trade direction
boolean directionResult = !orderBookFilter.getDirection().equals(offer.getDirection()); boolean directionResult = !orderBookFilter.getDirection().equals(offer.getDirection());

View file

@ -1,5 +1,6 @@
package io.bitsquare.trade.orderbook; package io.bitsquare.trade.orderbook;
import com.google.bitcoin.core.Coin;
import io.bitsquare.trade.Direction; import io.bitsquare.trade.Direction;
import javafx.beans.property.SimpleBooleanProperty; import javafx.beans.property.SimpleBooleanProperty;
@ -8,7 +9,7 @@ public class OrderBookFilter
private final SimpleBooleanProperty directionChangedProperty = new SimpleBooleanProperty(); private final SimpleBooleanProperty directionChangedProperty = new SimpleBooleanProperty();
private double price; private double price;
private double amount; private Coin amount;
private Direction direction; private Direction direction;
@ -16,12 +17,12 @@ public class OrderBookFilter
// Setters // Setters
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
public double getAmount() public Coin getAmount()
{ {
return amount; return amount;
} }
public void setAmount(double amount) public void setAmount(Coin amount)
{ {
this.amount = amount; this.amount = amount;
} }