Only optimistically get price when balance non-zero

This commit is contained in:
benthecarman
2023-09-23 22:26:37 -05:00
committed by Paul Miller
parent 414671acce
commit 8555f3a1f3

View File

@@ -182,17 +182,25 @@ export const Provider: ParentComponent = (props) => {
// Get balance + price optimistically
const balance = await mutinyWallet.get_balance();
let price;
try {
if (state.fiat.value === "BTC") {
price = 1;
} else {
price = await mutinyWallet.get_bitcoin_price(
state.fiat.value.toLowerCase() || "usd"
);
// only get price if balance is non-zero
if (
balance.confirmed > 0 ||
balance.unconfirmed > 0 ||
balance.lightning > 0 ||
balance.force_close > 0
) {
try {
if (state.fiat.value === "BTC") {
price = 1;
} else {
price = await mutinyWallet.get_bitcoin_price(
state.fiat.value.toLowerCase() || "usd"
);
}
} catch (e) {
console.error(e);
price = 0;
}
} catch (e) {
console.error(e);
price = 0;
}
setState({