diff --git a/BTCPayApp.Core/Wallet/LightningNodeService.cs b/BTCPayApp.Core/Wallet/LightningNodeService.cs index 816cc87..febab18 100644 --- a/BTCPayApp.Core/Wallet/LightningNodeService.cs +++ b/BTCPayApp.Core/Wallet/LightningNodeService.cs @@ -1,4 +1,3 @@ -using BTCPayApp.Core.Auth; using BTCPayApp.Core.BTCPayServer; using BTCPayApp.Core.Data; using BTCPayApp.Core.Helpers; @@ -19,13 +18,12 @@ public class LightningNodeManager : BaseHostedService private readonly BTCPayConnectionManager _btcPayConnectionManager; private readonly IServiceScopeFactory _serviceScopeFactory; - private IServiceScope? _nodeScope; public LDKNode? Node => _nodeScope?.ServiceProvider.GetService(); private LightningNodeState _state = LightningNodeState.Init; public bool IsHubConnected => _btcPayConnectionManager.ConnectionState is BTCPayConnectionState.ConnectedAsMaster; private async Task IsOnchainLightningDerivationConfigured() => (await _onChainWalletManager.GetConfig())?.Derivations.ContainsKey(WalletDerivation.LightningScripts) is true; - public async Task CanConfigureLightningNode () => IsHubConnected && await _onChainWalletManager.IsConfigured() && !await IsOnchainLightningDerivationConfigured() && State == LightningNodeState.NotConfigured; + public async Task CanConfigureLightningNode () => IsHubConnected && await _onChainWalletManager.IsConfigured() && !await IsOnchainLightningDerivationConfigured() && State == LightningNodeState.NotConfigured; // public string? ConnectionString => IsOnchainLightningDerivationConfigured && _accountManager.GetUserInfo() is {} acc // ? $"type=app;user={acc.UserId}": null; @@ -68,7 +66,6 @@ public async Task StartNode() return; } - _logger.LogInformation("Starting lightning node"); await _controlSemaphore.WaitAsync(); try @@ -122,7 +119,7 @@ public async Task StopNode(bool setAsStopped = true) _nodeScope = null; _controlSemaphore.Release(); if (setAsStopped) - State = LightningNodeState.Stopped; + State = LightningNodeState.Stopped; } } diff --git a/BTCPayApp.Core/Wallet/OnChainWalletManager.cs b/BTCPayApp.Core/Wallet/OnChainWalletManager.cs index 4a0d093..c6f63c4 100644 --- a/BTCPayApp.Core/Wallet/OnChainWalletManager.cs +++ b/BTCPayApp.Core/Wallet/OnChainWalletManager.cs @@ -63,6 +63,7 @@ private set } public event AsyncEventHandler<(OnChainWalletState Old, OnChainWalletState New)>? StateChanged; + public event AsyncEventHandler? SnapshotUpdated; public OnChainWalletManager( ConfigProvider configProvider, @@ -352,9 +353,9 @@ private async Task UpdateSnapshot() var bb = await GetBestBlock(); var identifiers = config.Derivations.Values.Select(derivation => derivation.Identifier).ToArray(); var utxos = await HubProxy.GetUTXOs(identifiers); - config.CoinSnapshot = new CoinSnapshot() + config.CoinSnapshot = new CoinSnapshot { - BlockSnapshot = new BlockSnapshot() + BlockSnapshot = new BlockSnapshot { BlockHash = uint256.Parse(bb.BlockHash), BlockHeight = (uint) bb.BlockHeight @@ -367,6 +368,7 @@ private async Task UpdateSnapshot() }).ToArray()) }; await _configProvider.Set(WalletConfig.Key, config, true); + SnapshotUpdated?.Invoke(this, config.CoinSnapshot); } finally { @@ -495,7 +497,6 @@ public interface ISignableCoin : ICoin }, pair => pair.Value.OrderByDescending(tx => tx.Timestamp).ToArray()); } - public async Task> GetUTXOS() { var config = await GetConfig(); diff --git a/BTCPayApp.UI/Pages/SendPage.razor b/BTCPayApp.UI/Pages/SendPage.razor index acfdb35..8113c88 100644 --- a/BTCPayApp.UI/Pages/SendPage.razor +++ b/BTCPayApp.UI/Pages/SendPage.razor @@ -34,7 +34,13 @@
-

Send from @(StoreInfo?.Name ?? "Store") Funds

+
+

Send from @(StoreInfo?.Name ?? "Store") Funds

+ @if (BalanceLoading) + { + + } +
@if (TotalBalance > 0 && (LightningOffchainLocalBalance is > 0 || OnchainConfirmedBalance is > 0) && (OnchainState == SourceState.Supported && OnChainWalletManager.IsActive || LightningState == SourceState.Supported && LightningNodeManager.IsActive)) @@ -163,12 +169,6 @@ } - else if (BalanceLoading) - { -
- -
- } else if (!string.IsNullOrEmpty(BalanceError)) { @BalanceError @@ -297,8 +297,14 @@ @if (Transactions?.Any() is true) { -

Recent Payments

- +
+

Recent Payments

+ @if (TransactionsLoading) + { + + } +
+ } }
@@ -407,9 +413,25 @@ ? await LightningNodeManager.IsLightningOurs(lightning) ? SourceState.Supported : SourceState.NotSupported : SourceState.NotConfigured; + OnChainWalletManager.SnapshotUpdated += OnSnapshotUpdated; + _ = LoadTransactions(); } + protected override ValueTask DisposeAsyncCore(bool disposing) + { + base.DisposeAsyncCore(disposing); + + OnChainWalletManager.SnapshotUpdated -= OnSnapshotUpdated; + + return ValueTask.CompletedTask; + } + + private async Task OnSnapshotUpdated(object? sender, CoinSnapshot _) + { + await LoadTransactions(); + } + private async Task OnBackClick() { if (Model.Transaction == null) @@ -422,6 +444,7 @@ { TransactionsError = null; TransactionsLoading = true; + await InvokeAsync(StateHasChanged); try { // load @@ -594,7 +617,6 @@ await OnChainWalletManager.BroadcastTransaction(transaction); Dispatcher.Dispatch(new StoreState.FetchBalances(StoreId!)); Model = new SendModel(); - _ = LoadTransactions(); return new FormResult(true, $"Transaction {transaction.GetHash()} broadcasted"); } catch (Exception ex) diff --git a/BTCPayApp.UI/StateMiddleware.cs b/BTCPayApp.UI/StateMiddleware.cs index 53afafc..05fa155 100644 --- a/BTCPayApp.UI/StateMiddleware.cs +++ b/BTCPayApp.UI/StateMiddleware.cs @@ -96,6 +96,14 @@ private async Task ListenIn(IDispatcher dispatcher) } }; + onChainWalletManager.SnapshotUpdated += async (sender, args) => + { + if (accountManager.GetCurrentStore() is { } store) + { + dispatcher.Dispatch(new StoreState.FetchBalances(store.Id)); + } + }; + lightningNodeService.StateChanged += async (sender, args) => { dispatcher.Dispatch(new RootState.LightningNodeStateUpdatedAction(lightningNodeService.State));