diff --git a/src/main/java/com/sparrowwallet/sparrow/control/TransactionDiagram.java b/src/main/java/com/sparrowwallet/sparrow/control/TransactionDiagram.java index e04bb789..409f57d0 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/TransactionDiagram.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/TransactionDiagram.java @@ -8,15 +8,13 @@ import com.sparrowwallet.drongo.protocol.Sha256Hash; import com.sparrowwallet.drongo.protocol.TransactionOutput; import com.sparrowwallet.drongo.uri.BitcoinURI; import com.sparrowwallet.drongo.wallet.*; -import com.sparrowwallet.sparrow.UnitFormat; -import com.sparrowwallet.sparrow.AppServices; -import com.sparrowwallet.sparrow.EventManager; -import com.sparrowwallet.sparrow.Theme; +import com.sparrowwallet.sparrow.*; import com.sparrowwallet.sparrow.event.ExcludeUtxoEvent; import com.sparrowwallet.sparrow.event.ReplaceChangeAddressEvent; import com.sparrowwallet.sparrow.glyphfont.FontAwesome5; import com.sparrowwallet.sparrow.glyphfont.GlyphUtils; import com.sparrowwallet.sparrow.io.Config; +import com.sparrowwallet.sparrow.net.ExchangeSource; import com.sparrowwallet.sparrow.wallet.OptimizationStrategy; import javafx.beans.property.BooleanProperty; import javafx.beans.property.ObjectProperty; @@ -229,6 +227,12 @@ public class TransactionDiagram extends GridPane { getChildren().clear(); getChildren().addAll(inputsTypePane, inputsPane, inputsLinesPane, txPane, outputsLinesPane, outputsPane); + if(!isFinal() && walletTx.getPayments().size() > 1) { + Pane totalsPane = getTotalsPane(); + GridPane.setConstraints(totalsPane, 2, 0, 3, 1); + getChildren().add(totalsPane); + } + if(contextMenu == null) { contextMenu = new ContextMenu(); MenuItem menuItem = new MenuItem("Save as Image..."); @@ -839,6 +843,34 @@ public class TransactionDiagram extends GridPane { return txPane; } + private Pane getTotalsPane() { + VBox totalsBox = new VBox(); + totalsBox.setPadding(new Insets(0, 0, 15, 0)); + totalsBox.setAlignment(Pos.CENTER); + + long amount = walletTx.getPayments().stream().mapToLong(Payment::getAmount).sum(); + long count = walletTx.getPayments().size(); + + HBox coinLabelBox = new HBox(); + coinLabelBox.setAlignment(Pos.CENTER); + CoinLabel totalCoinLabel = new CoinLabel(); + totalCoinLabel.setValue(amount); + coinLabelBox.getChildren().addAll(totalCoinLabel, new Label(" in "), new Label(Long.toString(count)), new Label(" payments")); + totalsBox.getChildren().addAll(createSpacer(), coinLabelBox); + + CurrencyRate currencyRate = AppServices.getFiatCurrencyExchangeRate(); + if(currencyRate != null && currencyRate.isAvailable() && Config.get().getExchangeSource() != ExchangeSource.NONE) { + HBox fiatLabelBox = new HBox(); + fiatLabelBox.setAlignment(Pos.CENTER); + FiatLabel fiatLabel = new FiatLabel(); + fiatLabel.set(currencyRate, amount); + fiatLabelBox.getChildren().add(fiatLabel); + totalsBox.getChildren().add(fiatLabelBox); + } + + return totalsBox; + } + private void saveAsImage() { Stage window = new Stage(); FileChooser fileChooser = new FileChooser(); diff --git a/src/main/java/com/sparrowwallet/sparrow/wallet/SendController.java b/src/main/java/com/sparrowwallet/sparrow/wallet/SendController.java index c3542619..2f2cd848 100644 --- a/src/main/java/com/sparrowwallet/sparrow/wallet/SendController.java +++ b/src/main/java/com/sparrowwallet/sparrow/wallet/SendController.java @@ -981,7 +981,7 @@ public class SendController extends WalletFormController implements Initializabl } private void setFiatFeeAmount(CurrencyRate currencyRate, Long amount) { - if(amount != null && currencyRate != null && currencyRate.isAvailable()) { + if(amount != null && currencyRate != null && currencyRate.isAvailable() && Config.get().getExchangeSource() != ExchangeSource.NONE) { fiatFeeAmount.set(currencyRate, amount); } } @@ -1519,12 +1519,18 @@ public class SendController extends WalletFormController implements Initializabl if(event.getExchangeSource() == ExchangeSource.NONE) { fiatFeeAmount.setCurrency(null); fiatFeeAmount.setBtcRate(0.0); + if(paymentTabs.getTabs().size() > 1) { + updateTransaction(); + } } } @Subscribe public void exchangeRatesUpdated(ExchangeRatesUpdatedEvent event) { setFiatFeeAmount(event.getCurrencyRate(), getFeeValueSats()); + if(paymentTabs.getTabs().size() > 1) { + updateTransaction(); + } } @Subscribe