Search in sources :

Example 6 with Contract

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

the class DisputeSummaryWindow method applyTradeAmountRadioButtonStates.

private void applyTradeAmountRadioButtonStates() {
    Contract contract = dispute.getContract();
    Offer offer = new Offer(contract.getOfferPayload());
    Coin buyerSecurityDeposit = offer.getBuyerSecurityDeposit();
    Coin sellerSecurityDeposit = offer.getSellerSecurityDeposit();
    Coin tradeAmount = contract.getTradeAmount();
    Coin buyerPayoutAmount = disputeResult.getBuyerPayoutAmount();
    Coin sellerPayoutAmount = disputeResult.getSellerPayoutAmount();
    buyerPayoutAmountInputTextField.setText(formatter.formatCoin(buyerPayoutAmount));
    sellerPayoutAmountInputTextField.setText(formatter.formatCoin(sellerPayoutAmount));
    if (buyerPayoutAmount.equals(tradeAmount.add(buyerSecurityDeposit)) && sellerPayoutAmount.equals(sellerSecurityDeposit)) {
        buyerGetsTradeAmountRadioButton.setSelected(true);
    } else if (buyerPayoutAmount.equals(tradeAmount.add(buyerSecurityDeposit).add(sellerSecurityDeposit)) && sellerPayoutAmount.equals(Coin.ZERO)) {
        buyerGetsAllRadioButton.setSelected(true);
    } else if (sellerPayoutAmount.equals(tradeAmount.add(sellerSecurityDeposit)) && buyerPayoutAmount.equals(buyerSecurityDeposit)) {
        sellerGetsTradeAmountRadioButton.setSelected(true);
    } else if (sellerPayoutAmount.equals(tradeAmount.add(buyerSecurityDeposit).add(sellerSecurityDeposit)) && buyerPayoutAmount.equals(Coin.ZERO)) {
        sellerGetsAllRadioButton.setSelected(true);
    } else {
        customRadioButton.setSelected(true);
    }
}
Also used : Coin(org.bitcoinj.core.Coin) Offer(bisq.core.offer.Offer) Contract(bisq.core.trade.Contract)

Example 7 with Contract

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

the class DisputeSummaryWindow method applyCustomAmounts.

private void applyCustomAmounts(InputTextField inputTextField) {
    Contract contract = dispute.getContract();
    Coin buyerAmount = formatter.parseToCoin(buyerPayoutAmountInputTextField.getText());
    Coin sellerAmount = formatter.parseToCoin(sellerPayoutAmountInputTextField.getText());
    Offer offer = new Offer(contract.getOfferPayload());
    Coin available = contract.getTradeAmount().add(offer.getBuyerSecurityDeposit()).add(offer.getSellerSecurityDeposit());
    Coin totalAmount = buyerAmount.add(sellerAmount);
    if (totalAmount.compareTo(available) > 0) {
        new Popup<>().warning(Res.get("disputeSummaryWindow.payout.adjustAmount", available.toFriendlyString())).show();
        if (inputTextField == buyerPayoutAmountInputTextField) {
            buyerAmount = available.subtract(sellerAmount);
            inputTextField.setText(formatter.formatCoin(buyerAmount));
        } else if (inputTextField == sellerPayoutAmountInputTextField) {
            sellerAmount = available.subtract(buyerAmount);
            inputTextField.setText(formatter.formatCoin(sellerAmount));
        }
    }
    disputeResult.setBuyerPayoutAmount(buyerAmount);
    disputeResult.setSellerPayoutAmount(sellerAmount);
    if (buyerAmount.compareTo(sellerAmount) > 0)
        disputeResult.setWinner(DisputeResult.Winner.BUYER);
    else
        disputeResult.setWinner(DisputeResult.Winner.SELLER);
}
Also used : Coin(org.bitcoinj.core.Coin) Offer(bisq.core.offer.Offer) Popup(bisq.desktop.main.overlays.popups.Popup) Contract(bisq.core.trade.Contract)

Example 8 with Contract

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

the class DisputeSummaryWindow method addInfoPane.

