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}";
await _storeRepository.UpdateSetting(storeId, nameof(FixedFloatSettings), fixedFloatSettings);
_memoryCache.Set(k, fixedFloatSettings);
_memoryCache.Remove(k);
}
}
}

View File

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

View File

@@ -9,34 +9,37 @@
}
<span class="form-text">An alias to reference in destinations of prisms.</span>
</div>
<div class="form-group">
<label class="form-label">Destination</label>
<input type="text" @bind="WorkingCopy.Destination" class="form-control"/>
@if (Invalid)
{
<span class="text-danger w-100">Invalid</span>
}
<span class="form-text">Can be a lightning address, LNURL, or a custom value that another plugin supports</span>
</div>
<div class="form-group">
<label class="form-label">Sat Threshold</label>
<input type="number" @bind="WorkingCopy.SatThreshold" min="1" class="form-control"/>
<span class="form-text">How many sats do you want to accumulate before sending? Leave blank to use default setting.</span>
</div>
<div class="form-group">
<label class="form-label">Reserve fee</label>
<input type="number" @bind="WorkingCopy.Reserve" min="0" max="100" class="form-control"/>
<span class="form-text">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.</span>
</div>
<div>
<button type="button" class="btn btn-primary" @onclick="Update">@(string.IsNullOrEmpty(OriginalWorkingId)? "Create": "Update")</button>
<button type="button" class="btn btn-secondary" @onclick="Cancel">Cancel</button>
@if (!string.IsNullOrEmpty(OriginalWorkingId))
{
<button type="button" class="btn btn-outline-danger" @onclick="() => SettingsChanged.InvokeAsync(null)">Remove</button>
}
</div>
</div>
@if (WorkingCopy is not null)
{
<div class="form-group">
<label class="form-label">Destination</label>
<input type="text" @bind="WorkingCopy.Destination" class="form-control"/>
@if (Invalid)
{
<span class="text-danger w-100">Invalid</span>
}
<span class="form-text">Can be a lightning address, LNURL, or a custom value that another plugin supports</span>
</div>
<div class="form-group">
<label class="form-label">Sat Threshold</label>
<input type="number" @bind="WorkingCopy.SatThreshold" min="1" class="form-control"/>
<span class="form-text">How many sats do you want to accumulate before sending? Leave blank to use default setting.</span>
</div>
<div class="form-group">
<label class="form-label">Reserve fee</label>
<input type="number" @bind="WorkingCopy.Reserve" min="0" max="100" class="form-control"/>
<span class="form-text">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.</span>
</div>
<div>
<button type="button" class="btn btn-primary" @onclick="Update">@(string.IsNullOrEmpty(OriginalWorkingId) ? "Create" : "Update")</button>
<button type="button" class="btn btn-secondary" @onclick="Cancel">Cancel</button>
@if (!string.IsNullOrEmpty(OriginalWorkingId))
{
<button type="button" class="btn btn-outline-danger" @onclick="() => OnUpdate.InvokeAsync((OriginalWorkingId, null))">Remove</button>
}
</div>
}
</div >
@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<string, bool> 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<PrismDestination?> SettingsChanged { get; set; }
[Parameter]
public EventCallback<string> IdChanged { get; set; }
public EventCallback<(string Id, PrismDestination? Destination)> OnUpdate { get; set; }
private Task Cancel()
{
{
return OnCancel.InvokeAsync(null);
}

View File

@@ -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">
</PrismDestinationEditor>
}
@@ -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";
}
}
}