Search in sources :

Example 11 with Contract

use of bisq.core.trade.Contract in project bisq-desktop by bisq-network.

the class ContractWindow method addContent.

private void addContent() {
    Contract contract = dispute.getContract();
    Offer offer = new Offer(contract.getOfferPayload());
    List<String> acceptedBanks = offer.getAcceptedBankIds();
    boolean showAcceptedBanks = acceptedBanks != null && !acceptedBanks.isEmpty();
    List<String> acceptedCountryCodes = offer.getAcceptedCountryCodes();
    boolean showAcceptedCountryCodes = acceptedCountryCodes != null && !acceptedCountryCodes.isEmpty();
    int rows = 17;
    if (dispute.getDepositTxSerialized() != null)
        rows++;
    if (dispute.getPayoutTxSerialized() != null)
        rows++;
    if (showAcceptedCountryCodes)
        rows++;
    if (showAcceptedBanks)
        rows++;
    PaymentAccountPayload sellerPaymentAccountPayload = contract.getSellerPaymentAccountPayload();
    addTitledGroupBg(gridPane, ++rowIndex, rows, Res.get("contractWindow.title"));
    addLabelTextFieldWithCopyIcon(gridPane, rowIndex, Res.getWithCol("shared.offerId"), offer.getId(), Layout.FIRST_ROW_DISTANCE).second.setMouseTransparent(false);
    addLabelTextField(gridPane, ++rowIndex, Res.get("contractWindow.dates"), formatter.formatDateTime(offer.getDate()) + " / " + formatter.formatDateTime(dispute.getTradeDate()));
    String currencyCode = offer.getCurrencyCode();
    addLabelTextField(gridPane, ++rowIndex, Res.getWithCol("shared.offerType"), formatter.getDirectionBothSides(offer.getDirection(), currencyCode));
    addLabelTextField(gridPane, ++rowIndex, Res.getWithCol("shared.tradePrice"), formatter.formatPrice(contract.getTradePrice()));
    addLabelTextField(gridPane, ++rowIndex, Res.getWithCol("shared.tradeAmount"), formatter.formatCoinWithCode(contract.getTradeAmount()));
    addLabelTextField(gridPane, ++rowIndex, formatter.formatVolumeLabel(currencyCode, ":"), formatter.formatVolumeWithCode(contract.getTradePrice().getVolumeByAmount(contract.getTradeAmount())));
    String securityDeposit = Res.getWithColAndCap("shared.buyer") + " " + formatter.formatCoinWithCode(offer.getBuyerSecurityDeposit()) + " / " + Res.getWithColAndCap("shared.seller") + " " + formatter.formatCoinWithCode(offer.getSellerSecurityDeposit());
    addLabelTextField(gridPane, ++rowIndex, Res.getWithCol("shared.securityDeposit"), securityDeposit);
    addLabelTextFieldWithCopyIcon(gridPane, ++rowIndex, Res.get("contractWindow.btcAddresses"), contract.getBuyerPayoutAddressString() + " / " + contract.getSellerPayoutAddressString()).second.setMouseTransparent(false);
    addLabelTextFieldWithCopyIcon(gridPane, ++rowIndex, Res.get("contractWindow.onions"), contract.getBuyerNodeAddress().getFullAddress() + " / " + contract.getSellerNodeAddress().getFullAddress());
    addLabelTextFieldWithCopyIcon(gridPane, ++rowIndex, Res.get("contractWindow.numDisputes"), disputeManager.getNrOfDisputes(true, contract) + " / " + disputeManager.getNrOfDisputes(false, contract));
    addLabelTextFieldWithCopyIcon(gridPane, ++rowIndex, Res.get("shared.paymentDetails", Res.get("shared.buyer")), contract.getBuyerPaymentAccountPayload().getPaymentDetails()).second.setMouseTransparent(false);
    addLabelTextFieldWithCopyIcon(gridPane, ++rowIndex, Res.get("shared.paymentDetails", Res.get("shared.seller")), sellerPaymentAccountPayload.getPaymentDetails()).second.setMouseTransparent(false);
    addLabelTextFieldWithCopyIcon(gridPane, ++rowIndex, Res.get("shared.arbitrator"), contract.getArbitratorNodeAddress().getFullAddress());
    if (showAcceptedCountryCodes) {
        String countries;
        Tooltip tooltip = null;
        if (CountryUtil.containsAllSepaEuroCountries(acceptedCountryCodes)) {
            countries = Res.getWithCol("shared.allEuroCountries");
        } else {
            countries = CountryUtil.getCodesString(acceptedCountryCodes);
            tooltip = new Tooltip(CountryUtil.getNamesByCodesString(acceptedCountryCodes));
        }
        TextField acceptedCountries = addLabelTextField(gridPane, ++rowIndex, Res.getWithCol("shared.acceptedTakerCountries"), countries).second;
        if (tooltip != null)
            acceptedCountries.setTooltip(new Tooltip());
    }
    if (showAcceptedBanks) {
        if (offer.getPaymentMethod().equals(PaymentMethod.SAME_BANK)) {
            addLabelTextField(gridPane, ++rowIndex, Res.getWithCol("shared.bankName"), acceptedBanks.get(0));
        } else if (offer.getPaymentMethod().equals(PaymentMethod.SPECIFIC_BANKS)) {
            String value = Joiner.on(", ").join(acceptedBanks);
            Tooltip tooltip = new Tooltip(Res.getWithCol("shared.acceptedBanks") + value);
            TextField acceptedBanksTextField = addLabelTextField(gridPane, ++rowIndex, Res.getWithCol("shared.acceptedBanks"), value).second;
            acceptedBanksTextField.setMouseTransparent(false);
            acceptedBanksTextField.setTooltip(tooltip);
        }
    }
    addLabelTxIdTextField(gridPane, ++rowIndex, Res.get("shared.makerFeeTxId"), offer.getOfferFeePaymentTxId());
    addLabelTxIdTextField(gridPane, ++rowIndex, Res.get("shared.takerFeeTxId"), contract.getTakerFeeTxID());
    if (dispute.getDepositTxSerialized() != null)
        addLabelTxIdTextField(gridPane, ++rowIndex, Res.getWithCol("shared.depositTransactionId"), dispute.getDepositTxId());
    if (dispute.getPayoutTxSerialized() != null)
        addLabelTxIdTextField(gridPane, ++rowIndex, Res.get("shared.payoutTxId"), dispute.getPayoutTxId());
    if (dispute.getContractHash() != null)
        addLabelTextFieldWithCopyIcon(gridPane, ++rowIndex, Res.get("contractWindow.contractHash"), Utils.HEX.encode(dispute.getContractHash())).second.setMouseTransparent(false);
    Button viewContractButton = addLabelButton(gridPane, ++rowIndex, Res.get("shared.contractAsJson"), Res.get("shared.viewContractAsJson"), 0).second;
    viewContractButton.setDefaultButton(false);
    viewContractButton.setOnAction(e -> {
        TextArea textArea = new TextArea();
        String contractAsJson = dispute.getContractAsJson();
        contractAsJson += "\n\nBuyerMultiSigPubKeyHex: " + Utils.HEX.encode(contract.getBuyerMultiSigPubKey());
        contractAsJson += "\nSellerMultiSigPubKeyHex: " + Utils.HEX.encode(contract.getSellerMultiSigPubKey());
        textArea.setText(contractAsJson);
        textArea.setPrefHeight(50);
        textArea.setEditable(false);
        textArea.setWrapText(true);
        textArea.setPrefSize(800, 600);
        Scene viewContractScene = new Scene(textArea);
        Stage viewContractStage = new Stage();
        viewContractStage.setTitle(Res.get("shared.contract.title", dispute.getShortTradeId()));
        viewContractStage.setScene(viewContractScene);
        if (owner == null)
            owner = MainView.getRootContainer();
        Scene rootScene = owner.getScene();
        viewContractStage.initOwner(rootScene.getWindow());
        viewContractStage.initModality(Modality.NONE);
        viewContractStage.initStyle(StageStyle.UTILITY);
        viewContractStage.show();
        Window window = rootScene.getWindow();
        double titleBarHeight = window.getHeight() - rootScene.getHeight();
        viewContractStage.setX(Math.round(window.getX() + (owner.getWidth() - viewContractStage.getWidth()) / 2) + 200);
        viewContractStage.setY(Math.round(window.getY() + titleBarHeight + (owner.getHeight() - viewContractStage.getHeight()) / 2) + 50);
    });
    Button closeButton = addButtonAfterGroup(gridPane, ++rowIndex, Res.get("shared.close"));
    // TODO app wide focus
    // closeButton.requestFocus();
    closeButton.setOnAction(e -> {
        closeHandlerOptional.ifPresent(Runnable::run);
        hide();
    });
}
Also used : Window(javafx.stage.Window) TextArea(javafx.scene.control.TextArea) Tooltip(javafx.scene.control.Tooltip) PaymentAccountPayload(bisq.core.payment.payload.PaymentAccountPayload) Scene(javafx.scene.Scene) Offer(bisq.core.offer.Offer) Button(javafx.scene.control.Button) TextField(javafx.scene.control.TextField) Stage(javafx.stage.Stage) Contract(bisq.core.trade.Contract)

