Reformat amount/minAmount and volume/minVolume, prevent usage of payment methods with Banks in US at create offer

This commit is contained in:
Manfred Karrer 2016-08-26 19:50:28 +02:00
parent eb9f40ab54
commit 5c2d7db3f8
17 changed files with 74 additions and 48 deletions

View file

@ -32,7 +32,7 @@ public class SearchComboBox<T> extends ComboBox<T> {
filteredList.setPredicate(item -> newValue.isEmpty() ||
getConverter().toString(item).toLowerCase().contains(newValue.toLowerCase()));
hide();
setVisibleRowCount(Math.min(20, filteredList.size()));
setVisibleRowCount(Math.min(12, filteredList.size()));
show();
});
}

View file

@ -251,7 +251,7 @@ abstract class BankForm extends PaymentMethodForm {
ComboBox<Country> countryComboBox = tuple3.third;
countryComboBox.setVisibleRowCount(20);
countryComboBox.setVisibleRowCount(15);
countryComboBox.setDisable(true);
countryComboBox.setPromptText("Select country");
countryComboBox.setConverter(new StringConverter<Country>() {

View file

@ -249,7 +249,7 @@ public class CashDepositForm extends PaymentMethodForm {
regionComboBox.setItems(FXCollections.observableArrayList(CountryUtil.getAllRegions()));
ComboBox<Country> countryComboBox = tuple3.third;
countryComboBox.setVisibleRowCount(20);
countryComboBox.setVisibleRowCount(15);
countryComboBox.setDisable(true);
countryComboBox.setPromptText("Select country");
countryComboBox.setConverter(new StringConverter<Country>() {

View file

@ -129,7 +129,7 @@ public class CryptoCurrencyForm extends PaymentMethodForm {
currencyComboBox = addLabelSearchComboBox(gridPane, ++gridRow, "Altcoin:", Layout.FIRST_ROW_AND_GROUP_DISTANCE).second;
currencyComboBox.setPromptText("Select or search altcoin");
currencyComboBox.setItems(FXCollections.observableArrayList(CurrencyUtil.getAllSortedCryptoCurrencies()));
currencyComboBox.setVisibleRowCount(Math.min(currencyComboBox.getItems().size(), 20));
currencyComboBox.setVisibleRowCount(Math.min(currencyComboBox.getItems().size(), 15));
currencyComboBox.setConverter(new StringConverter<TradeCurrency>() {
@Override
public String toString(TradeCurrency tradeCurrency) {

View file

@ -291,7 +291,7 @@ public class MainView extends InitializableView<StackPane, MainViewModel> {
private Tuple3<ComboBox<PriceFeedComboBoxItem>, Label, VBox> getMarketPriceBox(String text) {
ComboBox<PriceFeedComboBoxItem> priceComboBox = new ComboBox<>();
priceComboBox.setVisibleRowCount(40);
priceComboBox.setVisibleRowCount(20);
priceComboBox.setMaxWidth(220);
priceComboBox.setMinWidth(220);
priceComboBox.setFocusTraversable(false);

View file

@ -229,7 +229,7 @@ public class FiatAccountsView extends ActivatableViewAndModel<GridPane, FiatAcco
accountTitledGroupBg = addTitledGroupBg(root, ++gridRow, 1, "Create new account", Layout.GROUP_DISTANCE);
paymentMethodComboBox = addLabelComboBox(root, gridRow, "Payment method:", Layout.FIRST_ROW_AND_GROUP_DISTANCE).second;
paymentMethodComboBox.setPromptText("Select payment method");
paymentMethodComboBox.setVisibleRowCount(20);
paymentMethodComboBox.setVisibleRowCount(15);
paymentMethodComboBox.setPrefWidth(250);
List<PaymentMethod> list = PaymentMethod.ALL_VALUES.stream()
.filter(paymentMethod -> !paymentMethod.getId().equals(PaymentMethod.BLOCK_CHAINS_ID))

View file

@ -30,7 +30,7 @@
<columns>
<TableColumn text="Select" fx:id="selectColumn" minWidth="110" maxWidth="110" sortable="false"/>
<TableColumn text="Address" fx:id="addressColumn" minWidth="320"/>
<TableColumn text="Balance (BTC)" fx:id="balanceColumn" minWidth="150"/>
<TableColumn text="Balance in BTC" fx:id="balanceColumn" minWidth="150"/>
<TableColumn text="Confirmations" fx:id="confidenceColumn" minWidth="150"/>
<TableColumn text="Usage" fx:id="usageColumn" minWidth="200"/>
</columns>

View file

@ -31,7 +31,7 @@
<TableColumn text="Date/Time" fx:id="dateColumn" minWidth="180" maxWidth="180"/>
<TableColumn text="Details" fx:id="detailsColumn" minWidth="320"/>
<TableColumn text="Address" fx:id="addressColumn" minWidth="320"/>
<TableColumn text="Balance (BTC)" fx:id="balanceColumn" minWidth="110"/>
<TableColumn text="Balance in BTC" fx:id="balanceColumn" minWidth="110"/>
</columns>
</TableView>

View file

@ -31,7 +31,7 @@
<TableColumn text="Date/Time" fx:id="dateColumn" minWidth="180" maxWidth="180"/>
<TableColumn text="Details" fx:id="detailsColumn" minWidth="320"/>
<TableColumn text="Address" fx:id="addressColumn" minWidth="320"/>
<TableColumn text="Balance (BTC)" fx:id="balanceColumn" minWidth="110"/>
<TableColumn text="Balance in BTC" fx:id="balanceColumn" minWidth="110"/>
</columns>
</TableView>

View file

@ -30,7 +30,7 @@
<columns>
<TableColumn text="Select" fx:id="selectColumn" minWidth="60" maxWidth="60" sortable="false"/>
<TableColumn text="Address" fx:id="addressColumn" minWidth="320"/>
<TableColumn text="Balance (BTC)" fx:id="balanceColumn" minWidth="310" maxWidth="310"/>
<TableColumn text="Balance in BTC" fx:id="balanceColumn" minWidth="310" maxWidth="310"/>
</columns>
</TableView>

View file

@ -55,6 +55,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import java.util.stream.Collectors;
import static com.google.common.base.Preconditions.checkNotNull;
@ -107,7 +108,7 @@ class CreateOfferDataModel extends ActivatableDataModel {
final ObjectProperty<Coin> missingCoin = new SimpleObjectProperty<>(Coin.ZERO);
final ObjectProperty<Coin> balance = new SimpleObjectProperty<>();
final ObservableList<PaymentAccount> paymentAccounts = FXCollections.observableArrayList();
private final ObservableList<PaymentAccount> paymentAccounts = FXCollections.observableArrayList();
PaymentAccount paymentAccount;
boolean isTabSelected;
@ -177,7 +178,7 @@ class CreateOfferDataModel extends ActivatableDataModel {
}
};
paymentAccountsChangeListener = change -> paymentAccounts.setAll(user.getPaymentAccounts());
paymentAccountsChangeListener = change -> fillPaymentAccounts();
}
@Override
@ -185,8 +186,6 @@ class CreateOfferDataModel extends ActivatableDataModel {
addBindings();
addListeners();
paymentAccounts.setAll(user.getPaymentAccounts());
if (!preferences.getUseStickyMarketPrice() && isTabSelected)
priceFeedService.setCurrencyCode(tradeCurrencyCode.get());
@ -226,17 +225,19 @@ class CreateOfferDataModel extends ActivatableDataModel {
boolean initWithData(Offer.Direction direction, TradeCurrency tradeCurrency) {
this.direction = direction;
fillPaymentAccounts();
PaymentAccount account = user.findFirstPaymentAccountWithCurrency(tradeCurrency);
if (account != null) {
if (account != null && !isUSBankAccount(account)) {
paymentAccount = account;
this.tradeCurrency = tradeCurrency;
} else {
Optional<PaymentAccount> paymentAccountOptional = user.getPaymentAccounts().stream().findAny();
Optional<PaymentAccount> paymentAccountOptional = paymentAccounts.stream().findAny();
if (paymentAccountOptional.isPresent()) {
paymentAccount = paymentAccountOptional.get();
this.tradeCurrency = paymentAccount.getSingleTradeCurrency();
} else {
// Should never get called as in offer view you should not be able to open a create offer view
log.warn("PaymentAccount not available. Should never get called as in offer view you should not be able to open a create offer view");
return false;
}
}
@ -341,7 +342,7 @@ class CreateOfferDataModel extends ActivatableDataModel {
price.set(null);
marketPriceMargin = 0;
}
this.tradeCurrency = tradeCurrency;
final String code = tradeCurrency.getCode();
tradeCurrencyCode.set(code);
@ -376,6 +377,10 @@ class CreateOfferDataModel extends ActivatableDataModel {
}
}
void setMarketPriceMargin(double marketPriceMargin) {
this.marketPriceMargin = marketPriceMargin;
}
///////////////////////////////////////////////////////////////////////////////////////////
// Getters
@ -422,6 +427,14 @@ class CreateOfferDataModel extends ActivatableDataModel {
return !isMainNet.get() || feeFromFundingTxProperty.get().compareTo(FeePolicy.getMinRequiredFeeForFundingTx()) >= 0;
}*/
public ObservableList<PaymentAccount> getPaymentAccounts() {
return paymentAccounts;
}
double getMarketPriceMargin() {
return marketPriceMargin;
}
///////////////////////////////////////////////////////////////////////////////////////////
// Utils
@ -531,11 +544,16 @@ class CreateOfferDataModel extends ActivatableDataModel {
walletService.swapTradeEntryToAvailableEntry(offerId, AddressEntry.Context.RESERVED_FOR_TRADE);
}
double getMarketPriceMargin() {
return marketPriceMargin;
private void fillPaymentAccounts() {
paymentAccounts.setAll(user.getPaymentAccounts().stream()
.filter(e -> !isUSBankAccount(e))
.collect(Collectors.toSet()));
}
void setMarketPriceMargin(double marketPriceMargin) {
this.marketPriceMargin = marketPriceMargin;
private boolean isUSBankAccount(PaymentAccount paymentAccount) {
if (paymentAccount instanceof SameCountryRestrictedBankAccount && paymentAccount.getContractData() instanceof BankAccountContractData)
return ((SameCountryRestrictedBankAccount) paymentAccount).getCountryCode().equals("US");
else
return false;
}
}

View file

@ -198,7 +198,7 @@ public class CreateOfferView extends ActivatableViewAndModel<AnchorPane, CreateO
addressTextField.setAddress(model.getAddressAsString());
addressTextField.setPaymentLabel(model.getPaymentLabel());
paymentAccountsComboBox.setItems(model.getPaymentAccounts());
paymentAccountsComboBox.setItems(model.dataModel.getPaymentAccounts());
paymentAccountsComboBox.getSelectionModel().select(model.getPaymentAccount());
onPaymentAccountsComboBoxSelected();
@ -241,10 +241,8 @@ public class CreateOfferView extends ActivatableViewAndModel<AnchorPane, CreateO
public void initWithData(Offer.Direction direction, TradeCurrency tradeCurrency) {
boolean result = model.initWithData(direction, tradeCurrency);
if (!result) {
log.error("Payment account set up. That should not be possible as UI does not support that case.");
if (!result)
new Popup().warning("You don't have a payment account set up.").onClose(this::close).show();
}
if (direction == Offer.Direction.BUY) {
imageView.setId("image-buy-large");

View file

@ -48,7 +48,6 @@ import io.bitsquare.trade.offer.Offer;
import io.bitsquare.user.Preferences;
import javafx.beans.property.*;
import javafx.beans.value.ChangeListener;
import javafx.collections.ObservableList;
import org.bitcoinj.core.Address;
import org.bitcoinj.core.Coin;
@ -656,10 +655,6 @@ class CreateOfferViewModel extends ActivatableWithDataModel<CreateOfferDataModel
return dataModel.getDirection() == Offer.Direction.SELL;
}
public ObservableList<PaymentAccount> getPaymentAccounts() {
return dataModel.paymentAccounts;
}
public TradeCurrency getTradeCurrency() {
return dataModel.getTradeCurrency();
}

View file

@ -226,13 +226,13 @@ public class OfferBookView extends ActivatableViewAndModel<GridPane, OfferBookVi
(showAll, code) -> {
if (showAll) {
volumeColumn.setText("Amount (Min.)");
volumeColumn.setText("Amount (min - max)");
priceColumn.setText("Price");
if (!tableView.getColumns().contains(marketColumn))
tableView.getColumns().add(0, marketColumn);
} else {
volumeColumn.setText("Amount in " + code + " (Min.)");
volumeColumn.setText("Amount in " + code + " (min - max)");
priceColumn.setText(formatter.getPriceWithCurrencyCode(code));
if (tableView.getColumns().contains(marketColumn))
@ -427,9 +427,9 @@ public class OfferBookView extends ActivatableViewAndModel<GridPane, OfferBookVi
///////////////////////////////////////////////////////////////////////////////////////////
private TableColumn<OfferBookListItem, OfferBookListItem> getAmountColumn() {
TableColumn<OfferBookListItem, OfferBookListItem> column = new TableColumn<OfferBookListItem, OfferBookListItem>("Amount in BTC (Min.)") {
TableColumn<OfferBookListItem, OfferBookListItem> column = new TableColumn<OfferBookListItem, OfferBookListItem>("Amount in BTC (min - max)") {
{
setMinWidth(130);
setMinWidth(150);
}
};
column.setCellValueFactory((offer) -> new ReadOnlyObjectWrapper<>(offer.getValue()));

View file

@ -51,6 +51,7 @@ import javafx.collections.ListChangeListener;
import javafx.collections.ObservableList;
import javafx.collections.transformation.FilteredList;
import javafx.collections.transformation.SortedList;
import org.bitcoinj.core.Coin;
import org.bitcoinj.utils.Fiat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -132,7 +133,7 @@ class OfferBookViewModel extends ActivatableViewModel {
@Override
protected void activate() {
tradeCurrencyCodes = preferences.getTradeCurrenciesAsObservable().stream().map(e -> e.getCode()).collect(Collectors.toSet());
String code = direction == Offer.Direction.BUY ? preferences.getBuyScreenCurrencyCode() : preferences.getSellScreenCurrencyCode();
if (code != null && !code.isEmpty() && CurrencyUtil.getTradeCurrency(code).isPresent()) {
showAllTradeCurrenciesProperty.set(false);
@ -271,10 +272,14 @@ class OfferBookViewModel extends ActivatableViewModel {
return list;
}
String getAmount(OfferBookListItem item) {
return (item != null) ? formatter.formatCoin(item.getOffer().getAmount()) +
" (" + formatter.formatCoin(item.getOffer().getMinAmount()) + ")" : "";
Offer offer = item.getOffer();
Coin amount = offer.getAmount();
Coin minAmount = offer.getMinAmount();
if (amount.equals(minAmount))
return formatter.formatAmount(offer);
else
return formatter.formatAmountWithMinAmount(offer);
}
String getPrice(OfferBookListItem item) {
@ -298,13 +303,15 @@ class OfferBookViewModel extends ActivatableViewModel {
}
String getVolume(OfferBookListItem item) {
Fiat offerVolume = item.getOffer().getOfferVolume();
Fiat minOfferVolume = item.getOffer().getMinOfferVolume();
Offer offer = item.getOffer();
Fiat offerVolume = offer.getOfferVolume();
Fiat minOfferVolume = offer.getMinOfferVolume();
if (offerVolume != null && minOfferVolume != null) {
if (showAllTradeCurrenciesProperty.get())
return formatter.formatVolumeWithCode(offerVolume) + " (" + formatter.formatVolumeWithCode(minOfferVolume) + ")";
String postFix = showAllTradeCurrenciesProperty.get() ? " " + offer.getCurrencyCode() : "";
if (offerVolume.equals(minOfferVolume))
return formatter.formatVolume(offerVolume) + postFix;
else
return formatter.formatVolume(offerVolume) + " (" + formatter.formatVolume(minOfferVolume) + ")";
return formatter.formatMinVolumeAndVolume(offer) + postFix;
} else {
return "N/A";
}

View file

@ -76,7 +76,7 @@ class OpenOffersViewModel extends ActivatableWithDataModel<OpenOffersDataModel>
}
String getVolume(OpenOfferListItem item) {
return (item != null) ? formatter.formatVolumeWithMinVolumeWithCode(item.getOffer()) : "";
return (item != null) ? formatter.formatMinVolumeAndVolumeWithCode(item.getOffer()) : "";
}
String getDirectionLabel(OpenOfferListItem item) {

View file

@ -279,6 +279,10 @@ public class BSFormatter {
return CurrencyUtil.getNameByCode(currencyCode) + " amount" + postFix;
}
public String formatMinVolumeAndVolume(Offer offer) {
return formatVolume(offer.getMinOfferVolume()) + " - " + formatVolume(offer.getOfferVolume());
}
///////////////////////////////////////////////////////////////////////////////////////////
// Price
@ -342,11 +346,15 @@ public class BSFormatter {
return result;
}
public String formatAmountWithMinAmount(Offer offer) {
return formatCoin(offer.getAmount()) + " (" + formatCoin(offer.getMinAmount()) + ")";
public String formatAmount(Offer offer) {
return formatCoin(offer.getAmount());
}
public String formatVolumeWithMinVolumeWithCode(Offer offer) {
public String formatAmountWithMinAmount(Offer offer) {
return formatCoin(offer.getMinAmount()) + " - " + formatCoin(offer.getAmount());
}
public String formatMinVolumeAndVolumeWithCode(Offer offer) {
return formatFiatWithCode(offer.getOfferVolume()) +
" (" + formatFiatWithCode(offer.getMinOfferVolume()) + ")";
}