Search in sources :

Example 1 with PayNymDialog

use of com.sparrowwallet.sparrow.paynym.PayNymDialog in project sparrow by sparrowwallet.

the class PaymentController method initializeView.

@Override
public void initializeView() {
    updateOpenWallets();
    openWallets.prefWidthProperty().bind(address.widthProperty());
    openWallets.valueProperty().addListener((observable, oldValue, newValue) -> {
        if (newValue == payNymWallet) {
            boolean selectLinkedOnly = sendController.getPaymentTabs().getTabs().size() > 1 || !SorobanServices.canWalletMix(sendController.getWalletForm().getWallet());
            PayNymDialog payNymDialog = new PayNymDialog(sendController.getWalletForm().getWalletId(), true, selectLinkedOnly);
            Optional<PayNym> optPayNym = payNymDialog.showAndWait();
            optPayNym.ifPresent(this::setPayNym);
        } else if (newValue != null) {
            WalletNode freshNode = newValue.getFreshNode(KeyPurpose.RECEIVE);
            Address freshAddress = freshNode.getAddress();
            address.setText(freshAddress.toString());
            label.requestFocus();
        }
    });
    openWallets.setCellFactory(c -> new ListCell<>() {

        @Override
        protected void updateItem(Wallet wallet, boolean empty) {
            super.updateItem(wallet, empty);
            if (empty || wallet == null) {
                setText(null);
                setGraphic(null);
            } else {
                setText(wallet.getFullDisplayName() + (wallet == sendController.getWalletForm().getWallet() ? " (Consolidation)" : ""));
                setGraphic(wallet == payNymWallet ? getPayNymGlyph() : null);
            }
        }
    });
    payNymProperty.addListener((observable, oldValue, payNym) -> {
        updateMixOnlyStatus(payNym);
        revalidateAmount();
    });
    address.textProperty().addListener((observable, oldValue, newValue) -> {
        address.leftProperty().set(null);
        if (payNymProperty.get() != null && !newValue.equals(payNymProperty.get().nymName())) {
            payNymProperty.set(null);
        }
        try {
            BitcoinURI bitcoinURI = new BitcoinURI(newValue);
            Platform.runLater(() -> updateFromURI(bitcoinURI));
            return;
        } catch (Exception e) {
        // ignore, not a URI
        }
        if (sendController.getWalletForm().getWallet().hasPaymentCode()) {
            try {
                PaymentCode paymentCode = new PaymentCode(newValue);
                Wallet recipientBip47Wallet = sendController.getWalletForm().getWallet().getChildWallet(paymentCode, sendController.getWalletForm().getWallet().getScriptType());
                if (recipientBip47Wallet == null && sendController.getWalletForm().getWallet().getScriptType() != ScriptType.P2PKH) {
                    recipientBip47Wallet = sendController.getWalletForm().getWallet().getChildWallet(paymentCode, ScriptType.P2PKH);
                }
                if (recipientBip47Wallet != null) {
                    PayNym payNym = PayNym.fromWallet(recipientBip47Wallet);
                    Platform.runLater(() -> setPayNym(payNym));
                } else if (!paymentCode.equals(sendController.getWalletForm().getWallet().getPaymentCode())) {
                    ButtonType previewType = new ButtonType("Preview Transaction", ButtonBar.ButtonData.YES);
                    Optional<ButtonType> optButton = AppServices.showAlertDialog("Send notification transaction?", "This payment code is not yet linked with a notification transaction. Send a notification transaction?", Alert.AlertType.CONFIRMATION, ButtonType.CANCEL, previewType);
                    if (optButton.isPresent() && optButton.get() == previewType) {
                        Payment payment = new Payment(paymentCode.getNotificationAddress(), "Link " + paymentCode.toAbbreviatedString(), MINIMUM_P2PKH_OUTPUT_SATS, false);
                        Platform.runLater(() -> EventManager.get().post(new SpendUtxoEvent(sendController.getWalletForm().getWallet(), List.of(payment), List.of(new byte[80]), paymentCode)));
                    } else {
                        Platform.runLater(() -> address.setText(""));
                    }
                }
            } catch (Exception e) {
            // ignore, not a payment code
            }
        }
        revalidateAmount();
        maxButton.setDisable(!isMaxButtonEnabled());
        sendController.updateTransaction();
        if (validationSupport != null) {
            validationSupport.setErrorDecorationEnabled(true);
        }
    });
    label.textProperty().addListener((observable, oldValue, newValue) -> {
        maxButton.setDisable(!isMaxButtonEnabled());
        sendController.getCreateButton().setDisable(sendController.getWalletTransaction() == null || newValue == null || newValue.isEmpty() || sendController.isInsufficientFeeRate());
        sendController.updateTransaction();
    });
    amount.setTextFormatter(new CoinTextFormatter());
    amount.textProperty().addListener(amountListener);
    amountUnit.getSelectionModel().select(BitcoinUnit.BTC.equals(sendController.getBitcoinUnit(Config.get().getBitcoinUnit())) ? 0 : 1);
    amountUnit.valueProperty().addListener((observable, oldValue, newValue) -> {
        Long value = getRecipientValueSats(oldValue);
        if (value != null) {
            DecimalFormat df = new DecimalFormat("#.#", DecimalFormatSymbols.getInstance(Locale.ENGLISH));
            df.setMaximumFractionDigits(8);
            amount.setText(df.format(newValue.getValue(value)));
        }
    });
    maxButton.setDisable(!isMaxButtonEnabled());
    sendController.utxoSelectorProperty().addListener((observable, oldValue, newValue) -> {
        maxButton.setDisable(!isMaxButtonEnabled());
    });
    sendController.getPaymentTabs().getTabs().addListener((ListChangeListener<Tab>) c -> {
        maxButton.setDisable(!isMaxButtonEnabled());
    });
    sendController.utxoLabelSelectionProperty().addListener((observable, oldValue, newValue) -> {
        maxButton.setText("Max" + newValue);
    });
    amountStatus.managedProperty().bind(amountStatus.visibleProperty());
    amountStatus.visibleProperty().bind(sendController.insufficientInputsProperty().and(dustAmountProperty.not()).and(emptyAmountProperty.not()));
    dustStatus.managedProperty().bind(dustStatus.visibleProperty());
    dustStatus.visibleProperty().bind(dustAmountProperty);
    Optional<Tab> firstTab = sendController.getPaymentTabs().getTabs().stream().findFirst();
    if (firstTab.isPresent()) {
        PaymentController controller = (PaymentController) firstTab.get().getUserData();
        String firstLabel = controller.label.getText();
        label.setText(firstLabel);
    }
    addValidation(validationSupport);
}
Also used : Initializable(javafx.fxml.Initializable) PayNym(com.sparrowwallet.sparrow.paynym.PayNym) com.sparrowwallet.drongo.wallet(com.sparrowwallet.drongo.wallet) javafx.scene.control(javafx.scene.control) URL(java.net.URL) DecimalFormatSymbols(java.text.DecimalFormatSymbols) LoggerFactory(org.slf4j.LoggerFactory) ValidationSupport(org.controlsfx.validation.ValidationSupport) Config(com.sparrowwallet.sparrow.io.Config) PayNymAddress(com.sparrowwallet.sparrow.paynym.PayNymAddress) ExchangeSource(com.sparrowwallet.sparrow.net.ExchangeSource) ListChangeListener(javafx.collections.ListChangeListener) CurrencyRate(com.sparrowwallet.sparrow.CurrencyRate) FontAwesome5(com.sparrowwallet.sparrow.glyphfont.FontAwesome5) InvalidPaymentCodeException(com.sparrowwallet.drongo.bip47.InvalidPaymentCodeException) Collectors(java.util.stream.Collectors) BitcoinURI(com.sparrowwallet.drongo.uri.BitcoinURI) Platform(javafx.application.Platform) FXML(javafx.fxml.FXML) BooleanProperty(javafx.beans.property.BooleanProperty) KeyPurpose(com.sparrowwallet.drongo.KeyPurpose) ScriptType(com.sparrowwallet.drongo.protocol.ScriptType) PaymentCode(com.sparrowwallet.drongo.bip47.PaymentCode) Address(com.sparrowwallet.drongo.address.Address) java.util(java.util) FXCollections(javafx.collections.FXCollections) InvalidAddressException(com.sparrowwallet.drongo.address.InvalidAddressException) AppServices.showErrorDialog(com.sparrowwallet.sparrow.AppServices.showErrorDialog) Glyph(org.controlsfx.glyphfont.Glyph) TransactionOutput(com.sparrowwallet.drongo.protocol.TransactionOutput) ValidationResult(org.controlsfx.validation.ValidationResult) Subscribe(com.google.common.eventbus.Subscribe) Transaction(com.sparrowwallet.drongo.protocol.Transaction) ObjectProperty(javafx.beans.property.ObjectProperty) Logger(org.slf4j.Logger) P2PKHAddress(com.sparrowwallet.drongo.address.P2PKHAddress) com.sparrowwallet.sparrow.event(com.sparrowwallet.sparrow.event) DecimalFormat(java.text.DecimalFormat) com.sparrowwallet.sparrow.soroban(com.sparrowwallet.sparrow.soroban) BitcoinUnit(com.sparrowwallet.drongo.BitcoinUnit) PayNymDialog(com.sparrowwallet.sparrow.paynym.PayNymDialog) ActionEvent(javafx.event.ActionEvent) AppServices(com.sparrowwallet.sparrow.AppServices) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) EventManager(com.sparrowwallet.sparrow.EventManager) ECKey(com.sparrowwallet.drongo.crypto.ECKey) ObservableValue(javafx.beans.value.ObservableValue) Validator(org.controlsfx.validation.Validator) ChangeListener(javafx.beans.value.ChangeListener) com.sparrowwallet.sparrow.control(com.sparrowwallet.sparrow.control) PaymentCode(com.sparrowwallet.drongo.bip47.PaymentCode) PayNymAddress(com.sparrowwallet.sparrow.paynym.PayNymAddress) Address(com.sparrowwallet.drongo.address.Address) P2PKHAddress(com.sparrowwallet.drongo.address.P2PKHAddress) DecimalFormat(java.text.DecimalFormat) PayNym(com.sparrowwallet.sparrow.paynym.PayNym) InvalidPaymentCodeException(com.sparrowwallet.drongo.bip47.InvalidPaymentCodeException) InvalidAddressException(com.sparrowwallet.drongo.address.InvalidAddressException) PayNymDialog(com.sparrowwallet.sparrow.paynym.PayNymDialog) BitcoinURI(com.sparrowwallet.drongo.uri.BitcoinURI)

