mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-12-25 05:06:45 +00:00
fix npe in terminal for exchange rate updates without a btc rate
This commit is contained in:
parent
e2795c7ef3
commit
96c88b7472
3 changed files with 14 additions and 10 deletions
|
@ -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())));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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())));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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) {
|
||||||
|
|
Loading…
Reference in a new issue