Search in sources :

Example 1 with BalanceListener

use of bisq.core.btc.listeners.BalanceListener in project bisq-desktop by bisq-network.

the class BalanceWithConfirmationTextField method setup.

public void setup(Address address, BSFormatter formatter) {
    this.formatter = formatter;
    confidenceListener = new AddressConfidenceListener(address) {

        @Override
        public void onTransactionConfidenceChanged(TransactionConfidence confidence) {
            updateConfidence(confidence);
        }
    };
    walletService.addAddressConfidenceListener(confidenceListener);
    updateConfidence(walletService.getConfidenceForAddress(address));
    balanceListener = new BalanceListener(address) {

        @Override
        public void onBalanceChanged(Coin balance, Transaction tx) {
            updateBalance(balance);
        }
    };
    walletService.addBalanceListener(balanceListener);
    updateBalance(walletService.getBalanceForAddress(address));
}
Also used : Coin(org.bitcoinj.core.Coin) AddressConfidenceListener(bisq.core.btc.listeners.AddressConfidenceListener) BalanceListener(bisq.core.btc.listeners.BalanceListener) Transaction(org.bitcoinj.core.Transaction) TransactionConfidence(org.bitcoinj.core.TransactionConfidence)

Example 2 with BalanceListener

use of bisq.core.btc.listeners.BalanceListener in project bisq-desktop by bisq-network.

the class TakeOfferDataModel method initWithData.

// /////////////////////////////////////////////////////////////////////////////////////////
// API
// /////////////////////////////////////////////////////////////////////////////////////////
// called before activate
void initWithData(Offer offer) {
    this.offer = offer;
    tradePrice = offer.getPrice();
    addressEntry = btcWalletService.getOrCreateAddressEntry(offer.getId(), AddressEntry.Context.OFFER_FUNDING);
    checkNotNull(addressEntry, "addressEntry must not be null");
    ObservableList<PaymentAccount> possiblePaymentAccounts = getPossiblePaymentAccounts();
    checkArgument(!possiblePaymentAccounts.isEmpty(), "possiblePaymentAccounts.isEmpty()");
    paymentAccount = possiblePaymentAccounts.get(0);
    long myLimit = accountAgeWitnessService.getMyTradeLimit(paymentAccount, getCurrencyCode());
    this.amount.set(Coin.valueOf(Math.min(offer.getAmount().value, myLimit)));
    securityDeposit = offer.getDirection() == OfferPayload.Direction.SELL ? getBuyerSecurityDeposit() : getSellerSecurityDeposit();
    // Taker pays 3 times the tx fee (taker fee, deposit, payout) because the mining fee might be different when maker created the offer
    // and reserved his funds. Taker creates at least taker fee and deposit tx at nearly the same moment. Just the payout will
    // be later and still could lead to issues if the required fee changed a lot in the meantime. using RBF and/or
    // multiple batch-signed payout tx with different fees might be an option but RBF is not supported yet in BitcoinJ
    // and batched txs would add more complexity to the trade protocol.
    // A typical trade fee tx has about 260 bytes (if one input). The trade txs has about 336-414 bytes.
    // We use 320 as a average value.
    // trade fee tx: 260 bytes (1 input)
    // deposit tx: 336 bytes (1 MS output+ OP_RETURN) - 414 bytes (1 MS output + OP_RETURN + change in case of smaller trade amount)
    // payout tx: 371 bytes
    // disputed payout tx: 408 bytes
    // Set the default values (in rare cases if the fee request was not done yet we get the hard coded default values)
    // But the "take offer" happens usually after that so we should have already the value from the estimation service.
    txFeePerByteFromFeeService = feeService.getTxFeePerByte();
    txFeeFromFeeService = getTxFeeBySize(feeTxSize);
    // We request to get the actual estimated fee
    log.info("Start requestTxFee: txFeeFromFeeService={}", txFeeFromFeeService);
    feeService.requestFees(() -> {
        if (!freezeFee) {
            txFeePerByteFromFeeService = feeService.getTxFeePerByte();
            txFeeFromFeeService = getTxFeeBySize(feeTxSize);
            calculateTotalToPay();
            log.info("Completed requestTxFee: txFeeFromFeeService={}", txFeeFromFeeService);
        } else {
            log.warn("We received the tx fee respnse after we have shown the funding screen and ignore that " + "to avoid that the total funds to pay changes due cahnged tx fees.");
        }
    }, null);
    calculateVolume();
    calculateTotalToPay();
    balanceListener = new BalanceListener(addressEntry.getAddress()) {

        @Override
        public void onBalanceChanged(Coin balance, Transaction tx) {
            updateBalance();
        /*if (isMainNet.get()) {
                    SettableFuture<Coin> future = blockchainService.requestFee(tx.getHashAsString());
                    Futures.addCallback(future, new FutureCallback<Coin>() {
                        public void onSuccess(Coin fee) {
                            UserThread.execute(() -> setFeeFromFundingTx(fee));
                        }

                        public void onFailure(@NotNull Throwable throwable) {
                            UserThread.execute(() -> new Popup<>()
                                    .warning("We did not get a response for the request of the mining fee used " +
                                            "in the funding transaction.\n\n" +
                                            "Are you sure you used a sufficiently high fee of at least " +
                                            formatter.formatCoinWithCode(FeePolicy.getMinRequiredFeeForFundingTx()) + "?")
                                    .actionButtonText("Yes, I used a sufficiently high fee.")
                                    .onAction(() -> setFeeFromFundingTx(FeePolicy.getMinRequiredFeeForFundingTx()))
                                    .closeButtonText("No. Let's cancel that payment.")
                                    .onClose(() -> setFeeFromFundingTx(Coin.NEGATIVE_SATOSHI))
                                    .show());
                        }
                    });
                } else {
                    setFeeFromFundingTx(FeePolicy.getMinRequiredFeeForFundingTx());
                    isFeeFromFundingTxSufficient.set(feeFromFundingTx.compareTo(FeePolicy.getMinRequiredFeeForFundingTx()) >= 0);
                }*/
        }
    };
    offer.resetState();
    priceFeedService.setCurrencyCode(offer.getCurrencyCode());
}
Also used : Coin(org.bitcoinj.core.Coin) BalanceListener(bisq.core.btc.listeners.BalanceListener) Transaction(org.bitcoinj.core.Transaction) PaymentAccount(bisq.core.payment.PaymentAccount)

