diff --git a/common/src/main/java/io/bitsquare/app/Log.java b/common/src/main/java/io/bitsquare/app/Log.java index 15b8694eb2..54370c784e 100644 --- a/common/src/main/java/io/bitsquare/app/Log.java +++ b/common/src/main/java/io/bitsquare/app/Log.java @@ -48,7 +48,7 @@ public class Log { rollingPolicy.start(); triggeringPolicy = new SizeBasedTriggeringPolicy(); - triggeringPolicy.setMaxFileSize("10MB"); + triggeringPolicy.setMaxFileSize("1MB"); triggeringPolicy.start(); PatternLayoutEncoder encoder = new PatternLayoutEncoder(); @@ -63,7 +63,7 @@ public class Log { logbackLogger = loggerContext.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME); //TODO for now use always trace - logbackLogger.setLevel(useDetailedLogging ? Level.INFO : Level.INFO); + logbackLogger.setLevel(useDetailedLogging ? Level.TRACE : Level.INFO); // logbackLogger.setLevel(useDetailedLogging ? Level.TRACE : Level.DEBUG); logbackLogger.addAppender(appender); } diff --git a/common/src/main/java/io/bitsquare/common/util/Tuple4.java b/common/src/main/java/io/bitsquare/common/util/Tuple4.java new file mode 100644 index 0000000000..2e90f8e57f --- /dev/null +++ b/common/src/main/java/io/bitsquare/common/util/Tuple4.java @@ -0,0 +1,57 @@ +/* + * 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.common.util; + +import java.io.Serializable; + +public class Tuple4 implements Serializable { + final public A first; + final public B second; + final public C third; + final public D forth; + + public Tuple4(A first, B second, C third, D forth) { + this.first = first; + this.second = second; + this.third = third; + this.forth = forth; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof Tuple4)) return false; + + Tuple4 tuple4 = (Tuple4) o; + + if (first != null ? !first.equals(tuple4.first) : tuple4.first != null) return false; + if (second != null ? !second.equals(tuple4.second) : tuple4.second != null) return false; + if (third != null ? !third.equals(tuple4.third) : tuple4.third != null) return false; + return !(forth != null ? !forth.equals(tuple4.forth) : tuple4.forth != null); + + } + + @Override + public int hashCode() { + int result = first != null ? first.hashCode() : 0; + result = 31 * result + (second != null ? second.hashCode() : 0); + result = 31 * result + (third != null ? third.hashCode() : 0); + result = 31 * result + (forth != null ? forth.hashCode() : 0); + return result; + } +} diff --git a/core/src/main/java/io/bitsquare/locale/BankUtil.java b/core/src/main/java/io/bitsquare/locale/BankUtil.java new file mode 100644 index 0000000000..1eefbd1ae7 --- /dev/null +++ b/core/src/main/java/io/bitsquare/locale/BankUtil.java @@ -0,0 +1,47 @@ +/* + * 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.locale; + +public class BankUtil { + + public static boolean requiresHolderId(String countryCode) { + if (countryCode != null) { + switch (countryCode) { + case "BR": + return true; + default: + return false; + } + } else { + return false; + } + } + + public static String getHolderIdLabel(String countryCode) { + if (countryCode != null) { + switch (countryCode) { + case "BR": + return "CPF Number:"; + default: + return "Holder ID:"; + } + } else { + return "Holder ID:"; + } + } +} diff --git a/core/src/main/java/io/bitsquare/locale/Country.java b/core/src/main/java/io/bitsquare/locale/Country.java index c8b410267b..71ab2a56ac 100644 --- a/core/src/main/java/io/bitsquare/locale/Country.java +++ b/core/src/main/java/io/bitsquare/locale/Country.java @@ -29,7 +29,7 @@ public final class Country implements Persistable { public final String code; public final String name; - private final Region region; + public final Region region; public Country(String code, String name, Region region) { this.code = code; diff --git a/core/src/main/java/io/bitsquare/locale/CountryUtil.java b/core/src/main/java/io/bitsquare/locale/CountryUtil.java index 1c432b767a..c4779039a4 100644 --- a/core/src/main/java/io/bitsquare/locale/CountryUtil.java +++ b/core/src/main/java/io/bitsquare/locale/CountryUtil.java @@ -17,12 +17,11 @@ package io.bitsquare.locale; +import com.google.common.collect.Collections2; +import com.google.common.collect.Lists; import io.bitsquare.user.Preferences; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Locale; +import java.util.*; import java.util.stream.Collectors; public class CountryUtil { @@ -92,10 +91,71 @@ public class CountryUtil { return getNamesByCodes(countryCodes).stream().collect(Collectors.joining(",\n")); } + public static List getAllRegions() { + final List allRegions = new ArrayList<>(); + + String regionCode = "NA"; + Region region = new Region(regionCode, getRegionName(regionCode)); + allRegions.add(region); + + regionCode = "SA"; + region = new Region(regionCode, getRegionName(regionCode)); + allRegions.add(region); + + regionCode = "AF"; + region = new Region(regionCode, getRegionName(regionCode)); + allRegions.add(region); + + regionCode = "EU"; + region = new Region(regionCode, getRegionName(regionCode)); + allRegions.add(region); + + regionCode = "AS"; + region = new Region(regionCode, getRegionName(regionCode)); + allRegions.add(region); + + regionCode = "OC"; + region = new Region(regionCode, getRegionName(regionCode)); + allRegions.add(region); + + return allRegions; + } + + public static List getAllCountriesForRegion(Region selectedRegion) { + return Lists.newArrayList(Collections2.filter(getAllCountries(), country -> + selectedRegion != null && country != null && selectedRegion.equals(country.region))); + } + + private static List getAllCountries() { + final List allCountries = new ArrayList<>(); + for (final Locale locale : getAllCountryLocales()) { + String regionCode = getRegionCode(locale.getCountry()); + final Region region = new Region(regionCode, getRegionName(regionCode)); + final Country country = new Country(locale.getCountry(), locale.getDisplayCountry(), region); + allCountries.add(country); + } + return allCountries; + } + + // We use getAvailableLocales as we depend on display names (would be a bit painful with translations if handled + // from a static list -or we find something ready made?). + private static List getAllCountryLocales() { + List allLocales = Arrays.asList(Locale.getAvailableLocales()); + Set allLocalesAsSet = allLocales.stream().filter(locale -> !"".equals(locale.getCountry())) + .map(locale -> new Locale("", locale.getCountry(), "")) + .collect(Collectors.toSet()); + + allLocales = new ArrayList<>(); + allLocales.addAll(allLocalesAsSet); + allLocales.sort((locale1, locale2) -> locale1.getDisplayCountry().compareTo(locale2.getDisplayCountry())); + return allLocales; + } + private static List getNamesByCodes(List countryCodes) { return countryCodes.stream().map(CountryUtil::getNameByCode).collect(Collectors.toList()); } + // other source of countries: https://developers.braintreepayments.com/reference/general/countries/java private static final String[] countryCodes = new String[]{"AE", "AL", "AR", "AT", "AU", "BA", "BE", "BG", "BH", "BO", "BR", "BY", "CA", "CH", "CL", "CN", "CO", "CR", "CS", "CU", "CY", "CZ", "DE", "DK", "DO", "DZ", "EC", "EE", "EG", "ES", "FI", "FR", "GB", "GR", "GT", "HK", "HN", "HR", "HU", "ID", "IE", "IL", "IN", diff --git a/core/src/main/java/io/bitsquare/locale/Region.java b/core/src/main/java/io/bitsquare/locale/Region.java index 00e74aff59..1688ec6545 100644 --- a/core/src/main/java/io/bitsquare/locale/Region.java +++ b/core/src/main/java/io/bitsquare/locale/Region.java @@ -27,8 +27,8 @@ public final class Region implements Persistable { // That object is saved to disc. We need to take care of changes to not break deserialization. private static final long serialVersionUID = Version.LOCAL_DB_VERSION; - private final String code; - private final String name; + public final String code; + public final String name; public Region(String code, String name) { this.code = code; diff --git a/core/src/main/java/io/bitsquare/payment/AliPayAccount.java b/core/src/main/java/io/bitsquare/payment/AliPayAccount.java index c2bdcc2106..8be780b20d 100644 --- a/core/src/main/java/io/bitsquare/payment/AliPayAccount.java +++ b/core/src/main/java/io/bitsquare/payment/AliPayAccount.java @@ -27,8 +27,11 @@ public final class AliPayAccount extends PaymentAccount { public AliPayAccount() { super(PaymentMethod.ALI_PAY); setSingleTradeCurrency(new FiatCurrency("CNY")); + } - contractData = new AliPayAccountContractData(paymentMethod.getId(), id, paymentMethod.getMaxTradePeriod()); + @Override + protected PaymentAccountContractData setContractData() { + return new AliPayAccountContractData(paymentMethod.getId(), id, paymentMethod.getMaxTradePeriod()); } public void setAccountNr(String accountNr) { diff --git a/core/src/main/java/io/bitsquare/payment/BankAccountContractData.java b/core/src/main/java/io/bitsquare/payment/BankAccountContractData.java new file mode 100644 index 0000000000..ad540b667f --- /dev/null +++ b/core/src/main/java/io/bitsquare/payment/BankAccountContractData.java @@ -0,0 +1,112 @@ +/* + * 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.payment; + +import io.bitsquare.app.Version; +import io.bitsquare.locale.BankUtil; +import io.bitsquare.locale.CountryUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public abstract class BankAccountContractData extends PaymentAccountContractData { + // That object is sent over the wire, so we need to take care of version compatibility. + private static final long serialVersionUID = Version.P2P_NETWORK_VERSION; + + private static final Logger log = LoggerFactory.getLogger(BankAccountContractData.class); + + private String holderName; + private String bankName; + private String bankId; + private String branchId; + private String accountNr; + private String holderId; + + public BankAccountContractData(String paymentMethod, String id, int maxTradePeriod) { + super(paymentMethod, id, maxTradePeriod); + } + + @Override + public String getPaymentDetails() { + return "National Bank transfer - " + getPaymentDetailsForTradePopup().replace("\n", ", "); + } + + @Override + public String getPaymentDetailsForTradePopup() { + String holderIdString = BankUtil.requiresHolderId(countryCode) ? (getHolderIdLabel() + ": " + holderId + "\n") : ""; + return "Holder name: " + holderName + "\n" + + "Bank name: " + bankName + "\n" + + "Bank Nr.: " + bankId + "\n" + + "Branch Nr.: " + branchId + "\n" + + "Account Nr.: " + accountNr + "\n" + + holderIdString + + "Country of bank: " + CountryUtil.getNameAndCode(getCountryCode()); + } + + + public void setHolderName(String holderName) { + this.holderName = holderName; + } + + public String getHolderName() { + return holderName; + } + + public void setBankName(String bankName) { + this.bankName = bankName; + } + + public String getBankName() { + return bankName; + } + + public void setBankId(String bankId) { + this.bankId = bankId; + } + + public String getBankId() { + return bankId; + } + + public String getBranchId() { + return branchId; + } + + public void setBranchId(String branchId) { + this.branchId = branchId; + } + + public String getAccountNr() { + return accountNr; + } + + public void setAccountNr(String accountNr) { + this.accountNr = accountNr; + } + + public String getHolderId() { + return holderId; + } + + public void setHolderId(String holderId) { + this.holderId = holderId; + } + + public String getHolderIdLabel() { + return BankUtil.getHolderIdLabel(countryCode); + } +} diff --git a/core/src/main/java/io/bitsquare/payment/BlockChainAccount.java b/core/src/main/java/io/bitsquare/payment/BlockChainAccount.java index 3c7049f764..fe1d109181 100644 --- a/core/src/main/java/io/bitsquare/payment/BlockChainAccount.java +++ b/core/src/main/java/io/bitsquare/payment/BlockChainAccount.java @@ -27,7 +27,11 @@ public final class BlockChainAccount extends PaymentAccount { public BlockChainAccount() { super(PaymentMethod.BLOCK_CHAINS); - contractData = new BlockChainAccountContractData(paymentMethod.getId(), id, paymentMethod.getMaxTradePeriod()); + } + + @Override + protected PaymentAccountContractData setContractData() { + return new BlockChainAccountContractData(paymentMethod.getId(), id, paymentMethod.getMaxTradePeriod()); } public void setAddress(String address) { diff --git a/core/src/main/java/io/bitsquare/payment/NationalBankAccount.java b/core/src/main/java/io/bitsquare/payment/NationalBankAccount.java new file mode 100644 index 0000000000..57b43f5679 --- /dev/null +++ b/core/src/main/java/io/bitsquare/payment/NationalBankAccount.java @@ -0,0 +1,34 @@ +/* + * 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.payment; + +import io.bitsquare.app.Version; + +public final class NationalBankAccount extends PaymentAccount { + // That object is saved to disc. We need to take care of changes to not break deserialization. + private static final long serialVersionUID = Version.LOCAL_DB_VERSION; + + public NationalBankAccount() { + super(PaymentMethod.NATIONAL_BANK); + } + + @Override + protected PaymentAccountContractData setContractData() { + return new NationalBankAccountContractData(paymentMethod.getId(), id, paymentMethod.getMaxTradePeriod()); + } +} diff --git a/core/src/main/java/io/bitsquare/payment/NationalBankAccountContractData.java b/core/src/main/java/io/bitsquare/payment/NationalBankAccountContractData.java new file mode 100644 index 0000000000..15323ce495 --- /dev/null +++ b/core/src/main/java/io/bitsquare/payment/NationalBankAccountContractData.java @@ -0,0 +1,38 @@ +/* + * 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.payment; + +import io.bitsquare.app.Version; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public final class NationalBankAccountContractData extends BankAccountContractData { + // That object is sent over the wire, so we need to take care of version compatibility. + private static final long serialVersionUID = Version.P2P_NETWORK_VERSION; + + private static final Logger log = LoggerFactory.getLogger(NationalBankAccountContractData.class); + + public NationalBankAccountContractData(String paymentMethod, String id, int maxTradePeriod) { + super(paymentMethod, id, maxTradePeriod); + } + + @Override + public String getPaymentDetails() { + return "National Bank transfer - " + getPaymentDetailsForTradePopup().replace("\n", ", "); + } +} diff --git a/core/src/main/java/io/bitsquare/payment/OKPayAccount.java b/core/src/main/java/io/bitsquare/payment/OKPayAccount.java index b6cfa56371..4842e9dca1 100644 --- a/core/src/main/java/io/bitsquare/payment/OKPayAccount.java +++ b/core/src/main/java/io/bitsquare/payment/OKPayAccount.java @@ -31,7 +31,11 @@ public final class OKPayAccount extends PaymentAccount { public OKPayAccount() { super(PaymentMethod.OK_PAY); tradeCurrencies.addAll(CurrencyUtil.getAllOKPayCurrencies()); - contractData = new OKPayAccountContractData(paymentMethod.getId(), id, paymentMethod.getMaxTradePeriod()); + } + + @Override + protected PaymentAccountContractData setContractData() { + return new OKPayAccountContractData(paymentMethod.getId(), id, paymentMethod.getMaxTradePeriod()); } public void setAccountNr(String accountNr) { diff --git a/core/src/main/java/io/bitsquare/payment/PaymentAccount.java b/core/src/main/java/io/bitsquare/payment/PaymentAccount.java index 7a0fc3a09a..3a0f544fe2 100644 --- a/core/src/main/java/io/bitsquare/payment/PaymentAccount.java +++ b/core/src/main/java/io/bitsquare/payment/PaymentAccount.java @@ -44,7 +44,7 @@ public abstract class PaymentAccount implements Persistable { protected TradeCurrency selectedTradeCurrency; @Nullable protected Country country = null; - PaymentAccountContractData contractData; + public final PaymentAccountContractData contractData; /////////////////////////////////////////////////////////////////////////////////////////// @@ -56,6 +56,7 @@ public abstract class PaymentAccount implements Persistable { this.paymentMethod = paymentMethod; id = UUID.randomUUID().toString(); creationDate = new Date(); + contractData = setContractData(); } @@ -95,6 +96,8 @@ public abstract class PaymentAccount implements Persistable { // Getter, Setter /////////////////////////////////////////////////////////////////////////////////////////// + protected abstract PaymentAccountContractData setContractData(); + public String getAccountName() { return accountName; } diff --git a/core/src/main/java/io/bitsquare/payment/PaymentAccountContractData.java b/core/src/main/java/io/bitsquare/payment/PaymentAccountContractData.java index ca5d4ab4e9..3ce0154df9 100644 --- a/core/src/main/java/io/bitsquare/payment/PaymentAccountContractData.java +++ b/core/src/main/java/io/bitsquare/payment/PaymentAccountContractData.java @@ -31,7 +31,7 @@ public abstract class PaymentAccountContractData implements Payload { private final int maxTradePeriod; @Nullable - private String countryCode; + protected String countryCode; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/core/src/main/java/io/bitsquare/payment/PaymentAccountFactory.java b/core/src/main/java/io/bitsquare/payment/PaymentAccountFactory.java new file mode 100644 index 0000000000..1e3b362ea8 --- /dev/null +++ b/core/src/main/java/io/bitsquare/payment/PaymentAccountFactory.java @@ -0,0 +1,51 @@ +/* + * 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.payment; + +import io.bitsquare.common.persistance.Persistable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public abstract class PaymentAccountFactory implements Persistable { + private static final Logger log = LoggerFactory.getLogger(PaymentAccountFactory.class); + + public static PaymentAccount getPaymentAccount(PaymentMethod paymentMethod) { + switch (paymentMethod.getId()) { + case PaymentMethod.OK_PAY_ID: + return new OKPayAccount(); + case PaymentMethod.PERFECT_MONEY_ID: + return new PerfectMoneyAccount(); + case PaymentMethod.SEPA_ID: + return new SepaAccount(); + case PaymentMethod.NATIONAL_BANK_ID: + return new NationalBankAccount(); + case PaymentMethod.SAME_BANK_ID: + return new SameBankAccount(); + case PaymentMethod.SPECIFIC_BANKS_ID: + return new SpecificBankAccount(); + case PaymentMethod.ALI_PAY_ID: + return new AliPayAccount(); + case PaymentMethod.SWISH_ID: + return new SwishAccount(); + case PaymentMethod.BLOCK_CHAINS_ID: + return new BlockChainAccount(); + default: + throw new RuntimeException("Not supported PaymentMethod: " + paymentMethod); + } + } +} diff --git a/core/src/main/java/io/bitsquare/payment/PaymentMethod.java b/core/src/main/java/io/bitsquare/payment/PaymentMethod.java index feef66690e..56a563ee4e 100644 --- a/core/src/main/java/io/bitsquare/payment/PaymentMethod.java +++ b/core/src/main/java/io/bitsquare/payment/PaymentMethod.java @@ -41,6 +41,9 @@ public final class PaymentMethod implements Persistable, Comparable { public static final String OK_PAY_ID = "OK_PAY"; public static final String PERFECT_MONEY_ID = "PERFECT_MONEY"; public static final String SEPA_ID = "SEPA"; + public static final String NATIONAL_BANK_ID = "NATIONAL_BANK"; + public static final String SAME_BANK_ID = "SAME_BANK"; + public static final String SPECIFIC_BANKS_ID = "SPECIFIC_BANKS"; public static final String SWISH_ID = "SWISH"; public static final String ALI_PAY_ID = "ALI_PAY"; /* public static final String FED_WIRE="FED_WIRE";*/ @@ -51,6 +54,9 @@ public final class PaymentMethod implements Persistable, Comparable { public static PaymentMethod OK_PAY; public static PaymentMethod PERFECT_MONEY; public static PaymentMethod SEPA; + public static PaymentMethod NATIONAL_BANK; + public static PaymentMethod SAME_BANK; + public static PaymentMethod SPECIFIC_BANKS; public static PaymentMethod SWISH; public static PaymentMethod ALI_PAY; /* public static PaymentMethod FED_WIRE;*/ @@ -62,6 +68,9 @@ public final class PaymentMethod implements Persistable, Comparable { OK_PAY = new PaymentMethod(OK_PAY_ID, 0, DAY), // tx instant so min. wait time PERFECT_MONEY = new PaymentMethod(PERFECT_MONEY_ID, 0, DAY), SEPA = new PaymentMethod(SEPA_ID, 0, 8 * DAY), // sepa takes 1-3 business days. We use 8 days to include safety for holidays + NATIONAL_BANK = new PaymentMethod(NATIONAL_BANK_ID, 0, 4 * DAY), + SAME_BANK = new PaymentMethod(SAME_BANK_ID, 0, 2 * DAY), + SPECIFIC_BANKS = new PaymentMethod(SPECIFIC_BANKS_ID, 0, 4 * DAY), SWISH = new PaymentMethod(SWISH_ID, 0, DAY), ALI_PAY = new PaymentMethod(ALI_PAY_ID, 0, DAY), /* FED_WIRE = new PaymentMethod(FED_WIRE_ID, 0, DAY),*/ @@ -91,7 +100,7 @@ public final class PaymentMethod implements Persistable, Comparable { this.maxTradePeriod = maxTradePeriod; } - public static PaymentMethod getPaymentMethodByName(String name) { + public static PaymentMethod getPaymentMethodById(String name) { return ALL_VALUES.stream().filter(e -> e.getId().equals(name)).findFirst().get(); } diff --git a/core/src/main/java/io/bitsquare/payment/PerfectMoneyAccount.java b/core/src/main/java/io/bitsquare/payment/PerfectMoneyAccount.java index 2a3698bbe6..ffbbf6335b 100644 --- a/core/src/main/java/io/bitsquare/payment/PerfectMoneyAccount.java +++ b/core/src/main/java/io/bitsquare/payment/PerfectMoneyAccount.java @@ -27,8 +27,11 @@ public final class PerfectMoneyAccount extends PaymentAccount { public PerfectMoneyAccount() { super(PaymentMethod.PERFECT_MONEY); setSingleTradeCurrency(new FiatCurrency("USD")); + } - contractData = new PerfectMoneyAccountContractData(paymentMethod.getId(), id, paymentMethod.getMaxTradePeriod()); + @Override + protected PaymentAccountContractData setContractData() { + return new PerfectMoneyAccountContractData(paymentMethod.getId(), id, paymentMethod.getMaxTradePeriod()); } public void setAccountNr(String accountNr) { @@ -38,4 +41,6 @@ public final class PerfectMoneyAccount extends PaymentAccount { public String getAccountNr() { return ((PerfectMoneyAccountContractData) contractData).getAccountNr(); } + + } diff --git a/core/src/main/java/io/bitsquare/payment/SameBankAccount.java b/core/src/main/java/io/bitsquare/payment/SameBankAccount.java new file mode 100644 index 0000000000..3f687051d1 --- /dev/null +++ b/core/src/main/java/io/bitsquare/payment/SameBankAccount.java @@ -0,0 +1,34 @@ +/* + * 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.payment; + +import io.bitsquare.app.Version; + +public final class SameBankAccount extends PaymentAccount { + // That object is saved to disc. We need to take care of changes to not break deserialization. + private static final long serialVersionUID = Version.LOCAL_DB_VERSION; + + public SameBankAccount() { + super(PaymentMethod.SAME_BANK); + } + + @Override + protected PaymentAccountContractData setContractData() { + return new SameBankAccountContractData(paymentMethod.getId(), id, paymentMethod.getMaxTradePeriod()); + } +} diff --git a/core/src/main/java/io/bitsquare/payment/SameBankAccountContractData.java b/core/src/main/java/io/bitsquare/payment/SameBankAccountContractData.java new file mode 100644 index 0000000000..6811ef0219 --- /dev/null +++ b/core/src/main/java/io/bitsquare/payment/SameBankAccountContractData.java @@ -0,0 +1,39 @@ +/* + * 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.payment; + +import io.bitsquare.app.Version; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public final class SameBankAccountContractData extends BankAccountContractData { + // That object is sent over the wire, so we need to take care of version compatibility. + private static final long serialVersionUID = Version.P2P_NETWORK_VERSION; + + private static final Logger log = LoggerFactory.getLogger(SameBankAccountContractData.class); + + + public SameBankAccountContractData(String paymentMethod, String id, int maxTradePeriod) { + super(paymentMethod, id, maxTradePeriod); + } + + @Override + public String getPaymentDetails() { + return "Transfer with same Bank - " + getPaymentDetailsForTradePopup().replace("\n", ", "); + } +} diff --git a/core/src/main/java/io/bitsquare/payment/SepaAccount.java b/core/src/main/java/io/bitsquare/payment/SepaAccount.java index 1e6571453e..3e04f77771 100644 --- a/core/src/main/java/io/bitsquare/payment/SepaAccount.java +++ b/core/src/main/java/io/bitsquare/payment/SepaAccount.java @@ -27,8 +27,11 @@ public final class SepaAccount extends PaymentAccount { public SepaAccount() { super(PaymentMethod.SEPA); + } - contractData = new SepaAccountContractData(paymentMethod.getId(), id, paymentMethod.getMaxTradePeriod()); + @Override + protected PaymentAccountContractData setContractData() { + return new SepaAccountContractData(paymentMethod.getId(), id, paymentMethod.getMaxTradePeriod()); } public void setHolderName(String holderName) { @@ -67,4 +70,5 @@ public final class SepaAccount extends PaymentAccount { ((SepaAccountContractData) contractData).removeAcceptedCountry(countryCode); } + } diff --git a/core/src/main/java/io/bitsquare/payment/SpecificBankAccount.java b/core/src/main/java/io/bitsquare/payment/SpecificBankAccount.java new file mode 100644 index 0000000000..6ffc1b911e --- /dev/null +++ b/core/src/main/java/io/bitsquare/payment/SpecificBankAccount.java @@ -0,0 +1,34 @@ +/* + * 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.payment; + +import io.bitsquare.app.Version; + +public final class SpecificBankAccount extends PaymentAccount { + // That object is saved to disc. We need to take care of changes to not break deserialization. + private static final long serialVersionUID = Version.LOCAL_DB_VERSION; + + public SpecificBankAccount() { + super(PaymentMethod.SPECIFIC_BANKS); + } + + @Override + protected PaymentAccountContractData setContractData() { + return new SpecificBanksAccountContractData(paymentMethod.getId(), id, paymentMethod.getMaxTradePeriod()); + } +} diff --git a/core/src/main/java/io/bitsquare/payment/SpecificBanksAccountContractData.java b/core/src/main/java/io/bitsquare/payment/SpecificBanksAccountContractData.java new file mode 100644 index 0000000000..70fd789999 --- /dev/null +++ b/core/src/main/java/io/bitsquare/payment/SpecificBanksAccountContractData.java @@ -0,0 +1,59 @@ +/* + * 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.payment; + +import io.bitsquare.app.Version; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; + +public final class SpecificBanksAccountContractData extends BankAccountContractData { + // That object is sent over the wire, so we need to take care of version compatibility. + private static final long serialVersionUID = Version.P2P_NETWORK_VERSION; + + private static final Logger log = LoggerFactory.getLogger(SpecificBanksAccountContractData.class); + + + // Dont use a set here as we need a deterministic ordering, otherwise the contract hash does not match + private ArrayList acceptedBanks; + + public SpecificBanksAccountContractData(String paymentMethod, String id, int maxTradePeriod) { + super(paymentMethod, id, maxTradePeriod); + acceptedBanks = new ArrayList<>(); + } + + public void clearAcceptedBanks() { + acceptedBanks = new ArrayList<>(); + } + + public void addAcceptedBank(String bankName) { + if (!acceptedBanks.contains(bankName)) + acceptedBanks.add(bankName); + } + + public ArrayList getAcceptedBanks() { + return acceptedBanks; + } + + + @Override + public String getPaymentDetails() { + return "Transfers with specific banks - " + getPaymentDetailsForTradePopup().replace("\n", ", "); + } +} diff --git a/core/src/main/java/io/bitsquare/payment/SwishAccount.java b/core/src/main/java/io/bitsquare/payment/SwishAccount.java index d5cb1804c1..7b24dcb5e8 100644 --- a/core/src/main/java/io/bitsquare/payment/SwishAccount.java +++ b/core/src/main/java/io/bitsquare/payment/SwishAccount.java @@ -27,8 +27,11 @@ public final class SwishAccount extends PaymentAccount { public SwishAccount() { super(PaymentMethod.SWISH); setSingleTradeCurrency(new FiatCurrency("SEK")); + } - contractData = new SwishAccountContractData(paymentMethod.getId(), id, paymentMethod.getMaxTradePeriod()); + @Override + protected PaymentAccountContractData setContractData() { + return new SwishAccountContractData(paymentMethod.getId(), id, paymentMethod.getMaxTradePeriod()); } public void setMobileNr(String mobileNr) { diff --git a/core/src/main/java/io/bitsquare/payment/unused/FedWireAccount.java b/core/src/main/java/io/bitsquare/payment/unused/FedWireAccount.java deleted file mode 100644 index ee118869e0..0000000000 --- a/core/src/main/java/io/bitsquare/payment/unused/FedWireAccount.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * 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.payment.unused; - -import io.bitsquare.app.Version; -import io.bitsquare.payment.PaymentAccount; -import io.bitsquare.payment.PaymentMethod; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -// US only -public final class FedWireAccount extends PaymentAccount { - // That object is saved to disc. We need to take care of changes to not break deserialization. - private static final long serialVersionUID = Version.LOCAL_DB_VERSION; - - private static final Logger log = LoggerFactory.getLogger(FedWireAccount.class); - - private String holderName; - private String holderState; - private String holderZIP; - private String holderStreet; - private String holderCity; - private String holderSSN; // Optional? social security Nr only Arizona and Oklahoma? - private String accountNr; - private String bankCode;// SWIFT Code/BIC/RoutingNr/ABA (ABA for UD domestic) - private String bankName; - private String bankState; - private String bankZIP; - private String bankStreet; - private String bankCity; - - private FedWireAccount() { - super(PaymentMethod.SEPA); - } - - public String getHolderName() { - return holderName; - } - - public void setHolderName(String holderName) { - this.holderName = holderName; - } - - public String getAccountNr() { - return accountNr; - } - - public void setAccountNr(String accountNr) { - this.accountNr = accountNr; - } - - public String getBankCode() { - return bankCode; - } - - public void setBankCode(String bankCode) { - this.bankCode = bankCode; - } - - @Override - public String getPaymentDetails() { - return "{accountName='" + accountName + '\'' + - '}'; - } - - @Override - public String toString() { - return "SepaAccount{" + - "accountName='" + accountName + '\'' + - ", id='" + id + '\'' + - ", paymentMethod=" + paymentMethod + - ", holderName='" + holderName + '\'' + - ", accountNr='" + accountNr + '\'' + - ", bankCode='" + bankCode + '\'' + - ", country=" + country + - ", tradeCurrencies='" + getTradeCurrencies() + '\'' + - ", selectedTradeCurrency=" + selectedTradeCurrency + - '}'; - } -} diff --git a/core/src/main/java/io/bitsquare/payment/unused/TransferWiseAccount.java b/core/src/main/java/io/bitsquare/payment/unused/TransferWiseAccount.java deleted file mode 100644 index 96ed595a2c..0000000000 --- a/core/src/main/java/io/bitsquare/payment/unused/TransferWiseAccount.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * 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.payment.unused; - -import io.bitsquare.app.Version; -import io.bitsquare.payment.PaymentAccount; -import io.bitsquare.payment.PaymentMethod; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public final class TransferWiseAccount extends PaymentAccount { - // That object is saved to disc. We need to take care of changes to not break deserialization. - private static final long serialVersionUID = Version.LOCAL_DB_VERSION; - - private static final Logger log = LoggerFactory.getLogger(TransferWiseAccount.class); - - private String holderName; - private String iban; - private String bic; - - - private TransferWiseAccount() { - super(PaymentMethod.SEPA); - } - - public String getHolderName() { - return holderName; - } - - public void setHolderName(String holderName) { - this.holderName = holderName; - } - - public String getIban() { - return iban; - } - - public void setIban(String iban) { - this.iban = iban; - } - - public String getBic() { - return bic; - } - - public void setBic(String bic) { - this.bic = bic; - } - - @Override - public String getPaymentDetails() { - return "TransferWise{accountName='" + accountName + '\'' + - '}'; - } - - @Override - public String toString() { - return "TransferWiseAccount{" + - "accountName='" + accountName + '\'' + - ", id='" + id + '\'' + - ", paymentMethod=" + paymentMethod + - ", holderName='" + holderName + '\'' + - ", iban='" + iban + '\'' + - ", bic='" + bic + '\'' + - ", country=" + country + - ", tradeCurrencies='" + getTradeCurrencies() + '\'' + - ", selectedTradeCurrency=" + selectedTradeCurrency + - '}'; - } -} diff --git a/core/src/main/java/io/bitsquare/payment/unused/USPostalMoneyOrderAccount.java b/core/src/main/java/io/bitsquare/payment/unused/USPostalMoneyOrderAccount.java deleted file mode 100644 index c8c950b1b0..0000000000 --- a/core/src/main/java/io/bitsquare/payment/unused/USPostalMoneyOrderAccount.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * 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.payment.unused; - -import io.bitsquare.app.Version; -import io.bitsquare.payment.PaymentAccount; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public final class USPostalMoneyOrderAccount extends PaymentAccount { - // That object is saved to disc. We need to take care of changes to not break deserialization. - private static final long serialVersionUID = Version.LOCAL_DB_VERSION; - - private static final Logger log = LoggerFactory.getLogger(USPostalMoneyOrderAccount.class); - - private String holderName; - private String iban; - private String bic; - - /* - - Message (interface): - - GetDataRequest (Interface) - - PreliminaryGetDataRequest (final class) impl. AnonymousMessage - - GetUpdatedDataRequest (final class) impl. SendersNodeAddressMessage - - SendersNodeAddressMessage (Interface) - - PrefixedSealedAndSignedMessage (final class) impl. MailboxMessage - - GetUpdatedDataRequest (final class) impl. GetDataRequest - - GetPeersRequest (final class) extends PeerExchangeMessage - - AnonymousMessage (Interface) - - PreliminaryGetDataRequest (final class) impl. GetDataRequest - - DirectMessage (Interface) - - OfferMessage (abstract class) - - OfferAvailabilityRequest (final class) - - OfferAvailabilityResponse (final class) - - TradeMessage (abstract class) - - DepositTxPublishedMessage (final class) implements MailboxMessage - - FiatTransferStartedMessage (final class) implements MailboxMessage - - FinalizePayoutTxRequest (final class) implements MailboxMessage - - PayDepositRequest (final class) implements MailboxMessage - - PayoutTxFinalizedMessage (final class) implements MailboxMessage - - PublishDepositTxRequest (final class) - - DecryptedMsgWithPubKey (final class) - - MailboxMessage (Interface) - - PrefixedSealedAndSignedMessage (final class) implements SendersNodeAddressMessage - - DisputeMessage (abstract class) - - DisputeCommunicationMessage (final class) - - DisputeResultMessage (final class) - - OpenNewDisputeMessage (final class) - - PeerOpenedDisputeMessage (final class) - - PeerPublishedPayoutTxMessage (final class) - - DepositTxPublishedMessage (final class) extends TradeMessage - - FiatTransferStartedMessage (final class) extends TradeMessage - - FinalizePayoutTxRequest (final class) extends TradeMessage - - PayDepositRequest (final class) extends TradeMessage - - PayoutTxFinalizedMessage (final class) extends TradeMessage - - DataBroadcastMessage (abstract class) - - AddDataMessage (final class) - - RefreshTTLMessage (final class) - - RemoveDataMessage (final class) - - RemoveMailboxDataMessage (final class) - - PeerExchangeMessage (abstract class) - - GetPeersRequest (final class) implements SendersNodeAddressMessage - - GetPeersResponse (final class) - - KeepAliveMessage (abstract class) - - Ping (final class) - - Pong (final class) - - GetDataResponse (final class) - - CloseConnectionMessage (final class) - */ - private USPostalMoneyOrderAccount() { - super(null /*PaymentMethod.US_POSTAL_MONEY_ORDER*/); - } - - public String getHolderName() { - return holderName; - } - - public void setHolderName(String holderName) { - this.holderName = holderName; - } - - public String getIban() { - return iban; - } - - public void setIban(String iban) { - this.iban = iban; - } - - public String getBic() { - return bic; - } - - public void setBic(String bic) { - this.bic = bic; - } - - @Override - public String getPaymentDetails() { - return "{accountName='" + accountName + '\'' + - '}'; - } - - @Override - public String toString() { - return "USPostalMoneyOrderAccount{" + - "accountName='" + accountName + '\'' + - ", id='" + id + '\'' + - ", paymentMethod=" + paymentMethod + - ", holderName='" + holderName + '\'' + - ", iban='" + iban + '\'' + - ", bic='" + bic + '\'' + - ", country=" + country + - ", tradeCurrencies='" + getTradeCurrencies() + '\'' + - ", selectedTradeCurrency=" + selectedTradeCurrency + - '}'; - } -} diff --git a/core/src/main/java/io/bitsquare/trade/offer/Offer.java b/core/src/main/java/io/bitsquare/trade/offer/Offer.java index d4e6b8fd5f..9aa5e1c74d 100644 --- a/core/src/main/java/io/bitsquare/trade/offer/Offer.java +++ b/core/src/main/java/io/bitsquare/trade/offer/Offer.java @@ -319,7 +319,7 @@ public final class Offer implements StoragePayload, RequiresOwnerIsOnlinePayload } public PaymentMethod getPaymentMethod() { - return PaymentMethod.getPaymentMethodByName(paymentMethodName); + return PaymentMethod.getPaymentMethodById(paymentMethodName); } public String getCurrencyCode() { diff --git a/gui/src/main/java/io/bitsquare/gui/components/paymentmethods/BankForm.java b/gui/src/main/java/io/bitsquare/gui/components/paymentmethods/BankForm.java new file mode 100644 index 0000000000..745281cfd7 --- /dev/null +++ b/gui/src/main/java/io/bitsquare/gui/components/paymentmethods/BankForm.java @@ -0,0 +1,285 @@ +/* + * 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.components.paymentmethods; + +import io.bitsquare.common.util.Tuple3; +import io.bitsquare.common.util.Tuple4; +import io.bitsquare.gui.components.InputTextField; +import io.bitsquare.gui.util.Layout; +import io.bitsquare.gui.util.validation.InputValidator; +import io.bitsquare.locale.*; +import io.bitsquare.payment.BankAccountContractData; +import io.bitsquare.payment.PaymentAccount; +import io.bitsquare.payment.PaymentAccountContractData; +import javafx.collections.FXCollections; +import javafx.scene.control.ComboBox; +import javafx.scene.control.Label; +import javafx.scene.control.TextField; +import javafx.scene.layout.GridPane; +import javafx.util.StringConverter; +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import static io.bitsquare.gui.util.FormBuilder.*; + +abstract class BankForm extends PaymentMethodForm { + private static final Logger log = LoggerFactory.getLogger(BankForm.class); + + protected final BankAccountContractData bankAccountContractData; + private InputTextField bankNameInputTextField, bankIdInputTextField, branchIdInputTextField, accountNrInputTextField, holderIdInputTextField; + private TextField currencyTextField; + private Label holderIdLabel; + private InputTextField holderNameInputTextField; + + static int addFormForBuyer(GridPane gridPane, int gridRow, PaymentAccountContractData paymentAccountContractData) { + BankAccountContractData bankAccountContractData = (BankAccountContractData) paymentAccountContractData; + addLabelTextFieldWithCopyIcon(gridPane, ++gridRow, "Account holder name:", bankAccountContractData.getHolderName()); + addLabelTextFieldWithCopyIcon(gridPane, ++gridRow, "Country of bank:", CountryUtil.getNameAndCode(bankAccountContractData.getCountryCode())); + addLabelTextFieldWithCopyIcon(gridPane, ++gridRow, "Bank name:", bankAccountContractData.getBankName()); + addLabelTextFieldWithCopyIcon(gridPane, ++gridRow, "Bank number:", bankAccountContractData.getBankId()); + addLabelTextFieldWithCopyIcon(gridPane, ++gridRow, "Branch number:", bankAccountContractData.getBranchId()); + addLabelTextFieldWithCopyIcon(gridPane, ++gridRow, "Account number:", bankAccountContractData.getAccountNr()); + if (bankAccountContractData.getHolderId() != null) + addLabelTextFieldWithCopyIcon(gridPane, ++gridRow, bankAccountContractData.getHolderIdLabel(), bankAccountContractData.getHolderId()); + return gridRow; + } + + BankForm(PaymentAccount paymentAccount, InputValidator inputValidator, + GridPane gridPane, int gridRow) { + super(paymentAccount, inputValidator, gridPane, gridRow); + this.bankAccountContractData = (BankAccountContractData) paymentAccount.contractData; + } + + @Override + public void addFormForAddAccount() { + gridRowFrom = gridRow + 1; + + Tuple3 tuple3 = addLabelComboBoxComboBox(gridPane, ++gridRow, "Country:"); + currencyTextField = addLabelTextField(gridPane, ++gridRow, "Currency:").second; + currencyTextField.setMouseTransparent(true); + + ComboBox regionComboBox = tuple3.second; + regionComboBox.setPromptText("Select region"); + regionComboBox.setConverter(new StringConverter() { + @Override + public String toString(Region region) { + return region.name; + } + + @Override + public Region fromString(String s) { + return null; + } + }); + regionComboBox.setItems(FXCollections.observableArrayList(CountryUtil.getAllRegions())); + + + ComboBox countryComboBox = tuple3.third; + countryComboBox.setDisable(true); + countryComboBox.setPromptText("Select country"); + countryComboBox.setConverter(new StringConverter() { + @Override + public String toString(Country country) { + return country.name + " (" + country.code + ")"; + } + + @Override + public Country fromString(String s) { + return null; + } + }); + countryComboBox.setOnAction(e -> { + Country selectedItem = countryComboBox.getSelectionModel().getSelectedItem(); + paymentAccount.setCountry(selectedItem); + String countryCode = selectedItem.code; + TradeCurrency currency = CurrencyUtil.getCurrencyByCountryCode(countryCode); + paymentAccount.setSingleTradeCurrency(currency); + currencyTextField.setText(currency.getNameAndCode()); + + if (holderIdInputTextField != null) { + boolean requiresHolderId = BankUtil.requiresHolderId(countryCode); + if (requiresHolderId) { + holderNameInputTextField.minWidthProperty().unbind(); + holderNameInputTextField.setMinWidth(300); + } else { + holderNameInputTextField.minWidthProperty().bind(currencyTextField.widthProperty()); + } + holderIdLabel.setText(BankUtil.getHolderIdLabel(countryCode)); + holderIdLabel.setVisible(requiresHolderId); + holderIdLabel.setManaged(requiresHolderId); + holderIdInputTextField.resetValidation(); + holderIdInputTextField.setVisible(requiresHolderId); + holderIdInputTextField.setManaged(requiresHolderId); + if (!requiresHolderId) + holderIdInputTextField.setText(""); + } + + updateFromInputs(); + + onCountryChanged(); + }); + + regionComboBox.setOnAction(e -> { + Region selectedItem = regionComboBox.getSelectionModel().getSelectedItem(); + countryComboBox.setDisable(false); + countryComboBox.setItems(FXCollections.observableArrayList(CountryUtil.getAllCountriesForRegion(selectedItem))); + }); + + addAcceptedBanksForAddAccount(); + + addHolderNameAndId(); + + bankNameInputTextField = addLabelInputTextField(gridPane, ++gridRow, "Bank name:").second; + bankNameInputTextField.setValidator(inputValidator); + bankNameInputTextField.textProperty().addListener((ov, oldValue, newValue) -> { + bankAccountContractData.setBankName(newValue); + updateFromInputs(); + + }); + + bankIdInputTextField = addLabelInputTextField(gridPane, ++gridRow, "Bank number:").second; + bankIdInputTextField.setValidator(inputValidator); + bankIdInputTextField.textProperty().addListener((ov, oldValue, newValue) -> { + bankAccountContractData.setBankId(newValue); + updateFromInputs(); + + }); + + branchIdInputTextField = addLabelInputTextField(gridPane, ++gridRow, "Branch number:").second; + branchIdInputTextField.setValidator(inputValidator); + branchIdInputTextField.textProperty().addListener((ov, oldValue, newValue) -> { + bankAccountContractData.setBranchId(newValue); + updateFromInputs(); + + }); + + accountNrInputTextField = addLabelInputTextField(gridPane, ++gridRow, "Account number:").second; + accountNrInputTextField.setValidator(inputValidator); + accountNrInputTextField.textProperty().addListener((ov, oldValue, newValue) -> { + bankAccountContractData.setAccountNr(newValue); + updateFromInputs(); + + }); + + addAllowedPeriod(); + addAccountNameTextFieldWithAutoFillCheckBox(); + + updateFromInputs(); + } + + protected void onCountryChanged() { + } + + protected void addHolderNameAndId() { + Tuple4 tuple = addLabelInputTextFieldLabelInputTextField(gridPane, ++gridRow, "Account holder name:", BankUtil.getHolderIdLabel("")); + holderNameInputTextField = tuple.second; + holderNameInputTextField.setMinWidth(300); + holderNameInputTextField.setValidator(inputValidator); + holderNameInputTextField.textProperty().addListener((ov, oldValue, newValue) -> { + bankAccountContractData.setHolderName(newValue); + updateFromInputs(); + }); + holderNameInputTextField.minWidthProperty().bind(currencyTextField.widthProperty()); + + holderIdLabel = tuple.third; + holderIdLabel.setVisible(false); + holderIdLabel.setManaged(false); + + holderIdInputTextField = tuple.forth; + holderIdInputTextField.setVisible(false); + holderIdInputTextField.setManaged(false); + holderIdInputTextField.setValidator(inputValidator); + holderIdInputTextField.textProperty().addListener((ov, oldValue, newValue) -> { + bankAccountContractData.setHolderId(newValue); + updateFromInputs(); + }); + } + + protected void addAcceptedBanksForAddAccount() { + } + + + @Override + protected void autoFillNameTextField() { + if (useCustomAccountNameCheckBox != null && !useCustomAccountNameCheckBox.isSelected()) { + String bankName = bankNameInputTextField.getText(); + if (bankName.length() > 6) + bankName = StringUtils.abbreviate(bankName, 9); + String accountNr = accountNrInputTextField.getText(); + if (accountNr.length() > 6) + accountNr = StringUtils.abbreviate(accountNr, 9); + + String method = BSResources.get(paymentAccount.getPaymentMethod().getId()); + accountNameTextField.setText(method.concat(", ").concat(bankName).concat(", ").concat(accountNr)); + } + } + + @Override + public void updateAllInputsValid() { + boolean holderIdValid = true; + if (paymentAccount.getCountry() != null) { + if (BankUtil.requiresHolderId(paymentAccount.getCountry().code)) + holderIdValid = inputValidator.validate(bankAccountContractData.getHolderId()).isValid; + } + + allInputsValid.set(isAccountNameValid() + && inputValidator.validate(bankAccountContractData.getHolderName()).isValid + && inputValidator.validate(bankAccountContractData.getBankName()).isValid + && inputValidator.validate(bankAccountContractData.getBankId()).isValid + && inputValidator.validate(bankAccountContractData.getBranchId()).isValid + && inputValidator.validate(bankAccountContractData.getAccountNr()).isValid + && holderIdValid + && paymentAccount.getSingleTradeCurrency() != null + && paymentAccount.getCountry() != null); + } + + @Override + public void addFormForDisplayAccount() { + gridRowFrom = gridRow; + + addLabelTextField(gridPane, gridRow, "Account name:", paymentAccount.getAccountName(), Layout.FIRST_ROW_AND_GROUP_DISTANCE); + addLabelTextField(gridPane, ++gridRow, "Payment method:", BSResources.get(paymentAccount.getPaymentMethod().getId())); + addLabelTextField(gridPane, ++gridRow, "Country:", paymentAccount.getCountry() != null ? paymentAccount.getCountry().name : ""); + addLabelTextField(gridPane, ++gridRow, "Currency:", paymentAccount.getSingleTradeCurrency().getNameAndCode()); + addAcceptedBanksForDisplayAccount(); + addHolderNameAndIdForDisplayAccount(); + addLabelTextField(gridPane, ++gridRow, "Bank name:", bankAccountContractData.getBankName()).second.setMouseTransparent(false); + addLabelTextField(gridPane, ++gridRow, "Bank number:", bankAccountContractData.getBankId()).second.setMouseTransparent(false); + addLabelTextField(gridPane, ++gridRow, "Branch number:", bankAccountContractData.getBranchId()).second.setMouseTransparent(false); + addLabelTextField(gridPane, ++gridRow, "Account number:", bankAccountContractData.getAccountNr()).second.setMouseTransparent(false); + + addAllowedPeriod(); + } + + protected void addHolderNameAndIdForDisplayAccount() { + if (BankUtil.requiresHolderId(bankAccountContractData.getCountryCode())) { + Tuple4 tuple = addLabelTextFieldLabelTextField(gridPane, ++gridRow, + "Account holder name:", BankUtil.getHolderIdLabel(bankAccountContractData.getCountryCode())); + TextField holderNameTextField = tuple.second; + holderNameTextField.setText(bankAccountContractData.getHolderName()); + holderNameTextField.setMinWidth(300); + tuple.forth.setText(bankAccountContractData.getHolderId()); + } else { + addLabelTextField(gridPane, ++gridRow, "Account holder name:", bankAccountContractData.getHolderName()); + } + } + + public void addAcceptedBanksForDisplayAccount() { + } +} diff --git a/gui/src/main/java/io/bitsquare/gui/components/paymentmethods/NationalBankForm.java b/gui/src/main/java/io/bitsquare/gui/components/paymentmethods/NationalBankForm.java new file mode 100644 index 0000000000..aa9b168583 --- /dev/null +++ b/gui/src/main/java/io/bitsquare/gui/components/paymentmethods/NationalBankForm.java @@ -0,0 +1,39 @@ +/* + * 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.components.paymentmethods; + +import io.bitsquare.gui.util.validation.InputValidator; +import io.bitsquare.payment.PaymentAccount; +import io.bitsquare.payment.PaymentAccountContractData; +import javafx.scene.layout.GridPane; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class NationalBankForm extends BankForm { + private static final Logger log = LoggerFactory.getLogger(NationalBankForm.class); + + public static int addFormForBuyer(GridPane gridPane, int gridRow, PaymentAccountContractData paymentAccountContractData) { + BankForm.addFormForBuyer(gridPane, gridRow, paymentAccountContractData); + return gridRow; + } + + public NationalBankForm(PaymentAccount paymentAccount, InputValidator inputValidator, + GridPane gridPane, int gridRow) { + super(paymentAccount, inputValidator, gridPane, gridRow); + } +} diff --git a/gui/src/main/java/io/bitsquare/gui/components/paymentmethods/PaymentMethodForm.java b/gui/src/main/java/io/bitsquare/gui/components/paymentmethods/PaymentMethodForm.java index f2404f837e..4f0ec7307d 100644 --- a/gui/src/main/java/io/bitsquare/gui/components/paymentmethods/PaymentMethodForm.java +++ b/gui/src/main/java/io/bitsquare/gui/components/paymentmethods/PaymentMethodForm.java @@ -82,9 +82,10 @@ public abstract class PaymentMethodForm { protected void addAccountNameTextFieldWithAutoFillCheckBox() { Tuple3 tuple = addLabelInputTextFieldCheckBox(gridPane, ++gridRow, "Account name:", "Use custom account name"); accountNameTextField = tuple.second; - accountNameTextField.setPrefWidth(250); + accountNameTextField.setPrefWidth(300); accountNameTextField.setEditable(false); accountNameTextField.setValidator(inputValidator); + accountNameTextField.setFocusTraversable(false); accountNameTextField.textProperty().addListener((ov, oldValue, newValue) -> { paymentAccount.setAccountName(newValue); updateAllInputsValid(); @@ -92,7 +93,9 @@ public abstract class PaymentMethodForm { useCustomAccountNameCheckBox = tuple.third; useCustomAccountNameCheckBox.setSelected(false); useCustomAccountNameCheckBox.setOnAction(e -> { - accountNameTextField.setEditable(useCustomAccountNameCheckBox.isSelected()); + boolean selected = useCustomAccountNameCheckBox.isSelected(); + accountNameTextField.setEditable(selected); + accountNameTextField.setFocusTraversable(selected); autoFillNameTextField(); }); } diff --git a/gui/src/main/java/io/bitsquare/gui/components/paymentmethods/SameBankForm.java b/gui/src/main/java/io/bitsquare/gui/components/paymentmethods/SameBankForm.java new file mode 100644 index 0000000000..2baf0e6fa2 --- /dev/null +++ b/gui/src/main/java/io/bitsquare/gui/components/paymentmethods/SameBankForm.java @@ -0,0 +1,81 @@ +/* + * 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.components.paymentmethods; + +import io.bitsquare.common.util.Tuple2; +import io.bitsquare.gui.components.InputTextField; +import io.bitsquare.gui.util.validation.InputValidator; +import io.bitsquare.payment.PaymentAccount; +import io.bitsquare.payment.PaymentAccountContractData; +import javafx.scene.control.Label; +import javafx.scene.control.TextField; +import javafx.scene.layout.GridPane; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import static io.bitsquare.gui.util.FormBuilder.addLabelInputTextField; +import static io.bitsquare.gui.util.FormBuilder.addLabelTextField; + +public class SameBankForm extends BankForm { + private static final Logger log = LoggerFactory.getLogger(SameBankForm.class); + + public static int addFormForBuyer(GridPane gridPane, int gridRow, PaymentAccountContractData paymentAccountContractData) { + BankForm.addFormForBuyer(gridPane, gridRow, paymentAccountContractData); + return gridRow; + } + + public SameBankForm(PaymentAccount paymentAccount, InputValidator inputValidator, + GridPane gridPane, int gridRow) { + super(paymentAccount, inputValidator, gridPane, gridRow); + } + + @Override + protected void addHolderNameAndId() { + Tuple2 tuple = addLabelInputTextField(gridPane, ++gridRow, "Account holder name:"); + InputTextField holderNameInputTextField = tuple.second; + holderNameInputTextField.setValidator(inputValidator); + holderNameInputTextField.textProperty().addListener((ov, oldValue, newValue) -> { + bankAccountContractData.setHolderName(newValue); + updateFromInputs(); + }); + } + + @Override + public void updateAllInputsValid() { + allInputsValid.set(isAccountNameValid() + && inputValidator.validate(bankAccountContractData.getHolderName()).isValid + && inputValidator.validate(bankAccountContractData.getBankName()).isValid + && inputValidator.validate(bankAccountContractData.getBankId()).isValid + && inputValidator.validate(bankAccountContractData.getBranchId()).isValid + && inputValidator.validate(bankAccountContractData.getAccountNr()).isValid + && paymentAccount.getSingleTradeCurrency() != null + && paymentAccount.getCountry() != null); + } + + @Override + protected void addHolderNameAndIdForDisplayAccount() { + Tuple2 tuple = addLabelTextField(gridPane, ++gridRow, "Account holder name:"); + TextField holderNameTextField = tuple.second; + holderNameTextField.setMinWidth(300); + holderNameTextField.textProperty().addListener((ov, oldValue, newValue) -> { + bankAccountContractData.setHolderName(newValue); + updateFromInputs(); + }); + } + +} diff --git a/gui/src/main/java/io/bitsquare/gui/components/paymentmethods/SepaForm.java b/gui/src/main/java/io/bitsquare/gui/components/paymentmethods/SepaForm.java index 0037f4d965..f8aa3fa16c 100644 --- a/gui/src/main/java/io/bitsquare/gui/components/paymentmethods/SepaForm.java +++ b/gui/src/main/java/io/bitsquare/gui/components/paymentmethods/SepaForm.java @@ -251,10 +251,8 @@ public class SepaForm extends PaymentMethodForm { addLabelTextField(gridPane, gridRow, "Account name:", sepaAccount.getAccountName(), Layout.FIRST_ROW_AND_GROUP_DISTANCE); addLabelTextField(gridPane, ++gridRow, "Payment method:", BSResources.get(sepaAccount.getPaymentMethod().getId())); addLabelTextField(gridPane, ++gridRow, "Account holder name:", sepaAccount.getHolderName()); - TextField ibanField = addLabelTextField(gridPane, ++gridRow, "IBAN:", sepaAccount.getIban()).second; - ibanField.setMouseTransparent(false); - TextField bicField = addLabelTextField(gridPane, ++gridRow, "BIC/SWIFT:", sepaAccount.getBic()).second; - bicField.setMouseTransparent(false); + addLabelTextField(gridPane, ++gridRow, "IBAN:", sepaAccount.getIban()).second.setMouseTransparent(false); + addLabelTextField(gridPane, ++gridRow, "BIC/SWIFT:", sepaAccount.getBic()).second.setMouseTransparent(false); addLabelTextField(gridPane, ++gridRow, "Location of Bank:", sepaAccount.getCountry() != null ? sepaAccount.getCountry().name : ""); addLabelTextField(gridPane, ++gridRow, "Currency:", sepaAccount.getSingleTradeCurrency().getNameAndCode()); diff --git a/gui/src/main/java/io/bitsquare/gui/components/paymentmethods/SpecificBankForm.java b/gui/src/main/java/io/bitsquare/gui/components/paymentmethods/SpecificBankForm.java new file mode 100644 index 0000000000..02c9a312d6 --- /dev/null +++ b/gui/src/main/java/io/bitsquare/gui/components/paymentmethods/SpecificBankForm.java @@ -0,0 +1,108 @@ +/* + * 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.components.paymentmethods; + +import com.google.common.base.Joiner; +import io.bitsquare.common.util.Tuple3; +import io.bitsquare.gui.components.InputTextField; +import io.bitsquare.gui.util.validation.InputValidator; +import io.bitsquare.payment.PaymentAccount; +import io.bitsquare.payment.PaymentAccountContractData; +import io.bitsquare.payment.SpecificBanksAccountContractData; +import javafx.beans.binding.Bindings; +import javafx.scene.control.Button; +import javafx.scene.control.Label; +import javafx.scene.control.TextField; +import javafx.scene.control.Tooltip; +import javafx.scene.layout.GridPane; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import static io.bitsquare.gui.util.FormBuilder.*; + +public class SpecificBankForm extends BankForm { + private static final Logger log = LoggerFactory.getLogger(SpecificBankForm.class); + + private final SpecificBanksAccountContractData specificBanksAccountContractData; + private TextField acceptedBanksTextField; + private Tooltip acceptedBanksTooltip; + + public static int addFormForBuyer(GridPane gridPane, int gridRow, PaymentAccountContractData paymentAccountContractData) { + BankForm.addFormForBuyer(gridPane, gridRow, paymentAccountContractData); + return gridRow; + } + + public SpecificBankForm(PaymentAccount paymentAccount, InputValidator inputValidator, + GridPane gridPane, int gridRow) { + super(paymentAccount, inputValidator, gridPane, gridRow); + this.specificBanksAccountContractData = (SpecificBanksAccountContractData) paymentAccount.contractData; + } + + @Override + protected void addAcceptedBanksForAddAccount() { + Tuple3 addBankTuple = addLabelInputTextFieldButton(gridPane, ++gridRow, "Add name of accepted bank:", "Add accepted bank"); + InputTextField addBankInputTextField = addBankTuple.second; + addBankInputTextField.setMinWidth(300); + Button addButton = addBankTuple.third; + addButton.disableProperty().bind(Bindings.createBooleanBinding(() -> addBankInputTextField.getText().isEmpty(), addBankInputTextField.textProperty())); + + Tuple3 acceptedBanksTuple = addLabelTextFieldButton(gridPane, ++gridRow, "Accepted banks:", "Clear accepted banks"); + acceptedBanksTextField = acceptedBanksTuple.second; + acceptedBanksTextField.setMinWidth(addBankInputTextField.getMinWidth()); + acceptedBanksTextField.setMouseTransparent(false); + acceptedBanksTooltip = new Tooltip(); + acceptedBanksTextField.setTooltip(acceptedBanksTooltip); + Button clearButton = acceptedBanksTuple.third; + clearButton.disableProperty().bind(Bindings.createBooleanBinding(() -> acceptedBanksTextField.getText().isEmpty(), acceptedBanksTextField.textProperty())); + addButton.setOnAction(e -> { + specificBanksAccountContractData.addAcceptedBank(addBankInputTextField.getText()); + addBankInputTextField.setText(""); + String value = Joiner.on(", ").join(specificBanksAccountContractData.getAcceptedBanks()); + acceptedBanksTextField.setText(value); + acceptedBanksTooltip.setText(value); + updateAllInputsValid(); + }); + + clearButton.setOnAction(e -> resetAcceptedBanks()); + } + + private void resetAcceptedBanks() { + specificBanksAccountContractData.clearAcceptedBanks(); + acceptedBanksTextField.setText(""); + acceptedBanksTooltip.setText(""); + updateAllInputsValid(); + } + + @Override + protected void onCountryChanged() { + resetAcceptedBanks(); + } + + @Override + public void addAcceptedBanksForDisplayAccount() { + addLabelTextField(gridPane, ++gridRow, "Accepted banks:", + Joiner.on(", ").join(specificBanksAccountContractData.getAcceptedBanks())).second.setMouseTransparent(false); + } + + @Override + public void updateAllInputsValid() { + super.updateAllInputsValid(); + allInputsValid.set(allInputsValid.get() && inputValidator.validate(acceptedBanksTextField.getText()).isValid); + } + +} diff --git a/gui/src/main/java/io/bitsquare/gui/main/account/content/paymentsaccount/PaymentAccountView.java b/gui/src/main/java/io/bitsquare/gui/main/account/content/paymentsaccount/PaymentAccountView.java index a52c82dc00..9767ca6f63 100644 --- a/gui/src/main/java/io/bitsquare/gui/main/account/content/paymentsaccount/PaymentAccountView.java +++ b/gui/src/main/java/io/bitsquare/gui/main/account/content/paymentsaccount/PaymentAccountView.java @@ -28,7 +28,9 @@ import io.bitsquare.gui.util.ImageUtil; import io.bitsquare.gui.util.Layout; import io.bitsquare.gui.util.validation.*; import io.bitsquare.locale.BSResources; -import io.bitsquare.payment.*; +import io.bitsquare.payment.PaymentAccount; +import io.bitsquare.payment.PaymentAccountFactory; +import io.bitsquare.payment.PaymentMethod; import javafx.beans.value.ChangeListener; import javafx.collections.FXCollections; import javafx.geometry.VPos; @@ -238,8 +240,11 @@ public class PaymentAccountView extends ActivatableViewAndModel tuple = add2ButtonsAfterGroup(root, ++gridRow, "Delete account", "Cancel"); + Button deleteAccountButton = tuple.first; deleteAccountButton.setOnAction(event -> onDeleteAccount(paymentMethodForm.getPaymentAccount())); + Button cancelButton = tuple.second; + cancelButton.setOnAction(event -> removeSelectAccountForm()); GridPane.setRowSpan(accountTitledGroupBg, paymentMethodForm.getRowSpan()); model.onSelectAccount(paymentAccount); } @@ -255,32 +260,7 @@ public class PaymentAccountView extends ActivatableViewAndModel { List listItems = walletService.getWallet().getRecentTransactions(1000, true).stream() .map(transaction -> { - log.error("tx ID " + transaction.getHashAsString()); Optional tradableOptional = all.stream() .filter(tradable -> { String txId = transaction.getHashAsString(); @@ -193,19 +192,12 @@ public class TransactionsView extends ActivatableView { tradable.getId().equals(dispute.getTradeId())) .findAny() .isPresent(); - log.error("isTakeOfferFeeTx " + isTakeOfferFeeTx); - log.error("isOfferFeeTx " + isOfferFeeTx); - log.error("isDepositTx " + isDepositTx); - log.error("isPayoutTx " + isPayoutTx); - log.error("isDisputedPayoutTx " + isDisputedPayoutTx); return isTakeOfferFeeTx || isOfferFeeTx || isDepositTx || isPayoutTx || isDisputedPayoutTx; } else return false; }) .findAny(); - if (tradableOptional.isPresent()) - log.error("tradableOptional " + tradableOptional.get().getId()); return new TransactionsListItem(transaction, walletService, tradableOptional, formatter); }) .collect(Collectors.toList()); diff --git a/gui/src/main/java/io/bitsquare/gui/main/popups/Popup.java b/gui/src/main/java/io/bitsquare/gui/main/popups/Popup.java index 33d608b056..5b6c069ea7 100644 --- a/gui/src/main/java/io/bitsquare/gui/main/popups/Popup.java +++ b/gui/src/main/java/io/bitsquare/gui/main/popups/Popup.java @@ -103,6 +103,8 @@ public class Popup { public void hide() { animateHide(() -> { + if (owner == null) + owner = MainView.getRootContainer(); Scene rootScene = owner.getScene(); if (rootScene != null) { Window window = rootScene.getWindow(); @@ -308,6 +310,8 @@ public class Popup { } protected void layout() { + if (owner == null) + owner = MainView.getRootContainer(); Scene rootScene = owner.getScene(); if (rootScene != null) { Window window = rootScene.getWindow(); diff --git a/gui/src/main/java/io/bitsquare/gui/main/portfolio/pendingtrades/steps/buyer/BuyerStep2View.java b/gui/src/main/java/io/bitsquare/gui/main/portfolio/pendingtrades/steps/buyer/BuyerStep2View.java index 20cd0a51d9..92bd8d0890 100644 --- a/gui/src/main/java/io/bitsquare/gui/main/portfolio/pendingtrades/steps/buyer/BuyerStep2View.java +++ b/gui/src/main/java/io/bitsquare/gui/main/portfolio/pendingtrades/steps/buyer/BuyerStep2View.java @@ -138,6 +138,15 @@ public class BuyerStep2View extends TradeStepView { case PaymentMethod.SEPA_ID: gridRow = SepaForm.addFormForBuyer(gridPane, gridRow, paymentAccountContractData); break; + case PaymentMethod.NATIONAL_BANK_ID: + gridRow = NationalBankForm.addFormForBuyer(gridPane, gridRow, paymentAccountContractData); + break; + case PaymentMethod.SAME_BANK_ID: + gridRow = SameBankForm.addFormForBuyer(gridPane, gridRow, paymentAccountContractData); + break; + case PaymentMethod.SPECIFIC_BANKS_ID: + gridRow = SpecificBankForm.addFormForBuyer(gridPane, gridRow, paymentAccountContractData); + break; case PaymentMethod.SWISH_ID: gridRow = SwishForm.addFormForBuyer(gridPane, gridRow, paymentAccountContractData); break; diff --git a/gui/src/main/java/io/bitsquare/gui/util/FormBuilder.java b/gui/src/main/java/io/bitsquare/gui/util/FormBuilder.java index cc3485b570..3714be12d5 100644 --- a/gui/src/main/java/io/bitsquare/gui/util/FormBuilder.java +++ b/gui/src/main/java/io/bitsquare/gui/util/FormBuilder.java @@ -20,6 +20,7 @@ package io.bitsquare.gui.util; import de.jensd.fx.fontawesome.AwesomeIcon; import io.bitsquare.common.util.Tuple2; import io.bitsquare.common.util.Tuple3; +import io.bitsquare.common.util.Tuple4; import io.bitsquare.gui.components.*; import javafx.geometry.HPos; import javafx.geometry.Insets; @@ -308,6 +309,104 @@ public class FormBuilder { return new Tuple3<>(label, inputTextField, checkBox); } + + /////////////////////////////////////////////////////////////////////////////////////////// + // Label + InputTextField + Button + /////////////////////////////////////////////////////////////////////////////////////////// + + public static Tuple3 addLabelInputTextFieldButton(GridPane gridPane, int rowIndex, String title, String buttonTitle) { + Label label = addLabel(gridPane, rowIndex, title, 0); + + InputTextField inputTextField = new InputTextField(); + Button button = new Button(buttonTitle); + + HBox hBox = new HBox(); + hBox.setSpacing(10); + hBox.getChildren().addAll(inputTextField, button); + GridPane.setRowIndex(hBox, rowIndex); + GridPane.setColumnIndex(hBox, 1); + gridPane.getChildren().add(hBox); + + return new Tuple3<>(label, inputTextField, button); + } + + + /////////////////////////////////////////////////////////////////////////////////////////// + // Label + TextField + Button + /////////////////////////////////////////////////////////////////////////////////////////// + + public static Tuple3 addLabelTextFieldButton(GridPane gridPane, int rowIndex, String title, String buttonTitle) { + Label label = addLabel(gridPane, rowIndex, title, 0); + + TextField textField = new TextField(); + textField.setEditable(false); + textField.setMouseTransparent(true); + textField.setFocusTraversable(false); + Button button = new Button(buttonTitle); + + HBox hBox = new HBox(); + hBox.setSpacing(10); + hBox.getChildren().addAll(textField, button); + GridPane.setRowIndex(hBox, rowIndex); + GridPane.setColumnIndex(hBox, 1); + gridPane.getChildren().add(hBox); + + return new Tuple3<>(label, textField, button); + } + + + /////////////////////////////////////////////////////////////////////////////////////////// + // Label + InputTextField + Label + InputTextField + /////////////////////////////////////////////////////////////////////////////////////////// + + public static Tuple4 addLabelInputTextFieldLabelInputTextField(GridPane gridPane, int rowIndex, String title1, String title2) { + Label label1 = addLabel(gridPane, rowIndex, title1, 0); + + InputTextField inputTextField1 = new InputTextField(); + Label label2 = new Label(title2); + HBox.setMargin(label2, new Insets(5, 0, 0, 0)); + InputTextField inputTextField2 = new InputTextField(); + + HBox hBox = new HBox(); + hBox.setSpacing(10); + hBox.getChildren().addAll(inputTextField1, label2, inputTextField2); + GridPane.setRowIndex(hBox, rowIndex); + GridPane.setColumnIndex(hBox, 1); + gridPane.getChildren().add(hBox); + + return new Tuple4<>(label1, inputTextField1, label2, inputTextField2); + } + + + /////////////////////////////////////////////////////////////////////////////////////////// + // Label + TextField + Label + TextField + /////////////////////////////////////////////////////////////////////////////////////////// + + public static Tuple4 addLabelTextFieldLabelTextField(GridPane gridPane, int rowIndex, String title1, String title2) { + Label label1 = addLabel(gridPane, rowIndex, title1, 0); + + TextField textField1 = new TextField(); + textField1.setEditable(false); + textField1.setMouseTransparent(true); + textField1.setFocusTraversable(false); + Label label2 = new Label(title2); + HBox.setMargin(label2, new Insets(5, 0, 0, 0)); + TextField textField2 = new TextField(); + textField2.setEditable(false); + textField2.setMouseTransparent(true); + textField2.setFocusTraversable(false); + + HBox hBox = new HBox(); + hBox.setSpacing(10); + hBox.getChildren().addAll(textField1, label2, textField2); + GridPane.setRowIndex(hBox, rowIndex); + GridPane.setColumnIndex(hBox, 1); + gridPane.getChildren().add(hBox); + + return new Tuple4<>(label1, textField1, label2, textField2); + } + + /////////////////////////////////////////////////////////////////////////////////////////// // Button + CheckBox /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/gui/src/main/resources/i18n/displayStrings.properties b/gui/src/main/resources/i18n/displayStrings.properties index 1615dca4ba..250f7724c5 100644 --- a/gui/src/main/resources/i18n/displayStrings.properties +++ b/gui/src/main/resources/i18n/displayStrings.properties @@ -145,9 +145,11 @@ OK_PAY=OKPay PERFECT_MONEY=Perfect Money ALI_PAY=AliPay SEPA=SEPA +NATIONAL_BANK=National Bank transfer +SAME_BANK=Transfer with same Bank +SPECIFIC_BANKS=Transfers with specific banks FED_WIRE=Fed Wire SWISH= Swish TRANSFER_WISE=TransferWise US_POSTAL_MONEY_ORDER=US Postal money order BLOCK_CHAINS=Crypto currencies - diff --git a/network/src/main/java/io/bitsquare/p2p/peers/BroadcastHandler.java b/network/src/main/java/io/bitsquare/p2p/peers/BroadcastHandler.java index 822dd5e724..9a0d6bdcac 100644 --- a/network/src/main/java/io/bitsquare/p2p/peers/BroadcastHandler.java +++ b/network/src/main/java/io/bitsquare/p2p/peers/BroadcastHandler.java @@ -111,16 +111,17 @@ public class BroadcastHandler implements PeerManager.Listener { // the data owner sends to all and immediately connectedPeers.stream().forEach(connection -> sendToPeer(connection, message)); numOfPeers = connectedPeers.size(); - log.info("Broadcast message to {} peers.", numOfPeers); + log.info("Broadcast message to all {} connected peers.", numOfPeers); } else { // for relay nodes we limit to 2 recipients and use a delay List list = new ArrayList<>(connectedPeers); Collections.shuffle(list); int size = list.size(); - if (size > 1) + // We want min. 2 nodes + if (size > 3) list = list.subList(0, size / 2); numOfPeers = list.size(); - log.info("Broadcast message to {} peers.", numOfPeers); + log.info("Broadcast message to {} peers out of {} total connected peers.", numOfPeers, connectedPeers.size()); list.stream().forEach(connection -> UserThread.runAfterRandomDelay(() -> sendToPeer(connection, message), DELAY_MS, DELAY_MS * 2, TimeUnit.MILLISECONDS)); }