Search in sources :

Example 6 with CryptoCurrency

use of bisq.core.locale.CryptoCurrency in project bisq-desktop by bisq-network.

the class CreateOfferViewModelTest method setUp.

@Before
public void setUp() {
    final CryptoCurrency btc = new CryptoCurrency("BTC", "bitcoin");
    GlobalSettings.setDefaultTradeCurrency(btc);
    Res.setBaseCurrencyCode(btc.getCode());
    Res.setBaseCurrencyName(btc.getName());
    final BSFormatter bsFormatter = new BSFormatter();
    final BtcValidator btcValidator = new BtcValidator(bsFormatter);
    final AltcoinValidator altcoinValidator = new AltcoinValidator();
    final FiatPriceValidator fiatPriceValidator = new FiatPriceValidator();
    FeeService feeService = mock(FeeService.class);
    AddressEntry addressEntry = mock(AddressEntry.class);
    BtcWalletService btcWalletService = mock(BtcWalletService.class);
    PriceFeedService priceFeedService = mock(PriceFeedService.class);
    User user = mock(User.class);
    PaymentAccount paymentAccount = mock(PaymentAccount.class);
    BsqWalletService bsqWalletService = mock(BsqWalletService.class);
    SecurityDepositValidator securityDepositValidator = mock(SecurityDepositValidator.class);
    when(btcWalletService.getOrCreateAddressEntry(anyString(), any())).thenReturn(addressEntry);
    when(btcWalletService.getBalanceForAddress(any())).thenReturn(Coin.valueOf(1000L));
    when(priceFeedService.updateCounterProperty()).thenReturn(new SimpleIntegerProperty());
    when(priceFeedService.getMarketPrice(anyString())).thenReturn(new MarketPrice("USD", 12684.0450, Instant.now().getEpochSecond(), true));
    when(feeService.getTxFee(anyInt())).thenReturn(Coin.valueOf(1000L));
    when(user.findFirstPaymentAccountWithCurrency(any())).thenReturn(paymentAccount);
    when(user.getPaymentAccountsAsObservable()).thenReturn(FXCollections.observableSet());
    when(securityDepositValidator.validate(any())).thenReturn(new InputValidator.ValidationResult(false));
    CreateOfferDataModel dataModel = new CreateOfferDataModel(null, btcWalletService, bsqWalletService, empty, user, null, null, priceFeedService, null, null, null, feeService, bsFormatter);
    dataModel.initWithData(OfferPayload.Direction.BUY, new CryptoCurrency("BTC", "bitcoin"));
    dataModel.activate();
    model = new CreateOfferViewModel(dataModel, null, fiatPriceValidator, altcoinValidator, btcValidator, null, securityDepositValidator, null, null, priceFeedService, null, null, bsFormatter, null);
    model.activate();
}
Also used : BtcValidator(bisq.desktop.util.validation.BtcValidator) FiatPriceValidator(bisq.desktop.util.validation.FiatPriceValidator) User(bisq.core.user.User) AddressEntry(bisq.core.btc.AddressEntry) PaymentAccount(bisq.core.payment.PaymentAccount) FeeService(bisq.core.provider.fee.FeeService) BSFormatter(bisq.desktop.util.BSFormatter) AltcoinValidator(bisq.desktop.util.validation.AltcoinValidator) CryptoCurrency(bisq.core.locale.CryptoCurrency) SecurityDepositValidator(bisq.desktop.util.validation.SecurityDepositValidator) MarketPrice(bisq.core.provider.price.MarketPrice) InputValidator(bisq.core.util.validation.InputValidator) BtcWalletService(bisq.core.btc.wallet.BtcWalletService) PriceFeedService(bisq.core.provider.price.PriceFeedService) BsqWalletService(bisq.core.btc.wallet.BsqWalletService) SimpleIntegerProperty(javafx.beans.property.SimpleIntegerProperty) Before(org.junit.Before)

Example 7 with CryptoCurrency

use of bisq.core.locale.CryptoCurrency in project bisq-desktop by bisq-network.

the class OfferBookViewModelTest method getCryptoAccount.

private PaymentAccount getCryptoAccount(String currencyCode) {
    PaymentAccount paymentAccount = new CryptoCurrencyAccount();
    paymentAccount.addCurrency(new CryptoCurrency(currencyCode, null));
    return paymentAccount;
}
Also used : CryptoCurrency(bisq.core.locale.CryptoCurrency) CountryBasedPaymentAccount(bisq.core.payment.CountryBasedPaymentAccount) PaymentAccount(bisq.core.payment.PaymentAccount) CryptoCurrencyAccount(bisq.core.payment.CryptoCurrencyAccount)

