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(",")));
}
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);
}
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())));
}
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);
}
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();
}
Aggregations