Skip to content

Commit

Permalink
Set initial connection state
Browse files Browse the repository at this point in the history
  • Loading branch information
dennisreimann committed Aug 22, 2023
1 parent 8ae55be commit ca08084
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
9 changes: 0 additions & 9 deletions BTCPayApp.Core/BTCPayConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,13 @@ public Task TransactionDetected(string txid)
return Task.CompletedTask;
}

Task IBTCPayAppServerClient.OnTransactionDetected(string txid)
{
throw new NotImplementedException();
}

public Task NewBlock(string block)
{
_logger.LogInformation("NewBlock: {block}", block);
OnNewBlock?.Invoke(this, block);
return Task.CompletedTask;
}


public event EventHandler<string>? OnNewBlock;
public event EventHandler<string>? OnTransactionDetected;
}
Expand Down Expand Up @@ -99,7 +93,6 @@ private async Task TryStayConnected()
}
else
{

InvokeConnectionChange();
await Task.Delay(5000);
}
Expand Down Expand Up @@ -138,7 +131,6 @@ private async Task Kill()
HubProxy = null;
}


private async Task StartOrReplace()
{
await Kill();
Expand All @@ -158,7 +150,6 @@ private async Task StartOrReplace()
HubProxy = Connection.CreateHubProxy<IBTCPayAppServerHub>();
}


public Task StopAsync(CancellationToken cancellationToken)
{
_btcPayAppConfigManager.PairConfigUpdated -= OnPairConfigUpdated;
Expand Down
16 changes: 13 additions & 3 deletions BTCPayApp.UI/Shared/Dashboard.razor
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,17 @@
}
else if (State.Value.PairConfig is not null)
{
<MudAlert Severity="@ConnectionSeverity">Your BTCPay Server is paired. Connection status is @ConnectionStatus</MudAlert>
<MudAlert Severity="@ConnectionSeverity">
<div class="d-flex align-center justify-space-between gap-3">
Your BTCPay Server is paired. Connection status is @ConnectionStatus.
@if (State.Value.BTCPayServerConnectionState == HubConnectionState.Disconnected)
{
<MudButton Href="@Routes.Pair" Variant="Variant.Text" Color="Color.Error" Size="Size.Small">
Configure connection
</MudButton>
}
</div>
</MudAlert>
}
else
{
Expand Down Expand Up @@ -98,7 +108,7 @@ else
</MudPaper>

@code {
private string ConnectionStatus => State.Value.BTCPayServerConnectionState?.ToString() ?? "not connected";
private string ConnectionStatus => State.Value.BTCPayServerConnectionState?.ToString().ToLowerInvariant() ?? "not connected";

private Severity ConnectionSeverity => State.Value.BTCPayServerConnectionState switch {
HubConnectionState.Disconnected => Severity.Warning,
Expand All @@ -111,7 +121,7 @@ else
protected override Task OnAfterRenderAsync(bool firstRender)
{
if (!firstRender) return base.OnAfterRenderAsync(firstRender);
if (State.Value.BTCPayServerConnectionState is not HubConnectionState.Connected)
if (State.Value.BTCPayServerConnectionState is not HubConnectionState.Connected)
Dispatcher.Dispatch(new OnChainTransactionsState.LoadTransactionsAction(true));
return base.OnAfterRenderAsync(firstRender);
}
Expand Down
4 changes: 2 additions & 2 deletions BTCPayApp.UI/StateMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ public override async Task InitializeAsync(IDispatcher dispatcher, IStore store)
dispatcher.Dispatch(new RootState.LoadingAction(RootState.LoadingHandles.UiState, false));
}



await base.InitializeAsync(dispatcher, store);

ListenIn(dispatcher);
Expand Down Expand Up @@ -80,6 +78,8 @@ private void ListenIn(IDispatcher dispatcher)
dispatcher.Dispatch(new RootState.PairConfigLoadedAction(_btcPayAppConfigManager.PairConfig));
dispatcher.Dispatch(new RootState.LoadingAction(RootState.LoadingHandles.PairConfig, false));
dispatcher.Dispatch(new RootState.BTCPayConnectionUpdatedAction(_btcPayConnection.Connection?.State));
});
}
}

0 comments on commit ca08084

Please sign in to comment.