diff --git a/src/main/java/io/bitsquare/bank/BankAccountType.java b/src/main/java/io/bitsquare/bank/BankAccountType.java index 9e92f26193..8361703f1c 100644 --- a/src/main/java/io/bitsquare/bank/BankAccountType.java +++ b/src/main/java/io/bitsquare/bank/BankAccountType.java @@ -21,6 +21,7 @@ import java.util.ArrayList; import java.util.Arrays; public enum BankAccountType { + IRC("", ""), SEPA("IBAN", "BIC"), WIRE("primary ID", "secondary ID"), INTERNATIONAL("primary ID", "secondary ID"), diff --git a/src/main/java/io/bitsquare/gui/Navigation.java b/src/main/java/io/bitsquare/gui/Navigation.java index be48d5b898..b69e3974bd 100644 --- a/src/main/java/io/bitsquare/gui/Navigation.java +++ b/src/main/java/io/bitsquare/gui/Navigation.java @@ -200,7 +200,7 @@ public class Navigation { CHANGE_PASSWORD("/io/bitsquare/gui/main/account/content/password/PasswordView.fxml"), RESTRICTIONS("/io/bitsquare/gui/main/account/content/restrictions/RestrictionsView.fxml"), REGISTRATION("/io/bitsquare/gui/main/account/content/registration/RegistrationView.fxml"), - FIAT_ACCOUNT("/io/bitsquare/gui/main/account/content/fiat/FiatAccountView.fxml"), + FIAT_ACCOUNT("/io/bitsquare/gui/main/account/content/irc/IrcAccountView.fxml"), /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/main/java/io/bitsquare/gui/bitsquare.css b/src/main/java/io/bitsquare/gui/bitsquare.css index f13ddc4861..ec928a034e 100644 --- a/src/main/java/io/bitsquare/gui/bitsquare.css +++ b/src/main/java/io/bitsquare/gui/bitsquare.css @@ -348,7 +348,7 @@ textfield */ #wizard-title-deactivated { -fx-font-weight: bold; -fx-font-size: 16; - -fx-text-fill: #CCCCCC; + -fx-text-fill: #999999; } #wizard-title-active { -fx-font-weight: bold; @@ -362,7 +362,7 @@ textfield */ } #wizard-sub-title-deactivated { - -fx-text-fill: #CCCCCC; + -fx-text-fill: #999999; } #wizard-sub-title-active { -fx-text-fill: #333333; @@ -409,7 +409,7 @@ textfield */ #wizard-title-disabled { -fx-font-weight: bold; -fx-font-size: 16; - -fx-text-fill: #CCCCCC; + -fx-text-fill: #999999; } #wizard-title-active { -fx-font-weight: bold; diff --git a/src/main/java/io/bitsquare/gui/main/account/content/fiat/FiatAccountViewCB.java b/src/main/java/io/bitsquare/gui/main/account/content/fiat/FiatAccountViewCB.java index 6f15eb3b1c..5e70b8ef4b 100644 --- a/src/main/java/io/bitsquare/gui/main/account/content/fiat/FiatAccountViewCB.java +++ b/src/main/java/io/bitsquare/gui/main/account/content/fiat/FiatAccountViewCB.java @@ -187,7 +187,7 @@ public class FiatAccountViewCB extends CachedViewCB implements Co @FXML void onCompleted() { - if (parent != null) + if (parent instanceof MultiStepNavigation) ((MultiStepNavigation) parent).nextStep(this); } diff --git a/src/main/java/io/bitsquare/gui/main/account/content/irc/IrcAccountModel.java b/src/main/java/io/bitsquare/gui/main/account/content/irc/IrcAccountModel.java new file mode 100644 index 0000000000..427ec916c9 --- /dev/null +++ b/src/main/java/io/bitsquare/gui/main/account/content/irc/IrcAccountModel.java @@ -0,0 +1,211 @@ +/* + * This file is part of Bitsquare. + * + * Bitsquare is free software: you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at + * your option) any later version. + * + * Bitsquare is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + * License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Bitsquare. If not, see . + */ + +package io.bitsquare.gui.main.account.content.irc; + +import io.bitsquare.arbitrator.Arbitrator; +import io.bitsquare.arbitrator.Reputation; +import io.bitsquare.bank.BankAccount; +import io.bitsquare.bank.BankAccountType; +import io.bitsquare.gui.UIModel; +import io.bitsquare.locale.Country; +import io.bitsquare.locale.CountryUtil; +import io.bitsquare.locale.CurrencyUtil; +import io.bitsquare.locale.LanguageUtil; +import io.bitsquare.locale.Region; +import io.bitsquare.msg.MessageFacade; +import io.bitsquare.persistence.Persistence; +import io.bitsquare.settings.Settings; +import io.bitsquare.user.User; +import io.bitsquare.util.DSAKeyUtil; + +import org.bitcoinj.core.Coin; +import org.bitcoinj.core.ECKey; +import org.bitcoinj.core.Utils; + +import com.google.inject.Inject; + +import java.util.ArrayList; +import java.util.Currency; +import java.util.List; +import java.util.Locale; + +import javafx.beans.property.ObjectProperty; +import javafx.beans.property.SimpleObjectProperty; +import javafx.beans.property.SimpleStringProperty; +import javafx.beans.property.StringProperty; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +class IrcAccountModel extends UIModel { + private static final Logger log = LoggerFactory.getLogger(IrcAccountModel.class); + + private final User user; + private final Settings settings; + private MessageFacade messageFacade; + private final Persistence persistence; + + final StringProperty nickName = new SimpleStringProperty(); + final ObjectProperty type = new SimpleObjectProperty<>(); + final ObjectProperty currency = new SimpleObjectProperty<>(); + + final ObservableList allTypes = FXCollections.observableArrayList(BankAccountType + .getAllBankAccountTypes()); + final ObservableList allCurrencies = FXCollections.observableArrayList(CurrencyUtil + .getAllCurrencies()); + final ObservableList allBankAccounts = FXCollections.observableArrayList(); + + + /////////////////////////////////////////////////////////////////////////////////////////// + // Constructor + /////////////////////////////////////////////////////////////////////////////////////////// + + @Inject + IrcAccountModel(User user, Persistence persistence, Settings settings, MessageFacade messageFacade) { + this.persistence = persistence; + this.user = user; + this.settings = settings; + this.messageFacade = messageFacade; + } + + + /////////////////////////////////////////////////////////////////////////////////////////// + // Lifecycle + /////////////////////////////////////////////////////////////////////////////////////////// + + @SuppressWarnings("EmptyMethod") + @Override + public void initialize() { + super.initialize(); + + if (settings.getAcceptedArbitrators().isEmpty()) + addMockArbitrator(); + } + + @Override + public void activate() { + super.activate(); + allBankAccounts.setAll(user.getBankAccounts()); + } + + @SuppressWarnings("EmptyMethod") + @Override + public void deactivate() { + super.deactivate(); + } + + @SuppressWarnings("EmptyMethod") + @Override + public void terminate() { + super.terminate(); + } + + + /////////////////////////////////////////////////////////////////////////////////////////// + // Public + /////////////////////////////////////////////////////////////////////////////////////////// + + void saveBankAccount() { + BankAccount bankAccount = new BankAccount(type.get(), + currency.get(), + CountryUtil.getDefaultCountry(), + nickName.get(), + nickName.get(), + "irc", + "irc"); + user.setBankAccount(bankAccount); + saveUser(); + allBankAccounts.setAll(user.getBankAccounts()); + reset(); + } + + + /////////////////////////////////////////////////////////////////////////////////////////// + // Getters + /////////////////////////////////////////////////////////////////////////////////////////// + + ObservableList getAllCountriesFor(Region selectedRegion) { + return FXCollections.observableArrayList(CountryUtil.getAllCountriesFor(selectedRegion)); + } + + + /////////////////////////////////////////////////////////////////////////////////////////// + // Setters + /////////////////////////////////////////////////////////////////////////////////////////// + + void setType(BankAccountType type) { + this.type.set(type); + } + + void setCurrency(Currency currency) { + this.currency.set(currency); + } + + + /////////////////////////////////////////////////////////////////////////////////////////// + // Private methods + /////////////////////////////////////////////////////////////////////////////////////////// + + private void reset() { + nickName.set(null); + + type.set(null); + currency.set(null); + } + + private void saveUser() { + persistence.write(user); + } + + private void saveSettings() { + persistence.write(settings); + } + + private void addMockArbitrator() { + if (settings.getAcceptedArbitrators().isEmpty() && user.getMessageKeyPair() != null) { + String pubKeyAsHex = Utils.HEX.encode(new ECKey().getPubKey()); + String messagePubKeyAsHex = DSAKeyUtil.getHexStringFromPublicKey(user.getMessagePublicKey()); + List languages = new ArrayList<>(); + languages.add(LanguageUtil.getDefaultLanguageLocale()); + List arbitrationMethods = new ArrayList<>(); + arbitrationMethods.add(Arbitrator.METHOD.TLS_NOTARY); + List idVerifications = new ArrayList<>(); + idVerifications.add(Arbitrator.ID_VERIFICATION.PASSPORT); + idVerifications.add(Arbitrator.ID_VERIFICATION.GOV_ID); + + Arbitrator arbitrator = new Arbitrator(pubKeyAsHex, + messagePubKeyAsHex, + "Manfred Karrer", + Arbitrator.ID_TYPE.REAL_LIFE_ID, + languages, + new Reputation(), + Coin.parseCoin("0.1"), + arbitrationMethods, + idVerifications, + "http://bitsquare.io/", + "Bla bla..."); + + settings.addAcceptedArbitrator(arbitrator); + persistence.write(settings); + + messageFacade.addArbitrator(arbitrator); + } + } +} diff --git a/src/main/java/io/bitsquare/gui/main/account/content/irc/IrcAccountPm.java b/src/main/java/io/bitsquare/gui/main/account/content/irc/IrcAccountPm.java new file mode 100644 index 0000000000..70af7ad6cc --- /dev/null +++ b/src/main/java/io/bitsquare/gui/main/account/content/irc/IrcAccountPm.java @@ -0,0 +1,204 @@ +/* + * This file is part of Bitsquare. + * + * Bitsquare is free software: you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at + * your option) any later version. + * + * Bitsquare is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + * License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Bitsquare. If not, see . + */ + +package io.bitsquare.gui.main.account.content.irc; + +import io.bitsquare.bank.BankAccount; +import io.bitsquare.bank.BankAccountType; +import io.bitsquare.gui.PresentationModel; +import io.bitsquare.gui.util.validation.BankAccountNumberValidator; +import io.bitsquare.gui.util.validation.InputValidator; +import io.bitsquare.locale.BSResources; + +import com.google.inject.Inject; + +import java.util.Currency; + +import javafx.beans.property.BooleanProperty; +import javafx.beans.property.ObjectProperty; +import javafx.beans.property.SimpleBooleanProperty; +import javafx.beans.property.SimpleObjectProperty; +import javafx.beans.property.SimpleStringProperty; +import javafx.beans.property.StringProperty; +import javafx.collections.ObservableList; +import javafx.util.StringConverter; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +class IrcAccountPm extends PresentationModel { + private static final Logger log = LoggerFactory.getLogger(IrcAccountPm.class); + + private final InputValidator nickNameValidator; + + final StringProperty ircNickName = new SimpleStringProperty(); + final BooleanProperty saveButtonDisable = new SimpleBooleanProperty(true); + final ObjectProperty type = new SimpleObjectProperty<>(); + final ObjectProperty currency = new SimpleObjectProperty<>(); + + + /////////////////////////////////////////////////////////////////////////////////////////// + // Constructor + /////////////////////////////////////////////////////////////////////////////////////////// + + @Inject + IrcAccountPm(IrcAccountModel model, BankAccountNumberValidator nickNameValidator) { + super(model); + this.nickNameValidator = nickNameValidator; + } + + + /////////////////////////////////////////////////////////////////////////////////////////// + // Lifecycle + /////////////////////////////////////////////////////////////////////////////////////////// + + @Override + public void initialize() { + // input + ircNickName.bindBidirectional(model.nickName); + type.bindBidirectional(model.type); + currency.bindBidirectional(model.currency); + + model.nickName.addListener((ov, oldValue, newValue) -> validateInput()); + + super.initialize(); + } + + @Override + public void activate() { + super.activate(); + } + + @SuppressWarnings("EmptyMethod") + @Override + public void deactivate() { + super.deactivate(); + } + + @SuppressWarnings("EmptyMethod") + @Override + public void terminate() { + super.terminate(); + } + + + /////////////////////////////////////////////////////////////////////////////////////////// + // Public + /////////////////////////////////////////////////////////////////////////////////////////// + + InputValidator.ValidationResult requestSaveBankAccount() { + InputValidator.ValidationResult result = validateInput(); + if (result.isValid) { + model.saveBankAccount(); + } + return result; + } + + ObservableList getAllBankAccounts() { + return model.allBankAccounts; + } + + /////////////////////////////////////////////////////////////////////////////////////////// + // Converters + /////////////////////////////////////////////////////////////////////////////////////////// + + StringConverter getTypesConverter() { + return new StringConverter() { + @Override + public String toString(BankAccountType TypeInfo) { + return BSResources.get(TypeInfo.toString()); + } + + @Override + public BankAccountType fromString(String s) { + return null; + } + }; + } + + String getBankAccountType(BankAccountType bankAccountType) { + return bankAccountType != null ? BSResources.get(bankAccountType.toString()) : ""; + } + + StringConverter getCurrencyConverter() { + return new StringConverter() { + @Override + public String toString(Currency currency) { + return currency.getCurrencyCode() + " (" + currency.getDisplayName() + ")"; + } + + @Override + public Currency fromString(String s) { + return null; + } + }; + } + + + /////////////////////////////////////////////////////////////////////////////////////////// + // Getters + /////////////////////////////////////////////////////////////////////////////////////////// + + ObservableList getAllTypes() { + return model.allTypes; + } + + ObservableList getAllCurrencies() { + return model.allCurrencies; + } + + InputValidator getNickNameValidator() { + return nickNameValidator; + } + + + /////////////////////////////////////////////////////////////////////////////////////////// + // Setters + /////////////////////////////////////////////////////////////////////////////////////////// + + void setType(BankAccountType type) { + model.setType(type); + validateInput(); + } + + void setCurrency(Currency currency) { + model.setCurrency(currency); + validateInput(); + } + + + /////////////////////////////////////////////////////////////////////////////////////////// + // Private methods + /////////////////////////////////////////////////////////////////////////////////////////// + + + private InputValidator.ValidationResult validateInput() { + InputValidator.ValidationResult result = nickNameValidator.validate(model.nickName.get()); + if (model.currency.get() == null) + result = new InputValidator.ValidationResult(false, + "You have not selected a currency"); + if (result.isValid) { + if (model.type.get() == null) + result = new InputValidator.ValidationResult(false, + "You have not selected a payments method"); + } + + saveButtonDisable.set(!result.isValid); + return result; + } + +} diff --git a/src/main/java/io/bitsquare/gui/main/account/content/irc/IrcAccountView.fxml b/src/main/java/io/bitsquare/gui/main/account/content/irc/IrcAccountView.fxml new file mode 100644 index 0000000000..b0b5a06e9b --- /dev/null +++ b/src/main/java/io/bitsquare/gui/main/account/content/irc/IrcAccountView.fxml @@ -0,0 +1,82 @@ + + + + + + + + + + + + + + + + + + + + + + + +