From efc2100b26f59a78c5e4c0eaf54de18954bc2db2 Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Mon, 8 Sep 2014 02:06:31 +0200 Subject: [PATCH] Add payments account screen --- src/main/java/io/bitsquare/BitSquare.java | 2 +- src/main/java/io/bitsquare/SeedNode.java | 4 +- .../io/bitsquare/gui/CachedCodeBehind.java | 2 - .../java/io/bitsquare/gui/MainController.java | 86 ++++++-------- .../io/bitsquare/gui/account/AccountCB.java | 9 +- .../account/fiataccount/FiatAccountCB.java | 74 ++++++------ .../account/fiataccount/FiatAccountModel.java | 99 ++++++++-------- .../account/fiataccount/FiatAccountPm.java | 83 ++++++------- .../account/fiataccount/FiatAccountView.fxml | 45 +++---- .../registration/RegistrationView.fxml | 3 +- .../restrictions/RestrictionsModel.java | 4 +- .../bitsquare/gui/account/setup/SetupCB.java | 4 +- .../browser/ArbitratorBrowserController.java | 2 - .../ArbitratorRegistrationController.java | 2 +- src/main/java/io/bitsquare/gui/bitsquare.css | 4 - .../gui/components/ConfidenceDisplay.java | 8 +- .../gui/components/InputTextField.java | 28 +++-- .../io/bitsquare/gui/components/Popups.java | 29 +++-- .../gui/components/ValidatedTextField.java | 34 ++---- .../gui/components/btc/AddressTextField.java | 3 +- .../gui/components/btc/BalanceTextField.java | 2 +- .../java/io/bitsquare/gui/help/HelpId.java | 4 +- .../pending/PendingTradeController.java | 8 +- .../gui/settings/SettingsController.java | 2 +- .../gui/trade/createoffer/CreateOfferCB.java | 12 +- .../trade/orderbook/OrderBookController.java | 93 ++++----------- .../io/bitsquare/gui/util/BSFormatter.java | 2 +- .../io/bitsquare/gui/util/Transitions.java | 80 +++++++------ ...r.java => BankAccountNumberValidator.java} | 29 +---- .../gui/util/validation/BtcValidator.java | 8 +- .../gui/util/validation/FiatValidator.java | 10 +- .../gui/util/validation/InputValidator.java | 10 +- .../util/validation/PasswordValidator.java | 14 +-- .../msg/BootstrappedPeerFactory.java | 2 +- .../java/io/bitsquare/msg/MessageFacade.java | 10 +- .../java/io/bitsquare/trade/TradeManager.java | 4 +- .../messages/BankTransferInitedMessage.java | 12 +- .../messages/DepositTxPublishedMessage.java | 2 +- .../RequestTakerDepositPaymentMessage.java | 10 +- .../RespondToTakeOfferRequestMessage.java | 2 +- .../messages/PayoutTxPublishedMessage.java | 2 +- ...RequestOffererPublishDepositTxMessage.java | 22 ++-- .../messages/TakeOfferFeePayedMessage.java | 6 +- src/main/java/io/bitsquare/user/User.java | 89 ++++++++------ .../resources/i18n/displayStrings.properties | 10 +- .../i18n/displayStrings_de.properties | 111 ------------------ .../i18n/displayStrings_es.properties | 111 ------------------ .../i18n/displayStrings_sv_SE.properties | 111 ------------------ .../settings/RegistrationUITestRunner.java | 101 ++++++++++++++++ 49 files changed, 549 insertions(+), 855 deletions(-) rename src/main/java/io/bitsquare/gui/util/validation/{BankAccountValidator.java => BankAccountNumberValidator.java} (57%) create mode 100644 src/test/java/io/bitsquare/gui/settings/RegistrationUITestRunner.java diff --git a/src/main/java/io/bitsquare/BitSquare.java b/src/main/java/io/bitsquare/BitSquare.java index 718e5b7eb2..d2af1e97fc 100644 --- a/src/main/java/io/bitsquare/BitSquare.java +++ b/src/main/java/io/bitsquare/BitSquare.java @@ -51,7 +51,7 @@ import lighthouse.files.AppDirectory; public class BitSquare extends Application { private static final Logger log = LoggerFactory.getLogger(BitSquare.class); - public static boolean fillFormsWithDummyData = true; + public static final boolean fillFormsWithDummyData = true; private static String APP_NAME = "Bitsquare"; private static Stage primaryStage; diff --git a/src/main/java/io/bitsquare/SeedNode.java b/src/main/java/io/bitsquare/SeedNode.java index 2ed67d65a6..3d4b67ca24 100644 --- a/src/main/java/io/bitsquare/SeedNode.java +++ b/src/main/java/io/bitsquare/SeedNode.java @@ -94,12 +94,10 @@ public class SeedNode extends Thread { /////////////////////////////////////////////////////////////////////////////////////////// public void run() { - Peer peer = startupPeer(); - + startupPeer(); for (; ; ) { try { // ping(peer); - Thread.sleep(300); } catch (InterruptedException e) { log.error(e.toString()); diff --git a/src/main/java/io/bitsquare/gui/CachedCodeBehind.java b/src/main/java/io/bitsquare/gui/CachedCodeBehind.java index bc5a16f3c9..6538388f4a 100644 --- a/src/main/java/io/bitsquare/gui/CachedCodeBehind.java +++ b/src/main/java/io/bitsquare/gui/CachedCodeBehind.java @@ -39,7 +39,6 @@ public class CachedCodeBehind extends CodeBehind else if (oldValue != null && newValue == null) deactivate(); }); - activate(); presentationModel.initialized(); } @@ -71,7 +70,6 @@ public class CachedCodeBehind extends CodeBehind log.trace("Lifecycle: terminate " + this.getClass().getSimpleName()); super.terminate(); - deactivate(); presentationModel.terminate(); } diff --git a/src/main/java/io/bitsquare/gui/MainController.java b/src/main/java/io/bitsquare/gui/MainController.java index 1b288da65e..f096522cdd 100644 --- a/src/main/java/io/bitsquare/gui/MainController.java +++ b/src/main/java/io/bitsquare/gui/MainController.java @@ -45,7 +45,9 @@ import java.util.ResourceBundle; import javax.inject.Inject; import javafx.application.Platform; +import javafx.beans.Observable; import javafx.collections.FXCollections; +import javafx.collections.ObservableList; import javafx.fxml.Initializable; import javafx.geometry.Insets; import javafx.geometry.Pos; @@ -83,8 +85,6 @@ public class MainController extends ViewController { private Pane ordersButtonButtonHolder; private boolean messageFacadeInited; private boolean walletFacadeInited; - private VBox accountComboBoxHolder; - private Pane setupView; /////////////////////////////////////////////////////////////////////////////////////////// @@ -226,7 +226,7 @@ public class MainController extends ViewController { private void fadeOutSplash() { Profiler.printMsgWithTime("MainController.fadeOutSplash"); - Transitions.blurAndRemove(viewBuilder.splashVBox); + Transitions.blur(viewBuilder.splashVBox, 700, false, true); Transitions.fadeIn(viewBuilder.menuBar); Transitions.fadeIn(viewBuilder.contentScreen); } @@ -298,13 +298,6 @@ public class MainController extends ViewController { addAccountComboBox(viewBuilder.rightNavPane); - user.getBankAccountsSizeProperty().addListener((observableValue, oldValue, newValue) -> { - if ((int) newValue == 2) - viewBuilder.rightNavPane.getChildren().add(1, accountComboBoxHolder); - else if ((int) newValue < 2) - viewBuilder.rightNavPane.getChildren().remove(accountComboBoxHolder); - }); - settingsButton = addNavButton(viewBuilder.rightNavPane, "Settings", NavigationItem.SETTINGS); accountButton = addNavButton(viewBuilder.rightNavPane, "Account", NavigationItem.ACCOUNT); @@ -350,9 +343,6 @@ public class MainController extends ViewController { } private ToggleButton addNavButton(Pane parent, String title, NavigationItem navigationItem) { - // final Pane pane = new Pane(); - // pane.setPrefSize(50, 50); - ImageView icon = ImageUtil.getIconImageView(navigationItem.getIcon()); icon.setFitWidth(32); icon.setFitHeight(32); @@ -382,19 +372,7 @@ public class MainController extends ViewController { }); toggleButton.setOnAction(e -> loadView(navigationItem)); - - /* final Label titleLabel = new Label(title); - titleLabel.setLayoutY(35); - titleLabel.setId("nav-button-label"); - titleLabel.setMouseTransparent(true); - titleLabel.widthProperty().addListener((observableValue, number, newValue) -> - titleLabel.setLayoutX((50.0 - (double) newValue) / 2 - 1)); -*/ - // pane.getChildren().addAll(toggleButton); - // pane.getChildren().addAll(toggleButton, titleLabel); - // parent.getChildren().add(pane); parent.getChildren().add(toggleButton); - return toggleButton; } @@ -412,26 +390,26 @@ public class MainController extends ViewController { }); final Label titleLabel = new Label("Balance"); - titleLabel.prefWidthProperty().bind(balanceTextField.widthProperty()); titleLabel.setMouseTransparent(true); titleLabel.setId("nav-button-label"); + balanceTextField.widthProperty().addListener((ov, o, n) -> + titleLabel.setLayoutX(((double) n - titleLabel.getWidth()) / 2)); final VBox vBox = new VBox(); - vBox.setPadding(new Insets(12, 0, 0, 0)); + vBox.setPadding(new Insets(12, 5, 0, 0)); vBox.setSpacing(2); vBox.getChildren().setAll(balanceTextField, titleLabel); + vBox.setAlignment(Pos.CENTER); parent.getChildren().add(vBox); } private void addAccountComboBox(Pane parent) { - final ComboBox accountComboBox = - new ComboBox<>(FXCollections.observableArrayList(user.getBankAccounts())); - accountComboBox.setId("nav-account-combo-box"); - accountComboBox.setLayoutY(12); - if (user.getCurrentBankAccount() != null) - accountComboBox.getSelectionModel().select(user.getCurrentBankAccount()); - accountComboBox.valueProperty().addListener((ov, oldValue, newValue) -> user.setCurrentBankAccount(newValue)); - accountComboBox.setConverter(new StringConverter() { + final ObservableList accounts = user.getBankAccounts(); + final ComboBox comboBox = + new ComboBox<>(FXCollections.observableArrayList(accounts)); + comboBox.setLayoutY(12); + comboBox.setVisibleRowCount(5); + comboBox.setConverter(new StringConverter() { @Override public String toString(BankAccount bankAccount) { return bankAccount.getAccountTitle(); @@ -443,26 +421,32 @@ public class MainController extends ViewController { } }); - user.getSelectedBankAccountIndexProperty().addListener(observable -> - accountComboBox.getSelectionModel().select(user.getCurrentBankAccount())); - user.getBankAccountsSizeProperty().addListener(observable -> { - accountComboBox.setItems(FXCollections.observableArrayList(user.getBankAccounts())); - // need to delay it a bit otherwise it will not be set - Platform.runLater(() -> accountComboBox.getSelectionModel().select(user.getCurrentBankAccount())); + comboBox.setItems(accounts); + comboBox.valueProperty().addListener((ov, oldValue, newValue) -> user.setCurrentBankAccount(newValue)); + accounts.addListener((Observable observable) -> { + comboBox.setPromptText((accounts.size() == 0) ? "No accounts" : ""); + comboBox.setDisable((accounts.isEmpty())); }); + comboBox.setPromptText((accounts.isEmpty()) ? "No accounts" : ""); + comboBox.setDisable((accounts.isEmpty())); + user.currentBankAccountProperty().addListener((ov, oldValue, newValue) -> { + if (newValue != null) + comboBox.getSelectionModel().select(newValue); + }); + comboBox.getSelectionModel().select(user.getCurrentBankAccount()); final Label titleLabel = new Label("Bank account"); - titleLabel.prefWidthProperty().bind(accountComboBox.widthProperty()); titleLabel.setMouseTransparent(true); titleLabel.setId("nav-button-label"); + comboBox.widthProperty().addListener((ov, o, n) -> + titleLabel.setLayoutX(((double) n - titleLabel.getWidth()) / 2)); - accountComboBoxHolder = new VBox(); - accountComboBoxHolder.setPadding(new Insets(12, 0, 0, 0)); - accountComboBoxHolder.setSpacing(2); - accountComboBoxHolder.getChildren().setAll(accountComboBox, titleLabel); - - if (user.getBankAccounts().size() > 1) - parent.getChildren().add(accountComboBoxHolder); + VBox vBox = new VBox(); + vBox.setPadding(new Insets(12, 8, 0, 5)); + vBox.setSpacing(2); + vBox.setAlignment(Pos.CENTER); + vBox.getChildren().setAll(comboBox, titleLabel); + parent.getChildren().add(vBox); } } @@ -510,13 +494,13 @@ class ViewBuilder { anchorPane.setId("content-pane"); leftNavPane = new HBox(); - leftNavPane.setAlignment(Pos.CENTER); + // leftNavPane.setAlignment(Pos.CENTER); leftNavPane.setSpacing(10); AnchorPane.setLeftAnchor(leftNavPane, 10d); AnchorPane.setTopAnchor(leftNavPane, 0d); rightNavPane = new HBox(); - rightNavPane.setAlignment(Pos.CENTER); + // rightNavPane.setAlignment(Pos.CENTER); rightNavPane.setSpacing(10); AnchorPane.setRightAnchor(rightNavPane, 10d); AnchorPane.setTopAnchor(rightNavPane, 0d); diff --git a/src/main/java/io/bitsquare/gui/account/AccountCB.java b/src/main/java/io/bitsquare/gui/account/AccountCB.java index f9efa9830e..3f856bb38d 100644 --- a/src/main/java/io/bitsquare/gui/account/AccountCB.java +++ b/src/main/java/io/bitsquare/gui/account/AccountCB.java @@ -32,7 +32,6 @@ import java.util.ResourceBundle; import javax.inject.Inject; -import javafx.event.ActionEvent; import javafx.scene.control.*; import javafx.scene.layout.*; @@ -46,7 +45,6 @@ public class AccountCB extends CachedCodeBehind { public Label headLineLabel; public Label titleLabel; public Tab setupTab; - private Pane setupView; /////////////////////////////////////////////////////////////////////////////////////////// // Constructor @@ -66,6 +64,7 @@ public class AccountCB extends CachedCodeBehind { public void initialize(URL url, ResourceBundle rb) { super.initialize(url, rb); + loadViewAndGetChildController(NavigationItem.SETUP); } @Override @@ -83,7 +82,7 @@ public class AccountCB extends CachedCodeBehind { super.terminate(); } - public void onRegister(ActionEvent actionEvent) { + public void onRegister() { loadViewAndGetChildController(NavigationItem.SETUP); } @@ -98,7 +97,7 @@ public class AccountCB extends CachedCodeBehind { final GuiceFXMLLoader loader = new GuiceFXMLLoader(getClass().getResource(navigationItem.getFxmlUrl())); try { - setupView = loader.load(); + Pane setupView = loader.load(); setupTab.setContent(setupView); childController = loader.getController(); @@ -111,7 +110,7 @@ public class AccountCB extends CachedCodeBehind { log.error(e.getStackTrace().toString()); } - return null; + return (CodeBehind) childController; } /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/main/java/io/bitsquare/gui/account/fiataccount/FiatAccountCB.java b/src/main/java/io/bitsquare/gui/account/fiataccount/FiatAccountCB.java index 233cbe5549..e6484b5fb2 100644 --- a/src/main/java/io/bitsquare/gui/account/fiataccount/FiatAccountCB.java +++ b/src/main/java/io/bitsquare/gui/account/fiataccount/FiatAccountCB.java @@ -21,6 +21,7 @@ import io.bitsquare.bank.BankAccount; import io.bitsquare.bank.BankAccountType; import io.bitsquare.gui.CachedCodeBehind; import io.bitsquare.gui.account.setup.SetupCB; +import io.bitsquare.gui.components.InputTextField; import io.bitsquare.gui.components.Popups; import io.bitsquare.gui.help.Help; import io.bitsquare.gui.help.HelpId; @@ -47,14 +48,16 @@ import org.controlsfx.dialog.Dialog; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import static javafx.beans.binding.Bindings.createBooleanBinding; + public class FiatAccountCB extends CachedCodeBehind { private static final Logger log = LoggerFactory.getLogger(FiatAccountCB.class); @FXML private ComboBox regionComboBox; @FXML private ComboBox countryComboBox; - @FXML private TextField titleTextField, holderNameTextField, primaryIDTextField, secondaryIDTextField; - @FXML private Button saveButton, addBankAccountButton, changeBankAccountButton, removeBankAccountButton; + @FXML private InputTextField titleTextField, holderNameTextField, primaryIDTextField, secondaryIDTextField; + @FXML private Button saveButton, doneButton, removeBankAccountButton; @FXML private ComboBox selectionComboBox; @FXML private ComboBox typesComboBox; @FXML private ComboBox currencyComboBox; @@ -86,6 +89,11 @@ public class FiatAccountCB extends CachedCodeBehind { regionComboBox.setItems(presentationModel.getAllRegions()); regionComboBox.setConverter(presentationModel.getRegionConverter()); countryComboBox.setConverter(presentationModel.getCountryConverter()); + + titleTextField.setValidator(presentationModel.getValidator()); + holderNameTextField.setValidator(presentationModel.getValidator()); + primaryIDTextField.setValidator(presentationModel.getValidator()); + secondaryIDTextField.setValidator(presentationModel.getValidator()); } @Override @@ -115,7 +123,8 @@ public class FiatAccountCB extends CachedCodeBehind { @FXML public void onSelectAccount() { - presentationModel.setCurrentBankAccount(selectionComboBox.getSelectionModel().getSelectedItem()); + if (selectionComboBox.getSelectionModel().getSelectedItem() != null) + presentationModel.selectBankAccount(selectionComboBox.getSelectionModel().getSelectedItem()); } @FXML @@ -143,30 +152,35 @@ public class FiatAccountCB extends CachedCodeBehind { @FXML private void onSave() { InputValidator.ValidationResult result = presentationModel.saveBankAccount(); - if (result.isValid) - ((SetupCB) parentController).onCompleted(this); + if (result.isValid) { + selectionComboBox.getSelectionModel().select(null); + Popups.openInfo("You can add more accounts or continue to the next step.", + "Your payments account has been saved."); + } } @FXML - private void onAddAccount() { - log.error("onAddAccount"); + private void onDone() { + if (parentController != null) + ((SetupCB) parentController).onCompleted(this); } @FXML private void onRemoveAccount() { presentationModel.removeBankAccount(); + selectionComboBox.getSelectionModel().select(null); } @FXML - private void onChangeAccount() { - log.error("onChangeAccount"); - } - - @FXML - private void onOpenHelp() { + private void onOpenSetupHelp() { Help.openWindow(HelpId.SETUP_FIAT_ACCOUNT); } + @FXML + private void onOpenManageAccountsHelp() { + Help.openWindow(HelpId.MANAGE_FIAT_ACCOUNT); + } + /////////////////////////////////////////////////////////////////////////////////////////// // Private methods @@ -187,13 +201,6 @@ public class FiatAccountCB extends CachedCodeBehind { currencyComboBox.getSelectionModel().clearSelection(); }); - presentationModel.getCurrentBankAccount().addListener((ov, oldValue, newValue) -> { - if (newValue != null) - selectionComboBox.getSelectionModel().select(selectionComboBox.getItems().indexOf(newValue)); - else - selectionComboBox.getSelectionModel().clearSelection(); - }); - presentationModel.country.addListener((ov, oldValue, newValue) -> { if (newValue != null) { regionComboBox.getSelectionModel().select(regionComboBox.getItems().indexOf(newValue.getRegion())); @@ -205,26 +212,15 @@ public class FiatAccountCB extends CachedCodeBehind { } }); - presentationModel.getAllBankAccounts().addListener((ListChangeListener) change -> { - Object a = presentationModel.getAllBankAccounts(); - Object a2 = change.getList(); - - if (presentationModel.getCurrentBankAccount() != null) - selectionComboBox.getSelectionModel().select(selectionComboBox.getItems() - .indexOf(presentationModel.getCurrentBankAccount())); - else - selectionComboBox.getSelectionModel().clearSelection(); - }); - - presentationModel.countryNotInAcceptedCountriesList.addListener((ov, oldValue, newValue) -> { + presentationModel.getCountryNotInAcceptedCountriesList().addListener((ov, oldValue, newValue) -> { if (newValue) { List actions = new ArrayList<>(); actions.add(Dialog.Actions.YES); actions.add(Dialog.Actions.NO); Action response = Popups.openConfirmPopup("Warning", - "The country of your bank account is not included in the accepted countries in the general " + - "settings.\n\nDo you want to add it automatically?", + "The country of your bank account is not included in the accepted countries in the " + + "general settings.\n\nDo you want to add it automatically?", null, actions); @@ -232,6 +228,9 @@ public class FiatAccountCB extends CachedCodeBehind { presentationModel.addCountryToAcceptedCountriesList(); } }); + + presentationModel.getAllBankAccounts().addListener((ListChangeListener) change -> + doneButton.setDisable(change.getList().isEmpty())); } private void setupBindings() { @@ -247,9 +246,10 @@ public class FiatAccountCB extends CachedCodeBehind { selectionComboBox.disableProperty().bind(presentationModel.selectionDisable); saveButton.disableProperty().bind(presentationModel.saveButtonDisable); - addBankAccountButton.disableProperty().bind(presentationModel.addBankAccountButtonDisable); - changeBankAccountButton.disableProperty().bind(presentationModel.changeBankAccountButtonDisable); - removeBankAccountButton.disableProperty().bind(presentationModel.removeBankAccountButtonDisable); + + removeBankAccountButton.disableProperty().bind(createBooleanBinding(() -> + (selectionComboBox.getSelectionModel().selectedIndexProperty().get() == -1), + selectionComboBox.getSelectionModel().selectedIndexProperty())); } } diff --git a/src/main/java/io/bitsquare/gui/account/fiataccount/FiatAccountModel.java b/src/main/java/io/bitsquare/gui/account/fiataccount/FiatAccountModel.java index 056eedcd5b..1419e5505e 100644 --- a/src/main/java/io/bitsquare/gui/account/fiataccount/FiatAccountModel.java +++ b/src/main/java/io/bitsquare/gui/account/fiataccount/FiatAccountModel.java @@ -47,26 +47,26 @@ import org.slf4j.LoggerFactory; public class FiatAccountModel extends UIModel { private static final Logger log = LoggerFactory.getLogger(FiatAccountModel.class); - private User user; - private Settings settings; - private Persistence persistence; + private final User user; + private final Settings settings; + private final Persistence persistence; - StringProperty title = new SimpleStringProperty(); - StringProperty holderName = new SimpleStringProperty(); - StringProperty primaryID = new SimpleStringProperty(); - StringProperty secondaryID = new SimpleStringProperty(); - StringProperty primaryIDPrompt = new SimpleStringProperty(); - StringProperty secondaryIDPrompt = new SimpleStringProperty(); - BooleanProperty countryNotInAcceptedCountriesList = new SimpleBooleanProperty(); - ObjectProperty type = new SimpleObjectProperty<>(); - ObjectProperty country = new SimpleObjectProperty<>(); - ObjectProperty currency = new SimpleObjectProperty<>(); - ObjectProperty currentBankAccount = new SimpleObjectProperty<>(); - ObservableList allTypes = FXCollections.observableArrayList(BankAccountType + final StringProperty title = new SimpleStringProperty(); + final StringProperty holderName = new SimpleStringProperty(); + final StringProperty primaryID = new SimpleStringProperty(); + final StringProperty secondaryID = new SimpleStringProperty(); + final StringProperty primaryIDPrompt = new SimpleStringProperty(); + final StringProperty secondaryIDPrompt = new SimpleStringProperty(); + final BooleanProperty countryNotInAcceptedCountriesList = new SimpleBooleanProperty(); + final ObjectProperty type = new SimpleObjectProperty<>(); + final ObjectProperty country = new SimpleObjectProperty<>(); + final ObjectProperty currency = new SimpleObjectProperty<>(); + final ObjectProperty currentBankAccount = new SimpleObjectProperty<>(); + final ObservableList allTypes = FXCollections.observableArrayList(BankAccountType .getAllBankAccountTypes()); - ObservableList allBankAccounts = FXCollections.observableArrayList(); - ObservableList allCurrencies = FXCollections.observableArrayList(CurrencyUtil.getAllCurrencies()); - ObservableList allRegions = FXCollections.observableArrayList(CountryUtil.getAllRegions()); + final ObservableList allBankAccounts = FXCollections.observableArrayList(); + final ObservableList allCurrencies = FXCollections.observableArrayList(CurrencyUtil.getAllCurrencies()); + final ObservableList allRegions = FXCollections.observableArrayList(CountryUtil.getAllRegions()); /////////////////////////////////////////////////////////////////////////////////////////// @@ -121,16 +121,18 @@ public class FiatAccountModel extends UIModel { holderName.get(), primaryID.get(), secondaryID.get()); - user.addBankAccount(bankAccount); - + user.setBankAccount(bankAccount); saveUser(); - + allBankAccounts.setAll(user.getBankAccounts()); countryNotInAcceptedCountriesList.set(!settings.getAcceptedCountries().contains(country.get())); + reset(); } void removeBankAccount() { user.removeCurrentBankAccount(); saveUser(); + allBankAccounts.setAll(user.getBankAccounts()); + reset(); } // We ask the user if he likes to add his own bank account country to the accepted country list if he has not @@ -138,23 +140,10 @@ public class FiatAccountModel extends UIModel { void addCountryToAcceptedCountriesList() { settings.addAcceptedCountry(country.get()); saveSettings(); + countryNotInAcceptedCountriesList.set(false); } - - /////////////////////////////////////////////////////////////////////////////////////////// - // Getters - /////////////////////////////////////////////////////////////////////////////////////////// - - ObservableList getAllCountriesFor(Region selectedRegion) { - return FXCollections.observableArrayList(CountryUtil.getAllCountriesFor(selectedRegion)); - } - - - /////////////////////////////////////////////////////////////////////////////////////////// - // Setters - /////////////////////////////////////////////////////////////////////////////////////////// - - void setCurrentBankAccount(BankAccount bankAccount) { + void selectBankAccount(BankAccount bankAccount) { currentBankAccount.set(bankAccount); user.setCurrentBankAccount(bankAccount); @@ -173,19 +162,24 @@ public class FiatAccountModel extends UIModel { currency.set(bankAccount.getCurrency()); } else { - title.set(null); - holderName.set(null); - primaryID.set(null); - secondaryID.set(null); - primaryIDPrompt.set(null); - secondaryIDPrompt.set(null); - - type.set(null); - country.set(null); - currency.set(null); + reset(); } } + + /////////////////////////////////////////////////////////////////////////////////////////// + // Getters + /////////////////////////////////////////////////////////////////////////////////////////// + + ObservableList getAllCountriesFor(Region selectedRegion) { + return FXCollections.observableArrayList(CountryUtil.getAllCountriesFor(selectedRegion)); + } + + + /////////////////////////////////////////////////////////////////////////////////////////// + // Setters + /////////////////////////////////////////////////////////////////////////////////////////// + void setType(BankAccountType type) { this.type.set(type); @@ -212,6 +206,19 @@ public class FiatAccountModel extends UIModel { // Private methods /////////////////////////////////////////////////////////////////////////////////////////// + private void reset() { + title.set(null); + holderName.set(null); + primaryID.set(null); + secondaryID.set(null); + primaryIDPrompt.set(null); + secondaryIDPrompt.set(null); + + type.set(null); + country.set(null); + currency.set(null); + } + private void saveUser() { persistence.write(user); } diff --git a/src/main/java/io/bitsquare/gui/account/fiataccount/FiatAccountPm.java b/src/main/java/io/bitsquare/gui/account/fiataccount/FiatAccountPm.java index 1e44aa4a11..4e9dc0a058 100644 --- a/src/main/java/io/bitsquare/gui/account/fiataccount/FiatAccountPm.java +++ b/src/main/java/io/bitsquare/gui/account/fiataccount/FiatAccountPm.java @@ -20,7 +20,7 @@ package io.bitsquare.gui.account.fiataccount; import io.bitsquare.bank.BankAccount; import io.bitsquare.bank.BankAccountType; import io.bitsquare.gui.PresentationModel; -import io.bitsquare.gui.util.validation.BankAccountValidator; +import io.bitsquare.gui.util.validation.BankAccountNumberValidator; import io.bitsquare.gui.util.validation.InputValidator; import io.bitsquare.locale.BSResources; import io.bitsquare.locale.Country; @@ -46,25 +46,21 @@ import org.slf4j.LoggerFactory; public class FiatAccountPm extends PresentationModel { private static final Logger log = LoggerFactory.getLogger(FiatAccountPm.class); - private BankAccountValidator bankAccountValidator = new BankAccountValidator(); + private final BankAccountNumberValidator validator = new BankAccountNumberValidator(); - StringProperty title = new SimpleStringProperty(); - StringProperty holderName = new SimpleStringProperty(); - StringProperty primaryID = new SimpleStringProperty(); - StringProperty secondaryID = new SimpleStringProperty(); - StringProperty primaryIDPrompt = new SimpleStringProperty(); - StringProperty secondaryIDPrompt = new SimpleStringProperty(); - StringProperty selectionPrompt = new SimpleStringProperty(); - BooleanProperty selectionDisable = new SimpleBooleanProperty(); - BooleanProperty saveButtonDisable = new SimpleBooleanProperty(true); - BooleanProperty addBankAccountButtonDisable = new SimpleBooleanProperty(true); - BooleanProperty changeBankAccountButtonDisable = new SimpleBooleanProperty(true); - BooleanProperty removeBankAccountButtonDisable = new SimpleBooleanProperty(true); + final StringProperty title = new SimpleStringProperty(); + final StringProperty holderName = new SimpleStringProperty(); + final StringProperty primaryID = new SimpleStringProperty(); + final StringProperty secondaryID = new SimpleStringProperty(); + final StringProperty primaryIDPrompt = new SimpleStringProperty(); + final StringProperty secondaryIDPrompt = new SimpleStringProperty(); + final StringProperty selectionPrompt = new SimpleStringProperty(); + final BooleanProperty selectionDisable = new SimpleBooleanProperty(); + final BooleanProperty saveButtonDisable = new SimpleBooleanProperty(true); - BooleanProperty countryNotInAcceptedCountriesList = new SimpleBooleanProperty(); - ObjectProperty type = new SimpleObjectProperty<>(); - ObjectProperty country = new SimpleObjectProperty<>(); - ObjectProperty currency = new SimpleObjectProperty<>(); + final ObjectProperty type = new SimpleObjectProperty<>(); + final ObjectProperty country = new SimpleObjectProperty<>(); + final ObjectProperty currency = new SimpleObjectProperty<>(); /////////////////////////////////////////////////////////////////////////////////////////// @@ -96,20 +92,11 @@ public class FiatAccountPm extends PresentationModel { primaryIDPrompt.bind(model.primaryIDPrompt); secondaryIDPrompt.bind(model.secondaryIDPrompt); - countryNotInAcceptedCountriesList.bind(model.countryNotInAcceptedCountriesList); selectionPrompt.set("No bank account available"); selectionDisable.set(true); - model.title.addListener((ov, oldValue, newValue) -> { - validateInput(); - /* - InputValidator.ValidationResult result = validateInput(); - if (result.isValid) { - result = bankAccountValidator.validate(newValue); - saveButtonDisable.set(!result.isValid); - }*/ - }); + model.title.addListener((ov, oldValue, newValue) -> validateInput()); holderName.addListener((ov, oldValue, newValue) -> validateInput()); primaryID.addListener((ov, oldValue, newValue) -> validateInput()); secondaryID.addListener((ov, oldValue, newValue) -> validateInput()); @@ -119,7 +106,6 @@ public class FiatAccountPm extends PresentationModel { public void activate() { super.activate(); - model.allBankAccounts.addListener((ListChangeListener) change -> { if (model.allBankAccounts.isEmpty()) { selectionPrompt.set("No bank account available"); @@ -151,10 +137,6 @@ public class FiatAccountPm extends PresentationModel { InputValidator.ValidationResult result = validateInput(); if (result.isValid) { model.saveBankAccount(); - - addBankAccountButtonDisable.set(false); - changeBankAccountButtonDisable.set(false); - removeBankAccountButtonDisable.set(false); } return result; } @@ -163,18 +145,14 @@ public class FiatAccountPm extends PresentationModel { model.removeBankAccount(); } - void updateDoneButtonDisabled() { - /* boolean isValid = model.languageList != null && model.languageList.size() > 0 && - model.countryList != null && model.countryList.size() > 0 && - model.arbitratorList != null && model.arbitratorList.size() > -1; - doneButtonDisabled.set(!isValid);*/ - } - - void addCountryToAcceptedCountriesList() { model.addCountryToAcceptedCountriesList(); } + void selectBankAccount(BankAccount bankAccount) { + model.selectBankAccount(bankAccount); + } + /////////////////////////////////////////////////////////////////////////////////////////// // Converters @@ -281,16 +259,15 @@ public class FiatAccountPm extends PresentationModel { return model.getAllCountriesFor(selectedRegion); } + BooleanProperty getCountryNotInAcceptedCountriesList() { + return model.countryNotInAcceptedCountriesList; + } + /////////////////////////////////////////////////////////////////////////////////////////// // Setters /////////////////////////////////////////////////////////////////////////////////////////// - void setCurrentBankAccount(BankAccount bankAccount) { - model.setCurrentBankAccount(bankAccount); - validateInput(); - } - void setType(BankAccountType type) { model.setType(type); validateInput(); @@ -312,13 +289,13 @@ public class FiatAccountPm extends PresentationModel { private InputValidator.ValidationResult validateInput() { - InputValidator.ValidationResult result = bankAccountValidator.validate(model.title.get()); + InputValidator.ValidationResult result = validator.validate(model.title.get()); if (result.isValid) { - result = bankAccountValidator.validate(model.holderName.get()); + result = validator.validate(model.holderName.get()); if (result.isValid) { - result = bankAccountValidator.validate(model.primaryID.get()); + result = validator.validate(model.primaryID.get()); if (result.isValid) { - result = bankAccountValidator.validate(model.secondaryID.get()); + result = validator.validate(model.secondaryID.get()); if (result.isValid) { if (model.currency.get() == null) result = new InputValidator.ValidationResult(false, @@ -342,4 +319,10 @@ public class FiatAccountPm extends PresentationModel { return result; } + + public InputValidator getValidator() { + return validator; + } + + } diff --git a/src/main/java/io/bitsquare/gui/account/fiataccount/FiatAccountView.fxml b/src/main/java/io/bitsquare/gui/account/fiataccount/FiatAccountView.fxml index 3b052aeb62..a08d87bc09 100644 --- a/src/main/java/io/bitsquare/gui/account/fiataccount/FiatAccountView.fxml +++ b/src/main/java/io/bitsquare/gui/account/fiataccount/FiatAccountView.fxml @@ -19,6 +19,7 @@ + @@ -57,16 +58,16 @@