private void addInfoPane() {
    Contract contract = dispute.getContract();
    addTitledGroupBg(gridPane, ++rowIndex, 16, Res.get("disputeSummaryWindow.title"));
    addLabelTextField(gridPane, rowIndex, Res.getWithCol("shared.tradeId"), dispute.getShortTradeId(), Layout.FIRST_ROW_DISTANCE);
    addLabelTextField(gridPane, ++rowIndex, Res.get("disputeSummaryWindow.openDate"), formatter.formatDateTime(dispute.getOpeningDate()));
    if (dispute.isDisputeOpenerIsMaker()) {
        if (dispute.isDisputeOpenerIsBuyer())
            role = Res.get("support.buyerOfferer");
        else
            role = Res.get("support.sellerOfferer");
    } else {
        if (dispute.isDisputeOpenerIsBuyer())
            role = Res.get("support.buyerTaker");
        else
            role = Res.get("support.sellerTaker");
    }
    addLabelTextField(gridPane, ++rowIndex, Res.get("disputeSummaryWindow.role"), role);
    addLabelTextField(gridPane, ++rowIndex, Res.getWithCol("shared.tradeAmount"), formatter.formatCoinWithCode(contract.getTradeAmount()));
    addLabelTextField(gridPane, ++rowIndex, Res.getWithCol("shared.tradePrice"), formatter.formatPrice(contract.getTradePrice()));
    addLabelTextField(gridPane, ++rowIndex, Res.getWithCol("shared.tradeVolume"), formatter.formatVolumeWithCode(contract.getTradePrice().getVolumeByAmount(contract.getTradeAmount())));
}
Also used : Contract(bisq.core.trade.Contract)

Example 9 with Contract

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

the class TradeDetailsWindow method addContent.

