Search in sources :

Example 6 with Dispute

use of io.bitsquare.arbitration.Dispute in project bitsquare by bitsquare.

the class TraderDisputeView method initialize.

@Override
public void initialize() {
    Label label = new Label("Filter list:");
    HBox.setMargin(label, new Insets(5, 0, 0, 0));
    filterTextField = new InputTextField();
    filterTextField.setText("open");
    filterTextFieldListener = (observable, oldValue, newValue) -> applyFilteredListPredicate(filterTextField.getText());
    filterBox = new HBox();
    filterBox.setSpacing(5);
    filterBox.getChildren().addAll(label, filterTextField);
    VBox.setVgrow(filterBox, Priority.NEVER);
    filterBox.setVisible(false);
    filterBox.setManaged(false);
    tableView = new TableView<>();
    VBox.setVgrow(tableView, Priority.SOMETIMES);
    tableView.setMinHeight(150);
    root.getChildren().addAll(filterBox, tableView);
    tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
    Label placeholder = new Label("There are no open tickets");
    placeholder.setWrapText(true);
    tableView.setPlaceholder(placeholder);
    tableView.getSelectionModel().clearSelection();
    tableView.getColumns().add(getSelectColumn());
    TableColumn<Dispute, Dispute> contractColumn = getContractColumn();
    tableView.getColumns().add(contractColumn);
    TableColumn<Dispute, Dispute> dateColumn = getDateColumn();
    tableView.getColumns().add(dateColumn);
    TableColumn<Dispute, Dispute> tradeIdColumn = getTradeIdColumn();
    tableView.getColumns().add(tradeIdColumn);
    TableColumn<Dispute, Dispute> buyerOnionAddressColumn = getBuyerOnionAddressColumn();
    tableView.getColumns().add(buyerOnionAddressColumn);
    TableColumn<Dispute, Dispute> sellerOnionAddressColumn = getSellerOnionAddressColumn();
    tableView.getColumns().add(sellerOnionAddressColumn);
    TableColumn<Dispute, Dispute> marketColumn = getMarketColumn();
    tableView.getColumns().add(marketColumn);
    TableColumn<Dispute, Dispute> roleColumn = getRoleColumn();
    tableView.getColumns().add(roleColumn);
    TableColumn<Dispute, Dispute> stateColumn = getStateColumn();
    tableView.getColumns().add(stateColumn);
    tradeIdColumn.setComparator((o1, o2) -> o1.getTradeId().compareTo(o2.getTradeId()));
    dateColumn.setComparator((o1, o2) -> o1.getOpeningDate().compareTo(o2.getOpeningDate()));
    buyerOnionAddressColumn.setComparator((o1, o2) -> getBuyerOnionAddressColumnLabel(o1).compareTo(getBuyerOnionAddressColumnLabel(o2)));
    sellerOnionAddressColumn.setComparator((o1, o2) -> getSellerOnionAddressColumnLabel(o1).compareTo(getSellerOnionAddressColumnLabel(o2)));
    marketColumn.setComparator((o1, o2) -> formatter.getCurrencyPair(o1.getContract().offer.getCurrencyCode()).compareTo(o2.getContract().offer.getCurrencyCode()));
    dateColumn.setSortType(TableColumn.SortType.DESCENDING);
    tableView.getSortOrder().add(dateColumn);
    /*inputTextAreaListener = (observable, oldValue, newValue) ->
                sendButton.setDisable(newValue.length() == 0
                        && tempAttachments.size() == 0 &&
                        selectedDispute.disputeResultProperty().get() == null);*/
    selectedDisputeClosedPropertyListener = (observable, oldValue, newValue) -> {
        messagesInputBox.setVisible(!newValue);
        messagesInputBox.setManaged(!newValue);
        AnchorPane.setBottomAnchor(messageListView, newValue ? 0d : 120d);
    };
    disputeDirectMessageListListener = c -> scrollToBottom();
    keyEventEventHandler = event -> {
        if (new KeyCodeCombination(KeyCode.L, KeyCombination.ALT_DOWN).match(event)) {
            Map<String, List<Dispute>> map = new HashMap<>();
            disputeManager.getDisputesAsObservableList().stream().forEach(dispute -> {
                String tradeId = dispute.getTradeId();
                List<Dispute> list;
                if (!map.containsKey(tradeId))
                    map.put(tradeId, new ArrayList<>());
                list = map.get(tradeId);
                list.add(dispute);
            });
            List<List<Dispute>> disputeGroups = new ArrayList<>();
            map.entrySet().stream().forEach(entry -> {
                disputeGroups.add(entry.getValue());
            });
            disputeGroups.sort((o1, o2) -> !o1.isEmpty() && !o2.isEmpty() ? o1.get(0).getOpeningDate().compareTo(o2.get(0).getOpeningDate()) : 0);
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append("Summary of all disputes (No. of disputes: " + disputeGroups.size() + ")\n\n");
            disputeGroups.stream().forEach(disputeGroup -> {
                Dispute dispute0 = disputeGroup.get(0);
                stringBuilder.append("##########################################################################################/\n").append("## Trade ID: ").append(dispute0.getTradeId()).append("\n").append("## Date: ").append(formatter.formatDateTime(dispute0.getOpeningDate())).append("\n").append("## Is support ticket: ").append(dispute0.isSupportTicket()).append("\n");
                if (dispute0.disputeResultProperty().get() != null && dispute0.disputeResultProperty().get().getReason() != null) {
                    stringBuilder.append("## Reason: ").append(dispute0.disputeResultProperty().get().getReason()).append("\n");
                }
                stringBuilder.append("##########################################################################################/\n").append("\n");
                disputeGroup.stream().forEach(dispute -> {
                    stringBuilder.append("*******************************************************************************************\n").append("** Trader's ID: ").append(dispute.getTraderId()).append("\n*******************************************************************************************\n").append("\n");
                    dispute.getDisputeCommunicationMessagesAsObservableList().stream().forEach(m -> {
                        String role = m.isSenderIsTrader() ? ">> Trader's msg: " : "<< Arbitrator's msg: ";
                        stringBuilder.append(role).append(m.getMessage()).append("\n");
                    });
                    stringBuilder.append("\n");
                });
                stringBuilder.append("\n");
            });
            String message = stringBuilder.toString();
            new Popup().headLine("All disputes (" + disputeGroups.size() + ")").information(message).width(1000).actionButtonText("Copy").onAction(() -> Utilities.copyToClipboard(message)).show();
        } else if (new KeyCodeCombination(KeyCode.U, KeyCombination.ALT_DOWN).match(event)) {
            if (selectedDispute != null) {
                if (selectedDisputeClosedPropertyListener != null)
                    selectedDispute.isClosedProperty().removeListener(selectedDisputeClosedPropertyListener);
                selectedDispute.setIsClosed(false);
            }
        } else if (new KeyCodeCombination(KeyCode.R, KeyCombination.ALT_DOWN).match(event)) {
            if (selectedDispute != null) {
                PubKeyRing pubKeyRing = selectedDispute.getTraderPubKeyRing();
                NodeAddress nodeAddress;
                if (pubKeyRing.equals(selectedDispute.getContract().getBuyerPubKeyRing()))
                    nodeAddress = selectedDispute.getContract().getBuyerNodeAddress();
                else
                    nodeAddress = selectedDispute.getContract().getSellerNodeAddress();
                new SendPrivateNotificationWindow(pubKeyRing, nodeAddress).onAddAlertMessage(privateNotificationManager::sendPrivateNotificationMessageIfKeyIsValid).show();
            }
        }
    };
}
Also used : Insets(javafx.geometry.Insets) InputTextField(io.bitsquare.gui.components.InputTextField) KeyCodeCombination(javafx.scene.input.KeyCodeCombination) SendPrivateNotificationWindow(io.bitsquare.gui.main.overlays.windows.SendPrivateNotificationWindow) Popup(io.bitsquare.gui.main.overlays.popups.Popup) PubKeyRing(io.bitsquare.common.crypto.PubKeyRing) Dispute(io.bitsquare.arbitration.Dispute) SortedList(javafx.collections.transformation.SortedList) FilteredList(javafx.collections.transformation.FilteredList) ObservableList(javafx.collections.ObservableList) NodeAddress(io.bitsquare.p2p.NodeAddress)

