From 256388e4e3626a84ed2c75d96af70a85cfd6c819 Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Wed, 30 Apr 2014 23:04:10 +0200 Subject: [PATCH] payment process update to model changes --- TODO.txt | 3 + src/main/java/io/bitsquare/BitSquare.java | 35 +- .../io/bitsquare/btc/BlockChainFacade.java | 31 +- .../java/io/bitsquare/btc/WalletFacade.java | 4 +- .../java/io/bitsquare/di/BitSquareModule.java | 2 - .../gui/components/ConfirmationComponent.java | 2 +- .../processbar/ProcessStepItem.java | 3 +- .../processbar/ProcessStepsBuilder.java | 4 +- src/main/java/io/bitsquare/gui/global.css | 19 +- .../bitsquare/gui/setup/SetupController.java | 270 +++++---- .../io/bitsquare/gui/setup/SetupView.fxml | 4 +- .../trade/offer/CreateOfferController.java | 10 +- .../trade/orderbook/OrderBookController.java | 2 +- .../tradeprocess/TradeProcessController.java | 523 ++++++++++-------- .../trade/tradeprocess/TradeProcessView.fxml | 37 +- .../io/bitsquare/gui/util/FormBuilder.java | 14 +- .../java/io/bitsquare/gui/util/GUIUtils.java | 35 -- .../settings/OrderBookFilterSettings.java | 89 --- .../java/io/bitsquare/settings/Settings.java | 31 +- .../java/io/bitsquare/trade/Contract.java | 12 - src/main/java/io/bitsquare/trade/Offer.java | 22 +- .../io/bitsquare/trade/OfferConstraint.java | 29 - src/main/java/io/bitsquare/trade/Trade.java | 2 +- src/main/java/io/bitsquare/trade/Trading.java | 1 - .../trade/orderbook/MockOrderBook.java | 73 +-- .../java/io/bitsquare/user/Arbitrator.java | 48 ++ src/main/java/io/bitsquare/user/User.java | 13 +- src/main/java/io/bitsquare/util/MockData.java | 78 +++ src/main/java/io/bitsquare/util/Utils.java | 38 +- 29 files changed, 784 insertions(+), 650 deletions(-) delete mode 100644 src/main/java/io/bitsquare/gui/util/GUIUtils.java delete mode 100644 src/main/java/io/bitsquare/settings/OrderBookFilterSettings.java delete mode 100644 src/main/java/io/bitsquare/trade/OfferConstraint.java create mode 100644 src/main/java/io/bitsquare/user/Arbitrator.java create mode 100644 src/main/java/io/bitsquare/util/MockData.java diff --git a/TODO.txt b/TODO.txt index 49d34f2dfc..30d215a34e 100644 --- a/TODO.txt +++ b/TODO.txt @@ -5,9 +5,12 @@ Messaging! low prio: +- tx confirm. not working correct and reliable - add settings after setup - settings screen - return to setup when unregistered, change/add bank accounts from settings +- warning popups +- diff --git a/src/main/java/io/bitsquare/BitSquare.java b/src/main/java/io/bitsquare/BitSquare.java index ee014497e8..cd924f5464 100644 --- a/src/main/java/io/bitsquare/BitSquare.java +++ b/src/main/java/io/bitsquare/BitSquare.java @@ -8,6 +8,7 @@ import io.bitsquare.di.GuiceFXMLLoader; import io.bitsquare.gui.util.Localisation; import io.bitsquare.settings.Settings; import io.bitsquare.storage.Storage; +import io.bitsquare.user.Arbitrator; import io.bitsquare.user.User; import javafx.application.Application; import javafx.scene.Parent; @@ -17,6 +18,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.Locale; +import java.util.UUID; public class BitSquare extends Application { @@ -41,7 +43,7 @@ public class BitSquare extends Application user.updateFromStorage((User) storage.read(user.getClass().getName())); settings.updateFromStorage((Settings) storage.read(settings.getClass().getName())); - initSettings(settings, storage); + initSettings(settings, storage, user); stage.setTitle("BitSquare"); @@ -71,11 +73,12 @@ public class BitSquare extends Application super.stop(); } - private void initSettings(Settings settings, Storage storage) + private void initSettings(Settings settings, Storage storage, User user) { Settings savedSettings = (Settings) storage.read(settings.getClass().getName()); if (savedSettings == null) { + // write default settings settings.getAcceptedCountryLocales().clear(); settings.getAcceptedLanguageLocales().clear(); @@ -90,7 +93,35 @@ public class BitSquare extends Application settings.addAcceptedCountryLocale(new Locale("en", "US")); settings.addAcceptedCountryLocale(new Locale("es", "ES")); + settings.addArbitrator(new Arbitrator("Charly Boom", UUID.randomUUID().toString(), UUID.randomUUID().toString(), "http://www.arbit.io/Charly_Boom")); + settings.addArbitrator(new Arbitrator("Tom Shang", UUID.randomUUID().toString(), UUID.randomUUID().toString(), "http://www.arbit.io/Tom_Shang")); + settings.addArbitrator(new Arbitrator("Edward Snow", UUID.randomUUID().toString(), UUID.randomUUID().toString(), "http://www.arbit.io/Edward_Swow")); + settings.addArbitrator(new Arbitrator("Julian Sander", UUID.randomUUID().toString(), UUID.randomUUID().toString(), "http://www.arbit.io/Julian_Sander")); + storage.write(settings.getClass().getName(), settings); + + /* + BankAccount bankAccount1 = new BankAccount(new BankAccountType(BankAccountType.BankAccountTypeEnum.SEPA,"Iban", "Bic"), + MockData.getCurrencies().get(0), + MockData.getLocales().get(0), + "Main account", + "Manfred Karrer", + "564613242346", + "23432432434" + ); + BankAccount bankAccount2 = new BankAccount(new BankAccountType(BankAccountType.BankAccountTypeEnum.OK_PAY,"Number", "ID"), + MockData.getCurrencies().get(0), + MockData.getLocales().get(0), + "OK account", + "Manfred Karrer", + "22312123123123123", + "asdasdasdas" + ); + user.addBankAccount(bankAccount2); + user.addBankAccount(bankAccount1); + user.setAccountID(UUID.randomUUID().toString()); + storage.write(user.getClass().getName(), user); + */ } else { diff --git a/src/main/java/io/bitsquare/btc/BlockChainFacade.java b/src/main/java/io/bitsquare/btc/BlockChainFacade.java index 3e38275873..e53e86f85a 100644 --- a/src/main/java/io/bitsquare/btc/BlockChainFacade.java +++ b/src/main/java/io/bitsquare/btc/BlockChainFacade.java @@ -1,6 +1,7 @@ package io.bitsquare.btc; import com.google.inject.Inject; +import io.bitsquare.bank.BankAccount; /** * That facade delivers blockchain functionality from the bitcoinJ library @@ -15,11 +16,14 @@ public class BlockChainFacade } - public boolean verifyAddressInBlockChain(String hashAsHexStringToVerify, String address) + public boolean verifyEmbeddedData(String address) { - return findAddressInBlockChain(address) - && getDataForTxWithAddress(hashAsHexStringToVerify, address) - && isFeePayed(address); + return true; + /* + if (findAddressInBlockChain(address) && isFeePayed(address)) + return getDataForTxWithAddress(address) != null; + else + return true; */ } private boolean findAddressInBlockChain(String address) @@ -29,11 +33,11 @@ public class BlockChainFacade return true; } - private boolean getDataForTxWithAddress(String hashToVerify, String address) + private byte[] getDataForTxWithAddress(String address) { // TODO - // check if data after OP_RETURN match hashToVerify - return true; + // return data after OP_RETURN + return null; } private boolean isFeePayed(String address) @@ -43,4 +47,17 @@ public class BlockChainFacade return true; } + public boolean isAccountIDBlacklisted(String accountID) + { + // TODO + // check if accountID is on blacklist + return false; + } + + public boolean isBankAccountBlacklisted(BankAccount bankAccount) + { + // TODO + // check if accountID is on blacklist + return false; + } } diff --git a/src/main/java/io/bitsquare/btc/WalletFacade.java b/src/main/java/io/bitsquare/btc/WalletFacade.java index cd5d6844d1..55006aea50 100644 --- a/src/main/java/io/bitsquare/btc/WalletFacade.java +++ b/src/main/java/io/bitsquare/btc/WalletFacade.java @@ -171,9 +171,11 @@ public class WalletFacade implements WalletEventListener public boolean verifyAccountRegistration(String address, String hashAsHexStringToVerify, byte[] pubKey, String bankAccountIDs, String signatureBankAccountIDs) { + return true; + /* return cryptoFacade.verifySignature(pubKey, bankAccountIDs, signatureBankAccountIDs) && cryptoFacade.verifyHash(hashAsHexStringToVerify, bankAccountIDs, signatureBankAccountIDs) - && blockChainFacade.verifyAddressInBlockChain(hashAsHexStringToVerify, address); + && blockChainFacade.verifyEmbeddedData(address); */ } public int getRegConfNumBroadcastPeers() diff --git a/src/main/java/io/bitsquare/di/BitSquareModule.java b/src/main/java/io/bitsquare/di/BitSquareModule.java index 94a9048f39..7cba1a3cf1 100644 --- a/src/main/java/io/bitsquare/di/BitSquareModule.java +++ b/src/main/java/io/bitsquare/di/BitSquareModule.java @@ -14,7 +14,6 @@ import io.bitsquare.btc.BlockChainFacade; import io.bitsquare.btc.WalletFacade; import io.bitsquare.crypto.CryptoFacade; import io.bitsquare.msg.MessageFacade; -import io.bitsquare.settings.OrderBookFilterSettings; import io.bitsquare.settings.Settings; import io.bitsquare.storage.Storage; import io.bitsquare.trade.Trading; @@ -36,7 +35,6 @@ public class BitSquareModule extends AbstractModule bind(Storage.class).asEagerSingleton(); bind(Settings.class).asEagerSingleton(); bind(OrderBookFilter.class).asEagerSingleton(); - bind(OrderBookFilterSettings.class).asEagerSingleton(); bind(CryptoFacade.class).asEagerSingleton(); bind(WalletFacade.class).asEagerSingleton(); diff --git a/src/main/java/io/bitsquare/gui/components/ConfirmationComponent.java b/src/main/java/io/bitsquare/gui/components/ConfirmationComponent.java index 092670e870..4151b6a310 100644 --- a/src/main/java/io/bitsquare/gui/components/ConfirmationComponent.java +++ b/src/main/java/io/bitsquare/gui/components/ConfirmationComponent.java @@ -33,7 +33,7 @@ public class ConfirmationComponent implements WalletFacade.WalletListener { confirmIconImageView.setImage(getConfirmIconImage(numBroadcastPeers, depthInBlocks)); confirmationsLabel.setText(getConfirmationsText(numBroadcastPeers, depthInBlocks)); - if (depthInBlocks == 0) + if (depthInBlocks == 0 && numBroadcastPeers > 0) confirmSpinner.setProgress(-1); else confirmSpinner.setOpacity(0); diff --git a/src/main/java/io/bitsquare/gui/components/processbar/ProcessStepItem.java b/src/main/java/io/bitsquare/gui/components/processbar/ProcessStepItem.java index a953f76c0d..6aa2b4267e 100644 --- a/src/main/java/io/bitsquare/gui/components/processbar/ProcessStepItem.java +++ b/src/main/java/io/bitsquare/gui/components/processbar/ProcessStepItem.java @@ -1,5 +1,6 @@ package io.bitsquare.gui.components.processbar; +import io.bitsquare.gui.util.Colors; import javafx.scene.paint.Paint; public class ProcessStepItem @@ -10,7 +11,7 @@ public class ProcessStepItem public ProcessStepItem(String label) { - this(label, Paint.valueOf("#000000"), false); + this(label, Colors.BLUE, false); } public ProcessStepItem(String label, Paint color) diff --git a/src/main/java/io/bitsquare/gui/components/processbar/ProcessStepsBuilder.java b/src/main/java/io/bitsquare/gui/components/processbar/ProcessStepsBuilder.java index 26a0533310..0a6e9c88e9 100644 --- a/src/main/java/io/bitsquare/gui/components/processbar/ProcessStepsBuilder.java +++ b/src/main/java/io/bitsquare/gui/components/processbar/ProcessStepsBuilder.java @@ -1,6 +1,6 @@ package io.bitsquare.gui.components.processbar; -import io.bitsquare.gui.util.GUIUtils; +import io.bitsquare.util.Utils; import javafx.animation.AnimationTimer; import javafx.scene.control.Button; import javafx.scene.control.Control; @@ -65,7 +65,7 @@ public class ProcessStepsBuilder // TODO // mock simulate network delay - GUIUtils.setTimeout(100, (AnimationTimer animationTimer) -> { + Utils.setTimeout(100, (AnimationTimer animationTimer) -> { next(); return null; }); diff --git a/src/main/java/io/bitsquare/gui/global.css b/src/main/java/io/bitsquare/gui/global.css index f1ac14a825..dac2546c34 100644 --- a/src/main/java/io/bitsquare/gui/global.css +++ b/src/main/java/io/bitsquare/gui/global.css @@ -45,6 +45,21 @@ -fx-text-fill: #0096c9; } +.text-field:readonly { + -fx-text-fill: #000000; + -fx-background-color: #ffffff; +} + +#feedback-text { + -fx-font-size: 10; +} + +#label-url { + -fx-cursor: hand; + -fx-text-fill: blue; + -fx-underline: true; +} + /* table */ #orderbook-table .table-cell { @@ -59,10 +74,6 @@ -fx-alignment: center; } -#feedback-text { - -fx-font-size: 10; -} - /* forms */ #form-header-text { -fx-font-weight: bold; diff --git a/src/main/java/io/bitsquare/gui/setup/SetupController.java b/src/main/java/io/bitsquare/gui/setup/SetupController.java index d4fe9ac265..7110c7317c 100644 --- a/src/main/java/io/bitsquare/gui/setup/SetupController.java +++ b/src/main/java/io/bitsquare/gui/setup/SetupController.java @@ -7,16 +7,16 @@ import de.jensd.fx.fontawesome.AwesomeIcon; import io.bitsquare.bank.BankAccount; import io.bitsquare.bank.BankAccountType; import io.bitsquare.btc.WalletFacade; -import io.bitsquare.crypto.CryptoFacade; import io.bitsquare.gui.ChildController; import io.bitsquare.gui.NavigationController; import io.bitsquare.gui.components.ConfirmationComponent; import io.bitsquare.gui.components.NetworkSyncPane; import io.bitsquare.gui.components.processbar.ProcessStepBar; import io.bitsquare.gui.components.processbar.ProcessStepItem; -import io.bitsquare.gui.util.*; +import io.bitsquare.gui.util.FormBuilder; import io.bitsquare.gui.util.Formatter; -import io.bitsquare.settings.Settings; +import io.bitsquare.gui.util.Localisation; +import io.bitsquare.gui.util.Verification; import io.bitsquare.storage.Storage; import io.bitsquare.user.User; import io.bitsquare.util.Utils; @@ -27,7 +27,9 @@ import javafx.scene.input.Clipboard; import javafx.scene.input.ClipboardContent; import javafx.scene.layout.AnchorPane; import javafx.scene.layout.GridPane; +import javafx.scene.layout.VBox; import javafx.util.StringConverter; +import org.controlsfx.dialog.Dialogs; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -41,12 +43,8 @@ public class SetupController implements Initializable, ChildController, WalletFa private User user; private final WalletFacade walletFacade; - private CryptoFacade cryptoFacade; - private Settings settings; private Storage storage; - private List processStepItems = new ArrayList(); - private NavigationController navigationController; private TextField balanceLabel, accountTitle, accountHolderName, accountPrimaryID, accountSecondaryID; private ComboBox countryComboBox, bankTransferTypeComboBox, currencyComboBox; @@ -59,32 +57,29 @@ public class SetupController implements Initializable, ChildController, WalletFa @FXML private ProcessStepBar processStepBar; @FXML - private GridPane formGridPane; + private GridPane gridPane; @FXML private Button nextButton, skipButton; + @FXML + private VBox vBox; + /////////////////////////////////////////////////////////////////////////////////////////// + // Constructor(s) + /////////////////////////////////////////////////////////////////////////////////////////// + @Inject - public SetupController(User user, WalletFacade walletFacade, CryptoFacade cryptoFacade, Settings settings, Storage storage) + public SetupController(User user, WalletFacade walletFacade, Storage storage) { this.user = user; this.walletFacade = walletFacade; - this.cryptoFacade = cryptoFacade; - this.settings = settings; this.storage = storage; } - public void initialize(URL url, ResourceBundle rb) - { - processStepItems.add(new ProcessStepItem("Fund registration fee", Colors.BLUE)); - processStepItems.add(new ProcessStepItem("Add Bank account", Colors.BLUE)); - processStepItems.add(new ProcessStepItem("Complete", Colors.BLUE)); - processStepBar.setProcessStepItems(processStepItems); - walletFacade.addRegistrationWalletListener(this); - - buildStep0(); - } + /////////////////////////////////////////////////////////////////////////////////////////// + // Public methods + /////////////////////////////////////////////////////////////////////////////////////////// // pass in NetworkSyncPane from parent view public void setNetworkSyncPane(NetworkSyncPane networkSyncPane) @@ -92,12 +87,40 @@ public class SetupController implements Initializable, ChildController, WalletFa rootContainer.getChildren().add(networkSyncPane); } + + /////////////////////////////////////////////////////////////////////////////////////////// + // Interface implementation: Initializable + /////////////////////////////////////////////////////////////////////////////////////////// + + @Override + public void initialize(URL url, ResourceBundle rb) + { + processStepItems.add(new ProcessStepItem("Fund registration fee")); + processStepItems.add(new ProcessStepItem("Add Bank account")); + processStepItems.add(new ProcessStepItem("Complete")); + processStepBar.setProcessStepItems(processStepItems); + + walletFacade.addRegistrationWalletListener(this); + + buildStep0(); + } + + + /////////////////////////////////////////////////////////////////////////////////////////// + // Interface implementation: ChildController + /////////////////////////////////////////////////////////////////////////////////////////// + @Override public void setNavigationController(NavigationController navigationController) { this.navigationController = navigationController; } + + /////////////////////////////////////////////////////////////////////////////////////////// + // Interface implementation: WalletFacade.WalletListener + /////////////////////////////////////////////////////////////////////////////////////////// + @Override public void onConfidenceChanged(int numBroadcastPeers, int depthInBlocks) { @@ -115,40 +138,9 @@ public class SetupController implements Initializable, ChildController, WalletFa } - private void close() - { - walletFacade.removeRegistrationWalletListener(this); - navigationController.navigateToView(NavigationController.HOME, ""); - } - - // TODO need checks per bankTransferType - private boolean verifyBankAccountData() - { - boolean accountIDsByBankTransferTypeValid = Verification.verifyAccountIDsByBankTransferType(bankTransferTypeComboBox.getSelectionModel().getSelectedItem(), - accountPrimaryID.getText(), - accountSecondaryID.getText()); - - return bankTransferTypeComboBox.getSelectionModel().getSelectedItem() != null - && countryComboBox.getSelectionModel().getSelectedItem() != null - && currencyComboBox.getSelectionModel().getSelectedItem() != null - && accountTitle.getText().length() > 0 - && accountHolderName.getText().length() > 0 - && accountPrimaryID.getText().length() > 0 - && accountSecondaryID.getText().length() > 0 - && accountIDsByBankTransferTypeValid; - } - - - private void updateCreateAccountButton() - { - boolean funded = walletFacade.getAccountRegistrationBalance().compareTo(BigInteger.ZERO) > 0; - nextButton.setDisable(!funded || walletFacade.getRegConfDepthInBlocks() == 0); - } - - - /////////////////////////////////////////////////////////////////////////////////// - // GUI BUILDER - /////////////////////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////////// + // Private methods + /////////////////////////////////////////////////////////////////////////////////////////// private void buildStep0() { @@ -159,19 +151,19 @@ public class SetupController implements Initializable, ChildController, WalletFa "Your trading account will be the source for your reputation in the trading platform.\n\n" + "You need at least 1 confirmation for doing the registration payment."); - int gridRow = -1; + int row = -1; - TextField addressLabel = FormBuilder.addTextField(formGridPane, "Registration address:", walletFacade.getAccountRegistrationAddress().toString(), ++gridRow, false, true); + TextField addressLabel = FormBuilder.addTextField(gridPane, "Registration address:", walletFacade.getAccountRegistrationAddress().toString(), ++row, false, true); Label copyIcon = new Label(""); - formGridPane.add(copyIcon, 2, gridRow); + gridPane.add(copyIcon, 2, row); copyIcon.setId("copy-icon"); AwesomeDude.setIcon(copyIcon, AwesomeIcon.COPY); Tooltip.install(copyIcon, new Tooltip("Copy address to clipboard")); - balanceLabel = FormBuilder.addTextField(formGridPane, "Balance:", Formatter.formatSatoshis(walletFacade.getAccountRegistrationBalance(), true), ++gridRow); + balanceLabel = FormBuilder.addTextField(gridPane, "Balance:", Formatter.formatSatoshis(walletFacade.getAccountRegistrationBalance(), true), ++row); - ConfirmationComponent confirmationComponent = new ConfirmationComponent(walletFacade, formGridPane, ++gridRow); + new ConfirmationComponent(walletFacade, gridPane, ++row); nextButton.setText("Payment done"); updateCreateAccountButton(); @@ -200,9 +192,9 @@ public class SetupController implements Initializable, ChildController, WalletFa "That data will be stored in the blockchain in a way that your privacy is protected.\n" + "Only your trading partners will be able to read those data, so your privacy will be protected."); - formGridPane.getChildren().clear(); - int gridRow = -1; - bankTransferTypeComboBox = FormBuilder.addComboBox(formGridPane, "Bank account type:", Utils.getAllBankAccountTypes(), ++gridRow); + gridPane.getChildren().clear(); + int row = -1; + bankTransferTypeComboBox = FormBuilder.addComboBox(gridPane, "Bank account type:", Utils.getAllBankAccountTypes(), ++row); bankTransferTypeComboBox.setConverter(new StringConverter() { @Override @@ -219,12 +211,12 @@ public class SetupController implements Initializable, ChildController, WalletFa }); bankTransferTypeComboBox.setPromptText("Select bank account type"); - accountTitle = FormBuilder.addInputField(formGridPane, "Bank account title:", "", ++gridRow); - accountHolderName = FormBuilder.addInputField(formGridPane, "Bank account holder name:", "", ++gridRow); - accountPrimaryID = FormBuilder.addInputField(formGridPane, "Bank account primary ID", "", ++gridRow); - accountSecondaryID = FormBuilder.addInputField(formGridPane, "Bank account secondary ID:", "", ++gridRow); + accountTitle = FormBuilder.addInputField(gridPane, "Bank account title:", "", ++row); + accountHolderName = FormBuilder.addInputField(gridPane, "Bank account holder name:", "", ++row); + accountPrimaryID = FormBuilder.addInputField(gridPane, "Bank account primary ID", "", ++row); + accountSecondaryID = FormBuilder.addInputField(gridPane, "Bank account secondary ID:", "", ++row); - currencyComboBox = FormBuilder.addComboBox(formGridPane, "Currency used for bank account:", Utils.getAllCurrencies(), ++gridRow); + currencyComboBox = FormBuilder.addComboBox(gridPane, "Currency used for bank account:", Utils.getAllCurrencies(), ++row); currencyComboBox.setPromptText("Select currency"); currencyComboBox.setConverter(new StringConverter() { @@ -241,7 +233,7 @@ public class SetupController implements Initializable, ChildController, WalletFa } }); - countryComboBox = FormBuilder.addComboBox(formGridPane, "Country of bank account:", Utils.getAllLocales(), ++gridRow); + countryComboBox = FormBuilder.addComboBox(gridPane, "Country of bank account:", Utils.getAllLocales(), ++row); countryComboBox.setPromptText("Select country"); countryComboBox.setConverter(new StringConverter() { @@ -260,7 +252,7 @@ public class SetupController implements Initializable, ChildController, WalletFa addBankAccountButton = new Button("Add other Bank account"); - formGridPane.add(addBankAccountButton, 1, ++gridRow); + gridPane.add(addBankAccountButton, 1, ++row); nextButton.setText("Create account"); checkCreateAccountButtonState(); @@ -318,22 +310,100 @@ public class SetupController implements Initializable, ChildController, WalletFa buildStep2(); } catch (InsufficientMoneyException e1) { - log.warn(e1.toString()); - // TODO - processStepBar.next(); - buildStep2(); + Dialogs.create() + .title("Not enough money available") + .message("There is not enough money available. Please pay in first to your wallet.") + .nativeTitleBar() + .lightweight() + .showError(); } } - else - { - log.warn("You need to add a bank account first!"); - //TODO warning popup - } }); skipButton.setOnAction(e -> close()); } + private void buildStep2() + { + vBox.getChildren().remove(infoLabel); + vBox.getChildren().remove(nextButton); + vBox.getChildren().remove(skipButton); + + gridPane.getChildren().clear(); + int row = -1; + + FormBuilder.addHeaderLabel(gridPane, "Registration complete", ++row); + FormBuilder.addTextField(gridPane, "Registration address:", walletFacade.getAccountRegistrationAddress().toString(), ++row); + FormBuilder.addTextField(gridPane, "Balance:", Formatter.formatSatoshis(walletFacade.getAccountRegistrationBalance(), true), ++row); + + Button closeButton = FormBuilder.addButton(gridPane, "Close", ++row); + closeButton.setDefaultButton(true); + closeButton.setOnAction(e -> close()); + + FormBuilder.addVSpacer(gridPane, ++row); + + FormBuilder.addHeaderLabel(gridPane, "Summary", ++row); + Label info = new Label("You have saved following bank accounts with your trading account to the blockchain:"); + gridPane.add(info, 0, ++row); + GridPane.setColumnSpan(info, 3); + + FormBuilder.addVSpacer(gridPane, ++row); + + List bankAccounts = user.getBankAccounts(); + Iterator iterator = bankAccounts.iterator(); + int index = 0; + while (iterator.hasNext()) + { + FormBuilder.addHeaderLabel(gridPane, "Bank account " + (index + 1), ++row); + BankAccount bankAccount = iterator.next(); + // need to get updated row from subroutine + row = buildBankAccountDetails(bankAccount, ++row); + FormBuilder.addVSpacer(gridPane, ++row); + index++; + } + } + + private void close() + { + walletFacade.removeRegistrationWalletListener(this); + navigationController.navigateToView(NavigationController.HOME, ""); + } + + + // util + private int buildBankAccountDetails(BankAccount bankAccount, int row) + { + FormBuilder.addTextField(gridPane, "Bank account holder name:", bankAccount.getAccountHolderName(), ++row); + FormBuilder.addTextField(gridPane, "Bank account type", bankAccount.getBankAccountType().toString(), ++row); + FormBuilder.addTextField(gridPane, "Bank account primary ID", bankAccount.getAccountPrimaryID(), ++row); + FormBuilder.addTextField(gridPane, "Bank account secondary ID:", bankAccount.getAccountSecondaryID(), ++row); + return row; + } + + // TODO need checks per bankTransferType + private boolean verifyBankAccountData() + { + boolean accountIDsByBankTransferTypeValid = Verification.verifyAccountIDsByBankTransferType(bankTransferTypeComboBox.getSelectionModel().getSelectedItem(), + accountPrimaryID.getText(), + accountSecondaryID.getText()); + + return bankTransferTypeComboBox.getSelectionModel().getSelectedItem() != null + && countryComboBox.getSelectionModel().getSelectedItem() != null + && currencyComboBox.getSelectionModel().getSelectedItem() != null + && accountTitle.getText().length() > 0 + && accountHolderName.getText().length() > 0 + && accountPrimaryID.getText().length() > 0 + && accountSecondaryID.getText().length() > 0 + && accountIDsByBankTransferTypeValid; + } + + private void updateCreateAccountButton() + { + boolean funded = walletFacade.getAccountRegistrationBalance().compareTo(BigInteger.ZERO) > 0; + nextButton.setDisable(!funded || walletFacade.getRegConfDepthInBlocks() == 0); + } + + private void addBankAccount() { if (verifyBankAccountData()) @@ -355,47 +425,5 @@ public class SetupController implements Initializable, ChildController, WalletFa nextButton.setDisable(!verifyBankAccountData()); addBankAccountButton.setDisable(!verifyBankAccountData()); } - - private void buildStep2() - { - infoLabel.setText("Summary:\n" + - "You have saved following bank accounts with your trading account to the blockchain:"); - - formGridPane.getChildren().clear(); - int gridRow = -1; - List bankAccounts = user.getBankAccounts(); - Iterator iterator = bankAccounts.iterator(); - int index = 0; - while (iterator.hasNext()) - { - FormBuilder.addHeaderLabel(formGridPane, "Bank account " + (index + 1), ++gridRow); - BankAccount bankAccount = iterator.next(); - // need to get updated gridRow from subroutine - gridRow = buildBankAccountDetails(bankAccount, ++gridRow); - FormBuilder.addVSpacer(formGridPane, ++gridRow); - index++; - } - FormBuilder.addVSpacer(formGridPane, ++gridRow); - FormBuilder.addTextField(formGridPane, "Registration address:", walletFacade.getAccountRegistrationAddress().toString(), ++gridRow); - FormBuilder.addTextField(formGridPane, "Balance:", Formatter.formatSatoshis(walletFacade.getAccountRegistrationBalance(), true), ++gridRow); - - nextButton.setText("Done"); - skipButton.setOpacity(0); - - // handlers - nextButton.setOnAction(e -> close()); - } - - // util - private int buildBankAccountDetails(BankAccount bankAccount, int row) - { - FormBuilder.addTextField(formGridPane, "Bank account holder name:", bankAccount.getAccountHolderName(), ++row); - FormBuilder.addTextField(formGridPane, "Bank account type", bankAccount.getBankAccountType().toString(), ++row); - FormBuilder.addTextField(formGridPane, "Bank account primary ID", bankAccount.getAccountPrimaryID(), ++row); - FormBuilder.addTextField(formGridPane, "Bank account secondary ID:", bankAccount.getAccountSecondaryID(), ++row); - return row; - } - - } diff --git a/src/main/java/io/bitsquare/gui/setup/SetupView.fxml b/src/main/java/io/bitsquare/gui/setup/SetupView.fxml index 8490499276..9a59919c97 100644 --- a/src/main/java/io/bitsquare/gui/setup/SetupView.fxml +++ b/src/main/java/io/bitsquare/gui/setup/SetupView.fxml @@ -8,12 +8,12 @@ - +