fix npe in terminal for exchange rate updates without a btc rate

This commit is contained in:
Craig Raw 2022-10-29 08:33:55 +02:00
parent e2795c7ef3
commit 96c88b7472
3 changed files with 14 additions and 10 deletions

View file

@ -95,8 +95,8 @@ public class TransactionsDialog extends WalletDialog {
mempoolBalance.setText(formatBitcoinValue(walletTransactionsEntry.getMempoolBalance(), true));
if(AppServices.getFiatCurrencyExchangeRate() != null) {
fiatBalance.setText(formatFiatValue(getFiatValue(walletTransactionsEntry.getBalance(), AppServices.getFiatCurrencyExchangeRate().getBtcRate())));
fiatMempoolBalance.setText(formatFiatValue(getFiatValue(walletTransactionsEntry.getMempoolBalance(), AppServices.getFiatCurrencyExchangeRate().getBtcRate())));
fiatBalance.setText(formatFiatValue(getFiatValue(walletTransactionsEntry.getBalance(), AppServices.getFiatCurrencyExchangeRate())));
fiatMempoolBalance.setText(formatFiatValue(getFiatValue(walletTransactionsEntry.getMempoolBalance(), AppServices.getFiatCurrencyExchangeRate())));
} else {
fiatBalance.setText("");
fiatMempoolBalance.setText("");
@ -149,8 +149,8 @@ public class TransactionsDialog extends WalletDialog {
public void exchangeRatesUpdated(ExchangeRatesUpdatedEvent event) {
SparrowTerminal.get().getGuiThread().invokeLater(() -> {
WalletTransactionsEntry walletTransactionsEntry = getWalletForm().getWalletTransactionsEntry();
fiatBalance.setText(formatFiatValue(getFiatValue(walletTransactionsEntry.getBalance(), event.getBtcRate())));
fiatMempoolBalance.setText(formatFiatValue(getFiatValue(walletTransactionsEntry.getMempoolBalance(), event.getBtcRate())));
fiatBalance.setText(formatFiatValue(getFiatValue(walletTransactionsEntry.getBalance(), event.getCurrencyRate())));
fiatMempoolBalance.setText(formatFiatValue(getFiatValue(walletTransactionsEntry.getMempoolBalance(), event.getCurrencyRate())));
});
}
}

View file

@ -191,8 +191,8 @@ public class UtxosDialog extends WalletDialog {
mempoolBalance.setText(formatBitcoinValue(walletUtxosEntry.getMempoolBalance(), true));
if(AppServices.getFiatCurrencyExchangeRate() != null) {
fiatBalance.setText(formatFiatValue(getFiatValue(walletUtxosEntry.getBalance(), AppServices.getFiatCurrencyExchangeRate().getBtcRate())));
fiatMempoolBalance.setText(formatFiatValue(getFiatValue(walletUtxosEntry.getMempoolBalance(), AppServices.getFiatCurrencyExchangeRate().getBtcRate())));
fiatBalance.setText(formatFiatValue(getFiatValue(walletUtxosEntry.getBalance(), AppServices.getFiatCurrencyExchangeRate())));
fiatMempoolBalance.setText(formatFiatValue(getFiatValue(walletUtxosEntry.getMempoolBalance(), AppServices.getFiatCurrencyExchangeRate())));
} else {
fiatBalance.setText("");
fiatMempoolBalance.setText("");
@ -405,8 +405,8 @@ public class UtxosDialog extends WalletDialog {
public void exchangeRatesUpdated(ExchangeRatesUpdatedEvent event) {
SparrowTerminal.get().getGuiThread().invokeLater(() -> {
WalletUtxosEntry walletUtxosEntry = getWalletForm().getWalletUtxosEntry();
fiatBalance.setText(formatFiatValue(getFiatValue(walletUtxosEntry.getBalance(), event.getBtcRate())));
fiatMempoolBalance.setText(formatFiatValue(getFiatValue(walletUtxosEntry.getMempoolBalance(), event.getBtcRate())));
fiatBalance.setText(formatFiatValue(getFiatValue(walletUtxosEntry.getBalance(), event.getCurrencyRate())));
fiatMempoolBalance.setText(formatFiatValue(getFiatValue(walletUtxosEntry.getMempoolBalance(), event.getCurrencyRate())));
});
}
}

View file

@ -81,8 +81,12 @@ public class WalletDialog extends DialogWindow {
}
}
protected double getFiatValue(long satsValue, Double btcRate) {
return satsValue * btcRate / Transaction.SATOSHIS_PER_BITCOIN;
protected double getFiatValue(long satsValue, CurrencyRate currencyRate) {
if(currencyRate != null && currencyRate.isAvailable()) {
return satsValue * currencyRate.getBtcRate() / Transaction.SATOSHIS_PER_BITCOIN;
}
return 0d;
}
protected static String centerPad(String text, int length) {