Example 7 with Dispute

use of io.bitsquare.arbitration.Dispute in project bitsquare by bitsquare.

the class TraderDisputeView method activate.

@Override
protected void activate() {
    filterTextField.textProperty().addListener(filterTextFieldListener);
    disputeManager.cleanupDisputes();
    filteredList = new FilteredList<>(disputeManager.getDisputesAsObservableList());
    applyFilteredListPredicate(filterTextField.getText());
    sortedList = new SortedList<>(filteredList);
    sortedList.comparatorProperty().bind(tableView.comparatorProperty());
    tableView.setItems(sortedList);
    // sortedList.setComparator((o1, o2) -> o2.getOpeningDate().compareTo(o1.getOpeningDate()));
    selectedDisputeSubscription = EasyBind.subscribe(tableView.getSelectionModel().selectedItemProperty(), this::onSelectDispute);
    Dispute selectedItem = tableView.getSelectionModel().getSelectedItem();
    if (selectedItem != null)
        tableView.getSelectionModel().select(selectedItem);
    scrollToBottom();
    scene = root.getScene();
    if (scene != null)
        scene.addEventHandler(KeyEvent.KEY_RELEASED, keyEventEventHandler);
    // If doPrint=true we print out a html page which opens tabs with all deposit txs 
    // (firefox needs about:config change to allow > 20 tabs)
    // Useful to check if there any funds in not finished trades (no payout tx done).
    // Last check 10.02.2017 found 8 trades and we contacted all traders as far as possible (email if available 
    // otherwise in-app private notification)
    boolean doPrint = false;
    if (doPrint) {
        try {
            DateFormat formatter = new SimpleDateFormat("dd/MM/yy");
            Date startDate = formatter.parse("10/02/17");
            // print all from start
            startDate = new Date(0);
            HashMap<String, Dispute> map = new HashMap<>();
            disputeManager.getDisputesAsObservableList().stream().forEach(dispute -> {
                map.put(dispute.getDepositTxId(), dispute);
            });
            final Date finalStartDate = startDate;
            List<Dispute> disputes = new ArrayList<>(map.values());
            disputes.sort((o1, o2) -> o1.getOpeningDate().compareTo(o2.getOpeningDate()));
            List<List<Dispute>> subLists = Lists.partition(disputes, 1000);
            StringBuilder sb = new StringBuilder();
            subLists.stream().forEach(list -> {
                StringBuilder sb1 = new StringBuilder("\n<html><head><script type=\"text/javascript\">function load(){\n");
                StringBuilder sb2 = new StringBuilder("\n}</script></head><body onload=\"load()\">\n");
                list.stream().forEach(dispute -> {
                    if (dispute.getOpeningDate().after(finalStartDate)) {
                        String txId = dispute.getDepositTxId();
                        sb1.append("window.open(\"https://blockchain.info/tx/").append(txId).append("\", '_blank');\n");
                        sb2.append("Dispute ID: ").append(dispute.getId()).append(" Tx ID: ").append("<a href=\"https://blockchain.info/tx/").append(txId).append("\">").append(txId).append("</a> ").append("Opening date: ").append(formatter.format(dispute.getOpeningDate())).append("<br/>\n");
                    }
                });
                sb2.append("</body></html>");
                String res = sb1.toString() + sb2.toString();
                sb.append(res).append("\n\n\n");
            });
            log.info(sb.toString());
        } catch (ParseException ignore) {
        }
    }
}
Also used : DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) Dispute(io.bitsquare.arbitration.Dispute) SortedList(javafx.collections.transformation.SortedList) FilteredList(javafx.collections.transformation.FilteredList) ObservableList(javafx.collections.ObservableList) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat)

