display effective fee rate next to transaction fee rate when constructing a cpfp tx

This commit is contained in:
Craig Raw 2024-01-18 09:53:44 +02:00
parent 1d2081d2a6
commit 6fc52fdc0e
2 changed files with 12 additions and 6 deletions

View file

@ -382,6 +382,7 @@ public class SendController extends WalletFormController implements Initializabl
});
walletTransactionProperty.addListener((observable, oldValue, walletTransaction) -> {
setEffectiveFeeRate(walletTransaction);
if(walletTransaction != null) {
setPayments(walletTransaction.getPayments().stream().filter(payment -> payment.getType() != Payment.Type.FAKE_MIX).collect(Collectors.toList()));
@ -395,7 +396,6 @@ public class SendController extends WalletFormController implements Initializabl
}
setFeeRate(feeRate);
setEffectiveFeeRate(walletTransaction);
}
transactionDiagram.update(walletTransaction);
@ -881,22 +881,27 @@ public class SendController extends WalletFormController implements Initializabl
private void setFeeRate(Double feeRateAmt) {
UnitFormat format = Config.get().getUnitFormat() == null ? UnitFormat.DOT : Config.get().getUnitFormat();
feeRate.setText(format.getCurrencyFormat().format(feeRateAmt) + " sats/vB");
feeRate.setText(format.getCurrencyFormat().format(feeRateAmt) + (cpfpFeeRate.isVisible() ? "" : " sats/vB"));
setFeeRatePriority(feeRateAmt);
}
private void setEffectiveFeeRate(WalletTransaction walletTransaction) {
List<BlockTransaction> unconfirmedUtxoTxs = walletTransaction.getSelectedUtxos().keySet().stream().filter(ref -> ref.getHeight() <= 0)
.map(ref -> getWalletForm().getWallet().getWalletTransaction(ref.getHash())).filter(Objects::nonNull).distinct().collect(Collectors.toList());
List<BlockTransaction> unconfirmedUtxoTxs = walletTransaction == null ? Collections.emptyList() :
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()) {
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 effectiveRate = (utxoTxFee + thisFee) / (utxoTxSize + thisSize);
Tooltip tooltip = new Tooltip("Child Pays For Parent\n" + String.format("%.2f", effectiveRate) + " sats/vB effective rate");
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);
}
@ -1548,6 +1553,7 @@ public class SendController extends WalletFormController implements Initializabl
@Subscribe
public void unitFormatChanged(UnitFormatChangedEvent event) {
setEffectiveFeeRate(getWalletTransaction());
setFeeRate(getFeeRate());
if(fee.getTextFormatter() instanceof CoinTextFormatter coinTextFormatter && coinTextFormatter.getUnitFormat() != event.getUnitFormat()) {
Long value = getFeeValueSats(coinTextFormatter.getUnitFormat(), feeAmountUnit.getSelectionModel().getSelectedItem());

View file

@ -98,7 +98,7 @@
<Glyph fontFamily="Font Awesome 5 Free Solid" fontSize="12" icon="SIGN_OUT_ALT" />
</graphic>
<padding>
<Insets left="10"/>
<Insets left="4"/>
</padding>
</Label>
<Region HBox.hgrow="ALWAYS" />