upd prism

This commit is contained in:
Kukks
2023-08-14 12:51:34 +02:00
parent 30f7d5e339
commit c4d07a5134
4 changed files with 104 additions and 109 deletions

View File

@@ -40,7 +40,7 @@ namespace BTCPayServer.Plugins.FixedFloat
{ {
var k = $"{nameof(FixedFloatSettings)}_{storeId}"; var k = $"{nameof(FixedFloatSettings)}_{storeId}";
await _storeRepository.UpdateSetting(storeId, nameof(FixedFloatSettings), fixedFloatSettings); await _storeRepository.UpdateSetting(storeId, nameof(FixedFloatSettings), fixedFloatSettings);
_memoryCache.Set(k, fixedFloatSettings); _memoryCache.Remove(k);
} }
} }
} }

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.10</Version> <Version>1.1.11</Version>
</PropertyGroup> </PropertyGroup>
<!-- Plugin development properties --> <!-- Plugin development properties -->
<PropertyGroup> <PropertyGroup>

View File

@@ -9,6 +9,8 @@
} }
<span class="form-text">An alias to reference in destinations of prisms.</span> <span class="form-text">An alias to reference in destinations of prisms.</span>
</div> </div>
@if (WorkingCopy is not null)
{
<div class="form-group"> <div class="form-group">
<label class="form-label">Destination</label> <label class="form-label">Destination</label>
<input type="text" @bind="WorkingCopy.Destination" class="form-control"/> <input type="text" @bind="WorkingCopy.Destination" class="form-control"/>
@@ -33,9 +35,10 @@
<button type="button" class="btn btn-secondary" @onclick="Cancel">Cancel</button> <button type="button" class="btn btn-secondary" @onclick="Cancel">Cancel</button>
@if (!string.IsNullOrEmpty(OriginalWorkingId)) @if (!string.IsNullOrEmpty(OriginalWorkingId))
{ {
<button type="button" class="btn btn-outline-danger" @onclick="() => SettingsChanged.InvokeAsync(null)">Remove</button> <button type="button" class="btn btn-outline-danger" @onclick="() => OnUpdate.InvokeAsync((OriginalWorkingId, null))">Remove</button>
} }
</div> </div>
}
</div > </div >
@code { @code {
@@ -48,6 +51,7 @@
[Parameter] [Parameter]
public EventCallback OnCancel { get; set; } public EventCallback OnCancel { get; set; }
[Parameter] [Parameter]
public Func<string, bool> ValidateDestination { get; set; } public Func<string, bool> ValidateDestination { get; set; }
@@ -73,7 +77,6 @@ public EventCallback OnCancel { get; set; }
{ {
if (OriginalWorkingId != value) if (OriginalWorkingId != value)
{ {
WorkingId = value; WorkingId = value;
OriginalWorkingId = value; OriginalWorkingId = value;
InvalidId = false; InvalidId = false;
@@ -93,14 +96,12 @@ public EventCallback OnCancel { get; set; }
{ {
return; return;
} }
await IdChanged.InvokeAsync(WorkingId).ContinueWith(task => SettingsChanged.InvokeAsync(WorkingCopy)); await OnUpdate.InvokeAsync((WorkingId, WorkingCopy));
} }
[Parameter]
public EventCallback<PrismDestination?> SettingsChanged { get; set; }
[Parameter] [Parameter]
public EventCallback<string> IdChanged { get; set; } public EventCallback<(string Id, PrismDestination? Destination)> OnUpdate { get; set; }
private Task Cancel() private Task Cancel()

View File

@@ -126,8 +126,8 @@ else
ValidateId="ValidateId" ValidateId="ValidateId"
ValidateDestination="s => ValidateDestination(s, false)" ValidateDestination="s => ValidateDestination(s, false)"
Id="@SelectedDestinationId" Id="@SelectedDestinationId"
IdChanged="OnIdRenamed" Settings="@SelectedDestination"
@bind-Settings="SelectedDestination" OnUpdate="OnDestinationUpdated"
OnCancel="o => SelectedDestinationId = null"> OnCancel="o => SelectedDestinationId = null">
</PrismDestinationEditor> </PrismDestinationEditor>
} }
@@ -190,31 +190,6 @@ else
Settings.Destinations.TryGetValue(SelectedDestinationId, out var res); Settings.Destinations.TryGetValue(SelectedDestinationId, out var res);
return 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(); public string[] Destinations => Settings.Destinations.Keys.ToArray();
@@ -454,46 +429,6 @@ else
return true; 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) private async Task OnUpdateBalance((string destination, long newBalance) obj)
{ {
try 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";
}
}
} }