Example 2 with PayNymDialog

use of com.sparrowwallet.sparrow.paynym.PayNymDialog in project sparrow by sparrowwallet.

the class CounterpartyController method showPayNym.

public void showPayNym(ActionEvent event) {
    PayNymDialog payNymDialog = new PayNymDialog(walletId);
    payNymDialog.showAndWait();
}
Also used : PayNymDialog(com.sparrowwallet.sparrow.paynym.PayNymDialog)

Aggregations

PayNymDialog (com.sparrowwallet.sparrow.paynym.PayNymDialog)2 Subscribe (com.google.common.eventbus.Subscribe)1 BitcoinUnit (com.sparrowwallet.drongo.BitcoinUnit)1 KeyPurpose (com.sparrowwallet.drongo.KeyPurpose)1 Address (com.sparrowwallet.drongo.address.Address)1 InvalidAddressException (com.sparrowwallet.drongo.address.InvalidAddressException)1 P2PKHAddress (com.sparrowwallet.drongo.address.P2PKHAddress)1 InvalidPaymentCodeException (com.sparrowwallet.drongo.bip47.InvalidPaymentCodeException)1 PaymentCode (com.sparrowwallet.drongo.bip47.PaymentCode)1 ECKey (com.sparrowwallet.drongo.crypto.ECKey)1 ScriptType (com.sparrowwallet.drongo.protocol.ScriptType)1 Transaction (com.sparrowwallet.drongo.protocol.Transaction)1 TransactionOutput (com.sparrowwallet.drongo.protocol.TransactionOutput)1 BitcoinURI (com.sparrowwallet.drongo.uri.BitcoinURI)1 com.sparrowwallet.drongo.wallet (com.sparrowwallet.drongo.wallet)1 AppServices (com.sparrowwallet.sparrow.AppServices)1 AppServices.showErrorDialog (com.sparrowwallet.sparrow.AppServices.showErrorDialog)1 CurrencyRate (com.sparrowwallet.sparrow.CurrencyRate)1 EventManager (com.sparrowwallet.sparrow.EventManager)1 com.sparrowwallet.sparrow.control (com.sparrowwallet.sparrow.control)1