Skip to content

Commit c078aea

Browse files
committed
show total in transaction diagram when constructing multiple payment transactions
1 parent af4a283 commit c078aea

File tree

2 files changed

+43
-5
lines changed

2 files changed

+43
-5
lines changed

src/main/java/com/sparrowwallet/sparrow/control/TransactionDiagram.java

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,13 @@
88
import com.sparrowwallet.drongo.protocol.TransactionOutput;
99
import com.sparrowwallet.drongo.uri.BitcoinURI;
1010
import com.sparrowwallet.drongo.wallet.*;
11-
import com.sparrowwallet.sparrow.UnitFormat;
12-
import com.sparrowwallet.sparrow.AppServices;
13-
import com.sparrowwallet.sparrow.EventManager;
14-
import com.sparrowwallet.sparrow.Theme;
11+
import com.sparrowwallet.sparrow.*;
1512
import com.sparrowwallet.sparrow.event.ExcludeUtxoEvent;
1613
import com.sparrowwallet.sparrow.event.ReplaceChangeAddressEvent;
1714
import com.sparrowwallet.sparrow.glyphfont.FontAwesome5;
1815
import com.sparrowwallet.sparrow.glyphfont.GlyphUtils;
1916
import com.sparrowwallet.sparrow.io.Config;
17+
import com.sparrowwallet.sparrow.net.ExchangeSource;
2018
import com.sparrowwallet.sparrow.wallet.OptimizationStrategy;
2119
import javafx.beans.property.BooleanProperty;
2220
import javafx.beans.property.ObjectProperty;
@@ -229,6 +227,12 @@ public void update() {
229227
getChildren().clear();
230228
getChildren().addAll(inputsTypePane, inputsPane, inputsLinesPane, txPane, outputsLinesPane, outputsPane);
231229

230+
if(!isFinal() && walletTx.getPayments().size() > 1) {
231+
Pane totalsPane = getTotalsPane();
232+
GridPane.setConstraints(totalsPane, 2, 0, 3, 1);
233+
getChildren().add(totalsPane);
234+
}
235+
232236
if(contextMenu == null) {
233237
contextMenu = new ContextMenu();
234238
MenuItem menuItem = new MenuItem("Save as Image...");
@@ -839,6 +843,34 @@ private Pane getTransactionPane() {
839843
return txPane;
840844
}
841845

846+
private Pane getTotalsPane() {
847+
VBox totalsBox = new VBox();
848+
totalsBox.setPadding(new Insets(0, 0, 15, 0));
849+
totalsBox.setAlignment(Pos.CENTER);
850+
851+
long amount = walletTx.getPayments().stream().mapToLong(Payment::getAmount).sum();
852+
long count = walletTx.getPayments().size();
853+
854+
HBox coinLabelBox = new HBox();
855+
coinLabelBox.setAlignment(Pos.CENTER);
856+
CoinLabel totalCoinLabel = new CoinLabel();
857+
totalCoinLabel.setValue(amount);
858+
coinLabelBox.getChildren().addAll(totalCoinLabel, new Label(" in "), new Label(Long.toString(count)), new Label(" payments"));
859+
totalsBox.getChildren().addAll(createSpacer(), coinLabelBox);
860+
861+
CurrencyRate currencyRate = AppServices.getFiatCurrencyExchangeRate();
862+
if(currencyRate != null && currencyRate.isAvailable() && Config.get().getExchangeSource() != ExchangeSource.NONE) {
863+
HBox fiatLabelBox = new HBox();
864+
fiatLabelBox.setAlignment(Pos.CENTER);
865+
FiatLabel fiatLabel = new FiatLabel();
866+
fiatLabel.set(currencyRate, amount);
867+
fiatLabelBox.getChildren().add(fiatLabel);
868+
totalsBox.getChildren().add(fiatLabelBox);
869+
}
870+
871+
return totalsBox;
872+
}
873+
842874
private void saveAsImage() {
843875
Stage window = new Stage();
844876
FileChooser fileChooser = new FileChooser();

src/main/java/com/sparrowwallet/sparrow/wallet/SendController.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -981,7 +981,7 @@ private Node getSliderThumb() {
981981
}
982982

983983
private void setFiatFeeAmount(CurrencyRate currencyRate, Long amount) {
984-
if(amount != null && currencyRate != null && currencyRate.isAvailable()) {
984+
if(amount != null && currencyRate != null && currencyRate.isAvailable() && Config.get().getExchangeSource() != ExchangeSource.NONE) {
985985
fiatFeeAmount.set(currencyRate, amount);
986986
}
987987
}
@@ -1519,12 +1519,18 @@ public void fiatCurrencySelected(FiatCurrencySelectedEvent event) {
15191519
if(event.getExchangeSource() == ExchangeSource.NONE) {
15201520
fiatFeeAmount.setCurrency(null);
15211521
fiatFeeAmount.setBtcRate(0.0);
1522+
if(paymentTabs.getTabs().size() > 1) {
1523+
updateTransaction();
1524+
}
15221525
}
15231526
}
15241527

15251528
@Subscribe
15261529
public void exchangeRatesUpdated(ExchangeRatesUpdatedEvent event) {
15271530
setFiatFeeAmount(event.getCurrencyRate(), getFeeValueSats());
1531+
if(paymentTabs.getTabs().size() > 1) {
1532+
updateTransaction();
1533+
}
15281534
}
15291535

15301536
@Subscribe

0 commit comments

Comments
 (0)