From c4d07a5134d10437bf5a2acaf1a3dfd310a8e98e Mon Sep 17 00:00:00 2001 From: Kukks Date: Mon, 14 Aug 2023 12:51:34 +0200 Subject: [PATCH] upd prism --- .../FixedFloatService.cs | 2 +- .../BTCPayServer.Plugins.Prism.csproj | 2 +- .../Components/PrismDestinationEditor.razor | 81 +++++------ .../Components/PrismEdit.razor | 128 +++++++++--------- 4 files changed, 104 insertions(+), 109 deletions(-) diff --git a/Plugins/BTCPayServer.Plugins.FixedFloat/FixedFloatService.cs b/Plugins/BTCPayServer.Plugins.FixedFloat/FixedFloatService.cs index 9940349..1e8fff8 100644 --- a/Plugins/BTCPayServer.Plugins.FixedFloat/FixedFloatService.cs +++ b/Plugins/BTCPayServer.Plugins.FixedFloat/FixedFloatService.cs @@ -40,7 +40,7 @@ namespace BTCPayServer.Plugins.FixedFloat { var k = $"{nameof(FixedFloatSettings)}_{storeId}"; await _storeRepository.UpdateSetting(storeId, nameof(FixedFloatSettings), fixedFloatSettings); - _memoryCache.Set(k, fixedFloatSettings); + _memoryCache.Remove(k); } } } diff --git a/Plugins/BTCPayServer.Plugins.Prism/BTCPayServer.Plugins.Prism.csproj b/Plugins/BTCPayServer.Plugins.Prism/BTCPayServer.Plugins.Prism.csproj index ecc15c5..636c27b 100644 --- a/Plugins/BTCPayServer.Plugins.Prism/BTCPayServer.Plugins.Prism.csproj +++ b/Plugins/BTCPayServer.Plugins.Prism/BTCPayServer.Plugins.Prism.csproj @@ -11,7 +11,7 @@ LN Prism Automated value splits for lightning. - 1.1.10 + 1.1.11 diff --git a/Plugins/BTCPayServer.Plugins.Prism/Components/PrismDestinationEditor.razor b/Plugins/BTCPayServer.Plugins.Prism/Components/PrismDestinationEditor.razor index edd04a8..3843c19 100644 --- a/Plugins/BTCPayServer.Plugins.Prism/Components/PrismDestinationEditor.razor +++ b/Plugins/BTCPayServer.Plugins.Prism/Components/PrismDestinationEditor.razor @@ -9,34 +9,37 @@ } An alias to reference in destinations of prisms. -
- - - @if (Invalid) - { - Invalid - } - Can be a lightning address, LNURL, or a custom value that another plugin supports -
-
- - - How many sats do you want to accumulate before sending? Leave blank to use default setting. -
-
- - - 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)) - { - - } -
- + @if (WorkingCopy is not null) + { +
+ + + @if (Invalid) + { + Invalid + } + Can be a lightning address, LNURL, or a custom value that another plugin supports +
+
+ + + How many sats do you want to accumulate before sending? Leave blank to use default setting. +
+
+ + + 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)) + { + + } +
+ } + @code { @@ -45,9 +48,10 @@ private PrismDestination WorkingCopy { get; set; } private string WorkingId { get; set; } private string OriginalWorkingId { get; set; } - -[Parameter] -public EventCallback OnCancel { get; set; } + + [Parameter] + public EventCallback OnCancel { get; set; } + [Parameter] public Func ValidateDestination { get; set; } @@ -71,9 +75,8 @@ public EventCallback OnCancel { get; set; } get => WorkingId; set { - if (OriginalWorkingId != value ) + if (OriginalWorkingId != value) { - WorkingId = value; OriginalWorkingId = value; InvalidId = false; @@ -88,23 +91,21 @@ public EventCallback OnCancel { get; set; } Invalid = !ValidateDestination.Invoke(WorkingCopy.Destination); InvalidId = !ValidateId.Invoke(WorkingId); - - if(Invalid || InvalidId) + + if (Invalid || InvalidId) { return; } - await IdChanged.InvokeAsync(WorkingId).ContinueWith(task => SettingsChanged.InvokeAsync(WorkingCopy)); + await OnUpdate.InvokeAsync((WorkingId, WorkingCopy)); } - [Parameter] - public EventCallback SettingsChanged { get; set; } [Parameter] - public EventCallback IdChanged { get; set; } + public EventCallback<(string Id, PrismDestination? Destination)> OnUpdate { get; set; } private Task Cancel() - { + { return OnCancel.InvokeAsync(null); } diff --git a/Plugins/BTCPayServer.Plugins.Prism/Components/PrismEdit.razor b/Plugins/BTCPayServer.Plugins.Prism/Components/PrismEdit.razor index 2a0066a..99d1e1a 100644 --- a/Plugins/BTCPayServer.Plugins.Prism/Components/PrismEdit.razor +++ b/Plugins/BTCPayServer.Plugins.Prism/Components/PrismEdit.razor @@ -126,8 +126,8 @@ else ValidateId="ValidateId" ValidateDestination="s => ValidateDestination(s, false)" Id="@SelectedDestinationId" - IdChanged="OnIdRenamed" - @bind-Settings="SelectedDestination" + Settings="@SelectedDestination" + OnUpdate="OnDestinationUpdated" OnCancel="o => SelectedDestinationId = null"> } @@ -190,31 +190,6 @@ else Settings.Destinations.TryGetValue(SelectedDestinationId, out var res); return res; } - set - { - if (SelectedDestinationId is null) - return; - 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(); - - } } public string[] Destinations => Settings.Destinations.Keys.ToArray(); @@ -454,46 +429,6 @@ else return true; } - private async Task OnIdRenamed(string s) - { - if (SelectedDestinationId == s) - return; - if (string.IsNullOrEmpty(SelectedDestinationId)) - { - SelectedDestinationId = s; - return; - } - try - { - await SatBreaker._updateLock.WaitAsync(); - - if (SelectedDestinationId == s) - { - 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 - foreach (var destination in Settings.Splits.SelectMany(split => split.Destinations.Where(destination => destination.Destination == SelectedDestinationId))) - { - destination.Destination = s; - } - if (Settings.DestinationBalance.Remove(SelectedDestinationId, out var db)) - { - Settings.DestinationBalance.Add(s, db); - } - if (Settings.Destinations.Remove(SelectedDestinationId, out var dest)) - { - Settings.Destinations.Add(s, dest); - } - SelectedDestinationId = s; - - await SatBreaker.UpdatePrismSettingsForStore(StoreId, Settings, true); - } - finally - { - SatBreaker._updateLock.Release(); - } - } - private async Task OnUpdateBalance((string destination, long newBalance) obj) { try @@ -515,4 +450,63 @@ else } } + private async Task OnDestinationUpdated((string Id, PrismDestination? Destination) obj) + { + + if (obj.Destination is null && !string.IsNullOrEmpty(SelectedDestinationId)) + { + Settings.Destinations.Remove(SelectedDestinationId); + + foreach (var settingsSplit in Settings.Splits) + { + settingsSplit.Destinations.RemoveAll(split => split.Destination == SelectedDestinationId); + } + + SelectedDestinationId = null; + } + + else + { + Settings.Destinations.AddOrReplace(SelectedDestinationId, obj.Destination); + await SaveDestinations(); + var needSave = false; + if (!string.IsNullOrEmpty(SelectedDestinationId) && SelectedDestinationId != obj.Id) + { + try + { + await SatBreaker._updateLock.WaitAsync(); + + // 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 = obj.Id; + needSave = true; + } + if (Settings.DestinationBalance.Remove(SelectedDestinationId, out var db)) + { + needSave = true; + Settings.DestinationBalance.Add( obj.Id, db); + } + if (Settings.Destinations.Remove(SelectedDestinationId, out var dest)) + { + needSave = true; + Settings.Destinations.Add( obj.Id, dest); + } + if (needSave) + { + await SatBreaker.UpdatePrismSettingsForStore(StoreId, Settings, true); + } + } + finally + { + SatBreaker._updateLock.Release(); + } + } + SelectedDestinationId = "null"; + } + + + + } + } \ No newline at end of file