mirror of
https://github.com/bisq-network/bisq.git
synced 2025-02-23 15:00:30 +01:00
Add user preference combobox for BSQ block explorer with random default
This commit is contained in:
parent
14bec2ff4b
commit
78a72a2cc8
4 changed files with 61 additions and 11 deletions
|
@ -61,6 +61,7 @@ import java.util.Collections;
|
|||
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<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=")
|
||||
));
|
||||
|
||||
private static final ArrayList<BlockChainExplorer> 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<BlockChainExplorer> 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 final class Preferences implements PersistedDataHost, BridgeAddressProvid
|
|||
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 final class Preferences implements PersistedDataHost, BridgeAddressProvid
|
|||
throw new RuntimeException("BaseCurrencyNetwork not defined. BaseCurrencyNetwork=" + baseCurrencyNetwork);
|
||||
}
|
||||
|
||||
// if no preference is set, randomly select a BSQ block explorer for the user
|
||||
ArrayList<BlockChainExplorer> bsqExplorers = getBsqBlockChainExplorers();
|
||||
setBsqBlockChainExplorer(bsqExplorers.get((new Random()).nextInt(bsqExplorers.size())));
|
||||
|
||||
prefPayload.setDirectoryChooserPath(Utilities.getSystemHomeDirectory());
|
||||
|
||||
prefPayload.setOfferBookChartScreenCurrencyCode(preferredTradeCurrency.getCode());
|
||||
|
@ -241,10 +253,6 @@ public final class Preferences implements PersistedDataHost, BridgeAddressProvid
|
|||
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 @@ public final class Preferences implements PersistedDataHost, BridgeAddressProvid
|
|||
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 final class Preferences implements PersistedDataHost, BridgeAddressProvid
|
|||
}
|
||||
}
|
||||
|
||||
public ArrayList<BlockChainExplorer> 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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -181,6 +183,7 @@ public class PreferencesView extends ActivatableViewAndModel<GridPane, Preferenc
|
|||
@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 @@ public class PreferencesView extends ActivatableViewAndModel<GridPane, Preferenc
|
|||
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;
|
||||
|
@ -732,6 +741,21 @@ public class PreferencesView extends ActivatableViewAndModel<GridPane, Preferenc
|
|||
});
|
||||
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 @@ public class PreferencesView extends ActivatableViewAndModel<GridPane, Preferenc
|
|||
userLanguageComboBox.setOnAction(null);
|
||||
userCountryComboBox.setOnAction(null);
|
||||
blockChainExplorerComboBox.setOnAction(null);
|
||||
bsqBlockChainExplorerComboBox.setOnAction(null);
|
||||
deviationInputTextField.textProperty().removeListener(deviationListener);
|
||||
deviationInputTextField.focusedProperty().removeListener(deviationFocusedListener);
|
||||
transactionFeeInputTextField.focusedProperty().removeListener(transactionFeeFocusedListener);
|
||||
|
|
Loading…
Add table
Reference in a new issue