From 947013e088d063b32d3bccea5da634570a80edb6 Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Tue, 14 Jan 2025 10:44:53 +0200 Subject: [PATCH] only show cpfp rate if child fee increases effective fee rate --- .../sparrow/wallet/SendController.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/sparrowwallet/sparrow/wallet/SendController.java b/src/main/java/com/sparrowwallet/sparrow/wallet/SendController.java index b727e7f9..3cb46668 100644 --- a/src/main/java/com/sparrowwallet/sparrow/wallet/SendController.java +++ b/src/main/java/com/sparrowwallet/sparrow/wallet/SendController.java @@ -877,18 +877,23 @@ public class SendController extends WalletFormController implements Initializabl walletTransaction.getSelectedUtxos().keySet().stream().filter(ref -> ref.getHeight() <= 0) .map(ref -> getWalletForm().getWallet().getWalletTransaction(ref.getHash())) .filter(Objects::nonNull).distinct().collect(Collectors.toList()); - if(!unconfirmedUtxoTxs.isEmpty()) { + if(!unconfirmedUtxoTxs.isEmpty() && unconfirmedUtxoTxs.stream().allMatch(blkTx -> blkTx.getFee() != null && blkTx.getFee() > 0)) { long utxoTxFee = unconfirmedUtxoTxs.stream().mapToLong(BlockTransaction::getFee).sum(); double utxoTxSize = unconfirmedUtxoTxs.stream().mapToDouble(blkTx -> blkTx.getTransaction().getVirtualSize()).sum(); long thisFee = walletTransaction.getFee(); double thisSize = walletTransaction.getTransaction().getVirtualSize(); + double thisRate = thisFee / thisSize; double effectiveRate = (utxoTxFee + thisFee) / (utxoTxSize + thisSize); - UnitFormat format = Config.get().getUnitFormat() == null ? UnitFormat.DOT : Config.get().getUnitFormat(); - String strEffectiveRate = format.getCurrencyFormat().format(effectiveRate); - Tooltip tooltip = new Tooltip("CPFP (Child Pays For Parent)\n" + strEffectiveRate + " sats/vB effective rate"); - cpfpFeeRate.setTooltip(tooltip); - cpfpFeeRate.setVisible(true); - cpfpFeeRate.setText(strEffectiveRate + " sats/vB (CPFP)"); + if(thisRate > effectiveRate) { + UnitFormat format = Config.get().getUnitFormat() == null ? UnitFormat.DOT : Config.get().getUnitFormat(); + String strEffectiveRate = format.getCurrencyFormat().format(effectiveRate); + Tooltip tooltip = new Tooltip("CPFP (Child Pays For Parent)\n" + strEffectiveRate + " sats/vB effective rate"); + cpfpFeeRate.setTooltip(tooltip); + cpfpFeeRate.setVisible(true); + cpfpFeeRate.setText(strEffectiveRate + " sats/vB (CPFP)"); + } else { + cpfpFeeRate.setVisible(false); + } } else { cpfpFeeRate.setVisible(false); }