mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-07-27 00:45:23 -04:00
Remove BitSquareValidator (was deprecated)
This commit is contained in:
parent
a7e6fd96c7
commit
19e71ffad2
7 changed files with 71 additions and 325 deletions
|
@ -25,7 +25,6 @@ import io.bitsquare.gui.Navigation;
|
||||||
import io.bitsquare.gui.components.confidence.ConfidenceProgressIndicator;
|
import io.bitsquare.gui.components.confidence.ConfidenceProgressIndicator;
|
||||||
import io.bitsquare.gui.main.arbitrators.profile.ArbitratorProfileController;
|
import io.bitsquare.gui.main.arbitrators.profile.ArbitratorProfileController;
|
||||||
import io.bitsquare.gui.util.BSFormatter;
|
import io.bitsquare.gui.util.BSFormatter;
|
||||||
import io.bitsquare.gui.util.BitSquareValidator;
|
|
||||||
import io.bitsquare.locale.BSResources;
|
import io.bitsquare.locale.BSResources;
|
||||||
import io.bitsquare.locale.LanguageUtil;
|
import io.bitsquare.locale.LanguageUtil;
|
||||||
import io.bitsquare.msg.MessageFacade;
|
import io.bitsquare.msg.MessageFacade;
|
||||||
|
@ -451,13 +450,6 @@ public class ArbitratorRegistrationController extends CachedViewController {
|
||||||
|
|
||||||
|
|
||||||
private Arbitrator getEditedArbitrator() {
|
private Arbitrator getEditedArbitrator() {
|
||||||
try {
|
|
||||||
BitSquareValidator.textFieldsNotEmptyWithReset(
|
|
||||||
nameTextField, idTypeTextField, languagesTextField, methodsTextField, idVerificationsTextField);
|
|
||||||
BitSquareValidator.textFieldsHasDoubleValueWithReset(
|
|
||||||
maxTradeVolumeTextField, passiveServiceFeeTextField, minPassiveServiceFeeTextField,
|
|
||||||
arbitrationFeeTextField, minArbitrationFeeTextField);
|
|
||||||
|
|
||||||
String pubKeyAsHex = walletFacade.getArbitratorDepositAddressEntry().getPubKeyAsHexString();
|
String pubKeyAsHex = walletFacade.getArbitratorDepositAddressEntry().getPubKeyAsHexString();
|
||||||
String messagePubKeyAsHex = DSAKeyUtil.getHexStringFromPublicKey(user.getMessagePublicKey());
|
String messagePubKeyAsHex = DSAKeyUtil.getHexStringFromPublicKey(user.getMessagePublicKey());
|
||||||
String name = nameTextField.getText();
|
String name = nameTextField.getText();
|
||||||
|
@ -486,9 +478,6 @@ public class ArbitratorRegistrationController extends CachedViewController {
|
||||||
idVerificationList,
|
idVerificationList,
|
||||||
webUrl,
|
webUrl,
|
||||||
description);
|
description);
|
||||||
} catch (BitSquareValidator.ValidationException e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void close() {
|
private void close() {
|
||||||
|
|
|
@ -56,8 +56,7 @@ public class TransactionsListItem {
|
||||||
Coin valueSentFromMe = transaction.getValueSentFromMe(walletFacade.getWallet());
|
Coin valueSentFromMe = transaction.getValueSentFromMe(walletFacade.getWallet());
|
||||||
Address address = null;
|
Address address = null;
|
||||||
if (valueSentToMe.isZero()) {
|
if (valueSentToMe.isZero()) {
|
||||||
//TODO use BSFormatter
|
amount.set("-" + BSFormatter.formatCoin(valueSentFromMe));
|
||||||
amount.set("-" + valueSentFromMe.toFriendlyString());
|
|
||||||
|
|
||||||
for (TransactionOutput transactionOutput : transaction.getOutputs()) {
|
for (TransactionOutput transactionOutput : transaction.getOutputs()) {
|
||||||
if (!transactionOutput.isMine(walletFacade.getWallet())) {
|
if (!transactionOutput.isMine(walletFacade.getWallet())) {
|
||||||
|
@ -76,8 +75,7 @@ public class TransactionsListItem {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (valueSentFromMe.isZero()) {
|
else if (valueSentFromMe.isZero()) {
|
||||||
//TODO use BSFormatter
|
amount.set(BSFormatter.formatCoin(valueSentToMe));
|
||||||
amount.set(valueSentToMe.toFriendlyString());
|
|
||||||
type.set("Received with");
|
type.set("Received with");
|
||||||
|
|
||||||
for (TransactionOutput transactionOutput : transaction.getOutputs()) {
|
for (TransactionOutput transactionOutput : transaction.getOutputs()) {
|
||||||
|
@ -95,9 +93,7 @@ public class TransactionsListItem {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
//TODO use BSFormatter
|
amount.set(BSFormatter.formatCoin(valueSentToMe.subtract(valueSentFromMe)));
|
||||||
amount.set(valueSentToMe.subtract(valueSentFromMe).toFriendlyString());
|
|
||||||
|
|
||||||
boolean outgoing = false;
|
boolean outgoing = false;
|
||||||
for (TransactionOutput transactionOutput : transaction.getOutputs()) {
|
for (TransactionOutput transactionOutput : transaction.getOutputs()) {
|
||||||
if (!transactionOutput.isMine(walletFacade.getWallet())) {
|
if (!transactionOutput.isMine(walletFacade.getWallet())) {
|
||||||
|
|
|
@ -24,7 +24,6 @@ import io.bitsquare.btc.WalletFacade;
|
||||||
import io.bitsquare.gui.CachedViewController;
|
import io.bitsquare.gui.CachedViewController;
|
||||||
import io.bitsquare.gui.components.Popups;
|
import io.bitsquare.gui.components.Popups;
|
||||||
import io.bitsquare.gui.util.BSFormatter;
|
import io.bitsquare.gui.util.BSFormatter;
|
||||||
import io.bitsquare.gui.util.BitSquareValidator;
|
|
||||||
|
|
||||||
import com.google.bitcoin.core.AddressFormatException;
|
import com.google.bitcoin.core.AddressFormatException;
|
||||||
import com.google.bitcoin.core.Coin;
|
import com.google.bitcoin.core.Coin;
|
||||||
|
@ -113,8 +112,6 @@ public class WithdrawalController extends CachedViewController {
|
||||||
|
|
||||||
tableView.getSelectionModel().selectedItemProperty().addListener((observableValue, oldValue, newValue) -> {
|
tableView.getSelectionModel().selectedItemProperty().addListener((observableValue, oldValue, newValue) -> {
|
||||||
if (newValue != null) {
|
if (newValue != null) {
|
||||||
BitSquareValidator.resetTextFields(
|
|
||||||
withdrawFromTextField, withdrawToTextField, amountTextField, changeAddressTextField);
|
|
||||||
|
|
||||||
if (Coin.ZERO.compareTo(newValue.getBalance()) <= 0) {
|
if (Coin.ZERO.compareTo(newValue.getBalance()) <= 0) {
|
||||||
amountTextField.setText(newValue.getBalance().toPlainString());
|
amountTextField.setText(newValue.getBalance().toPlainString());
|
||||||
|
@ -145,18 +142,11 @@ public class WithdrawalController extends CachedViewController {
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
public void onWithdraw() {
|
public void onWithdraw() {
|
||||||
try {
|
|
||||||
BitSquareValidator.textFieldsNotEmpty(
|
|
||||||
amountTextField, withdrawFromTextField, withdrawToTextField, changeAddressTextField);
|
|
||||||
BitSquareValidator.textFieldsHasDoubleValueWithReset(amountTextField);
|
|
||||||
|
|
||||||
Coin amount = BSFormatter.parseToCoin(amountTextField.getText());
|
Coin amount = BSFormatter.parseToCoin(amountTextField.getText());
|
||||||
if (Restrictions.isMinSpendableAmount(amount)) {
|
if (Restrictions.isMinSpendableAmount(amount)) {
|
||||||
FutureCallback<Transaction> callback = new FutureCallback<Transaction>() {
|
FutureCallback<Transaction> callback = new FutureCallback<Transaction>() {
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(@javax.annotation.Nullable Transaction transaction) {
|
public void onSuccess(@javax.annotation.Nullable Transaction transaction) {
|
||||||
BitSquareValidator.resetTextFields(
|
|
||||||
withdrawFromTextField, withdrawToTextField, amountTextField, changeAddressTextField);
|
|
||||||
if (transaction != null) {
|
if (transaction != null) {
|
||||||
log.info("onWithdraw onSuccess tx ID:" + transaction.getHashAsString());
|
log.info("onWithdraw onSuccess tx ID:" + transaction.getHashAsString());
|
||||||
}
|
}
|
||||||
|
@ -199,9 +189,6 @@ public class WithdrawalController extends CachedViewController {
|
||||||
"The amount to transfer is lower the the transaction fee and the min. possible tx value.");
|
"The amount to transfer is lower the the transaction fee and the min. possible tx value.");
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (BitSquareValidator.ValidationException e) {
|
|
||||||
log.trace(e.toString());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@ import io.bitsquare.btc.WalletFacade;
|
||||||
import io.bitsquare.btc.listeners.AddressConfidenceListener;
|
import io.bitsquare.btc.listeners.AddressConfidenceListener;
|
||||||
import io.bitsquare.btc.listeners.BalanceListener;
|
import io.bitsquare.btc.listeners.BalanceListener;
|
||||||
import io.bitsquare.gui.components.confidence.ConfidenceProgressIndicator;
|
import io.bitsquare.gui.components.confidence.ConfidenceProgressIndicator;
|
||||||
|
import io.bitsquare.gui.util.BSFormatter;
|
||||||
|
|
||||||
import com.google.bitcoin.core.Address;
|
import com.google.bitcoin.core.Address;
|
||||||
import com.google.bitcoin.core.Coin;
|
import com.google.bitcoin.core.Coin;
|
||||||
|
@ -93,8 +94,7 @@ public class WithdrawalListItem {
|
||||||
private void updateBalance(Coin balance) {
|
private void updateBalance(Coin balance) {
|
||||||
this.balance = balance;
|
this.balance = balance;
|
||||||
if (balance != null) {
|
if (balance != null) {
|
||||||
//TODO use BSFormatter
|
balanceLabel.setText(BSFormatter.formatCoin(balance));
|
||||||
balanceLabel.setText(balance.toFriendlyString());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,173 +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 <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.bitsquare.gui.util;
|
|
||||||
|
|
||||||
import io.bitsquare.bank.BankAccountType;
|
|
||||||
import io.bitsquare.trade.Offer;
|
|
||||||
|
|
||||||
import com.google.bitcoin.core.Coin;
|
|
||||||
|
|
||||||
import javafx.scene.control.*;
|
|
||||||
import javafx.scene.effect.*;
|
|
||||||
import javafx.scene.paint.*;
|
|
||||||
|
|
||||||
//TODO to be removed
|
|
||||||
@Deprecated
|
|
||||||
public class BitSquareValidator {
|
|
||||||
private static final Effect invalidEffect = new DropShadow(BlurType.THREE_PASS_BOX, Color.RED, 4, 0.0, 0, 0);
|
|
||||||
private static final String invalidStyle = "-fx-border-color: red";
|
|
||||||
|
|
||||||
public static boolean tradeAmountOutOfRange(Coin tradeAmount, Offer offer) {
|
|
||||||
return tradeAmount.compareTo(offer.getAmount()) > 0 || tradeAmount.compareTo(offer.getMinAmount()) < 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean greaterThanZero(Coin value) {
|
|
||||||
return value.compareTo(Coin.ZERO) > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void textFieldsNotEmptyWithReset(TextField... textFields) throws ValidationException {
|
|
||||||
resetTextFields(textFields);
|
|
||||||
textFieldsNotEmpty(textFields);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void resetTextFields(TextField... textFields) {
|
|
||||||
for (TextField textField : textFields) {
|
|
||||||
textField.setStyle("-fx-border-color: null");
|
|
||||||
textField.setEffect(null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void textFieldsNotEmpty(TextField... textFields) throws ValidationException {
|
|
||||||
for (TextField textField : textFields) {
|
|
||||||
textFieldNotEmpty(textField);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void textFieldNotEmpty(TextField textField) throws ValidationException {
|
|
||||||
if (!validateStringNotEmpty(textField.getText())) {
|
|
||||||
textField.setEffect(invalidEffect);
|
|
||||||
textField.setStyle(invalidStyle);
|
|
||||||
throw new ValidationException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void textFieldsHasDoubleValueWithReset(TextField... textFields) throws ValidationException {
|
|
||||||
resetTextFields(textFields);
|
|
||||||
textFieldsHasDoubleValue(textFields);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void textFieldsHasDoubleValue(TextField... textFields) throws ValidationException {
|
|
||||||
for (TextField textField : textFields) {
|
|
||||||
textFieldHasDoubleValue(textField);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void textFieldHasDoubleValue(TextField textField) throws ValidationException {
|
|
||||||
if (!validateStringAsDouble(textField.getText().replace(",", "."))) {
|
|
||||||
textField.setEffect(invalidEffect);
|
|
||||||
textField.setStyle(invalidStyle);
|
|
||||||
throw new ValidationException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static void textFieldsHasPositiveDoubleValueWithReset(TextField... textFields) throws ValidationException {
|
|
||||||
resetTextFields(textFields);
|
|
||||||
textFieldsHasPositiveDoubleValue(textFields);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void textFieldsHasPositiveDoubleValue(TextField... textFields) throws ValidationException {
|
|
||||||
for (TextField textField : textFields) {
|
|
||||||
textFieldHasPositiveDoubleValue(textField);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void textFieldHasPositiveDoubleValue(TextField textField) throws ValidationException {
|
|
||||||
String input = textField.getText().replace(",", ".");
|
|
||||||
if (!validateStringAsDouble(input)) {
|
|
||||||
textField.setEffect(invalidEffect);
|
|
||||||
textField.setStyle(invalidStyle);
|
|
||||||
throw new ValidationException();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
double val = Double.parseDouble(input);
|
|
||||||
if (val <= 0) {
|
|
||||||
textField.setEffect(invalidEffect);
|
|
||||||
textField.setStyle(invalidStyle);
|
|
||||||
throw new ValidationException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO
|
|
||||||
public static void textFieldBankAccountPrimaryIDIsValid(TextField textField, BankAccountType bankAccountType)
|
|
||||||
throws ValidationException {
|
|
||||||
if (!validateStringNotEmpty(textField.getText())) {
|
|
||||||
textField.setEffect(invalidEffect);
|
|
||||||
textField.setStyle(invalidStyle);
|
|
||||||
throw new ValidationException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO
|
|
||||||
public static void textFieldBankAccountSecondaryIDIsValid(TextField textField,
|
|
||||||
BankAccountType bankAccountType) throws
|
|
||||||
ValidationException {
|
|
||||||
if (!validateStringNotEmpty(textField.getText())) {
|
|
||||||
textField.setEffect(invalidEffect);
|
|
||||||
textField.setStyle(invalidStyle);
|
|
||||||
throw new ValidationException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean validateStringsAsDouble(String... inputs) {
|
|
||||||
boolean result = true;
|
|
||||||
for (String input : inputs) {
|
|
||||||
result &= validateStringAsDouble(input);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean validateStringAsDouble(String input) {
|
|
||||||
try {
|
|
||||||
input = input.replace(",", ".");
|
|
||||||
//noinspection ResultOfMethodCallIgnored
|
|
||||||
Double.parseDouble(input);
|
|
||||||
return true;
|
|
||||||
} catch (NumberFormatException | NullPointerException e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean validateStringsNotEmpty(String... inputs) {
|
|
||||||
boolean result = true;
|
|
||||||
for (String input : inputs) {
|
|
||||||
result &= validateStringNotEmpty(input);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean validateStringNotEmpty(String input) {
|
|
||||||
return input != null && !input.isEmpty() && !" ".equals(input);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class ValidationException extends Exception {
|
|
||||||
private static final long serialVersionUID = -5583980308504568844L;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -21,7 +21,6 @@ import io.bitsquare.btc.RestrictionsTest;
|
||||||
import io.bitsquare.gui.main.trade.createoffer.CreateOfferPMTest;
|
import io.bitsquare.gui.main.trade.createoffer.CreateOfferPMTest;
|
||||||
import io.bitsquare.gui.util.BSFormatterTest;
|
import io.bitsquare.gui.util.BSFormatterTest;
|
||||||
import io.bitsquare.gui.util.BitSquareConverterTest;
|
import io.bitsquare.gui.util.BitSquareConverterTest;
|
||||||
import io.bitsquare.gui.util.BitSquareNumberValidatorTest;
|
|
||||||
import io.bitsquare.gui.util.validation.BtcValidatorTest;
|
import io.bitsquare.gui.util.validation.BtcValidatorTest;
|
||||||
import io.bitsquare.gui.util.validation.FiatValidatorTest;
|
import io.bitsquare.gui.util.validation.FiatValidatorTest;
|
||||||
import io.bitsquare.msg.P2PNodeTest;
|
import io.bitsquare.msg.P2PNodeTest;
|
||||||
|
@ -33,7 +32,6 @@ import org.junit.runners.Suite;
|
||||||
@Suite.SuiteClasses({
|
@Suite.SuiteClasses({
|
||||||
RestrictionsTest.class,
|
RestrictionsTest.class,
|
||||||
BitSquareConverterTest.class,
|
BitSquareConverterTest.class,
|
||||||
BitSquareNumberValidatorTest.class,
|
|
||||||
P2PNodeTest.class,
|
P2PNodeTest.class,
|
||||||
FiatValidatorTest.class,
|
FiatValidatorTest.class,
|
||||||
RestrictionsTest.class,
|
RestrictionsTest.class,
|
||||||
|
|
|
@ -1,51 +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 <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.bitsquare.gui.util;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
public class BitSquareNumberValidatorTest {
|
|
||||||
@Test
|
|
||||||
public void testValidateStringAsDouble() {
|
|
||||||
assertTrue(BitSquareValidator.validateStringAsDouble("0"));
|
|
||||||
assertTrue(BitSquareValidator.validateStringAsDouble("1"));
|
|
||||||
assertTrue(BitSquareValidator.validateStringAsDouble("0,1"));
|
|
||||||
assertTrue(BitSquareValidator.validateStringAsDouble("0.01"));
|
|
||||||
|
|
||||||
assertFalse(BitSquareValidator.validateStringAsDouble(""));
|
|
||||||
assertFalse(BitSquareValidator.validateStringAsDouble("a"));
|
|
||||||
assertFalse(BitSquareValidator.validateStringAsDouble("0.0.1"));
|
|
||||||
assertFalse(BitSquareValidator.validateStringAsDouble("1,000.1"));
|
|
||||||
assertFalse(BitSquareValidator.validateStringAsDouble("1.000,1"));
|
|
||||||
assertFalse(BitSquareValidator.validateStringAsDouble(null));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testValidateStringNotEmpty() {
|
|
||||||
assertTrue(BitSquareValidator.validateStringNotEmpty("a"));
|
|
||||||
assertTrue(BitSquareValidator.validateStringNotEmpty("123"));
|
|
||||||
|
|
||||||
assertFalse(BitSquareValidator.validateStringNotEmpty(""));
|
|
||||||
assertFalse(BitSquareValidator.validateStringNotEmpty(" "));
|
|
||||||
assertFalse(BitSquareValidator.validateStringNotEmpty(null));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
Loading…
Add table
Add a link
Reference in a new issue