private void addContent() {
    Offer offer = trade.getOffer();
    Contract contract = trade.getContract();
    int rows = 5;
    addTitledGroupBg(gridPane, ++rowIndex, rows, Res.get("tradeDetailsWindow.headline"));
    boolean myOffer = tradeManager.isMyOffer(offer);
    String fiatDirectionInfo;
    String btcDirectionInfo;
    String toReceive = " " + Res.get("shared.toReceive");
    String toSpend = " " + Res.get("shared.toSpend");
    String offerType = Res.getWithCol("shared.offerType");
    if (tradeManager.isBuyer(offer)) {
        addLabelTextField(gridPane, rowIndex, offerType, formatter.getDirectionForBuyer(myOffer, offer.getCurrencyCode()), Layout.FIRST_ROW_DISTANCE);
        fiatDirectionInfo = toSpend;
        btcDirectionInfo = toReceive;
    } else {
        addLabelTextField(gridPane, rowIndex, offerType, formatter.getDirectionForSeller(myOffer, offer.getCurrencyCode()), Layout.FIRST_ROW_DISTANCE);
        fiatDirectionInfo = toReceive;
        btcDirectionInfo = toSpend;
    }
    addLabelTextField(gridPane, ++rowIndex, Res.get("shared.btcAmount") + btcDirectionInfo, formatter.formatCoinWithCode(trade.getTradeAmount()));
    addLabelTextField(gridPane, ++rowIndex, formatter.formatVolumeLabel(offer.getCurrencyCode()) + fiatDirectionInfo, formatter.formatVolumeWithCode(trade.getTradeVolume()));
    addLabelTextField(gridPane, ++rowIndex, Res.get("shared.tradePrice"), formatter.formatPrice(trade.getTradePrice()));
    addLabelTextField(gridPane, ++rowIndex, Res.getWithCol("shared.paymentMethod"), Res.get(offer.getPaymentMethod().getId()));
    // second group
    rows = 6;
    PaymentAccountPayload buyerPaymentAccountPayload = null;
    PaymentAccountPayload sellerPaymentAccountPayload = null;
    if (contract != null) {
        rows++;
        buyerPaymentAccountPayload = contract.getBuyerPaymentAccountPayload();
        sellerPaymentAccountPayload = contract.getSellerPaymentAccountPayload();
        if (buyerPaymentAccountPayload != null)
            rows++;
        if (sellerPaymentAccountPayload != null)
            rows++;
        if (buyerPaymentAccountPayload == null && sellerPaymentAccountPayload == null)
            rows++;
    }
    if (trade.getTakerFeeTxId() != null)
        rows++;
    if (trade.getDepositTx() != null)
        rows++;
    if (trade.getPayoutTx() != null)
        rows++;
    boolean showDisputedTx = disputeManager.findOwnDispute(trade.getId()).isPresent() && disputeManager.findOwnDispute(trade.getId()).get().getDisputePayoutTxId() != null;
    if (showDisputedTx)
        rows++;
    if (trade.hasFailed())
        rows += 2;
    if (trade.getTradingPeerNodeAddress() != null)
        rows++;
    addTitledGroupBg(gridPane, ++rowIndex, rows, Res.get("shared.details"), Layout.GROUP_DISTANCE);
    addLabelTextFieldWithCopyIcon(gridPane, rowIndex, Res.get("shared.tradeId"), trade.getId(), Layout.FIRST_ROW_AND_GROUP_DISTANCE);
    addLabelTextField(gridPane, ++rowIndex, Res.get("tradeDetailsWindow.tradeDate"), formatter.formatDateTime(trade.getDate()));
    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);
    String txFee = Res.get("shared.makerTxFee", formatter.formatCoinWithCode(offer.getTxFee())) + " / " + Res.get("shared.takerTxFee", formatter.formatCoinWithCode(offer.getTxFee().multiply(3L)));
    addLabelTextField(gridPane, ++rowIndex, Res.get("tradeDetailsWindow.txFee"), txFee);
    if (trade.getArbitratorNodeAddress() != null)
        addLabelTextFieldWithCopyIcon(gridPane, ++rowIndex, Res.get("shared.arbitrator"), trade.getArbitratorNodeAddress().getFullAddress());
    if (trade.getTradingPeerNodeAddress() != null)
        addLabelTextFieldWithCopyIcon(gridPane, ++rowIndex, Res.get("tradeDetailsWindow.tradingPeersOnion"), trade.getTradingPeerNodeAddress().getFullAddress());
    if (contract != null) {
        if (buyerPaymentAccountPayload != null) {
            TextFieldWithCopyIcon tf = addLabelTextFieldWithCopyIcon(gridPane, ++rowIndex, Res.get("shared.paymentDetails", Res.get("shared.buyer")), buyerPaymentAccountPayload.getPaymentDetails()).second;
            tf.setTooltip(new Tooltip(tf.getText()));
        }
        if (sellerPaymentAccountPayload != null) {
            TextFieldWithCopyIcon tf = addLabelTextFieldWithCopyIcon(gridPane, ++rowIndex, Res.get("shared.paymentDetails", Res.get("shared.seller")), sellerPaymentAccountPayload.getPaymentDetails()).second;
            tf.setTooltip(new Tooltip(tf.getText()));
        }
        if (buyerPaymentAccountPayload == null && sellerPaymentAccountPayload == null)
            addLabelTextField(gridPane, ++rowIndex, Res.getWithCol("shared.paymentMethod"), Res.get(contract.getPaymentMethodId()));
    }
    addLabelTxIdTextField(gridPane, ++rowIndex, Res.get("shared.makerFeeTxId"), offer.getOfferFeePaymentTxId());
    if (trade.getTakerFeeTxId() != null)
        addLabelTxIdTextField(gridPane, ++rowIndex, Res.get("shared.takerFeeTxId"), trade.getTakerFeeTxId());
    if (trade.getDepositTx() != null)
        addLabelTxIdTextField(gridPane, ++rowIndex, Res.getWithCol("shared.depositTransactionId"), trade.getDepositTx().getHashAsString());
    if (trade.getPayoutTx() != null)
        addLabelTxIdTextField(gridPane, ++rowIndex, Res.get("shared.payoutTxId"), trade.getPayoutTx().getHashAsString());
    if (showDisputedTx)
        addLabelTxIdTextField(gridPane, ++rowIndex, Res.get("tradeDetailsWindow.disputedPayoutTxId"), disputeManager.findOwnDispute(trade.getId()).get().getDisputePayoutTxId());
    if (contract != null) {
        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();
            textArea.setText(trade.getContractAsJson());
            String contractAsJson = trade.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", trade.getShortId()));
            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);
        });
    }
    if (trade.hasFailed()) {
        textArea = addLabelTextArea(gridPane, ++rowIndex, Res.get("shared.errorMessage"), "").second;
        textArea.setText(trade.getErrorMessage());
        textArea.setEditable(false);
        IntegerProperty count = new SimpleIntegerProperty(20);
        int rowHeight = 10;
        textArea.prefHeightProperty().bindBidirectional(count);
        changeListener = (ov, old, newVal) -> {
            if (newVal.intValue() > rowHeight)
                count.setValue(count.get() + newVal.intValue() + 10);
        };
        textArea.scrollTopProperty().addListener(changeListener);
        textArea.setScrollTop(30);
        TextField state = addLabelTextField(gridPane, ++rowIndex, Res.get("tradeDetailsWindow.tradeState")).second;
        state.setText(trade.getState().getPhase().name());
    }
    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) IntegerProperty(javafx.beans.property.IntegerProperty) SimpleIntegerProperty(javafx.beans.property.SimpleIntegerProperty) TextArea(javafx.scene.control.TextArea) TextFieldWithCopyIcon(bisq.desktop.components.TextFieldWithCopyIcon) 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) Stage(javafx.stage.Stage) TextField(javafx.scene.control.TextField) Contract(bisq.core.trade.Contract) SimpleIntegerProperty(javafx.beans.property.SimpleIntegerProperty)