Example 12 with Contract

use of bisq.core.trade.Contract in project bisq-core by bisq-network.

the class DisputeManager method sendDisputeDirectMessage.

// traders send msg to the arbitrator or arbitrator to 1 trader (trader to trader is not allowed)
public DisputeCommunicationMessage sendDisputeDirectMessage(Dispute dispute, String text, ArrayList<Attachment> attachments) {
    DisputeCommunicationMessage disputeCommunicationMessage = new DisputeCommunicationMessage(dispute.getTradeId(), dispute.getTraderPubKeyRing().hashCode(), isTrader(dispute), text, null, p2PService.getAddress(), new Date().getTime(), false, false, UUID.randomUUID().toString());
    disputeCommunicationMessage.addAllAttachments(attachments);
    PubKeyRing receiverPubKeyRing = null;
    NodeAddress peerNodeAddress = null;
    if (isTrader(dispute)) {
        dispute.addDisputeMessage(disputeCommunicationMessage);
        receiverPubKeyRing = dispute.getArbitratorPubKeyRing();
        peerNodeAddress = dispute.getContract().getArbitratorNodeAddress();
    } else if (isArbitrator(dispute)) {
        if (!disputeCommunicationMessage.isSystemMessage())
            dispute.addDisputeMessage(disputeCommunicationMessage);
        receiverPubKeyRing = dispute.getTraderPubKeyRing();
        Contract contract = dispute.getContract();
        if (contract.getBuyerPubKeyRing().equals(receiverPubKeyRing))
            peerNodeAddress = contract.getBuyerNodeAddress();
        else
            peerNodeAddress = contract.getSellerNodeAddress();
    } else {
        log.error("That must not happen. Trader cannot communicate to other trader.");
    }
    if (receiverPubKeyRing != null) {
        log.trace("sendDisputeDirectMessage to peerAddress " + peerNodeAddress);
        p2PService.sendEncryptedMailboxMessage(peerNodeAddress, receiverPubKeyRing, disputeCommunicationMessage, new SendMailboxMessageListener() {

            @Override
            public void onArrived() {
                log.info("Message arrived at peer. tradeId={}", disputeCommunicationMessage.getTradeId());
                disputeCommunicationMessage.setArrived(true);
            }

            @Override
            public void onStoredInMailbox() {
                log.info("Message stored in mailbox. tradeId={}", disputeCommunicationMessage.getTradeId());
                disputeCommunicationMessage.setStoredInMailbox(true);
            }

            @Override
            public void onFault(String errorMessage) {
                log.error("sendEncryptedMailboxMessage failed. disputeCommunicationMessage=" + disputeCommunicationMessage);
            }
        });
    }
    return disputeCommunicationMessage;
}
Also used : PubKeyRing(bisq.common.crypto.PubKeyRing) NodeAddress(bisq.network.p2p.NodeAddress) SendMailboxMessageListener(bisq.network.p2p.SendMailboxMessageListener) Contract(bisq.core.trade.Contract) DisputeCommunicationMessage(bisq.core.arbitration.messages.DisputeCommunicationMessage) Date(java.util.Date)

