diff --git a/drongo b/drongo index f00754b1..9b117cd7 160000 --- a/drongo +++ b/drongo @@ -1 +1 @@ -Subproject commit f00754b15779e94faa65c3de5c0a977cc51d865b +Subproject commit 9b117cd7f90caba5e280034dee5865a1a42d82c1 diff --git a/src/main/java/com/sparrowwallet/sparrow/AppController.java b/src/main/java/com/sparrowwallet/sparrow/AppController.java index b7bfc2fa..0e6fc24d 100644 --- a/src/main/java/com/sparrowwallet/sparrow/AppController.java +++ b/src/main/java/com/sparrowwallet/sparrow/AppController.java @@ -861,6 +861,12 @@ public class AppController implements Initializable { tabs.getSelectionModel().select(tab); } + @Subscribe + public void viewPSBT(ViewPSBTEvent event) { + Tab tab = addTransactionTab(event.getLabel(), event.getPsbt()); + tabs.getSelectionModel().select(tab); + } + @Subscribe public void bitcoinUnitChanged(BitcoinUnitChangedEvent event) { Optional selectedToggle = bitcoinUnit.getToggles().stream().filter(toggle -> event.getBitcoinUnit().equals(toggle.getUserData())).findFirst(); diff --git a/src/main/java/com/sparrowwallet/sparrow/event/ViewPSBTEvent.java b/src/main/java/com/sparrowwallet/sparrow/event/ViewPSBTEvent.java new file mode 100644 index 00000000..a5e3f31c --- /dev/null +++ b/src/main/java/com/sparrowwallet/sparrow/event/ViewPSBTEvent.java @@ -0,0 +1,38 @@ +package com.sparrowwallet.sparrow.event; + +import com.sparrowwallet.drongo.psbt.PSBT; +import com.sparrowwallet.sparrow.transaction.TransactionView; + +public class ViewPSBTEvent { + private final String label; + private final PSBT psbt; + private final TransactionView initialView; + private final Integer initialIndex; + + public ViewPSBTEvent(String label, PSBT psbt) { + this(label, psbt, TransactionView.HEADERS, null); + } + + public ViewPSBTEvent(String label, PSBT psbt, TransactionView initialView, Integer initialIndex) { + this.label = label; + this.psbt = psbt; + this.initialView = initialView; + this.initialIndex = initialIndex; + } + + public String getLabel() { + return label; + } + + public PSBT getPsbt() { + return psbt; + } + + public TransactionView getInitialView() { + return initialView; + } + + public Integer getInitialIndex() { + return initialIndex; + } +} diff --git a/src/main/java/com/sparrowwallet/sparrow/event/ViewTransactionEvent.java b/src/main/java/com/sparrowwallet/sparrow/event/ViewTransactionEvent.java index 70e91d27..0ddd53ed 100644 --- a/src/main/java/com/sparrowwallet/sparrow/event/ViewTransactionEvent.java +++ b/src/main/java/com/sparrowwallet/sparrow/event/ViewTransactionEvent.java @@ -5,9 +5,9 @@ import com.sparrowwallet.sparrow.transaction.TransactionView; import com.sparrowwallet.sparrow.wallet.HashIndexEntry; public class ViewTransactionEvent { - public final BlockTransaction blockTransaction; - public final TransactionView initialView; - public final Integer initialIndex; + private final BlockTransaction blockTransaction; + private final TransactionView initialView; + private final Integer initialIndex; public ViewTransactionEvent(BlockTransaction blockTransaction) { this(blockTransaction, TransactionView.HEADERS, null); diff --git a/src/main/java/com/sparrowwallet/sparrow/wallet/SendController.java b/src/main/java/com/sparrowwallet/sparrow/wallet/SendController.java index 23fb0315..83bbd1cc 100644 --- a/src/main/java/com/sparrowwallet/sparrow/wallet/SendController.java +++ b/src/main/java/com/sparrowwallet/sparrow/wallet/SendController.java @@ -7,6 +7,7 @@ import com.sparrowwallet.drongo.address.InvalidAddressException; import com.sparrowwallet.drongo.address.P2PKHAddress; import com.sparrowwallet.drongo.protocol.Transaction; import com.sparrowwallet.drongo.protocol.TransactionOutput; +import com.sparrowwallet.drongo.psbt.PSBT; import com.sparrowwallet.drongo.wallet.*; import com.sparrowwallet.sparrow.AppController; import com.sparrowwallet.sparrow.CurrencyRate; @@ -147,14 +148,16 @@ public class SendController extends WalletFormController implements Initializabl @Override public void initializeView() { - addValidation(); - address.textProperty().addListener((observable, oldValue, newValue) -> { revalidate(amount, amountListener); maxButton.setDisable(!isValidRecipientAddress()); updateTransaction(); }); + label.textProperty().addListener((observable, oldValue, newValue) -> { + createButton.setDisable(walletTransactionProperty.get() == null || newValue == null || newValue.isEmpty()); + }); + amount.setTextFormatter(new CoinTextFormatter()); amount.textProperty().addListener(amountListener); @@ -265,10 +268,12 @@ public class SendController extends WalletFormController implements Initializabl } transactionDiagram.update(walletTransaction); - createButton.setDisable(walletTransaction == null); + createButton.setDisable(walletTransaction == null || label.getText().isEmpty()); }); address.setText("32YSPMaUePf511u5adEckiNq8QLec9ksXX"); + + addValidation(); } private void addValidation() { @@ -276,6 +281,9 @@ public class SendController extends WalletFormController implements Initializabl validationSupport.registerValidator(address, Validator.combine( (Control c, String newValue) -> ValidationResult.fromErrorIf( c, "Invalid Address", !newValue.isEmpty() && !isValidRecipientAddress()) )); + validationSupport.registerValidator(label, Validator.combine( + Validator.createEmptyValidator("Label is required") + )); validationSupport.registerValidator(amount, Validator.combine( (Control c, String newValue) -> ValidationResult.fromErrorIf( c, "Insufficient Inputs", insufficientInputsProperty.get()), (Control c, String newValue) -> ValidationResult.fromErrorIf( c, "Insufficient Value", getRecipientValueSats() != null && getRecipientValueSats() <= getRecipientDustThreshold()) @@ -499,7 +507,8 @@ public class SendController extends WalletFormController implements Initializabl } public void createTransaction(ActionEvent event) { - + PSBT psbt = walletTransactionProperty.get().createPSBT(); + EventManager.get().post(new ViewPSBTEvent(label.getText(), psbt)); } @Subscribe