Show Lightning node availability in navigation (#5951)

* Show Lightning node availability in navigation

Instead of simply communicating the setup state of the store's LN node, this now also checks its availability.

Closes  #5940.

* Cleanups

* Add Selenium test for public node page and status in nav

* Cache the available lightning node result

---------

Co-authored-by: nicolas.dorier <nicolas.dorier@gmail.com>
This commit is contained in:
d11n
2024-04-26 08:30:34 +02:00
committed by GitHub
parent d3277306cf
commit 8d429f064b
9 changed files with 121 additions and 26 deletions

View File

@@ -1,6 +1,9 @@
#nullable enable
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using BTCPayServer.Abstractions.Constants;
using BTCPayServer.Client;
@@ -15,6 +18,7 @@ using BTCPayServer.Payments.Lightning;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using NBitcoin;
using NBitcoin.DataEncoders;
namespace BTCPayServer.Controllers;
@@ -161,10 +165,19 @@ public partial class UIStoresController
CryptoCode = lnNetwork.CryptoCode,
PaymentMethodId = handler.PaymentMethodId,
Address = lightning?.GetDisplayableConnectionString(),
Enabled = isEnabled
});
Enabled = isEnabled,
CacheKey = GetCacheKey(lightning)
});
}
}
}
private string? GetCacheKey(LightningPaymentMethodConfig? lightning)
{
if (lightning is null)
return null;
var connStr = lightning.IsInternalNode ? lightning.InternalNodeRef : lightning.ConnectionString;
connStr ??= string.Empty;
return "LN-INFO-" + Encoders.Hex.EncodeData(SHA256.HashData(Encoding.UTF8.GetBytes(connStr))[0..4]);
}
}