Dashboard: Add Lightning balances and services (#3838)

* Update Lightning lib

* Refactoring: Move Lightning methods and props to ExternalServices

* Rename Lightning services

* Add Lightning balance to dashboard

* Split Lightning dashboard tiles

* View updates
This commit is contained in:
d11n
2022-06-14 07:36:22 +02:00
committed by GitHub
parent 4a0f10ea99
commit 479f21f4f3
14 changed files with 451 additions and 40 deletions

View File

@@ -20,17 +20,6 @@ namespace BTCPayServer.Controllers
{
public partial class UIStoresController
{
private readonly ExternalServiceTypes[] _externalServiceTypes =
{
ExternalServiceTypes.Spark,
ExternalServiceTypes.RTL,
ExternalServiceTypes.ThunderHub
};
private readonly string[] _externalServiceNames =
{
"Lightning Terminal"
};
[HttpGet("{storeId}/lightning/{cryptoCode}")]
public IActionResult Lightning(string storeId, string cryptoCode)
{
@@ -48,7 +37,7 @@ namespace BTCPayServer.Controllers
if (vm.LightningNodeType == LightningNodeType.Internal)
{
var services = _externalServiceOptions.Value.ExternalServices.ToList()
.Where(service => _externalServiceTypes.Contains(service.Type))
.Where(service => ExternalServices.LightningServiceTypes.Contains(service.Type))
.Select(async service =>
{
var model = new AdditionalServiceViewModel
@@ -60,7 +49,7 @@ namespace BTCPayServer.Controllers
};
try
{
model.Link = await GetServiceLink(service);
model.Link = await service.GetLink(Request.GetAbsoluteUriNoPathBase(), _BtcpayServerOptions.NetworkType);
}
catch (Exception exception)
{
@@ -74,7 +63,7 @@ namespace BTCPayServer.Controllers
// other services
foreach ((string key, Uri value) in _externalServiceOptions.Value.OtherExternalServices)
{
if (_externalServiceNames.Contains(key))
if (ExternalServices.LightningServiceNames.Contains(key))
{
services.Add(new AdditionalServiceViewModel
{
@@ -398,12 +387,5 @@ namespace BTCPayServer.Controllers
.FirstOrDefault(d => d.PaymentId == id);
return existing;
}
private async Task<string> GetServiceLink(ExternalService service)
{
var connectionString = await service.ConnectionString.Expand(Request.GetAbsoluteUriNoPathBase(), service.Type, _BtcpayServerOptions.NetworkType);
var tokenParam = service.Type == ExternalServiceTypes.ThunderHub ? "token" : "access-key";
return $"{connectionString.Server}?{tokenParam}={connectionString.AccessKey}";
}
}
}