public IActionResult LightningBalance(string storeId, string cryptoCode) { var store = HttpContext.GetStoreData(); if (store == null) { return(NotFound()); } var vm = new StoreLightningBalanceViewModel { Store = store, CryptoCode = cryptoCode }; return(ViewComponent("StoreLightningBalance", new { vm })); }
public async Task <IViewComponentResult> InvokeAsync(StoreLightningBalanceViewModel vm) { if (vm.Store == null) { throw new ArgumentNullException(nameof(vm.Store)); } if (vm.CryptoCode == null) { throw new ArgumentNullException(nameof(vm.CryptoCode)); } vm.DefaultCurrency = vm.Store.GetStoreBlob().DefaultCurrency; vm.CurrencyData = _currencies.GetCurrencyData(vm.DefaultCurrency, true); if (vm.InitialRendering) { return(View(vm)); } try { var lightningClient = GetLightningClient(vm.Store, vm.CryptoCode); var balance = await lightningClient.GetBalance(); vm.Balance = balance; vm.TotalOnchain = balance.OnchainBalance != null ? (balance.OnchainBalance.Confirmed ?? 0L) + (balance.OnchainBalance.Reserved ?? 0L) + (balance.OnchainBalance.Unconfirmed ?? 0L) : null; vm.TotalOffchain = balance.OffchainBalance != null ? (balance.OffchainBalance.Opening ?? 0) + (balance.OffchainBalance.Local ?? 0) + (balance.OffchainBalance.Closing ?? 0) : null; } catch (NotSupportedException) { // not all implementations support balance fetching vm.ProblemDescription = "Your node does not support balance fetching."; } catch { // general error vm.ProblemDescription = "Could not fetch Lightning balance."; } return(View(vm)); }