Example 13 with Contract

use of bisq.core.trade.Contract in project bisq-core by bisq-network.

the class DisputeManager method sendDisputeResultMessage.

// arbitrator send result to trader
public void sendDisputeResultMessage(DisputeResult disputeResult, Dispute dispute, String text) {
    DisputeCommunicationMessage disputeCommunicationMessage = new DisputeCommunicationMessage(dispute.getTradeId(), dispute.getTraderPubKeyRing().hashCode(), false, text, null, p2PService.getAddress(), new Date().getTime(), false, false, UUID.randomUUID().toString());
    dispute.addDisputeMessage(disputeCommunicationMessage);
    disputeResult.setDisputeCommunicationMessage(disputeCommunicationMessage);
    NodeAddress peerNodeAddress;
    Contract contract = dispute.getContract();
    if (contract.getBuyerPubKeyRing().equals(dispute.getTraderPubKeyRing()))
        peerNodeAddress = contract.getBuyerNodeAddress();
    else
        peerNodeAddress = contract.getSellerNodeAddress();
    p2PService.sendEncryptedMailboxMessage(peerNodeAddress, dispute.getTraderPubKeyRing(), new DisputeResultMessage(disputeResult, p2PService.getAddress(), UUID.randomUUID().toString()), new SendMailboxMessageListener() {

        @Override
        public void onArrived() {
            log.info("Message arrived at peer. tradeId={}", disputeCommunicationMessage.getTradeId());
            disputeCommunicationMessage.setArrived(true);
        }

        @Override
        public void onStoredInMailbox() {
            log.info("Message stored in mailbox. tradeId={}", disputeCommunicationMessage.getTradeId());
            disputeCommunicationMessage.setStoredInMailbox(true);
        }

        @Override
        public void onFault(String errorMessage) {
            log.error("sendEncryptedMailboxMessage failed. disputeCommunicationMessage=" + disputeCommunicationMessage);
        }
    });
}
Also used : DisputeResultMessage(bisq.core.arbitration.messages.DisputeResultMessage) NodeAddress(bisq.network.p2p.NodeAddress) SendMailboxMessageListener(bisq.network.p2p.SendMailboxMessageListener) Contract(bisq.core.trade.Contract) DisputeCommunicationMessage(bisq.core.arbitration.messages.DisputeCommunicationMessage) Date(java.util.Date)

