only show cpfp rate if child fee increases effective fee rate

This commit is contained in:
Craig Raw 2025-01-14 10:44:53 +02:00
parent 25f441a6a8
commit 947013e088

View file

@ -877,12 +877,14 @@ public class SendController extends WalletFormController implements Initializabl
walletTransaction.getSelectedUtxos().keySet().stream().filter(ref -> ref.getHeight() <= 0) walletTransaction.getSelectedUtxos().keySet().stream().filter(ref -> ref.getHeight() <= 0)
.map(ref -> getWalletForm().getWallet().getWalletTransaction(ref.getHash())) .map(ref -> getWalletForm().getWallet().getWalletTransaction(ref.getHash()))
.filter(Objects::nonNull).distinct().collect(Collectors.toList()); .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(); long utxoTxFee = unconfirmedUtxoTxs.stream().mapToLong(BlockTransaction::getFee).sum();
double utxoTxSize = unconfirmedUtxoTxs.stream().mapToDouble(blkTx -> blkTx.getTransaction().getVirtualSize()).sum(); double utxoTxSize = unconfirmedUtxoTxs.stream().mapToDouble(blkTx -> blkTx.getTransaction().getVirtualSize()).sum();
long thisFee = walletTransaction.getFee(); long thisFee = walletTransaction.getFee();
double thisSize = walletTransaction.getTransaction().getVirtualSize(); double thisSize = walletTransaction.getTransaction().getVirtualSize();
double thisRate = thisFee / thisSize;
double effectiveRate = (utxoTxFee + thisFee) / (utxoTxSize + thisSize); double effectiveRate = (utxoTxFee + thisFee) / (utxoTxSize + thisSize);
if(thisRate > effectiveRate) {
UnitFormat format = Config.get().getUnitFormat() == null ? UnitFormat.DOT : Config.get().getUnitFormat(); UnitFormat format = Config.get().getUnitFormat() == null ? UnitFormat.DOT : Config.get().getUnitFormat();
String strEffectiveRate = format.getCurrencyFormat().format(effectiveRate); String strEffectiveRate = format.getCurrencyFormat().format(effectiveRate);
Tooltip tooltip = new Tooltip("CPFP (Child Pays For Parent)\n" + strEffectiveRate + " sats/vB effective rate"); Tooltip tooltip = new Tooltip("CPFP (Child Pays For Parent)\n" + strEffectiveRate + " sats/vB effective rate");
@ -892,6 +894,9 @@ public class SendController extends WalletFormController implements Initializabl
} else { } else {
cpfpFeeRate.setVisible(false); cpfpFeeRate.setVisible(false);
} }
} else {
cpfpFeeRate.setVisible(false);
}
} }
private void setFeeRatePriority(Double feeRateAmt) { private void setFeeRatePriority(Double feeRateAmt) {