From 0dcc20cd035422e8f2a96270efff0634fa091720 Mon Sep 17 00:00:00 2001 From: Christoph Atteneder Date: Mon, 14 Oct 2019 11:27:25 +0200 Subject: [PATCH 1/2] Clean up dead code parts --- .../resources/i18n/displayStrings.properties | 2 +- .../java/bisq/desktop/main/MainViewModel.java | 2 +- .../main/offer/MutableOfferViewModel.java | 11 +-- .../offer/takeoffer/TakeOfferViewModel.java | 10 +- .../pendingtrades/PendingTradesViewModel.java | 6 +- .../settings/network/NetworkSettingsView.java | 2 +- .../main/java/bisq/desktop/util/GUIUtil.java | 92 ++----------------- 7 files changed, 24 insertions(+), 101 deletions(-) diff --git a/core/src/main/resources/i18n/displayStrings.properties b/core/src/main/resources/i18n/displayStrings.properties index 2f384a70366..cedbfc3b6ce 100644 --- a/core/src/main/resources/i18n/displayStrings.properties +++ b/core/src/main/resources/i18n/displayStrings.properties @@ -334,7 +334,7 @@ offerbook.filterByCurrency=Filter by currency offerbook.filterByPaymentMethod=Filter by payment method offerbook.timeSinceSigning=Time since signing offerbook.timeSinceSigning.info=This account was verified and {0} -offerbook.timeSinceSigning.info.arbitrator=signed by an arbitrator and can sign peers accounts +offerbook.timeSinceSigning.info.arbitrator=signed by an arbitrator and can sign peer accounts offerbook.timeSinceSigning.info.peer=signed by a peer, waiting for limits to be lifted offerbook.timeSinceSigning.info.peerLimitLifted=signed by a peer and limits were lifted offerbook.timeSinceSigning.info.signer=signed by peer and can sign peer accounts diff --git a/desktop/src/main/java/bisq/desktop/main/MainViewModel.java b/desktop/src/main/java/bisq/desktop/main/MainViewModel.java index 41fc37a88b5..a87b0809186 100644 --- a/desktop/src/main/java/bisq/desktop/main/MainViewModel.java +++ b/desktop/src/main/java/bisq/desktop/main/MainViewModel.java @@ -303,7 +303,7 @@ private void setupHandlers() { }); bisqSetup.setSpvFileCorruptedHandler(msg -> new Popup<>().warning(msg) .actionButtonText(Res.get("settings.net.reSyncSPVChainButton")) - .onAction(() -> GUIUtil.reSyncSPVChain(walletsSetup, preferences)) + .onAction(() -> GUIUtil.reSyncSPVChain(preferences)) .show()); bisqSetup.setVoteResultExceptionHandler(voteResultException -> log.warn(voteResultException.toString())); diff --git a/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferViewModel.java b/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferViewModel.java index add7392df52..92f67543739 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferViewModel.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferViewModel.java @@ -956,7 +956,7 @@ public String getSecurityDepositPopOverLabel(String depositInBTC) { public String getSecurityDepositInfo() { return btcFormatter.formatCoinWithCode(dataModel.getSecurityDeposit()) + - GUIUtil.getPercentageOfTradeAmount(dataModel.getSecurityDeposit(), dataModel.getAmount().get(), btcFormatter); + GUIUtil.getPercentageOfTradeAmount(dataModel.getSecurityDeposit(), dataModel.getAmount().get()); } public String getSecurityDepositWithCode() { @@ -968,7 +968,7 @@ public String getTradeFee() { final Coin makerFeeAsCoin = dataModel.getMakerFee(); final String makerFee = getFormatterForMakerFee().formatCoinWithCode(makerFeeAsCoin); if (dataModel.isCurrencyForMakerFeeBtc()) - return makerFee + GUIUtil.getPercentageOfTradeAmount(makerFeeAsCoin, dataModel.getAmount().get(), btcFormatter); + return makerFee + GUIUtil.getPercentageOfTradeAmount(makerFeeAsCoin, dataModel.getAmount().get()); else return makerFee + " (" + Res.get("shared.tradingFeeInBsqInfo", btcFormatter.formatCoinWithCode(makerFeeAsCoin)) + ")"; } @@ -976,7 +976,7 @@ public String getTradeFee() { public String getMakerFeePercentage() { final Coin makerFeeAsCoin = dataModel.getMakerFee(); if (dataModel.isCurrencyForMakerFeeBtc()) - return GUIUtil.getPercentage(makerFeeAsCoin, dataModel.getAmount().get(), btcFormatter); + return GUIUtil.getPercentage(makerFeeAsCoin, dataModel.getAmount().get()); else return Res.get("dao.paidWithBsq"); } @@ -1004,13 +1004,13 @@ public String getFundsStructure() { public String getTxFee() { Coin txFeeAsCoin = dataModel.getTxFee(); return btcFormatter.formatCoinWithCode(txFeeAsCoin) + - GUIUtil.getPercentageOfTradeAmount(txFeeAsCoin, dataModel.getAmount().get(), btcFormatter); + GUIUtil.getPercentageOfTradeAmount(txFeeAsCoin, dataModel.getAmount().get()); } public String getTxFeePercentage() { Coin txFeeAsCoin = dataModel.getTxFee(); - return GUIUtil.getPercentage(txFeeAsCoin, dataModel.getAmount().get(), btcFormatter); + return GUIUtil.getPercentage(txFeeAsCoin, dataModel.getAmount().get()); } public PaymentAccount getPaymentAccount() { @@ -1046,7 +1046,6 @@ public M getDataModel() { return dataModel; } - /////////////////////////////////////////////////////////////////////////////////////////// // Utils /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/desktop/src/main/java/bisq/desktop/main/offer/takeoffer/TakeOfferViewModel.java b/desktop/src/main/java/bisq/desktop/main/offer/takeoffer/TakeOfferViewModel.java index 1722bd759c1..1c539865ff8 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/takeoffer/TakeOfferViewModel.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/takeoffer/TakeOfferViewModel.java @@ -698,7 +698,7 @@ String getTradeAmount() { public String getSecurityDepositInfo() { return btcFormatter.formatCoinWithCode(dataModel.getSecurityDeposit()) + - GUIUtil.getPercentageOfTradeAmount(dataModel.getSecurityDeposit(), dataModel.getAmount().get(), btcFormatter); + GUIUtil.getPercentageOfTradeAmount(dataModel.getSecurityDeposit(), dataModel.getAmount().get()); } public String getSecurityDepositWithCode() { @@ -710,7 +710,7 @@ public String getTradeFee() { final Coin takerFeeAsCoin = dataModel.getTakerFee(); final String takerFee = getFormatterForTakerFee().formatCoinWithCode(takerFeeAsCoin); if (dataModel.isCurrencyForTakerFeeBtc()) - return takerFee + GUIUtil.getPercentageOfTradeAmount(takerFeeAsCoin, dataModel.getAmount().get(), btcFormatter); + return takerFee + GUIUtil.getPercentageOfTradeAmount(takerFeeAsCoin, dataModel.getAmount().get()); else return takerFee + " (" + Res.get("shared.tradingFeeInBsqInfo", btcFormatter.formatCoinWithCode(takerFeeAsCoin)) + ")"; } @@ -718,7 +718,7 @@ public String getTradeFee() { public String getTakerFeePercentage() { final Coin takerFeeAsCoin = dataModel.getTakerFee(); if (dataModel.isCurrencyForTakerFeeBtc()) - return takerFeeAsCoin != null ? GUIUtil.getPercentage(takerFeeAsCoin, dataModel.getAmount().get(), btcFormatter) : Res.get("shared.na"); + return takerFeeAsCoin != null ? GUIUtil.getPercentage(takerFeeAsCoin, dataModel.getAmount().get()) : Res.get("shared.na"); else return Res.get("dao.paidWithBsq"); } @@ -734,13 +734,13 @@ public String getTotalToPayInfo() { public String getTxFee() { Coin txFeeAsCoin = dataModel.getTotalTxFee(); return btcFormatter.formatCoinWithCode(txFeeAsCoin) + - GUIUtil.getPercentageOfTradeAmount(txFeeAsCoin, dataModel.getAmount().get(), btcFormatter); + GUIUtil.getPercentageOfTradeAmount(txFeeAsCoin, dataModel.getAmount().get()); } public String getTxFeePercentage() { Coin txFeeAsCoin = dataModel.getTotalTxFee(); - return GUIUtil.getPercentage(txFeeAsCoin, dataModel.getAmount().get(), btcFormatter); + return GUIUtil.getPercentage(txFeeAsCoin, dataModel.getAmount().get()); } public PaymentMethod getPaymentMethod() { diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/PendingTradesViewModel.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/PendingTradesViewModel.java index e4001bae2a7..69454b419c9 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/PendingTradesViewModel.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/PendingTradesViewModel.java @@ -287,7 +287,7 @@ public String getFiatVolume() { public String getTxFee() { if (trade != null && trade.getTradeAmount() != null) { Coin txFee = dataModel.getTxFee(); - String percentage = GUIUtil.getPercentageOfTradeAmount(txFee, trade.getTradeAmount(), btcFormatter); + String percentage = GUIUtil.getPercentageOfTradeAmount(txFee, trade.getTradeAmount()); return btcFormatter.formatCoinWithCode(txFee) + percentage; } else { return ""; @@ -299,7 +299,7 @@ public String getTradeFee() { if (dataModel.isMaker() && dataModel.getOffer().isCurrencyForMakerFeeBtc() || !dataModel.isMaker() && dataModel.getTrade().isCurrencyForTakerFeeBtc()) { Coin tradeFeeInBTC = dataModel.getTradeFeeInBTC(); - String percentage = GUIUtil.getPercentageOfTradeAmount(tradeFeeInBTC, trade.getTradeAmount(), btcFormatter); + String percentage = GUIUtil.getPercentageOfTradeAmount(tradeFeeInBTC, trade.getTradeAmount()); return btcFormatter.formatCoinWithCode(tradeFeeInBTC) + percentage; } else { return bsqFormatter.formatCoinWithCode(dataModel.getTradeFeeAsBsq()); @@ -316,7 +316,7 @@ public String getSecurityDeposit() { Coin securityDeposit = dataModel.isBuyer() ? offer.getBuyerSecurityDeposit() : offer.getSellerSecurityDeposit(); - String percentage = GUIUtil.getPercentageOfTradeAmount(securityDeposit, trade.getTradeAmount(), btcFormatter); + String percentage = GUIUtil.getPercentageOfTradeAmount(securityDeposit, trade.getTradeAmount()); return btcFormatter.formatCoinWithCode(securityDeposit) + percentage; } else { return ""; diff --git a/desktop/src/main/java/bisq/desktop/main/settings/network/NetworkSettingsView.java b/desktop/src/main/java/bisq/desktop/main/settings/network/NetworkSettingsView.java index a39911d442c..d4d2006b1e5 100644 --- a/desktop/src/main/java/bisq/desktop/main/settings/network/NetworkSettingsView.java +++ b/desktop/src/main/java/bisq/desktop/main/settings/network/NetworkSettingsView.java @@ -264,7 +264,7 @@ public void activate() { } }); - reSyncSPVChainButton.setOnAction(event -> GUIUtil.reSyncSPVChain(walletsSetup, preferences)); + reSyncSPVChainButton.setOnAction(event -> GUIUtil.reSyncSPVChain(preferences)); bitcoinPeersSubscription = EasyBind.subscribe(walletsSetup.connectedPeersProperty(), connectedPeers -> updateBitcoinPeersTextArea()); diff --git a/desktop/src/main/java/bisq/desktop/util/GUIUtil.java b/desktop/src/main/java/bisq/desktop/util/GUIUtil.java index d52a227007e..96cf4b18846 100644 --- a/desktop/src/main/java/bisq/desktop/util/GUIUtil.java +++ b/desktop/src/main/java/bisq/desktop/util/GUIUtil.java @@ -93,6 +93,7 @@ import javafx.scene.Node; import javafx.scene.Scene; import javafx.scene.control.ComboBox; +import javafx.scene.control.ContentDisplay; import javafx.scene.control.Label; import javafx.scene.control.ListCell; import javafx.scene.control.ListView; @@ -103,13 +104,9 @@ import javafx.scene.layout.AnchorPane; import javafx.scene.layout.GridPane; import javafx.scene.layout.HBox; -import javafx.scene.layout.Pane; -import javafx.scene.layout.Region; import javafx.geometry.Orientation; -import javafx.beans.property.DoubleProperty; - import javafx.collections.FXCollections; import javafx.util.Callback; @@ -117,7 +114,6 @@ import java.net.URI; import java.net.URISyntaxException; -import java.net.URLEncoder; import java.nio.file.Paths; @@ -209,7 +205,7 @@ public static void exportAccounts(ArrayList accounts, CorruptedDatabaseFilesHandler corruptedDatabaseFilesHandler) { if (!accounts.isEmpty()) { String directory = getDirectoryFromChooser(preferences, stage); - if (directory != null && !directory.isEmpty()) { + if (!directory.isEmpty()) { Storage> paymentAccountsStorage = new Storage<>(new File(directory), persistenceProtoResolver, corruptedDatabaseFilesHandler); paymentAccountsStorage.initAndGetPersisted(new PaymentAccountList(accounts), fileName, 100); paymentAccountsStorage.queueUpForSave(); @@ -309,7 +305,7 @@ public static void exportJSON(String fileName, JsonElement data, Stage stage) { } } - public static String getDirectoryFromChooser(Preferences preferences, Stage stage) { + private static String getDirectoryFromChooser(Preferences preferences, Stage stage) { DirectoryChooser directoryChooser = new DirectoryChooser(); File initDir = new File(preferences.getDirectoryChooserPath()); if (initDir.isDirectory()) { @@ -326,51 +322,6 @@ public static String getDirectoryFromChooser(Preferences preferences, Stage stag } } - public static ListCell getCurrencyListItemButtonCell(String postFixSingle, String postFixMulti, - Preferences preferences) { - return new ListCell<>() { - - @Override - protected void updateItem(CurrencyListItem item, boolean empty) { - super.updateItem(item, empty); - - if (item != null && !empty) { - String code = item.tradeCurrency.getCode(); - - AnchorPane pane = new AnchorPane(); - Label currency = new AutoTooltipLabel(code + " - " + item.tradeCurrency.getName()); - currency.getStyleClass().add("currency-label-selected"); - AnchorPane.setLeftAnchor(currency, 0.0); - pane.getChildren().add(currency); - - switch (code) { - case GUIUtil.SHOW_ALL_FLAG: - currency.setText(Res.get("list.currency.showAll")); - break; - case GUIUtil.EDIT_FLAG: - currency.setText(Res.get("list.currency.editList")); - break; - default: - if (preferences.isSortMarketCurrenciesNumerically()) { - Label numberOfOffers = new AutoTooltipLabel(item.numTrades + " " + - (item.numTrades == 1 ? postFixSingle : postFixMulti)); - numberOfOffers.getStyleClass().add("offer-label-small"); - AnchorPane.setRightAnchor(numberOfOffers, 0.0); - AnchorPane.setBottomAnchor(numberOfOffers, 2.0); - pane.getChildren().add(numberOfOffers); - } - } - - setGraphic(pane); - setText(""); - } else { - setGraphic(null); - setText(""); - } - } - }; - } - public static Callback, ListCell> getCurrencyListItemCellFactory(String postFixSingle, String postFixMulti, Preferences preferences) { @@ -692,23 +643,12 @@ private static void doOpenWebPage(String target) { } } - public static void openMail(String to, String subject, String body) { - try { - subject = URLEncoder.encode(subject, "UTF-8").replace("+", "%20"); - body = URLEncoder.encode(body, "UTF-8").replace("+", "%20"); - Utilities.openURI(new URI("mailto:" + to + "?subject=" + subject + "&body=" + body)); - } catch (IOException | URISyntaxException e) { - log.error("openMail failed " + e.getMessage()); - e.printStackTrace(); - } - } - - public static String getPercentageOfTradeAmount(Coin fee, Coin tradeAmount, BSFormatter formatter) { - return " (" + getPercentage(fee, tradeAmount, formatter) + + public static String getPercentageOfTradeAmount(Coin fee, Coin tradeAmount) { + return " (" + getPercentage(fee, tradeAmount) + " " + Res.get("guiUtil.ofTradeAmount") + ")"; } - public static String getPercentage(Coin part, Coin total, BSFormatter formatter) { + public static String getPercentage(Coin part, Coin total) { return BSFormatter.formatToPercentWithSymbol((double) part.value / (double) total.value); } @@ -735,22 +675,6 @@ public static void showClearXchangeWarning() { .show(); } - public static void fillAvailableHeight(Pane container, Region component, DoubleProperty initialOccupiedHeight) { - UserThread.runAfter(() -> { - - double available; - if (container.getParent() instanceof Pane) - available = ((Pane) container.getParent()).getHeight(); - else - available = container.getHeight(); - - if (initialOccupiedHeight.get() == -1 && component.getHeight() > 0) { - initialOccupiedHeight.set(available - component.getHeight()); - } - component.setPrefHeight(available - initialOccupiedHeight.get()); - }, 100, TimeUnit.MILLISECONDS); - } - public static String getBitcoinURI(String address, Coin amount, String label) { return address != null ? BitcoinURI.convertToBitcoinURI(Address.fromBase58(BisqEnvironment.getParameters(), @@ -819,7 +743,7 @@ public static void requestFocus(Node node) { UserThread.execute(node::requestFocus); } - public static void reSyncSPVChain(WalletsSetup walletsSetup, Preferences preferences) { + public static void reSyncSPVChain(Preferences preferences) { try { new Popup<>().feedback(Res.get("settings.net.reSyncSPVSuccess")) .useShutDownButton() @@ -874,7 +798,7 @@ public static void showSelectableTextModal(String title, String text) { } public static StringConverter getPaymentAccountsComboBoxStringConverter() { - return new StringConverter() { + return new StringConverter<>() { @Override public String toString(PaymentAccount paymentAccount) { if (paymentAccount.hasMultipleCurrencies()) { From b366ae0a6b83086841953e3be38ec0d9bef1c938 Mon Sep 17 00:00:00 2001 From: Christoph Atteneder Date: Mon, 14 Oct 2019 11:43:27 +0200 Subject: [PATCH 2/2] Add account signing state to payment account selection --- .../resources/i18n/displayStrings.properties | 2 +- .../desktop/main/offer/MutableOfferView.java | 1 + .../main/offer/MutableOfferViewModel.java | 15 ++++++ .../createoffer/CreateOfferViewModel.java | 6 ++- .../main/offer/takeoffer/TakeOfferView.java | 1 + .../offer/takeoffer/TakeOfferViewModel.java | 15 ++++++ .../editoffer/EditOfferViewModel.java | 6 ++- .../main/java/bisq/desktop/util/GUIUtil.java | 49 +++++++++++++++++++ .../createoffer/CreateOfferViewModelTest.java | 2 +- 9 files changed, 91 insertions(+), 6 deletions(-) diff --git a/core/src/main/resources/i18n/displayStrings.properties b/core/src/main/resources/i18n/displayStrings.properties index cedbfc3b6ce..48a8fad9091 100644 --- a/core/src/main/resources/i18n/displayStrings.properties +++ b/core/src/main/resources/i18n/displayStrings.properties @@ -342,7 +342,7 @@ offerbook.timeSinceSigning.daysSinceSigning={0} days offerbook.timeSinceSigning.daysSinceSigning.long={0} since signing offerbook.timeSinceSigning.help=By trading with a payment account that was verified by an arbitrator or a peer, your account gets signed as well.\n\ - 30 days later the initial limit of 0.01 BTC gets lifted and after 90 days your account can sign other peers as well. + 30 days later the initial limit of 0.01 BTC gets lifted and after 60 days your account can sign other peers as well. offerbook.timeSinceSigning.notSigned=Not signed yet offerbook.timeSinceSigning.notSigned.noNeed=Unsigned shared.notSigned=This account hasn't been signed yet diff --git a/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferView.java b/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferView.java index ac10b4570fb..d4fe7ae23fc 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferView.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferView.java @@ -213,6 +213,7 @@ protected void initialize() { paymentAccountsComboBox.setConverter(GUIUtil.getPaymentAccountsComboBoxStringConverter()); paymentAccountsComboBox.setButtonCell(GUIUtil.getComboBoxButtonCell(Res.get("shared.selectTradingAccount"), paymentAccountsComboBox, false)); + paymentAccountsComboBox.setCellFactory(model.getPaymentAccountListCellFactory(paymentAccountsComboBox)); doSetFocus(); } diff --git a/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferViewModel.java b/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferViewModel.java index 92f67543739..49229861073 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferViewModel.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferViewModel.java @@ -35,6 +35,7 @@ import bisq.desktop.util.validation.MonetaryValidator; import bisq.desktop.util.validation.SecurityDepositValidator; +import bisq.core.account.witness.AccountAgeWitnessService; import bisq.core.btc.wallet.Restrictions; import bisq.core.locale.CurrencyUtil; import bisq.core.locale.Res; @@ -66,6 +67,10 @@ import javax.inject.Inject; +import javafx.scene.control.ComboBox; +import javafx.scene.control.ListCell; +import javafx.scene.control.ListView; + import javafx.beans.property.BooleanProperty; import javafx.beans.property.IntegerProperty; import javafx.beans.property.ObjectProperty; @@ -76,6 +81,8 @@ import javafx.beans.property.StringProperty; import javafx.beans.value.ChangeListener; +import javafx.util.Callback; + import java.util.Optional; import java.util.concurrent.TimeUnit; @@ -86,6 +93,7 @@ public abstract class MutableOfferViewModel ext private final BsqValidator bsqValidator; protected final SecurityDepositValidator securityDepositValidator; private final PriceFeedService priceFeedService; + private AccountAgeWitnessService accountAgeWitnessService; private final Navigation navigation; private final Preferences preferences; protected final BSFormatter btcFormatter; @@ -185,6 +193,7 @@ public MutableOfferViewModel(M dataModel, BsqValidator bsqValidator, SecurityDepositValidator securityDepositValidator, PriceFeedService priceFeedService, + AccountAgeWitnessService accountAgeWitnessService, Navigation navigation, Preferences preferences, BSFormatter btcFormatter, @@ -198,6 +207,7 @@ public MutableOfferViewModel(M dataModel, this.bsqValidator = bsqValidator; this.securityDepositValidator = securityDepositValidator; this.priceFeedService = priceFeedService; + this.accountAgeWitnessService = accountAgeWitnessService; this.navigation = navigation; this.preferences = preferences; this.btcFormatter = btcFormatter; @@ -1042,6 +1052,11 @@ public Offer createAndGetOffer() { return offer; } + public Callback, ListCell> getPaymentAccountListCellFactory( + ComboBox paymentAccountsComboBox) { + return GUIUtil.getPaymentAccountListCellFactory(paymentAccountsComboBox, accountAgeWitnessService); + } + public M getDataModel() { return dataModel; } diff --git a/desktop/src/main/java/bisq/desktop/main/offer/createoffer/CreateOfferViewModel.java b/desktop/src/main/java/bisq/desktop/main/offer/createoffer/CreateOfferViewModel.java index 87e33952b1a..0736cc65385 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/createoffer/CreateOfferViewModel.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/createoffer/CreateOfferViewModel.java @@ -27,6 +27,7 @@ import bisq.desktop.util.validation.FiatVolumeValidator; import bisq.desktop.util.validation.SecurityDepositValidator; +import bisq.core.account.witness.AccountAgeWitnessService; import bisq.core.provider.price.PriceFeedService; import bisq.core.user.Preferences; import bisq.core.util.BSFormatter; @@ -45,6 +46,7 @@ public CreateOfferViewModel(CreateOfferDataModel dataModel, BsqValidator bsqValidator, SecurityDepositValidator securityDepositValidator, PriceFeedService priceFeedService, + AccountAgeWitnessService accountAgeWitnessService, Navigation navigation, Preferences preferences, BSFormatter btcFormatter, @@ -57,9 +59,9 @@ public CreateOfferViewModel(CreateOfferDataModel dataModel, bsqValidator, securityDepositValidator, priceFeedService, + accountAgeWitnessService, navigation, preferences, - btcFormatter, - bsqFormatter); + btcFormatter, bsqFormatter); } } diff --git a/desktop/src/main/java/bisq/desktop/main/offer/takeoffer/TakeOfferView.java b/desktop/src/main/java/bisq/desktop/main/offer/takeoffer/TakeOfferView.java index ef304a71fbd..ccd8cce0de9 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/takeoffer/TakeOfferView.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/takeoffer/TakeOfferView.java @@ -834,6 +834,7 @@ private void addPaymentGroup() { paymentAccountsComboBox = paymentAccountTuple.first; HBox.setMargin(paymentAccountsComboBox, new Insets(Layout.FLOATING_LABEL_DISTANCE, 0, 0, 0)); paymentAccountsComboBox.setConverter(GUIUtil.getPaymentAccountsComboBoxStringConverter()); + paymentAccountsComboBox.setCellFactory(model.getPaymentAccountListCellFactory(paymentAccountsComboBox)); paymentAccountsComboBox.setVisible(false); paymentAccountsComboBox.setManaged(false); paymentAccountsComboBox.setOnAction(e -> { diff --git a/desktop/src/main/java/bisq/desktop/main/offer/takeoffer/TakeOfferViewModel.java b/desktop/src/main/java/bisq/desktop/main/offer/takeoffer/TakeOfferViewModel.java index 1c539865ff8..98b4c8d4ae2 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/takeoffer/TakeOfferViewModel.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/takeoffer/TakeOfferViewModel.java @@ -28,6 +28,7 @@ import bisq.desktop.util.GUIUtil; import bisq.desktop.util.validation.BtcValidator; +import bisq.core.account.witness.AccountAgeWitnessService; import bisq.core.btc.setup.WalletsSetup; import bisq.core.locale.CurrencyUtil; import bisq.core.locale.Res; @@ -57,6 +58,10 @@ import javax.inject.Inject; +import javafx.scene.control.ComboBox; +import javafx.scene.control.ListCell; +import javafx.scene.control.ListView; + import javafx.beans.property.BooleanProperty; import javafx.beans.property.ObjectProperty; import javafx.beans.property.SimpleBooleanProperty; @@ -67,6 +72,8 @@ import javafx.collections.ObservableList; +import javafx.util.Callback; + import java.util.Optional; import javax.annotation.Nullable; @@ -81,6 +88,7 @@ class TakeOfferViewModel extends ActivatableWithDataModel im private final WalletsSetup walletsSetup; private final Preferences preferences; private final PriceFeedService priceFeedService; + private AccountAgeWitnessService accountAgeWitnessService; private final Navigation navigation; private final BSFormatter btcFormatter; private final BsqFormatter bsqFormatter; @@ -141,6 +149,7 @@ public TakeOfferViewModel(TakeOfferDataModel dataModel, WalletsSetup walletsSetup, Preferences preferences, PriceFeedService priceFeedService, + AccountAgeWitnessService accountAgeWitnessService, Navigation navigation, BSFormatter btcFormatter, BsqFormatter bsqFormatter) { @@ -152,6 +161,7 @@ public TakeOfferViewModel(TakeOfferDataModel dataModel, this.walletsSetup = walletsSetup; this.preferences = preferences; this.priceFeedService = priceFeedService; + this.accountAgeWitnessService = accountAgeWitnessService; this.navigation = navigation; this.btcFormatter = btcFormatter; this.bsqFormatter = bsqFormatter; @@ -778,4 +788,9 @@ public String getSellerSecurityDeposit() { private BSFormatter getFormatterForTakerFee() { return dataModel.isCurrencyForTakerFeeBtc() ? btcFormatter : bsqFormatter; } + + public Callback, ListCell> getPaymentAccountListCellFactory( + ComboBox paymentAccountsComboBox) { + return GUIUtil.getPaymentAccountListCellFactory(paymentAccountsComboBox, accountAgeWitnessService); + } } diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/editoffer/EditOfferViewModel.java b/desktop/src/main/java/bisq/desktop/main/portfolio/editoffer/EditOfferViewModel.java index 5a20c1f3535..8825ca4b6bd 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/editoffer/EditOfferViewModel.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/editoffer/EditOfferViewModel.java @@ -26,6 +26,7 @@ import bisq.desktop.util.validation.FiatVolumeValidator; import bisq.desktop.util.validation.SecurityDepositValidator; +import bisq.core.account.witness.AccountAgeWitnessService; import bisq.core.offer.OpenOffer; import bisq.core.provider.price.PriceFeedService; import bisq.core.user.Preferences; @@ -48,6 +49,7 @@ public EditOfferViewModel(EditOfferDataModel dataModel, BsqValidator bsqValidator, SecurityDepositValidator securityDepositValidator, PriceFeedService priceFeedService, + AccountAgeWitnessService accountAgeWitnessService, Navigation navigation, Preferences preferences, BSFormatter btcFormatter, @@ -60,10 +62,10 @@ public EditOfferViewModel(EditOfferDataModel dataModel, bsqValidator, securityDepositValidator, priceFeedService, + accountAgeWitnessService, navigation, preferences, - btcFormatter, - bsqFormatter); + btcFormatter, bsqFormatter); syncMinAmountWithAmount = false; } diff --git a/desktop/src/main/java/bisq/desktop/util/GUIUtil.java b/desktop/src/main/java/bisq/desktop/util/GUIUtil.java index 96cf4b18846..bdac68f9489 100644 --- a/desktop/src/main/java/bisq/desktop/util/GUIUtil.java +++ b/desktop/src/main/java/bisq/desktop/util/GUIUtil.java @@ -21,12 +21,15 @@ import bisq.desktop.app.BisqApp; import bisq.desktop.components.AutoTooltipLabel; import bisq.desktop.components.BisqTextArea; +import bisq.desktop.components.InfoAutoTooltipLabel; import bisq.desktop.components.indicator.TxConfidenceIndicator; import bisq.desktop.main.MainView; import bisq.desktop.main.account.AccountView; import bisq.desktop.main.account.content.fiataccounts.FiatAccountsView; import bisq.desktop.main.overlays.popups.Popup; +import bisq.core.account.witness.AccountAgeWitness; +import bisq.core.account.witness.AccountAgeWitnessService; import bisq.core.app.BisqEnvironment; import bisq.core.btc.setup.WalletsSetup; import bisq.core.btc.wallet.WalletsManager; @@ -84,6 +87,8 @@ import org.apache.commons.lang3.StringUtils; +import de.jensd.fx.glyphs.materialdesignicons.MaterialDesignIcon; + import javafx.stage.DirectoryChooser; import javafx.stage.FileChooser; import javafx.stage.Modality; @@ -818,6 +823,50 @@ public PaymentAccount fromString(String s) { }; } + public static Callback, ListCell> getPaymentAccountListCellFactory( + ComboBox paymentAccountsComboBox, + AccountAgeWitnessService accountAgeWitnessService) { + return p -> new ListCell<>() { + @Override + protected void updateItem(PaymentAccount item, boolean empty) { + super.updateItem(item, empty); + + if (item != null && !empty) { + + boolean needsSigning = PaymentMethod.hasChargebackRisk(item.getPaymentMethod(), + item.getTradeCurrencies()); + + InfoAutoTooltipLabel label = new InfoAutoTooltipLabel( + paymentAccountsComboBox.getConverter().toString(item), + ContentDisplay.RIGHT); + + if (needsSigning) { + AccountAgeWitness myWitness = accountAgeWitnessService.getMyWitness( + item.paymentAccountPayload); + AccountAgeWitnessService.SignState signState = + accountAgeWitnessService.getSignState(myWitness); + String info = StringUtils.capitalize(signState.getPresentation()); + + MaterialDesignIcon icon; + + switch (signState) { + case PEER_SIGNER: + case ARBITRATOR: + icon = MaterialDesignIcon.APPROVAL; + break; + default: + icon = MaterialDesignIcon.ALERT_CIRCLE_OUTLINE; + } + label.setIcon(icon, info); + } + setGraphic(label); + } else { + setGraphic(null); + } + } + }; + } + public static void removeChildrenFromGridPaneRows(GridPane gridPane, int start, int end) { Map> childByRowMap = new HashMap<>(); gridPane.getChildren().forEach(child -> { diff --git a/desktop/src/test/java/bisq/desktop/main/offer/createoffer/CreateOfferViewModelTest.java b/desktop/src/test/java/bisq/desktop/main/offer/createoffer/CreateOfferViewModelTest.java index 6ffaf5cfbf7..515126304ca 100644 --- a/desktop/src/test/java/bisq/desktop/main/offer/createoffer/CreateOfferViewModelTest.java +++ b/desktop/src/test/java/bisq/desktop/main/offer/createoffer/CreateOfferViewModelTest.java @@ -112,7 +112,7 @@ public void setUp() { dataModel.activate(); model = new CreateOfferViewModel(dataModel, null, fiatPriceValidator, altcoinValidator, - btcValidator, null, securityDepositValidator, priceFeedService, null, + btcValidator, null, securityDepositValidator, priceFeedService, null, null, preferences, bsFormatter, bsqFormatter); model.activate(); }