mirror of
https://github.com/bisq-network/bisq.git
synced 2025-02-23 15:00:30 +01:00
Short circuit confidence updates in DepositListItem
Add a 'lazyFields' volatile field to DepositListItem to detect initialisation of the associated memoised 'LazyFields' supplier, allowing confidence updates to be short-circuited when the corresponding indicator has not yet been lazily loaded. This is for consistency with the 'LazyFields' logic just added to TxConfidenceListItem and should make the UI more responsive if a new block arrives when the funds deposit list is in view, by avoiding the entire list of item tooltips & confidence indicators from being force- initialised.
This commit is contained in:
parent
04fae6d81e
commit
76c2781505
1 changed files with 16 additions and 8 deletions
|
@ -53,10 +53,11 @@ class DepositListItem implements FilterableListItem {
|
||||||
private Coin balanceAsCoin;
|
private Coin balanceAsCoin;
|
||||||
private final String addressString;
|
private final String addressString;
|
||||||
private String usage = "-";
|
private String usage = "-";
|
||||||
private TxConfidenceListener txConfidenceListener;
|
private final TxConfidenceListener txConfidenceListener;
|
||||||
private BalanceListener balanceListener;
|
private final BalanceListener balanceListener;
|
||||||
private int numTxOutputs = 0;
|
private int numTxOutputs = 0;
|
||||||
private final Supplier<LazyFields> lazyFieldsSupplier;
|
private final Supplier<LazyFields> lazyFieldsSupplier;
|
||||||
|
private volatile LazyFields lazyFields;
|
||||||
|
|
||||||
private static class LazyFields {
|
private static class LazyFields {
|
||||||
TxConfidenceIndicator txConfidenceIndicator;
|
TxConfidenceIndicator txConfidenceIndicator;
|
||||||
|
@ -82,19 +83,21 @@ class DepositListItem implements FilterableListItem {
|
||||||
tooltip = new Tooltip(Res.get("shared.notUsedYet"));
|
tooltip = new Tooltip(Res.get("shared.notUsedYet"));
|
||||||
txConfidenceIndicator.setProgress(0);
|
txConfidenceIndicator.setProgress(0);
|
||||||
txConfidenceIndicator.setTooltip(tooltip);
|
txConfidenceIndicator.setTooltip(tooltip);
|
||||||
if (confidence != null) {
|
|
||||||
GUIUtil.updateConfidence(confidence, tooltip, txConfidenceIndicator);
|
lazyFields = this;
|
||||||
}
|
updateConfidence(confidence);
|
||||||
}});
|
}});
|
||||||
|
|
||||||
if (confidence != null) {
|
if (confidence != null) {
|
||||||
txConfidenceListener = new TxConfidenceListener(confidence.getTransactionHash().toString()) {
|
txConfidenceListener = new TxConfidenceListener(confidence.getTransactionHash().toString()) {
|
||||||
@Override
|
@Override
|
||||||
public void onTransactionConfidenceChanged(TransactionConfidence confidence) {
|
public void onTransactionConfidenceChanged(TransactionConfidence confidence) {
|
||||||
GUIUtil.updateConfidence(confidence, lazy().tooltip, lazy().txConfidenceIndicator);
|
updateConfidence(confidence);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
walletService.addTxConfidenceListener(txConfidenceListener);
|
walletService.addTxConfidenceListener(txConfidenceListener);
|
||||||
|
} else {
|
||||||
|
txConfidenceListener = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
balanceListener = new BalanceListener(address) {
|
balanceListener = new BalanceListener(address) {
|
||||||
|
@ -102,8 +105,7 @@ class DepositListItem implements FilterableListItem {
|
||||||
public void onBalanceChanged(Coin balanceAsCoin, Transaction tx) {
|
public void onBalanceChanged(Coin balanceAsCoin, Transaction tx) {
|
||||||
DepositListItem.this.balanceAsCoin = balanceAsCoin;
|
DepositListItem.this.balanceAsCoin = balanceAsCoin;
|
||||||
DepositListItem.this.balance.set(formatter.formatCoin(balanceAsCoin));
|
DepositListItem.this.balance.set(formatter.formatCoin(balanceAsCoin));
|
||||||
var confidence = walletService.getConfidenceForTxId(tx.getTxId().toString());
|
updateConfidence(walletService.getConfidenceForTxId(tx.getTxId().toString()));
|
||||||
GUIUtil.updateConfidence(confidence, lazy().tooltip, lazy().txConfidenceIndicator);
|
|
||||||
updateUsage(address);
|
updateUsage(address);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -115,6 +117,12 @@ class DepositListItem implements FilterableListItem {
|
||||||
updateUsage(address);
|
updateUsage(address);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateConfidence(TransactionConfidence confidence) {
|
||||||
|
if (confidence != null && lazyFields != null) {
|
||||||
|
GUIUtil.updateConfidence(confidence, lazyFields.tooltip, lazyFields.txConfidenceIndicator);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void updateUsage(Address address) {
|
private void updateUsage(Address address) {
|
||||||
numTxOutputs = walletService.getNumTxOutputsForAddress(address);
|
numTxOutputs = walletService.getNumTxOutputsForAddress(address);
|
||||||
usage = numTxOutputs == 0 ? Res.get("funds.deposit.unused") : Res.get("funds.deposit.usedInTx", numTxOutputs);
|
usage = numTxOutputs == 0 ? Res.get("funds.deposit.unused") : Res.get("funds.deposit.usedInTx", numTxOutputs);
|
||||||
|
|
Loading…
Add table
Reference in a new issue