breez fixes

This commit is contained in:
Kukks
2024-03-22 11:22:55 +01:00
parent d67a42a30a
commit de5d6c9113
7 changed files with 52 additions and 25 deletions

View File

@@ -417,6 +417,11 @@ public class BreezController : Controller
var client = _breezService.GetClient(storeId); var client = _breezService.GetClient(storeId);
existing.SetLightningUrl(client); existing.SetLightningUrl(client);
store.SetSupportedPaymentMethod(existing); store.SetSupportedPaymentMethod(existing);
var lnurl = new LNURLPaySupportedPaymentMethod()
{
CryptoCode = "BTC",
};
store.SetSupportedPaymentMethod(lnurl);
await _storeRepository.UpdateStore(store); await _storeRepository.UpdateStore(store);
} }
@@ -438,7 +443,6 @@ public class BreezController : Controller
} }
viewModel ??= new PaymentsViewModel(); viewModel ??= new PaymentsViewModel();
viewModel.Payments = client.Sdk.ListPayments(new ListPaymentsRequest(null, null, null,null,true, viewModel.Payments = client.Sdk.ListPayments(new ListPaymentsRequest(null, null, null,null,true,
(uint?) viewModel.Skip, (uint?) viewModel.Count)); (uint?) viewModel.Skip, (uint?) viewModel.Count));

View File

@@ -114,6 +114,7 @@ public class BreezLightningClient : ILightningClient, IDisposable, EventListener
BOLT11 = lnPaymentDetails.data.bolt11, BOLT11 = lnPaymentDetails.data.bolt11,
Status = p.status switch Status = p.status switch
{ {
PaymentStatus.PENDING => LightningInvoiceStatus.Unpaid,
PaymentStatus.FAILED => LightningInvoiceStatus.Expired, PaymentStatus.FAILED => LightningInvoiceStatus.Expired,
PaymentStatus.COMPLETE => LightningInvoiceStatus.Paid, PaymentStatus.COMPLETE => LightningInvoiceStatus.Paid,
_ => LightningInvoiceStatus.Unpaid _ => LightningInvoiceStatus.Unpaid
@@ -132,7 +133,7 @@ public class BreezLightningClient : ILightningClient, IDisposable, EventListener
{ {
Id = paymentHash.ToString(), Id = paymentHash.ToString(),
PaymentHash = paymentHash.ToString(), PaymentHash = paymentHash.ToString(),
Status = LightningInvoiceStatus.Expired, Status = LightningInvoiceStatus.Unpaid
}; };
return FromPayment(p); return FromPayment(p);
@@ -328,7 +329,7 @@ public class BreezLightningClient : ILightningClient, IDisposable, EventListener
public void Dispose() public void Dispose()
{ {
Sdk.Dispose(); Sdk.Dispose();
Sdk.Dispose(); Sdk.Dispose();
} }
@@ -345,13 +346,14 @@ public class BreezLightningClient : ILightningClient, IDisposable, EventListener
breezLightningClient.EventReceived += BreezLightningClientOnEventReceived; breezLightningClient.EventReceived += BreezLightningClientOnEventReceived;
} }
private readonly ConcurrentQueue<Task<LightningInvoice>> _invoices = new(); private readonly ConcurrentQueue<Payment> _invoices = new();
private void BreezLightningClientOnEventReceived(object sender, BreezEvent e) private void BreezLightningClientOnEventReceived(object sender, BreezEvent e)
{ {
if (e is BreezEvent.InvoicePaid pre) if (e is BreezEvent.InvoicePaid pre && pre.details.payment is {})
{ {
_invoices.Enqueue(_breezLightningClient.GetInvoice(pre.details.paymentHash, _cancellationToken));
_invoices.Enqueue(pre.details.payment);
} }
} }
@@ -364,9 +366,9 @@ public class BreezLightningClient : ILightningClient, IDisposable, EventListener
{ {
while (cancellation.IsCancellationRequested is not true) while (cancellation.IsCancellationRequested is not true)
{ {
if (_invoices.TryDequeue(out var task)) if (_invoices.TryDequeue(out var payment))
{ {
return await task.WithCancellation(cancellation); return _breezLightningClient.FromPayment(payment);
} }
await Task.Delay(100, cancellation); await Task.Delay(100, cancellation);

View File

@@ -160,6 +160,8 @@ public class BreezService:EventHostedServiceBase
public BreezLightningClient? GetClient(string? storeId) public BreezLightningClient? GetClient(string? storeId)
{ {
tcs.Task.GetAwaiter().GetResult();
if(storeId is null) if(storeId is null)
return null; return null;
_clients.TryGetValue(storeId, out var client); _clients.TryGetValue(storeId, out var client);
@@ -167,6 +169,7 @@ public class BreezService:EventHostedServiceBase
} }
public BreezLightningClient? GetClientByPaymentKey(string? paymentKey) public BreezLightningClient? GetClientByPaymentKey(string? paymentKey)
{ {
tcs.Task.GetAwaiter().GetResult();
if(paymentKey is null) if(paymentKey is null)
return null; return null;
var match = _settings.FirstOrDefault(pair => pair.Value.PaymentKey == paymentKey).Key; var match = _settings.FirstOrDefault(pair => pair.Value.PaymentKey == paymentKey).Key;

View File

@@ -16,5 +16,5 @@ public class BreezSettings
[JsonIgnore] [JsonIgnore]
public IFormFile GreenlightCredentials { get; set; } public IFormFile? GreenlightCredentials { get; set; }
} }

View File

@@ -12,24 +12,25 @@
string s => s, string s => s,
StoreDashboardViewModel dashboardModel => dashboardModel.StoreId, StoreDashboardViewModel dashboardModel => dashboardModel.StoreId,
_ => Context.GetImplicitStoreId() _ => Context.GetImplicitStoreId()
}; };
var sdk = BreezService.GetClient(storeId)?.Sdk; var sdk = BreezService.GetClient(storeId)?.Sdk;
} }
<div class="sticky-header-setup"></div> <div class="sticky-header-setup"></div>
<div class="sticky-header mb-l"> <div class="sticky-header mb-l">
<h2 class="mt-1 mb-2 mb-lg-4">Breez</h2> <h2 class="mt-1 mb-2 mb-lg-4">Breez / Greenlight</h2>
<nav id="SectionNav"> @if (sdk is not null)
<div class="nav"> {
@if (sdk is not null) <nav id="SectionNav">
{ <div class="nav">
<a permission="@Policies.CanViewStoreSettings" asp-action="Info" asp-route-storeId="@storeId" class="nav-link @ViewData.IsActivePage("Breez", null, "Info")">Info</a> <a permission="@Policies.CanViewStoreSettings" asp-action="Info" asp-route-storeId="@storeId" class="nav-link @ViewData.IsActivePage("Breez", null, "Info")">Info</a>
<a permission="@Policies.CanViewStoreSettings" asp-action="Payments" asp-route-storeId="@storeId" class="nav-link @ViewData.IsActivePage("Breez", null, "Payments")">Payments</a> <a permission="@Policies.CanViewStoreSettings" asp-action="Payments" asp-route-storeId="@storeId" class="nav-link @ViewData.IsActivePage("Breez", null, "Payments")">Payments</a>
<a permission="@Policies.CanCreateInvoice" asp-action="SwapIn" asp-route-storeId="@storeId" class="nav-link @ViewData.IsActivePage("Breez", null, "SwapIn")">Swap In</a> <a permission="@Policies.CanCreateInvoice" asp-action="SwapIn" asp-route-storeId="@storeId" class="nav-link @ViewData.IsActivePage("Breez", null, "SwapIn")">Swap In</a>
<a permission="@Policies.CanModifyStoreSettings" asp-action="SwapOut" asp-route-storeId="@storeId" class="nav-link @ViewData.IsActivePage("Breez", null, "SwapOut")">Swap Out</a> <a permission="@Policies.CanModifyStoreSettings" asp-action="SwapOut" asp-route-storeId="@storeId" class="nav-link @ViewData.IsActivePage("Breez", null, "SwapOut")">Swap Out</a>
}
<a permission="@Policies.CanModifyStoreSettings" asp-action="Configure" asp-route-storeId="@storeId" class="nav-link @ViewData.IsActivePage("Breez", null, "Configure")">Configuration</a> <a permission="@Policies.CanModifyStoreSettings" asp-action="Configure" asp-route-storeId="@storeId" class="nav-link @ViewData.IsActivePage("Breez", null, "Configure")">Configuration</a>
</div> </div>
</nav> </nav>
}
</div> </div>

View File

@@ -24,7 +24,17 @@
var nodeState = sdk.NodeInfo(); var nodeState = sdk.NodeInfo();
var lspInfo = sdk.LspInfo(); var lspInfo = sdk.LspInfo();
} }
<div class="widget store-numbers" id="Breez-Info" style="grid-column-start: 1; grid-column-end: 4;"> <style>
#Breez-Info{
order: -3;
}
@@media (min-width: 1200px) {
#Breez-Info{
grid-column-start: 1; grid-column-end: 6; order: -1;
}}
</style>
<div class="widget store-numbers" id="Breez-Info" style="">
@if (Model is StoreDashboardViewModel) @if (Model is StoreDashboardViewModel)
{ {
<header> <header>

View File

@@ -1,5 +1,4 @@
@using Breez.Sdk @using Breez.Sdk
@using BTCPayServer.Abstractions.Extensions
@using BTCPayServer.Lightning @using BTCPayServer.Lightning
@using BTCPayServer.Models.StoreViewModels @using BTCPayServer.Models.StoreViewModels
@using BTCPayServer.Plugins.Breez @using BTCPayServer.Plugins.Breez
@@ -20,8 +19,16 @@
var isDashboard = Model is StoreDashboardViewModel; var isDashboard = Model is StoreDashboardViewModel;
} }
@if (isDashboard)
<div class="@(isDashboard ? "widget store-wallet-balance" : "")" style="@(isDashboard ? "grid-column-start: 4;grid-column-end: 13;" : "")"> {
<style>
@@media (min-width: 1200px) {
#breez-payments{
grid-column-start: 6; grid-column-end: 13;
}}
</style>
}
<div id="breez-payments" class="@(isDashboard ? "widget store-wallet-balance" : "")">
@if (isDashboard) @if (isDashboard)
{ {
<header> <header>
@@ -47,7 +54,7 @@
<th class="w-125px">Id</th> <th class="w-125px">Id</th>
<th class="w-125px">Timestamp</th> <th class="w-125px">Timestamp</th>
<th class="w-125px">Type</th> <th class="w-125px">Type</th>
<th class="w-125px">Amount</th>a <th class="w-125px">Amount</th>
<th class="text-nowrap">Fee</th> <th class="text-nowrap">Fee</th>
<th class="text-nowrap">Status</th> <th class="text-nowrap">Status</th>
<th class="text-nowrap">Description</th> <th class="text-nowrap">Description</th>