suggest opening the send to many dialog when adding multiple payments on the send tab

This commit is contained in:
Craig Raw 2025-06-05 10:31:37 +02:00
parent 25770c2426
commit f28e00b97e
5 changed files with 66 additions and 7 deletions

View file

@ -1422,6 +1422,10 @@ public class AppController implements Initializable {
}
public void sendToMany(ActionEvent event) {
sendToMany(Collections.emptyList());
}
private void sendToMany(List<Payment> initialPayments) {
if(sendToManyDialog != null) {
Stage stage = (Stage)sendToManyDialog.getDialogPane().getScene().getWindow();
stage.setAlwaysOnTop(true);
@ -1437,7 +1441,7 @@ public class AppController implements Initializable {
bitcoinUnit = wallet.getAutoUnit();
}
sendToManyDialog = new SendToManyDialog(bitcoinUnit);
sendToManyDialog = new SendToManyDialog(bitcoinUnit, initialPayments);
sendToManyDialog.initModality(Modality.NONE);
Optional<List<Payment>> optPayments = sendToManyDialog.showAndWait();
sendToManyDialog = null;
@ -3107,6 +3111,11 @@ public class AppController implements Initializable {
}
}
@Subscribe
public void requestSendToMany(RequestSendToManyEvent event) {
sendToMany(event.getPayments());
}
@Subscribe
public void functionAction(FunctionActionEvent event) {
selectTab(event.getWallet());

View file

@ -13,8 +13,6 @@ import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Node;
import javafx.scene.control.*;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.Clipboard;
import javafx.scene.layout.StackPane;
import javafx.stage.FileChooser;
@ -34,7 +32,7 @@ public class SendToManyDialog extends Dialog<List<Payment>> {
private final SpreadsheetView spreadsheetView;
public static final AddressCellType ADDRESS = new AddressCellType();
public SendToManyDialog(BitcoinUnit bitcoinUnit) {
public SendToManyDialog(BitcoinUnit bitcoinUnit, List<Payment> payments) {
this.bitcoinUnit = bitcoinUnit;
final DialogPane dialogPane = new SendToManyDialogPane();
@ -44,7 +42,8 @@ public class SendToManyDialog extends Dialog<List<Payment>> {
dialogPane.setHeaderText("Send to many recipients by specifying addresses and amounts.\nOnly the first row's label is necessary.");
dialogPane.setGraphic(new DialogImage(DialogImage.Type.SPARROW));
List<Payment> initialPayments = IntStream.range(0, 100).mapToObj(i -> new Payment(null, null, -1, false)).collect(Collectors.toList());
List<Payment> initialPayments = IntStream.range(0, 100)
.mapToObj(i -> i < payments.size() ? payments.get(i) : new Payment(null, null, -1, false)).collect(Collectors.toList());
Grid grid = getGrid(initialPayments);
spreadsheetView = new SpreadsheetView(grid) {

View file

@ -0,0 +1,17 @@
package com.sparrowwallet.sparrow.event;
import com.sparrowwallet.drongo.wallet.Payment;
import java.util.List;
public class RequestSendToManyEvent {
private final List<Payment> payments;
public RequestSendToManyEvent(List<Payment> payments) {
this.payments = payments;
}
public List<Payment> getPayments() {
return payments;
}
}

View file

@ -53,6 +53,7 @@ public class Config {
private boolean signBsmsExports = false;
private boolean preventSleep = false;
private Boolean connectToBroadcast;
private Boolean suggestSendToMany;
private List<File> recentWalletFiles;
private Integer keyDerivationPeriod;
private long dustAttackThreshold = DUST_ATTACK_THRESHOLD_SATS;
@ -361,6 +362,15 @@ public class Config {
flush();
}
public Boolean getSuggestSendToMany() {
return suggestSendToMany;
}
public void setSuggestSendToMany(Boolean suggestSendToMany) {
this.suggestSendToMany = suggestSendToMany;
flush();
}
public List<File> getRecentWalletFiles() {
return recentWalletFiles;
}

View file

@ -491,11 +491,35 @@ public class SendController extends WalletFormController implements Initializabl
validationSupport.setErrorDecorationEnabled(false);
}
public Tab addPaymentTab() {
public void addPaymentTab() {
if(Config.get().getSuggestSendToMany() == null && openSendToMany()) {
return;
}
Tab tab = getPaymentTab();
paymentTabs.getTabs().add(tab);
paymentTabs.getSelectionModel().select(tab);
return tab;
}
private boolean openSendToMany() {
try {
List<Payment> payments = getPayments();
if(payments.size() == 3) {
ConfirmationAlert confirmationAlert = new ConfirmationAlert("Open Send To Many?", "Open the Tools > Send To Many dialog to add multiple payments?", ButtonType.NO, ButtonType.YES);
Optional<ButtonType> optType = confirmationAlert.showAndWait();
if(confirmationAlert.isDontAskAgain() && optType.isPresent()) {
Config.get().setSuggestSendToMany(optType.get() == ButtonType.YES);
}
if(optType.isPresent() && optType.get() == ButtonType.YES) {
Platform.runLater(() -> EventManager.get().post(new RequestSendToManyEvent(payments)));
return true;
}
}
} catch(Exception e) {
//ignore
}
return false;
}
public Tab getPaymentTab() {