mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-03-15 10:26:37 -04:00
Remove BitSquareValidator (was deprecated)
This commit is contained in:
parent
a7e6fd96c7
commit
19e71ffad2
@ -25,7 +25,6 @@ import io.bitsquare.gui.Navigation;
|
||||
import io.bitsquare.gui.components.confidence.ConfidenceProgressIndicator;
|
||||
import io.bitsquare.gui.main.arbitrators.profile.ArbitratorProfileController;
|
||||
import io.bitsquare.gui.util.BSFormatter;
|
||||
import io.bitsquare.gui.util.BitSquareValidator;
|
||||
import io.bitsquare.locale.BSResources;
|
||||
import io.bitsquare.locale.LanguageUtil;
|
||||
import io.bitsquare.msg.MessageFacade;
|
||||
@ -451,44 +450,34 @@ public class ArbitratorRegistrationController extends CachedViewController {
|
||||
|
||||
|
||||
private Arbitrator getEditedArbitrator() {
|
||||
try {
|
||||
BitSquareValidator.textFieldsNotEmptyWithReset(
|
||||
nameTextField, idTypeTextField, languagesTextField, methodsTextField, idVerificationsTextField);
|
||||
BitSquareValidator.textFieldsHasDoubleValueWithReset(
|
||||
maxTradeVolumeTextField, passiveServiceFeeTextField, minPassiveServiceFeeTextField,
|
||||
arbitrationFeeTextField, minArbitrationFeeTextField);
|
||||
String pubKeyAsHex = walletFacade.getArbitratorDepositAddressEntry().getPubKeyAsHexString();
|
||||
String messagePubKeyAsHex = DSAKeyUtil.getHexStringFromPublicKey(user.getMessagePublicKey());
|
||||
String name = nameTextField.getText();
|
||||
|
||||
String pubKeyAsHex = walletFacade.getArbitratorDepositAddressEntry().getPubKeyAsHexString();
|
||||
String messagePubKeyAsHex = DSAKeyUtil.getHexStringFromPublicKey(user.getMessagePublicKey());
|
||||
String name = nameTextField.getText();
|
||||
double maxTradeVolume = BSFormatter.parseToDouble(maxTradeVolumeTextField.getText());
|
||||
double passiveServiceFee = BSFormatter.parseToDouble(passiveServiceFeeTextField.getText());
|
||||
double minPassiveServiceFee = BSFormatter.parseToDouble(minPassiveServiceFeeTextField.getText());
|
||||
double arbitrationFee = BSFormatter.parseToDouble(arbitrationFeeTextField.getText());
|
||||
double minArbitrationFee = BSFormatter.parseToDouble(minArbitrationFeeTextField.getText());
|
||||
|
||||
double maxTradeVolume = BSFormatter.parseToDouble(maxTradeVolumeTextField.getText());
|
||||
double passiveServiceFee = BSFormatter.parseToDouble(passiveServiceFeeTextField.getText());
|
||||
double minPassiveServiceFee = BSFormatter.parseToDouble(minPassiveServiceFeeTextField.getText());
|
||||
double arbitrationFee = BSFormatter.parseToDouble(arbitrationFeeTextField.getText());
|
||||
double minArbitrationFee = BSFormatter.parseToDouble(minArbitrationFeeTextField.getText());
|
||||
String webUrl = webPageTextField.getText();
|
||||
String description = descriptionTextArea.getText();
|
||||
|
||||
String webUrl = webPageTextField.getText();
|
||||
String description = descriptionTextArea.getText();
|
||||
|
||||
return new Arbitrator(pubKeyAsHex,
|
||||
messagePubKeyAsHex,
|
||||
name,
|
||||
idType,
|
||||
languageList,
|
||||
new Reputation(),
|
||||
maxTradeVolume,
|
||||
passiveServiceFee,
|
||||
minPassiveServiceFee,
|
||||
arbitrationFee,
|
||||
minArbitrationFee,
|
||||
methodList,
|
||||
idVerificationList,
|
||||
webUrl,
|
||||
description);
|
||||
} catch (BitSquareValidator.ValidationException e) {
|
||||
return null;
|
||||
}
|
||||
return new Arbitrator(pubKeyAsHex,
|
||||
messagePubKeyAsHex,
|
||||
name,
|
||||
idType,
|
||||
languageList,
|
||||
new Reputation(),
|
||||
maxTradeVolume,
|
||||
passiveServiceFee,
|
||||
minPassiveServiceFee,
|
||||
arbitrationFee,
|
||||
minArbitrationFee,
|
||||
methodList,
|
||||
idVerificationList,
|
||||
webUrl,
|
||||
description);
|
||||
}
|
||||
|
||||
private void close() {
|
||||
|
@ -56,8 +56,7 @@ public class TransactionsListItem {
|
||||
Coin valueSentFromMe = transaction.getValueSentFromMe(walletFacade.getWallet());
|
||||
Address address = null;
|
||||
if (valueSentToMe.isZero()) {
|
||||
//TODO use BSFormatter
|
||||
amount.set("-" + valueSentFromMe.toFriendlyString());
|
||||
amount.set("-" + BSFormatter.formatCoin(valueSentFromMe));
|
||||
|
||||
for (TransactionOutput transactionOutput : transaction.getOutputs()) {
|
||||
if (!transactionOutput.isMine(walletFacade.getWallet())) {
|
||||
@ -76,8 +75,7 @@ public class TransactionsListItem {
|
||||
}
|
||||
}
|
||||
else if (valueSentFromMe.isZero()) {
|
||||
//TODO use BSFormatter
|
||||
amount.set(valueSentToMe.toFriendlyString());
|
||||
amount.set(BSFormatter.formatCoin(valueSentToMe));
|
||||
type.set("Received with");
|
||||
|
||||
for (TransactionOutput transactionOutput : transaction.getOutputs()) {
|
||||
@ -95,9 +93,7 @@ public class TransactionsListItem {
|
||||
}
|
||||
}
|
||||
else {
|
||||
//TODO use BSFormatter
|
||||
amount.set(valueSentToMe.subtract(valueSentFromMe).toFriendlyString());
|
||||
|
||||
amount.set(BSFormatter.formatCoin(valueSentToMe.subtract(valueSentFromMe)));
|
||||
boolean outgoing = false;
|
||||
for (TransactionOutput transactionOutput : transaction.getOutputs()) {
|
||||
if (!transactionOutput.isMine(walletFacade.getWallet())) {
|
||||
|
@ -24,7 +24,6 @@ import io.bitsquare.btc.WalletFacade;
|
||||
import io.bitsquare.gui.CachedViewController;
|
||||
import io.bitsquare.gui.components.Popups;
|
||||
import io.bitsquare.gui.util.BSFormatter;
|
||||
import io.bitsquare.gui.util.BitSquareValidator;
|
||||
|
||||
import com.google.bitcoin.core.AddressFormatException;
|
||||
import com.google.bitcoin.core.Coin;
|
||||
@ -113,8 +112,6 @@ public class WithdrawalController extends CachedViewController {
|
||||
|
||||
tableView.getSelectionModel().selectedItemProperty().addListener((observableValue, oldValue, newValue) -> {
|
||||
if (newValue != null) {
|
||||
BitSquareValidator.resetTextFields(
|
||||
withdrawFromTextField, withdrawToTextField, amountTextField, changeAddressTextField);
|
||||
|
||||
if (Coin.ZERO.compareTo(newValue.getBalance()) <= 0) {
|
||||
amountTextField.setText(newValue.getBalance().toPlainString());
|
||||
@ -145,63 +142,53 @@ public class WithdrawalController extends CachedViewController {
|
||||
|
||||
@FXML
|
||||
public void onWithdraw() {
|
||||
try {
|
||||
BitSquareValidator.textFieldsNotEmpty(
|
||||
amountTextField, withdrawFromTextField, withdrawToTextField, changeAddressTextField);
|
||||
BitSquareValidator.textFieldsHasDoubleValueWithReset(amountTextField);
|
||||
|
||||
Coin amount = BSFormatter.parseToCoin(amountTextField.getText());
|
||||
if (Restrictions.isMinSpendableAmount(amount)) {
|
||||
FutureCallback<Transaction> callback = new FutureCallback<Transaction>() {
|
||||
@Override
|
||||
public void onSuccess(@javax.annotation.Nullable Transaction transaction) {
|
||||
BitSquareValidator.resetTextFields(
|
||||
withdrawFromTextField, withdrawToTextField, amountTextField, changeAddressTextField);
|
||||
if (transaction != null) {
|
||||
log.info("onWithdraw onSuccess tx ID:" + transaction.getHashAsString());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NotNull Throwable t) {
|
||||
log.debug("onWithdraw onFailure");
|
||||
}
|
||||
};
|
||||
|
||||
Action response = Popups.openConfirmPopup(
|
||||
"Withdrawal request", "Confirm your request",
|
||||
"Your withdrawal request:\n\n" + "Amount: " + amountTextField.getText() + " BTC\n" + "Sending" +
|
||||
" address: " + withdrawFromTextField.getText() + "\n" + "Receiving address: " +
|
||||
withdrawToTextField.getText() + "\n" + "Transaction fee: " +
|
||||
BSFormatter.formatCoinWithCode(FeePolicy.TX_FEE) + "\n" +
|
||||
"You receive in total: " +
|
||||
BSFormatter.formatCoinWithCode(amount.subtract(FeePolicy.TX_FEE)) + " BTC\n\n" +
|
||||
"Are you sure you withdraw that amount?");
|
||||
if (response == Dialog.Actions.OK) {
|
||||
try {
|
||||
walletFacade.sendFunds(
|
||||
withdrawFromTextField.getText(), withdrawToTextField.getText(),
|
||||
changeAddressTextField.getText(), amount, callback);
|
||||
} catch (AddressFormatException e) {
|
||||
Popups.openErrorPopup("Address invalid",
|
||||
"The address is not correct. Please check the address format.");
|
||||
|
||||
} catch (InsufficientMoneyException e) {
|
||||
Popups.openInsufficientMoneyPopup();
|
||||
} catch (IllegalArgumentException e) {
|
||||
Popups.openErrorPopup("Wrong inputs", "Please check the inputs.");
|
||||
Coin amount = BSFormatter.parseToCoin(amountTextField.getText());
|
||||
if (Restrictions.isMinSpendableAmount(amount)) {
|
||||
FutureCallback<Transaction> callback = new FutureCallback<Transaction>() {
|
||||
@Override
|
||||
public void onSuccess(@javax.annotation.Nullable Transaction transaction) {
|
||||
if (transaction != null) {
|
||||
log.info("onWithdraw onSuccess tx ID:" + transaction.getHashAsString());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
Popups.openErrorPopup("Insufficient amount",
|
||||
"The amount to transfer is lower the the transaction fee and the min. possible tx value.");
|
||||
@Override
|
||||
public void onFailure(@NotNull Throwable t) {
|
||||
log.debug("onWithdraw onFailure");
|
||||
}
|
||||
};
|
||||
|
||||
Action response = Popups.openConfirmPopup(
|
||||
"Withdrawal request", "Confirm your request",
|
||||
"Your withdrawal request:\n\n" + "Amount: " + amountTextField.getText() + " BTC\n" + "Sending" +
|
||||
" address: " + withdrawFromTextField.getText() + "\n" + "Receiving address: " +
|
||||
withdrawToTextField.getText() + "\n" + "Transaction fee: " +
|
||||
BSFormatter.formatCoinWithCode(FeePolicy.TX_FEE) + "\n" +
|
||||
"You receive in total: " +
|
||||
BSFormatter.formatCoinWithCode(amount.subtract(FeePolicy.TX_FEE)) + " BTC\n\n" +
|
||||
"Are you sure you withdraw that amount?");
|
||||
if (response == Dialog.Actions.OK) {
|
||||
try {
|
||||
walletFacade.sendFunds(
|
||||
withdrawFromTextField.getText(), withdrawToTextField.getText(),
|
||||
changeAddressTextField.getText(), amount, callback);
|
||||
} catch (AddressFormatException e) {
|
||||
Popups.openErrorPopup("Address invalid",
|
||||
"The address is not correct. Please check the address format.");
|
||||
|
||||
} catch (InsufficientMoneyException e) {
|
||||
Popups.openInsufficientMoneyPopup();
|
||||
} catch (IllegalArgumentException e) {
|
||||
Popups.openErrorPopup("Wrong inputs", "Please check the inputs.");
|
||||
}
|
||||
}
|
||||
|
||||
} catch (BitSquareValidator.ValidationException e) {
|
||||
log.trace(e.toString());
|
||||
}
|
||||
else {
|
||||
Popups.openErrorPopup("Insufficient amount",
|
||||
"The amount to transfer is lower the the transaction fee and the min. possible tx value.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -22,6 +22,7 @@ import io.bitsquare.btc.WalletFacade;
|
||||
import io.bitsquare.btc.listeners.AddressConfidenceListener;
|
||||
import io.bitsquare.btc.listeners.BalanceListener;
|
||||
import io.bitsquare.gui.components.confidence.ConfidenceProgressIndicator;
|
||||
import io.bitsquare.gui.util.BSFormatter;
|
||||
|
||||
import com.google.bitcoin.core.Address;
|
||||
import com.google.bitcoin.core.Coin;
|
||||
@ -93,8 +94,7 @@ public class WithdrawalListItem {
|
||||
private void updateBalance(Coin balance) {
|
||||
this.balance = balance;
|
||||
if (balance != null) {
|
||||
//TODO use BSFormatter
|
||||
balanceLabel.setText(balance.toFriendlyString());
|
||||
balanceLabel.setText(BSFormatter.formatCoin(balance));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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.util.BSFormatterTest;
|
||||
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.FiatValidatorTest;
|
||||
import io.bitsquare.msg.P2PNodeTest;
|
||||
@ -33,7 +32,6 @@ import org.junit.runners.Suite;
|
||||
@Suite.SuiteClasses({
|
||||
RestrictionsTest.class,
|
||||
BitSquareConverterTest.class,
|
||||
BitSquareNumberValidatorTest.class,
|
||||
P2PNodeTest.class,
|
||||
FiatValidatorTest.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…
x
Reference in New Issue
Block a user