Example 8 with CryptoCurrency

use of bisq.core.locale.CryptoCurrency in project bisq-desktop by bisq-network.

the class AltCoinAccountsView method onSaveNewAccount.

// /////////////////////////////////////////////////////////////////////////////////////////
// UI actions
// /////////////////////////////////////////////////////////////////////////////////////////
private void onSaveNewAccount(PaymentAccount paymentAccount) {
    TradeCurrency selectedTradeCurrency = paymentAccount.getSelectedTradeCurrency();
    if (selectedTradeCurrency != null) {
        String code = selectedTradeCurrency.getCode();
        if (selectedTradeCurrency instanceof CryptoCurrency && ((CryptoCurrency) selectedTradeCurrency).isAsset()) {
            String name = selectedTradeCurrency.getName();
            new Popup<>().information(Res.get("account.altcoin.popup.wallet.msg", selectedTradeCurrency.getCodeAndName(), name, name)).closeButtonText(Res.get("account.altcoin.popup.wallet.confirm")).show();
        }
        switch(code) {
            case "XMR":
                new Popup<>().information(Res.get("account.altcoin.popup.xmr.msg")).useIUnderstandButton().show();
                break;
            case "ZEC":
                new Popup<>().information(Res.get("account.altcoin.popup.ZEC.msg", "ZEC")).useIUnderstandButton().show();
                break;
            case "XZC":
                new Popup<>().information(Res.get("account.altcoin.popup.XZC.msg", "XZC")).useIUnderstandButton().show();
                break;
            case "BCH":
            case "BCHC":
                new Popup<>().information(Res.get("account.altcoin.popup.bch")).useIUnderstandButton().show();
                break;
            case "BTG":
                new Popup<>().information(Res.get("account.altcoin.popup.btg")).useIUnderstandButton().show();
                break;
        }
        if (!model.getPaymentAccounts().stream().filter(e -> e.getAccountName() != null && e.getAccountName().equals(paymentAccount.getAccountName())).findAny().isPresent()) {
            model.onSaveNewAccount(paymentAccount);
            removeNewAccountForm();
        } else {
            new Popup<>().warning(Res.get("shared.accountNameAlreadyUsed")).show();
        }
    }
}
Also used : Button(javafx.scene.control.Button) TradeCurrency(bisq.core.locale.TradeCurrency) ListView(javafx.scene.control.ListView) ListCell(javafx.scene.control.ListCell) Layout(bisq.desktop.util.Layout) FxmlView(bisq.desktop.common.view.FxmlView) BSFormatter(bisq.desktop.util.BSFormatter) AltCoinAddressValidator(bisq.core.payment.validation.AltCoinAddressValidator) Inject(javax.inject.Inject) PaymentAccountFactory(bisq.core.payment.PaymentAccountFactory) Tuple2(bisq.common.util.Tuple2) CryptoCurrencyForm(bisq.desktop.components.paymentmethods.CryptoCurrencyForm) Tuple3(bisq.common.util.Tuple3) VPos(javafx.geometry.VPos) Res(bisq.core.locale.Res) Callback(javafx.util.Callback) TitledGroupBg(bisq.desktop.components.TitledGroupBg) GridPane(javafx.scene.layout.GridPane) FormBuilder.addLabelListView(bisq.desktop.util.FormBuilder.addLabelListView) FormBuilder.add3ButtonsAfterGroup(bisq.desktop.util.FormBuilder.add3ButtonsAfterGroup) Popup(bisq.desktop.main.overlays.popups.Popup) Label(javafx.scene.control.Label) AutoTooltipLabel(bisq.desktop.components.AutoTooltipLabel) FormBuilder.addTitledGroupBg(bisq.desktop.util.FormBuilder.addTitledGroupBg) FormBuilder(bisq.desktop.util.FormBuilder) PaymentMethod(bisq.core.payment.payload.PaymentMethod) AccountAgeWitnessService(bisq.core.payment.AccountAgeWitnessService) TimeUnit(java.util.concurrent.TimeUnit) PaymentMethodForm(bisq.desktop.components.paymentmethods.PaymentMethodForm) PaymentAccount(bisq.core.payment.PaymentAccount) InputValidator(bisq.core.util.validation.InputValidator) FormBuilder.add2ButtonsAfterGroup(bisq.desktop.util.FormBuilder.add2ButtonsAfterGroup) CryptoCurrency(bisq.core.locale.CryptoCurrency) ImageUtil(bisq.desktop.util.ImageUtil) AnchorPane(javafx.scene.layout.AnchorPane) ImageView(javafx.scene.image.ImageView) AutoTooltipButton(bisq.desktop.components.AutoTooltipButton) UserThread(bisq.common.UserThread) ActivatableViewAndModel(bisq.desktop.common.view.ActivatableViewAndModel) ChangeListener(javafx.beans.value.ChangeListener) CryptoCurrency(bisq.core.locale.CryptoCurrency) TradeCurrency(bisq.core.locale.TradeCurrency) Popup(bisq.desktop.main.overlays.popups.Popup)

