From 5d823571df20b693f35f1b5a3531ed472d40185c Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Thu, 3 Feb 2022 12:45:01 +0200 Subject: [PATCH] remap partial batch successes to original ids, lock menu functionality when wallet is locked --- drongo | 2 +- .../sparrowwallet/sparrow/AppController.java | 9 +++++---- .../sparrow/control/SearchWalletDialog.java | 3 +++ .../sparrow/control/TransactionDiagram.java | 17 ++++++++++------ .../sparrow/net/PagedBatchRequestBuilder.java | 20 ++++++++++++++++--- 5 files changed, 37 insertions(+), 14 deletions(-) diff --git a/drongo b/drongo index 9618c73c..ee732fb2 160000 --- a/drongo +++ b/drongo @@ -1 +1 @@ -Subproject commit 9618c73c50e59035cd373d932970f446032cd9e5 +Subproject commit ee732fb2235fbe242d75366fc37d3f53e2082519 diff --git a/src/main/java/com/sparrowwallet/sparrow/AppController.java b/src/main/java/com/sparrowwallet/sparrow/AppController.java index e26fad2c..7a37bc6b 100644 --- a/src/main/java/com/sparrowwallet/sparrow/AppController.java +++ b/src/main/java/com/sparrowwallet/sparrow/AppController.java @@ -422,9 +422,8 @@ public class AppController implements Initializable { Parent root = loader.load(); AboutController controller = loader.getController(); - Stage stage = new Stage(); + Stage stage = new Stage(StageStyle.UNDECORATED); stage.setTitle("About " + MainApp.APP_NAME); - stage.initStyle(StageStyle.UNDECORATED); stage.initOwner(tabs.getScene().getWindow()); stage.initModality(Modality.WINDOW_MODAL); stage.setResizable(false); @@ -1960,7 +1959,7 @@ public class AppController implements Initializable { saveTransaction.setVisible(true); saveTransaction.setDisable(true); lockWallet.setDisable(walletTabData.getWalletForm().lockedProperty().get()); - exportWallet.setDisable(walletTabData.getWallet() == null || !walletTabData.getWallet().isValid()); + exportWallet.setDisable(walletTabData.getWallet() == null || !walletTabData.getWallet().isValid() || walletTabData.getWalletForm().isLocked()); showLoadingLog.setDisable(false); showTxHex.setDisable(true); findMixingPartner.setDisable(exportWallet.isDisable() || !SorobanServices.canWalletMix(walletTabData.getWallet()) || !AppServices.onlineProperty().get()); @@ -1987,7 +1986,7 @@ public class AppController implements Initializable { WalletForm selectedWalletForm = getSelectedWalletForm(); if(selectedWalletForm != null) { if(selectedWalletForm.getWalletId().equals(event.getWalletId())) { - exportWallet.setDisable(!event.getWallet().isValid()); + exportWallet.setDisable(!event.getWallet().isValid() || selectedWalletForm.isLocked()); findMixingPartner.setDisable(exportWallet.isDisable() || !SorobanServices.canWalletMix(event.getWallet()) || !AppServices.onlineProperty().get()); } } @@ -2476,6 +2475,7 @@ public class AppController implements Initializable { WalletForm selectedWalletForm = getSelectedWalletForm(); if(selectedWalletForm != null && selectedWalletForm.getMasterWallet().equals(event.getWallet())) { lockWallet.setDisable(true); + exportWallet.setDisable(true); } } @@ -2484,6 +2484,7 @@ public class AppController implements Initializable { WalletForm selectedWalletForm = getSelectedWalletForm(); if(selectedWalletForm != null && selectedWalletForm.getMasterWallet().equals(event.getWallet())) { lockWallet.setDisable(false); + exportWallet.setDisable(!event.getWallet().isValid()); } } } diff --git a/src/main/java/com/sparrowwallet/sparrow/control/SearchWalletDialog.java b/src/main/java/com/sparrowwallet/sparrow/control/SearchWalletDialog.java index 664db723..71b51cab 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/SearchWalletDialog.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/SearchWalletDialog.java @@ -4,6 +4,7 @@ import com.sparrowwallet.drongo.KeyPurpose; import com.sparrowwallet.drongo.wallet.Wallet; import com.sparrowwallet.sparrow.AppServices; import com.sparrowwallet.sparrow.wallet.*; +import javafx.application.Platform; import javafx.beans.property.ReadOnlyObjectWrapper; import javafx.collections.ListChangeListener; import javafx.scene.control.*; @@ -134,6 +135,8 @@ public class SearchWalletDialog extends Dialog { }); setResizable(true); + + Platform.runLater(search::requestFocus); } private void searchWallet(String searchText) { diff --git a/src/main/java/com/sparrowwallet/sparrow/control/TransactionDiagram.java b/src/main/java/com/sparrowwallet/sparrow/control/TransactionDiagram.java index bedb37d2..e91d085b 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/TransactionDiagram.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/TransactionDiagram.java @@ -8,10 +8,12 @@ import com.sparrowwallet.drongo.uri.BitcoinURI; import com.sparrowwallet.drongo.wallet.*; import com.sparrowwallet.sparrow.AppServices; import com.sparrowwallet.sparrow.EventManager; +import com.sparrowwallet.sparrow.Theme; import com.sparrowwallet.sparrow.event.ExcludeUtxoEvent; import com.sparrowwallet.sparrow.event.ReplaceChangeAddressEvent; import com.sparrowwallet.sparrow.event.SorobanInitiatedEvent; import com.sparrowwallet.sparrow.glyphfont.FontAwesome5; +import com.sparrowwallet.sparrow.io.Config; import com.sparrowwallet.sparrow.soroban.SorobanServices; import com.sparrowwallet.sparrow.wallet.OptimizationStrategy; import javafx.beans.property.BooleanProperty; @@ -67,15 +69,17 @@ public class TransactionDiagram extends GridPane { @Override public void handle(MouseEvent event) { if(!event.isConsumed()) { - Stage stage = new Stage(); + Stage stage = new Stage(StageStyle.UNDECORATED); stage.setTitle(walletTx.getPayments().iterator().next().getLabel()); - stage.initStyle(StageStyle.UNDECORATED); stage.initOwner(TransactionDiagram.this.getScene().getWindow()); stage.initModality(Modality.WINDOW_MODAL); stage.setResizable(false); VBox vBox = new VBox(20); vBox.getStylesheets().add(AppServices.class.getResource("general.css").toExternalForm()); + if(Config.get().getTheme() == Theme.DARK) { + vBox.getStylesheets().add(AppServices.class.getResource("darktheme.css").toExternalForm()); + } vBox.getStylesheets().add(AppServices.class.getResource("wallet/wallet.css").toExternalForm()); vBox.getStylesheets().add(AppServices.class.getResource("wallet/send.css").toExternalForm()); vBox.setPadding(new Insets(20, 40, 20, 50)); @@ -411,8 +415,9 @@ public class TransactionDiagram extends GridPane { } else if(input instanceof AdditionalBlockTransactionHashIndex additionalReference) { inputValue = input.getValue(); StringJoiner joiner = new StringJoiner("\n"); + joiner.add("Spending " + getSatsValue(inputValue) + " sats from" + (isExpanded() ? ":" : " (click to expand):")); for(BlockTransactionHashIndex additionalInput : additionalReference.getAdditionalInputs()) { - joiner.add(getInputDescription(additionalInput)); + joiner.add(additionalInput.getHashAsString() + ":" + additionalInput.getIndex()); } tooltip.setText(joiner.toString()); } else if(input instanceof InvisibleBlockTransactionHashIndex) { @@ -464,8 +469,8 @@ public class TransactionDiagram extends GridPane { } else if(label.getText().trim().isEmpty()) { amountLabel.setText(""); } - amountLabel.setMinWidth(TextUtils.computeTextWidth(amountLabel.getFont(), amountLabel.getText(), 0.0D) + 7); - amountLabel.setPadding(new Insets(0, 0, 0, 5)); + amountLabel.setMinWidth(TextUtils.computeTextWidth(amountLabel.getFont(), amountLabel.getText(), 0.0D) + 12); + amountLabel.setPadding(new Insets(0, 0, 0, 10)); inputBox.getChildren().addAll(region, amountLabel); } @@ -637,7 +642,7 @@ public class TransactionDiagram extends GridPane { WalletNode toNode = walletTx.getWallet() != null ? walletTx.getWallet().getWalletAddresses().get(payment.getAddress()) : null; Tooltip recipientTooltip = new Tooltip((toWallet == null ? (toNode != null ? "Consolidate " : "Pay ") : "Receive ") + getSatsValue(payment.getAmount()) + " sats to " - + (payment instanceof AdditionalPayment ? "\n" + payment : (toWallet == null ? (payment.getLabel() == null ? (toNode != null ? toNode : "external address") : payment.getLabel()) : toWallet.getFullDisplayName()) + "\n" + payment.getAddress().toString())); + + (payment instanceof AdditionalPayment ? (isExpanded() ? "\n" : "(click to expand)\n") + payment : (toWallet == null ? (payment.getLabel() == null ? (toNode != null ? toNode : "external address") : payment.getLabel()) : toWallet.getFullDisplayName()) + "\n" + payment.getAddress().toString())); recipientTooltip.getStyleClass().add("recipient-label"); recipientTooltip.setShowDelay(new Duration(TOOLTIP_SHOW_DELAY)); recipientTooltip.setShowDuration(Duration.INDEFINITE); diff --git a/src/main/java/com/sparrowwallet/sparrow/net/PagedBatchRequestBuilder.java b/src/main/java/com/sparrowwallet/sparrow/net/PagedBatchRequestBuilder.java index c97b3563..41545c07 100644 --- a/src/main/java/com/sparrowwallet/sparrow/net/PagedBatchRequestBuilder.java +++ b/src/main/java/com/sparrowwallet/sparrow/net/PagedBatchRequestBuilder.java @@ -5,6 +5,8 @@ import com.github.arteam.simplejsonrpc.client.JsonRpcClient; import com.github.arteam.simplejsonrpc.client.Transport; import com.github.arteam.simplejsonrpc.client.builder.AbstractBuilder; import com.github.arteam.simplejsonrpc.client.builder.BatchRequestBuilder; +import com.github.arteam.simplejsonrpc.client.exception.JsonRpcBatchException; +import com.github.arteam.simplejsonrpc.core.domain.ErrorMessage; import com.google.common.collect.Lists; import com.sparrowwallet.sparrow.io.Config; import org.jetbrains.annotations.NotNull; @@ -122,9 +124,21 @@ public class PagedBatchRequestBuilder extends AbstractBuilder { batchRequest.add(request.counterId, request.method, request.params); } - Map pageResult = new RetryLogic>(maxAttempts, RETRY_DELAY_SECS, List.of(IllegalStateException.class, IllegalArgumentException.class)).getResult(batchRequest::execute); - for(Map.Entry pageEntry : pageResult.entrySet()) { - allResults.put(counterIdMap.get(pageEntry.getKey()), pageEntry.getValue()); + try { + Map pageResult = new RetryLogic>(maxAttempts, RETRY_DELAY_SECS, List.of(IllegalStateException.class, IllegalArgumentException.class)).getResult(batchRequest::execute); + for(Map.Entry pageEntry : pageResult.entrySet()) { + allResults.put(counterIdMap.get(pageEntry.getKey()), pageEntry.getValue()); + } + } catch(JsonRpcBatchException e) { + Map mappedSuccesess = new HashMap<>(); + for(Map.Entry successEntry : e.getSuccesses().entrySet()) { + mappedSuccesess.put(counterIdMap.get((Long)successEntry.getKey()), successEntry.getValue()); + } + Map mappedErrors = new HashMap<>(); + for(Map.Entry errorEntry : e.getErrors().entrySet()) { + mappedErrors.put(counterIdMap.get((Long)errorEntry.getKey()), errorEntry.getValue()); + } + throw new JsonRpcBatchException(e.getMessage(), mappedSuccesess, mappedErrors); } } else { BatchRequestBuilder batchRequest = client.createBatchRequest().keysType(keysType).returnType(returnType);