From 8555f3a1f343a00e3ff81f35c225ed30f7dd8686 Mon Sep 17 00:00:00 2001 From: benthecarman Date: Sat, 23 Sep 2023 22:26:37 -0500 Subject: [PATCH] Only optimistically get price when balance non-zero --- src/state/megaStore.tsx | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/state/megaStore.tsx b/src/state/megaStore.tsx index 6d752d5..8df24da 100644 --- a/src/state/megaStore.tsx +++ b/src/state/megaStore.tsx @@ -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({