mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-12-25 21:26:43 +00:00
fix order of outputs displayed in transaction diagram where there are multiple payments with the same address and amount
This commit is contained in:
parent
b5196d1ac2
commit
3162371838
1 changed files with 16 additions and 18 deletions
|
@ -720,6 +720,7 @@ public class TransactionDiagram extends GridPane {
|
||||||
outputNodes.add(new OutputNode(paymentBox, payment.getAddress(), payment.getAmount()));
|
outputNodes.add(new OutputNode(paymentBox, payment.getAddress(), payment.getAmount()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Set<Integer> seenIndexes = new HashSet<>();
|
||||||
for(Map.Entry<WalletNode, Long> changeEntry : walletTx.getChangeMap().entrySet()) {
|
for(Map.Entry<WalletNode, Long> changeEntry : walletTx.getChangeMap().entrySet()) {
|
||||||
WalletNode changeNode = changeEntry.getKey();
|
WalletNode changeNode = changeEntry.getKey();
|
||||||
WalletNode defaultChangeNode = walletTx.getWallet().getFreshNode(KeyPurpose.CHANGE);
|
WalletNode defaultChangeNode = walletTx.getWallet().getFreshNode(KeyPurpose.CHANGE);
|
||||||
|
@ -765,11 +766,15 @@ public class TransactionDiagram extends GridPane {
|
||||||
actionBox.getChildren().addAll(region, amountLabel);
|
actionBox.getChildren().addAll(region, amountLabel);
|
||||||
}
|
}
|
||||||
|
|
||||||
outputNodes.add(new OutputNode(actionBox, changeAddress, changeEntry.getValue()));
|
int changeIndex = outputNodes.size();
|
||||||
}
|
|
||||||
|
|
||||||
if(isFinal()) {
|
if(isFinal()) {
|
||||||
Collections.sort(outputNodes);
|
changeIndex = getOutputIndex(changeAddress, changeEntry.getValue(), seenIndexes);
|
||||||
|
seenIndexes.add(changeIndex);
|
||||||
|
if(changeIndex > outputNodes.size()) {
|
||||||
|
changeIndex = outputNodes.size();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
outputNodes.add(changeIndex, new OutputNode(actionBox, changeAddress, changeEntry.getValue()));
|
||||||
}
|
}
|
||||||
|
|
||||||
for(OutputNode outputNode : outputNodes) {
|
for(OutputNode outputNode : outputNodes) {
|
||||||
|
@ -931,7 +936,7 @@ public class TransactionDiagram extends GridPane {
|
||||||
if(payment.getType() == Payment.Type.WHIRLPOOL_FEE) {
|
if(payment.getType() == Payment.Type.WHIRLPOOL_FEE) {
|
||||||
return "Whirlpool fee";
|
return "Whirlpool fee";
|
||||||
} else if(walletTx.isPremixSend(payment)) {
|
} else if(walletTx.isPremixSend(payment)) {
|
||||||
int premixIndex = getOutputIndex(payment.getAddress(), payment.getAmount()) - 2;
|
int premixIndex = getOutputIndex(payment.getAddress(), payment.getAmount(), Collections.emptySet()) - 1;
|
||||||
return "Premix #" + premixIndex;
|
return "Premix #" + premixIndex;
|
||||||
} else if(walletTx.isBadbankSend(payment)) {
|
} else if(walletTx.isBadbankSend(payment)) {
|
||||||
return "Badbank change";
|
return "Badbank change";
|
||||||
|
@ -940,8 +945,10 @@ public class TransactionDiagram extends GridPane {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getOutputIndex(Address address, long amount) {
|
private int getOutputIndex(Address address, long amount, Collection<Integer> seenIndexes) {
|
||||||
return walletTx.getTransaction().getOutputs().stream().filter(txOutput -> address.equals(txOutput.getScript().getToAddress()) && txOutput.getValue() == amount).mapToInt(TransactionOutput::getIndex).findFirst().orElseThrow();
|
List<TransactionOutput> addressOutputs = walletTx.getTransaction().getOutputs().stream().filter(txOutput -> txOutput.getScript().getToAddress() != null).collect(Collectors.toList());
|
||||||
|
TransactionOutput output = addressOutputs.stream().filter(txOutput -> address.equals(txOutput.getScript().getToAddress()) && txOutput.getValue() == amount && !seenIndexes.contains(txOutput.getIndex())).findFirst().orElseThrow();
|
||||||
|
return addressOutputs.indexOf(output);
|
||||||
}
|
}
|
||||||
|
|
||||||
Wallet getToWallet(Payment payment) {
|
Wallet getToWallet(Payment payment) {
|
||||||
|
@ -1315,7 +1322,7 @@ public class TransactionDiagram extends GridPane {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class OutputNode implements Comparable<OutputNode> {
|
private static class OutputNode {
|
||||||
public Pane outputLabel;
|
public Pane outputLabel;
|
||||||
public Address address;
|
public Address address;
|
||||||
public long amount;
|
public long amount;
|
||||||
|
@ -1325,15 +1332,6 @@ public class TransactionDiagram extends GridPane {
|
||||||
this.address = address;
|
this.address = address;
|
||||||
this.amount = amount;
|
this.amount = amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int compareTo(TransactionDiagram.OutputNode o) {
|
|
||||||
try {
|
|
||||||
return getOutputIndex(address, amount) - getOutputIndex(o.address, o.amount);
|
|
||||||
} catch(Exception e) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class LabelContextMenu extends ContextMenu {
|
private class LabelContextMenu extends ContextMenu {
|
||||||
|
|
Loading…
Reference in a new issue