Search in sources :

Example 31 with Offer

use of bisq.core.offer.Offer in project bisq-desktop by bisq-network.

the class TakeOfferDataModel method onTakeOffer.

// /////////////////////////////////////////////////////////////////////////////////////////
// UI actions
// /////////////////////////////////////////////////////////////////////////////////////////
// errorMessageHandler is used only in the check availability phase. As soon we have a trade we write the error msg in the trade object as we want to
// have it persisted as well.
void onTakeOffer(TradeResultHandler tradeResultHandler) {
    checkNotNull(txFeeFromFeeService, "txFeeFromFeeService must not be null");
    checkNotNull(getTakerFee(), "takerFee must not be null");
    Coin fundsNeededForTrade = getSecurityDeposit().add(txFeeFromFeeService).add(txFeeFromFeeService);
    if (isBuyOffer())
        fundsNeededForTrade = fundsNeededForTrade.add(amount.get());
    if (filterManager.isCurrencyBanned(offer.getCurrencyCode())) {
        new Popup<>().warning(Res.get("offerbook.warning.currencyBanned")).show();
    } else if (filterManager.isPaymentMethodBanned(offer.getPaymentMethod())) {
        new Popup<>().warning(Res.get("offerbook.warning.paymentMethodBanned")).show();
    } else if (filterManager.isOfferIdBanned(offer.getId())) {
        new Popup<>().warning(Res.get("offerbook.warning.offerBlocked")).show();
    } else if (filterManager.isNodeAddressBanned(offer.getMakerNodeAddress())) {
        new Popup<>().warning(Res.get("offerbook.warning.nodeBlocked")).show();
    } else {
        tradeManager.onTakeOffer(amount.get(), txFeeFromFeeService, getTakerFee(), isCurrencyForTakerFeeBtc(), tradePrice.getValue(), fundsNeededForTrade, offer, paymentAccount.getId(), useSavingsWallet, tradeResultHandler, errorMessage -> {
            log.warn(errorMessage);
            new Popup<>().warning(errorMessage).show();
        });
    }
}
Also used : Arbitrator(bisq.core.arbitration.Arbitrator) BtcWalletService(bisq.core.btc.wallet.BtcWalletService) TradeResultHandler(bisq.core.trade.handlers.TradeResultHandler) Transaction(org.bitcoinj.core.Transaction) ReadOnlyObjectProperty(javafx.beans.property.ReadOnlyObjectProperty) Coin(org.bitcoinj.core.Coin) Wallet(org.bitcoinj.wallet.Wallet) Inject(com.google.inject.Inject) Volume(bisq.core.monetary.Volume) PaymentAccountUtil(bisq.core.payment.PaymentAccountUtil) User(bisq.core.user.User) BalanceListener(bisq.core.btc.listeners.BalanceListener) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) OfferPayload(bisq.core.offer.OfferPayload) Res(bisq.core.locale.Res) CurrencyUtil(bisq.core.locale.CurrencyUtil) OfferDataModel(bisq.desktop.main.offer.OfferDataModel) Nullable(javax.annotation.Nullable) Popup(bisq.desktop.main.overlays.popups.Popup) Offer(bisq.core.offer.Offer) ObjectProperty(javafx.beans.property.ObjectProperty) FilterManager(bisq.core.filter.FilterManager) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) BisqEnvironment(bisq.core.app.BisqEnvironment) PaymentMethod(bisq.core.payment.payload.PaymentMethod) InsufficientMoneyException(org.bitcoinj.core.InsufficientMoneyException) BsqWalletService(bisq.core.btc.wallet.BsqWalletService) AccountAgeWitnessService(bisq.core.payment.AccountAgeWitnessService) PaymentAccount(bisq.core.payment.PaymentAccount) List(java.util.List) PriceFeedService(bisq.core.provider.price.PriceFeedService) AddressEntry(bisq.core.btc.AddressEntry) TradeWalletService(bisq.core.btc.wallet.TradeWalletService) TradeManager(bisq.core.trade.TradeManager) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) Preferences(bisq.core.user.Preferences) Price(bisq.core.monetary.Price) FeeService(bisq.core.provider.fee.FeeService) Address(org.bitcoinj.core.Address) ObservableList(javafx.collections.ObservableList) Restrictions(bisq.core.btc.Restrictions) CoinUtil(bisq.core.util.CoinUtil) Coin(org.bitcoinj.core.Coin) Popup(bisq.desktop.main.overlays.popups.Popup)