Example 14 with Contract

use of bisq.core.trade.Contract in project bisq-desktop by bisq-network.

the class DisputeSummaryWindow method addContent.

private void addContent() {
    Contract contract = dispute.getContract();
    if (dispute.getDisputeResultProperty().get() == null)
        disputeResult = new DisputeResult(dispute.getTradeId(), dispute.getTraderId());
    else
        disputeResult = dispute.getDisputeResultProperty().get();
    peersDisputeOptional = disputeManager.getDisputesAsObservableList().stream().filter(d -> dispute.getTradeId().equals(d.getTradeId()) && dispute.getTraderId() != d.getTraderId()).findFirst();
    addInfoPane();
    if (!dispute.isSupportTicket())
        addCheckboxes();
    addTradeAmountPayoutControls();
    addPayoutAmountTextFields();
    addReasonControls();
    boolean applyPeersDisputeResult = peersDisputeOptional.isPresent() && peersDisputeOptional.get().isClosed();
    if (applyPeersDisputeResult) {
        // If the other peers dispute has been closed we apply the result to ourselves
        DisputeResult peersDisputeResult = peersDisputeOptional.get().getDisputeResultProperty().get();
        disputeResult.setBuyerPayoutAmount(peersDisputeResult.getBuyerPayoutAmount());
        disputeResult.setSellerPayoutAmount(peersDisputeResult.getSellerPayoutAmount());
        disputeResult.setWinner(peersDisputeResult.getWinner());
        disputeResult.setLoserPublisher(peersDisputeResult.isLoserPublisher());
        disputeResult.setReason(peersDisputeResult.getReason());
        disputeResult.setSummaryNotes(peersDisputeResult.summaryNotesProperty().get());
        /* if (disputeResult.getBuyerPayoutAmount() != null) {
                log.debug("buyerPayoutAmount " + disputeResult.getBuyerPayoutAmount().toFriendlyString());
                log.debug("sellerPayoutAmount " + disputeResult.getSellerPayoutAmount().toFriendlyString());
            }*/
        buyerGetsTradeAmountRadioButton.setDisable(true);
        buyerGetsAllRadioButton.setDisable(true);
        sellerGetsTradeAmountRadioButton.setDisable(true);
        sellerGetsAllRadioButton.setDisable(true);
        customRadioButton.setDisable(true);
        buyerPayoutAmountInputTextField.setDisable(true);
        sellerPayoutAmountInputTextField.setDisable(true);
        buyerPayoutAmountInputTextField.setEditable(false);
        sellerPayoutAmountInputTextField.setEditable(false);
        reasonWasBugRadioButton.setDisable(true);
        reasonWasUsabilityIssueRadioButton.setDisable(true);
        reasonProtocolViolationRadioButton.setDisable(true);
        reasonNoReplyRadioButton.setDisable(true);
        reasonWasScamRadioButton.setDisable(true);
        reasonWasOtherRadioButton.setDisable(true);
        reasonWasBankRadioButton.setDisable(true);
        isLoserPublisherCheckBox.setDisable(true);
        isLoserPublisherCheckBox.setSelected(peersDisputeResult.isLoserPublisher());
        applyPayoutAmounts(tradeAmountToggleGroup.selectedToggleProperty().get());
        applyTradeAmountRadioButtonStates();
    } else {
        isLoserPublisherCheckBox.setSelected(false);
    }
    setReasonRadioButtonState();
    addSummaryNotes();
    addButtons(contract);
}
Also used : Contract(bisq.core.trade.Contract) DisputeResult(bisq.core.arbitration.DisputeResult)

