Search in sources :

Example 36 with Popup

use of bisq.desktop.main.overlays.popups.Popup 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 37 with Popup

use of bisq.desktop.main.overlays.popups.Popup in project bisq-desktop by bisq-network.

the class WithdrawalView method onWithdraw.

// /////////////////////////////////////////////////////////////////////////////////////////
// UI handlers
// /////////////////////////////////////////////////////////////////////////////////////////
@FXML
public void onWithdraw() {
    if (GUIUtil.isReadyForTxBroadcast(p2PService, walletsSetup)) {
        try {
            // We do not know sendersAmount if senderPaysFee is true. We repeat fee calculation after first attempt if senderPaysFee is true.
            Transaction feeEstimationTransaction = walletService.getFeeEstimationTransactionForMultipleAddresses(fromAddresses, amountAsCoin);
            if (feeExcluded && feeEstimationTransaction != null) {
                sendersAmount = amountAsCoin.add(feeEstimationTransaction.getFee());
                feeEstimationTransaction = walletService.getFeeEstimationTransactionForMultipleAddresses(fromAddresses, sendersAmount);
            }
            checkNotNull(feeEstimationTransaction, "feeEstimationTransaction must not be null");
            Coin fee = feeEstimationTransaction.getFee();
            sendersAmount = feeExcluded ? amountAsCoin.add(fee) : amountAsCoin;
            Coin receiverAmount = feeExcluded ? amountAsCoin : amountAsCoin.subtract(fee);
            if (areInputsValid()) {
                int txSize = feeEstimationTransaction.bitcoinSerialize().length;
                log.info("Fee for tx with size {}: {} " + Res.getBaseCurrencyCode() + "", txSize, fee.toPlainString());
                if (receiverAmount.isPositive()) {
                    double feePerByte = CoinUtil.getFeePerByte(fee, txSize);
                    double kb = txSize / 1000d;
                    new Popup<>().headLine(Res.get("funds.withdrawal.confirmWithdrawalRequest")).confirmation(Res.get("shared.sendFundsDetailsWithFee", formatter.formatCoinWithCode(sendersAmount), withdrawFromTextField.getText(), withdrawToTextField.getText(), formatter.formatCoinWithCode(fee), feePerByte, kb, formatter.formatCoinWithCode(receiverAmount))).actionButtonText(Res.get("shared.yes")).onAction(() -> doWithdraw(sendersAmount, fee, new FutureCallback<Transaction>() {

                        @Override
                        public void onSuccess(@javax.annotation.Nullable Transaction transaction) {
                            if (transaction != null) {
                                log.debug("onWithdraw onSuccess tx ID:" + transaction.getHashAsString());
                            } else {
                                log.error("onWithdraw transaction is null");
                            }
                            List<Trade> trades = new ArrayList<>(tradeManager.getTradableList());
                            trades.stream().filter(Trade::isPayoutPublished).forEach(trade -> {
                                walletService.getAddressEntry(trade.getId(), AddressEntry.Context.TRADE_PAYOUT).ifPresent(addressEntry -> {
                                    if (walletService.getBalanceForAddress(addressEntry.getAddress()).isZero())
                                        tradeManager.addTradeToClosedTrades(trade);
                                });
                            });
                        }

                        @Override
                        public void onFailure(@NotNull Throwable t) {
                            log.error("onWithdraw onFailure");
                        }
                    })).closeButtonText(Res.get("shared.cancel")).show();
                } else {
                    new Popup<>().warning(Res.get("portfolio.pending.step5_buyer.amountTooLow")).show();
                }
            }
        } catch (InsufficientFundsException e) {
            new Popup<>().warning(Res.get("funds.withdrawal.warn.amountExceeds") + "\n\nError message:\n" + e.getMessage()).show();
        } catch (Throwable e) {
            e.printStackTrace();
            log.error(e.toString());
            new Popup<>().warning(e.toString()).show();
        }
    } else {
        GUIUtil.showNotReadyForTxBroadcastPopups(p2PService, walletsSetup);
    }
}
Also used : ArrayList(java.util.ArrayList) NotNull(org.jetbrains.annotations.NotNull) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) Coin(org.bitcoinj.core.Coin) Trade(bisq.core.trade.Trade) Transaction(org.bitcoinj.core.Transaction) Popup(bisq.desktop.main.overlays.popups.Popup) InsufficientFundsException(bisq.core.btc.InsufficientFundsException) FutureCallback(com.google.common.util.concurrent.FutureCallback) FXML(javafx.fxml.FXML)

