From 83234d69d4cc7c5e65d9550f71cdb073c76639ab Mon Sep 17 00:00:00 2001 From: Kukks Date: Sun, 13 Aug 2023 10:33:56 +0200 Subject: [PATCH] many fixes to prism ui --- .../Components/PrismDestinationEditor.razor | 22 ++- .../Components/PrismDestinationManager.razor | 54 ------ .../Components/PrismEdit.razor | 169 ++++++++++++------ .../BTCPayServer.Plugins.Prism/SatBreaker.cs | 2 +- 4 files changed, 130 insertions(+), 117 deletions(-) delete mode 100644 Plugins/BTCPayServer.Plugins.Prism/Components/PrismDestinationManager.razor diff --git a/Plugins/BTCPayServer.Plugins.Prism/Components/PrismDestinationEditor.razor b/Plugins/BTCPayServer.Plugins.Prism/Components/PrismDestinationEditor.razor index b887bb3..edd04a8 100644 --- a/Plugins/BTCPayServer.Plugins.Prism/Components/PrismDestinationEditor.razor +++ b/Plugins/BTCPayServer.Plugins.Prism/Components/PrismDestinationEditor.razor @@ -29,8 +29,12 @@ When a payout is being generated, how much of its amount in percentage should be excluded to cover the fee? Once the payment is settled, if the lightning node provides the exact fee, the balance is adjusted accordingly. Leave blank to use default setting.
- - + + + @if (!string.IsNullOrEmpty(OriginalWorkingId)) + { + + }
@@ -42,7 +46,8 @@ private string WorkingId { get; set; } private string OriginalWorkingId { get; set; } - +[Parameter] +public EventCallback OnCancel { get; set; } [Parameter] public Func ValidateDestination { get; set; } @@ -66,8 +71,9 @@ get => WorkingId; set { - if (OriginalWorkingId != value) + if (OriginalWorkingId != value ) { + WorkingId = value; OriginalWorkingId = value; InvalidId = false; @@ -87,8 +93,7 @@ { return; } - await SettingsChanged.InvokeAsync(WorkingCopy); - await IdChanged.InvokeAsync(WorkingId); + await IdChanged.InvokeAsync(WorkingId).ContinueWith(task => SettingsChanged.InvokeAsync(WorkingCopy)); } [Parameter] @@ -98,4 +103,9 @@ public EventCallback IdChanged { get; set; } + private Task Cancel() + { + return OnCancel.InvokeAsync(null); + } + } \ No newline at end of file diff --git a/Plugins/BTCPayServer.Plugins.Prism/Components/PrismDestinationManager.razor b/Plugins/BTCPayServer.Plugins.Prism/Components/PrismDestinationManager.razor deleted file mode 100644 index 4734e7f..0000000 --- a/Plugins/BTCPayServer.Plugins.Prism/Components/PrismDestinationManager.razor +++ /dev/null @@ -1,54 +0,0 @@ -@* @using NBitcoin *@ -@* @if (Destinations.Any()) *@ -@* { *@ -@*
*@ -@* *@ -@*
*@ -@* *@ -@* @if (SelectedDestinationId is not null && SelectedDestinationId != "null") *@ -@* { *@ -@* *@ -@* } *@ -@* } *@ -@* *@ -@* @code { *@ -@* *@ -@* [Parameter] *@ -@* public Dictionary Destinations { get; set; } *@ -@* *@ -@* *@ -@* public string? SelectedDestinationId { get; set; } *@ -@* *@ -@* public PrismDestination? SelectedDestination *@ -@* { *@ -@* get *@ -@* { *@ -@* if (SelectedDestinationId is null or "null") *@ -@* return null; *@ -@* Destinations.TryGetValue(SelectedDestinationId, out var res); *@ -@* return res; *@ -@* } *@ -@* set *@ -@* { *@ -@* if (SelectedDestinationId is null) *@ -@* return; *@ -@* if (value is null) *@ -@* { *@ -@* Destinations.Remove(SelectedDestinationId); *@ -@* SelectedDestinationId = null; *@ -@* } *@ -@* else *@ -@* { *@ -@* Destinations.AddOrReplace(SelectedDestinationId, value); *@ -@* } *@ -@* } *@ -@* } *@ -@* *@ -@* } *@ \ No newline at end of file diff --git a/Plugins/BTCPayServer.Plugins.Prism/Components/PrismEdit.razor b/Plugins/BTCPayServer.Plugins.Prism/Components/PrismEdit.razor index 6731e44..2a0066a 100644 --- a/Plugins/BTCPayServer.Plugins.Prism/Components/PrismEdit.razor +++ b/Plugins/BTCPayServer.Plugins.Prism/Components/PrismEdit.razor @@ -66,60 +66,75 @@ else -
-
- -
- - - -
-
- - - - How many sats do you want to accumulate per destination before sending? -
-
- - - - When a payout is being generated, how many of its amount in percentage should be excluded to cover the fee? Once the payment is settled, if the lightning node provides the exact fee, the balance is adjusted accordingly. -
-
- - -
+
- -
- @foreach (var item in Settings.Splits) - { - - } -
-
- @if (Destinations.Any()) - { -
- -
- } - @if (SelectedDestinationId is not null && SelectedDestinationId != "null") +
+ @if (SelectedDestinationId is null or "null") { - +

Global Prism Settings

+
+
+ +
+ + + +
+
+ + + + How many sats do you want to accumulate per destination before sending? +
+
+ + + + When a payout is being generated, how many of its amount in percentage should be excluded to cover the fee? Once the payment is settled, if the lightning node provides the exact fee, the balance is adjusted accordingly. +
+
+ + +
+ + @if(Settings.Splits.Any()) + { +

Your Prisms

+ @foreach (var item in Settings.Splits) + { + + } + } + } + else + { + @if (SelectedDestinationId is not null && SelectedDestinationId != "null") + { + switch (SelectedDestinationId) + { + case "": +

Create new Destination

+ break; + default: +

Editing @SelectedDestinationId Destination

+ break; + } + + + + } }
- + @if (StatusMessageModel != null) @@ -130,12 +145,25 @@ else }
- - - + @if (SelectedDestinationId is null or "null") + { + + + + + } + @if (PrismEditButtonsFilter is not null) { - @((MarkupString)PrismEditButtonsFilter) + @((MarkupString) PrismEditButtonsFilter) }
@@ -151,7 +179,7 @@ else StateHasChanged(); } - public string? SelectedDestinationId { get; set; } + public string? SelectedDestinationId { get; set; } = "null"; public PrismDestination? SelectedDestination { @@ -169,12 +197,23 @@ else if (value is null) { Settings.Destinations.Remove(SelectedDestinationId); + + foreach (var settingsSplit in Settings.Splits) + { + settingsSplit.Destinations.RemoveAll(split => split.Destination == SelectedDestinationId); + } + SelectedDestinationId = null; } else { Settings.Destinations.AddOrReplace(SelectedDestinationId, value); + + SelectedDestinationId = "null"; } + + _ = SaveDestinations(); + } } @@ -186,6 +225,7 @@ else public bool NoPayoutProcessors { get; set; } private string PrismEditButtonsFilter { get; set; } + protected override async Task OnAfterRenderAsync(bool firstRender) { if (firstRender) @@ -347,6 +387,13 @@ else } } + private async Task SaveDestinations() + { + var settz = await SatBreaker.Get(StoreId); + settz.Destinations = Settings.Destinations; + await UpdateAndShowResult(settz); + } + private async Task Save() { var settz = await SatBreaker.Get(StoreId); @@ -356,6 +403,11 @@ else settz.SatThreshold = Settings.SatThreshold; settz.Reserve = Settings.Reserve; Settings = settz; + await UpdateAndShowResult(settz); + } + + private async Task UpdateAndShowResult(PrismSettings settz) + { var updateResult = await SatBreaker.UpdatePrismSettingsForStore(StoreId, settz); if (!updateResult) @@ -404,8 +456,13 @@ else private async Task OnIdRenamed(string s) { - if(SelectedDestinationId == s) + if (SelectedDestinationId == s) return; + if (string.IsNullOrEmpty(SelectedDestinationId)) + { + SelectedDestinationId = s; + return; + } try { await SatBreaker._updateLock.WaitAsync(); @@ -414,7 +471,7 @@ else { return; } - // find all prisms splits that use this id + all destination balances that use this id + all pending payouts that use this id and rename them + // find all prisms splits that use this id + all destination balances that use this id + all pending payouts that use this id and rename them foreach (var destination in Settings.Splits.SelectMany(split => split.Destinations.Where(destination => destination.Destination == SelectedDestinationId))) { destination.Destination = s; @@ -423,7 +480,7 @@ else { Settings.DestinationBalance.Add(s, db); } - if(Settings.Destinations.Remove(SelectedDestinationId, out var dest)) + if (Settings.Destinations.Remove(SelectedDestinationId, out var dest)) { Settings.Destinations.Add(s, dest); } @@ -451,11 +508,11 @@ else Settings.DestinationBalance.AddOrReplace(obj.destination, obj.newBalance); } await SatBreaker.UpdatePrismSettingsForStore(StoreId, Settings, true); - } finally { SatBreaker._updateLock.Release(); } } + } \ No newline at end of file diff --git a/Plugins/BTCPayServer.Plugins.Prism/SatBreaker.cs b/Plugins/BTCPayServer.Plugins.Prism/SatBreaker.cs index c34e219..68cd046 100644 --- a/Plugins/BTCPayServer.Plugins.Prism/SatBreaker.cs +++ b/Plugins/BTCPayServer.Plugins.Prism/SatBreaker.cs @@ -313,7 +313,7 @@ namespace BTCPayServer.Plugins.Prism { return; } -var onChainCatchAllIdentifier = "*"+ PaymentTypes.BTCLike.ToStringNormalized(); + var onChainCatchAllIdentifier = "*"+ PaymentTypes.BTCLike.ToStringNormalized(); var catchAllPrism = prismSettings.Splits.FirstOrDefault(split => split.Source == "*" || split.Source ==onChainCatchAllIdentifier); Split prism = null; LightningAddressData address = null;