use of bisq.core.locale.FiatCurrency in project bisq-desktop by bisq-network.
the class AltCoinAccountsDataModel method onSaveNewAccount.
// /////////////////////////////////////////////////////////////////////////////////////////
// UI actions
// /////////////////////////////////////////////////////////////////////////////////////////
public void onSaveNewAccount(PaymentAccount paymentAccount) {
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()) {
tradeCurrencies.stream().forEach(tradeCurrency -> {
if (tradeCurrency instanceof FiatCurrency)
preferences.addFiatCurrency((FiatCurrency) tradeCurrency);
else
preferences.addCryptoCurrency((CryptoCurrency) tradeCurrency);
});
}
if (!(paymentAccount instanceof CryptoCurrencyAccount))
accountAgeWitnessService.publishMyAccountAgeWitness(paymentAccount.getPaymentAccountPayload());
}
use of bisq.core.locale.FiatCurrency in project bisq-desktop by bisq-network.
the class OfferBookView method setDirectionTitles.
private void setDirectionTitles() {
TradeCurrency selectedTradeCurrency = model.getSelectedTradeCurrency();
if (selectedTradeCurrency != null) {
OfferPayload.Direction direction = model.getDirection();
String directionText = direction == OfferPayload.Direction.BUY ? Res.get("shared.buy") : Res.get("shared.sell");
String mirroredDirectionText = direction == OfferPayload.Direction.SELL ? Res.get("shared.buy") : Res.get("shared.sell");
String code = selectedTradeCurrency.getCode();
if (model.showAllTradeCurrenciesProperty.get())
createOfferButton.setText(Res.get("offerbook.createOfferTo", directionText, Res.getBaseCurrencyCode()));
else if (selectedTradeCurrency instanceof FiatCurrency)
createOfferButton.setText(Res.get("offerbook.createOfferTo", directionText, Res.getBaseCurrencyCode()) + " " + (direction == OfferPayload.Direction.BUY ? Res.get("offerbook.buyWithOtherCurrency", code) : Res.get("offerbook.sellForOtherCurrency", code)));
else
createOfferButton.setText(Res.get("offerbook.createOfferTo", mirroredDirectionText, code) + " (" + directionText + " " + Res.getBaseCurrencyCode() + ")");
}
}
use of bisq.core.locale.FiatCurrency in project bisq-desktop by bisq-network.
the class PreferencesView method activateDisplayCurrencies.
private void activateDisplayCurrencies() {
preferredTradeCurrencyComboBox.setItems(tradeCurrencies);
preferredTradeCurrencyComboBox.getSelectionModel().select(preferences.getPreferredTradeCurrency());
preferredTradeCurrencyComboBox.setVisibleRowCount(25);
preferredTradeCurrencyComboBox.setOnAction(e -> {
TradeCurrency selectedItem = preferredTradeCurrencyComboBox.getSelectionModel().getSelectedItem();
if (selectedItem != null)
preferences.setPreferredTradeCurrency(selectedItem);
});
fiatCurrenciesComboBox.setItems(allFiatCurrencies);
fiatCurrenciesListView.setItems(fiatCurrencies);
fiatCurrenciesComboBox.setOnAction(e -> {
FiatCurrency selectedItem = fiatCurrenciesComboBox.getSelectionModel().getSelectedItem();
if (selectedItem != null) {
preferences.addFiatCurrency(selectedItem);
if (allFiatCurrencies.contains(selectedItem)) {
UserThread.execute(() -> {
fiatCurrenciesComboBox.getSelectionModel().clearSelection();
allFiatCurrencies.remove(selectedItem);
});
}
}
});
cryptoCurrenciesComboBox.setItems(allCryptoCurrencies);
cryptoCurrenciesListView.setItems(cryptoCurrencies);
cryptoCurrenciesComboBox.setOnAction(e -> {
CryptoCurrency selectedItem = cryptoCurrenciesComboBox.getSelectionModel().getSelectedItem();
if (selectedItem != null) {
preferences.addCryptoCurrency(selectedItem);
if (allCryptoCurrencies.contains(selectedItem)) {
UserThread.execute(() -> {
cryptoCurrenciesComboBox.getSelectionModel().clearSelection();
allCryptoCurrencies.remove(selectedItem);
});
}
}
});
}
use of bisq.core.locale.FiatCurrency in project bisq-desktop by bisq-network.
the class TradesChartsViewModelTest method testItemLists.
@Test
public void testItemLists() throws ParseException {
// Helper class to add historic trades
class Trade {
Trade(String date, String size, String price, String cc) {
try {
this.date = dateFormat.parse(date);
} catch (ParseException p) {
this.date = new Date();
}
this.size = size;
this.price = price;
this.cc = cc;
}
Date date;
String size;
String price;
String cc;
}
;
// Trade EUR
model.selectedTradeCurrencyProperty.setValue(new FiatCurrency("EUR"));
ArrayList<Trade> trades = new ArrayList<Trade>();
// Set predetermined time to use as "now" during test
// Monday
Date test_time = dateFormat.parse("2018-01-01T00:00:05");
new MockUp<System>() {
@Mock
long currentTimeMillis() {
return test_time.getTime();
}
};
// Two trades 10 seconds apart, different YEAR, MONTH, WEEK, DAY, HOUR, MINUTE_10
trades.add(new Trade("2017-12-31T23:59:52", "1", "100", "EUR"));
trades.add(new Trade("2018-01-01T00:00:02", "1", "110", "EUR"));
Set<TradeStatistics2> set = new HashSet<>();
trades.forEach(t -> {
set.add(new TradeStatistics2(offer, Price.parse(t.cc, t.price), Coin.parseCoin(t.size), t.date, null));
});
ObservableSet<TradeStatistics2> tradeStats = FXCollections.observableSet(set);
// Run test for each tick type
for (TradesChartsViewModel.TickUnit tick : TradesChartsViewModel.TickUnit.values()) {
new Expectations() {
{
tsm.getObservableTradeStatisticsSet();
result = tradeStats;
}
};
// Trigger chart update
model.setTickUnit(tick);
assertEquals(model.selectedTradeCurrencyProperty.get().getCode(), tradeStats.iterator().next().getCurrencyCode());
assertEquals(2, model.priceItems.size());
assertEquals(2, model.volumeItems.size());
}
}
use of bisq.core.locale.FiatCurrency in project bisq-desktop by bisq-network.
the class TradesChartsViewModelTest method testGetCandleData.
@SuppressWarnings("ConstantConditions")
@Test
public void testGetCandleData() {
model.selectedTradeCurrencyProperty.setValue(new FiatCurrency("EUR"));
long low = Fiat.parseFiat("EUR", "500").value;
long open = Fiat.parseFiat("EUR", "520").value;
long close = Fiat.parseFiat("EUR", "580").value;
long high = Fiat.parseFiat("EUR", "600").value;
long average = Fiat.parseFiat("EUR", "550").value;
long amount = Coin.parseCoin("4").value;
long volume = Fiat.parseFiat("EUR", "2200").value;
boolean isBullish = true;
Set<TradeStatistics2> set = new HashSet<>();
final Date now = new Date();
set.add(new TradeStatistics2(offer, Price.parse("EUR", "520"), Coin.parseCoin("1"), new Date(now.getTime()), null));
set.add(new TradeStatistics2(offer, Price.parse("EUR", "500"), Coin.parseCoin("1"), new Date(now.getTime() + 100), null));
set.add(new TradeStatistics2(offer, Price.parse("EUR", "600"), Coin.parseCoin("1"), new Date(now.getTime() + 200), null));
set.add(new TradeStatistics2(offer, Price.parse("EUR", "580"), Coin.parseCoin("1"), new Date(now.getTime() + 300), null));
CandleData candleData = model.getCandleData(model.roundToTick(now, TradesChartsViewModel.TickUnit.DAY).getTime(), set);
assertEquals(open, candleData.open);
assertEquals(close, candleData.close);
assertEquals(high, candleData.high);
assertEquals(low, candleData.low);
assertEquals(average, candleData.average);
assertEquals(amount, candleData.accumulatedAmount);
assertEquals(volume, candleData.accumulatedVolume);
assertEquals(isBullish, candleData.isBullish);
}
Aggregations