Example 3 with BalanceListener

use of bisq.core.btc.listeners.BalanceListener in project bisq-desktop by bisq-network.

the class DepositView method initialize.

@Override
public void initialize() {
    paymentLabelString = Res.get("funds.deposit.fundBisqWallet");
    selectColumn.setGraphic(new AutoTooltipLabel(Res.get("shared.select")));
    addressColumn.setGraphic(new AutoTooltipLabel(Res.get("shared.address")));
    balanceColumn.setGraphic(new AutoTooltipLabel(Res.get("shared.balanceWithCur", Res.getBaseCurrencyCode())));
    confirmationsColumn.setGraphic(new AutoTooltipLabel(Res.get("shared.confirmations")));
    usageColumn.setGraphic(new AutoTooltipLabel(Res.get("shared.usage")));
    // trigger creation of at least 1 savings address
    walletService.getOrCreateAddressEntry(AddressEntry.Context.AVAILABLE);
    tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
    tableView.setPlaceholder(new AutoTooltipLabel(Res.get("funds.deposit.noAddresses")));
    tableViewSelectionListener = (observableValue, oldValue, newValue) -> {
        if (newValue != null) {
            fillForm(newValue.getAddressString());
            GUIUtil.requestFocus(amountTextField);
        }
    };
    setSelectColumnCellFactory();
    setAddressColumnCellFactory();
    setBalanceColumnCellFactory();
    setUsageColumnCellFactory();
    setConfidenceColumnCellFactory();
    addressColumn.setComparator((o1, o2) -> o1.getAddressString().compareTo(o2.getAddressString()));
    balanceColumn.setComparator((o1, o2) -> o1.getBalanceAsCoin().compareTo(o2.getBalanceAsCoin()));
    confirmationsColumn.setComparator((o1, o2) -> Double.valueOf(o1.getTxConfidenceIndicator().getProgress()).compareTo(o2.getTxConfidenceIndicator().getProgress()));
    usageColumn.setComparator((a, b) -> (a.getNumTxOutputs() < b.getNumTxOutputs()) ? -1 : ((a.getNumTxOutputs() == b.getNumTxOutputs()) ? 0 : 1));
    tableView.getSortOrder().add(usageColumn);
    tableView.setItems(sortedList);
    titledGroupBg = addTitledGroupBg(gridPane, gridRow, 3, Res.get("funds.deposit.fundWallet"));
    qrCodeImageView = new ImageView();
    qrCodeImageView.getStyleClass().add("qr-code");
    Tooltip.install(qrCodeImageView, new Tooltip(Res.get("shared.openLargeQRWindow")));
    qrCodeImageView.setOnMouseClicked(e -> GUIUtil.showFeeInfoBeforeExecute(() -> UserThread.runAfter(() -> new QRCodeWindow(getBitcoinURI()).show(), 200, TimeUnit.MILLISECONDS)));
    GridPane.setRowIndex(qrCodeImageView, gridRow);
    GridPane.setColumnIndex(qrCodeImageView, 1);
    GridPane.setMargin(qrCodeImageView, new Insets(Layout.FIRST_ROW_DISTANCE, 0, 0, 0));
    gridPane.getChildren().add(qrCodeImageView);
    Tuple2<Label, AddressTextField> addressTuple = addLabelAddressTextField(gridPane, ++gridRow, Res.getWithCol("shared.address"));
    addressLabel = addressTuple.first;
    // GridPane.setValignment(addressLabel, VPos.TOP);
    // GridPane.setMargin(addressLabel, new Insets(3, 0, 0, 0));
    addressTextField = addressTuple.second;
    addressTextField.setPaymentLabel(paymentLabelString);
    Tuple2<Label, InputTextField> amountTuple = addLabelInputTextField(gridPane, ++gridRow, Res.get("funds.deposit.amount"));
    amountLabel = amountTuple.first;
    amountTextField = amountTuple.second;
    if (DevEnv.isDevMode())
        amountTextField.setText("10");
    titledGroupBg.setVisible(false);
    titledGroupBg.setManaged(false);
    qrCodeImageView.setVisible(false);
    qrCodeImageView.setManaged(false);
    addressLabel.setVisible(false);
    addressLabel.setManaged(false);
    addressTextField.setVisible(false);
    addressTextField.setManaged(false);
    amountLabel.setVisible(false);
    amountTextField.setManaged(false);
    generateNewAddressButton = addButton(gridPane, ++gridRow, Res.get("funds.deposit.generateAddress"), -20);
    GridPane.setColumnIndex(generateNewAddressButton, 0);
    GridPane.setHalignment(generateNewAddressButton, HPos.LEFT);
    generateNewAddressButton.setOnAction(event -> {
        boolean hasUnUsedAddress = observableList.stream().filter(e -> e.getNumTxOutputs() == 0).findAny().isPresent();
        if (hasUnUsedAddress) {
            new Popup<>().warning(Res.get("funds.deposit.selectUnused")).show();
        } else {
            AddressEntry newSavingsAddressEntry = walletService.getOrCreateUnusedAddressEntry(AddressEntry.Context.AVAILABLE);
            updateList();
            observableList.stream().filter(depositListItem -> depositListItem.getAddressString().equals(newSavingsAddressEntry.getAddressString())).findAny().ifPresent(depositListItem -> tableView.getSelectionModel().select(depositListItem));
        }
    });
    balanceListener = new BalanceListener() {

        @Override
        public void onBalanceChanged(Coin balance, Transaction tx) {
            updateList();
        }
    };
    GUIUtil.focusWhenAddedToScene(amountTextField);
}
Also used : Insets(javafx.geometry.Insets) BalanceListener(bisq.core.btc.listeners.BalanceListener) AddressEntry(bisq.core.btc.AddressEntry) AddressTextField(bisq.desktop.components.AddressTextField) FormBuilder.addLabelAddressTextField(bisq.desktop.util.FormBuilder.addLabelAddressTextField) InputTextField(bisq.desktop.components.InputTextField) FormBuilder.addLabelInputTextField(bisq.desktop.util.FormBuilder.addLabelInputTextField) Tooltip(javafx.scene.control.Tooltip) AutoTooltipLabel(bisq.desktop.components.AutoTooltipLabel) Label(javafx.scene.control.Label) QRCodeWindow(bisq.desktop.main.overlays.windows.QRCodeWindow) Coin(org.bitcoinj.core.Coin) Transaction(org.bitcoinj.core.Transaction) Popup(bisq.desktop.main.overlays.popups.Popup) ImageView(javafx.scene.image.ImageView) AutoTooltipLabel(bisq.desktop.components.AutoTooltipLabel)