Example 8 with Dispute

use of io.bitsquare.arbitration.Dispute in project bitsquare by bitsquare.

the class PendingTradesDataModel method doOpenDispute.

private void doOpenDispute(boolean isSupportTicket, Transaction depositTx) {
    Log.traceCall("depositTx=" + depositTx);
    byte[] depositTxSerialized = null;
    byte[] payoutTxSerialized = null;
    String depositTxHashAsString = null;
    String payoutTxHashAsString = null;
    if (depositTx != null) {
        depositTxSerialized = depositTx.bitcoinSerialize();
        depositTxHashAsString = depositTx.getHashAsString();
    } else {
        log.warn("depositTx is null");
    }
    Trade trade = getTrade();
    if (trade != null) {
        Transaction payoutTx = trade.getPayoutTx();
        if (payoutTx != null) {
            payoutTxSerialized = payoutTx.bitcoinSerialize();
            payoutTxHashAsString = payoutTx.getHashAsString();
        } else {
            log.debug("payoutTx is null at doOpenDispute");
        }
        final Arbitrator acceptedArbitratorByAddress = user.getAcceptedArbitratorByAddress(trade.getArbitratorNodeAddress());
        checkNotNull(acceptedArbitratorByAddress, "acceptedArbitratorByAddress must no tbe null");
        Dispute dispute = new Dispute(disputeManager.getDisputeStorage(), trade.getId(), // traderId
        keyRing.getPubKeyRing().hashCode(), trade.getOffer().getDirection() == Offer.Direction.BUY ? isOfferer : !isOfferer, isOfferer, keyRing.getPubKeyRing(), trade.getDate(), trade.getContract(), trade.getContractHash(), depositTxSerialized, payoutTxSerialized, depositTxHashAsString, payoutTxHashAsString, trade.getContractAsJson(), trade.getOffererContractSignature(), trade.getTakerContractSignature(), acceptedArbitratorByAddress.getPubKeyRing(), isSupportTicket);
        trade.setDisputeState(Trade.DisputeState.DISPUTE_REQUESTED);
        if (p2PService.isBootstrapped()) {
            sendOpenNewDisputeMessage(dispute, false);
        } else {
            new Popup().information("You need to wait until you are fully connected to the network.\n" + "That might take up to about 2 minutes at startup.").show();
        }
    } else {
        log.warn("trade is null at doOpenDispute");
    }
}
Also used : Trade(io.bitsquare.trade.Trade) BuyerTrade(io.bitsquare.trade.BuyerTrade) SellerTrade(io.bitsquare.trade.SellerTrade) Transaction(org.bitcoinj.core.Transaction) Popup(io.bitsquare.gui.main.overlays.popups.Popup) Dispute(io.bitsquare.arbitration.Dispute) Arbitrator(io.bitsquare.arbitration.Arbitrator)