Example 38 with Popup

use of bisq.desktop.main.overlays.popups.Popup in project bisq-desktop by bisq-network.

the class MakeProposalView method publishProposal.

private void publishProposal(ProposalType type) {
    try {
        Proposal proposal = createProposal(type);
        Transaction tx = Objects.requireNonNull(proposal).getTx();
        Coin miningFee = Objects.requireNonNull(tx).getFee();
        int txSize = tx.bitcoinSerialize().length;
        validateInputs();
        new Popup<>().headLine(Res.get("dao.proposal.create.confirm")).confirmation(Res.get("dao.proposal.create.confirm.info", bsqFormatter.formatCoinWithCode(ProposalConsensus.getCreateCompensationRequestFee(readableBsqBlockChain)), btcFormatter.formatCoinWithCode(miningFee), CoinUtil.getFeePerByte(miningFee, txSize), (txSize / 1000d))).actionButtonText(Res.get("shared.yes")).onAction(() -> {
            proposalCollectionsService.publishProposal(proposal, new FutureCallback<Transaction>() {

                @Override
                public void onSuccess(@Nullable Transaction transaction) {
                    proposalDisplay.clearForm();
                    proposalTypeComboBox.getSelectionModel().clearSelection();
                    new Popup<>().confirmation(Res.get("dao.tx.published.success")).show();
                }

                @Override
                public void onFailure(@NotNull Throwable t) {
                    log.error(t.toString());
                    new Popup<>().warning(t.toString()).show();
                }
            });
        }).closeButtonText(Res.get("shared.cancel")).show();
    } catch (InsufficientMoneyException e) {
        BSFormatter formatter = e instanceof InsufficientBsqException ? bsqFormatter : btcFormatter;
        new Popup<>().warning(Res.get("dao.proposal.create.missingFunds", formatter.formatCoinWithCode(e.missing))).show();
    } catch (CompensationAmountException e) {
        new Popup<>().warning(Res.get("validation.bsq.amountBelowMinAmount", bsqFormatter.formatCoinWithCode(e.required))).show();
    } catch (TransactionVerificationException | WalletException e) {
        log.error(e.toString());
        e.printStackTrace();
        new Popup<>().warning(e.toString()).show();
    } catch (ChangeBelowDustException e) {
        // TODO
        e.printStackTrace();
    }
}
Also used : WalletException(bisq.core.btc.exceptions.WalletException) TransactionVerificationException(bisq.core.btc.exceptions.TransactionVerificationException) InsufficientMoneyException(org.bitcoinj.core.InsufficientMoneyException) BSFormatter(bisq.desktop.util.BSFormatter) CompensationAmountException(bisq.core.dao.proposal.compensation.CompensationAmountException) ChangeBelowDustException(bisq.core.btc.wallet.ChangeBelowDustException) Coin(org.bitcoinj.core.Coin) Transaction(org.bitcoinj.core.Transaction) InsufficientBsqException(bisq.core.btc.wallet.InsufficientBsqException) Popup(bisq.desktop.main.overlays.popups.Popup) Proposal(bisq.core.dao.proposal.Proposal)

Example 39 with Popup

use of bisq.desktop.main.overlays.popups.Popup in project bisq-desktop by bisq-network.

the class WesternUnionForm method addFormForAddAccount.

