Skip to content

Commit

Permalink
Add sign all checkbox. Fix list entry display (#3450)
Browse files Browse the repository at this point in the history
* Add sign all checkbox. Fix list entry display

* Add summary to log and clipboard
  • Loading branch information
chimp1984 authored and ripcurlx committed Oct 23, 2019
1 parent 5d0a068 commit d591763
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 16 deletions.
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 @@ -2540,6 +2540,7 @@ popup.news.launch.ntp.description=Multisig escrows are now 2-of-2 with a new dis

popup.accountSigning.selectAccounts.headline=Select payment accounts
popup.accountSigning.selectAccounts.description=Based on the payment method and point of time all payment accounts that are connected to a dispute where a payout to the buyer occurred will be selected for you to sign.
popup.accountSigning.selectAccounts.signAll=Sign all payment methods
popup.accountSigning.selectAccounts.datePicker=Select point of time until which accounts will be signed

popup.accountSigning.confirmSelectedAccounts.headline=Confirm selected payment accounts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,27 @@
import bisq.desktop.main.overlays.popups.Popup;

import bisq.core.account.witness.AccountAgeWitnessService;
import bisq.core.app.AppOptionKeys;
import bisq.core.locale.Res;
import bisq.core.payment.payload.PaymentMethod;
import bisq.core.support.dispute.Dispute;
import bisq.core.support.dispute.arbitration.ArbitrationManager;
import bisq.core.support.dispute.arbitration.TraderDataItem;
import bisq.core.support.dispute.arbitration.arbitrator.ArbitratorManager;
import bisq.core.util.BSFormatter;

import bisq.common.util.Tuple2;
import bisq.common.util.Tuple3;
import bisq.common.util.Utilities;

import org.bitcoinj.core.ECKey;
import org.bitcoinj.core.Utils;

import javax.inject.Inject;
import javax.inject.Named;

import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.ComboBox;
import javafx.scene.control.DatePicker;
import javafx.scene.control.Label;
Expand All @@ -47,9 +53,11 @@
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;

import javafx.geometry.HPos;
import javafx.geometry.VPos;

import javafx.collections.FXCollections;
import javafx.collections.ObservableList;

import javafx.util.Callback;
import javafx.util.StringConverter;
Expand All @@ -59,6 +67,7 @@
import java.time.ZoneOffset;
import java.time.temporal.ChronoUnit;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
Expand All @@ -72,29 +81,38 @@ public class SignPaymentAccountsWindow extends Overlay<SignPaymentAccountsWindow

private Label descriptionLabel;
private ComboBox<PaymentMethod> paymentMethodComboBox;
private CheckBox signAllCheckbox;
private DatePicker datePicker;
private InputTextField privateKey;
private ListView<TraderDataItem> selectedPaymentAccountsList = new ListView<>();
private final AccountAgeWitnessService accountAgeWitnessService;
private final ArbitratorManager arbitratorManager;
private final ArbitrationManager arbitrationManager;
private final String appName;


@Inject
public SignPaymentAccountsWindow(AccountAgeWitnessService accountAgeWitnessService,
ArbitratorManager arbitratorManager,
ArbitrationManager arbitrationManager) {
ArbitrationManager arbitrationManager,
@Named(AppOptionKeys.APP_NAME_KEY) String appName) {
this.accountAgeWitnessService = accountAgeWitnessService;
this.arbitratorManager = arbitratorManager;
this.arbitrationManager = arbitrationManager;
this.appName = appName;
}

@Override
public void show() {
width = 1000;
rowIndex = -1;
createGridPane();
gridPane.getColumnConstraints().get(1).setHgrow(Priority.NEVER);

// We want to have more space to read list entries... initial screen does not look so nice now, but
// dynamically updating height of window is a bit tricky.... @christoph feel free to improve if you like...
gridPane.setPrefHeight(600);

gridPane.getColumnConstraints().get(1).setHgrow(Priority.NEVER);

headLine(Res.get("popup.accountSigning.selectAccounts.headline"));
type = Type.Attention;
Expand All @@ -108,7 +126,6 @@ public void show() {
}

private void addSelectAccountsContent() {

descriptionLabel = addMultilineLabel(gridPane, ++rowIndex,
Res.get("popup.accountSigning.selectAccounts.description"));

Expand All @@ -126,14 +143,17 @@ public PaymentMethod fromString(String s) {
}
});

List<PaymentMethod> list = PaymentMethod.getPaymentMethods().stream()
.filter(paymentMethod -> !paymentMethod.isAsset())
.filter(PaymentMethod::hasChargebackRisk)
.collect(Collectors.toList());

paymentMethodComboBox.setItems(FXCollections.observableArrayList(list));
paymentMethodComboBox.setItems(FXCollections.observableArrayList(getPaymentMethods()));
paymentMethodComboBox.setOnAction(e -> updateAccountSelectionState());

signAllCheckbox = addLabelCheckBox(gridPane, ++rowIndex, Res.get("popup.accountSigning.selectAccounts.signAll"));
GridPane.setHalignment(signAllCheckbox, HPos.LEFT);
signAllCheckbox.selectedProperty().addListener((observable, oldValue, newValue) -> {
paymentMethodComboBox.setDisable(newValue);
updateAccountSelectionState();
});

datePicker = addTopLabelDatePicker(gridPane, ++rowIndex,
Res.get("popup.accountSigning.selectAccounts.datePicker"),
0).second;
Expand All @@ -142,14 +162,21 @@ public PaymentMethod fromString(String s) {
.atZone(ZoneId.systemDefault()).toLocalDate());
}

