mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-03-15 10:26:37 -04:00
use bindings in create offer controller
This commit is contained in:
parent
daecafa3c1
commit
a9be983caa
@ -155,7 +155,7 @@ public class WithdrawalController implements Initializable, ChildController, Hib
|
||||
BitSquareValidator.textFieldsNotEmpty(amountTextField, withdrawFromTextField, withdrawToTextField, changeAddressTextField);
|
||||
BitSquareValidator.textFieldsHasDoubleValueWithReset(amountTextField);
|
||||
|
||||
Coin amount = BitSquareFormatter.parseBtcToCoin(amountTextField.getText());
|
||||
Coin amount = BitSquareFormatter.parseToCoin(amountTextField.getText());
|
||||
if (BtcValidator.isMinSpendableAmount(amount))
|
||||
{
|
||||
FutureCallback<Transaction> callback = new FutureCallback<Transaction>()
|
||||
@ -181,8 +181,8 @@ public class WithdrawalController implements Initializable, ChildController, Hib
|
||||
"Amount: " + amountTextField.getText() + " BTC\n" +
|
||||
"Sending address: " + withdrawFromTextField.getText() + "\n" +
|
||||
"Receiving address: " + withdrawToTextField.getText() + "\n" +
|
||||
"Transaction fee: " + BitSquareFormatter.formatCoinToBtcWithCode(FeePolicy.TX_FEE) + "\n" +
|
||||
"You receive in total: " + BitSquareFormatter.formatCoinToBtcWithCode(amount.subtract(FeePolicy.TX_FEE)) + " BTC\n\n" +
|
||||
"Transaction fee: " + BitSquareFormatter.formatCoinWithCode(FeePolicy.TX_FEE) + "\n" +
|
||||
"You receive in total: " + BitSquareFormatter.formatCoinWithCode(amount.subtract(FeePolicy.TX_FEE)) + " BTC\n\n" +
|
||||
"Are you sure you withdraw that amount?");
|
||||
if (response == Dialog.Actions.OK)
|
||||
{
|
||||
|
@ -16,17 +16,20 @@ import io.bitsquare.gui.components.confidence.ConfidenceProgressIndicator;
|
||||
import io.bitsquare.gui.popups.Popups;
|
||||
import io.bitsquare.gui.util.BitSquareConverter;
|
||||
import io.bitsquare.gui.util.BitSquareFormatter;
|
||||
import io.bitsquare.gui.util.BitSquareValidator;
|
||||
import io.bitsquare.locale.Localisation;
|
||||
import io.bitsquare.settings.Settings;
|
||||
import io.bitsquare.trade.Direction;
|
||||
import io.bitsquare.trade.TradeManager;
|
||||
import io.bitsquare.trade.orderbook.OrderBookFilter;
|
||||
import io.bitsquare.user.Arbitrator;
|
||||
import io.bitsquare.user.User;
|
||||
import java.net.URL;
|
||||
import java.util.Random;
|
||||
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.Initializable;
|
||||
import javafx.scene.control.Button;
|
||||
@ -38,6 +41,26 @@ import javax.inject.Inject;
|
||||
import org.slf4j.Logger;
|
||||
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
|
||||
{
|
||||
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 Settings settings;
|
||||
private final User user;
|
||||
|
||||
private final ViewModel viewModel = new ViewModel();
|
||||
private Direction direction;
|
||||
|
||||
private NavigationController navigationController;
|
||||
private Direction direction;
|
||||
// private Offer offer;
|
||||
private AddressEntry addressEntry;
|
||||
|
||||
@FXML
|
||||
private AnchorPane rootContainer;
|
||||
@FXML
|
||||
private Label buyLabel, confirmationLabel, txTitleLabel, collateralLabel;
|
||||
@FXML
|
||||
private TextField volumeTextField, amountTextField, priceTextField, totalTextField;
|
||||
private TextField volumeTextField, amountTextField, priceTextField, totalsTextField;
|
||||
@FXML
|
||||
private Button placeOfferButton, closeButton;
|
||||
@FXML
|
||||
@ -69,6 +90,7 @@ public class CreateOfferController implements Initializable, ChildController, Hi
|
||||
@FXML private AddressTextField addressTextField;
|
||||
@FXML private BalanceTextField balanceTextField;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Constructor
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -80,7 +102,6 @@ public class CreateOfferController implements Initializable, ChildController, Hi
|
||||
this.walletFacade = walletFacade;
|
||||
this.settings = settings;
|
||||
this.user = user;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -91,38 +112,27 @@ public class CreateOfferController implements Initializable, ChildController, Hi
|
||||
public void setOrderBookFilter(OrderBookFilter orderBookFilter)
|
||||
{
|
||||
direction = orderBookFilter.getDirection();
|
||||
//TODO
|
||||
amountTextField.setText(BitSquareFormatter.formatPrice(orderBookFilter.getAmount()));
|
||||
//TODO
|
||||
minAmountTextField.setText(BitSquareFormatter.formatPrice(orderBookFilter.getAmount()));
|
||||
|
||||
priceTextField.setText(BitSquareFormatter.formatPrice(orderBookFilter.getPrice()));
|
||||
buyLabel.setText(BitSquareFormatter.formatDirection(direction, false) + ":");
|
||||
collateralLabel.setText("Collateral (" + getCollateralAsPercent() + "):");
|
||||
viewModel.direction.set(BitSquareFormatter.formatDirection(direction, false));
|
||||
viewModel.amount.set(BitSquareFormatter.formatCoin(orderBookFilter.getAmount()));
|
||||
viewModel.minAmount.set(BitSquareFormatter.formatCoin(orderBookFilter.getAmount()));
|
||||
viewModel.price.set(BitSquareFormatter.formatPrice(orderBookFilter.getPrice()));
|
||||
|
||||
updateVolume();
|
||||
updateTotals();
|
||||
buyLabel.setText(viewModel.direction.get() + ":");
|
||||
collateralLabel.setText("Collateral (" + BitSquareFormatter.formatCollateralPercent(settings.getCollateral()) + "):");
|
||||
|
||||
//TODO
|
||||
//TODO just for dev testing
|
||||
if (BitSquare.fillFormsWithDummyData)
|
||||
{
|
||||
//amountTextField.setText("" + (int) (new Random().nextDouble() * 100 / 10 + 1));
|
||||
amountTextField.setText("1");
|
||||
priceTextField.setText("" + (int) (499 - new Random().nextDouble() * 1000 / 100));
|
||||
minAmountTextField.setText("0.1");
|
||||
if (orderBookFilter.getAmount() != null)
|
||||
{
|
||||
amountTextField.setText("1");
|
||||
minAmountTextField.setText("0.1");
|
||||
}
|
||||
|
||||
if (orderBookFilter.getPrice() != 0)
|
||||
priceTextField.setText("" + (int) (499 - new Random().nextDouble() * 1000 / 100));
|
||||
}
|
||||
|
||||
updateVolume();
|
||||
updateTotals();
|
||||
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
|
||||
public void initialize(URL url, ResourceBundle rb)
|
||||
{
|
||||
// static data
|
||||
BankAccount currentBankAccount = user.getCurrentBankAccount();
|
||||
if (currentBankAccount != null)
|
||||
{
|
||||
@ -142,13 +153,48 @@ public class CreateOfferController implements Initializable, ChildController, Hi
|
||||
}
|
||||
acceptedCountriesTextField.setText(BitSquareFormatter.countryLocalesToString(settings.getAcceptedCountries()));
|
||||
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());
|
||||
|
||||
balanceTextField.setAddress(addressEntry.getAddress());
|
||||
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
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
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
|
||||
public void onPlaceOffer()
|
||||
{
|
||||
@ -233,15 +240,18 @@ public class CreateOfferController implements Initializable, ChildController, Hi
|
||||
{
|
||||
placeOfferButton.setDisable(true);
|
||||
|
||||
double price = BitSquareConverter.stringToDouble(priceTextField.getText());
|
||||
Coin amount = BitSquareFormatter.parseBtcToCoin(getAmountString());
|
||||
Coin minAmount = BitSquareFormatter.parseBtcToCoin(getMinAmountString());
|
||||
double price = BitSquareConverter.stringToDouble(viewModel.price.get());
|
||||
Coin amount = BitSquareFormatter.parseToCoin(viewModel.amount.get());
|
||||
Coin minAmount = BitSquareFormatter.parseToCoin(viewModel.minAmount.get());
|
||||
|
||||
tradeManager.requestPlaceOffer(direction,
|
||||
price,
|
||||
amount,
|
||||
minAmount,
|
||||
(transaction) -> setupSuccessScreen(transaction.getHashAsString()),
|
||||
(transaction) -> {
|
||||
viewModel.isOfferPlacedScreen.set(true);
|
||||
txTextField.setText(transaction.getHashAsString());
|
||||
},
|
||||
errorMessage -> {
|
||||
Popups.openErrorPopup("An error occurred", errorMessage);
|
||||
placeOfferButton.setDisable(false);
|
||||
@ -249,6 +259,7 @@ public class CreateOfferController implements Initializable, ChildController, Hi
|
||||
}
|
||||
}
|
||||
|
||||
@FXML
|
||||
public void onClose()
|
||||
{
|
||||
TabPane tabPane = ((TabPane) (rootContainer.getParent().getParent()));
|
||||
@ -262,91 +273,42 @@ public class CreateOfferController implements Initializable, ChildController, Hi
|
||||
// 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);
|
||||
confirmationLabel.setVisible(true);
|
||||
txTitleLabel.setVisible(true);
|
||||
txTextField.setVisible(true);
|
||||
closeButton.setVisible(true);
|
||||
inputFieldsValid = price > 0 &&
|
||||
amount > 0 &&
|
||||
minAmount > 0 &&
|
||||
minAmount <= amount/* &&
|
||||
viewModel.collateral >= settings.getMinCollateral() &&
|
||||
viewModel.collateral <= settings.getMaxCollateral()*/;
|
||||
|
||||
txTextField.setText(transactionId);
|
||||
}
|
||||
|
||||
private void updateTotals()
|
||||
{
|
||||
Coin amountAsCoin = BitSquareFormatter.parseBtcToCoin(getAmountString());
|
||||
Coin collateral = amountAsCoin.divide((long) (1d / getCollateral()));
|
||||
Coin totals = FeePolicy.CREATE_OFFER_FEE.add(collateral).add(FeePolicy.TX_FEE);
|
||||
totalTextField.setText(BitSquareFormatter.formatCoinToBtcWithCode(totals));
|
||||
}
|
||||
|
||||
private void updateVolume()
|
||||
{
|
||||
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
|
||||
if (!inputFieldsValid)
|
||||
{
|
||||
BitSquareValidator.textFieldsHasPositiveDoubleValueWithReset(amountTextField);
|
||||
return amountTextField.getText();
|
||||
} catch (BitSquareValidator.ValidationException e)
|
||||
{
|
||||
return "0";
|
||||
Popups.openWarningPopup("Invalid input", "Your input is invalid");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private String getMinAmountString()
|
||||
{
|
||||
try
|
||||
/* Arbitrator arbitrator = settings.getRandomArbitrator(getAmountAsCoin());
|
||||
if (arbitrator == null)
|
||||
{
|
||||
BitSquareValidator.textFieldsHasPositiveDoubleValueWithReset(minAmountTextField);
|
||||
return minAmountTextField.getText();
|
||||
} catch (BitSquareValidator.ValidationException e)
|
||||
Popups.openWarningPopup("No arbitrator available", "No arbitrator from your arbitrator list does match the collateral and amount value.");
|
||||
return false;
|
||||
}*/
|
||||
|
||||
if (user.getCurrentBankAccount() == null)
|
||||
{
|
||||
return "0";
|
||||
log.error("Must never happen!");
|
||||
Popups.openWarningPopup("No bank account selected", "No bank account selected.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private double getCollateral()
|
||||
{
|
||||
// TODO
|
||||
return settings.getCollateral();
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,7 @@
|
||||
<TextField fx:id="feeLabel" editable="false" GridPane.columnIndex="1" GridPane.rowIndex="4"/>
|
||||
|
||||
<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"/>
|
||||
<AddressTextField fx:id="addressTextField" GridPane.columnIndex="1" GridPane.rowIndex="6"/>
|
||||
|
@ -128,7 +128,7 @@ public class OrderBookController implements Initializable, ChildController
|
||||
|
||||
// handlers
|
||||
amount.textProperty().addListener((observable, oldValue, newValue) -> {
|
||||
orderBookFilter.setAmount(textInputToNumber(oldValue, newValue));
|
||||
orderBookFilter.setAmount(BitSquareFormatter.parseToCoin(newValue));
|
||||
updateVolume();
|
||||
});
|
||||
|
||||
@ -230,7 +230,7 @@ public class OrderBookController implements Initializable, ChildController
|
||||
else
|
||||
{
|
||||
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)
|
||||
{
|
||||
MainController.GET_INSTANCE().navigateToView(NavigationItem.FUNDS);
|
||||
@ -344,7 +344,7 @@ public class OrderBookController implements Initializable, ChildController
|
||||
Coin requestedAmount;
|
||||
if (!"".equals(amount.getText()))
|
||||
{
|
||||
requestedAmount = BitSquareFormatter.parseBtcToCoin(amount.getText());
|
||||
requestedAmount = BitSquareFormatter.parseToCoin(amount.getText());
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -550,6 +550,7 @@ public class OrderBookController implements Initializable, ChildController
|
||||
// Utils
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
private double textInputToNumber(String oldValue, String newValue)
|
||||
{
|
||||
//TODO use regex.... or custom textfield component
|
||||
|
@ -19,7 +19,7 @@ public class OrderBookListItem
|
||||
{
|
||||
this.offer = offer;
|
||||
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()));
|
||||
}
|
||||
|
||||
|
@ -102,13 +102,13 @@ public class TakerOfferController implements Initializable, ChildController
|
||||
public void applyData()
|
||||
{
|
||||
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()));
|
||||
applyVolume();
|
||||
collateralLabel.setText("Collateral (" + getCollateralAsPercent() + "):");
|
||||
applyCollateral();
|
||||
applyTotal();
|
||||
feeTextField.setText(BitSquareFormatter.formatCoinToBtcWithCode(getFee()));
|
||||
feeTextField.setText(BitSquareFormatter.formatCoinWithCode(getFee()));
|
||||
totalTextField.setText(getFormattedTotal());
|
||||
|
||||
bankAccountTypeTextField.setText(offer.getBankAccountType().toString());
|
||||
@ -152,7 +152,7 @@ public class TakerOfferController implements Initializable, ChildController
|
||||
public void onTakeOffer()
|
||||
{
|
||||
AddressEntry addressEntry = walletFacade.getAddressInfoByTradeID(offer.getId());
|
||||
Coin amount = BitSquareFormatter.parseBtcToCoin(getAmountString());
|
||||
Coin amount = BitSquareFormatter.parseToCoin(getAmountString());
|
||||
// TODO more validation (fee payment, blacklist,...)
|
||||
if (amountTextField.isInvalid())
|
||||
{
|
||||
@ -201,10 +201,10 @@ public class TakerOfferController implements Initializable, ChildController
|
||||
{
|
||||
accordion.setExpandedPane(summaryTitledPane);
|
||||
|
||||
summaryPaidTextField.setText(BitSquareFormatter.formatCoinToBtcWithCode(trade.getTradeAmount()));
|
||||
summaryPaidTextField.setText(BitSquareFormatter.formatCoinWithCode(trade.getTradeAmount()));
|
||||
summaryReceivedTextField.setText(BitSquareFormatter.formatVolume(trade.getTradeVolume()));
|
||||
summaryFeesTextField.setText(BitSquareFormatter.formatCoinToBtcWithCode(FeePolicy.TAKE_OFFER_FEE.add(FeePolicy.TX_FEE)));
|
||||
summaryCollateralTextField.setText(BitSquareFormatter.formatCoinToBtcWithCode(trade.getCollateralAmount()));
|
||||
summaryFeesTextField.setText(BitSquareFormatter.formatCoinWithCode(FeePolicy.TAKE_OFFER_FEE.add(FeePolicy.TX_FEE)));
|
||||
summaryCollateralTextField.setText(BitSquareFormatter.formatCoinWithCode(trade.getCollateralAmount()));
|
||||
summaryDepositTxIdTextField.setText(depositTxId);
|
||||
summaryPayoutTxIdTextField.setText(payoutTxId);
|
||||
}
|
||||
@ -283,7 +283,7 @@ public class TakerOfferController implements Initializable, ChildController
|
||||
|
||||
private String getFormattedTotal()
|
||||
{
|
||||
return BitSquareFormatter.formatCoinToBtcWithCode(getTotal());
|
||||
return BitSquareFormatter.formatCoinWithCode(getTotal());
|
||||
}
|
||||
|
||||
|
||||
@ -295,7 +295,7 @@ public class TakerOfferController implements Initializable, ChildController
|
||||
|
||||
private Coin getAmountInSatoshis()
|
||||
{
|
||||
return BitSquareFormatter.parseBtcToCoin(getAmountString());
|
||||
return BitSquareFormatter.parseToCoin(getAmountString());
|
||||
}
|
||||
|
||||
private String getAmountString()
|
||||
@ -327,15 +327,15 @@ public class TakerOfferController implements Initializable, ChildController
|
||||
|
||||
private Coin getCollateralAsCoin()
|
||||
{
|
||||
Coin amountAsCoin = BitSquareFormatter.parseBtcToCoin(getAmountString());
|
||||
Coin amountAsCoin = BitSquareFormatter.parseToCoin(getAmountString());
|
||||
return amountAsCoin.divide((long) (1d / offer.getCollateral()));
|
||||
}
|
||||
|
||||
private String getFormattedCollateralAsBtc()
|
||||
{
|
||||
Coin amountAsCoin = BitSquareFormatter.parseBtcToCoin(getAmountString());
|
||||
Coin amountAsCoin = BitSquareFormatter.parseToCoin(getAmountString());
|
||||
Coin collateralAsCoin = amountAsCoin.divide((long) (1d / getCollateral()));
|
||||
return BitSquareFormatter.formatCoinToBtc(collateralAsCoin);
|
||||
return BitSquareFormatter.formatCoin(collateralAsCoin);
|
||||
}
|
||||
|
||||
private String getCollateralAsPercent()
|
||||
|
@ -22,7 +22,7 @@ public class OfferListItem
|
||||
this.date.set(BitSquareFormatter.formatDateTime(offer.getCreationDate()));
|
||||
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.offerId = offer.getId();
|
||||
}
|
||||
|
@ -297,10 +297,10 @@ public class PendingTradeController implements Initializable, ChildController, H
|
||||
primaryBankAccountIDTitleLabel.setText("Total fees (offer fee + tx fee):");
|
||||
secondaryBankAccountIDTitleLabel.setText("Refunded collateral:");
|
||||
|
||||
bankAccountTypeTextField.setText(BitSquareFormatter.formatCoinToBtcWithCode(trade.getTradeAmount()));
|
||||
bankAccountTypeTextField.setText(BitSquareFormatter.formatCoinWithCode(trade.getTradeAmount()));
|
||||
holderNameTextField.setText(BitSquareFormatter.formatVolume(trade.getTradeVolume()));
|
||||
primaryBankAccountIDTextField.setText(BitSquareFormatter.formatCoinToBtcWithCode(FeePolicy.CREATE_OFFER_FEE.add(FeePolicy.TX_FEE)));
|
||||
secondaryBankAccountIDTextField.setText(BitSquareFormatter.formatCoinToBtcWithCode(trade.getCollateralAmount()));
|
||||
primaryBankAccountIDTextField.setText(BitSquareFormatter.formatCoinWithCode(FeePolicy.CREATE_OFFER_FEE.add(FeePolicy.TX_FEE)));
|
||||
secondaryBankAccountIDTextField.setText(BitSquareFormatter.formatCoinWithCode(trade.getCollateralAmount()));
|
||||
|
||||
holderNameCopyIcon.setVisible(false);
|
||||
primaryBankAccountIDCopyIcon.setVisible(false);
|
||||
|
@ -22,19 +22,20 @@ public class BitSquareFormatter
|
||||
// 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();
|
||||
} */
|
||||
|
||||
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.
|
||||
* @return
|
||||
*/
|
||||
public static Coin parseBtcToCoin(String input)
|
||||
public static Coin parseToCoin(String input)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -62,6 +63,7 @@ public class BitSquareFormatter
|
||||
// FIAT
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
public static String formatPrice(double price)
|
||||
{
|
||||
return formatDouble(price);
|
||||
|
@ -113,11 +113,8 @@ public class OrderBook implements OrderBookListener
|
||||
// Apply applyFilter only if there is a valid value set
|
||||
// The requested amount must be lower or equal then the offer amount
|
||||
boolean amountResult = true;
|
||||
if (orderBookFilter.getAmount() > 0)
|
||||
{
|
||||
//TODO
|
||||
amountResult = orderBookFilter.getAmount() <= offer.getAmount().value;
|
||||
}
|
||||
if (orderBookFilter.getAmount() != null)
|
||||
amountResult = orderBookFilter.getAmount().compareTo(offer.getAmount()) <= 0;
|
||||
|
||||
// The requested trade direction must be opposite of the offerList trade direction
|
||||
boolean directionResult = !orderBookFilter.getDirection().equals(offer.getDirection());
|
||||
|
@ -1,5 +1,6 @@
|
||||
package io.bitsquare.trade.orderbook;
|
||||
|
||||
import com.google.bitcoin.core.Coin;
|
||||
import io.bitsquare.trade.Direction;
|
||||
import javafx.beans.property.SimpleBooleanProperty;
|
||||
|
||||
@ -8,7 +9,7 @@ public class OrderBookFilter
|
||||
private final SimpleBooleanProperty directionChangedProperty = new SimpleBooleanProperty();
|
||||
|
||||
private double price;
|
||||
private double amount;
|
||||
private Coin amount;
|
||||
private Direction direction;
|
||||
|
||||
|
||||
@ -16,12 +17,12 @@ public class OrderBookFilter
|
||||
// Setters
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public double getAmount()
|
||||
public Coin getAmount()
|
||||
{
|
||||
return amount;
|
||||
}
|
||||
|
||||
public void setAmount(double amount)
|
||||
public void setAmount(Coin amount)
|
||||
{
|
||||
this.amount = amount;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user