Example 4 with BalanceListener

use of bisq.core.btc.listeners.BalanceListener in project bisq-desktop by bisq-network.

the class LockedView method initialize.

@Override
public void initialize() {
    dateColumn.setGraphic(new AutoTooltipLabel(Res.get("shared.dateTime")));
    detailsColumn.setGraphic(new AutoTooltipLabel(Res.get("shared.details")));
    addressColumn.setGraphic(new AutoTooltipLabel(Res.get("shared.address")));
    balanceColumn.setGraphic(new AutoTooltipLabel(Res.get("shared.balanceWithCur", Res.getBaseCurrencyCode())));
    tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
    tableView.setPlaceholder(new AutoTooltipLabel(Res.get("funds.locked.noFunds")));
    setDateColumnCellFactory();
    setDetailsColumnCellFactory();
    setAddressColumnCellFactory();
    setBalanceColumnCellFactory();
    addressColumn.setComparator((o1, o2) -> o1.getAddressString().compareTo(o2.getAddressString()));
    detailsColumn.setComparator((o1, o2) -> o1.getTrade().getId().compareTo(o2.getTrade().getId()));
    balanceColumn.setComparator((o1, o2) -> o1.getBalance().compareTo(o2.getBalance()));
    dateColumn.setComparator((o1, o2) -> {
        if (getTradable(o1).isPresent() && getTradable(o2).isPresent())
            return getTradable(o2).get().getDate().compareTo(getTradable(o1).get().getDate());
        else
            return 0;
    });
    tableView.getSortOrder().add(dateColumn);
    dateColumn.setSortType(TableColumn.SortType.DESCENDING);
    balanceListener = new BalanceListener() {

        @Override
        public void onBalanceChanged(Coin balance, Transaction tx) {
            updateList();
        }
    };
    openOfferListChangeListener = c -> updateList();
    tradeListChangeListener = c -> updateList();
}
Also used : Coin(org.bitcoinj.core.Coin) BalanceListener(bisq.core.btc.listeners.BalanceListener) Transaction(org.bitcoinj.core.Transaction) AutoTooltipLabel(bisq.desktop.components.AutoTooltipLabel)