Example 9 with CryptoCurrency

use of bisq.core.locale.CryptoCurrency in project bisq-desktop by bisq-network.

the class PreferencesView method initializeDisplayCurrencies.

private void initializeDisplayCurrencies() {
    TitledGroupBg titledGroupBg = addTitledGroupBg(root, ++gridRow, 3, Res.get("setting.preferences.currenciesInList"), Layout.GROUP_DISTANCE);
    GridPane.setColumnSpan(titledGroupBg, 4);
    // noinspection unchecked
    preferredTradeCurrencyComboBox = addLabelComboBox(root, gridRow, Res.get("setting.preferences.prefCurrency"), Layout.FIRST_ROW_AND_GROUP_DISTANCE).second;
    preferredTradeCurrencyComboBox.setConverter(new StringConverter<TradeCurrency>() {

        @Override
        public String toString(TradeCurrency tradeCurrency) {
            // http://boschista.deviantart.com/journal/Cool-ASCII-Symbols-214218618
            return tradeCurrency.getDisplayPrefix() + tradeCurrency.getNameAndCode();
        }

        @Override
        public TradeCurrency fromString(String s) {
            return null;
        }
    });
    Tuple2<Label, ListView> fiatTuple = addLabelListView(root, ++gridRow, Res.get("setting.preferences.displayFiat"));
    GridPane.setValignment(fiatTuple.first, VPos.TOP);
    // noinspection unchecked
    fiatCurrenciesListView = fiatTuple.second;
    fiatCurrenciesListView.setMinHeight(2 * Layout.LIST_ROW_HEIGHT + 2);
    fiatCurrenciesListView.setPrefHeight(3 * Layout.LIST_ROW_HEIGHT + 2);
    Label placeholder = new AutoTooltipLabel(Res.get("setting.preferences.noFiat"));
    placeholder.setWrapText(true);
    fiatCurrenciesListView.setPlaceholder(placeholder);
    fiatCurrenciesListView.setCellFactory(new Callback<ListView<FiatCurrency>, ListCell<FiatCurrency>>() {

        @Override
        public ListCell<FiatCurrency> call(ListView<FiatCurrency> list) {
            return new ListCell<FiatCurrency>() {

                final Label label = new AutoTooltipLabel();

                final ImageView icon = ImageUtil.getImageViewById(ImageUtil.REMOVE_ICON);

                final Button removeButton = new AutoTooltipButton("", icon);

                final AnchorPane pane = new AnchorPane(label, removeButton);

                {
                    label.setLayoutY(5);
                    removeButton.setId("icon-button");
                    AnchorPane.setRightAnchor(removeButton, 0d);
                }

                @Override
                public void updateItem(final FiatCurrency item, boolean empty) {
                    super.updateItem(item, empty);
                    if (item != null && !empty) {
                        label.setText(item.getNameAndCode());
                        removeButton.setOnAction(e -> {
                            if (item.equals(preferences.getPreferredTradeCurrency())) {
                                new Popup<>().warning(Res.get("setting.preferences.cannotRemovePrefCurrency")).show();
                            } else {
                                preferences.removeFiatCurrency(item);
                                if (!allFiatCurrencies.contains(item))
                                    allFiatCurrencies.add(item);
                            }
                        });
                        setGraphic(pane);
                    } else {
                        setGraphic(null);
                        removeButton.setOnAction(null);
                    }
                }
            };
        }
    });
    Tuple2<Label, ListView> cryptoCurrenciesTuple = addLabelListView(root, gridRow, Res.get("setting.preferences.displayAltcoins"));
    GridPane.setValignment(cryptoCurrenciesTuple.first, VPos.TOP);
    GridPane.setMargin(cryptoCurrenciesTuple.first, new Insets(0, 0, 0, 20));
    // noinspection unchecked
    cryptoCurrenciesListView = cryptoCurrenciesTuple.second;
    GridPane.setColumnIndex(cryptoCurrenciesTuple.first, 2);
    GridPane.setColumnIndex(cryptoCurrenciesListView, 3);
    cryptoCurrenciesListView.setMinHeight(2 * Layout.LIST_ROW_HEIGHT + 2);
    cryptoCurrenciesListView.setPrefHeight(3 * Layout.LIST_ROW_HEIGHT + 2);
    placeholder = new AutoTooltipLabel(Res.get("setting.preferences.noAltcoins"));
    placeholder.setWrapText(true);
    cryptoCurrenciesListView.setPlaceholder(placeholder);
    cryptoCurrenciesListView.setCellFactory(new Callback<ListView<CryptoCurrency>, ListCell<CryptoCurrency>>() {

        @Override
        public ListCell<CryptoCurrency> call(ListView<CryptoCurrency> list) {
            return new ListCell<CryptoCurrency>() {

                final Label label = new AutoTooltipLabel();

                final ImageView icon = ImageUtil.getImageViewById(ImageUtil.REMOVE_ICON);

                final Button removeButton = new AutoTooltipButton("", icon);

                final AnchorPane pane = new AnchorPane(label, removeButton);

                {
                    label.setLayoutY(5);
                    removeButton.setId("icon-button");
                    AnchorPane.setRightAnchor(removeButton, 0d);
                }

                @Override
                public void updateItem(final CryptoCurrency item, boolean empty) {
                    super.updateItem(item, empty);
                    if (item != null && !empty) {
                        label.setText(item.getNameAndCode());
                        removeButton.setOnAction(e -> {
                            if (item.equals(preferences.getPreferredTradeCurrency())) {
                                new Popup<>().warning(Res.get("setting.preferences.cannotRemovePrefCurrency")).show();
                            } else {
                                preferences.removeCryptoCurrency(item);
                                if (!allCryptoCurrencies.contains(item))
                                    allCryptoCurrencies.add(item);
                            }
                        });
                        setGraphic(pane);
                    } else {
                        setGraphic(null);
                        removeButton.setOnAction(null);
                    }
                }
            };
        }
    });
    // noinspection unchecked
    fiatCurrenciesComboBox = addLabelComboBox(root, ++gridRow).second;
    fiatCurrenciesComboBox.setPromptText(Res.get("setting.preferences.addFiat"));
    fiatCurrenciesComboBox.setConverter(new StringConverter<FiatCurrency>() {

        @Override
        public String toString(FiatCurrency tradeCurrency) {
            return tradeCurrency.getNameAndCode();
        }

        @Override
        public FiatCurrency fromString(String s) {
            return null;
        }
    });
    Tuple2<Label, ComboBox> labelComboBoxTuple2 = addLabelComboBox(root, gridRow);
    // noinspection unchecked
    cryptoCurrenciesComboBox = labelComboBoxTuple2.second;
    GridPane.setColumnIndex(cryptoCurrenciesComboBox, 3);
    cryptoCurrenciesComboBox.setPromptText(Res.get("setting.preferences.addAltcoin"));
    cryptoCurrenciesComboBox.setConverter(new StringConverter<CryptoCurrency>() {

        @Override
        public String toString(CryptoCurrency tradeCurrency) {
            return tradeCurrency.getNameAndCode();
        }

        @Override
        public CryptoCurrency fromString(String s) {
            return null;
        }
    });
}
Also used : Button(javafx.scene.control.Button) Arrays(java.util.Arrays) Coin(org.bitcoinj.core.Coin) ListCell(javafx.scene.control.ListCell) Layout(bisq.desktop.util.Layout) StringUtils(org.apache.commons.lang3.StringUtils) BSFormatter(bisq.desktop.util.BSFormatter) InputTextField(bisq.desktop.components.InputTextField) ComboBox(javafx.scene.control.ComboBox) Res(bisq.core.locale.Res) BisqApp(bisq.desktop.app.BisqApp) Popup(bisq.desktop.main.overlays.popups.Popup) AutoTooltipLabel(bisq.desktop.components.AutoTooltipLabel) FormBuilder(bisq.desktop.util.FormBuilder) BlockChainExplorer(bisq.core.user.BlockChainExplorer) BaseCurrencyNetwork(bisq.core.btc.BaseCurrencyNetwork) Collectors(java.util.stream.Collectors) List(java.util.List) CryptoCurrency(bisq.core.locale.CryptoCurrency) DevEnv(bisq.common.app.DevEnv) AnchorPane(javafx.scene.layout.AnchorPane) AutoTooltipButton(bisq.desktop.components.AutoTooltipButton) Preferences(bisq.core.user.Preferences) UserThread(bisq.common.UserThread) CountryUtil(bisq.core.locale.CountryUtil) Activatable(bisq.desktop.common.model.Activatable) FeeService(bisq.core.provider.fee.FeeService) ObservableList(javafx.collections.ObservableList) TradeCurrency(bisq.core.locale.TradeCurrency) ListView(javafx.scene.control.ListView) FXCollections(javafx.collections.FXCollections) FiatCurrency(bisq.core.locale.FiatCurrency) FxmlView(bisq.desktop.common.view.FxmlView) Inject(javax.inject.Inject) Tuple2(bisq.common.util.Tuple2) Tuple3(bisq.common.util.Tuple3) Insets(javafx.geometry.Insets) Country(bisq.core.locale.Country) VPos(javafx.geometry.VPos) CurrencyUtil(bisq.core.locale.CurrencyUtil) Callback(javafx.util.Callback) TitledGroupBg(bisq.desktop.components.TitledGroupBg) GridPane(javafx.scene.layout.GridPane) Label(javafx.scene.control.Label) CheckBox(javafx.scene.control.CheckBox) BisqEnvironment(bisq.core.app.BisqEnvironment) StringConverter(javafx.util.StringConverter) TimeUnit(java.util.concurrent.TimeUnit) ImageUtil(bisq.desktop.util.ImageUtil) ImageView(javafx.scene.image.ImageView) LanguageUtil(bisq.core.locale.LanguageUtil) ActivatableViewAndModel(bisq.desktop.common.view.ActivatableViewAndModel) ChangeListener(javafx.beans.value.ChangeListener) Insets(javafx.geometry.Insets) ListCell(javafx.scene.control.ListCell) AutoTooltipLabel(bisq.desktop.components.AutoTooltipLabel) Label(javafx.scene.control.Label) CryptoCurrency(bisq.core.locale.CryptoCurrency) ListView(javafx.scene.control.ListView) Button(javafx.scene.control.Button) AutoTooltipButton(bisq.desktop.components.AutoTooltipButton) FiatCurrency(bisq.core.locale.FiatCurrency) ImageView(javafx.scene.image.ImageView) AutoTooltipLabel(bisq.desktop.components.AutoTooltipLabel) AnchorPane(javafx.scene.layout.AnchorPane) TradeCurrency(bisq.core.locale.TradeCurrency) ComboBox(javafx.scene.control.ComboBox) AutoTooltipButton(bisq.desktop.components.AutoTooltipButton) TitledGroupBg(bisq.desktop.components.TitledGroupBg)

