mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-05-12 19:42:15 -04:00
fixed utest, update formatting added comments
This commit is contained in:
parent
25b2afc545
commit
98c6e34b23
50 changed files with 286 additions and 368 deletions
6
pom.xml
6
pom.xml
|
@ -239,12 +239,6 @@
|
|||
<version>13.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>net.glxn</groupId>
|
||||
<artifactId>qrgen</artifactId>
|
||||
<version>1.3</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-all</artifactId>
|
||||
|
|
|
@ -43,7 +43,7 @@ import org.slf4j.LoggerFactory;
|
|||
/**
|
||||
* Well known node which is reachable for all peers for bootstrapping.
|
||||
* There will be several SeedNodes running on several servers.
|
||||
* <p/>
|
||||
* <p>
|
||||
* TODO: Alternative bootstrap methods will follow later (save locally list of known nodes reported form other peers...)
|
||||
*/
|
||||
public class SeedNode extends Thread {
|
||||
|
|
|
@ -35,12 +35,18 @@ public class BankAccount implements Serializable {
|
|||
private final String accountSecondaryID; // like BIC
|
||||
private final String accountHolderName;
|
||||
private final Country country; // where bank is registered
|
||||
|
||||
// The main currency if account support multiple currencies.
|
||||
// The user can create multiple bank accounts with same bank account but other currency if his bank account
|
||||
// support that.
|
||||
private final Currency currency;
|
||||
private final String accountTitle;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Constructor
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public BankAccount(BankAccountType bankAccountType, Currency currency, Country country, String accountTitle,
|
||||
String accountHolderName, String accountPrimaryID, String accountSecondaryID) {
|
||||
this.bankAccountType = bankAccountType;
|
||||
|
@ -52,18 +58,10 @@ public class BankAccount implements Serializable {
|
|||
this.accountSecondaryID = accountSecondaryID;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(accountTitle);
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof BankAccount)) return false;
|
||||
if (obj == this) return true;
|
||||
|
||||
final BankAccount other = (BankAccount) obj;
|
||||
return accountTitle.equals(other.getUid());
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Getters/Setters
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public String getAccountPrimaryID() {
|
||||
return accountPrimaryID;
|
||||
|
@ -98,6 +96,25 @@ public class BankAccount implements Serializable {
|
|||
return accountTitle;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Methods
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(accountTitle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof BankAccount)) return false;
|
||||
if (obj == this) return true;
|
||||
|
||||
final BankAccount other = (BankAccount) obj;
|
||||
return accountTitle.equals(other.getUid());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "BankAccount{" +
|
||||
|
|
|
@ -24,6 +24,10 @@ import com.google.bitcoin.crypto.DeterministicKey;
|
|||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Is a minimalistic wallet abstraction used to separate transactions between different activities like:
|
||||
* Registration, trade and arbiter deposit.
|
||||
*/
|
||||
public class AddressEntry implements Serializable {
|
||||
private static final long serialVersionUID = 5501603992599920416L;
|
||||
private transient DeterministicKey key;
|
||||
|
|
|
@ -23,6 +23,7 @@ import com.google.bitcoin.core.Transaction;
|
|||
|
||||
import javax.inject.Inject;
|
||||
|
||||
// TODO will be probably removed
|
||||
public class BtcValidator {
|
||||
private static NetworkParameters params;
|
||||
|
||||
|
|
|
@ -34,6 +34,8 @@ public class FeePolicy {
|
|||
public static final Coin CREATE_OFFER_FEE = Coin.MILLICOIN; // 0.001
|
||||
public static final Coin TAKE_OFFER_FEE = CREATE_OFFER_FEE;
|
||||
private static final Logger log = LoggerFactory.getLogger(FeePolicy.class);
|
||||
|
||||
// those are just dummy yet. trading fees will go probably to arbiters
|
||||
private static final String registrationFeeAddress = "mvkDXt4QmN4Nq9dRUsRigBCaovde9nLkZR";
|
||||
private static final String createOfferFeeAddress = "n2upbsaKAe4PD3cc4JfS7UCqPC5oNd7Ckg";
|
||||
private static final String takeOfferFeeAddress = "n2upbsaKAe4PD3cc4JfS7UCqPC5oNd7Ckg";
|
||||
|
|
|
@ -32,6 +32,5 @@ public class ConfidenceListener {
|
|||
}
|
||||
|
||||
public void onTransactionConfidenceChanged(TransactionConfidence confidence) {
|
||||
|
||||
}
|
||||
}
|
|
@ -103,7 +103,7 @@ public class GuiceFXMLLoader {
|
|||
* A JavaFX controller factory for constructing controllers via Guice DI. To
|
||||
* install this in the {@link javafx.fxml.FXMLLoader}, pass it as a parameter to
|
||||
* {@link javafx.fxml.FXMLLoader#setControllerFactory(javafx.util.Callback)}.
|
||||
* <p/>
|
||||
* <p>
|
||||
* Once set, make sure you do <b>not</b> use the static methods on
|
||||
* {@link javafx.fxml.FXMLLoader} when creating your JavaFX node.
|
||||
*/
|
||||
|
|
|
@ -16,8 +16,7 @@
|
|||
~ along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
|
||||
-->
|
||||
|
||||
<?import javafx.scene.layout.BorderPane?>
|
||||
|
||||
<?import javafx.scene.layout.*?>
|
||||
<BorderPane fx:id="root" id="splash" fx:controller="io.bitsquare.gui.MainController"
|
||||
prefHeight="750" prefWidth="1000" stylesheets="/io/bitsquare/gui/bitsquare.css"
|
||||
xmlns:fx="http://javafx.com/fxml">
|
||||
|
|
|
@ -16,9 +16,8 @@
|
|||
~ along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
|
||||
-->
|
||||
|
||||
<?import javafx.scene.control.Button?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
|
||||
<AnchorPane fx:id="root" fx:controller="io.bitsquare.gui.arbitrators.overview.ArbitratorOverviewController"
|
||||
prefHeight="600" prefWidth="800" AnchorPane.bottomAnchor="30.0" AnchorPane.leftAnchor="10.0"
|
||||
AnchorPane.rightAnchor="10.0" AnchorPane.topAnchor="10.0"
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
<?import javafx.geometry.Insets?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
|
||||
<GridPane fx:id="root" fx:controller="io.bitsquare.gui.arbitrators.profile.ArbitratorProfileController"
|
||||
hgap="5.0" vgap="5.0" AnchorPane.bottomAnchor="80.0" AnchorPane.leftAnchor="10.0"
|
||||
AnchorPane.rightAnchor="10.0" AnchorPane.topAnchor="10.0"
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
<?import javafx.geometry.Insets?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
|
||||
<AnchorPane fx:id="root" fx:controller="io.bitsquare.gui.arbitrators.registration.ArbitratorRegistrationController"
|
||||
prefHeight="600" prefWidth="800" AnchorPane.bottomAnchor="30.0" AnchorPane.leftAnchor="10.0"
|
||||
AnchorPane.rightAnchor="10.0" AnchorPane.topAnchor="10.0"
|
||||
|
|
|
@ -38,7 +38,7 @@ import org.slf4j.LoggerFactory;
|
|||
* TextField with validation support. Validation is executed on the Validator object.
|
||||
* In case of a invalid result we display a error message with a PopOver.
|
||||
* The position is derived from the textField or if set from the errorPopupLayoutReference object.
|
||||
* <p/>
|
||||
* <p>
|
||||
* That class implements just what we need for the moment. It is not intended as a general purpose library class.
|
||||
*/
|
||||
public class ValidatingTextField extends TextField {
|
||||
|
|
|
@ -43,22 +43,22 @@ import javafx.scene.control.*;
|
|||
* <p>
|
||||
* ProgressIndicator sets focusTraversable to false.
|
||||
* </p>
|
||||
* <p/>
|
||||
* <p/>
|
||||
* <p>
|
||||
* <p>
|
||||
* This first example creates a ProgressIndicator with an indeterminate value :
|
||||
* <pre><code>
|
||||
* import javafx.scene.control.ProgressIndicator;
|
||||
* ProgressIndicator p1 = new ProgressIndicator();
|
||||
* </code></pre>
|
||||
* <p/>
|
||||
* <p/>
|
||||
* <p>
|
||||
* <p>
|
||||
* This next example creates a ProgressIndicator which is 25% complete :
|
||||
* <pre><code>
|
||||
* import javafx.scene.control.ProgressIndicator;
|
||||
* ProgressIndicator p2 = new ProgressIndicator();
|
||||
* p2.setProgress(0.25F);
|
||||
* </code></pre>
|
||||
* <p/>
|
||||
* <p>
|
||||
* Implementation of ProgressIndicator According to JavaFX UI Control API Specification
|
||||
*
|
||||
* @since JavaFX 2.0
|
||||
|
@ -81,7 +81,7 @@ public class ConfidenceProgressIndicator extends Control {
|
|||
**************************************************************************/
|
||||
/**
|
||||
* Initialize the style class to 'progress-indicator'.
|
||||
* <p/>
|
||||
* <p>
|
||||
* This is the selector class from which CSS can be used to style
|
||||
* this control.
|
||||
*/
|
||||
|
|
|
@ -17,9 +17,8 @@
|
|||
-->
|
||||
|
||||
<?import io.bitsquare.gui.components.CachingTabPane?>
|
||||
<?import javafx.scene.control.Tab?>
|
||||
<?import javafx.scene.layout.AnchorPane?>
|
||||
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
<CachingTabPane fx:id="root" fx:controller="io.bitsquare.gui.funds.FundsController"
|
||||
AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0"
|
||||
AnchorPane.topAnchor="0.0"
|
||||
|
|
|
@ -18,10 +18,9 @@
|
|||
-->
|
||||
|
||||
<?import javafx.geometry.Insets?>
|
||||
<?import javafx.scene.control.cell.*?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.control.cell.PropertyValueFactory?>
|
||||
<?import javafx.scene.layout.VBox?>
|
||||
|
||||
<?import javafx.scene.layout.*?>
|
||||
<VBox fx:id="root" fx:controller="io.bitsquare.gui.funds.deposit.DepositController"
|
||||
spacing="10" xmlns:fx="http://javafx.com/fxml">
|
||||
<padding>
|
||||
|
|
|
@ -18,10 +18,9 @@
|
|||
-->
|
||||
|
||||
<?import javafx.geometry.Insets?>
|
||||
<?import javafx.scene.control.cell.PropertyValueFactory?>
|
||||
<?import javafx.scene.control.cell.*?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.layout.VBox?>
|
||||
|
||||
<?import javafx.scene.layout.*?>
|
||||
<VBox fx:id="root" fx:controller="io.bitsquare.gui.funds.transactions.TransactionsController"
|
||||
spacing="10" xmlns:fx="http://javafx.com/fxml">
|
||||
<padding>
|
||||
|
|
|
@ -19,9 +19,8 @@
|
|||
|
||||
<?import javafx.geometry.Insets?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.control.cell.PropertyValueFactory?>
|
||||
<?import javafx.scene.control.cell.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
|
||||
<VBox fx:id="root" fx:controller="io.bitsquare.gui.funds.withdrawal.WithdrawalController"
|
||||
spacing="10" xmlns:fx="http://javafx.com/fxml">
|
||||
<padding>
|
||||
|
|
|
@ -17,10 +17,8 @@
|
|||
~ along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
|
||||
-->
|
||||
|
||||
<?import javafx.scene.control.Button?>
|
||||
<?import javafx.scene.control.Label?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
|
||||
<AnchorPane fx:id="root" fx:controller="io.bitsquare.gui.home.HomeController"
|
||||
AnchorPane.bottomAnchor="30" AnchorPane.leftAnchor="10" AnchorPane.rightAnchor="10"
|
||||
AnchorPane.topAnchor="10"
|
||||
|
|
|
@ -17,9 +17,8 @@
|
|||
~ along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
|
||||
-->
|
||||
|
||||
<?import javafx.scene.control.Label?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
|
||||
<AnchorPane fx:id="root" fx:controller="io.bitsquare.gui.msg.MsgController"
|
||||
AnchorPane.bottomAnchor="0" AnchorPane.leftAnchor="0" AnchorPane.rightAnchor="0" AnchorPane.topAnchor="0"
|
||||
xmlns:fx="http://javafx.com/fxml">
|
||||
|
|
|
@ -18,9 +18,8 @@
|
|||
-->
|
||||
|
||||
<?import io.bitsquare.gui.components.CachingTabPane?>
|
||||
<?import javafx.scene.control.Tab?>
|
||||
<?import javafx.scene.layout.AnchorPane?>
|
||||
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
<CachingTabPane fx:id="root" fx:controller="io.bitsquare.gui.orders.OrdersController"
|
||||
AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0"
|
||||
AnchorPane.topAnchor="0.0"
|
||||
|
|
|
@ -17,9 +17,8 @@
|
|||
~ along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
|
||||
-->
|
||||
|
||||
<?import javafx.scene.control.Label?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
|
||||
<AnchorPane fx:id="root" fx:controller="io.bitsquare.gui.orders.closed.ClosedTradeController"
|
||||
AnchorPane.bottomAnchor="0" AnchorPane.leftAnchor="0" AnchorPane.rightAnchor="0" AnchorPane.topAnchor="0"
|
||||
xmlns:fx="http://javafx.com/fxml">
|
||||
|
|
|
@ -20,8 +20,7 @@
|
|||
<?import javafx.geometry.Insets?>
|
||||
<?import javafx.scene.control.cell.*?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.layout.VBox?>
|
||||
|
||||
<?import javafx.scene.layout.*?>
|
||||
<VBox fx:id="root" fx:controller="io.bitsquare.gui.orders.offer.OfferController"
|
||||
spacing="10" xmlns:fx="http://javafx.com/fxml">
|
||||
<padding>
|
||||
|
|
|
@ -18,11 +18,10 @@
|
|||
-->
|
||||
|
||||
<?import io.bitsquare.gui.components.confidence.ConfidenceProgressIndicator?>
|
||||
<?import javafx.geometry.*?>
|
||||
<?import javafx.geometry.Insets?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.control.cell.PropertyValueFactory?>
|
||||
<?import javafx.scene.control.cell.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
|
||||
<VBox fx:id="root" fx:controller="io.bitsquare.gui.orders.pending.PendingTradeController"
|
||||
spacing="10" AnchorPane.bottomAnchor="0"
|
||||
AnchorPane.leftAnchor="0" AnchorPane.rightAnchor="0" AnchorPane.topAnchor="0"
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
<?import javafx.geometry.Insets?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
|
||||
<TabPane fx:id="root" fx:controller="io.bitsquare.gui.settings.SettingsController"
|
||||
AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0"
|
||||
AnchorPane.topAnchor="0.0"
|
||||
|
|
|
@ -17,9 +17,8 @@
|
|||
~ along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
|
||||
-->
|
||||
|
||||
<?import javafx.scene.control.TabPane?>
|
||||
<?import javafx.scene.layout.AnchorPane?>
|
||||
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
<TabPane fx:id="root" fx:controller="io.bitsquare.gui.trade.BuyController"
|
||||
AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0"
|
||||
AnchorPane.topAnchor="0.0"
|
||||
|
|
|
@ -17,9 +17,8 @@
|
|||
~ along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
|
||||
-->
|
||||
|
||||
<?import javafx.scene.control.TabPane?>
|
||||
<?import javafx.scene.layout.AnchorPane?>
|
||||
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
<TabPane fx:id="root" fx:controller="io.bitsquare.gui.trade.SellController"
|
||||
AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0"
|
||||
AnchorPane.topAnchor="0.0"
|
||||
|
|
|
@ -39,27 +39,26 @@ import javafx.scene.layout.*;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
//TODO check DI
|
||||
|
||||
/**
|
||||
* Code behind (FXML Controller is part of View, not a classical controller from MVC):
|
||||
* <p>
|
||||
* Creates Presenter and passes Model from DI to Presenter. Does not hold a reference to Model
|
||||
* <p>
|
||||
* - Setup binding from Presenter to View elements (also bidirectional - Inputs). Binding are only to presenters properties, not logical bindings or cross-view element bindings.
|
||||
* - Setup binding from Presenter to View elements (also bidirectional - Inputs). Binding are only to presenters
|
||||
* properties, not logical bindings or cross-view element bindings.
|
||||
* - Listen to UI events (Action) from View and call method in Presenter.
|
||||
* - Is entry node for hierarchical view graphs. Passes method calls to Presenter. Calls methods on sub views.
|
||||
* - Handle lifecycle and self removal from scene graph.
|
||||
* - Non declarative (dynamic) view definitions (if it gets larger, then user a ViewBuilder)
|
||||
* <p>
|
||||
* View:
|
||||
* - Mostly declared in FXML. Dynamic parts are declared in Controller. If more view elements need to be defined in code then use ViewBuilder.
|
||||
* - Mostly declared in FXML. Dynamic parts are declared in Controller. If more view elements need to be defined in
|
||||
* code then use ViewBuilder.
|
||||
* <p>
|
||||
* Optional ViewBuilder:
|
||||
* - Replacement for FXML view definitions.
|
||||
*/
|
||||
public class CreateOfferCodeBehind extends CachedViewController
|
||||
{
|
||||
public class CreateOfferCodeBehind extends CachedViewController {
|
||||
private static final Logger log = LoggerFactory.getLogger(CreateOfferCodeBehind.class);
|
||||
|
||||
private final CreateOfferPresenter presenter;
|
||||
|
@ -69,7 +68,9 @@ public class CreateOfferCodeBehind extends CachedViewController
|
|||
|
||||
@FXML private ValidatingTextField amountTextField, minAmountTextField, priceTextField, volumeTextField;
|
||||
@FXML private Button placeOfferButton, closeButton;
|
||||
@FXML private TextField totalToPayTextField, collateralTextField, bankAccountTypeTextField, bankAccountCurrencyTextField, bankAccountCountyTextField, acceptedCountriesTextField, acceptedLanguagesTextField,
|
||||
@FXML private TextField totalToPayTextField, collateralTextField, bankAccountTypeTextField,
|
||||
bankAccountCurrencyTextField, bankAccountCountyTextField, acceptedCountriesTextField,
|
||||
acceptedLanguagesTextField,
|
||||
feeLabel, transactionIdTextField;
|
||||
@FXML private ConfidenceProgressIndicator progressIndicator;
|
||||
@FXML private AddressTextField addressTextField;
|
||||
|
@ -81,8 +82,7 @@ public class CreateOfferCodeBehind extends CachedViewController
|
|||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@Inject
|
||||
public CreateOfferCodeBehind(CreateOfferModel model)
|
||||
{
|
||||
public CreateOfferCodeBehind(CreateOfferModel model) {
|
||||
presenter = new CreateOfferPresenter(model);
|
||||
}
|
||||
|
||||
|
@ -92,23 +92,20 @@ public class CreateOfferCodeBehind extends CachedViewController
|
|||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@Override
|
||||
public void initialize(URL url, ResourceBundle rb)
|
||||
{
|
||||
public void initialize(URL url, ResourceBundle rb) {
|
||||
super.initialize(url, rb);
|
||||
presenter.onViewInitialized();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deactivate()
|
||||
{
|
||||
public void deactivate() {
|
||||
super.deactivate();
|
||||
presenter.deactivate();
|
||||
((TradeController) parentController).onCreateOfferViewRemoved();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void activate()
|
||||
{
|
||||
public void activate() {
|
||||
super.activate();
|
||||
presenter.activate();
|
||||
|
||||
|
@ -129,8 +126,7 @@ public class CreateOfferCodeBehind extends CachedViewController
|
|||
// Public methods
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public void setOrderBookFilter(OrderBookFilter orderBookFilter)
|
||||
{
|
||||
public void setOrderBookFilter(OrderBookFilter orderBookFilter) {
|
||||
presenter.setOrderBookFilter(orderBookFilter);
|
||||
}
|
||||
|
||||
|
@ -139,14 +135,12 @@ public class CreateOfferCodeBehind extends CachedViewController
|
|||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@FXML
|
||||
public void onPlaceOffer()
|
||||
{
|
||||
public void onPlaceOffer() {
|
||||
presenter.placeOffer();
|
||||
}
|
||||
|
||||
@FXML
|
||||
public void onClose()
|
||||
{
|
||||
public void onClose() {
|
||||
presenter.close();
|
||||
|
||||
TabPane tabPane = ((TabPane) (rootContainer.getParent().getParent()));
|
||||
|
@ -158,15 +152,19 @@ public class CreateOfferCodeBehind extends CachedViewController
|
|||
// Private Methods
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
private void setupListeners()
|
||||
{
|
||||
volumeTextField.focusedProperty().addListener((observableValue, oldValue, newValue) -> presenter.checkVolumeOnFocusOut(oldValue, newValue, volumeTextField.getText()));
|
||||
amountTextField.focusedProperty().addListener((observableValue, oldValue, newValue) -> presenter.onFocusOutAmountTextField(oldValue, newValue));
|
||||
priceTextField.focusedProperty().addListener((observableValue, oldValue, newValue) -> presenter.onFocusOutPriceTextField(oldValue, newValue));
|
||||
private void setupListeners() {
|
||||
volumeTextField.focusedProperty().addListener((observableValue, oldValue,
|
||||
newValue) -> presenter.checkVolumeOnFocusOut(oldValue,
|
||||
newValue, volumeTextField.getText()));
|
||||
amountTextField.focusedProperty().addListener((observableValue, oldValue,
|
||||
newValue) -> presenter.onFocusOutAmountTextField(oldValue,
|
||||
newValue));
|
||||
priceTextField.focusedProperty().addListener((observableValue, oldValue,
|
||||
newValue) -> presenter.onFocusOutPriceTextField(oldValue,
|
||||
newValue));
|
||||
|
||||
presenter.validateInput.addListener((o, oldValue, newValue) -> {
|
||||
if (newValue)
|
||||
{
|
||||
if (newValue) {
|
||||
amountTextField.reValidate();
|
||||
minAmountTextField.reValidate();
|
||||
volumeTextField.reValidate();
|
||||
|
@ -175,16 +173,15 @@ public class CreateOfferCodeBehind extends CachedViewController
|
|||
});
|
||||
|
||||
presenter.showVolumeAdjustedWarning.addListener((o, oldValue, newValue) -> {
|
||||
if (newValue)
|
||||
{
|
||||
Popups.openWarningPopup("Warning", "The total volume you have entered leads to invalid fractional Bitcoin amounts.\nThe amount has been adjusted and a new total volume be calculated from it.");
|
||||
if (newValue) {
|
||||
Popups.openWarningPopup("Warning", "The total volume you have entered leads to invalid fractional " +
|
||||
"Bitcoin amounts.\nThe amount has been adjusted and a new total volume be calculated from it.");
|
||||
volumeTextField.setText(presenter.volume.get());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void setupBindings()
|
||||
{
|
||||
private void setupBindings() {
|
||||
buyLabel.textProperty().bind(presenter.directionLabel);
|
||||
amountTextField.textProperty().bindBidirectional(presenter.amount);
|
||||
priceTextField.textProperty().bindBidirectional(presenter.price);
|
||||
|
@ -221,8 +218,7 @@ public class CreateOfferCodeBehind extends CachedViewController
|
|||
.and(priceTextField.isValidProperty()).not());*/
|
||||
}
|
||||
|
||||
private void setupTextFieldValidators()
|
||||
{
|
||||
private void setupTextFieldValidators() {
|
||||
/* BtcValidator amountValidator = new BtcValidator();
|
||||
amountTextField.setNumberValidator(amountValidator);
|
||||
amountTextField.setErrorPopupLayoutReference((Region) amountTextField.getParent());
|
||||
|
|
|
@ -59,8 +59,7 @@ import static com.google.common.base.Preconditions.checkArgument;
|
|||
* - Holds domain data
|
||||
* - Use Properties for bindable data
|
||||
*/
|
||||
class CreateOfferModel
|
||||
{
|
||||
class CreateOfferModel {
|
||||
private static final Logger log = LoggerFactory.getLogger(CreateOfferModel.class);
|
||||
|
||||
private final TradeManager tradeManager;
|
||||
|
@ -68,8 +67,7 @@ class CreateOfferModel
|
|||
private final Settings settings;
|
||||
private final User user;
|
||||
|
||||
String getOfferId()
|
||||
{
|
||||
String getOfferId() {
|
||||
return offerId;
|
||||
}
|
||||
|
||||
|
@ -106,8 +104,7 @@ class CreateOfferModel
|
|||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@Inject
|
||||
CreateOfferModel(TradeManager tradeManager, WalletFacade walletFacade, Settings settings, User user)
|
||||
{
|
||||
CreateOfferModel(TradeManager tradeManager, WalletFacade walletFacade, Settings settings, User user) {
|
||||
this.tradeManager = tradeManager;
|
||||
this.walletFacade = walletFacade;
|
||||
this.settings = settings;
|
||||
|
@ -115,7 +112,8 @@ class CreateOfferModel
|
|||
|
||||
offerId = UUID.randomUUID().toString();
|
||||
totalFeesAsCoin = FeePolicy.CREATE_OFFER_FEE.add(FeePolicy.TX_FEE);
|
||||
if (walletFacade != null && walletFacade.getWallet() != null) addressEntry = walletFacade.getAddressInfoByTradeID(offerId);
|
||||
if (walletFacade != null && walletFacade.getWallet() != null)
|
||||
addressEntry = walletFacade.getAddressInfoByTradeID(offerId);
|
||||
}
|
||||
|
||||
|
||||
|
@ -123,13 +121,11 @@ class CreateOfferModel
|
|||
// Methods
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void activate()
|
||||
{
|
||||
void activate() {
|
||||
collateralAsLong.set(settings.getCollateral());
|
||||
|
||||
BankAccount bankAccount = user.getCurrentBankAccount();
|
||||
if (bankAccount != null)
|
||||
{
|
||||
if (bankAccount != null) {
|
||||
bankAccountType.set(bankAccount.getBankAccountType().toString());
|
||||
bankAccountCurrency.set(bankAccount.getCurrency().getCurrencyCode());
|
||||
bankAccountCounty.set(bankAccount.getCountry().getName());
|
||||
|
@ -138,8 +134,7 @@ class CreateOfferModel
|
|||
acceptedLanguages.setAll(settings.getAcceptedLanguageLocales());
|
||||
}
|
||||
|
||||
void placeOffer()
|
||||
{
|
||||
void placeOffer() {
|
||||
tradeManager.requestPlaceOffer(offerId,
|
||||
direction,
|
||||
priceAsFiat.value,
|
||||
|
@ -161,13 +156,11 @@ class CreateOfferModel
|
|||
// Setter/Getter
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Direction getDirection()
|
||||
{
|
||||
Direction getDirection() {
|
||||
return direction;
|
||||
}
|
||||
|
||||
void setDirection(Direction direction)
|
||||
{
|
||||
void setDirection(Direction direction) {
|
||||
// direction must not be changed once it is initially set
|
||||
checkArgument(this.direction == null);
|
||||
this.direction = direction;
|
||||
|
|
|
@ -45,11 +45,12 @@ import static javafx.beans.binding.Bindings.createStringBinding;
|
|||
* Knows Model, does not know the View (CodeBehind)
|
||||
* <p>
|
||||
* - Holds data and state of the View (formatted)
|
||||
* - Receive view input from Controller. Validates input, apply business logic, format to Presenter properties and convert input to Model.
|
||||
* - Listen to updates from Model, apply business logic and format it to Presenter properties. Model update handling can be done via Binding.
|
||||
* - Receive view input from Controller. Validates input, apply business logic, format to Presenter properties and
|
||||
* convert input to Model.
|
||||
* - Listen to updates from Model, apply business logic and format it to Presenter properties. Model update handling
|
||||
* can be done via Binding.
|
||||
*/
|
||||
class CreateOfferPresenter
|
||||
{
|
||||
class CreateOfferPresenter {
|
||||
private static final Logger log = LoggerFactory.getLogger(CreateOfferPresenter.class);
|
||||
|
||||
private CreateOfferModel model;
|
||||
|
@ -83,8 +84,7 @@ class CreateOfferPresenter
|
|||
// Constructor
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
CreateOfferPresenter(CreateOfferModel model)
|
||||
{
|
||||
CreateOfferPresenter(CreateOfferModel model) {
|
||||
this.model = model;
|
||||
}
|
||||
|
||||
|
@ -93,35 +93,35 @@ class CreateOfferPresenter
|
|||
// Lifecycle
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void onViewInitialized()
|
||||
{
|
||||
void onViewInitialized() {
|
||||
totalFeesLabel.set(BSFormatter.formatBtc(model.totalFeesAsCoin));
|
||||
paymentLabel.set("Bitsquare trade (" + model.getOfferId() + ")");
|
||||
// address.set(model.addressEntry.getAddress().toString());
|
||||
|
||||
setupInputListeners();
|
||||
|
||||
collateralLabel.bind(Bindings.createStringBinding(() -> "Collateral (" + BSFormatter.formatCollateralPercent(model.collateralAsLong.get()) + "):", model.collateralAsLong));
|
||||
bankAccountType.bind(Bindings.createStringBinding(() -> Localisation.get(model.bankAccountType.get()), model.bankAccountType));
|
||||
collateralLabel.bind(Bindings.createStringBinding(() -> "Collateral (" + BSFormatter.formatCollateralPercent
|
||||
(model.collateralAsLong.get()) + "):", model.collateralAsLong));
|
||||
bankAccountType.bind(Bindings.createStringBinding(() -> Localisation.get(model.bankAccountType.get()),
|
||||
model.bankAccountType));
|
||||
bankAccountCurrency.bind(model.bankAccountCurrency);
|
||||
bankAccountCounty.bind(model.bankAccountCounty);
|
||||
totalToPayAsCoin.bind(model.totalToPayAsCoin);
|
||||
|
||||
model.acceptedCountries.addListener((Observable o) -> acceptedCountries.set(BSFormatter.countryLocalesToString(model.acceptedCountries)));
|
||||
model.acceptedLanguages.addListener((Observable o) -> acceptedLanguages.set(BSFormatter.languageLocalesToString(model.acceptedLanguages)));
|
||||
model.acceptedCountries.addListener((Observable o) -> acceptedCountries.set(BSFormatter
|
||||
.countryLocalesToString(model.acceptedCountries)));
|
||||
model.acceptedLanguages.addListener((Observable o) -> acceptedLanguages.set(BSFormatter
|
||||
.languageLocalesToString(model.acceptedLanguages)));
|
||||
|
||||
}
|
||||
|
||||
void deactivate()
|
||||
{
|
||||
void deactivate() {
|
||||
}
|
||||
|
||||
void activate()
|
||||
{
|
||||
void activate() {
|
||||
model.activate();
|
||||
|
||||
|
||||
|
||||
// totalToPay.addListener((ov) -> addressTextField.setAmountToPay(model.totalToPayAsCoin));
|
||||
}
|
||||
|
||||
|
@ -130,8 +130,7 @@ class CreateOfferPresenter
|
|||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
void setOrderBookFilter(OrderBookFilter orderBookFilter)
|
||||
{
|
||||
void setOrderBookFilter(OrderBookFilter orderBookFilter) {
|
||||
// model
|
||||
model.setDirection(orderBookFilter.getDirection());
|
||||
model.amountAsCoin = orderBookFilter.getAmount();
|
||||
|
@ -151,8 +150,7 @@ class CreateOfferPresenter
|
|||
// View Events
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void placeOffer()
|
||||
{
|
||||
void placeOffer() {
|
||||
model.amountAsCoin = parseToCoin(amount.get());
|
||||
model.minAmountAsCoin = parseToCoin(minAmount.get());
|
||||
model.priceAsFiat = parseToFiat(price.get());
|
||||
|
@ -162,8 +160,7 @@ class CreateOfferPresenter
|
|||
|
||||
//balanceTextField.getBalance()
|
||||
|
||||
if (inputValid())
|
||||
{
|
||||
if (inputValid()) {
|
||||
model.placeOffer();
|
||||
isPlaceOfferButtonDisabled.set(true);
|
||||
placeOfferButtonVisible.set(true);
|
||||
|
@ -183,8 +180,7 @@ class CreateOfferPresenter
|
|||
}
|
||||
|
||||
|
||||
void close()
|
||||
{
|
||||
void close() {
|
||||
|
||||
}
|
||||
|
||||
|
@ -192,14 +188,12 @@ class CreateOfferPresenter
|
|||
//
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
private boolean inputValid()
|
||||
{
|
||||
private boolean inputValid() {
|
||||
//TODO
|
||||
return true;
|
||||
}
|
||||
|
||||
void setupInputListeners()
|
||||
{
|
||||
void setupInputListeners() {
|
||||
|
||||
// bindBidirectional for amount, price, volume and minAmount
|
||||
amount.addListener(ov -> {
|
||||
|
@ -225,25 +219,21 @@ class CreateOfferPresenter
|
|||
}
|
||||
|
||||
|
||||
private void setVolume()
|
||||
{
|
||||
private void setVolume() {
|
||||
model.amountAsCoin = parseToCoin(amount.get());
|
||||
model.priceAsFiat = parseToFiat(price.get());
|
||||
|
||||
if (model.priceAsFiat != null && model.amountAsCoin != null && !model.amountAsCoin.isZero())
|
||||
{
|
||||
if (model.priceAsFiat != null && model.amountAsCoin != null && !model.amountAsCoin.isZero()) {
|
||||
model.tradeVolumeAsFiat = new ExchangeRate(model.priceAsFiat).coinToFiat(model.amountAsCoin);
|
||||
volume.set(formatFiat(model.tradeVolumeAsFiat));
|
||||
}
|
||||
}
|
||||
|
||||
private void setAmount()
|
||||
{
|
||||
private void setAmount() {
|
||||
model.tradeVolumeAsFiat = parseToFiat(volume.get());
|
||||
model.priceAsFiat = parseToFiat(price.get());
|
||||
|
||||
if (model.tradeVolumeAsFiat != null && model.priceAsFiat != null && !model.priceAsFiat.isZero())
|
||||
{
|
||||
if (model.tradeVolumeAsFiat != null && model.priceAsFiat != null && !model.priceAsFiat.isZero()) {
|
||||
model.amountAsCoin = new ExchangeRate(model.priceAsFiat).fiatToCoin(model.tradeVolumeAsFiat);
|
||||
|
||||
// If we got a btc value with more then 4 decimals we convert it to max 4 decimals
|
||||
|
@ -254,31 +244,26 @@ class CreateOfferPresenter
|
|||
}
|
||||
}
|
||||
|
||||
private void setTotalToPay()
|
||||
{
|
||||
private void setTotalToPay() {
|
||||
setCollateral();
|
||||
|
||||
if (model.collateralAsCoin != null)
|
||||
{
|
||||
if (model.collateralAsCoin != null) {
|
||||
model.totalToPayAsCoin.set(model.collateralAsCoin.add(model.totalFeesAsCoin));
|
||||
totalToPay.bind(createStringBinding(() -> formatBtcWithCode(model.totalToPayAsCoin.get()), model.totalToPayAsCoin));
|
||||
totalToPay.bind(createStringBinding(() -> formatBtcWithCode(model.totalToPayAsCoin.get()),
|
||||
model.totalToPayAsCoin));
|
||||
}
|
||||
}
|
||||
|
||||
private void setCollateral()
|
||||
{
|
||||
if (model.amountAsCoin != null)
|
||||
{
|
||||
private void setCollateral() {
|
||||
if (model.amountAsCoin != null) {
|
||||
model.collateralAsCoin = model.amountAsCoin.multiply(model.collateralAsLong.get()).divide(1000);
|
||||
collateral.set(BSFormatter.formatBtcWithCode(model.collateralAsCoin));
|
||||
}
|
||||
}
|
||||
|
||||
// We adjust the volume if fractional coins result from volume/price division on focus out
|
||||
void checkVolumeOnFocusOut(Boolean oldValue, Boolean newValue, String volumeTextFieldText)
|
||||
{
|
||||
if (oldValue && !newValue)
|
||||
{
|
||||
void checkVolumeOnFocusOut(Boolean oldValue, Boolean newValue, String volumeTextFieldText) {
|
||||
if (oldValue && !newValue) {
|
||||
setVolume();
|
||||
if (!formatFiat(parseToFiat(volumeTextFieldText)).equals(volume.get()))
|
||||
showVolumeAdjustedWarning.set(true);
|
||||
|
@ -291,15 +276,13 @@ class CreateOfferPresenter
|
|||
amountTextField.reValidate();*/
|
||||
}
|
||||
|
||||
void onFocusOutAmountTextField(Boolean oldValue, Boolean newValue)
|
||||
{
|
||||
void onFocusOutAmountTextField(Boolean oldValue, Boolean newValue) {
|
||||
// only on focus out and ignore focus loss from window
|
||||
/* if (!newValue && amountTextField.getScene() != null && amountTextField.getScene().getWindow().isFocused())
|
||||
volumeTextField.reValidate();*/
|
||||
}
|
||||
|
||||
void onFocusOutPriceTextField(Boolean oldValue, Boolean newValue)
|
||||
{
|
||||
void onFocusOutPriceTextField(Boolean oldValue, Boolean newValue) {
|
||||
// only on focus out and ignore focus loss from window
|
||||
/* if (!newValue && priceTextField.getScene() != null && priceTextField.getScene().getWindow().isFocused())
|
||||
volumeTextField.reValidate();*/
|
||||
|
|
|
@ -20,11 +20,11 @@
|
|||
<?import io.bitsquare.gui.components.btc.AddressTextField?>
|
||||
<?import io.bitsquare.gui.components.btc.BalanceTextField?>
|
||||
<?import io.bitsquare.gui.components.confidence.ConfidenceProgressIndicator?>
|
||||
<?import io.bitsquare.gui.components.*?>
|
||||
<?import javafx.geometry.*?>
|
||||
<?import io.bitsquare.gui.components.ValidatingTextField?>
|
||||
<?import io.bitsquare.gui.components.VSpacer?>
|
||||
<?import javafx.geometry.Insets?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
|
||||
<AnchorPane fx:id="root" fx:controller="io.bitsquare.gui.trade.createoffer.CreateOfferCodeBehind"
|
||||
prefHeight="500" prefWidth="800" AnchorPane.bottomAnchor="10.0" AnchorPane.leftAnchor="10.0"
|
||||
AnchorPane.rightAnchor="10.0" AnchorPane.topAnchor="10.0"
|
||||
|
|
|
@ -17,11 +17,10 @@
|
|||
~ along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
|
||||
-->
|
||||
|
||||
<?import javafx.geometry.*?>
|
||||
<?import javafx.geometry.Insets?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.control.cell.PropertyValueFactory?>
|
||||
<?import javafx.scene.control.cell.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
|
||||
<AnchorPane fx:id="root" fx:controller="io.bitsquare.gui.trade.orderbook.OrderBookController"
|
||||
AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0"
|
||||
AnchorPane.topAnchor="0.0"
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
<?import javafx.geometry.Insets?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
|
||||
<AnchorPane fx:id="root" fx:controller="io.bitsquare.gui.trade.takeoffer.TakerOfferController"
|
||||
xmlns:fx="http://javafx.com/fxml">
|
||||
<Accordion fx:id="accordion" AnchorPane.bottomAnchor="30.0" AnchorPane.leftAnchor="10.0"
|
||||
|
|
|
@ -40,8 +40,7 @@ import org.slf4j.LoggerFactory;
|
|||
import static com.google.common.base.Preconditions.*;
|
||||
|
||||
//TODO a lot of old trash... need to cleanup...
|
||||
public class BSFormatter
|
||||
{
|
||||
public class BSFormatter {
|
||||
private static final Logger log = LoggerFactory.getLogger(BSFormatter.class);
|
||||
|
||||
// format is like: 1,00 or 1,0010 never more then 4 decimals
|
||||
|
@ -58,18 +57,15 @@ public class BSFormatter
|
|||
// Config
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public static void useMilliBitFormat()
|
||||
{
|
||||
public static void useMilliBitFormat() {
|
||||
coinFormat = CoinFormat.MBTC.repeatOptionalDecimals(2, 1);
|
||||
}
|
||||
|
||||
public static void setFiatCurrencyCode(String currencyCode)
|
||||
{
|
||||
public static void setFiatCurrencyCode(String currencyCode) {
|
||||
BSFormatter.currencyCode = currencyCode;
|
||||
}
|
||||
|
||||
public static void setLocale(Locale locale)
|
||||
{
|
||||
public static void setLocale(Locale locale) {
|
||||
BSFormatter.locale = locale;
|
||||
}
|
||||
|
||||
|
@ -78,39 +74,30 @@ public class BSFormatter
|
|||
// BTC
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public static String formatBtc(Coin coin)
|
||||
{
|
||||
try
|
||||
{
|
||||
public static String formatBtc(Coin coin) {
|
||||
try {
|
||||
return coinFormat.noCode().format(coin).toString();
|
||||
} catch (Throwable t)
|
||||
{
|
||||
} catch (Throwable t) {
|
||||
log.warn("Exception at formatBtc: " + t.toString());
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public static String formatBtcWithCode(Coin coin)
|
||||
{
|
||||
try
|
||||
{
|
||||
public static String formatBtcWithCode(Coin coin) {
|
||||
try {
|
||||
return coinFormat.postfixCode().format(coin).toString();
|
||||
} catch (Throwable t)
|
||||
{
|
||||
} catch (Throwable t) {
|
||||
log.warn("Exception at formatBtcWithCode: " + t.toString());
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public static Coin parseToCoin(String input)
|
||||
{
|
||||
try
|
||||
{
|
||||
public static Coin parseToCoin(String input) {
|
||||
try {
|
||||
input = input.replace(",", ".");
|
||||
Double.parseDouble(input); // test if valid double
|
||||
return Coin.parseCoin(input);
|
||||
} catch (Throwable t)
|
||||
{
|
||||
} catch (Throwable t) {
|
||||
log.warn("Exception at parseToCoin: " + t.toString());
|
||||
return Coin.ZERO;
|
||||
}
|
||||
|
@ -122,8 +109,7 @@ public class BSFormatter
|
|||
* @param coin The coin which should be transformed
|
||||
* @return The transformed coin
|
||||
*/
|
||||
public static Coin applyFormatRules(Coin coin)
|
||||
{
|
||||
public static Coin applyFormatRules(Coin coin) {
|
||||
return parseToCoin(formatBtc(coin));
|
||||
}
|
||||
|
||||
|
@ -132,39 +118,30 @@ public class BSFormatter
|
|||
// FIAT
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public static String formatFiat(Fiat fiat)
|
||||
{
|
||||
try
|
||||
{
|
||||
public static String formatFiat(Fiat fiat) {
|
||||
try {
|
||||
return fiatFormat.noCode().format(fiat).toString();
|
||||
} catch (Throwable t)
|
||||
{
|
||||
} catch (Throwable t) {
|
||||
log.warn("Exception at formatFiat: " + t.toString());
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public static String formatFiatWithCode(Fiat fiat)
|
||||
{
|
||||
try
|
||||
{
|
||||
public static String formatFiatWithCode(Fiat fiat) {
|
||||
try {
|
||||
return fiatFormat.postfixCode().format(fiat).toString();
|
||||
} catch (Throwable t)
|
||||
{
|
||||
} catch (Throwable t) {
|
||||
log.warn("Exception at formatFiatWithCode: " + t.toString());
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public static Fiat parseToFiat(String input)
|
||||
{
|
||||
try
|
||||
{
|
||||
public static Fiat parseToFiat(String input) {
|
||||
try {
|
||||
input = input.replace(",", ".");
|
||||
Double.parseDouble(input); // test if valid double
|
||||
return Fiat.parseFiat(currencyCode, input);
|
||||
} catch (Exception e)
|
||||
{
|
||||
} catch (Exception e) {
|
||||
return Fiat.valueOf(currencyCode, 0);
|
||||
}
|
||||
}
|
||||
|
@ -175,46 +152,39 @@ public class BSFormatter
|
|||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* @param input String to be converted to a double. Both decimal points "." and "," are supported. Thousands separator is not supported.
|
||||
* @param input String to be converted to a double. Both decimal points "." and ",
|
||||
* " are supported. Thousands separator is not supported.
|
||||
* @return Returns a double value. Any invalid value returns Double.NEGATIVE_INFINITY.
|
||||
*/
|
||||
public static double parseToDouble(String input)
|
||||
{
|
||||
try
|
||||
{
|
||||
public static double parseToDouble(String input) {
|
||||
try {
|
||||
checkNotNull(input);
|
||||
checkArgument(input.length() > 0);
|
||||
input = input.replace(",", ".").trim();
|
||||
return Double.parseDouble(input);
|
||||
} catch (Exception e)
|
||||
{
|
||||
} catch (Exception e) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static String formatDirection(Direction direction, boolean allUpperCase)
|
||||
{
|
||||
public static String formatDirection(Direction direction, boolean allUpperCase) {
|
||||
String result = (direction == Direction.BUY) ? "Buy" : "Sell";
|
||||
if (allUpperCase)
|
||||
{
|
||||
if (allUpperCase) {
|
||||
result = result.toUpperCase();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static String formatDouble(double value)
|
||||
{
|
||||
public static String formatDouble(double value) {
|
||||
return formatDouble(value, 4);
|
||||
}
|
||||
|
||||
public static String formatDouble(double value, int fractionDigits)
|
||||
{
|
||||
public static String formatDouble(double value, int fractionDigits) {
|
||||
DecimalFormat decimalFormat = getDecimalFormat(fractionDigits);
|
||||
return decimalFormat.format(value);
|
||||
}
|
||||
|
||||
public static DecimalFormat getDecimalFormat(int fractionDigits)
|
||||
{
|
||||
public static DecimalFormat getDecimalFormat(int fractionDigits) {
|
||||
DecimalFormat decimalFormat = (DecimalFormat) DecimalFormat.getInstance(locale);
|
||||
decimalFormat.setMinimumFractionDigits(fractionDigits);
|
||||
decimalFormat.setMaximumFractionDigits(fractionDigits);
|
||||
|
@ -222,32 +192,26 @@ public class BSFormatter
|
|||
return decimalFormat;
|
||||
}
|
||||
|
||||
public static String countryLocalesToString(List<Country> countries)
|
||||
{
|
||||
public static String countryLocalesToString(List<Country> countries) {
|
||||
String result = "";
|
||||
int i = 0;
|
||||
for (Country country : countries)
|
||||
{
|
||||
for (Country country : countries) {
|
||||
result += country.getName();
|
||||
i++;
|
||||
if (i < countries.size())
|
||||
{
|
||||
if (i < countries.size()) {
|
||||
result += ", ";
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static String languageLocalesToString(List<Locale> languageLocales)
|
||||
{
|
||||
public static String languageLocalesToString(List<Locale> languageLocales) {
|
||||
String result = "";
|
||||
int i = 0;
|
||||
for (Locale locale : languageLocales)
|
||||
{
|
||||
for (Locale locale : languageLocales) {
|
||||
result += locale.getDisplayLanguage();
|
||||
i++;
|
||||
if (i < languageLocales.size())
|
||||
{
|
||||
if (i < languageLocales.size()) {
|
||||
result += ", ";
|
||||
}
|
||||
}
|
||||
|
@ -255,16 +219,13 @@ public class BSFormatter
|
|||
}
|
||||
|
||||
|
||||
public static String arbitrationMethodsToString(List<Arbitrator.METHOD> items)
|
||||
{
|
||||
public static String arbitrationMethodsToString(List<Arbitrator.METHOD> items) {
|
||||
String result = "";
|
||||
int i = 0;
|
||||
for (Arbitrator.METHOD item : items)
|
||||
{
|
||||
for (Arbitrator.METHOD item : items) {
|
||||
result += Localisation.get(item.toString());
|
||||
i++;
|
||||
if (i < items.size())
|
||||
{
|
||||
if (i < items.size()) {
|
||||
result += ", ";
|
||||
}
|
||||
}
|
||||
|
@ -272,62 +233,52 @@ public class BSFormatter
|
|||
}
|
||||
|
||||
|
||||
public static String arbitrationIDVerificationsToString(List<Arbitrator.ID_VERIFICATION> items)
|
||||
{
|
||||
public static String arbitrationIDVerificationsToString(List<Arbitrator.ID_VERIFICATION> items) {
|
||||
String result = "";
|
||||
int i = 0;
|
||||
for (Arbitrator.ID_VERIFICATION item : items)
|
||||
{
|
||||
for (Arbitrator.ID_VERIFICATION item : items) {
|
||||
result += Localisation.get(item.toString());
|
||||
i++;
|
||||
if (i < items.size())
|
||||
{
|
||||
if (i < items.size()) {
|
||||
result += ", ";
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static String formatDateTime(Date date)
|
||||
{
|
||||
public static String formatDateTime(Date date) {
|
||||
DateFormat dateFormatter = DateFormat.getDateInstance(DateFormat.DEFAULT, locale);
|
||||
DateFormat timeFormatter = DateFormat.getTimeInstance(DateFormat.DEFAULT, locale);
|
||||
return dateFormatter.format(date) + " " + timeFormatter.format(date);
|
||||
}
|
||||
|
||||
public static String formatCollateralPercent(long collateral)
|
||||
{
|
||||
public static String formatCollateralPercent(long collateral) {
|
||||
return getDecimalFormat(1).format(collateral / 10) + " %";
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static String formatPrice(double volume)
|
||||
{
|
||||
public static String formatPrice(double volume) {
|
||||
return formatDouble(volume);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static String formatVolume(double volume)
|
||||
{
|
||||
public static String formatVolume(double volume) {
|
||||
return formatDouble(volume);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static String formatVolumeWithMinVolume(double volume, double minVolume)
|
||||
{
|
||||
public static String formatVolumeWithMinVolume(double volume, double minVolume) {
|
||||
return formatDouble(volume) + " (" + formatDouble(minVolume) + ")";
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static String formatCoin(Coin coin)
|
||||
{
|
||||
public static String formatCoin(Coin coin) {
|
||||
return coin != null ? coin.toPlainString() : "";
|
||||
}
|
||||
|
||||
|
||||
@Deprecated
|
||||
public static String formatCoinWithCode(Coin coin)
|
||||
{
|
||||
public static String formatCoinWithCode(Coin coin) {
|
||||
return coin != null ? coin.toFriendlyString() : "";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ import org.slf4j.LoggerFactory;
|
|||
|
||||
/**
|
||||
* BtcValidator for validating BTC values.
|
||||
* <p/>
|
||||
* <p>
|
||||
* That class implements just what we need for the moment. It is not intended as a general purpose library class.
|
||||
*/
|
||||
public class BtcValidator extends NumberValidator {
|
||||
|
|
|
@ -22,7 +22,7 @@ import org.slf4j.LoggerFactory;
|
|||
|
||||
/**
|
||||
* FiatNumberValidator for validating fiat values.
|
||||
* <p/>
|
||||
* <p>
|
||||
* That class implements just what we need for the moment. It is not intended as a general purpose library class.
|
||||
*/
|
||||
public class FiatValidator extends NumberValidator {
|
||||
|
|
|
@ -25,7 +25,7 @@ import org.slf4j.LoggerFactory;
|
|||
* Localisation not supported at the moment
|
||||
* The decimal mark can be either "." or ",". Thousand separators are not supported yet,
|
||||
* but might be added alter with Local support.
|
||||
* <p/>
|
||||
* <p>
|
||||
* That class implements just what we need for the moment. It is not intended as a general purpose library class.
|
||||
*/
|
||||
public abstract class NumberValidator {
|
||||
|
|
|
@ -67,7 +67,7 @@ import org.slf4j.LoggerFactory;
|
|||
* It is the translating domain specific functionality to the messaging layer.
|
||||
* The TomP2P library codebase shall not be used outside that facade.
|
||||
* That way we limit the dependency of the TomP2P library only to that class (and it's sub components).
|
||||
* <p/>
|
||||
* <p>
|
||||
* TODO: improve callbacks that Platform.runLater is not necessary. We call usually that methods form teh UI thread.
|
||||
*/
|
||||
public class MessageFacade implements MessageBroker {
|
||||
|
|
|
@ -50,9 +50,9 @@ import static io.bitsquare.util.Validator.*;
|
|||
/**
|
||||
* Responsible for the correct execution of the sequence of tasks, message passing to the peer and message processing
|
||||
* from the peer.
|
||||
* <p/>
|
||||
* <p>
|
||||
* This class handles the role of the offerer as the Bitcoin buyer.
|
||||
* <p/>
|
||||
* <p>
|
||||
* It uses sub tasks to not pollute the main class too much with all the async result/fault handling.
|
||||
* Any data from incoming messages need to be validated before further processing.
|
||||
*/
|
||||
|
|
|
@ -33,13 +33,11 @@ import org.slf4j.LoggerFactory;
|
|||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class CreateOfferPresenterTest
|
||||
{
|
||||
public class CreateOfferPresenterTest {
|
||||
private static final Logger log = LoggerFactory.getLogger(CreateOfferPresenterTest.class);
|
||||
|
||||
@Test
|
||||
public void testBindings()
|
||||
{
|
||||
public void testBindings() {
|
||||
CreateOfferModel model = new CreateOfferModel(null, null, null, null);
|
||||
|
||||
BSFormatter.setLocale(Locale.US);
|
||||
|
@ -54,7 +52,7 @@ public class CreateOfferPresenterTest
|
|||
assertEquals(Coin.COIN, model.amountAsCoin);
|
||||
assertEquals(Fiat.valueOf("EUR", 500 * 10000), model.priceAsFiat);
|
||||
assertEquals(Fiat.valueOf("EUR", 500 * 10000), model.tradeVolumeAsFiat);
|
||||
assertEquals(Coin.parseCoin("0.1011"), model.totalToPayAsCoin);
|
||||
assertEquals(Coin.parseCoin("0.1011"), model.totalToPayAsCoin.get());
|
||||
|
||||
presenter.price.set("500");
|
||||
presenter.volume.set("500");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue