mirror of
https://github.com/haveno-dex/haveno.git
synced 2024-12-26 07:49:31 -05:00
funds tab shows num confirmations per receive address
This commit is contained in:
parent
3da228750f
commit
24a8ecea2b
@ -23,10 +23,20 @@ import bisq.core.btc.wallet.XmrWalletService;
|
|||||||
import bisq.core.locale.Res;
|
import bisq.core.locale.Res;
|
||||||
import bisq.core.util.ParsingUtils;
|
import bisq.core.util.ParsingUtils;
|
||||||
import bisq.core.util.coin.CoinFormatter;
|
import bisq.core.util.coin.CoinFormatter;
|
||||||
|
import bisq.desktop.components.indicator.TxConfidenceIndicator;
|
||||||
|
import bisq.desktop.util.GUIUtil;
|
||||||
|
import com.google.common.base.Supplier;
|
||||||
|
import com.google.common.base.Suppliers;
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
|
import java.util.List;
|
||||||
import javafx.beans.property.SimpleStringProperty;
|
import javafx.beans.property.SimpleStringProperty;
|
||||||
import javafx.beans.property.StringProperty;
|
import javafx.beans.property.StringProperty;
|
||||||
|
import javafx.scene.control.Tooltip;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import monero.daemon.model.MoneroTx;
|
||||||
|
import monero.wallet.model.MoneroTransferQuery;
|
||||||
|
import monero.wallet.model.MoneroTxQuery;
|
||||||
|
import monero.wallet.model.MoneroTxWallet;
|
||||||
import org.bitcoinj.core.Coin;
|
import org.bitcoinj.core.Coin;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@ -38,6 +48,16 @@ class DepositListItem {
|
|||||||
private String usage = "-";
|
private String usage = "-";
|
||||||
private XmrBalanceListener balanceListener;
|
private XmrBalanceListener balanceListener;
|
||||||
private int numTxOutputs = 0;
|
private int numTxOutputs = 0;
|
||||||
|
private final Supplier<LazyFields> lazyFieldsSupplier;
|
||||||
|
|
||||||
|
private static class LazyFields {
|
||||||
|
TxConfidenceIndicator txConfidenceIndicator;
|
||||||
|
Tooltip tooltip;
|
||||||
|
}
|
||||||
|
|
||||||
|
private LazyFields lazy() {
|
||||||
|
return lazyFieldsSupplier.get();
|
||||||
|
}
|
||||||
|
|
||||||
DepositListItem(XmrAddressEntry addressEntry, XmrWalletService xmrWalletService, CoinFormatter formatter) {
|
DepositListItem(XmrAddressEntry addressEntry, XmrWalletService xmrWalletService, CoinFormatter formatter) {
|
||||||
this.xmrWalletService = xmrWalletService;
|
this.xmrWalletService = xmrWalletService;
|
||||||
@ -58,6 +78,22 @@ class DepositListItem {
|
|||||||
balance.set(formatter.formatCoin(balanceAsCoin));
|
balance.set(formatter.formatCoin(balanceAsCoin));
|
||||||
|
|
||||||
updateUsage(addressEntry.getSubaddressIndex());
|
updateUsage(addressEntry.getSubaddressIndex());
|
||||||
|
|
||||||
|
// confidence
|
||||||
|
lazyFieldsSupplier = Suppliers.memoize(() -> new LazyFields() {{
|
||||||
|
txConfidenceIndicator = new TxConfidenceIndicator();
|
||||||
|
txConfidenceIndicator.setId("funds-confidence");
|
||||||
|
tooltip = new Tooltip(Res.get("shared.notUsedYet"));
|
||||||
|
txConfidenceIndicator.setProgress(0);
|
||||||
|
txConfidenceIndicator.setTooltip(tooltip);
|
||||||
|
MoneroTx tx = getTxWithFewestConfirmations();
|
||||||
|
if (tx == null) {
|
||||||
|
txConfidenceIndicator.setVisible(false);
|
||||||
|
} else {
|
||||||
|
GUIUtil.updateConfidence(tx, tooltip, txConfidenceIndicator);
|
||||||
|
txConfidenceIndicator.setVisible(true);
|
||||||
|
}
|
||||||
|
}});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateUsage(int subaddressIndex) {
|
private void updateUsage(int subaddressIndex) {
|
||||||
@ -69,6 +105,10 @@ class DepositListItem {
|
|||||||
xmrWalletService.removeBalanceListener(balanceListener);
|
xmrWalletService.removeBalanceListener(balanceListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TxConfidenceIndicator getTxConfidenceIndicator() {
|
||||||
|
return lazy().txConfidenceIndicator;
|
||||||
|
}
|
||||||
|
|
||||||
public String getAddressString() {
|
public String getAddressString() {
|
||||||
return addressEntry.getAddressString();
|
return addressEntry.getAddressString();
|
||||||
}
|
}
|
||||||
@ -93,7 +133,23 @@ class DepositListItem {
|
|||||||
return numTxOutputs;
|
return numTxOutputs;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getNumConfirmationsSinceFirstUsed() {
|
public long getNumConfirmationsSinceFirstUsed() {
|
||||||
throw new RuntimeException("Not implemented");
|
MoneroTx tx = getTxWithFewestConfirmations();
|
||||||
|
return tx == null ? 0 : tx.getNumConfirmations();
|
||||||
|
}
|
||||||
|
|
||||||
|
private MoneroTxWallet getTxWithFewestConfirmations() {
|
||||||
|
|
||||||
|
// get txs with incoming transfers to subaddress
|
||||||
|
List<MoneroTxWallet> txs = xmrWalletService.getWallet()
|
||||||
|
.getTxs(new MoneroTxQuery()
|
||||||
|
.setTransferQuery(new MoneroTransferQuery()
|
||||||
|
.setIsIncoming(true)
|
||||||
|
.setSubaddressIndex(addressEntry.getSubaddressIndex())));
|
||||||
|
|
||||||
|
// get tx with fewest confirmations
|
||||||
|
MoneroTxWallet highestTx = null;
|
||||||
|
for (MoneroTxWallet tx : txs) if (highestTx == null || tx.getNumConfirmations() < highestTx.getNumConfirmations()) highestTx = tx;
|
||||||
|
return highestTx;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -155,7 +155,7 @@ public class DepositView extends ActivatableView<VBox, Void> {
|
|||||||
|
|
||||||
addressColumn.setComparator(Comparator.comparing(DepositListItem::getAddressString));
|
addressColumn.setComparator(Comparator.comparing(DepositListItem::getAddressString));
|
||||||
balanceColumn.setComparator(Comparator.comparing(DepositListItem::getBalanceAsCoin));
|
balanceColumn.setComparator(Comparator.comparing(DepositListItem::getBalanceAsCoin));
|
||||||
confirmationsColumn.setComparator(Comparator.comparingInt(o -> o.getNumConfirmationsSinceFirstUsed()));
|
confirmationsColumn.setComparator(Comparator.comparingLong(o -> o.getNumConfirmationsSinceFirstUsed()));
|
||||||
usageColumn.setComparator(Comparator.comparingInt(DepositListItem::getNumTxOutputs));
|
usageColumn.setComparator(Comparator.comparingInt(DepositListItem::getNumTxOutputs));
|
||||||
tableView.getSortOrder().add(usageColumn);
|
tableView.getSortOrder().add(usageColumn);
|
||||||
tableView.setItems(sortedList);
|
tableView.setItems(sortedList);
|
||||||
@ -422,7 +422,7 @@ public class DepositView extends ActivatableView<VBox, Void> {
|
|||||||
super.updateItem(item, empty);
|
super.updateItem(item, empty);
|
||||||
|
|
||||||
if (item != null && !empty) {
|
if (item != null && !empty) {
|
||||||
//setGraphic(item.getTxConfidenceIndicator());
|
setGraphic(item.getTxConfidenceIndicator());
|
||||||
} else {
|
} else {
|
||||||
setGraphic(null);
|
setGraphic(null);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user