This commit is contained in:
Kukks
2023-07-04 14:35:00 +02:00
parent 241e319e46
commit 0a900079c9
3 changed files with 22 additions and 8 deletions

View File

@@ -11,7 +11,7 @@
<PropertyGroup> <PropertyGroup>
<Product>LN Prism</Product> <Product>LN Prism</Product>
<Description>Automated value splits for lightning.</Description> <Description>Automated value splits for lightning.</Description>
<Version>1.1.0</Version> <Version>1.1.1</Version>
</PropertyGroup> </PropertyGroup>
<!-- Plugin development properties --> <!-- Plugin development properties -->
<PropertyGroup> <PropertyGroup>

View File

@@ -5,6 +5,8 @@
@using BTCPayServer.PayoutProcessors @using BTCPayServer.PayoutProcessors
@using Microsoft.AspNetCore.Http @using Microsoft.AspNetCore.Http
@using Microsoft.AspNetCore.Routing @using Microsoft.AspNetCore.Routing
@using Microsoft.Extensions.Logging
@using Newtonsoft.Json.Linq
@using LightningAddressData = BTCPayServer.Data.LightningAddressData @using LightningAddressData = BTCPayServer.Data.LightningAddressData
@inject IPluginHookService PluginHookService @inject IPluginHookService PluginHookService
@inject LightningAddressService LightningAddressService @inject LightningAddressService LightningAddressService
@@ -12,7 +14,8 @@
@inject IEnumerable<IPayoutProcessorFactory> PayoutProcessorFactories @inject IEnumerable<IPayoutProcessorFactory> PayoutProcessorFactories
@inject SatBreaker SatBreaker @inject SatBreaker SatBreaker
@inject LinkGenerator LinkGenerator @inject LinkGenerator LinkGenerator
@inject IHttpContextAccessor httpContextAccessor @inject IHttpContextAccessor HttpContextAccessor
@inject ILogger<PrismEdit> Logger
@if (Loading) @if (Loading)
{ {
@@ -103,7 +106,7 @@ else
@code { @code {
public bool Loading { get; set; } = true; public bool Loading { get; set; } = true;
public List<LightningAddressData> Users { get; set; } public List<LightningAddressData> Users { get; set; } = new();
public PaymentMethodId pmi { get; set; } = new("BTC", LightningPaymentType.Instance); public PaymentMethodId pmi { get; set; } = new("BTC", LightningPaymentType.Instance);
public bool NoPayoutProcessors { get; set; } public bool NoPayoutProcessors { get; set; }
@@ -111,9 +114,13 @@ else
{ {
if (firstRender) if (firstRender)
{ {
PayoutProcessorLink = LinkGenerator.GetUriByAction(httpContextAccessor.HttpContext, "ConfigureStorePayoutProcessors", "UIPayoutProcessors", new {StoreId}); try
LNAddressLink = LinkGenerator.GetUriByAction(httpContextAccessor.HttpContext, "EditLightningAddress", "UILNURL", new {StoreId}); {
PayoutsLink = LinkGenerator.GetUriByAction(httpContextAccessor.HttpContext, "Payouts", "UIStorePullPayments", new {StoreId, payoutState = PayoutState.AwaitingPayment, paymentMethodId = pmi.ToString()}); Logger.LogDebug("Loading prism settings");
PayoutProcessorLink = LinkGenerator.GetUriByAction(HttpContextAccessor.HttpContext, "ConfigureStorePayoutProcessors", "UIPayoutProcessors", new {StoreId});
LNAddressLink = LinkGenerator.GetUriByAction(HttpContextAccessor.HttpContext, "EditLightningAddress", "UILNURL", new {StoreId});
PayoutsLink = LinkGenerator.GetUriByAction(HttpContextAccessor.HttpContext, "Payouts", "UIStorePullPayments", new {StoreId, payoutState = PayoutState.AwaitingPayment, paymentMethodId = pmi.ToString()});
var fetchSettings = SatBreaker.Get(StoreId); var fetchSettings = SatBreaker.Get(StoreId);
var fetchLnAddresses = LightningAddressService.Get(new LightningAddressQuery() var fetchLnAddresses = LightningAddressService.Get(new LightningAddressQuery()
@@ -135,7 +142,7 @@ else
await Task.WhenAll(tasks); await Task.WhenAll(tasks);
Settings = await fetchSettings; Settings = await fetchSettings;
Users = await fetchLnAddresses; Users = await fetchLnAddresses;
Logger.LogInformation(JObject.FromObject(Settings).ToString());
EditContext = new EditContext(Settings); EditContext = new EditContext(Settings);
MessageStore = new ValidationMessageStore(EditContext); MessageStore = new ValidationMessageStore(EditContext);
EditContext.OnValidationRequested += Validate; EditContext.OnValidationRequested += Validate;
@@ -144,6 +151,11 @@ else
NoPayoutProcessors = PayoutProcessorFactories.Any(factory => factory.GetSupportedPaymentMethods().Contains(pmi)) && !(await fetchProcessors).Any(); NoPayoutProcessors = PayoutProcessorFactories.Any(factory => factory.GetSupportedPaymentMethods().Contains(pmi)) && !(await fetchProcessors).Any();
Loading = false; Loading = false;
await InvokeAsync(StateHasChanged); await InvokeAsync(StateHasChanged);
}
catch (Exception e)
{
Logger.LogError(e, "Error while loading sat breaker settings");
}
} }
await base.OnAfterRenderAsync(firstRender); await base.OnAfterRenderAsync(firstRender);
} }

View File

@@ -205,7 +205,7 @@ namespace BTCPayServer.Plugins.Prism
public async Task<PrismSettings> Get(string storeId) public async Task<PrismSettings> Get(string storeId)
{ {
return JObject.FromObject(_prismSettings.TryGetValue(storeId, out var settings) ? settings : new PrismSettings()).ToObject<PrismSettings>(); return JObject.FromObject(_prismSettings.TryGetValue(storeId, out var settings) && settings is not null ? settings : new PrismSettings()).ToObject<PrismSettings>();
} }
public async Task<bool> UpdatePrismSettingsForStore(string storeId, PrismSettings updatedSettings, public async Task<bool> UpdatePrismSettingsForStore(string storeId, PrismSettings updatedSettings,
@@ -381,6 +381,8 @@ namespace BTCPayServer.Plugins.Prism
private async Task<bool> CreatePayouts(string storeId, PrismSettings prismSettings) private async Task<bool> CreatePayouts(string storeId, PrismSettings prismSettings)
{ {
var result = false; var result = false;
prismSettings.DestinationBalance ??= new Dictionary<string, long>();
prismSettings.Destinations ??= new Dictionary<string, PrismDestination>();
foreach (var (destination, amtMsats) in prismSettings.DestinationBalance) foreach (var (destination, amtMsats) in prismSettings.DestinationBalance)
{ {
prismSettings.Destinations.TryGetValue(destination, out var destinationSettings); prismSettings.Destinations.TryGetValue(destination, out var destinationSettings);