Skip to content

Commit

Permalink
display effective fee rate next to transaction fee rate when construc…
Browse files Browse the repository at this point in the history
…ting a cpfp tx
  • Loading branch information
craigraw committed Jan 18, 2024
1 parent 1d2081d commit 6fc52fd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
16 changes: 11 additions & 5 deletions src/main/java/com/sparrowwallet/sparrow/wallet/SendController.java
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ public Double fromString(String string) {
});

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()));

Expand All @@ -395,7 +396,6 @@ public Double fromString(String string) {
}

setFeeRate(feeRate);
setEffectiveFeeRate(walletTransaction);
}

transactionDiagram.update(walletTransaction);
Expand Down Expand Up @@ -881,22 +881,27 @@ public boolean isInsufficientFeeRate() {

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);
}
Expand Down Expand Up @@ -1548,6 +1553,7 @@ public void bitcoinUnitChanged(BitcoinUnitChangedEvent event) {

@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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down

0 comments on commit 6fc52fd

Please sign in to comment.