mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-11-04 21:36:45 +00:00
update utxo fiat balances as rates change
This commit is contained in:
parent
468384d82a
commit
5e31cdb7ac
2 changed files with 27 additions and 2 deletions
|
@ -18,6 +18,7 @@ import com.sparrowwallet.sparrow.event.*;
|
|||
import com.sparrowwallet.sparrow.glyphfont.FontAwesome5;
|
||||
import com.sparrowwallet.sparrow.io.Config;
|
||||
import com.sparrowwallet.sparrow.io.Storage;
|
||||
import com.sparrowwallet.sparrow.net.ExchangeSource;
|
||||
import com.sparrowwallet.sparrow.whirlpool.Whirlpool;
|
||||
import com.sparrowwallet.sparrow.whirlpool.WhirlpoolDialog;
|
||||
import com.sparrowwallet.sparrow.whirlpool.WhirlpoolServices;
|
||||
|
@ -186,8 +187,8 @@ public class UtxosController extends WalletFormController implements Initializab
|
|||
}
|
||||
|
||||
private void updateFields(WalletUtxosEntry walletUtxosEntry) {
|
||||
balance.setValue(walletUtxosEntry.getChildren().stream().mapToLong(Entry::getValue).sum());
|
||||
mempoolBalance.setValue(walletUtxosEntry.getChildren().stream().filter(entry -> ((UtxoEntry)entry).getHashIndex().getHeight() <= 0).mapToLong(Entry::getValue).sum());
|
||||
balance.setValue(walletUtxosEntry.getBalance());
|
||||
mempoolBalance.setValue(walletUtxosEntry.getMempoolBalance());
|
||||
utxoCount.setText(walletUtxosEntry.getChildren() != null ? Integer.toString(walletUtxosEntry.getChildren().size()) : "0");
|
||||
}
|
||||
|
||||
|
@ -612,4 +613,20 @@ public class UtxosController extends WalletFormController implements Initializab
|
|||
selectEntry(utxosTable, utxosTable.getRoot(), event.getEntry());
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void fiatCurrencySelected(FiatCurrencySelectedEvent event) {
|
||||
if(event.getExchangeSource() == ExchangeSource.NONE) {
|
||||
fiatBalance.setCurrency(null);
|
||||
fiatBalance.setBtcRate(0.0);
|
||||
fiatMempoolBalance.setCurrency(null);
|
||||
fiatMempoolBalance.setBtcRate(0.0);
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void exchangeRatesUpdated(ExchangeRatesUpdatedEvent event) {
|
||||
setFiatBalance(fiatBalance, event.getCurrencyRate(), getWalletForm().getWalletUtxosEntry().getBalance());
|
||||
setFiatBalance(fiatMempoolBalance, event.getCurrencyRate(), getWalletForm().getWalletUtxosEntry().getMempoolBalance());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -76,4 +76,12 @@ public class WalletUtxosEntry extends Entry {
|
|||
calculateDuplicates();
|
||||
updateMixProgress();
|
||||
}
|
||||
|
||||
public long getBalance() {
|
||||
return getChildren().stream().mapToLong(Entry::getValue).sum();
|
||||
}
|
||||
|
||||
public long getMempoolBalance() {
|
||||
return getChildren().stream().filter(entry -> ((UtxoEntry)entry).getHashIndex().getHeight() <= 0).mapToLong(Entry::getValue).sum();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue