diff --git a/src/main/java/com/sparrowwallet/sparrow/control/EntryCell.java b/src/main/java/com/sparrowwallet/sparrow/control/EntryCell.java index cf3fc4d2..efa7d0e3 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/EntryCell.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/EntryCell.java @@ -36,7 +36,7 @@ public class EntryCell extends TreeTableCell implements Confirmati private static final Logger log = LoggerFactory.getLogger(EntryCell.class); public static final DateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm"); - private static final Pattern REPLACED_BY_FEE_SUFFIX = Pattern.compile("(.*)\\(Replaced By Fee( #)?(\\d+)?\\).*"); + public static final Pattern REPLACED_BY_FEE_SUFFIX = Pattern.compile("(.*?)( \\(Replaced By Fee( #)?(\\d+)?\\)).*?"); private static EntryCell lastCell; @@ -263,17 +263,21 @@ public class EntryCell extends TreeTableCell implements Confirmati List payments = externalOutputs.stream().map(txOutput -> { try { String label = transactionEntry.getLabel() == null ? "" : transactionEntry.getLabel(); - Matcher matcher = REPLACED_BY_FEE_SUFFIX.matcher(label); + label = REPLACED_BY_FEE_SUFFIX.matcher(label).replaceAll("$1"); + String[] paymentLabels = label.split(", "); + if(externalOutputs.size() > 1 && externalOutputs.size() == paymentLabels.length) { + label = paymentLabels[externalOutputs.indexOf(txOutput)]; + } + Matcher matcher = REPLACED_BY_FEE_SUFFIX.matcher(transactionEntry.getLabel() == null ? "" : transactionEntry.getLabel()); if(matcher.matches()) { - String base = matcher.group(1); if(matcher.groupCount() > 2 && matcher.group(3) != null) { int count = Integer.parseInt(matcher.group(3)) + 1; - label = base + "(Replaced By Fee #" + count + ")"; + label += " (Replaced By Fee #" + count + ")"; } else { - label = base + "(Replaced By Fee #2)"; + label += " (Replaced By Fee #2)"; } } else { - label += (label.isEmpty() ? "" : " ") + "(Replaced By Fee)"; + label += " (Replaced By Fee)"; } if(txOutput.getScript().getToAddress() != null) { diff --git a/src/main/java/com/sparrowwallet/sparrow/transaction/HeadersController.java b/src/main/java/com/sparrowwallet/sparrow/transaction/HeadersController.java index 43848f5b..fbe230bd 100644 --- a/src/main/java/com/sparrowwallet/sparrow/transaction/HeadersController.java +++ b/src/main/java/com/sparrowwallet/sparrow/transaction/HeadersController.java @@ -1507,6 +1507,13 @@ public class HeadersController extends TransactionFormController implements Init StringJoiner joiner = new StringJoiner(", "); outputIndexLabels.values().forEach(joiner::add); name = joiner.toString(); + + Matcher matcher = EntryCell.REPLACED_BY_FEE_SUFFIX.matcher(name); + name = matcher.replaceAll("$1"); + matcher.reset(); + if(matcher.find()) { + name += matcher.group(2); + } } blockTransaction.setLabel(name != null && name.length() > 255 ? name.substring(0, 255) : name); changedLabelEntries.add(new TransactionEntry(event.getWallet(), blockTransaction, Collections.emptyMap(), Collections.emptyMap()));