Search in sources :

Example 6 with BaseCurrencyNetwork

use of bisq.core.btc.BaseCurrencyNetwork in project bisq-desktop by bisq-network.

the class PreferencesView method initializeGeneralOptions.

// /////////////////////////////////////////////////////////////////////////////////////////
// Initialize
// /////////////////////////////////////////////////////////////////////////////////////////
private void initializeGeneralOptions() {
    TitledGroupBg titledGroupBg = addTitledGroupBg(root, gridRow, 8, Res.get("setting.preferences.general"));
    GridPane.setColumnSpan(titledGroupBg, 4);
    // selectBaseCurrencyNetwork
    // noinspection unchecked
    selectBaseCurrencyNetworkComboBox = addLabelComboBox(root, gridRow, Res.getWithCol("settings.preferences.selectCurrencyNetwork"), Layout.FIRST_ROW_DISTANCE).second;
    selectBaseCurrencyNetworkComboBox.setConverter(new StringConverter<BaseCurrencyNetwork>() {

        @Override
        public String toString(BaseCurrencyNetwork baseCurrencyNetwork) {
            return DevEnv.isDevMode() ? (baseCurrencyNetwork.getCurrencyName() + "_" + baseCurrencyNetwork.getNetwork()) : baseCurrencyNetwork.getCurrencyName();
        }

        @Override
        public BaseCurrencyNetwork fromString(String string) {
            return null;
        }
    });
    // userLanguage
    // noinspection unchecked
    userLanguageComboBox = addLabelComboBox(root, ++gridRow, Res.getWithCol("shared.language")).second;
    // userCountry
    // noinspection unchecked
    userCountryComboBox = addLabelComboBox(root, ++gridRow, Res.getWithCol("shared.country")).second;
    // blockChainExplorer
    // noinspection unchecked
    blockChainExplorerComboBox = addLabelComboBox(root, ++gridRow, Res.get("setting.preferences.explorer")).second;
    // transactionFee
    Tuple3<Label, InputTextField, CheckBox> tuple = addLabelInputTextFieldCheckBox(root, ++gridRow, Res.get("setting.preferences.txFee"), Res.get("setting.preferences.useCustomValue"));
    transactionFeeInputTextField = tuple.second;
    useCustomFeeCheckbox = tuple.third;
    useCustomFeeCheckboxListener = (observable, oldValue, newValue) -> {
        preferences.setUseCustomWithdrawalTxFee(newValue);
        transactionFeeInputTextField.setEditable(newValue);
        if (!newValue) {
            transactionFeeInputTextField.setText(String.valueOf(feeService.getTxFeePerByte().value));
            try {
                preferences.setWithdrawalTxFeeInBytes(feeService.getTxFeePerByte().value);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        preferences.setUseCustomWithdrawalTxFee(newValue);
    };
    transactionFeeFocusedListener = (o, oldValue, newValue) -> {
        if (oldValue && !newValue) {
            String estimatedFee = String.valueOf(feeService.getTxFeePerByte().value);
            try {
                int withdrawalTxFeePerByte = Integer.parseInt(transactionFeeInputTextField.getText());
                final long minFeePerByte = BisqEnvironment.getBaseCurrencyNetwork().getDefaultMinFeePerByte();
                if (withdrawalTxFeePerByte < minFeePerByte) {
                    new Popup<>().warning(Res.get("setting.preferences.txFeeMin", minFeePerByte)).show();
                    transactionFeeInputTextField.setText(estimatedFee);
                } else if (withdrawalTxFeePerByte > 5000) {
                    new Popup<>().warning(Res.get("setting.preferences.txFeeTooLarge")).show();
                    transactionFeeInputTextField.setText(estimatedFee);
                } else {
                    preferences.setWithdrawalTxFeeInBytes(withdrawalTxFeePerByte);
                }
            } catch (NumberFormatException t) {
                log.error(t.toString());
                t.printStackTrace();
                new Popup<>().warning(Res.get("validation.integerOnly")).show();
                transactionFeeInputTextField.setText(estimatedFee);
            } catch (Throwable t) {
                log.error(t.toString());
                t.printStackTrace();
                new Popup<>().warning(Res.get("validation.inputError", t.getMessage())).show();
                transactionFeeInputTextField.setText(estimatedFee);
            }
        }
    };
    transactionFeeChangeListener = (observable, oldValue, newValue) -> transactionFeeInputTextField.setText(String.valueOf(feeService.getTxFeePerByte().value));
    // deviation
    deviationInputTextField = addLabelInputTextField(root, ++gridRow, Res.get("setting.preferences.deviation")).second;
    deviationListener = (observable, oldValue, newValue) -> {
        try {
            double value = formatter.parsePercentStringToDouble(newValue);
            final double maxDeviation = 0.5;
            if (value <= maxDeviation) {
                preferences.setMaxPriceDistanceInPercent(value);
            } else {
                new Popup<>().warning(Res.get("setting.preferences.deviationToLarge", maxDeviation * 100)).show();
                UserThread.runAfter(() -> deviationInputTextField.setText(formatter.formatPercentagePrice(preferences.getMaxPriceDistanceInPercent())), 100, TimeUnit.MILLISECONDS);
            }
        } catch (NumberFormatException t) {
            log.error("Exception at parseDouble deviation: " + t.toString());
            UserThread.runAfter(() -> deviationInputTextField.setText(formatter.formatPercentagePrice(preferences.getMaxPriceDistanceInPercent())), 100, TimeUnit.MILLISECONDS);
        }
    };
    deviationFocusedListener = (observable1, oldValue1, newValue1) -> {
        if (oldValue1 && !newValue1)
            UserThread.runAfter(() -> deviationInputTextField.setText(formatter.formatPercentagePrice(preferences.getMaxPriceDistanceInPercent())), 100, TimeUnit.MILLISECONDS);
    };
    // autoSelectArbitrators
    autoSelectArbitratorsCheckBox = addLabelCheckBox(root, ++gridRow, Res.get("setting.preferences.autoSelectArbitrators"), "").second;
    // ignoreTraders
    ignoreTradersListInputTextField = addLabelInputTextField(root, ++gridRow, Res.get("setting.preferences.ignorePeers")).second;
    ignoreTradersListListener = (observable, oldValue, newValue) -> preferences.setIgnoreTradersList(Arrays.asList(StringUtils.deleteWhitespace(newValue).replace(":9999", "").replace(".onion", "").split(",")));
}
Also used : InputTextField(bisq.desktop.components.InputTextField) AutoTooltipLabel(bisq.desktop.components.AutoTooltipLabel) Label(javafx.scene.control.Label) CheckBox(javafx.scene.control.CheckBox) Popup(bisq.desktop.main.overlays.popups.Popup) BaseCurrencyNetwork(bisq.core.btc.BaseCurrencyNetwork) TitledGroupBg(bisq.desktop.components.TitledGroupBg)

Example 7 with BaseCurrencyNetwork

use of bisq.core.btc.BaseCurrencyNetwork in project bisq-desktop by bisq-network.

the class InteracETransferValidatorTest method setup.

@Before
public void setup() {
    final BaseCurrencyNetwork baseCurrencyNetwork = BisqEnvironment.getBaseCurrencyNetwork();
    final String currencyCode = baseCurrencyNetwork.getCurrencyCode();
    Res.setBaseCurrencyCode(currencyCode);
    Res.setBaseCurrencyName(baseCurrencyNetwork.getCurrencyName());
    CurrencyUtil.setBaseCurrencyCode(currencyCode);
}
Also used : BaseCurrencyNetwork(bisq.core.btc.BaseCurrencyNetwork) Before(org.junit.Before)

Example 8 with BaseCurrencyNetwork

use of bisq.core.btc.BaseCurrencyNetwork in project bisq-desktop by bisq-network.

the class BisqApp method init.

// NOTE: This method is not called on the JavaFX Application Thread.
@Override
public void init() throws Exception {
    String logPath = Paths.get(bisqEnvironment.getProperty(AppOptionKeys.APP_DATA_DIR_KEY), "bisq").toString();
    Log.setup(logPath);
    log.info("Log files under: " + logPath);
    Utilities.printSysInfo();
    Log.setLevel(Level.toLevel(bisqEnvironment.getRequiredProperty(CommonOptionKeys.LOG_LEVEL_KEY)));
    UserThread.setExecutor(Platform::runLater);
    UserThread.setTimerClass(UITimer.class);
    shutDownHandler = this::stop;
    // setup UncaughtExceptionHandler
    Thread.UncaughtExceptionHandler handler = (thread, throwable) -> {
        // Might come from another thread
        if (throwable.getCause() != null && throwable.getCause().getCause() != null && throwable.getCause().getCause() instanceof BlockStoreException) {
            log.error(throwable.getMessage());
        } else if (throwable instanceof ClassCastException && "sun.awt.image.BufImgSurfaceData cannot be cast to sun.java2d.xr.XRSurfaceData".equals(throwable.getMessage())) {
            log.warn(throwable.getMessage());
        } else {
            log.error("Uncaught Exception from thread " + Thread.currentThread().getName());
            log.error("throwableMessage= " + throwable.getMessage());
            log.error("throwableClass= " + throwable.getClass());
            log.error("Stack trace:\n" + ExceptionUtils.getStackTrace(throwable));
            throwable.printStackTrace();
            UserThread.execute(() -> showErrorPopup(throwable, false));
        }
    };
    Thread.setDefaultUncaughtExceptionHandler(handler);
    Thread.currentThread().setUncaughtExceptionHandler(handler);
    try {
        Utilities.checkCryptoPolicySetup();
    } catch (NoSuchAlgorithmException | LimitedKeyStrengthException e) {
        e.printStackTrace();
        UserThread.execute(() -> showErrorPopup(e, true));
    }
    Security.addProvider(new BouncyCastleProvider());
    final BaseCurrencyNetwork baseCurrencyNetwork = BisqEnvironment.getBaseCurrencyNetwork();
    final String currencyCode = baseCurrencyNetwork.getCurrencyCode();
    Res.setBaseCurrencyCode(currencyCode);
    Res.setBaseCurrencyName(baseCurrencyNetwork.getCurrencyName());
    CurrencyUtil.setBaseCurrencyCode(currencyCode);
    Capabilities.setSupportedCapabilities(new ArrayList<>(Arrays.asList(Capabilities.Capability.TRADE_STATISTICS.ordinal(), Capabilities.Capability.TRADE_STATISTICS_2.ordinal(), Capabilities.Capability.ACCOUNT_AGE_WITNESS.ordinal(), Capabilities.Capability.COMP_REQUEST.ordinal(), Capabilities.Capability.VOTE.ordinal())));
}
Also used : StageStyle(javafx.stage.StageStyle) ManualPayoutTxWindow(bisq.desktop.main.overlays.windows.ManualPayoutTxWindow) Arrays(java.util.Arrays) Utilities(bisq.common.util.Utilities) DaoManager(bisq.core.dao.DaoManager) Key(com.google.inject.Key) LoggerFactory(org.slf4j.LoggerFactory) Security(java.security.Security) StackPane(javafx.scene.layout.StackPane) DisputeManager(bisq.core.arbitration.DisputeManager) User(bisq.core.user.User) Application(javafx.application.Application) Parent(javafx.scene.Parent) ViewLoader(bisq.desktop.common.view.ViewLoader) AddressEntryList(bisq.core.btc.AddressEntryList) Res(bisq.core.locale.Res) SendAlertMessageWindow(bisq.desktop.main.overlays.windows.SendAlertMessageWindow) BlockStoreException(org.bitcoinj.store.BlockStoreException) INITIAL_SCENE_WIDTH(bisq.desktop.util.Layout.INITIAL_SCENE_WIDTH) VoteService(bisq.core.dao.vote.VoteService) Pane(javafx.scene.layout.Pane) Navigation(bisq.desktop.Navigation) Popup(bisq.desktop.main.overlays.popups.Popup) ClosedTradableManager(bisq.core.trade.closed.ClosedTradableManager) Capabilities(bisq.common.app.Capabilities) P2PService(bisq.network.p2p.P2PService) CachingViewLoader(bisq.desktop.common.view.CachingViewLoader) ArbitratorManager(bisq.core.arbitration.ArbitratorManager) AutoTooltipLabel(bisq.desktop.components.AutoTooltipLabel) FilterManager(bisq.core.filter.FilterManager) PersistedDataHost(bisq.common.proto.persistable.PersistedDataHost) ShowWalletDataWindow(bisq.desktop.main.overlays.windows.ShowWalletDataWindow) KeyEvent(javafx.scene.input.KeyEvent) BaseCurrencyNetwork(bisq.core.btc.BaseCurrencyNetwork) BsqWalletService(bisq.core.btc.wallet.BsqWalletService) Platform(javafx.application.Platform) List(java.util.List) WalletsSetup(bisq.core.btc.wallet.WalletsSetup) DevEnv(bisq.common.app.DevEnv) TradeManager(bisq.core.trade.TradeManager) Logger(ch.qos.logback.classic.Logger) EmptyWalletWindow(bisq.desktop.main.overlays.windows.EmptyWalletWindow) AppOptionKeys(bisq.core.app.AppOptionKeys) Preferences(bisq.core.user.Preferences) UserThread(bisq.common.UserThread) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) EventStreams(org.reactfx.EventStreams) INITIAL_SCENE_HEIGHT(bisq.desktop.util.Layout.INITIAL_SCENE_HEIGHT) ExceptionUtils(org.apache.commons.lang3.exception.ExceptionUtils) BtcWalletService(bisq.core.btc.wallet.BtcWalletService) Scene(javafx.scene.Scene) AlertManager(bisq.core.alert.AlertManager) WalletService(bisq.core.btc.wallet.WalletService) CommonOptionKeys(bisq.common.CommonOptionKeys) ArrayList(java.util.ArrayList) WalletsManager(bisq.core.btc.wallet.WalletsManager) UITimer(bisq.desktop.common.UITimer) CurrencyUtil(bisq.core.locale.CurrencyUtil) Profiler(bisq.common.util.Profiler) LimitedKeyStrengthException(bisq.common.crypto.LimitedKeyStrengthException) InjectorViewFactory(bisq.desktop.common.view.guice.InjectorViewFactory) KeyCode(javafx.scene.input.KeyCode) Version(bisq.common.app.Version) Modality(javafx.stage.Modality) Label(javafx.scene.control.Label) FailedTradesManager(bisq.core.trade.failed.FailedTradesManager) ResultHandler(bisq.common.handlers.ResultHandler) Log(bisq.common.app.Log) IOException(java.io.IOException) BisqEnvironment(bisq.core.app.BisqEnvironment) Names(com.google.inject.name.Names) OpenOfferManager(bisq.core.offer.OpenOfferManager) BouncyCastleProvider(org.bouncycastle.jce.provider.BouncyCastleProvider) DebugView(bisq.desktop.main.debug.DebugView) Injector(com.google.inject.Injector) TimeUnit(java.util.concurrent.TimeUnit) View(bisq.desktop.common.view.View) MainView(bisq.desktop.main.MainView) Level(ch.qos.logback.classic.Level) Stage(javafx.stage.Stage) ImageUtil(bisq.desktop.util.ImageUtil) Paths(java.nio.file.Paths) Storage(bisq.common.storage.Storage) FilterWindow(bisq.desktop.main.overlays.windows.FilterWindow) SystemTray(bisq.desktop.SystemTray) Guice(com.google.inject.Guice) Image(javafx.scene.image.Image) ProposalCollectionsService(bisq.core.dao.proposal.ProposalCollectionsService) Platform(javafx.application.Platform) BlockStoreException(org.bitcoinj.store.BlockStoreException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) UserThread(bisq.common.UserThread) LimitedKeyStrengthException(bisq.common.crypto.LimitedKeyStrengthException) BaseCurrencyNetwork(bisq.core.btc.BaseCurrencyNetwork) BouncyCastleProvider(org.bouncycastle.jce.provider.BouncyCastleProvider)

Example 9 with BaseCurrencyNetwork

use of bisq.core.btc.BaseCurrencyNetwork in project bisq-core by bisq-network.

the class AltCoinAddressValidatorTest method setup.

@Before
public void setup() {
    final BaseCurrencyNetwork baseCurrencyNetwork = BisqEnvironment.getBaseCurrencyNetwork();
    final String currencyCode = baseCurrencyNetwork.getCurrencyCode();
    Res.setBaseCurrencyCode(currencyCode);
    Res.setBaseCurrencyName(baseCurrencyNetwork.getCurrencyName());
    CurrencyUtil.setBaseCurrencyCode(currencyCode);
}
Also used : BaseCurrencyNetwork(bisq.core.btc.BaseCurrencyNetwork) Before(org.junit.Before)

Example 10 with BaseCurrencyNetwork

use of bisq.core.btc.BaseCurrencyNetwork in project bisq-core by bisq-network.

the class Preferences method readPersisted.

@Override
public void readPersisted() {
    PreferencesPayload persisted = storage.initAndGetPersistedWithFileName("PreferencesPayload", 100);
    final BaseCurrencyNetwork baseCurrencyNetwork = BisqEnvironment.getBaseCurrencyNetwork();
    TradeCurrency preferredTradeCurrency;
    if (persisted != null) {
        prefPayload = persisted;
        GlobalSettings.setLocale(new Locale(prefPayload.getUserLanguage(), prefPayload.getUserCountry().code));
        GlobalSettings.setUseAnimations(prefPayload.isUseAnimations());
        preferredTradeCurrency = checkNotNull(prefPayload.getPreferredTradeCurrency(), "preferredTradeCurrency must not be null");
        setPreferredTradeCurrency(preferredTradeCurrency);
        setFiatCurrencies(prefPayload.getFiatCurrencies());
        setCryptoCurrencies(prefPayload.getCryptoCurrencies());
    } else {
        prefPayload = new PreferencesPayload();
        prefPayload.setUserLanguage(GlobalSettings.getLocale().getLanguage());
        prefPayload.setUserCountry(CountryUtil.getDefaultCountry());
        GlobalSettings.setLocale(new Locale(prefPayload.getUserLanguage(), prefPayload.getUserCountry().code));
        preferredTradeCurrency = checkNotNull(CurrencyUtil.getCurrencyByCountryCode(prefPayload.getUserCountry().code), "preferredTradeCurrency must not be null");
        prefPayload.setPreferredTradeCurrency(preferredTradeCurrency);
        setFiatCurrencies(CurrencyUtil.getMainFiatCurrencies());
        setCryptoCurrencies(CurrencyUtil.getMainCryptoCurrencies());
        switch(baseCurrencyNetwork.getCurrencyCode()) {
            case "BTC":
                setBlockChainExplorerMainNet(BTC_MAIN_NET_EXPLORERS.get(0));
                setBlockChainExplorerTestNet(BTC_TEST_NET_EXPLORERS.get(0));
                break;
            case "LTC":
                setBlockChainExplorerMainNet(LTC_MAIN_NET_EXPLORERS.get(0));
                setBlockChainExplorerTestNet(LTC_TEST_NET_EXPLORERS.get(0));
                break;
            case "DASH":
                setBlockChainExplorerMainNet(DASH_MAIN_NET_EXPLORERS.get(0));
                setBlockChainExplorerTestNet(DASH_TEST_NET_EXPLORERS.get(0));
                break;
            default:
                throw new RuntimeException("BaseCurrencyNetwork not defined. BaseCurrencyNetwork=" + baseCurrencyNetwork);
        }
        prefPayload.setDirectoryChooserPath(Utilities.getSystemHomeDirectory());
        prefPayload.setOfferBookChartScreenCurrencyCode(preferredTradeCurrency.getCode());
        prefPayload.setTradeChartsScreenCurrencyCode(preferredTradeCurrency.getCode());
        prefPayload.setBuyScreenCurrencyCode(preferredTradeCurrency.getCode());
        prefPayload.setSellScreenCurrencyCode(preferredTradeCurrency.getCode());
    }
    prefPayload.setBsqBlockChainExplorer(baseCurrencyNetwork.isMainnet() ? BSQ_MAIN_NET_EXPLORER : BSQ_TEST_NET_EXPLORER);
    // We don't want to pass Preferences to all popups where the dont show again checkbox is used, so we use
    // that static lookup class to avoid static access to the Preferences directly.
    DontShowAgainLookup.setPreferences(this);
    GlobalSettings.setDefaultTradeCurrency(preferredTradeCurrency);
    // set all properties
    useAnimationsProperty.set(prefPayload.isUseAnimations());
    useCustomWithdrawalTxFeeProperty.set(prefPayload.isUseCustomWithdrawalTxFee());
    withdrawalTxFeeInBytesProperty.set(prefPayload.getWithdrawalTxFeeInBytes());
    tradeCurrenciesAsObservable.addAll(prefPayload.getFiatCurrencies());
    tradeCurrenciesAsObservable.addAll(prefPayload.getCryptoCurrencies());
    // Override settings with options if set
    if (useTorFlagFromOptions != null && !useTorFlagFromOptions.isEmpty()) {
        if (useTorFlagFromOptions.equals("false"))
            setUseTorForBitcoinJ(false);
        else if (useTorFlagFromOptions.equals("true"))
            setUseTorForBitcoinJ(true);
    }
    if (btcNodesFromOptions != null && !btcNodesFromOptions.isEmpty()) {
        if (getBitcoinNodes() != null && !getBitcoinNodes().equals(btcNodesFromOptions)) {
            log.warn("The Bitcoin node(s) from the program argument and the one(s) persisted in the UI are different. " + "The Bitcoin node(s) {} from the program argument will be used.", btcNodesFromOptions);
        }
        setBitcoinNodes(btcNodesFromOptions);
        setBitcoinNodesOptionOrdinal(BitcoinNodes.BitcoinNodesOption.CUSTOM.ordinal());
    }
    initialReadDone = true;
    persist();
}
Also used : Locale(java.util.Locale) TradeCurrency(bisq.core.locale.TradeCurrency) BaseCurrencyNetwork(bisq.core.btc.BaseCurrencyNetwork)

Aggregations

BaseCurrencyNetwork (bisq.core.btc.BaseCurrencyNetwork)10 Before (org.junit.Before)4 UserThread (bisq.common.UserThread)2 DevEnv (bisq.common.app.DevEnv)2 BisqEnvironment (bisq.core.app.BisqEnvironment)2 Res (bisq.core.locale.Res)2 Label (javafx.scene.control.Label)2 CommonOptionKeys (bisq.common.CommonOptionKeys)1 Capabilities (bisq.common.app.Capabilities)1 Log (bisq.common.app.Log)1 Version (bisq.common.app.Version)1 LimitedKeyStrengthException (bisq.common.crypto.LimitedKeyStrengthException)1 ResultHandler (bisq.common.handlers.ResultHandler)1 PersistedDataHost (bisq.common.proto.persistable.PersistedDataHost)1 Storage (bisq.common.storage.Storage)1 Profiler (bisq.common.util.Profiler)1 Tuple2 (bisq.common.util.Tuple2)1 Utilities (bisq.common.util.Utilities)1 AlertManager (bisq.core.alert.AlertManager)1 AppOptionKeys (bisq.core.app.AppOptionKeys)1