Example 32 with Offer

use of bisq.core.offer.Offer 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 33 with Offer

use of bisq.core.offer.Offer in project bisq-desktop by bisq-network.

the class BSFormatterTest method testFormatDifferentVolume.

@Test
public void testFormatDifferentVolume() {
    Offer offer = mock(Offer.class);
    Volume btcMin = Volume.parse("0.10", "BTC");
    Volume btcMax = Volume.parse("0.25", "BTC");
    when(offer.isRange()).thenReturn(true);
    when(offer.getMinVolume()).thenReturn(btcMin);
    when(offer.getVolume()).thenReturn(btcMax);
    assertEquals("0.10000000 - 0.25000000", formatter.formatVolume(offer, false, 0));
}
Also used : OfferMaker.btcUsdOffer(bisq.core.offer.OfferMaker.btcUsdOffer) Offer(bisq.core.offer.Offer) Volume(bisq.core.monetary.Volume) VolumeMaker.usdVolume(bisq.core.monetary.VolumeMaker.usdVolume) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 34 with Offer

use of bisq.core.offer.Offer in project bisq-desktop by bisq-network.

the class BSFormatterTest method testFormatNullVolume.

@Test
public void testFormatNullVolume() {
    Offer offer = mock(Offer.class);
    when(offer.getMinVolume()).thenReturn(null);
    when(offer.getVolume()).thenReturn(null);
    assertEquals("", formatter.formatVolume(offer.getVolume()));
}
Also used : OfferMaker.btcUsdOffer(bisq.core.offer.OfferMaker.btcUsdOffer) Offer(bisq.core.offer.Offer) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 35 with Offer

use of bisq.core.offer.Offer in project bisq-desktop by bisq-network.

the class BSFormatterTest method testFormatAmountWithAlignmenWithDecimalsNoRange.

@Test
public void testFormatAmountWithAlignmenWithDecimalsNoRange() {
    OfferPayload offerPayload = mock(OfferPayload.class);
    Offer offer = new Offer(offerPayload);
    when(offerPayload.getMinAmount()).thenReturn(10000000L);
    when(offerPayload.getAmount()).thenReturn(10000000L);
    assertEquals("         0.1000", formatter.formatAmount(offer, 4, true, 15));
}
Also used : OfferMaker.btcUsdOffer(bisq.core.offer.OfferMaker.btcUsdOffer) Offer(bisq.core.offer.Offer) OfferPayload(bisq.core.offer.OfferPayload) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

Offer (bisq.core.offer.Offer)49 Coin (org.bitcoinj.core.Coin)15 Test (org.junit.Test)13 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)12 OfferPayload (bisq.core.offer.OfferPayload)10 Price (bisq.core.monetary.Price)9 OfferMaker.btcUsdOffer (bisq.core.offer.OfferMaker.btcUsdOffer)8 PaymentMethod (bisq.core.payment.payload.PaymentMethod)7 Contract (bisq.core.trade.Contract)7 NodeAddress (bisq.network.p2p.NodeAddress)7 Volume (bisq.core.monetary.Volume)6 PeerInfoIcon (bisq.desktop.components.PeerInfoIcon)6 Popup (bisq.desktop.main.overlays.popups.Popup)6 MainView (bisq.desktop.main.MainView)5 Button (javafx.scene.control.Button)5 TableCell (javafx.scene.control.TableCell)5 TableColumn (javafx.scene.control.TableColumn)5 TradeCurrency (bisq.core.locale.TradeCurrency)4 AutoTooltipButton (bisq.desktop.components.AutoTooltipButton)4 AutoTooltipLabel (bisq.desktop.components.AutoTooltipLabel)4