From 78a72a2cc8298fa135da9d761b76f22b912e6add Mon Sep 17 00:00:00 2001 From: wiz Date: Sun, 15 Dec 2019 23:44:23 +0900 Subject: [PATCH 1/3] Add user preference combobox for BSQ block explorer with random default --- .../main/java/bisq/core/user/Preferences.java | 44 ++++++++++++++----- .../bisq/core/user/PreferencesPayload.java | 2 +- .../resources/i18n/displayStrings.properties | 1 + .../settings/preferences/PreferencesView.java | 25 +++++++++++ 4 files changed, 61 insertions(+), 11 deletions(-) diff --git a/core/src/main/java/bisq/core/user/Preferences.java b/core/src/main/java/bisq/core/user/Preferences.java index ae89c58a84f..54c9d0c5111 100644 --- a/core/src/main/java/bisq/core/user/Preferences.java +++ b/core/src/main/java/bisq/core/user/Preferences.java @@ -61,6 +61,7 @@ import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.Random; import java.util.stream.Collectors; import lombok.Getter; @@ -107,12 +108,18 @@ public final class Preferences implements PersistedDataHost, BridgeAddressProvid new BlockChainExplorer("BTC DAO-testnet explorer", "https://bisq.network/explorer/btc/dao_testnet/tx/", "https://bisq.network/explorer/btc/dao_testnet/address/") )); - public static final BlockChainExplorer BSQ_MAIN_NET_EXPLORER = new BlockChainExplorer("BSQ", "https://explorer.bisq.network/tx.html?tx=", - "https://explorer.bisq.network/Address.html?addr="); - private static final BlockChainExplorer BSQ_BETA_NET_EXPLORER = new BlockChainExplorer("BSQ", "http://explorer.betanet.bisq.network/tx.html?tx=", - "http://explorer.betanet.bisq.network/Address.html?addr="); - private static final BlockChainExplorer BSQ_TEST_NET_EXPLORER = new BlockChainExplorer("BSQ", "http://explorer.testnet.bisq.network/tx.html?tx=", - "http://explorer.testnet.bisq.network/Address.html?addr="); + public static final ArrayList BSQ_MAIN_NET_EXPLORERS = new ArrayList<>(Arrays.asList( + new BlockChainExplorer("bsq.wiz.biz (@wiz)", "https://bsq.wiz.biz/tx.html?tx=", "https://bsq.wiz.biz/Address.html?addr="), + new BlockChainExplorer("explorer.sqrrm.net (@sqrrm)", "https://explorer.sqrrm.net/tx.html?tx=", "https://explorer.sqrrm.net/Address.html?addr=") + )); + + private static final ArrayList BSQ_BETA_NET_EXPLORERS = new ArrayList<>(Collections.singletonList( + new BlockChainExplorer("BSQ", "http://explorer.betanet.bisq.network/tx.html?tx=", "http://explorer.betanet.bisq.network/Address.html?addr=") + )); + + private static final ArrayList BSQ_TEST_NET_EXPLORERS = new ArrayList<>(Collections.singletonList( + new BlockChainExplorer("BSQ", "http://explorer.testnet.bisq.network/tx.html?tx=", "http://explorer.testnet.bisq.network/Address.html?addr=") + )); // payload is initialized so the default values are available for Property initialization. @Setter @@ -213,6 +220,7 @@ public void readPersisted() { setPreferredTradeCurrency(preferredTradeCurrency); setFiatCurrencies(prefPayload.getFiatCurrencies()); setCryptoCurrencies(prefPayload.getCryptoCurrencies()); + setBsqBlockChainExplorer(prefPayload.getBsqBlockChainExplorer()); } else { prefPayload = new PreferencesPayload(); prefPayload.setUserLanguage(GlobalSettings.getLocale().getLanguage()); @@ -233,6 +241,10 @@ public void readPersisted() { throw new RuntimeException("BaseCurrencyNetwork not defined. BaseCurrencyNetwork=" + baseCurrencyNetwork); } + // if no preference is set, randomly select a BSQ block explorer for the user + ArrayList bsqExplorers = getBsqBlockChainExplorers(); + setBsqBlockChainExplorer(bsqExplorers.get((new Random()).nextInt(bsqExplorers.size()))); + prefPayload.setDirectoryChooserPath(Utilities.getSystemHomeDirectory()); prefPayload.setOfferBookChartScreenCurrencyCode(preferredTradeCurrency.getCode()); @@ -241,10 +253,6 @@ public void readPersisted() { prefPayload.setSellScreenCurrencyCode(preferredTradeCurrency.getCode()); } - prefPayload.setBsqBlockChainExplorer(baseCurrencyNetwork.isMainnet() ? BSQ_MAIN_NET_EXPLORER : - baseCurrencyNetwork.isDaoBetaNet() ? BSQ_BETA_NET_EXPLORER : - BSQ_TEST_NET_EXPLORER); - // We don't want to pass Preferences to all popups where the don't show again checkbox is used, so we use // that static lookup class to avoid static access to the Preferences directly. DontShowAgainLookup.setPreferences(this); @@ -531,6 +539,11 @@ private void setCryptoCurrencies(List currencies) { cryptoCurrenciesAsObservable.setAll(currencies.stream().distinct().collect(Collectors.toList())); } + public void setBsqBlockChainExplorer(BlockChainExplorer bsqBlockChainExplorer) { + prefPayload.setBsqBlockChainExplorer(bsqBlockChainExplorer); + persist(); + } + public void setBlockChainExplorerTestNet(BlockChainExplorer blockChainExplorerTestNet) { prefPayload.setBlockChainExplorerTestNet(blockChainExplorerTestNet); persist(); @@ -720,6 +733,17 @@ public ArrayList getBlockChainExplorers() { } } + public ArrayList getBsqBlockChainExplorers() + { + BaseCurrencyNetwork baseCurrencyNetwork = BisqEnvironment.getBaseCurrencyNetwork(); + if (baseCurrencyNetwork.isMainnet()) + return BSQ_MAIN_NET_EXPLORERS; + else if (baseCurrencyNetwork.isDaoBetaNet()) + return BSQ_BETA_NET_EXPLORERS; + else // testnet + return BSQ_TEST_NET_EXPLORERS; + } + public boolean showAgain(String key) { return !prefPayload.getDontShowAgainMap().containsKey(key) || !prefPayload.getDontShowAgainMap().get(key); } diff --git a/core/src/main/java/bisq/core/user/PreferencesPayload.java b/core/src/main/java/bisq/core/user/PreferencesPayload.java index 1cddc321787..4dc8396df5b 100644 --- a/core/src/main/java/bisq/core/user/PreferencesPayload.java +++ b/core/src/main/java/bisq/core/user/PreferencesPayload.java @@ -59,7 +59,7 @@ public final class PreferencesPayload implements PersistableEnvelope { private List cryptoCurrencies = new ArrayList<>(); private BlockChainExplorer blockChainExplorerMainNet; private BlockChainExplorer blockChainExplorerTestNet; - private BlockChainExplorer bsqBlockChainExplorer = Preferences.BSQ_MAIN_NET_EXPLORER; + private BlockChainExplorer bsqBlockChainExplorer; @Nullable private String backupDirectory; private boolean autoSelectArbitrators = true; diff --git a/core/src/main/resources/i18n/displayStrings.properties b/core/src/main/resources/i18n/displayStrings.properties index c0fb596fca9..958efbeb8b5 100644 --- a/core/src/main/resources/i18n/displayStrings.properties +++ b/core/src/main/resources/i18n/displayStrings.properties @@ -1023,6 +1023,7 @@ settings.tab.about=About setting.preferences.general=General preferences setting.preferences.explorer=Bitcoin block explorer +setting.preferences.explorer.bsq=BSQ block explorer setting.preferences.deviation=Max. deviation from market price setting.preferences.avoidStandbyMode=Avoid standby mode setting.preferences.deviationToLarge=Values higher than {0}% are not allowed. diff --git a/desktop/src/main/java/bisq/desktop/main/settings/preferences/PreferencesView.java b/desktop/src/main/java/bisq/desktop/main/settings/preferences/PreferencesView.java index 26c529f761c..709c7769318 100644 --- a/desktop/src/main/java/bisq/desktop/main/settings/preferences/PreferencesView.java +++ b/desktop/src/main/java/bisq/desktop/main/settings/preferences/PreferencesView.java @@ -102,6 +102,7 @@ public class PreferencesView extends ActivatableViewAndModel btcDenominationComboBox; private ComboBox blockChainExplorerComboBox; + private ComboBox bsqBlockChainExplorerComboBox; private ComboBox userLanguageComboBox; private ComboBox userCountryComboBox; private ComboBox preferredTradeCurrencyComboBox; @@ -132,6 +133,7 @@ public class PreferencesView extends ActivatableViewAndModel displayCurrenciesListChangeListener; private ObservableList blockExplorers; + private ObservableList bsqBlockChainExplorers; private ObservableList languageCodes; private ObservableList countries; private ObservableList fiatCurrencies; @@ -181,6 +183,7 @@ public PreferencesView(PreferencesViewModel model, @Override public void initialize() { blockExplorers = FXCollections.observableArrayList(preferences.getBlockChainExplorers()); + bsqBlockChainExplorers = FXCollections.observableArrayList(preferences.getBsqBlockChainExplorers()); languageCodes = FXCollections.observableArrayList(LanguageUtil.getUserLanguageCodes()); countries = FXCollections.observableArrayList(CountryUtil.getAllCountries()); fiatCurrencies = preferences.getFiatCurrenciesAsObservable(); @@ -237,11 +240,17 @@ private void initializeGeneralOptions() { Res.get("shared.country")); userCountryComboBox.setButtonCell(GUIUtil.getComboBoxButtonCell(Res.get("shared.country"), userCountryComboBox, false)); + blockChainExplorerComboBox = addComboBox(root, ++gridRow, Res.get("setting.preferences.explorer")); blockChainExplorerComboBox.setButtonCell(GUIUtil.getComboBoxButtonCell(Res.get("setting.preferences.explorer"), blockChainExplorerComboBox, false)); + bsqBlockChainExplorerComboBox = addComboBox(root, ++gridRow, + Res.get("setting.preferences.explorer.bsq")); + bsqBlockChainExplorerComboBox.setButtonCell(GUIUtil.getComboBoxButtonCell(Res.get("setting.preferences.explorer.bsq"), + bsqBlockChainExplorerComboBox, false)); + Tuple3 tuple = addTopLabelInputTextFieldSlideToggleButton(root, ++gridRow, Res.get("setting.preferences.txFee"), Res.get("setting.preferences.useCustomValue")); transactionFeeInputTextField = tuple.second; @@ -732,6 +741,21 @@ public BlockChainExplorer fromString(String string) { }); blockChainExplorerComboBox.setOnAction(e -> preferences.setBlockChainExplorer(blockChainExplorerComboBox.getSelectionModel().getSelectedItem())); + bsqBlockChainExplorerComboBox.setItems(bsqBlockChainExplorers); + bsqBlockChainExplorerComboBox.getSelectionModel().select(preferences.getBsqBlockChainExplorer()); + bsqBlockChainExplorerComboBox.setConverter(new StringConverter<>() { + @Override + public String toString(BlockChainExplorer bsqBlockChainExplorer) { + return bsqBlockChainExplorer.name; + } + + @Override + public BlockChainExplorer fromString(String string) { + return null; + } + }); + bsqBlockChainExplorerComboBox.setOnAction(e -> preferences.setBsqBlockChainExplorer(bsqBlockChainExplorerComboBox.getSelectionModel().getSelectedItem())); + deviationInputTextField.setText(FormattingUtils.formatPercentagePrice(preferences.getMaxPriceDistanceInPercent())); deviationInputTextField.textProperty().addListener(deviationListener); deviationInputTextField.focusedProperty().addListener(deviationFocusedListener); @@ -918,6 +942,7 @@ private void deactivateGeneralOptions() { userLanguageComboBox.setOnAction(null); userCountryComboBox.setOnAction(null); blockChainExplorerComboBox.setOnAction(null); + bsqBlockChainExplorerComboBox.setOnAction(null); deviationInputTextField.textProperty().removeListener(deviationListener); deviationInputTextField.focusedProperty().removeListener(deviationFocusedListener); transactionFeeInputTextField.focusedProperty().removeListener(transactionFeeFocusedListener); From e41df654b05891d958d94c240ca2af9e34c0fbbc Mon Sep 17 00:00:00 2001 From: wiz Date: Tue, 17 Dec 2019 19:41:32 +0900 Subject: [PATCH 2/3] Remove betanet and testnet BSQ block explorers --- .../main/java/bisq/core/user/Preferences.java | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/core/src/main/java/bisq/core/user/Preferences.java b/core/src/main/java/bisq/core/user/Preferences.java index 54c9d0c5111..ef332fa9292 100644 --- a/core/src/main/java/bisq/core/user/Preferences.java +++ b/core/src/main/java/bisq/core/user/Preferences.java @@ -113,14 +113,6 @@ public final class Preferences implements PersistedDataHost, BridgeAddressProvid new BlockChainExplorer("explorer.sqrrm.net (@sqrrm)", "https://explorer.sqrrm.net/tx.html?tx=", "https://explorer.sqrrm.net/Address.html?addr=") )); - private static final ArrayList BSQ_BETA_NET_EXPLORERS = new ArrayList<>(Collections.singletonList( - new BlockChainExplorer("BSQ", "http://explorer.betanet.bisq.network/tx.html?tx=", "http://explorer.betanet.bisq.network/Address.html?addr=") - )); - - private static final ArrayList BSQ_TEST_NET_EXPLORERS = new ArrayList<>(Collections.singletonList( - new BlockChainExplorer("BSQ", "http://explorer.testnet.bisq.network/tx.html?tx=", "http://explorer.testnet.bisq.network/Address.html?addr=") - )); - // payload is initialized so the default values are available for Property initialization. @Setter @Delegate(excludes = ExcludesDelegateMethods.class) @@ -733,16 +725,7 @@ public ArrayList getBlockChainExplorers() { } } - public ArrayList getBsqBlockChainExplorers() - { - BaseCurrencyNetwork baseCurrencyNetwork = BisqEnvironment.getBaseCurrencyNetwork(); - if (baseCurrencyNetwork.isMainnet()) - return BSQ_MAIN_NET_EXPLORERS; - else if (baseCurrencyNetwork.isDaoBetaNet()) - return BSQ_BETA_NET_EXPLORERS; - else // testnet - return BSQ_TEST_NET_EXPLORERS; - } + public ArrayList getBsqBlockChainExplorers() { return BSQ_MAIN_NET_EXPLORERS; } public boolean showAgain(String key) { return !prefPayload.getDontShowAgainMap().containsKey(key) || !prefPayload.getDontShowAgainMap().get(key); From 8b23cacd2c37d7d0234c8c82fb26e2ba7e440a94 Mon Sep 17 00:00:00 2001 From: wiz Date: Wed, 18 Dec 2019 16:38:31 +0900 Subject: [PATCH 3/3] Always check if a valid BSQ block explorer is set --- core/src/main/java/bisq/core/user/Preferences.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/bisq/core/user/Preferences.java b/core/src/main/java/bisq/core/user/Preferences.java index ef332fa9292..7d826b7a47b 100644 --- a/core/src/main/java/bisq/core/user/Preferences.java +++ b/core/src/main/java/bisq/core/user/Preferences.java @@ -233,10 +233,6 @@ public void readPersisted() { throw new RuntimeException("BaseCurrencyNetwork not defined. BaseCurrencyNetwork=" + baseCurrencyNetwork); } - // if no preference is set, randomly select a BSQ block explorer for the user - ArrayList bsqExplorers = getBsqBlockChainExplorers(); - setBsqBlockChainExplorer(bsqExplorers.get((new Random()).nextInt(bsqExplorers.size()))); - prefPayload.setDirectoryChooserPath(Utilities.getSystemHomeDirectory()); prefPayload.setOfferBookChartScreenCurrencyCode(preferredTradeCurrency.getCode()); @@ -256,6 +252,12 @@ public void readPersisted() { useStandbyModeProperty.set(prefPayload.isUseStandbyMode()); cssThemeProperty.set(prefPayload.getCssTheme()); + // if no valid block explorer is set, randomly select a valid BSQ block explorer + ArrayList bsqExplorers = getBsqBlockChainExplorers(); + BlockChainExplorer bsqExplorer = getBsqBlockChainExplorer(); + if (bsqExplorer == null || bsqExplorers.contains(bsqExplorer) == false) + setBsqBlockChainExplorer(bsqExplorers.get((new Random()).nextInt(bsqExplorers.size()))); + tradeCurrenciesAsObservable.addAll(prefPayload.getFiatCurrencies()); tradeCurrenciesAsObservable.addAll(prefPayload.getCryptoCurrencies()); dontShowAgainMapAsObservable.putAll(getDontShowAgainMap());