Aggregations

Dispute (io.bitsquare.arbitration.Dispute)8 Popup (io.bitsquare.gui.main.overlays.popups.Popup)7 Trade (io.bitsquare.trade.Trade)5 ObservableList (javafx.collections.ObservableList)5 PrivateNotificationManager (io.bitsquare.alert.PrivateNotificationManager)4 Version (io.bitsquare.app.Version)4 DisputeManager (io.bitsquare.arbitration.DisputeManager)4 Timer (io.bitsquare.common.Timer)4 UserThread (io.bitsquare.common.UserThread)4 PubKeyRing (io.bitsquare.common.crypto.PubKeyRing)4 InputTextField (io.bitsquare.gui.components.InputTextField)4 SendPrivateNotificationWindow (io.bitsquare.gui.main.overlays.windows.SendPrivateNotificationWindow)4 BSFormatter (io.bitsquare.gui.util.BSFormatter)4 GUIUtil (io.bitsquare.gui.util.GUIUtil)4 NodeAddress (io.bitsquare.p2p.NodeAddress)4 P2PService (io.bitsquare.p2p.P2PService)4 Connection (io.bitsquare.p2p.network.Connection)4 TradeManager (io.bitsquare.trade.TradeManager)4 FilteredList (javafx.collections.transformation.FilteredList)4 SortedList (javafx.collections.transformation.SortedList)4