use of bisq.core.locale.TradeCurrency in project bisq-desktop by bisq-network.
the class GUIUtil method getCurrencyListItemConverter.
public static StringConverter<CurrencyListItem> getCurrencyListItemConverter(String postFixSingle, String postFixMulti, Preferences preferences) {
return new StringConverter<CurrencyListItem>() {
@Override
public String toString(CurrencyListItem item) {
TradeCurrency tradeCurrency = item.tradeCurrency;
String code = tradeCurrency.getCode();
switch(code) {
case GUIUtil.SHOW_ALL_FLAG:
return "▶ " + Res.get("list.currency.showAll");
case GUIUtil.EDIT_FLAG:
return "▼ " + Res.get("list.currency.editList");
default:
String displayString = CurrencyUtil.getNameByCode(code) + " (" + code + ")";
if (preferences.isSortMarketCurrenciesNumerically()) {
final int numTrades = item.numTrades;
displayString += " - " + numTrades + " " + (numTrades == 1 ? postFixSingle : postFixMulti);
}
return tradeCurrency.getDisplayPrefix() + displayString;
}
}
@Override
public CurrencyListItem fromString(String s) {
return null;
}
};
}
use of bisq.core.locale.TradeCurrency in project bisq-api by mrosseel.
the class BisqProxy method addPaymentAccount.
public PaymentAccount addPaymentAccount(PaymentAccount paymentAccount) {
if (paymentAccount instanceof CryptoCurrencyAccount) {
final CryptoCurrencyAccount cryptoCurrencyAccount = (CryptoCurrencyAccount) paymentAccount;
final TradeCurrency tradeCurrency = cryptoCurrencyAccount.getSingleTradeCurrency();
if (null == tradeCurrency) {
throw new ValidationException("There must be exactly one trade currency");
}
final AltCoinAddressValidator altCoinAddressValidator = injector.getInstance(AltCoinAddressValidator.class);
altCoinAddressValidator.setCurrencyCode(tradeCurrency.getCode());
final InputValidator.ValidationResult validationResult = altCoinAddressValidator.validate(cryptoCurrencyAccount.getAddress());
if (!validationResult.isValid) {
throw new ValidationException(validationResult.errorMessage);
}
}
user.addPaymentAccount(paymentAccount);
TradeCurrency singleTradeCurrency = paymentAccount.getSingleTradeCurrency();
List<TradeCurrency> tradeCurrencies = paymentAccount.getTradeCurrencies();
if (singleTradeCurrency != null) {
if (singleTradeCurrency instanceof FiatCurrency)
preferences.addFiatCurrency((FiatCurrency) singleTradeCurrency);
else
preferences.addCryptoCurrency((CryptoCurrency) singleTradeCurrency);
} else if (tradeCurrencies != null && !tradeCurrencies.isEmpty()) {
if (tradeCurrencies.contains(CurrencyUtil.getDefaultTradeCurrency()))
paymentAccount.setSelectedTradeCurrency(CurrencyUtil.getDefaultTradeCurrency());
else
paymentAccount.setSelectedTradeCurrency(tradeCurrencies.get(0));
tradeCurrencies.forEach(tradeCurrency -> {
if (tradeCurrency instanceof FiatCurrency)
preferences.addFiatCurrency((FiatCurrency) tradeCurrency);
else
preferences.addCryptoCurrency((CryptoCurrency) tradeCurrency);
});
}
accountAgeWitnessService.publishMyAccountAgeWitness(paymentAccount.getPaymentAccountPayload());
return paymentAccount;
}
use of bisq.core.locale.TradeCurrency in project bisq-api by mrosseel.
the class BisqProxy method getPriceFeed.
public PriceFeed getPriceFeed(String[] codes) {
final PriceFeedService priceFeedService = injector.getInstance(PriceFeedService.class);
final List<FiatCurrency> fiatCurrencies = preferences.getFiatCurrencies();
final List<CryptoCurrency> cryptoCurrencies = preferences.getCryptoCurrencies();
final Stream<String> codesStream;
if (null == codes || 0 == codes.length)
codesStream = Stream.concat(fiatCurrencies.stream(), cryptoCurrencies.stream()).map(TradeCurrency::getCode);
else
codesStream = Arrays.asList(codes).stream();
final List<MarketPrice> marketPrices = codesStream.map(priceFeedService::getMarketPrice).filter(i -> null != i).collect(toList());
final PriceFeed priceFeed = new PriceFeed();
for (MarketPrice price : marketPrices) priceFeed.prices.put(price.getCurrencyCode(), price.getPrice());
return priceFeed;
}
use of bisq.core.locale.TradeCurrency in project bisq-api by mrosseel.
the class AbstractPaymentAccountConverter method toRestModel.
protected void toRestModel(R rest, B business) {
rest.id = business.getId();
rest.accountName = business.getAccountName();
final TradeCurrency selectedTradeCurrency = business.getSelectedTradeCurrency();
if (null != selectedTradeCurrency)
rest.selectedTradeCurrency = selectedTradeCurrency.getCode();
final List<TradeCurrency> tradeCurrencies = business.getTradeCurrencies();
if (null != tradeCurrencies)
tradeCurrencies.stream().forEach(currency -> rest.tradeCurrencies.add(currency.getCode()));
}
use of bisq.core.locale.TradeCurrency in project bisq-desktop by bisq-network.
the class CreateOfferView method onPaymentAccountsComboBoxSelected.
private void onPaymentAccountsComboBoxSelected() {
// Temporary deactivate handler as the payment account change can populate a new currency list and causes
// unwanted selection events (item 0)
currencyComboBox.setOnAction(null);
PaymentAccount paymentAccount = paymentAccountsComboBox.getSelectionModel().getSelectedItem();
if (paymentAccount != null) {
maybeShowClearXchangeWarning(paymentAccount);
currencyComboBox.setVisible(paymentAccount.hasMultipleCurrencies());
if (paymentAccount.hasMultipleCurrencies()) {
final List<TradeCurrency> tradeCurrencies = paymentAccount.getTradeCurrencies();
currencyComboBox.setItems(FXCollections.observableArrayList(tradeCurrencies));
if (paymentAccount.getSelectedTradeCurrency() != null)
currencyComboBox.getSelectionModel().select(paymentAccount.getSelectedTradeCurrency());
else if (tradeCurrencies.contains(model.getTradeCurrency()))
currencyComboBox.getSelectionModel().select(model.getTradeCurrency());
else
currencyComboBox.getSelectionModel().select(tradeCurrencies.get(0));
model.onPaymentAccountSelected(paymentAccount);
} else {
TradeCurrency singleTradeCurrency = paymentAccount.getSingleTradeCurrency();
if (singleTradeCurrency != null)
currencyTextField.setText(singleTradeCurrency.getNameAndCode());
model.onPaymentAccountSelected(paymentAccount);
model.onCurrencySelected(model.dataModel.getTradeCurrency());
}
} else {
currencyComboBox.setVisible(false);
currencyTextField.setText("");
}
currencyComboBox.setOnAction(currencyComboBoxSelectionHandler);
}
Aggregations