Example 10 with CryptoCurrency

use of bisq.core.locale.CryptoCurrency in project bisq-core by bisq-network.

the class ReceiptPredicatesTest method testIsMatchingCurrency.

@Test
public void testIsMatchingCurrency() {
    Offer offer = mock(Offer.class);
    when(offer.getCurrencyCode()).thenReturn("USD");
    PaymentAccount account = mock(PaymentAccount.class);
    when(account.getTradeCurrencies()).thenReturn(Lists.newArrayList(new CryptoCurrency("BTC", "Bitcoin"), new CryptoCurrency("ETH", "Ether")));
    assertFalse(predicates.isMatchingCurrency(offer, account));
}
Also used : CryptoCurrency(bisq.core.locale.CryptoCurrency) Offer(bisq.core.offer.Offer) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

CryptoCurrency (bisq.core.locale.CryptoCurrency)10 PaymentAccount (bisq.core.payment.PaymentAccount)6 TradeCurrency (bisq.core.locale.TradeCurrency)5 FiatCurrency (bisq.core.locale.FiatCurrency)4 BSFormatter (bisq.desktop.util.BSFormatter)3 ArrayList (java.util.ArrayList)3 UserThread (bisq.common.UserThread)2 PersistenceProtoResolver (bisq.common.proto.persistable.PersistenceProtoResolver)2 Tuple2 (bisq.common.util.Tuple2)2 Tuple3 (bisq.common.util.Tuple3)2 CurrencyUtil (bisq.core.locale.CurrencyUtil)2 Res (bisq.core.locale.Res)2 OpenOfferManager (bisq.core.offer.OpenOfferManager)2 AccountAgeWitnessService (bisq.core.payment.AccountAgeWitnessService)2 CryptoCurrencyAccount (bisq.core.payment.CryptoCurrencyAccount)2 PaymentMethod (bisq.core.payment.payload.PaymentMethod)2 FeeService (bisq.core.provider.fee.FeeService)2 TradeManager (bisq.core.trade.TradeManager)2 Preferences (bisq.core.user.Preferences)2 User (bisq.core.user.User)2