Example 5 with BalanceListener

use of bisq.core.btc.listeners.BalanceListener in project bisq-desktop by bisq-network.

the class WithdrawalView method initialize.

@Override
public void initialize() {
    inputsLabel.setText(Res.getWithCol("funds.withdrawal.inputs"));
    useAllInputsRadioButton.setText(Res.get("funds.withdrawal.useAllInputs"));
    useCustomInputsRadioButton.setText(Res.get("funds.withdrawal.useCustomInputs"));
    amountLabel.setText(Res.getWithCol("funds.withdrawal.receiverAmount", Res.getBaseCurrencyCode()));
    feeExcludedRadioButton.setText(Res.get("funds.withdrawal.feeExcluded"));
    feeIncludedRadioButton.setText(Res.get("funds.withdrawal.feeIncluded"));
    fromLabel.setText(Res.get("funds.withdrawal.fromLabel", Res.getBaseCurrencyCode()));
    toLabel.setText(Res.get("funds.withdrawal.toLabel", Res.getBaseCurrencyCode()));
    withdrawButton.setText(Res.get("funds.withdrawal.withdrawButton"));
    addressColumn.setGraphic(new AutoTooltipLabel(Res.get("shared.address")));
    balanceColumn.setGraphic(new AutoTooltipLabel(Res.get("shared.balanceWithCur", Res.getBaseCurrencyCode())));
    selectColumn.setGraphic(new AutoTooltipLabel(Res.get("shared.select")));
    tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
    tableView.setPlaceholder(new AutoTooltipLabel(Res.get("funds.withdrawal.noFundsAvailable")));
    tableView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
    setAddressColumnCellFactory();
    setBalanceColumnCellFactory();
    setSelectColumnCellFactory();
    addressColumn.setComparator((o1, o2) -> o1.getAddressString().compareTo(o2.getAddressString()));
    balanceColumn.setComparator((o1, o2) -> o1.getBalance().compareTo(o2.getBalance()));
    balanceColumn.setSortType(TableColumn.SortType.DESCENDING);
    tableView.getSortOrder().add(balanceColumn);
    balanceListener = new BalanceListener() {

        @Override
        public void onBalanceChanged(Coin balance, Transaction tx) {
            updateList();
        }
    };
    amountListener = (observable, oldValue, newValue) -> {
        if (amountTextField.focusedProperty().get()) {
            try {
                amountAsCoin = formatter.parseToCoin(amountTextField.getText());
            } catch (Throwable t) {
                log.error("Error at amountTextField input. " + t.toString());
            }
        }
    };
    amountFocusListener = (observable, oldValue, newValue) -> {
        if (oldValue && !newValue) {
            if (amountAsCoin.isPositive())
                amountTextField.setText(formatter.formatCoin(amountAsCoin));
            else
                amountTextField.setText("");
        }
    };
    feeToggleGroup = new ToggleGroup();
    feeExcludedRadioButton.setToggleGroup(feeToggleGroup);
    feeIncludedRadioButton.setToggleGroup(feeToggleGroup);
    feeToggleGroupListener = (observable, oldValue, newValue) -> {
        feeExcluded = newValue == feeExcludedRadioButton;
        amountLabel.setText(feeExcluded ? Res.getWithCol("funds.withdrawal.receiverAmount", Res.getBaseCurrencyCode()) : Res.getWithCol("funds.withdrawal.senderAmount", Res.getBaseCurrencyCode()));
    };
    inputsToggleGroup = new ToggleGroup();
    useAllInputsRadioButton.setToggleGroup(inputsToggleGroup);
    useCustomInputsRadioButton.setToggleGroup(inputsToggleGroup);
    inputsToggleGroupListener = (observable, oldValue, newValue) -> {
        useAllInputs.set(newValue == useAllInputsRadioButton);
        updateInputSelection();
    };
}
Also used : Coin(org.bitcoinj.core.Coin) BalanceListener(bisq.core.btc.listeners.BalanceListener) Transaction(org.bitcoinj.core.Transaction) ToggleGroup(javafx.scene.control.ToggleGroup) AutoTooltipLabel(bisq.desktop.components.AutoTooltipLabel)

Aggregations

BalanceListener (bisq.core.btc.listeners.BalanceListener)7 Coin (org.bitcoinj.core.Coin)7 Transaction (org.bitcoinj.core.Transaction)7 AutoTooltipLabel (bisq.desktop.components.AutoTooltipLabel)4 AddressEntry (bisq.core.btc.AddressEntry)2 PaymentAccount (bisq.core.payment.PaymentAccount)2 Popup (bisq.desktop.main.overlays.popups.Popup)2 Clock (bisq.common.Clock)1 Timer (bisq.common.Timer)1 UserThread (bisq.common.UserThread)1 DevEnv (bisq.common.app.DevEnv)1 Version (bisq.common.app.Version)1 CryptoException (bisq.common.crypto.CryptoException)1 KeyRing (bisq.common.crypto.KeyRing)1 SealedAndSigned (bisq.common.crypto.SealedAndSigned)1 Alert (bisq.core.alert.Alert)1 AlertManager (bisq.core.alert.AlertManager)1 PrivateNotificationManager (bisq.core.alert.PrivateNotificationManager)1 PrivateNotificationPayload (bisq.core.alert.PrivateNotificationPayload)1 AppOptionKeys (bisq.core.app.AppOptionKeys)1