Example 15 with Contract

use of bisq.core.trade.Contract in project bisq-desktop by bisq-network.

the class DisputeSummaryWindow method applyPayoutAmountsToDisputeResult.

private void applyPayoutAmountsToDisputeResult(Toggle selectedTradeAmountToggle) {
    Contract contract = dispute.getContract();
    Offer offer = new Offer(contract.getOfferPayload());
    Coin buyerSecurityDeposit = offer.getBuyerSecurityDeposit();
    Coin sellerSecurityDeposit = offer.getSellerSecurityDeposit();
    Coin tradeAmount = contract.getTradeAmount();
    if (selectedTradeAmountToggle == buyerGetsTradeAmountRadioButton) {
        disputeResult.setBuyerPayoutAmount(tradeAmount.add(buyerSecurityDeposit));
        disputeResult.setSellerPayoutAmount(sellerSecurityDeposit);
        disputeResult.setWinner(DisputeResult.Winner.BUYER);
    } else if (selectedTradeAmountToggle == buyerGetsAllRadioButton) {
        disputeResult.setBuyerPayoutAmount(tradeAmount.add(buyerSecurityDeposit).add(sellerSecurityDeposit));
        disputeResult.setSellerPayoutAmount(Coin.ZERO);
        disputeResult.setWinner(DisputeResult.Winner.BUYER);
    } else if (selectedTradeAmountToggle == sellerGetsTradeAmountRadioButton) {
        disputeResult.setBuyerPayoutAmount(buyerSecurityDeposit);
        disputeResult.setSellerPayoutAmount(tradeAmount.add(sellerSecurityDeposit));
        disputeResult.setWinner(DisputeResult.Winner.SELLER);
    } else if (selectedTradeAmountToggle == sellerGetsAllRadioButton) {
        disputeResult.setBuyerPayoutAmount(Coin.ZERO);
        disputeResult.setSellerPayoutAmount(tradeAmount.add(sellerSecurityDeposit).add(buyerSecurityDeposit));
        disputeResult.setWinner(DisputeResult.Winner.SELLER);
    }
    buyerPayoutAmountInputTextField.setText(formatter.formatCoin(disputeResult.getBuyerPayoutAmount()));
    sellerPayoutAmountInputTextField.setText(formatter.formatCoin(disputeResult.getSellerPayoutAmount()));
}
Also used : Coin(org.bitcoinj.core.Coin) Offer(bisq.core.offer.Offer) Contract(bisq.core.trade.Contract)

Aggregations

Contract (bisq.core.trade.Contract)17 Offer (bisq.core.offer.Offer)7 Coin (org.bitcoinj.core.Coin)6 PaymentAccountPayload (bisq.core.payment.payload.PaymentAccountPayload)5 NodeAddress (bisq.network.p2p.NodeAddress)5 DisputeCommunicationMessage (bisq.core.arbitration.messages.DisputeCommunicationMessage)4 AddressEntry (bisq.core.btc.AddressEntry)3 BtcWalletService (bisq.core.btc.wallet.BtcWalletService)3 TradingPeer (bisq.core.trade.protocol.TradingPeer)3 SendMailboxMessageListener (bisq.network.p2p.SendMailboxMessageListener)3 Date (java.util.Date)3 Button (javafx.scene.control.Button)3 Tooltip (javafx.scene.control.Tooltip)3 PubKeyRing (bisq.common.crypto.PubKeyRing)2 Trade (bisq.core.trade.Trade)2 TextFieldWithCopyIcon (bisq.desktop.components.TextFieldWithCopyIcon)2 Scene (javafx.scene.Scene)2 TextArea (javafx.scene.control.TextArea)2 TextField (javafx.scene.control.TextField)2 Stage (javafx.stage.Stage)2