Skip to content

Commit

Permalink
More warning fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dennisreimann committed Nov 7, 2024
1 parent f87076e commit b05b54d
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 98 deletions.
2 changes: 1 addition & 1 deletion BTCPayApp.Core/LDK/LDKNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ public async Task<LightningConfig> GetConfig()
return await _configProvider.Get<LightningConfig>(LightningConfig.Key) ?? new LightningConfig();
}

public async Task<string[]> GetJITLSPs()
public async Task<string[]?> GetJITLSPs()
{
return ServiceProvider.GetServices<IJITService>().Select(jit => jit.ProviderName).ToArray();
}
Expand Down
8 changes: 4 additions & 4 deletions BTCPayApp.Desktop/StartupExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,12 @@ public DesktopDataDirectoryProvider(IConfiguration configuration)
}
public virtual Task<string> GetAppDataDirectory()
{
var dirName = _configuration.GetValue<string>("BTCPAYAPP_DIRNAME", "BTCPayApp")!;
return Task.FromResult(GetDirectory(dirName));
var def = "BTCPayApp";
var dirName = _configuration.GetValue("BTCPAYAPP_DIRNAME", def);
return Task.FromResult(GetDirectory(dirName ?? def));
}

private string GetDirectory(
string appDirectory)
private string GetDirectory(string appDirectory)
{
var environmentVariable1 = _configuration.GetValue<string>("HOME");
var environmentVariable2 = _configuration.GetValue<string>("APPDATA");
Expand Down
4 changes: 2 additions & 2 deletions BTCPayApp.UI/Components/AccountSwitch.razor
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<Icon Symbol="caret-down"/>
</button>
<ul class="dropdown-menu">
@if (_accounts.Count() > 1)
@if (_accounts?.Count() > 1)
{
@foreach (var account in _accounts)
{
Expand Down Expand Up @@ -85,7 +85,7 @@

@code {
private BTCPayAccount? _account;
private IEnumerable<BTCPayAccount> _accounts;
private IEnumerable<BTCPayAccount>? _accounts;
private bool _sending;
private string? _errorMessage;
private LoginModel? Model { get; set; }
Expand Down
27 changes: 14 additions & 13 deletions BTCPayApp.UI/Components/ValidationEditContext.razor
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@using System.Linq.Expressions
@implements IDisposable

<EditForm EditContext="EditContext" OnSubmit="OnSubmit" @attributes="@InputAttributes">
<EditForm EditContext="EditContext" OnSubmit="@OnSubmit" @attributes="@InputAttributes">
@if (!string.IsNullOrEmpty(ErrorMessage))
{
<Alert Type="danger">@ErrorMessage</Alert>
Expand All @@ -22,8 +22,8 @@
</EditForm>

@code {
[Parameter]
public object Model { get; set; }
[Parameter, EditorRequired]
public object Model { get; set; } = null!;

[Parameter]
public Func<Task>? Validate { get; set; }
Expand All @@ -44,10 +44,10 @@
public string? ErrorMessage { get; set; }

[Parameter(CaptureUnmatchedValues = true)]
public Dictionary<string, object> InputAttributes { get; set; }
public Dictionary<string, object>? InputAttributes { get; set; }

public EditContext EditContext { get; set; }
public ValidationMessageStore MessageStore { get; set; }
public EditContext? EditContext { get; set; }
public ValidationMessageStore? MessageStore { get; set; }

protected override void OnInitialized()
{
Expand All @@ -67,14 +67,14 @@

private void EditContextOnOnFieldChanged(object? sender, FieldChangedEventArgs e)
{
if (!EditContext.GetValidationMessages(e.FieldIdentifier).Any()) return;
MessageStore.Clear(e.FieldIdentifier);
EditContext.NotifyValidationStateChanged();
if (!EditContext?.GetValidationMessages(e.FieldIdentifier).Any() is true) return;
MessageStore?.Clear(e.FieldIdentifier);
EditContext?.NotifyValidationStateChanged();
}

public void NotifyFieldChanged(Expression<Func<object>> field)
{
EditContext.NotifyFieldChanged(FieldIdentifier.Create(field));
EditContext?.NotifyFieldChanged(FieldIdentifier.Create(field));
}

private void EditContextOnOnValidationStateChanged(object? sender, ValidationStateChangedEventArgs e)
Expand All @@ -86,7 +86,7 @@
{
if (Validate is not null)
await Validate.Invoke();
EditContext.Validate();
EditContext?.Validate();

if (Invalid)
{
Expand All @@ -98,15 +98,16 @@
}
}

public bool Invalid => EditContext.GetValidationMessages().Any();
public bool Invalid => EditContext?.GetValidationMessages().Any() is true;

public async Task Submit()
{
await OnSubmit(EditContext);
if (EditContext != null) await OnSubmit(EditContext);
}

public void Dispose()
{
if (EditContext == null) return;
EditContext.OnFieldChanged -= EditContextOnOnFieldChanged;
EditContext.OnValidationRequested -= EditContextOnOnValidationRequested;
EditContext.OnValidationStateChanged -= EditContextOnOnValidationStateChanged;
Expand Down
70 changes: 36 additions & 34 deletions BTCPayApp.UI/Pages/Settings/LightningChannelsPage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
<h2>Peers</h2>
@if (_peers?.Any() is true || _config?.Peers.Any() is true)
{
var rememberedButUnconnected = _config.Peers.Keys.Where(peer => _peers.All(p => !string.Equals(p.nodeId, peer, StringComparison.InvariantCultureIgnoreCase)));
@foreach (var peer in _peers)
var rememberedButUnconnected = _config!.Peers.Keys.Where(peer => _peers!.All(p => !string.Equals(p.nodeId, peer, StringComparison.InvariantCultureIgnoreCase)));
@foreach (var peer in _peers!)
{
var peerRemembered = _config.Peers.TryGetValue(peer.nodeId.ToLowerInvariant(), out var peerConfig);
<div class="box">
Expand All @@ -44,7 +44,7 @@
<TruncateCenter Text="@peer.socket" Padding="30" Copy="true" Elastic="true" class="form-control-plaintext"/>
<label>Socket</label>
</div>
@if (!string.IsNullOrEmpty(peerConfig.Label))
@if (!string.IsNullOrEmpty(peerConfig?.Label))
{
<div class="form-floating">
<TruncateCenter Text="@peerConfig.Label" Padding="15" Copy="true" Elastic="true" class="form-control-plaintext"/>
Expand All @@ -56,14 +56,14 @@
@if (peerRemembered)
{
<button type="button" class="btn btn-outline-danger btn-sm" @onclick="() => UpdatePeer(peer.nodeId, null)">Forget peer</button>
<button type="button" class="btn btn-outline-primary btn-sm" @onclick="() => UpdatePeer(peer.nodeId, peerConfig with { Persistent = !peerConfig.Persistent })">
@(peerConfig.Persistent? "Persistent connection enabled": "Persistent connection disabled")
<button type="button" class="btn btn-outline-primary btn-sm" @onclick="() => UpdatePeer(peer.nodeId, peerConfig! with { Persistent = !peerConfig.Persistent })">
@(peerConfig!.Persistent? "Persistent connection enabled": "Persistent connection disabled")
</button>
<button type="button" class="btn btn-outline-primary btn-sm" @onclick="() => UpdatePeer(peer.nodeId, peerConfig with { Trusted = !peerConfig.Trusted })">@(peerConfig.Trusted? "Trusted": "Untrusted")</button>
}
else if (peer.socket is not null)
{
<button type="button" class="btn btn-outline-primary btn-sm" @onclick="() => UpdatePeer(peer.nodeId, new PeerInfo() { Endpoint = peer.socket })">Remember peer</button>
<button type="button" class="btn btn-outline-primary btn-sm" @onclick="() => UpdatePeer(peer.nodeId, new PeerInfo { Endpoint = peer.socket })">Remember peer</button>
}
</div>
</div>
Expand Down Expand Up @@ -109,27 +109,30 @@
</div>
}

<h2>Connect Peer</h2>
<ValidationEditContext @ref="_connectEditContext" Model="PeerModel" OnValidSubmit="() => ConnectToNewPeer()" SuccessMessage="@ConnectSuccessMessage" ErrorMessage="@ConnectErrorMessage">
<DataAnnotationsValidator/>
<fieldset class="box">
<div class="form-group">
<label for="PeerUrl" class="form-label" data-required>Peer URL</label>
<InputText @bind-Value="PeerModel.PeerUrl" id="PeerUrl" class="form-control"/>
<ValidationMessage For="@(() => PeerModel.PeerUrl)"/>
</div>
<button type="submit" class="btn btn-primary w-100" disabled="@(_connectEditContext!.Invalid || PeerConnecting)">
@if (PeerConnecting)
{
<LoadingIndicator/>
}
else
{
<span>Connect Peer</span>
}
</button>
</fieldset>
</ValidationEditContext>
@if (PeerModel != null)
{
<h2>Connect Peer</h2>
<ValidationEditContext @ref="_connectEditContext" Model="PeerModel" OnValidSubmit="() => ConnectToNewPeer()" SuccessMessage="@ConnectSuccessMessage" ErrorMessage="@ConnectErrorMessage">
<DataAnnotationsValidator/>
<fieldset class="box">
<div class="form-group">
<label for="PeerUrl" class="form-label" data-required>Peer URL</label>
<InputText @bind-Value="PeerModel.PeerUrl" id="PeerUrl" class="form-control"/>
<ValidationMessage For="@(() => PeerModel.PeerUrl)"/>
</div>
<button type="submit" class="btn btn-primary w-100" disabled="@(_connectEditContext!.Invalid || PeerConnecting)">
@if (PeerConnecting)
{
<LoadingIndicator/>
}
else
{
<span>Connect Peer</span>
}
</button>
</fieldset>
</ValidationEditContext>
}

<h2>Channels</h2>
@if (_channels?.Any() is true)
Expand All @@ -156,12 +159,10 @@
<tbody>
@foreach (var channel in _channels)
{

var connected = _peers.Any(p => string.Equals(p.nodeId, channel.Value.channelDetails?.get_counterparty().get_node_id().ToString(), StringComparison.InvariantCultureIgnoreCase));
var connected = _peers?.Any(p => string.Equals(p.nodeId, channel.Value.channelDetails?.get_counterparty().get_node_id().ToString(), StringComparison.InvariantCultureIgnoreCase)) is true;
var active = false;
var alternates = channel.Value.channel.Aliases.Select(alias => alias.Id).ToHashSet();

if(channel.Value.channelDetails is not null)
if (channel.Value.channelDetails is not null)
{
if(channel.Value.channelDetails.get_short_channel_id() is Option_u64Z.Option_u64Z_Some some)
{
Expand All @@ -182,10 +183,11 @@
@if (channel.Value.channelDetails is not null && channel.Value.channelDetails.get_counterparty() is ChannelCounterparty counterparty)
{
var counterpartyNodeId = Convert.ToHexString(counterparty.get_node_id()).ToLowerInvariant();
if(_config.Peers.TryGetValue(counterpartyNodeId, out var peerConfig) && !string.IsNullOrEmpty(peerConfig.Label))
if (_config.Peers.TryGetValue(counterpartyNodeId, out var peerConfig) && !string.IsNullOrEmpty(peerConfig.Label))
{
<span>@peerConfig.Label</span>
}else
}
else
{
<span>@counterpartyNodeId</span>
}
Expand Down Expand Up @@ -245,7 +247,7 @@
</div>
}

@if (_peers?.Any() is true)
@if (_peers?.Any() is true && _config?.Peers != null && ChannelModel != null)
{
<h2>Open Channel</h2>
<ValidationEditContext @ref="_openChannelEditContext" Model="ChannelModel" OnValidSubmit="() => OpenChannel()" SuccessMessage="@ChannelSuccessMessage" ErrorMessage="@ChannelErrorMessage">
Expand Down
24 changes: 12 additions & 12 deletions BTCPayApp.UI/Pages/Settings/LightningPage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,16 @@
@if (Node is not null)
{
<h2>Lightning Settings</h2>
<ValidationEditContext @ref="_validationEditContext" Model="Model" OnValidSubmit="UpdateConfig" SuccessMessage="@_successMessage" ErrorMessage="@_errorMessage">
<ValidationEditContext @ref="_validationEditContext" Model="Model" OnValidSubmit="UpdateConfig" SuccessMessage="@SuccessMessage" ErrorMessage="@ErrorMessage">
<DataAnnotationsValidator/>
<fieldset class="box">
@if (JITOptions?.Any() is true)
@if (_jitOptions?.Any() is true)
{
<div class="form-group">
<label for="JITLSP" class="form-label">Lightning Service Provider</label>
<InputSelect id="JITLSP" @bind-Value="Model.JitLsp" class="form-select">
<option value="">None</option>
@foreach (var jit in JITOptions)
@foreach (var jit in _jitOptions)
{
<option value="@jit">@jit</option>
}
Expand Down Expand Up @@ -129,14 +129,14 @@
private LightningConfig? _config;
private LDKNode? Node => LightningNodeManager.Node;
private string? StoreId => AccountManager.GetCurrentStore()?.Id;
private string PaymentMethodId => LightningNodeManager.PaymentMethodId;
private static string PaymentMethodId => LightningNodeManager.PaymentMethodId;
private string? _storePaymentMethodIdentifier;
// We need a ui/component for the api keys now.
// private string? ConnectionString => LightningNodeManager.ConnectionString;
private string[] JITOptions;
private string[]? _jitOptions;
private SettingsModel Model { get; set; } = new();
private string? _successMessage { get; set; }
private string? _errorMessage { get; set; }
private string? SuccessMessage { get; set; }
private string? ErrorMessage { get; set; }
private ValidationEditContext? _validationEditContext;

private class SettingsModel
Expand All @@ -151,7 +151,7 @@
if (Node is not null)
{
Node.ConfigUpdated += RefreshConfig;
JITOptions = await Node.GetJITLSPs();
_jitOptions = await Node.GetJITLSPs();
await RefreshConfig(this, await Node.GetConfig());
}

Expand All @@ -172,7 +172,7 @@
private async Task UpdateConfig()
{
if (Node is null) return;
_successMessage = _errorMessage = null;
SuccessMessage = ErrorMessage = null;
try
{
await Node.UpdateConfig(config =>
Expand All @@ -181,11 +181,11 @@
config.RapidGossipSyncUrl = string.IsNullOrEmpty(Model.RgsUrl) ? null : Uri.TryCreate(Model.RgsUrl, UriKind.Absolute, out var uri) ? uri: null;
return Task.FromResult((config, true));
});
_successMessage = "Lightning configuration updated.";
SuccessMessage = "Lightning configuration updated.";
}
catch (Exception e)
{
_errorMessage = e.Message;
ErrorMessage = e.Message;
}
}

Expand Down Expand Up @@ -243,7 +243,7 @@
}
catch (Exception ex)
{
_errorMessage = "Error configuring LN wallet";
ErrorMessage = "Error configuring LN wallet";
Logger.LogError(ex, "Error configuring LN wallet");
}
}
Expand Down
Loading

0 comments on commit b05b54d

Please sign in to comment.