Example 10 with Contract

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

the class SellerStep3View method addContent.

// /////////////////////////////////////////////////////////////////////////////////////////
// Content
// /////////////////////////////////////////////////////////////////////////////////////////
@Override
protected void addContent() {
    addTradeInfoBlock();
    TitledGroupBg titledGroupBg = addTitledGroupBg(gridPane, ++gridRow, 3, Res.get("portfolio.pending.step3_seller.confirmPaymentReceipt"), Layout.GROUP_DISTANCE);
    TextFieldWithCopyIcon field = addLabelTextFieldWithCopyIcon(gridPane, gridRow, Res.get("portfolio.pending.step3_seller.amountToReceive"), model.getFiatVolume(), Layout.FIRST_ROW_AND_GROUP_DISTANCE).second;
    field.setCopyWithoutCurrencyPostFix(true);
    String myPaymentDetails = "";
    String peersPaymentDetails = "";
    String myTitle = "";
    String peersTitle = "";
    boolean isBlockChain = false;
    String nameByCode = CurrencyUtil.getNameByCode(trade.getOffer().getCurrencyCode());
    Contract contract = trade.getContract();
    if (contract != null) {
        PaymentAccountPayload myPaymentAccountPayload = contract.getSellerPaymentAccountPayload();
        PaymentAccountPayload peersPaymentAccountPayload = contract.getBuyerPaymentAccountPayload();
        if (myPaymentAccountPayload instanceof CryptoCurrencyAccountPayload) {
            myPaymentDetails = ((CryptoCurrencyAccountPayload) myPaymentAccountPayload).getAddress();
            peersPaymentDetails = ((CryptoCurrencyAccountPayload) peersPaymentAccountPayload).getAddress();
            myTitle = Res.get("portfolio.pending.step3_seller.yourAddress", nameByCode);
            peersTitle = Res.get("portfolio.pending.step3_seller.buyersAddress", nameByCode);
            isBlockChain = true;
        } else {
            myPaymentDetails = myPaymentAccountPayload.getPaymentDetails();
            peersPaymentDetails = peersPaymentAccountPayload.getPaymentDetails();
            myTitle = Res.get("portfolio.pending.step3_seller.yourAccount");
            peersTitle = Res.get("portfolio.pending.step3_seller.buyersAccount");
        }
    }
    TextFieldWithCopyIcon myPaymentDetailsTextField = addLabelTextFieldWithCopyIcon(gridPane, ++gridRow, myTitle, myPaymentDetails).second;
    myPaymentDetailsTextField.setMouseTransparent(false);
    myPaymentDetailsTextField.setTooltip(new Tooltip(myPaymentDetails));
    TextFieldWithCopyIcon peersPaymentDetailsTextField = addLabelTextFieldWithCopyIcon(gridPane, ++gridRow, peersTitle, peersPaymentDetails).second;
    peersPaymentDetailsTextField.setMouseTransparent(false);
    peersPaymentDetailsTextField.setTooltip(new Tooltip(peersPaymentDetails));
    if (!isBlockChain) {
        addLabelTextFieldWithCopyIcon(gridPane, ++gridRow, Res.getWithCol("shared.reasonForPayment"), model.dataModel.getReference());
        GridPane.setRowSpan(titledGroupBg, 4);
    }
    Tuple3<Button, BusyAnimation, Label> tuple = addButtonBusyAnimationLabelAfterGroup(gridPane, ++gridRow, Res.get("portfolio.pending.step3_seller.confirmReceipt"));
    confirmButton = tuple.first;
    confirmButton.setOnAction(e -> onPaymentReceived());
    busyAnimation = tuple.second;
    statusLabel = tuple.third;
}
Also used : BusyAnimation(bisq.desktop.components.BusyAnimation) Button(javafx.scene.control.Button) FormBuilder.addLabelTextFieldWithCopyIcon(bisq.desktop.util.FormBuilder.addLabelTextFieldWithCopyIcon) TextFieldWithCopyIcon(bisq.desktop.components.TextFieldWithCopyIcon) Tooltip(javafx.scene.control.Tooltip) PaymentAccountPayload(bisq.core.payment.payload.PaymentAccountPayload) Label(javafx.scene.control.Label) TitledGroupBg(bisq.desktop.components.TitledGroupBg) FormBuilder.addTitledGroupBg(bisq.desktop.util.FormBuilder.addTitledGroupBg) Contract(bisq.core.trade.Contract) CryptoCurrencyAccountPayload(bisq.core.payment.payload.CryptoCurrencyAccountPayload)

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