private List<PaymentMethod> getPaymentMethods() {
return PaymentMethod.getPaymentMethods().stream()
.filter(paymentMethod -> !paymentMethod.isAsset())
.filter(PaymentMethod::hasChargebackRisk)
.collect(Collectors.toList());
}

private void addECKeyField() {
privateKey = addInputTextField(gridPane, ++rowIndex, Res.get("popup.accountSigning.signAccounts.ECKey"));
GridPane.setVgrow(privateKey, Priority.ALWAYS);
GridPane.setValignment(privateKey, VPos.TOP);
}

private void updateAccountSelectionState() {
actionButton.setDisable(paymentMethodComboBox.getSelectionModel().isEmpty() ||
actionButton.setDisable((!signAllCheckbox.isSelected() && paymentMethodComboBox.getSelectionModel().isEmpty()) ||
datePicker.getValue() == null
);
}
Expand All @@ -166,18 +193,55 @@ private void addSelectedAccountsContent() {
++rowIndex, Res.get("popup.accountSigning.confirmSelectedAccounts.headline"));
GridPane.setRowSpan(selectedPaymentAccountsTuple.third, 2);
selectedPaymentAccountsList = selectedPaymentAccountsTuple.second;
selectedPaymentAccountsList.setItems(FXCollections.observableArrayList(
accountAgeWitnessService.getTraderPaymentAccounts(
datePicker.getValue().atStartOfDay().toEpochSecond(ZoneOffset.UTC) * 1000,
paymentMethodComboBox.getSelectionModel().getSelectedItem(),
arbitrationManager.getDisputesAsObservableList())));
ObservableList<Dispute> disputesAsObservableList = arbitrationManager.getDisputesAsObservableList();
long safeDate = datePicker.getValue().atStartOfDay().toEpochSecond(ZoneOffset.UTC) * 1000;
List<TraderDataItem> traderDataItemList;
StringBuilder sb = new StringBuilder("Summary for ").append(appName).append("\n");
if (signAllCheckbox.isSelected()) {
traderDataItemList = new ArrayList<>();
getPaymentMethods().forEach(paymentMethod -> {
List<TraderDataItem> list = accountAgeWitnessService.getTraderPaymentAccounts(
safeDate,
paymentMethod,
disputesAsObservableList);
traderDataItemList.addAll(list);

sb.append("\nPayment method: ").append(Res.get(paymentMethod.getId()))
.append(" (No. of signed accounts: ").append(list.size()).append(")\n");
list.forEach(traderDataItem -> {
sb.append("Account created: ")
.append(BSFormatter.formatDateTime(new Date(traderDataItem.getAccountAgeWitness().getDate()), true))
.append(" Account: ")
.append(traderDataItem.getPaymentAccountPayload().getPaymentDetails()).append("\n");
});
});
sb.append("\nTotal accounts signed: ").append(traderDataItemList.size());
} else {
PaymentMethod paymentMethod = paymentMethodComboBox.getSelectionModel().getSelectedItem();
traderDataItemList = accountAgeWitnessService.getTraderPaymentAccounts(
safeDate,
paymentMethod,
disputesAsObservableList);
sb.append("\nPayment method: ").append(Res.get(paymentMethod.getId()))
.append(" (No. of signed accounts: ").append(traderDataItemList.size()).append(")\n");
traderDataItemList.forEach(traderDataItem -> {
sb.append("Account created: ")
.append(BSFormatter.formatDateTime(new Date(traderDataItem.getAccountAgeWitness().getDate()), true))
.append(" Account: ")
.append(traderDataItem.getPaymentAccountPayload().getPaymentDetails()).append("\n");
});
}
log.info(sb.toString());
Utilities.copyToClipboard(sb.toString());

selectedPaymentAccountsList.setItems(FXCollections.observableArrayList(traderDataItemList));

headLineLabel.setText(Res.get("popup.accountSigning.confirmSelectedAccounts.headline"));
descriptionLabel.setText(Res.get("popup.accountSigning.confirmSelectedAccounts.description",
selectedPaymentAccountsList.getItems().size()));
((AutoTooltipButton) actionButton).updateText(Res.get("popup.accountSigning.confirmSelectedAccounts.button"));

actionButton.setDisable(selectedPaymentAccountsList.getItems().size() == 0);
updateAccountSelectionState();

actionButton.setOnAction(e -> addAccountsToSignContent());

Expand All @@ -191,7 +255,7 @@ protected void updateItem(TraderDataItem item, boolean empty) {
super.updateItem(item, empty);

if (item != null && !empty) {
setText(item.getPaymentAccountPayload().toString());
setText(item.getPaymentAccountPayload().getPaymentDetails());
} else {
setText(null);
}
Expand Down

0 comments on commit d591763

Please sign in to comment.