mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-03-15 10:26:37 -04:00
Remove static methods from BSFormatter
This commit is contained in:
parent
19e71ffad2
commit
1130da6a8f
@ -12,7 +12,6 @@ public class PresentationModel<T extends UIModel> {
|
||||
this.model = model;
|
||||
}
|
||||
|
||||
// TODO Still open question if we enforce a model or not? For small UIs it might be too much overhead.
|
||||
public PresentationModel() {
|
||||
}
|
||||
|
||||
|
@ -44,6 +44,7 @@ public class BalanceTextField extends AnchorPane {
|
||||
|
||||
private final Effect fundedEffect = new DropShadow(BlurType.THREE_PASS_BOX, Color.GREEN, 4, 0.0, 0, 0);
|
||||
private final Effect notFundedEffect = new DropShadow(BlurType.THREE_PASS_BOX, Color.ORANGERED, 4, 0.0, 0, 0);
|
||||
private BSFormatter formatter;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -73,7 +74,8 @@ public class BalanceTextField extends AnchorPane {
|
||||
getChildren().addAll(balanceTextField, progressIndicator);
|
||||
}
|
||||
|
||||
public void setup(WalletFacade walletFacade, Address address) {
|
||||
public void setup(WalletFacade walletFacade, Address address, BSFormatter formatter) {
|
||||
this.formatter = formatter;
|
||||
walletFacade.addAddressConfidenceListener(new AddressConfidenceListener(address) {
|
||||
@Override
|
||||
public void onTransactionConfidenceChanged(TransactionConfidence confidence) {
|
||||
@ -127,7 +129,7 @@ public class BalanceTextField extends AnchorPane {
|
||||
}
|
||||
|
||||
private void updateBalance(Coin balance) {
|
||||
balanceTextField.setText(BSFormatter.formatCoinWithCode(balance));
|
||||
balanceTextField.setText(formatter.formatCoinWithCode(balance));
|
||||
if (balance.isPositive())
|
||||
balanceTextField.setEffect(fundedEffect);
|
||||
else
|
||||
|
@ -47,6 +47,7 @@ class MainPM extends PresentationModel<MainModel> {
|
||||
final StringProperty splashScreenInfoText = new SimpleStringProperty();
|
||||
final BooleanProperty networkSyncComplete = new SimpleBooleanProperty();
|
||||
final IntegerProperty numPendingTrades = new SimpleIntegerProperty();
|
||||
private BSFormatter formatter;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -54,8 +55,9 @@ class MainPM extends PresentationModel<MainModel> {
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@Inject
|
||||
private MainPM(MainModel model) {
|
||||
private MainPM(MainModel model, BSFormatter formatter) {
|
||||
super(model);
|
||||
this.formatter = formatter;
|
||||
}
|
||||
|
||||
|
||||
@ -74,7 +76,7 @@ class MainPM extends PresentationModel<MainModel> {
|
||||
|
||||
model.networkSyncProgress.addListener((ov, oldValue, newValue) -> {
|
||||
if ((double) newValue > 0)
|
||||
splashScreenInfoText.set("Synchronise with network " + BSFormatter.formatToPercent((double) newValue));
|
||||
splashScreenInfoText.set("Synchronise with network " + formatter.formatToPercent((double) newValue));
|
||||
else if ((double) newValue == 1)
|
||||
splashScreenInfoText.set("Synchronise with network completed.");
|
||||
else
|
||||
@ -82,7 +84,7 @@ class MainPM extends PresentationModel<MainModel> {
|
||||
|
||||
});
|
||||
|
||||
model.balance.addListener((ov, oldValue, newValue) -> balance.set(BSFormatter.formatCoinWithCode
|
||||
model.balance.addListener((ov, oldValue, newValue) -> balance.set(formatter.formatCoinWithCode
|
||||
(newValue)));
|
||||
|
||||
model.getBankAccounts().addListener((ListChangeListener<BankAccount>) change -> {
|
||||
|
@ -19,6 +19,7 @@ package io.bitsquare.gui.main.account.content.registration;
|
||||
|
||||
import io.bitsquare.btc.WalletFacade;
|
||||
import io.bitsquare.gui.PresentationModel;
|
||||
import io.bitsquare.gui.util.BSFormatter;
|
||||
import io.bitsquare.locale.BSResources;
|
||||
|
||||
import com.google.bitcoin.core.Address;
|
||||
@ -36,7 +37,6 @@ import javafx.beans.property.StringProperty;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import static io.bitsquare.gui.util.BSFormatter.formatCoinWithCode;
|
||||
|
||||
class RegistrationPM extends PresentationModel<RegistrationModel> {
|
||||
private static final Logger log = LoggerFactory.getLogger(RegistrationPM.class);
|
||||
@ -47,6 +47,7 @@ class RegistrationPM extends PresentationModel<RegistrationModel> {
|
||||
|
||||
// That is needed for the addressTextField
|
||||
final ObjectProperty<Address> address = new SimpleObjectProperty<>();
|
||||
private BSFormatter formatter;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -54,8 +55,9 @@ class RegistrationPM extends PresentationModel<RegistrationModel> {
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@Inject
|
||||
private RegistrationPM(RegistrationModel model) {
|
||||
private RegistrationPM(RegistrationModel model, BSFormatter formatter) {
|
||||
super(model);
|
||||
this.formatter = formatter;
|
||||
}
|
||||
|
||||
|
||||
@ -124,6 +126,10 @@ class RegistrationPM extends PresentationModel<RegistrationModel> {
|
||||
return model.getWalletFacade();
|
||||
}
|
||||
|
||||
BSFormatter getFormatter() {
|
||||
return formatter;
|
||||
}
|
||||
|
||||
Coin getFeeAsCoin() {
|
||||
return model.getFeeAsCoin();
|
||||
}
|
||||
@ -137,7 +143,7 @@ class RegistrationPM extends PresentationModel<RegistrationModel> {
|
||||
}
|
||||
|
||||
String getFeeAsString() {
|
||||
return formatCoinWithCode(model.getFeeAsCoin());
|
||||
return formatter.formatCoinWithCode(model.getFeeAsCoin());
|
||||
}
|
||||
|
||||
String getTransactionId() {
|
||||
@ -153,4 +159,5 @@ class RegistrationPM extends PresentationModel<RegistrationModel> {
|
||||
isPayButtonDisabled.set(!(model.isWalletFunded.get()));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -88,7 +88,8 @@ public class RegistrationViewCB extends CachedViewCB<RegistrationPM> implements
|
||||
// TODO find better solution
|
||||
addressTextField.setOverlayManager(overlayManager);
|
||||
|
||||
balanceTextField.setup(presentationModel.getWalletFacade(), presentationModel.address.get());
|
||||
balanceTextField.setup(presentationModel.getWalletFacade(), presentationModel.address.get(),
|
||||
presentationModel.getFormatter());
|
||||
|
||||
payButton.disableProperty().bind(presentationModel.isPayButtonDisabled);
|
||||
|
||||
|
@ -32,6 +32,7 @@ class SeedWordsPM extends PresentationModel<SeedWordsModel> {
|
||||
private static final Logger log = LoggerFactory.getLogger(SeedWordsPM.class);
|
||||
|
||||
final StringProperty seedWords = new SimpleStringProperty();
|
||||
private BSFormatter formatter;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -39,8 +40,9 @@ class SeedWordsPM extends PresentationModel<SeedWordsModel> {
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@Inject
|
||||
private SeedWordsPM(SeedWordsModel model) {
|
||||
private SeedWordsPM(SeedWordsModel model, BSFormatter formatter) {
|
||||
super(model);
|
||||
this.formatter = formatter;
|
||||
}
|
||||
|
||||
|
||||
@ -54,7 +56,7 @@ class SeedWordsPM extends PresentationModel<SeedWordsModel> {
|
||||
super.initialize();
|
||||
|
||||
if (model.getMnemonicCode() != null)
|
||||
seedWords.set(BSFormatter.mnemonicCodeToString(model.getMnemonicCode()));
|
||||
seedWords.set(formatter.mnemonicCodeToString(model.getMnemonicCode()));
|
||||
}
|
||||
|
||||
@SuppressWarnings("EmptyMethod")
|
||||
|
@ -40,6 +40,7 @@ public class ArbitratorProfileController extends CachedViewController {
|
||||
private final Settings settings;
|
||||
|
||||
private final Persistence persistence;
|
||||
private BSFormatter formatter;
|
||||
private Arbitrator arbitrator;
|
||||
|
||||
|
||||
@ -55,12 +56,13 @@ public class ArbitratorProfileController extends CachedViewController {
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@Inject
|
||||
public ArbitratorProfileController(Settings settings, Persistence persistence) {
|
||||
public ArbitratorProfileController(Settings settings, Persistence persistence, BSFormatter formatter) {
|
||||
this.settings = settings;
|
||||
this.persistence = persistence;
|
||||
|
||||
// Settings persistedSettings = (Settings) storage.read(settings.getClass().getName());
|
||||
// settings.applyPersistedSettings(persistedSettings);
|
||||
this.formatter = formatter;
|
||||
}
|
||||
|
||||
|
||||
@ -125,16 +127,16 @@ public class ArbitratorProfileController extends CachedViewController {
|
||||
nameLabel.setText(name);
|
||||
|
||||
nameTextField.setText(arbitrator.getName());
|
||||
languagesTextField.setText(BSFormatter.languageLocalesToString(arbitrator.getLanguages()));
|
||||
languagesTextField.setText(formatter.languageLocalesToString(arbitrator.getLanguages()));
|
||||
reputationTextField.setText(arbitrator.getReputation().toString());
|
||||
maxTradeVolumeTextField.setText(String.valueOf(arbitrator.getMaxTradeVolume()) + " BTC");
|
||||
passiveServiceFeeTextField.setText(String.valueOf(arbitrator.getPassiveServiceFee()) + " % (Min. " +
|
||||
String.valueOf(arbitrator.getMinPassiveServiceFee()) + " BTC)");
|
||||
arbitrationFeeTextField.setText(String.valueOf(arbitrator.getArbitrationFee()) + " % (Min. " + String
|
||||
.valueOf(arbitrator.getMinArbitrationFee()) + " BTC)");
|
||||
methodsTextField.setText(BSFormatter.arbitrationMethodsToString(arbitrator.getArbitrationMethods()));
|
||||
methodsTextField.setText(formatter.arbitrationMethodsToString(arbitrator.getArbitrationMethods()));
|
||||
idVerificationsTextField.setText(
|
||||
BSFormatter.arbitrationIDVerificationsToString(arbitrator.getIdVerifications()));
|
||||
formatter.arbitrationIDVerificationsToString(arbitrator.getIdVerifications()));
|
||||
webPageTextField.setText(arbitrator.getWebUrl());
|
||||
descriptionTextArea.setText(arbitrator.getDescription());
|
||||
}
|
||||
|
@ -71,6 +71,7 @@ public class ArbitratorRegistrationController extends CachedViewController {
|
||||
private final WalletFacade walletFacade;
|
||||
private final MessageFacade messageFacade;
|
||||
private final User user;
|
||||
private BSFormatter formatter;
|
||||
private Arbitrator arbitrator = new Arbitrator();
|
||||
private ArbitratorProfileController arbitratorProfileController;
|
||||
private boolean isEditMode;
|
||||
@ -104,11 +105,12 @@ public class ArbitratorRegistrationController extends CachedViewController {
|
||||
|
||||
@Inject
|
||||
private ArbitratorRegistrationController(Persistence persistence, WalletFacade walletFacade,
|
||||
MessageFacade messageFacade, User user) {
|
||||
MessageFacade messageFacade, User user, BSFormatter formatter) {
|
||||
this.persistence = persistence;
|
||||
this.walletFacade = walletFacade;
|
||||
this.messageFacade = messageFacade;
|
||||
this.user = user;
|
||||
this.formatter = formatter;
|
||||
}
|
||||
|
||||
|
||||
@ -129,7 +131,7 @@ public class ArbitratorRegistrationController extends CachedViewController {
|
||||
}
|
||||
else {
|
||||
languageList.add(LanguageUtil.getDefaultLanguageLocale());
|
||||
languagesTextField.setText(BSFormatter.languageLocalesToString(languageList));
|
||||
languagesTextField.setText(formatter.languageLocalesToString(languageList));
|
||||
}
|
||||
|
||||
languageComboBox.setItems(FXCollections.observableArrayList(LanguageUtil.getAllLanguageLocales()));
|
||||
@ -274,7 +276,7 @@ public class ArbitratorRegistrationController extends CachedViewController {
|
||||
Locale item = languageComboBox.getSelectionModel().getSelectedItem();
|
||||
if (!languageList.contains(item) && item != null) {
|
||||
languageList.add(item);
|
||||
languagesTextField.setText(BSFormatter.languageLocalesToString(languageList));
|
||||
languagesTextField.setText(formatter.languageLocalesToString(languageList));
|
||||
languageComboBox.getSelectionModel().clearSelection();
|
||||
}
|
||||
}
|
||||
@ -290,7 +292,7 @@ public class ArbitratorRegistrationController extends CachedViewController {
|
||||
Arbitrator.METHOD item = methodsComboBox.getSelectionModel().getSelectedItem();
|
||||
if (!methodList.contains(item) && item != null) {
|
||||
methodList.add(item);
|
||||
methodsTextField.setText(BSFormatter.arbitrationMethodsToString(methodList));
|
||||
methodsTextField.setText(formatter.arbitrationMethodsToString(methodList));
|
||||
methodsComboBox.getSelectionModel().clearSelection();
|
||||
}
|
||||
}
|
||||
@ -309,7 +311,7 @@ public class ArbitratorRegistrationController extends CachedViewController {
|
||||
if (!idVerificationList.contains(idVerification)) {
|
||||
idVerificationList.add(idVerification);
|
||||
idVerificationsTextField.setText(
|
||||
BSFormatter.arbitrationIDVerificationsToString(idVerificationList));
|
||||
formatter.arbitrationIDVerificationsToString(idVerificationList));
|
||||
}
|
||||
}
|
||||
|
||||
@ -429,15 +431,15 @@ public class ArbitratorRegistrationController extends CachedViewController {
|
||||
|
||||
nameTextField.setText(arbitrator.getName());
|
||||
idTypeTextField.setText(BSResources.get(arbitrator.getIdType().toString()));
|
||||
languagesTextField.setText(BSFormatter.languageLocalesToString(arbitrator.getLanguages()));
|
||||
languagesTextField.setText(formatter.languageLocalesToString(arbitrator.getLanguages()));
|
||||
maxTradeVolumeTextField.setText(String.valueOf(arbitrator.getMaxTradeVolume()));
|
||||
passiveServiceFeeTextField.setText(String.valueOf(arbitrator.getPassiveServiceFee()));
|
||||
minPassiveServiceFeeTextField.setText(String.valueOf(arbitrator.getMinPassiveServiceFee()));
|
||||
arbitrationFeeTextField.setText(String.valueOf(arbitrator.getArbitrationFee()));
|
||||
minArbitrationFeeTextField.setText(String.valueOf(arbitrator.getMinArbitrationFee()));
|
||||
methodsTextField.setText(BSFormatter.arbitrationMethodsToString(arbitrator.getArbitrationMethods()));
|
||||
methodsTextField.setText(formatter.arbitrationMethodsToString(arbitrator.getArbitrationMethods()));
|
||||
idVerificationsTextField.setText(
|
||||
BSFormatter.arbitrationIDVerificationsToString(arbitrator.getIdVerifications()));
|
||||
formatter.arbitrationIDVerificationsToString(arbitrator.getIdVerifications()));
|
||||
webPageTextField.setText(arbitrator.getWebUrl());
|
||||
descriptionTextArea.setText(arbitrator.getDescription());
|
||||
|
||||
@ -454,11 +456,11 @@ public class ArbitratorRegistrationController extends CachedViewController {
|
||||
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 = formatter.parseToDouble(maxTradeVolumeTextField.getText());
|
||||
double passiveServiceFee = formatter.parseToDouble(passiveServiceFeeTextField.getText());
|
||||
double minPassiveServiceFee = formatter.parseToDouble(minPassiveServiceFeeTextField.getText());
|
||||
double arbitrationFee = formatter.parseToDouble(arbitrationFeeTextField.getText());
|
||||
double minArbitrationFee = formatter.parseToDouble(minArbitrationFeeTextField.getText());
|
||||
|
||||
String webUrl = webPageTextField.getText();
|
||||
String description = descriptionTextArea.getText();
|
||||
|
@ -19,6 +19,7 @@ package io.bitsquare.gui.main.funds.transactions;
|
||||
|
||||
import io.bitsquare.btc.WalletFacade;
|
||||
import io.bitsquare.gui.CachedViewController;
|
||||
import io.bitsquare.gui.util.BSFormatter;
|
||||
|
||||
import com.google.bitcoin.core.Transaction;
|
||||
|
||||
@ -44,6 +45,7 @@ public class TransactionsController extends CachedViewController {
|
||||
private static final Logger log = LoggerFactory.getLogger(TransactionsController.class);
|
||||
|
||||
private final WalletFacade walletFacade;
|
||||
private BSFormatter formatter;
|
||||
private ObservableList<TransactionsListItem> transactionsListItems;
|
||||
|
||||
@FXML TableView<TransactionsListItem> tableView;
|
||||
@ -56,8 +58,9 @@ public class TransactionsController extends CachedViewController {
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@Inject
|
||||
private TransactionsController(WalletFacade walletFacade) {
|
||||
private TransactionsController(WalletFacade walletFacade, BSFormatter formatter) {
|
||||
this.walletFacade = walletFacade;
|
||||
this.formatter = formatter;
|
||||
}
|
||||
|
||||
|
||||
@ -90,7 +93,7 @@ public class TransactionsController extends CachedViewController {
|
||||
List<Transaction> transactions = walletFacade.getWallet().getRecentTransactions(10000, true);
|
||||
transactionsListItems = FXCollections.observableArrayList();
|
||||
transactionsListItems.addAll(transactions.stream().map(transaction ->
|
||||
new TransactionsListItem(transaction, walletFacade)).collect(Collectors.toList()));
|
||||
new TransactionsListItem(transaction, walletFacade, formatter)).collect(Collectors.toList()));
|
||||
|
||||
tableView.setItems(transactionsListItems);
|
||||
}
|
||||
|
@ -49,14 +49,14 @@ public class TransactionsListItem {
|
||||
private String addressString;
|
||||
private AddressConfidenceListener confidenceListener;
|
||||
|
||||
public TransactionsListItem(Transaction transaction, WalletFacade walletFacade) {
|
||||
public TransactionsListItem(Transaction transaction, WalletFacade walletFacade, BSFormatter formatter) {
|
||||
this.walletFacade = walletFacade;
|
||||
|
||||
Coin valueSentToMe = transaction.getValueSentToMe(walletFacade.getWallet());
|
||||
Coin valueSentFromMe = transaction.getValueSentFromMe(walletFacade.getWallet());
|
||||
Address address = null;
|
||||
if (valueSentToMe.isZero()) {
|
||||
amount.set("-" + BSFormatter.formatCoin(valueSentFromMe));
|
||||
amount.set("-" + formatter.formatCoin(valueSentFromMe));
|
||||
|
||||
for (TransactionOutput transactionOutput : transaction.getOutputs()) {
|
||||
if (!transactionOutput.isMine(walletFacade.getWallet())) {
|
||||
@ -75,7 +75,7 @@ public class TransactionsListItem {
|
||||
}
|
||||
}
|
||||
else if (valueSentFromMe.isZero()) {
|
||||
amount.set(BSFormatter.formatCoin(valueSentToMe));
|
||||
amount.set(formatter.formatCoin(valueSentToMe));
|
||||
type.set("Received with");
|
||||
|
||||
for (TransactionOutput transactionOutput : transaction.getOutputs()) {
|
||||
@ -93,7 +93,7 @@ public class TransactionsListItem {
|
||||
}
|
||||
}
|
||||
else {
|
||||
amount.set(BSFormatter.formatCoin(valueSentToMe.subtract(valueSentFromMe)));
|
||||
amount.set(formatter.formatCoin(valueSentToMe.subtract(valueSentFromMe)));
|
||||
boolean outgoing = false;
|
||||
for (TransactionOutput transactionOutput : transaction.getOutputs()) {
|
||||
if (!transactionOutput.isMine(walletFacade.getWallet())) {
|
||||
@ -119,7 +119,7 @@ public class TransactionsListItem {
|
||||
}
|
||||
}
|
||||
|
||||
date.set(BSFormatter.formatDateTime(transaction.getUpdateTime()));
|
||||
date.set(formatter.formatDateTime(transaction.getUpdateTime()));
|
||||
|
||||
// confidence
|
||||
progressIndicator = new ConfidenceProgressIndicator();
|
||||
|
@ -64,6 +64,7 @@ public class WithdrawalController extends CachedViewController {
|
||||
|
||||
|
||||
private final WalletFacade walletFacade;
|
||||
private BSFormatter formatter;
|
||||
private ObservableList<WithdrawalListItem> addressList;
|
||||
|
||||
@FXML TableView<WithdrawalListItem> tableView;
|
||||
@ -78,8 +79,9 @@ public class WithdrawalController extends CachedViewController {
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@Inject
|
||||
private WithdrawalController(WalletFacade walletFacade) {
|
||||
private WithdrawalController(WalletFacade walletFacade, BSFormatter formatter) {
|
||||
this.walletFacade = walletFacade;
|
||||
this.formatter = formatter;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -130,7 +132,7 @@ public class WithdrawalController extends CachedViewController {
|
||||
List<AddressEntry> addressEntryList = walletFacade.getAddressEntryList();
|
||||
addressList = FXCollections.observableArrayList();
|
||||
addressList.addAll(addressEntryList.stream().map(anAddressEntryList ->
|
||||
new WithdrawalListItem(anAddressEntryList, walletFacade)).collect(Collectors.toList()));
|
||||
new WithdrawalListItem(anAddressEntryList, walletFacade, formatter)).collect(Collectors.toList()));
|
||||
|
||||
tableView.setItems(addressList);
|
||||
}
|
||||
@ -142,7 +144,7 @@ public class WithdrawalController extends CachedViewController {
|
||||
|
||||
@FXML
|
||||
public void onWithdraw() {
|
||||
Coin amount = BSFormatter.parseToCoin(amountTextField.getText());
|
||||
Coin amount = formatter.parseToCoin(amountTextField.getText());
|
||||
if (Restrictions.isMinSpendableAmount(amount)) {
|
||||
FutureCallback<Transaction> callback = new FutureCallback<Transaction>() {
|
||||
@Override
|
||||
@ -163,9 +165,9 @@ public class WithdrawalController extends CachedViewController {
|
||||
"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" +
|
||||
formatter.formatCoinWithCode(FeePolicy.TX_FEE) + "\n" +
|
||||
"You receive in total: " +
|
||||
BSFormatter.formatCoinWithCode(amount.subtract(FeePolicy.TX_FEE)) + " BTC\n\n" +
|
||||
formatter.formatCoinWithCode(amount.subtract(FeePolicy.TX_FEE)) + " BTC\n\n" +
|
||||
"Are you sure you withdraw that amount?");
|
||||
if (response == Dialog.Actions.OK) {
|
||||
try {
|
||||
|
@ -43,6 +43,7 @@ public class WithdrawalListItem {
|
||||
private final AddressEntry addressEntry;
|
||||
|
||||
private final WalletFacade walletFacade;
|
||||
private BSFormatter formatter;
|
||||
private final AddressConfidenceListener confidenceListener;
|
||||
|
||||
private final ConfidenceProgressIndicator progressIndicator;
|
||||
@ -51,9 +52,10 @@ public class WithdrawalListItem {
|
||||
|
||||
private Coin balance;
|
||||
|
||||
public WithdrawalListItem(AddressEntry addressEntry, WalletFacade walletFacade) {
|
||||
public WithdrawalListItem(AddressEntry addressEntry, WalletFacade walletFacade, BSFormatter formatter) {
|
||||
this.addressEntry = addressEntry;
|
||||
this.walletFacade = walletFacade;
|
||||
this.formatter = formatter;
|
||||
this.addressString.set(getAddress().toString());
|
||||
|
||||
// confidence
|
||||
@ -94,7 +96,7 @@ public class WithdrawalListItem {
|
||||
private void updateBalance(Coin balance) {
|
||||
this.balance = balance;
|
||||
if (balance != null) {
|
||||
balanceLabel.setText(BSFormatter.formatCoin(balance));
|
||||
balanceLabel.setText(formatter.formatCoin(balance));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -84,19 +84,19 @@ class ClosedTradesPM extends PresentationModel<ClosedTradesModel> {
|
||||
}
|
||||
|
||||
String getAmount(ClosedTradesListItem item) {
|
||||
return (item != null) ? BSFormatter.formatAmountWithMinAmount(item.getTrade().getOffer()) : "";
|
||||
return (item != null) ? formatter.formatAmountWithMinAmount(item.getTrade().getOffer()) : "";
|
||||
}
|
||||
|
||||
String getPrice(ClosedTradesListItem item) {
|
||||
return (item != null) ? BSFormatter.formatFiat(item.getTrade().getOffer().getPrice()) : "";
|
||||
return (item != null) ? formatter.formatFiat(item.getTrade().getOffer().getPrice()) : "";
|
||||
}
|
||||
|
||||
String getVolume(ClosedTradesListItem item) {
|
||||
return (item != null) ? BSFormatter.formatVolumeWithMinVolume(item.getTrade().getOffer()) : "";
|
||||
return (item != null) ? formatter.formatVolumeWithMinVolume(item.getTrade().getOffer()) : "";
|
||||
}
|
||||
|
||||
String getDirectionLabel(ClosedTradesListItem item) {
|
||||
return (item != null) ? BSFormatter.formatDirection(item.getTrade().getOffer().getMirroredDirection()) : "";
|
||||
return (item != null) ? formatter.formatDirection(item.getTrade().getOffer().getMirroredDirection()) : "";
|
||||
}
|
||||
|
||||
String getDate(ClosedTradesListItem item) {
|
||||
|
@ -93,19 +93,19 @@ class OffersPM extends PresentationModel<OffersModel> {
|
||||
}
|
||||
|
||||
String getAmount(OfferListItem item) {
|
||||
return (item != null) ? BSFormatter.formatAmountWithMinAmount(item.getOffer()) : "";
|
||||
return (item != null) ? formatter.formatAmountWithMinAmount(item.getOffer()) : "";
|
||||
}
|
||||
|
||||
String getPrice(OfferListItem item) {
|
||||
return (item != null) ? BSFormatter.formatFiat(item.getOffer().getPrice()) : "";
|
||||
return (item != null) ? formatter.formatFiat(item.getOffer().getPrice()) : "";
|
||||
}
|
||||
|
||||
String getVolume(OfferListItem item) {
|
||||
return (item != null) ? BSFormatter.formatVolumeWithMinVolume(item.getOffer()) : "";
|
||||
return (item != null) ? formatter.formatVolumeWithMinVolume(item.getOffer()) : "";
|
||||
}
|
||||
|
||||
String getDirectionLabel(OfferListItem item) {
|
||||
return (item != null) ? BSFormatter.formatDirection(item.getOffer().getMirroredDirection()) : "";
|
||||
return (item != null) ? formatter.formatDirection(item.getOffer().getMirroredDirection()) : "";
|
||||
}
|
||||
|
||||
String getDate(OfferListItem item) {
|
||||
|
@ -154,19 +154,19 @@ public class PendingTradesPM extends PresentationModel<PendingTradesModel> {
|
||||
}
|
||||
|
||||
String getAmount(PendingTradesListItem item) {
|
||||
return (item != null) ? BSFormatter.formatAmountWithMinAmount(item.getTrade().getOffer()) : "";
|
||||
return (item != null) ? formatter.formatAmountWithMinAmount(item.getTrade().getOffer()) : "";
|
||||
}
|
||||
|
||||
String getPrice(PendingTradesListItem item) {
|
||||
return (item != null) ? BSFormatter.formatFiat(item.getTrade().getOffer().getPrice()) : "";
|
||||
return (item != null) ? formatter.formatFiat(item.getTrade().getOffer().getPrice()) : "";
|
||||
}
|
||||
|
||||
String getVolume(PendingTradesListItem item) {
|
||||
return (item != null) ? BSFormatter.formatVolumeWithMinVolume(item.getTrade().getOffer()) : "";
|
||||
return (item != null) ? formatter.formatVolumeWithMinVolume(item.getTrade().getOffer()) : "";
|
||||
}
|
||||
|
||||
String getDirectionLabel(PendingTradesListItem item) {
|
||||
return (item != null) ? BSFormatter.formatDirection(item.getTrade().getOffer().getMirroredDirection()) : "";
|
||||
return (item != null) ? formatter.formatDirection(item.getTrade().getOffer().getMirroredDirection()) : "";
|
||||
}
|
||||
|
||||
String getDate(PendingTradesListItem item) {
|
||||
|
@ -24,6 +24,7 @@ import io.bitsquare.btc.FeePolicy;
|
||||
import io.bitsquare.btc.WalletFacade;
|
||||
import io.bitsquare.btc.listeners.BalanceListener;
|
||||
import io.bitsquare.gui.UIModel;
|
||||
import io.bitsquare.gui.util.BSFormatter;
|
||||
import io.bitsquare.locale.Country;
|
||||
import io.bitsquare.settings.Settings;
|
||||
import io.bitsquare.trade.Direction;
|
||||
@ -57,7 +58,6 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static io.bitsquare.gui.util.BSFormatter.reduceTo4Decimals;
|
||||
|
||||
/**
|
||||
* Domain for that UI element.
|
||||
@ -71,6 +71,7 @@ class CreateOfferModel extends UIModel {
|
||||
private final WalletFacade walletFacade;
|
||||
private final Settings settings;
|
||||
private final User user;
|
||||
private BSFormatter formatter;
|
||||
|
||||
private final String offerId;
|
||||
|
||||
@ -111,11 +112,13 @@ class CreateOfferModel extends UIModel {
|
||||
|
||||
// non private for testing
|
||||
@Inject
|
||||
public CreateOfferModel(TradeManager tradeManager, WalletFacade walletFacade, Settings settings, User user) {
|
||||
public CreateOfferModel(TradeManager tradeManager, WalletFacade walletFacade, Settings settings, User user,
|
||||
BSFormatter formatter) {
|
||||
this.tradeManager = tradeManager;
|
||||
this.walletFacade = walletFacade;
|
||||
this.settings = settings;
|
||||
this.user = user;
|
||||
this.formatter = formatter;
|
||||
|
||||
offerId = UUID.randomUUID().toString();
|
||||
}
|
||||
@ -228,7 +231,8 @@ class CreateOfferModel extends UIModel {
|
||||
!volumeAsFiat.get().isZero() &&
|
||||
!priceAsFiat.get().isZero()) {
|
||||
// If we got a btc value with more then 4 decimals we convert it to max 4 decimals
|
||||
amountAsCoin.set(reduceTo4Decimals(new ExchangeRate(priceAsFiat.get()).fiatToCoin(volumeAsFiat.get())));
|
||||
amountAsCoin.set(formatter.reduceTo4Decimals(new ExchangeRate(priceAsFiat.get()).fiatToCoin
|
||||
(volumeAsFiat.get())));
|
||||
|
||||
calculateTotalToPay();
|
||||
calculateCollateral();
|
||||
|
@ -44,13 +44,13 @@ import javafx.beans.property.StringProperty;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import static io.bitsquare.gui.util.BSFormatter.*;
|
||||
import static javafx.beans.binding.Bindings.createStringBinding;
|
||||
|
||||
class CreateOfferPM extends PresentationModel<CreateOfferModel> {
|
||||
private static final Logger log = LoggerFactory.getLogger(CreateOfferPM.class);
|
||||
|
||||
private final BtcValidator btcValidator;
|
||||
private BSFormatter formatter;
|
||||
private final FiatValidator fiatValidator;
|
||||
|
||||
final StringProperty amount = new SimpleStringProperty();
|
||||
@ -100,11 +100,13 @@ class CreateOfferPM extends PresentationModel<CreateOfferModel> {
|
||||
|
||||
// non private for testing
|
||||
@Inject
|
||||
CreateOfferPM(CreateOfferModel model, FiatValidator fiatValidator, BtcValidator btcValidator) {
|
||||
CreateOfferPM(CreateOfferModel model, FiatValidator fiatValidator, BtcValidator btcValidator,
|
||||
BSFormatter formatter) {
|
||||
super(model);
|
||||
|
||||
this.fiatValidator = fiatValidator;
|
||||
this.btcValidator = btcValidator;
|
||||
this.formatter = formatter;
|
||||
}
|
||||
|
||||
|
||||
@ -169,7 +171,7 @@ class CreateOfferPM extends PresentationModel<CreateOfferModel> {
|
||||
// apply only if valid
|
||||
boolean priceValid = false;
|
||||
if (price != null && isBtcInputValid(price.toPlainString()).isValid) {
|
||||
model.priceAsFiat.set(parseToFiatWith2Decimals(price.toPlainString()));
|
||||
model.priceAsFiat.set(formatter.parseToFiatWith2Decimals(price.toPlainString()));
|
||||
priceValid = true;
|
||||
}
|
||||
|
||||
@ -206,11 +208,11 @@ class CreateOfferPM extends PresentationModel<CreateOfferModel> {
|
||||
InputValidator.ValidationResult result = isBtcInputValid(amount.get());
|
||||
amountValidationResult.set(result);
|
||||
if (result.isValid) {
|
||||
showWarningInvalidBtcDecimalPlaces.set(!hasBtcValidDecimals(userInput));
|
||||
showWarningInvalidBtcDecimalPlaces.set(!formatter.hasBtcValidDecimals(userInput));
|
||||
// only allow max 4 decimal places for btc values
|
||||
setAmountToModel();
|
||||
// reformat input
|
||||
amount.set(formatCoin(model.amountAsCoin.get()));
|
||||
amount.set(formatter.formatCoin(model.amountAsCoin.get()));
|
||||
|
||||
calculateVolume();
|
||||
|
||||
@ -233,9 +235,9 @@ class CreateOfferPM extends PresentationModel<CreateOfferModel> {
|
||||
InputValidator.ValidationResult result = isBtcInputValid(minAmount.get());
|
||||
minAmountValidationResult.set(result);
|
||||
if (result.isValid) {
|
||||
showWarningInvalidBtcDecimalPlaces.set(!hasBtcValidDecimals(userInput));
|
||||
showWarningInvalidBtcDecimalPlaces.set(!formatter.hasBtcValidDecimals(userInput));
|
||||
setMinAmountToModel();
|
||||
minAmount.set(formatCoin(model.minAmountAsCoin.get()));
|
||||
minAmount.set(formatter.formatCoin(model.minAmountAsCoin.get()));
|
||||
|
||||
if (!model.isMinAmountLessOrEqualAmount()) {
|
||||
minAmountValidationResult.set(new InputValidator.ValidationResult(false,
|
||||
@ -256,9 +258,9 @@ class CreateOfferPM extends PresentationModel<CreateOfferModel> {
|
||||
boolean isValid = result.isValid;
|
||||
priceValidationResult.set(result);
|
||||
if (isValid) {
|
||||
showWarningInvalidFiatDecimalPlaces.set(!hasFiatValidDecimals(userInput));
|
||||
showWarningInvalidFiatDecimalPlaces.set(!formatter.hasFiatValidDecimals(userInput));
|
||||
setPriceToModel();
|
||||
price.set(formatFiat(model.priceAsFiat.get()));
|
||||
price.set(formatter.formatFiat(model.priceAsFiat.get()));
|
||||
|
||||
calculateVolume();
|
||||
}
|
||||
@ -270,16 +272,17 @@ class CreateOfferPM extends PresentationModel<CreateOfferModel> {
|
||||
InputValidator.ValidationResult result = isBtcInputValid(volume.get());
|
||||
volumeValidationResult.set(result);
|
||||
if (result.isValid) {
|
||||
showWarningInvalidFiatDecimalPlaces.set(!hasFiatValidDecimals(userInput));
|
||||
showWarningInvalidFiatDecimalPlaces.set(!formatter.hasFiatValidDecimals(userInput));
|
||||
setVolumeToModel();
|
||||
volume.set(formatFiat(model.volumeAsFiat.get()));
|
||||
volume.set(formatter.formatFiat(model.volumeAsFiat.get()));
|
||||
|
||||
calculateAmount();
|
||||
|
||||
// must be placed after calculateAmount (btc value has been adjusted in case the calculation leads to
|
||||
// invalid decimal places for the amount value
|
||||
showWarningAdjustedVolume.set(!formatFiat(parseToFiatWith2Decimals(userInput)).equals(volume
|
||||
.get()));
|
||||
showWarningAdjustedVolume.set(!formatter.formatFiat(formatter.parseToFiatWith2Decimals(userInput))
|
||||
.equals(volume
|
||||
.get()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -293,6 +296,9 @@ class CreateOfferPM extends PresentationModel<CreateOfferModel> {
|
||||
return model.getWalletFacade();
|
||||
}
|
||||
|
||||
BSFormatter getFormatter() {
|
||||
return formatter;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Private
|
||||
@ -342,10 +348,10 @@ class CreateOfferPM extends PresentationModel<CreateOfferModel> {
|
||||
});
|
||||
|
||||
// Binding with Bindings.createObjectBinding does not work because of bi-directional binding
|
||||
model.amountAsCoin.addListener((ov, oldValue, newValue) -> amount.set(formatCoin(newValue)));
|
||||
model.minAmountAsCoin.addListener((ov, oldValue, newValue) -> minAmount.set(formatCoin(newValue)));
|
||||
model.priceAsFiat.addListener((ov, oldValue, newValue) -> price.set(formatFiat(newValue)));
|
||||
model.volumeAsFiat.addListener((ov, oldValue, newValue) -> volume.set(formatFiat(newValue)));
|
||||
model.amountAsCoin.addListener((ov, oldValue, newValue) -> amount.set(formatter.formatCoin(newValue)));
|
||||
model.minAmountAsCoin.addListener((ov, oldValue, newValue) -> minAmount.set(formatter.formatCoin(newValue)));
|
||||
model.priceAsFiat.addListener((ov, oldValue, newValue) -> price.set(formatter.formatFiat(newValue)));
|
||||
model.volumeAsFiat.addListener((ov, oldValue, newValue) -> volume.set(formatter.formatFiat(newValue)));
|
||||
|
||||
model.requestPlaceOfferErrorMessage.addListener((ov, oldValue, newValue) -> {
|
||||
if (newValue != null)
|
||||
@ -355,29 +361,29 @@ class CreateOfferPM extends PresentationModel<CreateOfferModel> {
|
||||
(!newValue));
|
||||
|
||||
// ObservableLists
|
||||
model.acceptedCountries.addListener((Observable o) -> acceptedCountries.set(BSFormatter
|
||||
model.acceptedCountries.addListener((Observable o) -> acceptedCountries.set(formatter
|
||||
.countryLocalesToString(model.acceptedCountries)));
|
||||
model.acceptedLanguages.addListener((Observable o) -> acceptedLanguages.set(BSFormatter
|
||||
model.acceptedLanguages.addListener((Observable o) -> acceptedLanguages.set(formatter
|
||||
.languageLocalesToString(model.acceptedLanguages)));
|
||||
model.acceptedArbitrators.addListener((Observable o) -> acceptedArbitrators.set(BSFormatter
|
||||
model.acceptedArbitrators.addListener((Observable o) -> acceptedArbitrators.set(formatter
|
||||
.arbitratorsToString(model.acceptedArbitrators)));
|
||||
}
|
||||
|
||||
private void setupBindings() {
|
||||
totalToPay.bind(createStringBinding(() -> formatCoinWithCode(model.totalToPayAsCoin.get()),
|
||||
totalToPay.bind(createStringBinding(() -> formatter.formatCoinWithCode(model.totalToPayAsCoin.get()),
|
||||
model.totalToPayAsCoin));
|
||||
collateral.bind(createStringBinding(() -> formatCoinWithCode(model.collateralAsCoin.get()),
|
||||
collateral.bind(createStringBinding(() -> formatter.formatCoinWithCode(model.collateralAsCoin.get()),
|
||||
model.collateralAsCoin));
|
||||
|
||||
collateralLabel.bind(Bindings.createStringBinding(() ->
|
||||
BSResources.get("createOffer.fundsBox.collateral",
|
||||
BSFormatter.formatCollateralPercent(model.collateralAsLong.get())),
|
||||
formatter.formatCollateralPercent(model.collateralAsLong.get())),
|
||||
model.collateralAsLong));
|
||||
totalToPayAsCoin.bind(model.totalToPayAsCoin);
|
||||
|
||||
offerFee.bind(createStringBinding(() -> formatCoinWithCode(model.offerFeeAsCoin.get()),
|
||||
offerFee.bind(createStringBinding(() -> formatter.formatCoinWithCode(model.offerFeeAsCoin.get()),
|
||||
model.offerFeeAsCoin));
|
||||
networkFee.bind(createStringBinding(() -> formatCoinWithCode(model.networkFeeAsCoin.get()),
|
||||
networkFee.bind(createStringBinding(() -> formatter.formatCoinWithCode(model.networkFeeAsCoin.get()),
|
||||
model.offerFeeAsCoin));
|
||||
|
||||
bankAccountType.bind(Bindings.createStringBinding(() -> BSResources.get(model.bankAccountType.get()),
|
||||
@ -418,19 +424,19 @@ class CreateOfferPM extends PresentationModel<CreateOfferModel> {
|
||||
}
|
||||
|
||||
private void setAmountToModel() {
|
||||
model.amountAsCoin.set(parseToCoinWith4Decimals(amount.get()));
|
||||
model.amountAsCoin.set(formatter.parseToCoinWith4Decimals(amount.get()));
|
||||
}
|
||||
|
||||
private void setMinAmountToModel() {
|
||||
model.minAmountAsCoin.set(parseToCoinWith4Decimals(minAmount.get()));
|
||||
model.minAmountAsCoin.set(formatter.parseToCoinWith4Decimals(minAmount.get()));
|
||||
}
|
||||
|
||||
private void setPriceToModel() {
|
||||
model.priceAsFiat.set(parseToFiatWith2Decimals(price.get()));
|
||||
model.priceAsFiat.set(formatter.parseToFiatWith2Decimals(price.get()));
|
||||
}
|
||||
|
||||
private void setVolumeToModel() {
|
||||
model.volumeAsFiat.set(parseToFiatWith2Decimals(volume.get()));
|
||||
model.volumeAsFiat.set(formatter.parseToFiatWith2Decimals(volume.get()));
|
||||
}
|
||||
|
||||
private void updateButtonDisableState() {
|
||||
|
@ -131,7 +131,8 @@ public class CreateOfferViewCB extends CachedViewCB<CreateOfferPM> {
|
||||
|
||||
setupListeners();
|
||||
setupBindings();
|
||||
balanceTextField.setup(presentationModel.getWalletFacade(), presentationModel.address.get());
|
||||
balanceTextField.setup(presentationModel.getWalletFacade(), presentationModel.address.get(),
|
||||
presentationModel.getFormatter());
|
||||
volumeTextField.setPromptText(BSResources.get("createOffer.volume.prompt", presentationModel.fiatCode.get()));
|
||||
}
|
||||
|
||||
|
@ -47,7 +47,6 @@ import javafx.collections.transformation.SortedList;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import static io.bitsquare.gui.util.BSFormatter.reduceTo4Decimals;
|
||||
|
||||
/**
|
||||
* It holds the scope specific domain data for either a buy or sell UI screen.
|
||||
@ -58,6 +57,7 @@ class OrderBookModel extends UIModel {
|
||||
private final User user;
|
||||
private final OrderBook orderBook;
|
||||
private final Settings settings;
|
||||
private BSFormatter formatter;
|
||||
private final TradeManager tradeManager;
|
||||
|
||||
private final FilteredList<OrderBookListItem> filteredItems;
|
||||
@ -85,11 +85,13 @@ class OrderBookModel extends UIModel {
|
||||
OrderBookModel(User user,
|
||||
TradeManager tradeManager,
|
||||
OrderBook orderBook,
|
||||
Settings settings) {
|
||||
Settings settings,
|
||||
BSFormatter formatter) {
|
||||
this.tradeManager = tradeManager;
|
||||
this.user = user;
|
||||
this.orderBook = orderBook;
|
||||
this.settings = settings;
|
||||
this.formatter = formatter;
|
||||
|
||||
filteredItems = new FilteredList<>(orderBook.getOrderBookListItems());
|
||||
sortedItems = new SortedList<>(filteredItems);
|
||||
@ -164,7 +166,8 @@ class OrderBookModel extends UIModel {
|
||||
!volumeAsFiat.get().isZero() &&
|
||||
!priceAsFiat.get().isZero()) {
|
||||
// If we got a btc value with more then 4 decimals we convert it to max 4 decimals
|
||||
amountAsCoin.set(reduceTo4Decimals(new ExchangeRate(priceAsFiat.get()).fiatToCoin(volumeAsFiat.get())));
|
||||
amountAsCoin.set(formatter.reduceTo4Decimals(new ExchangeRate(priceAsFiat.get()).fiatToCoin
|
||||
(volumeAsFiat.get())));
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
// Should be never reached
|
||||
@ -180,7 +183,7 @@ class OrderBookModel extends UIModel {
|
||||
boolean countryResult = offer.getAcceptedCountries().contains(user.getCurrentBankAccount().getCountry());
|
||||
if (!countryResult)
|
||||
restrictionsInfo.set("This offer requires that the payments account resides in one of those countries:\n" +
|
||||
BSFormatter.countryLocalesToString(offer.getAcceptedCountries()) +
|
||||
formatter.countryLocalesToString(offer.getAcceptedCountries()) +
|
||||
"\n\nThe country of your payments account (" + user.getCurrentBankAccount().getCountry().getName() +
|
||||
") is not included in that list.");
|
||||
|
||||
|
@ -38,12 +38,11 @@ import javafx.collections.transformation.SortedList;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import static io.bitsquare.gui.util.BSFormatter.*;
|
||||
|
||||
class OrderBookPM extends PresentationModel<OrderBookModel> {
|
||||
private static final Logger log = LoggerFactory.getLogger(OrderBookPM.class);
|
||||
|
||||
private final OptionalBtcValidator optionalBtcValidator;
|
||||
private BSFormatter formatter;
|
||||
private final OptionalFiatValidator optionalFiatValidator;
|
||||
|
||||
final StringProperty amount = new SimpleStringProperty();
|
||||
@ -61,11 +60,13 @@ class OrderBookPM extends PresentationModel<OrderBookModel> {
|
||||
@Inject
|
||||
OrderBookPM(OrderBookModel model,
|
||||
OptionalFiatValidator optionalFiatValidator,
|
||||
OptionalBtcValidator optionalBtcValidator) {
|
||||
OptionalBtcValidator optionalBtcValidator,
|
||||
BSFormatter formatter) {
|
||||
super(model);
|
||||
|
||||
this.optionalFiatValidator = optionalFiatValidator;
|
||||
this.optionalBtcValidator = optionalBtcValidator;
|
||||
this.formatter = formatter;
|
||||
}
|
||||
|
||||
|
||||
@ -108,9 +109,11 @@ class OrderBookPM extends PresentationModel<OrderBookModel> {
|
||||
});
|
||||
|
||||
// Binding with Bindings.createObjectBinding does not work because of bi-directional binding
|
||||
model.amountAsCoinProperty().addListener((ov, oldValue, newValue) -> amount.set(formatCoin(newValue)));
|
||||
model.priceAsFiatProperty().addListener((ov, oldValue, newValue) -> price.set(formatFiat(newValue)));
|
||||
model.volumeAsFiatProperty().addListener((ov, oldValue, newValue) -> volume.set(formatFiat(newValue)));
|
||||
model.amountAsCoinProperty().addListener((ov, oldValue, newValue) -> amount.set(formatter.formatCoin
|
||||
(newValue)));
|
||||
model.priceAsFiatProperty().addListener((ov, oldValue, newValue) -> price.set(formatter.formatFiat(newValue)));
|
||||
model.volumeAsFiatProperty().addListener((ov, oldValue, newValue) -> volume.set(formatter.formatFiat
|
||||
(newValue)));
|
||||
}
|
||||
|
||||
@SuppressWarnings("EmptyMethod")
|
||||
@ -183,17 +186,17 @@ class OrderBookPM extends PresentationModel<OrderBookModel> {
|
||||
}
|
||||
|
||||
String getAmount(OrderBookListItem item) {
|
||||
return (item != null) ? BSFormatter.formatCoin(item.getOffer().getAmount()) +
|
||||
" (" + BSFormatter.formatCoin(item.getOffer().getMinAmount()) + ")" : "";
|
||||
return (item != null) ? formatter.formatCoin(item.getOffer().getAmount()) +
|
||||
" (" + formatter.formatCoin(item.getOffer().getMinAmount()) + ")" : "";
|
||||
}
|
||||
|
||||
String getPrice(OrderBookListItem item) {
|
||||
return (item != null) ? BSFormatter.formatFiat(item.getOffer().getPrice()) : "";
|
||||
return (item != null) ? formatter.formatFiat(item.getOffer().getPrice()) : "";
|
||||
}
|
||||
|
||||
String getVolume(OrderBookListItem item) {
|
||||
return (item != null) ? BSFormatter.formatFiat(item.getOffer().getOfferVolume()) +
|
||||
" (" + BSFormatter.formatFiat(item.getOffer().getMinOfferVolume()) + ")" : "";
|
||||
return (item != null) ? formatter.formatFiat(item.getOffer().getOfferVolume()) +
|
||||
" (" + formatter.formatFiat(item.getOffer().getMinOfferVolume()) + ")" : "";
|
||||
}
|
||||
|
||||
String getBankAccountType(OrderBookListItem item) {
|
||||
@ -201,7 +204,7 @@ class OrderBookPM extends PresentationModel<OrderBookModel> {
|
||||
}
|
||||
|
||||
String getDirectionLabel(Offer offer) {
|
||||
return BSFormatter.formatDirection(offer.getMirroredDirection());
|
||||
return formatter.formatDirection(offer.getMirroredDirection());
|
||||
}
|
||||
|
||||
Direction getDirection() {
|
||||
@ -229,15 +232,15 @@ class OrderBookPM extends PresentationModel<OrderBookModel> {
|
||||
}
|
||||
|
||||
private void setAmountToModel() {
|
||||
model.setAmount(parseToCoinWith4Decimals(amount.get()));
|
||||
model.setAmount(formatter.parseToCoinWith4Decimals(amount.get()));
|
||||
}
|
||||
|
||||
private void setPriceToModel() {
|
||||
model.setPrice(parseToFiatWith2Decimals(price.get()));
|
||||
model.setPrice(formatter.parseToFiatWith2Decimals(price.get()));
|
||||
}
|
||||
|
||||
private void setVolumeToModel() {
|
||||
model.setVolume(parseToFiatWith2Decimals(volume.get()));
|
||||
model.setVolume(formatter.parseToFiatWith2Decimals(volume.get()));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -41,7 +41,6 @@ import javafx.beans.property.StringProperty;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import static io.bitsquare.gui.util.BSFormatter.*;
|
||||
import static javafx.beans.binding.Bindings.createStringBinding;
|
||||
|
||||
class TakeOfferPM extends PresentationModel<TakeOfferModel> {
|
||||
@ -67,6 +66,7 @@ class TakeOfferPM extends PresentationModel<TakeOfferModel> {
|
||||
final ObjectProperty<Address> address = new SimpleObjectProperty<>();
|
||||
|
||||
private final BtcValidator btcValidator;
|
||||
private BSFormatter formatter;
|
||||
|
||||
final StringProperty amount = new SimpleStringProperty();
|
||||
final StringProperty volume = new SimpleStringProperty();
|
||||
@ -94,10 +94,11 @@ class TakeOfferPM extends PresentationModel<TakeOfferModel> {
|
||||
|
||||
// non private for testing
|
||||
@Inject
|
||||
TakeOfferPM(TakeOfferModel model, BtcValidator btcValidator) {
|
||||
TakeOfferPM(TakeOfferModel model, BtcValidator btcValidator, BSFormatter formatter) {
|
||||
super(model);
|
||||
|
||||
this.btcValidator = btcValidator;
|
||||
this.formatter = formatter;
|
||||
}
|
||||
|
||||
|
||||
@ -110,8 +111,8 @@ class TakeOfferPM extends PresentationModel<TakeOfferModel> {
|
||||
super.initialize();
|
||||
|
||||
// static
|
||||
offerFee = formatCoinWithCode(model.offerFeeAsCoin.get());
|
||||
networkFee = formatCoinWithCode(model.networkFeeAsCoin.get());
|
||||
offerFee = formatter.formatCoinWithCode(model.offerFeeAsCoin.get());
|
||||
networkFee = formatter.formatCoinWithCode(model.networkFeeAsCoin.get());
|
||||
|
||||
setupBindings();
|
||||
setupListeners();
|
||||
@ -157,9 +158,9 @@ class TakeOfferPM extends PresentationModel<TakeOfferModel> {
|
||||
|
||||
//model.volumeAsFiat.set(offer.getVolumeByAmount(model.amountAsCoin.get()));
|
||||
|
||||
amountRange = BSFormatter.formatCoinWithCode(offer.getMinAmount()) + " - " +
|
||||
BSFormatter.formatCoinWithCode(offer.getAmount());
|
||||
price = BSFormatter.formatFiatWithCode(offer.getPrice());
|
||||
amountRange = formatter.formatCoinWithCode(offer.getMinAmount()) + " - " +
|
||||
formatter.formatCoinWithCode(offer.getAmount());
|
||||
price = formatter.formatFiatWithCode(offer.getPrice());
|
||||
|
||||
paymentLabel = BSResources.get("takeOffer.fundsBox.paymentLabel", offer.getId());
|
||||
if (model.getAddressEntry() != null) {
|
||||
@ -167,11 +168,11 @@ class TakeOfferPM extends PresentationModel<TakeOfferModel> {
|
||||
address.set(model.getAddressEntry().getAddress());
|
||||
}
|
||||
collateralLabel = BSResources.get("takeOffer.fundsBox.collateral",
|
||||
BSFormatter.formatCollateralPercent(offer.getCollateral()));
|
||||
formatter.formatCollateralPercent(offer.getCollateral()));
|
||||
|
||||
acceptedCountries = BSFormatter.countryLocalesToString(offer.getAcceptedCountries());
|
||||
acceptedLanguages = BSFormatter.languageLocalesToString(offer.getAcceptedLanguageLocales());
|
||||
acceptedArbitrators = BSFormatter.arbitratorsToString(offer.getArbitrators());
|
||||
acceptedCountries = formatter.countryLocalesToString(offer.getAcceptedCountries());
|
||||
acceptedLanguages = formatter.languageLocalesToString(offer.getAcceptedLanguageLocales());
|
||||
acceptedArbitrators = formatter.arbitratorsToString(offer.getArbitrators());
|
||||
bankAccountType = BSResources.get(offer.getBankAccountType().toString());
|
||||
bankAccountCurrency = BSResources.get(offer.getCurrency().getDisplayName());
|
||||
bankAccountCounty = BSResources.get(offer.getBankAccountCountry().getName());
|
||||
@ -206,11 +207,11 @@ class TakeOfferPM extends PresentationModel<TakeOfferModel> {
|
||||
InputValidator.ValidationResult result = isBtcInputValid(amount.get());
|
||||
amountValidationResult.set(result);
|
||||
if (result.isValid) {
|
||||
showWarningInvalidBtcDecimalPlaces.set(!hasBtcValidDecimals(userInput));
|
||||
showWarningInvalidBtcDecimalPlaces.set(!formatter.hasBtcValidDecimals(userInput));
|
||||
// only allow max 4 decimal places for btc values
|
||||
setAmountToModel();
|
||||
// reformat input
|
||||
amount.set(formatCoin(model.amountAsCoin.get()));
|
||||
amount.set(formatter.formatCoin(model.amountAsCoin.get()));
|
||||
|
||||
calculateVolume();
|
||||
|
||||
@ -234,6 +235,10 @@ class TakeOfferPM extends PresentationModel<TakeOfferModel> {
|
||||
return model.getWalletFacade();
|
||||
}
|
||||
|
||||
BSFormatter getFormatter() {
|
||||
return formatter;
|
||||
}
|
||||
|
||||
String getOfferFee() {
|
||||
return offerFee;
|
||||
}
|
||||
@ -318,7 +323,7 @@ class TakeOfferPM extends PresentationModel<TakeOfferModel> {
|
||||
});
|
||||
|
||||
// Binding with Bindings.createObjectBinding does not work because of bi-directional binding
|
||||
model.amountAsCoin.addListener((ov, oldValue, newValue) -> amount.set(formatCoin(newValue)));
|
||||
model.amountAsCoin.addListener((ov, oldValue, newValue) -> amount.set(formatter.formatCoin(newValue)));
|
||||
|
||||
model.requestTakeOfferErrorMessage.addListener((ov, oldValue, newValue) -> {
|
||||
if (newValue != null)
|
||||
@ -329,10 +334,11 @@ class TakeOfferPM extends PresentationModel<TakeOfferModel> {
|
||||
}
|
||||
|
||||
private void setupBindings() {
|
||||
volume.bind(createStringBinding(() -> formatFiatWithCode(model.volumeAsFiat.get()), model.volumeAsFiat));
|
||||
totalToPay.bind(createStringBinding(() -> formatCoinWithCode(model.totalToPayAsCoin.get()),
|
||||
volume.bind(createStringBinding(() -> formatter.formatFiatWithCode(model.volumeAsFiat.get()),
|
||||
model.volumeAsFiat));
|
||||
totalToPay.bind(createStringBinding(() -> formatter.formatCoinWithCode(model.totalToPayAsCoin.get()),
|
||||
model.totalToPayAsCoin));
|
||||
collateral.bind(createStringBinding(() -> formatCoinWithCode(model.collateralAsCoin.get()),
|
||||
collateral.bind(createStringBinding(() -> formatter.formatCoinWithCode(model.collateralAsCoin.get()),
|
||||
model.collateralAsCoin));
|
||||
|
||||
totalToPayAsCoin.bind(model.totalToPayAsCoin);
|
||||
@ -350,7 +356,7 @@ class TakeOfferPM extends PresentationModel<TakeOfferModel> {
|
||||
}
|
||||
|
||||
private void setAmountToModel() {
|
||||
model.amountAsCoin.set(parseToCoinWith4Decimals(amount.get()));
|
||||
model.amountAsCoin.set(formatter.parseToCoinWith4Decimals(amount.get()));
|
||||
}
|
||||
|
||||
private void updateButtonDisableState() {
|
||||
@ -364,4 +370,5 @@ class TakeOfferPM extends PresentationModel<TakeOfferModel> {
|
||||
private InputValidator.ValidationResult isBtcInputValid(String input) {
|
||||
return btcValidator.validate(input);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -168,7 +168,8 @@ public class TakeOfferViewCB extends CachedViewCB<TakeOfferPM> {
|
||||
volumeDescriptionLabel.setText(BSResources.get("takeOffer.amountPriceBox.volumeDescription",
|
||||
presentationModel.getFiatCode()));
|
||||
|
||||
balanceTextField.setup(presentationModel.getWalletFacade(), presentationModel.address.get());
|
||||
balanceTextField.setup(presentationModel.getWalletFacade(), presentationModel.address.get(),
|
||||
presentationModel.getFormatter());
|
||||
|
||||
buyLabel.setText(presentationModel.getDirectionLabel());
|
||||
amountRangeTextField.setText(presentationModel.getAmountRange());
|
||||
|
@ -57,9 +57,9 @@ import static com.google.common.base.Preconditions.*;
|
||||
public class BSFormatter {
|
||||
private static final Logger log = LoggerFactory.getLogger(BSFormatter.class);
|
||||
|
||||
private static Locale locale = Locale.getDefault();
|
||||
private static boolean useMilliBit;
|
||||
private static int scale = 3;
|
||||
private Locale locale = Locale.getDefault();
|
||||
private boolean useMilliBit;
|
||||
private int scale = 3;
|
||||
|
||||
// Format use 2 min decimal places and 2 more optional: 1.00 or 1.0010
|
||||
// There are not more then 4 decimals allowed.
|
||||
@ -68,12 +68,12 @@ public class BSFormatter {
|
||||
// Input of a group separator (1,123,45) lead to an validation error.
|
||||
// Note: BtcFormat was intended to be used, but it lead to many problems (automatic format to mBit,
|
||||
// no way to remove grouping separator). It seems to be not optimal for user input formatting.
|
||||
private static CoinFormat coinFormat = CoinFormat.BTC.repeatOptionalDecimals(2, 1);
|
||||
private CoinFormat coinFormat = CoinFormat.BTC.repeatOptionalDecimals(2, 1);
|
||||
|
||||
private static String currencyCode = Currency.getInstance(Locale.getDefault()).getCurrencyCode();
|
||||
private String currencyCode = Currency.getInstance(Locale.getDefault()).getCurrencyCode();
|
||||
|
||||
// format is like: 1,00 never more then 2 decimals
|
||||
private static final CoinFormat fiatFormat = CoinFormat.FIAT.repeatOptionalDecimals(0, 0).code(0, currencyCode);
|
||||
private final CoinFormat fiatFormat = CoinFormat.FIAT.repeatOptionalDecimals(0, 0).code(0, currencyCode);
|
||||
|
||||
|
||||
@Inject
|
||||
@ -95,8 +95,8 @@ public class BSFormatter {
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
public static void useMilliBitFormat(boolean useMilliBit) {
|
||||
BSFormatter.useMilliBit = useMilliBit;
|
||||
public void useMilliBitFormat(boolean useMilliBit) {
|
||||
this.useMilliBit = useMilliBit;
|
||||
coinFormat = getCoinFormat();
|
||||
scale = useMilliBit ? 0 : 3;
|
||||
}
|
||||
@ -104,19 +104,19 @@ public class BSFormatter {
|
||||
/**
|
||||
* Note that setting the locale does not set the currency as it might be independent.
|
||||
*/
|
||||
public static void setLocale(Locale locale) {
|
||||
BSFormatter.locale = locale;
|
||||
public void setLocale(Locale locale) {
|
||||
this.locale = locale;
|
||||
}
|
||||
|
||||
private static CoinFormat getCoinFormat() {
|
||||
private CoinFormat getCoinFormat() {
|
||||
if (useMilliBit)
|
||||
return CoinFormat.MBTC.repeatOptionalDecimals(2, 1);
|
||||
else
|
||||
return CoinFormat.BTC.repeatOptionalDecimals(2, 1);
|
||||
}
|
||||
|
||||
public static void setFiatCurrencyCode(String currencyCode) {
|
||||
BSFormatter.currencyCode = currencyCode;
|
||||
public void setFiatCurrencyCode(String currencyCode) {
|
||||
this.currencyCode = currencyCode;
|
||||
fiatFormat.code(0, currencyCode);
|
||||
}
|
||||
|
||||
@ -125,7 +125,7 @@ public class BSFormatter {
|
||||
// BTC
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public static String formatCoin(Coin coin) {
|
||||
public String formatCoin(Coin coin) {
|
||||
try {
|
||||
return coinFormat.noCode().format(coin).toString();
|
||||
} catch (Throwable t) {
|
||||
@ -134,7 +134,7 @@ public class BSFormatter {
|
||||
}
|
||||
}
|
||||
|
||||
public static String formatCoinWithCode(Coin coin) {
|
||||
public String formatCoinWithCode(Coin coin) {
|
||||
try {
|
||||
// we don't use the code feature from coinFormat as it does automatic switching between mBTC and BTC and
|
||||
// pre and post fixing
|
||||
@ -146,7 +146,7 @@ public class BSFormatter {
|
||||
}
|
||||
|
||||
|
||||
public static Coin parseToCoin(String input) {
|
||||
public Coin parseToCoin(String input) {
|
||||
try {
|
||||
return coinFormat.parse(cleanInput(input));
|
||||
} catch (Throwable t) {
|
||||
@ -163,7 +163,7 @@ public class BSFormatter {
|
||||
* @param input
|
||||
* @return
|
||||
*/
|
||||
public static Coin parseToCoinWith4Decimals(String input) {
|
||||
public Coin parseToCoinWith4Decimals(String input) {
|
||||
try {
|
||||
return Coin.valueOf(new BigDecimal(parseToCoin(cleanInput(input)).value).setScale(-scale - 1,
|
||||
BigDecimal.ROUND_HALF_UP).setScale(scale + 1).toBigInteger().longValue());
|
||||
@ -173,7 +173,7 @@ public class BSFormatter {
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean hasBtcValidDecimals(String input) {
|
||||
public boolean hasBtcValidDecimals(String input) {
|
||||
return parseToCoin(input).equals(parseToCoinWith4Decimals(input));
|
||||
}
|
||||
|
||||
@ -183,7 +183,7 @@ public class BSFormatter {
|
||||
* @param coin The coin which should be transformed
|
||||
* @return The transformed coin
|
||||
*/
|
||||
public static Coin reduceTo4Decimals(Coin coin) {
|
||||
public Coin reduceTo4Decimals(Coin coin) {
|
||||
return parseToCoin(formatCoin(coin));
|
||||
}
|
||||
|
||||
@ -192,7 +192,7 @@ public class BSFormatter {
|
||||
// FIAT
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public static String formatFiat(Fiat fiat) {
|
||||
public String formatFiat(Fiat fiat) {
|
||||
try {
|
||||
return fiatFormat.noCode().format(fiat).toString();
|
||||
} catch (Throwable t) {
|
||||
@ -201,7 +201,7 @@ public class BSFormatter {
|
||||
}
|
||||
}
|
||||
|
||||
public static String formatFiatWithCode(Fiat fiat) {
|
||||
public String formatFiatWithCode(Fiat fiat) {
|
||||
try {
|
||||
return fiatFormat.postfixCode().format(fiat).toString();
|
||||
} catch (Throwable t) {
|
||||
@ -210,7 +210,7 @@ public class BSFormatter {
|
||||
}
|
||||
}
|
||||
|
||||
public static Fiat parseToFiat(String input) {
|
||||
public Fiat parseToFiat(String input) {
|
||||
try {
|
||||
return Fiat.parseFiat(currencyCode, cleanInput(input));
|
||||
} catch (Exception e) {
|
||||
@ -226,7 +226,7 @@ public class BSFormatter {
|
||||
* @param input
|
||||
* @return
|
||||
*/
|
||||
public static Fiat parseToFiatWith2Decimals(String input) {
|
||||
public Fiat parseToFiatWith2Decimals(String input) {
|
||||
try {
|
||||
return parseToFiat(new BigDecimal(cleanInput(input)).setScale(2, BigDecimal.ROUND_HALF_UP).toString());
|
||||
} catch (Throwable t) {
|
||||
@ -236,7 +236,7 @@ public class BSFormatter {
|
||||
|
||||
}
|
||||
|
||||
public static boolean hasFiatValidDecimals(String input) {
|
||||
public boolean hasFiatValidDecimals(String input) {
|
||||
return parseToFiat(input).equals(parseToFiatWith2Decimals(input));
|
||||
}
|
||||
|
||||
@ -251,7 +251,7 @@ public class BSFormatter {
|
||||
* @return Returns a double value. Any invalid value returns Double.NEGATIVE_INFINITY.
|
||||
*/
|
||||
@Deprecated //TODO use Fiat or Btc if possible
|
||||
public static double parseToDouble(String input) {
|
||||
public double parseToDouble(String input) {
|
||||
try {
|
||||
checkNotNull(input);
|
||||
checkArgument(input.length() > 0);
|
||||
@ -262,11 +262,11 @@ public class BSFormatter {
|
||||
}
|
||||
}
|
||||
|
||||
public static String formatDirection(Direction direction) {
|
||||
public String formatDirection(Direction direction) {
|
||||
return formatDirection(direction, true);
|
||||
}
|
||||
|
||||
public static String formatDirection(Direction direction, boolean allUpperCase) {
|
||||
public String formatDirection(Direction direction, boolean allUpperCase) {
|
||||
String result = (direction == Direction.BUY) ? "Buy" : "Sell";
|
||||
if (allUpperCase) {
|
||||
result = result.toUpperCase();
|
||||
@ -274,47 +274,47 @@ public class BSFormatter {
|
||||
return result;
|
||||
}
|
||||
|
||||
public static String formatAmountWithMinAmount(Offer offer) {
|
||||
return formatCoin(offer.getAmount()) + " (" + BSFormatter.formatCoin(offer.getMinAmount()) + ")";
|
||||
public String formatAmountWithMinAmount(Offer offer) {
|
||||
return formatCoin(offer.getAmount()) + " (" + formatCoin(offer.getMinAmount()) + ")";
|
||||
}
|
||||
|
||||
public static String formatVolumeWithMinVolume(Offer offer) {
|
||||
return BSFormatter.formatFiat(offer.getOfferVolume()) +
|
||||
" (" + BSFormatter.formatFiat(offer.getMinOfferVolume()) + ")";
|
||||
public String formatVolumeWithMinVolume(Offer offer) {
|
||||
return formatFiat(offer.getOfferVolume()) +
|
||||
" (" + formatFiat(offer.getMinOfferVolume()) + ")";
|
||||
}
|
||||
|
||||
public static String countryLocalesToString(List<Country> countries) {
|
||||
public String countryLocalesToString(List<Country> countries) {
|
||||
return countries.stream().map(Country::getName).collect(Collectors.joining(", "));
|
||||
}
|
||||
|
||||
public static String arbitratorsToString(List<Arbitrator> arbitrators) {
|
||||
public String arbitratorsToString(List<Arbitrator> arbitrators) {
|
||||
return arbitrators.stream().map(Arbitrator::getName).collect(Collectors.joining(", "));
|
||||
}
|
||||
|
||||
public static String languageLocalesToString(List<Locale> languageLocales) {
|
||||
public String languageLocalesToString(List<Locale> languageLocales) {
|
||||
return languageLocales.stream().map(e -> e.getDisplayLanguage()).collect(Collectors.joining(", "));
|
||||
}
|
||||
|
||||
public static String arbitrationMethodsToString(List<Arbitrator.METHOD> methods) {
|
||||
public String arbitrationMethodsToString(List<Arbitrator.METHOD> methods) {
|
||||
return methods.stream().map(e -> BSResources.get(e.toString())).collect(Collectors.joining(", "));
|
||||
}
|
||||
|
||||
public static String arbitrationIDVerificationsToString(List<Arbitrator.ID_VERIFICATION> items) {
|
||||
public String arbitrationIDVerificationsToString(List<Arbitrator.ID_VERIFICATION> items) {
|
||||
return items.stream().map(e -> BSResources.get(e.toString())).collect(Collectors.joining(", "));
|
||||
}
|
||||
|
||||
public static String mnemonicCodeToString(List<String> mnemonicCode) {
|
||||
public String mnemonicCodeToString(List<String> mnemonicCode) {
|
||||
return mnemonicCode.stream().collect(Collectors.joining(" "));
|
||||
}
|
||||
|
||||
|
||||
public static String formatDateTime(Date date) {
|
||||
public String formatDateTime(Date date) {
|
||||
DateFormat dateFormatter = DateFormat.getDateInstance(DateFormat.DEFAULT, locale);
|
||||
DateFormat timeFormatter = DateFormat.getTimeInstance(DateFormat.DEFAULT, locale);
|
||||
return dateFormatter.format(date) + " " + timeFormatter.format(date);
|
||||
}
|
||||
|
||||
public static String formatCollateralPercent(long collateral) {
|
||||
public String formatCollateralPercent(long collateral) {
|
||||
DecimalFormat decimalFormat = (DecimalFormat) DecimalFormat.getInstance(locale);
|
||||
decimalFormat.setMinimumFractionDigits(1);
|
||||
decimalFormat.setMaximumFractionDigits(1);
|
||||
@ -322,7 +322,7 @@ public class BSFormatter {
|
||||
return decimalFormat.format(collateral / 10) + " %";
|
||||
}
|
||||
|
||||
public static String formatToPercent(double value) {
|
||||
public String formatToPercent(double value) {
|
||||
DecimalFormat decimalFormat = (DecimalFormat) DecimalFormat.getInstance(locale);
|
||||
decimalFormat.setMinimumFractionDigits(1);
|
||||
decimalFormat.setMaximumFractionDigits(1);
|
||||
@ -330,7 +330,7 @@ public class BSFormatter {
|
||||
return decimalFormat.format(value / 100) + " %";
|
||||
}
|
||||
|
||||
private static String cleanInput(String input) {
|
||||
private String cleanInput(String input) {
|
||||
input = input.replace(",", ".");
|
||||
// don't use String.valueOf(Double.parseDouble(input)) as return value as it gives scientific
|
||||
// notation (1.0E-6) which screw up coinFormat.parse
|
||||
|
@ -20,7 +20,6 @@ package io.bitsquare;
|
||||
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.validation.BtcValidatorTest;
|
||||
import io.bitsquare.gui.util.validation.FiatValidatorTest;
|
||||
import io.bitsquare.msg.P2PNodeTest;
|
||||
@ -31,7 +30,6 @@ import org.junit.runners.Suite;
|
||||
@RunWith(Suite.class)
|
||||
@Suite.SuiteClasses({
|
||||
RestrictionsTest.class,
|
||||
BitSquareConverterTest.class,
|
||||
P2PNodeTest.class,
|
||||
FiatValidatorTest.class,
|
||||
RestrictionsTest.class,
|
||||
|
@ -22,6 +22,7 @@ import io.bitsquare.gui.util.BSFormatter;
|
||||
import io.bitsquare.gui.util.validation.BtcValidator;
|
||||
import io.bitsquare.gui.util.validation.FiatValidator;
|
||||
import io.bitsquare.locale.Country;
|
||||
import io.bitsquare.user.User;
|
||||
|
||||
import com.google.bitcoin.core.Coin;
|
||||
import com.google.bitcoin.utils.Fiat;
|
||||
@ -44,12 +45,12 @@ public class CreateOfferPMTest {
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
model = new CreateOfferModel(null, null, null, null);
|
||||
BSFormatter formatter = new BSFormatter(new User());
|
||||
formatter.setLocale(Locale.US);
|
||||
formatter.setFiatCurrencyCode("USD");
|
||||
model = new CreateOfferModel(null, null, null, null, formatter);
|
||||
|
||||
BSFormatter.setLocale(Locale.US);
|
||||
BSFormatter.setFiatCurrencyCode("USD");
|
||||
|
||||
presenter = new CreateOfferPM(model, new FiatValidator(null), new BtcValidator());
|
||||
presenter = new CreateOfferPM(model, new FiatValidator(null), new BtcValidator(), formatter);
|
||||
presenter.initialize();
|
||||
}
|
||||
|
||||
|
@ -17,6 +17,8 @@
|
||||
|
||||
package io.bitsquare.gui.util;
|
||||
|
||||
import io.bitsquare.user.User;
|
||||
|
||||
import com.google.bitcoin.core.Coin;
|
||||
|
||||
import java.util.Locale;
|
||||
@ -26,7 +28,6 @@ import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import static io.bitsquare.gui.util.BSFormatter.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class BSFormatterTest {
|
||||
@ -34,136 +35,143 @@ public class BSFormatterTest {
|
||||
|
||||
@Test
|
||||
public void testParseToBtc() {
|
||||
useMilliBitFormat(false);
|
||||
assertEquals(Coin.ZERO, parseToCoin("0"));
|
||||
assertEquals(Coin.COIN, parseToCoin("1"));
|
||||
assertEquals(Coin.SATOSHI, parseToCoin("0,00000001"));
|
||||
BSFormatter formatter = new BSFormatter(new User());
|
||||
formatter.useMilliBitFormat(false);
|
||||
assertEquals(Coin.ZERO, formatter.parseToCoin("0"));
|
||||
assertEquals(Coin.COIN, formatter.parseToCoin("1"));
|
||||
assertEquals(Coin.SATOSHI, formatter.parseToCoin("0,00000001"));
|
||||
|
||||
assertEquals(Coin.parseCoin("-1"), parseToCoin("-1"));
|
||||
assertEquals(Coin.parseCoin("1.1"), parseToCoin("1,1"));
|
||||
assertEquals(Coin.parseCoin("1.1"), parseToCoin("1.1"));
|
||||
assertEquals(Coin.parseCoin("0"), parseToCoin("1.123,45"));
|
||||
assertEquals(Coin.parseCoin("0"), parseToCoin("1,123.45"));
|
||||
assertEquals(Coin.parseCoin("-1"), formatter.parseToCoin("-1"));
|
||||
assertEquals(Coin.parseCoin("1.1"), formatter.parseToCoin("1,1"));
|
||||
assertEquals(Coin.parseCoin("1.1"), formatter.parseToCoin("1.1"));
|
||||
assertEquals(Coin.parseCoin("0"), formatter.parseToCoin("1.123,45"));
|
||||
assertEquals(Coin.parseCoin("0"), formatter.parseToCoin("1,123.45"));
|
||||
|
||||
assertEquals(Coin.parseCoin("1.1234"), parseToCoinWith4Decimals("1,12342"));
|
||||
assertEquals(Coin.parseCoin("1.1235"), parseToCoinWith4Decimals("1,12345"));
|
||||
assertEquals(Coin.parseCoin("1.1230"), parseToCoinWith4Decimals("1,123"));
|
||||
assertEquals(Coin.parseCoin("1.1234"), formatter.parseToCoinWith4Decimals("1,12342"));
|
||||
assertEquals(Coin.parseCoin("1.1235"), formatter.parseToCoinWith4Decimals("1,12345"));
|
||||
assertEquals(Coin.parseCoin("1.1230"), formatter.parseToCoinWith4Decimals("1,123"));
|
||||
|
||||
// change to mBTC
|
||||
useMilliBitFormat(true);
|
||||
assertEquals(Coin.parseCoin("1"), parseToCoin("1000"));
|
||||
assertEquals(Coin.parseCoin("0.123"), parseToCoin("123"));
|
||||
assertEquals(Coin.parseCoin("0.1234"), parseToCoin("123.4"));
|
||||
assertEquals(Coin.parseCoin("0.12345"), parseToCoin("123.45"));
|
||||
assertEquals(Coin.parseCoin("0.123456"), parseToCoin("123.456"));
|
||||
assertEquals(Coin.parseCoin("0"), parseToCoin("123,456.7"));
|
||||
formatter.useMilliBitFormat(true);
|
||||
assertEquals(Coin.parseCoin("1"), formatter.parseToCoin("1000"));
|
||||
assertEquals(Coin.parseCoin("0.123"), formatter.parseToCoin("123"));
|
||||
assertEquals(Coin.parseCoin("0.1234"), formatter.parseToCoin("123.4"));
|
||||
assertEquals(Coin.parseCoin("0.12345"), formatter.parseToCoin("123.45"));
|
||||
assertEquals(Coin.parseCoin("0.123456"), formatter.parseToCoin("123.456"));
|
||||
assertEquals(Coin.parseCoin("0"), formatter.parseToCoin("123,456.7"));
|
||||
|
||||
assertEquals(Coin.parseCoin("0.001123"), parseToCoinWith4Decimals("1.123"));
|
||||
assertEquals(Coin.parseCoin("0.0011234"), parseToCoinWith4Decimals("1.1234"));
|
||||
assertEquals(Coin.parseCoin("0.0011234"), parseToCoinWith4Decimals("1.12342"));
|
||||
assertEquals(Coin.parseCoin("0.0011235"), parseToCoinWith4Decimals("1.12345"));
|
||||
assertEquals(Coin.parseCoin("0.001123"), formatter.parseToCoinWith4Decimals("1.123"));
|
||||
assertEquals(Coin.parseCoin("0.0011234"), formatter.parseToCoinWith4Decimals("1.1234"));
|
||||
assertEquals(Coin.parseCoin("0.0011234"), formatter.parseToCoinWith4Decimals("1.12342"));
|
||||
assertEquals(Coin.parseCoin("0.0011235"), formatter.parseToCoinWith4Decimals("1.12345"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFormatCoin() {
|
||||
useMilliBitFormat(false);
|
||||
assertEquals("1.00", formatCoin(Coin.COIN));
|
||||
assertEquals("1.0120", formatCoin(Coin.parseCoin("1.012")));
|
||||
assertEquals("1012.30", formatCoin(Coin.parseCoin("1012.3")));
|
||||
assertEquals("1.0120", formatCoin(Coin.parseCoin("1.01200")));
|
||||
assertEquals("1.0123", formatCoin(Coin.parseCoin("1.01234")));
|
||||
BSFormatter formatter = new BSFormatter(new User());
|
||||
formatter.useMilliBitFormat(false);
|
||||
assertEquals("1.00", formatter.formatCoin(Coin.COIN));
|
||||
assertEquals("1.0120", formatter.formatCoin(Coin.parseCoin("1.012")));
|
||||
assertEquals("1012.30", formatter.formatCoin(Coin.parseCoin("1012.3")));
|
||||
assertEquals("1.0120", formatter.formatCoin(Coin.parseCoin("1.01200")));
|
||||
assertEquals("1.0123", formatter.formatCoin(Coin.parseCoin("1.01234")));
|
||||
|
||||
assertEquals("1.2345", formatCoin(Coin.parseCoin("1.2345")));
|
||||
assertEquals("1.2346", formatCoin(Coin.parseCoin("1.23456")));
|
||||
assertEquals("1.2346", formatCoin(Coin.parseCoin("1.234567")));
|
||||
assertEquals("1.2345", formatCoin(Coin.parseCoin("1.23448")));
|
||||
assertEquals("1.2345", formatter.formatCoin(Coin.parseCoin("1.2345")));
|
||||
assertEquals("1.2346", formatter.formatCoin(Coin.parseCoin("1.23456")));
|
||||
assertEquals("1.2346", formatter.formatCoin(Coin.parseCoin("1.234567")));
|
||||
assertEquals("1.2345", formatter.formatCoin(Coin.parseCoin("1.23448")));
|
||||
|
||||
assertEquals("1.00", formatCoin(Coin.COIN));
|
||||
assertEquals("1012.30", formatCoin(Coin.parseCoin("1012.3")));
|
||||
assertEquals("1.00", formatter.formatCoin(Coin.COIN));
|
||||
assertEquals("1012.30", formatter.formatCoin(Coin.parseCoin("1012.3")));
|
||||
|
||||
// change to mBTC
|
||||
useMilliBitFormat(true);
|
||||
assertEquals("1000.00", formatCoin(Coin.COIN));
|
||||
assertEquals("1.00", formatCoin(Coin.MILLICOIN));
|
||||
assertEquals("0.0010", formatCoin(Coin.MICROCOIN));
|
||||
formatter.useMilliBitFormat(true);
|
||||
assertEquals("1000.00", formatter.formatCoin(Coin.COIN));
|
||||
assertEquals("1.00", formatter.formatCoin(Coin.MILLICOIN));
|
||||
assertEquals("0.0010", formatter.formatCoin(Coin.MICROCOIN));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFormatCoinWithCode() {
|
||||
useMilliBitFormat(false);
|
||||
assertEquals("1.00 BTC", formatCoinWithCode(Coin.COIN));
|
||||
assertEquals("1.01 BTC", formatCoinWithCode(Coin.parseCoin("1.01")));
|
||||
assertEquals("1.0120 BTC", formatCoinWithCode(Coin.parseCoin("1.012")));
|
||||
assertEquals("1012.30 BTC", formatCoinWithCode(Coin.parseCoin("1012.3")));
|
||||
assertEquals("1.0120 BTC", formatCoinWithCode(Coin.parseCoin("1.01200")));
|
||||
assertEquals("1.0123 BTC", formatCoinWithCode(Coin.parseCoin("1.01234")));
|
||||
BSFormatter formatter = new BSFormatter(new User());
|
||||
formatter.useMilliBitFormat(false);
|
||||
assertEquals("1.00 BTC", formatter.formatCoinWithCode(Coin.COIN));
|
||||
assertEquals("1.01 BTC", formatter.formatCoinWithCode(Coin.parseCoin("1.01")));
|
||||
assertEquals("1.0120 BTC", formatter.formatCoinWithCode(Coin.parseCoin("1.012")));
|
||||
assertEquals("1012.30 BTC", formatter.formatCoinWithCode(Coin.parseCoin("1012.3")));
|
||||
assertEquals("1.0120 BTC", formatter.formatCoinWithCode(Coin.parseCoin("1.01200")));
|
||||
assertEquals("1.0123 BTC", formatter.formatCoinWithCode(Coin.parseCoin("1.01234")));
|
||||
|
||||
assertEquals("1.2345 BTC", formatCoinWithCode(Coin.parseCoin("1.2345")));
|
||||
assertEquals("1.2346 BTC", formatCoinWithCode(Coin.parseCoin("1.23456")));
|
||||
assertEquals("1.2346 BTC", formatCoinWithCode(Coin.parseCoin("1.234567")));
|
||||
assertEquals("1.2345 BTC", formatCoinWithCode(Coin.parseCoin("1.23448")));
|
||||
assertEquals("1.2345 BTC", formatter.formatCoinWithCode(Coin.parseCoin("1.2345")));
|
||||
assertEquals("1.2346 BTC", formatter.formatCoinWithCode(Coin.parseCoin("1.23456")));
|
||||
assertEquals("1.2346 BTC", formatter.formatCoinWithCode(Coin.parseCoin("1.234567")));
|
||||
assertEquals("1.2345 BTC", formatter.formatCoinWithCode(Coin.parseCoin("1.23448")));
|
||||
|
||||
assertEquals("1.00 BTC", formatCoinWithCode(Coin.COIN));
|
||||
assertEquals("1012.30 BTC", formatCoinWithCode(Coin.parseCoin("1012.3")));
|
||||
assertEquals("1.00 BTC", formatter.formatCoinWithCode(Coin.COIN));
|
||||
assertEquals("1012.30 BTC", formatter.formatCoinWithCode(Coin.parseCoin("1012.3")));
|
||||
|
||||
// change to mBTC
|
||||
useMilliBitFormat(true);
|
||||
assertEquals("1000.00 mBTC", formatCoinWithCode(Coin.COIN));
|
||||
assertEquals("1.00 mBTC", formatCoinWithCode(Coin.MILLICOIN));
|
||||
assertEquals("0.0010 mBTC", formatCoinWithCode(Coin.MICROCOIN));
|
||||
formatter.useMilliBitFormat(true);
|
||||
assertEquals("1000.00 mBTC", formatter.formatCoinWithCode(Coin.COIN));
|
||||
assertEquals("1.00 mBTC", formatter.formatCoinWithCode(Coin.MILLICOIN));
|
||||
assertEquals("0.0010 mBTC", formatter.formatCoinWithCode(Coin.MICROCOIN));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testParseToBtcWith4Decimals() {
|
||||
useMilliBitFormat(false);
|
||||
assertEquals(Coin.parseCoin("0"), parseToCoinWith4Decimals("0"));
|
||||
assertEquals(Coin.parseCoin("0"), parseToCoinWith4Decimals(null));
|
||||
assertEquals(Coin.parseCoin("0"), parseToCoinWith4Decimals("s"));
|
||||
assertEquals(Coin.parseCoin("0.0012"), parseToCoinWith4Decimals("0,00123"));
|
||||
assertEquals(Coin.parseCoin("0.0013"), parseToCoinWith4Decimals("0,00125"));
|
||||
BSFormatter formatter = new BSFormatter(new User());
|
||||
formatter.useMilliBitFormat(false);
|
||||
assertEquals(Coin.parseCoin("0"), formatter.parseToCoinWith4Decimals("0"));
|
||||
assertEquals(Coin.parseCoin("0"), formatter.parseToCoinWith4Decimals(null));
|
||||
assertEquals(Coin.parseCoin("0"), formatter.parseToCoinWith4Decimals("s"));
|
||||
assertEquals(Coin.parseCoin("0.0012"), formatter.parseToCoinWith4Decimals("0,00123"));
|
||||
assertEquals(Coin.parseCoin("0.0013"), formatter.parseToCoinWith4Decimals("0,00125"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHasBtcValidDecimals() {
|
||||
useMilliBitFormat(false);
|
||||
setLocale(Locale.GERMAN);
|
||||
assertTrue(hasBtcValidDecimals(null));
|
||||
assertTrue(hasBtcValidDecimals("0"));
|
||||
assertTrue(hasBtcValidDecimals("0,0001"));
|
||||
assertTrue(hasBtcValidDecimals("0.0001"));
|
||||
assertTrue(hasBtcValidDecimals("0.0009"));
|
||||
assertTrue(hasBtcValidDecimals("20000000.0001"));
|
||||
assertFalse(hasBtcValidDecimals("20000000.000123"));
|
||||
assertFalse(hasBtcValidDecimals("0.00012"));
|
||||
assertFalse(hasBtcValidDecimals("0.0001222312312312313"));
|
||||
BSFormatter formatter = new BSFormatter(new User());
|
||||
formatter.useMilliBitFormat(false);
|
||||
formatter.setLocale(Locale.GERMAN);
|
||||
assertTrue(formatter.hasBtcValidDecimals(null));
|
||||
assertTrue(formatter.hasBtcValidDecimals("0"));
|
||||
assertTrue(formatter.hasBtcValidDecimals("0,0001"));
|
||||
assertTrue(formatter.hasBtcValidDecimals("0.0001"));
|
||||
assertTrue(formatter.hasBtcValidDecimals("0.0009"));
|
||||
assertTrue(formatter.hasBtcValidDecimals("20000000.0001"));
|
||||
assertFalse(formatter.hasBtcValidDecimals("20000000.000123"));
|
||||
assertFalse(formatter.hasBtcValidDecimals("0.00012"));
|
||||
assertFalse(formatter.hasBtcValidDecimals("0.0001222312312312313"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseToFiatWith2Decimals() {
|
||||
useMilliBitFormat(false);
|
||||
setLocale(Locale.GERMAN);
|
||||
assertEquals("0", parseToFiatWith2Decimals("0").toPlainString());
|
||||
assertEquals("0", parseToFiatWith2Decimals(null).toPlainString());
|
||||
assertEquals("0", parseToFiatWith2Decimals("s").toPlainString());
|
||||
assertEquals("0.12", parseToFiatWith2Decimals("0.123").toPlainString());
|
||||
assertEquals("0.13", parseToFiatWith2Decimals("0.125").toPlainString());
|
||||
assertEquals("0.13", parseToFiatWith2Decimals("0,125").toPlainString());
|
||||
BSFormatter formatter = new BSFormatter(new User());
|
||||
formatter.useMilliBitFormat(false);
|
||||
formatter.setLocale(Locale.GERMAN);
|
||||
assertEquals("0", formatter.parseToFiatWith2Decimals("0").toPlainString());
|
||||
assertEquals("0", formatter.parseToFiatWith2Decimals(null).toPlainString());
|
||||
assertEquals("0", formatter.parseToFiatWith2Decimals("s").toPlainString());
|
||||
assertEquals("0.12", formatter.parseToFiatWith2Decimals("0.123").toPlainString());
|
||||
assertEquals("0.13", formatter.parseToFiatWith2Decimals("0.125").toPlainString());
|
||||
assertEquals("0.13", formatter.parseToFiatWith2Decimals("0,125").toPlainString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHasFiatValidDecimals() {
|
||||
useMilliBitFormat(false);
|
||||
setLocale(Locale.GERMAN);
|
||||
assertTrue(hasFiatValidDecimals(null));
|
||||
assertTrue(hasFiatValidDecimals("0"));
|
||||
assertTrue(hasFiatValidDecimals("0,01"));
|
||||
assertTrue(hasFiatValidDecimals("0.01"));
|
||||
assertTrue(hasFiatValidDecimals("0.09"));
|
||||
assertTrue(hasFiatValidDecimals("20000000.01"));
|
||||
assertFalse(hasFiatValidDecimals("20000000.0123"));
|
||||
assertFalse(hasFiatValidDecimals("0.012"));
|
||||
assertFalse(hasFiatValidDecimals("0.01222312312312313"));
|
||||
BSFormatter formatter = new BSFormatter(new User());
|
||||
formatter.useMilliBitFormat(false);
|
||||
formatter.setLocale(Locale.GERMAN);
|
||||
assertTrue(formatter.hasFiatValidDecimals(null));
|
||||
assertTrue(formatter.hasFiatValidDecimals("0"));
|
||||
assertTrue(formatter.hasFiatValidDecimals("0,01"));
|
||||
assertTrue(formatter.hasFiatValidDecimals("0.01"));
|
||||
assertTrue(formatter.hasFiatValidDecimals("0.09"));
|
||||
assertTrue(formatter.hasFiatValidDecimals("20000000.01"));
|
||||
assertFalse(formatter.hasFiatValidDecimals("20000000.0123"));
|
||||
assertFalse(formatter.hasFiatValidDecimals("0.012"));
|
||||
assertFalse(formatter.hasFiatValidDecimals("0.01222312312312313"));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,44 +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 BitSquareConverterTest {
|
||||
|
||||
@Test
|
||||
public void testStringToDouble() {
|
||||
|
||||
assertEquals(1, BSFormatter.parseToDouble("1"), 0);
|
||||
assertEquals(0.1, BSFormatter.parseToDouble("0.1"), 0);
|
||||
assertEquals(0.1, BSFormatter.parseToDouble("0,1"), 0);
|
||||
assertEquals(1, BSFormatter.parseToDouble("1.0"), 0);
|
||||
assertEquals(1, BSFormatter.parseToDouble("1,0"), 0);
|
||||
|
||||
assertEquals(0, BSFormatter.parseToDouble("1,000.2"), 0);
|
||||
assertEquals(0, BSFormatter.parseToDouble("1,000.2"), 0);
|
||||
assertEquals(0, BSFormatter.parseToDouble(null), 0);
|
||||
assertEquals(0, BSFormatter.parseToDouble(""), 0);
|
||||
assertEquals(0, BSFormatter.parseToDouble(""), 0);
|
||||
assertEquals(0, BSFormatter.parseToDouble("."), 0);
|
||||
assertEquals(0, BSFormatter.parseToDouble(","), 0);
|
||||
assertEquals(0, BSFormatter.parseToDouble("a"), 0);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user