Skip to content

Commit

Permalink
Add account signing state to payment account selection
Browse files Browse the repository at this point in the history
  • Loading branch information
ripcurlx committed Oct 14, 2019
1 parent 0dcc20c commit fb7af25
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -86,6 +93,7 @@ public abstract class MutableOfferViewModel<M extends MutableOfferDataModel> 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;
Expand Down Expand Up @@ -185,6 +193,7 @@ public MutableOfferViewModel(M dataModel,
BsqValidator bsqValidator,
SecurityDepositValidator securityDepositValidator,
PriceFeedService priceFeedService,
AccountAgeWitnessService accountAgeWitnessService,
Navigation navigation,
Preferences preferences,
BSFormatter btcFormatter,
Expand All @@ -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;
Expand Down Expand Up @@ -1042,6 +1052,11 @@ public Offer createAndGetOffer() {
return offer;
}

public Callback<ListView<PaymentAccount>, ListCell<PaymentAccount>> getPaymentAccountListCellFactory(
ComboBox<PaymentAccount> paymentAccountsComboBox) {
return GUIUtil.getPaymentAccountListCellFactory(paymentAccountsComboBox, accountAgeWitnessService);
}

public M getDataModel() {
return dataModel;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -45,6 +46,7 @@ public CreateOfferViewModel(CreateOfferDataModel dataModel,
BsqValidator bsqValidator,
SecurityDepositValidator securityDepositValidator,
PriceFeedService priceFeedService,
AccountAgeWitnessService accountAgeWitnessService,
Navigation navigation,
Preferences preferences,
BSFormatter btcFormatter,
Expand All @@ -57,9 +59,9 @@ public CreateOfferViewModel(CreateOfferDataModel dataModel,
bsqValidator,
securityDepositValidator,
priceFeedService,
accountAgeWitnessService,
navigation,
preferences,
btcFormatter,
bsqFormatter);
btcFormatter, bsqFormatter);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -67,6 +72,8 @@

import javafx.collections.ObservableList;

import javafx.util.Callback;

import java.util.Optional;

import javax.annotation.Nullable;
Expand All @@ -81,6 +88,7 @@ class TakeOfferViewModel extends ActivatableWithDataModel<TakeOfferDataModel> 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;
Expand Down Expand Up @@ -141,6 +149,7 @@ public TakeOfferViewModel(TakeOfferDataModel dataModel,
WalletsSetup walletsSetup,
Preferences preferences,
PriceFeedService priceFeedService,
AccountAgeWitnessService accountAgeWitnessService,
Navigation navigation,
BSFormatter btcFormatter,
BsqFormatter bsqFormatter) {
Expand All @@ -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;
Expand Down Expand Up @@ -778,4 +788,9 @@ public String getSellerSecurityDeposit() {
private BSFormatter getFormatterForTakerFee() {
return dataModel.isCurrencyForTakerFeeBtc() ? btcFormatter : bsqFormatter;
}

public Callback<ListView<PaymentAccount>, ListCell<PaymentAccount>> getPaymentAccountListCellFactory(
ComboBox<PaymentAccount> paymentAccountsComboBox) {
return GUIUtil.getPaymentAccountListCellFactory(paymentAccountsComboBox, accountAgeWitnessService);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -48,6 +49,7 @@ public EditOfferViewModel(EditOfferDataModel dataModel,
BsqValidator bsqValidator,
SecurityDepositValidator securityDepositValidator,
PriceFeedService priceFeedService,
AccountAgeWitnessService accountAgeWitnessService,
Navigation navigation,
Preferences preferences,
BSFormatter btcFormatter,
Expand All @@ -60,10 +62,10 @@ public EditOfferViewModel(EditOfferDataModel dataModel,
bsqValidator,
securityDepositValidator,
priceFeedService,
accountAgeWitnessService,
navigation,
preferences,
btcFormatter,
bsqFormatter);
btcFormatter, bsqFormatter);
syncMinAmountWithAmount = false;
}

Expand Down
49 changes: 49 additions & 0 deletions desktop/src/main/java/bisq/desktop/util/GUIUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -818,6 +823,50 @@ public PaymentAccount fromString(String s) {
};
}

public static Callback<ListView<PaymentAccount>, ListCell<PaymentAccount>> getPaymentAccountListCellFactory(
ComboBox<PaymentAccount> 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<Integer, List<Node>> childByRowMap = new HashMap<>();
gridPane.getChildren().forEach(child -> {
Expand Down

0 comments on commit fb7af25

Please sign in to comment.