@Override
public void addFormForAddAccount() {
    gridRowFrom = gridRow + 1;
    Tuple3<Label, ComboBox, ComboBox> tuple3 = FormBuilder.addLabelComboBoxComboBox(gridPane, ++gridRow, Res.get("payment.country"));
    // noinspection unchecked,unchecked,unchecked
    ComboBox<Region> regionComboBox = tuple3.second;
    regionComboBox.setPromptText(Res.get("payment.select.region"));
    regionComboBox.setConverter(new StringConverter<Region>() {

        @Override
        public String toString(Region region) {
            return region.name;
        }

        @Override
        public Region fromString(String s) {
            return null;
        }
    });
    regionComboBox.setItems(FXCollections.observableArrayList(CountryUtil.getAllRegions()));
    // noinspection unchecked,unchecked,unchecked
    ComboBox<Country> countryComboBox = tuple3.third;
    countryComboBox.setVisibleRowCount(15);
    countryComboBox.setDisable(true);
    countryComboBox.setPromptText(Res.get("payment.select.country"));
    countryComboBox.setConverter(new StringConverter<Country>() {

        @Override
        public String toString(Country country) {
            return country.name + " (" + country.code + ")";
        }

        @Override
        public Country fromString(String s) {
            return null;
        }
    });
    countryComboBox.setOnAction(e -> {
        Country selectedItem = countryComboBox.getSelectionModel().getSelectedItem();
        if (selectedItem != null) {
            getCountryBasedPaymentAccount().setCountry(selectedItem);
            String countryCode = selectedItem.code;
            TradeCurrency currency = CurrencyUtil.getCurrencyByCountryCode(countryCode);
            paymentAccount.setSingleTradeCurrency(currency);
            currencyComboBox.setDisable(false);
            currencyComboBox.getSelectionModel().select(currency);
            updateFromInputs();
            applyIsStateRequired();
            cityInputTextField.setText("");
            stateInputTextField.setText("");
        }
    });
    regionComboBox.setOnAction(e -> {
        Region selectedItem = regionComboBox.getSelectionModel().getSelectedItem();
        if (selectedItem != null) {
            countryComboBox.setDisable(false);
            countryComboBox.setItems(FXCollections.observableArrayList(CountryUtil.getAllCountriesForRegion(selectedItem)));
        }
    });
    // noinspection unchecked
    currencyComboBox = FormBuilder.addLabelComboBox(gridPane, ++gridRow, Res.getWithCol("shared.currency")).second;
    currencyComboBox.setPromptText(Res.get("list.currency.select"));
    currencyComboBox.setItems(FXCollections.observableArrayList(CurrencyUtil.getAllSortedFiatCurrencies()));
    currencyComboBox.setOnAction(e -> {
        TradeCurrency selectedItem = currencyComboBox.getSelectionModel().getSelectedItem();
        FiatCurrency defaultCurrency = CurrencyUtil.getCurrencyByCountryCode(countryComboBox.getSelectionModel().getSelectedItem().code);
        if (!defaultCurrency.equals(selectedItem)) {
            new Popup<>().warning(Res.get("payment.foreign.currency")).actionButtonText(Res.get("shared.yes")).onAction(() -> {
                paymentAccount.setSingleTradeCurrency(selectedItem);
                autoFillNameTextField();
            }).closeButtonText(Res.get("payment.restore.default")).onClose(() -> currencyComboBox.getSelectionModel().select(defaultCurrency)).show();
        } else {
            paymentAccount.setSingleTradeCurrency(selectedItem);
            autoFillNameTextField();
        }
    });
    currencyComboBox.setConverter(new StringConverter<TradeCurrency>() {

        @Override
        public String toString(TradeCurrency currency) {
            return currency.getNameAndCode();
        }

        @Override
        public TradeCurrency fromString(String string) {
            return null;
        }
    });
    currencyComboBox.setDisable(true);
    holderNameInputTextField = FormBuilder.addLabelInputTextField(gridPane, ++gridRow, Res.getWithCol("payment.account.fullName")).second;
    holderNameInputTextField.textProperty().addListener((ov, oldValue, newValue) -> {
        westernUnionAccountPayload.setHolderName(newValue);
        updateFromInputs();
    });
    holderNameInputTextField.setValidator(inputValidator);
    cityInputTextField = FormBuilder.addLabelInputTextField(gridPane, ++gridRow, Res.get("payment.account.city")).second;
    cityInputTextField.textProperty().addListener((ov, oldValue, newValue) -> {
        westernUnionAccountPayload.setCity(newValue);
        updateFromInputs();
    });
    final Tuple2<Label, InputTextField> tuple2 = FormBuilder.addLabelInputTextField(gridPane, ++gridRow, Res.get("payment.account.state"));
    stateLabel = tuple2.first;
    stateInputTextField = tuple2.second;
    stateInputTextField.textProperty().addListener((ov, oldValue, newValue) -> {
        westernUnionAccountPayload.setState(newValue);
        updateFromInputs();
    });
    applyIsStateRequired();
    emailInputTextField = FormBuilder.addLabelInputTextField(gridPane, ++gridRow, Res.get("payment.email")).second;
    emailInputTextField.textProperty().addListener((ov, oldValue, newValue) -> {
        westernUnionAccountPayload.setEmail(newValue);
        updateFromInputs();
    });
    emailInputTextField.setValidator(emailValidator);
    addLimitations();
    addAccountNameTextFieldWithAutoFillCheckBox();
    updateFromInputs();
}
Also used : TradeCurrency(bisq.core.locale.TradeCurrency) ComboBox(javafx.scene.control.ComboBox) InputTextField(bisq.desktop.components.InputTextField) Label(javafx.scene.control.Label) Popup(bisq.desktop.main.overlays.popups.Popup) Region(bisq.core.locale.Region) Country(bisq.core.locale.Country) FiatCurrency(bisq.core.locale.FiatCurrency)

