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)); mempoolBalance.setText(formatBitcoinValue(walletTransactionsEntry.getMempoolBalance(), true));
if(AppServices.getFiatCurrencyExchangeRate() != null) { if(AppServices.getFiatCurrencyExchangeRate() != null) {
fiatBalance.setText(formatFiatValue(getFiatValue(walletTransactionsEntry.getBalance(), AppServices.getFiatCurrencyExchangeRate().getBtcRate()))); fiatBalance.setText(formatFiatValue(getFiatValue(walletTransactionsEntry.getBalance(), AppServices.getFiatCurrencyExchangeRate())));
fiatMempoolBalance.setText(formatFiatValue(getFiatValue(walletTransactionsEntry.getMempoolBalance(), AppServices.getFiatCurrencyExchangeRate().getBtcRate()))); fiatMempoolBalance.setText(formatFiatValue(getFiatValue(walletTransactionsEntry.getMempoolBalance(), AppServices.getFiatCurrencyExchangeRate())));
} else { } else {
fiatBalance.setText(""); fiatBalance.setText("");
fiatMempoolBalance.setText(""); fiatMempoolBalance.setText("");
@ -149,8 +149,8 @@ public class TransactionsDialog extends WalletDialog {
public void exchangeRatesUpdated(ExchangeRatesUpdatedEvent event) { public void exchangeRatesUpdated(ExchangeRatesUpdatedEvent event) {
SparrowTerminal.get().getGuiThread().invokeLater(() -> { SparrowTerminal.get().getGuiThread().invokeLater(() -> {
WalletTransactionsEntry walletTransactionsEntry = getWalletForm().getWalletTransactionsEntry(); WalletTransactionsEntry walletTransactionsEntry = getWalletForm().getWalletTransactionsEntry();
fiatBalance.setText(formatFiatValue(getFiatValue(walletTransactionsEntry.getBalance(), event.getBtcRate()))); fiatBalance.setText(formatFiatValue(getFiatValue(walletTransactionsEntry.getBalance(), event.getCurrencyRate())));
fiatMempoolBalance.setText(formatFiatValue(getFiatValue(walletTransactionsEntry.getMempoolBalance(), event.getBtcRate()))); 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)); mempoolBalance.setText(formatBitcoinValue(walletUtxosEntry.getMempoolBalance(), true));
if(AppServices.getFiatCurrencyExchangeRate() != null) { if(AppServices.getFiatCurrencyExchangeRate() != null) {
fiatBalance.setText(formatFiatValue(getFiatValue(walletUtxosEntry.getBalance(), AppServices.getFiatCurrencyExchangeRate().getBtcRate()))); fiatBalance.setText(formatFiatValue(getFiatValue(walletUtxosEntry.getBalance(), AppServices.getFiatCurrencyExchangeRate())));
fiatMempoolBalance.setText(formatFiatValue(getFiatValue(walletUtxosEntry.getMempoolBalance(), AppServices.getFiatCurrencyExchangeRate().getBtcRate()))); fiatMempoolBalance.setText(formatFiatValue(getFiatValue(walletUtxosEntry.getMempoolBalance(), AppServices.getFiatCurrencyExchangeRate())));
} else { } else {
fiatBalance.setText(""); fiatBalance.setText("");
fiatMempoolBalance.setText(""); fiatMempoolBalance.setText("");
@ -405,8 +405,8 @@ public class UtxosDialog extends WalletDialog {
public void exchangeRatesUpdated(ExchangeRatesUpdatedEvent event) { public void exchangeRatesUpdated(ExchangeRatesUpdatedEvent event) {
SparrowTerminal.get().getGuiThread().invokeLater(() -> { SparrowTerminal.get().getGuiThread().invokeLater(() -> {
WalletUtxosEntry walletUtxosEntry = getWalletForm().getWalletUtxosEntry(); WalletUtxosEntry walletUtxosEntry = getWalletForm().getWalletUtxosEntry();
fiatBalance.setText(formatFiatValue(getFiatValue(walletUtxosEntry.getBalance(), event.getBtcRate()))); fiatBalance.setText(formatFiatValue(getFiatValue(walletUtxosEntry.getBalance(), event.getCurrencyRate())));
fiatMempoolBalance.setText(formatFiatValue(getFiatValue(walletUtxosEntry.getMempoolBalance(), event.getBtcRate()))); 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) { protected double getFiatValue(long satsValue, CurrencyRate currencyRate) {
return satsValue * btcRate / Transaction.SATOSHIS_PER_BITCOIN; if(currencyRate != null && currencyRate.isAvailable()) {
return satsValue * currencyRate.getBtcRate() / Transaction.SATOSHIS_PER_BITCOIN;
}
return 0d;
} }
protected static String centerPad(String text, int length) { protected static String centerPad(String text, int length) {