From b1564125215742ca89f422a4b3d127269ac3ce60 Mon Sep 17 00:00:00 2001 From: benthecarman Date: Tue, 19 Sep 2023 16:25:29 -0500 Subject: [PATCH] Set price on startup --- src/state/megaStore.tsx | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/state/megaStore.tsx b/src/state/megaStore.tsx index 1dcdbe1..6d752d5 100644 --- a/src/state/megaStore.tsx +++ b/src/state/megaStore.tsx @@ -179,14 +179,28 @@ export const Provider: ParentComponent = (props) => { } } - // Get balance optimistically + // 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" + ); + } + } catch (e) { + console.error(e); + price = 0; + } setState({ mutiny_wallet: mutinyWallet, wallet_loading: false, subscription_timestamp: subscription_timestamp, load_stage: "done", + price: price || 0, balance }); } catch (e) {