Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add user preference combobox for BSQ block explorer with random default #3792

Merged
merged 3 commits into from
Dec 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 19 additions & 10 deletions core/src/main/java/bisq/core/user/Preferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -107,12 +108,10 @@ 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<BlockChainExplorer> 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=")
));

// payload is initialized so the default values are available for Property initialization.
@Setter
Expand Down Expand Up @@ -213,6 +212,7 @@ public void readPersisted() {
setPreferredTradeCurrency(preferredTradeCurrency);
setFiatCurrencies(prefPayload.getFiatCurrencies());
setCryptoCurrencies(prefPayload.getCryptoCurrencies());
setBsqBlockChainExplorer(prefPayload.getBsqBlockChainExplorer());
} else {
prefPayload = new PreferencesPayload();
prefPayload.setUserLanguage(GlobalSettings.getLocale().getLanguage());
Expand Down Expand Up @@ -241,10 +241,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);
Expand All @@ -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<BlockChainExplorer> 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());
Expand Down Expand Up @@ -531,6 +533,11 @@ private void setCryptoCurrencies(List<CryptoCurrency> 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();
Expand Down Expand Up @@ -720,6 +727,8 @@ public ArrayList<BlockChainExplorer> getBlockChainExplorers() {
}
}

public ArrayList<BlockChainExplorer> getBsqBlockChainExplorers() { return BSQ_MAIN_NET_EXPLORERS; }

public boolean showAgain(String key) {
return !prefPayload.getDontShowAgainMap().containsKey(key) || !prefPayload.getDontShowAgainMap().get(key);
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/bisq/core/user/PreferencesPayload.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public final class PreferencesPayload implements PersistableEnvelope {
private List<CryptoCurrency> 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;
Expand Down
1 change: 1 addition & 0 deletions core/src/main/resources/i18n/displayStrings.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ public class PreferencesView extends ActivatableViewAndModel<GridPane, Preferenc
// not supported yet
//private ComboBox<String> btcDenominationComboBox;
private ComboBox<BlockChainExplorer> blockChainExplorerComboBox;
private ComboBox<BlockChainExplorer> bsqBlockChainExplorerComboBox;
private ComboBox<String> userLanguageComboBox;
private ComboBox<Country> userCountryComboBox;
private ComboBox<TradeCurrency> preferredTradeCurrencyComboBox;
Expand Down Expand Up @@ -132,6 +133,7 @@ public class PreferencesView extends ActivatableViewAndModel<GridPane, Preferenc
private Button resetDontShowAgainButton, resyncDaoButton;
// private ListChangeListener<TradeCurrency> displayCurrenciesListChangeListener;
private ObservableList<BlockChainExplorer> blockExplorers;
private ObservableList<BlockChainExplorer> bsqBlockChainExplorers;
private ObservableList<String> languageCodes;
private ObservableList<Country> countries;
private ObservableList<FiatCurrency> fiatCurrencies;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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<Label, InputTextField, ToggleButton> tuple = addTopLabelInputTextFieldSlideToggleButton(root, ++gridRow,
Res.get("setting.preferences.txFee"), Res.get("setting.preferences.useCustomValue"));
transactionFeeInputTextField = tuple.second;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down