Example 40 with Popup

use of bisq.desktop.main.overlays.popups.Popup in project bisq-desktop by bisq-network.

the class MainView method createFooter.

private AnchorPane createFooter() {
    // line
    Separator separator = new Separator();
    separator.setId("footer-pane-line");
    separator.setPrefHeight(1);
    setLeftAnchor(separator, 0d);
    setRightAnchor(separator, 0d);
    setTopAnchor(separator, 0d);
    // BTC
    Label btcInfoLabel = new AutoTooltipLabel();
    btcInfoLabel.setId("footer-pane");
    btcInfoLabel.textProperty().bind(model.btcInfo);
    ProgressBar blockchainSyncIndicator = new ProgressBar(-1);
    blockchainSyncIndicator.setPrefWidth(120);
    blockchainSyncIndicator.setMaxHeight(10);
    blockchainSyncIndicator.progressProperty().bind(model.btcSyncProgress);
    model.walletServiceErrorMsg.addListener((ov, oldValue, newValue) -> {
        if (newValue != null) {
            btcInfoLabel.setId("splash-error-state-msg");
            btcInfoLabel.getStyleClass().add("error-text");
            if (btcNetworkWarnMsgPopup == null) {
                btcNetworkWarnMsgPopup = new Popup<>().warning(newValue);
                btcNetworkWarnMsgPopup.show();
            }
        } else {
            btcInfoLabel.setId("footer-pane");
            if (btcNetworkWarnMsgPopup != null)
                btcNetworkWarnMsgPopup.hide();
        }
    });
    model.btcSyncProgress.addListener((ov, oldValue, newValue) -> {
        if ((double) newValue >= 1) {
            blockchainSyncIndicator.setVisible(false);
            blockchainSyncIndicator.setManaged(false);
        }
    });
    HBox blockchainSyncBox = new HBox();
    blockchainSyncBox.setSpacing(10);
    blockchainSyncBox.setAlignment(Pos.CENTER);
    blockchainSyncBox.getChildren().addAll(btcInfoLabel, blockchainSyncIndicator);
    setLeftAnchor(blockchainSyncBox, 10d);
    setBottomAnchor(blockchainSyncBox, 7d);
    // version
    versionLabel = new AutoTooltipLabel();
    versionLabel.setId("footer-pane");
    versionLabel.setTextAlignment(TextAlignment.CENTER);
    versionLabel.setAlignment(Pos.BASELINE_CENTER);
    versionLabel.setText("v" + Version.VERSION);
    root.widthProperty().addListener((ov, oldValue, newValue) -> {
        versionLabel.setLayoutX(((double) newValue - versionLabel.getWidth()) / 2);
    });
    setBottomAnchor(versionLabel, 7d);
    model.newVersionAvailableProperty.addListener((observable, oldValue, newValue) -> {
        versionLabel.getStyleClass().removeAll("version-new", "version");
        if (newValue) {
            versionLabel.getStyleClass().add("version-new");
            versionLabel.setOnMouseClicked(e -> model.openDownloadWindow());
            versionLabel.setText("v" + Version.VERSION + " " + Res.get("mainView.version.update"));
        } else {
            versionLabel.getStyleClass().add("version");
            versionLabel.setOnMouseClicked(null);
            versionLabel.setText("v" + Version.VERSION);
        }
    });
    // P2P Network
    Label p2PNetworkLabel = new AutoTooltipLabel();
    p2PNetworkLabel.setId("footer-pane");
    setRightAnchor(p2PNetworkLabel, 33d);
    setBottomAnchor(p2PNetworkLabel, 7d);
    p2PNetworkLabel.textProperty().bind(model.p2PNetworkInfo);
    ImageView p2PNetworkIcon = new ImageView();
    setRightAnchor(p2PNetworkIcon, 10d);
    setBottomAnchor(p2PNetworkIcon, 7d);
    p2PNetworkIcon.setOpacity(0.4);
    p2PNetworkIcon.idProperty().bind(model.p2PNetworkIconId);
    p2PNetworkLabel.idProperty().bind(model.p2pNetworkLabelId);
    model.p2pNetworkWarnMsg.addListener((ov, oldValue, newValue) -> {
        if (newValue != null) {
            p2PNetworkWarnMsgPopup = new Popup<>().warning(newValue);
            p2PNetworkWarnMsgPopup.show();
        } else if (p2PNetworkWarnMsgPopup != null) {
            p2PNetworkWarnMsgPopup.hide();
        }
    });
    model.bootstrapComplete.addListener((observable, oldValue, newValue) -> {
        p2PNetworkIcon.setOpacity(1);
    });
    return new AnchorPane(separator, blockchainSyncBox, versionLabel, p2PNetworkLabel, p2PNetworkIcon) {

        {
            setId("footer-pane");
            setMinHeight(30);
            setMaxHeight(30);
        }
    };
}
Also used : HBox(javafx.scene.layout.HBox) Popup(bisq.desktop.main.overlays.popups.Popup) AutoTooltipLabel(bisq.desktop.components.AutoTooltipLabel) Label(javafx.scene.control.Label) ImageView(javafx.scene.image.ImageView) AutoTooltipLabel(bisq.desktop.components.AutoTooltipLabel) ProgressBar(javafx.scene.control.ProgressBar) AnchorPane(javafx.scene.layout.AnchorPane) Separator(javafx.scene.control.Separator)

Aggregations

Popup (bisq.desktop.main.overlays.popups.Popup)57 Label (javafx.scene.control.Label)22 Coin (org.bitcoinj.core.Coin)17 AutoTooltipLabel (bisq.desktop.components.AutoTooltipLabel)16 Button (javafx.scene.control.Button)16 Res (bisq.core.locale.Res)13 AutoTooltipButton (bisq.desktop.components.AutoTooltipButton)13 Insets (javafx.geometry.Insets)13 InputTextField (bisq.desktop.components.InputTextField)12 BSFormatter (bisq.desktop.util.BSFormatter)12 Transaction (org.bitcoinj.core.Transaction)12 List (java.util.List)11 UserThread (bisq.common.UserThread)10 ChangeListener (javafx.beans.value.ChangeListener)9 BusyAnimation (bisq.desktop.components.BusyAnimation)8 ObservableList (javafx.collections.ObservableList)8 HBox (javafx.scene.layout.HBox)8 Tuple2 (bisq.common.util.Tuple2)7 FxmlView (bisq.desktop.common.view.FxmlView)7 TradeCurrency (bisq.core.locale.TradeCurrency)6