mirror of
https://github.com/aljazceru/BTCPayServerPlugins.git
synced 2025-12-17 07:34:24 +01:00
upd prism
This commit is contained in:
@@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|||||||
@@ -9,34 +9,37 @@
|
|||||||
}
|
}
|
||||||
<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>
|
||||||
<div class="form-group">
|
@if (WorkingCopy is not null)
|
||||||
<label class="form-label">Destination</label>
|
{
|
||||||
<input type="text" @bind="WorkingCopy.Destination" class="form-control"/>
|
<div class="form-group">
|
||||||
@if (Invalid)
|
<label class="form-label">Destination</label>
|
||||||
{
|
<input type="text" @bind="WorkingCopy.Destination" class="form-control"/>
|
||||||
<span class="text-danger w-100">Invalid</span>
|
@if (Invalid)
|
||||||
}
|
{
|
||||||
<span class="form-text">Can be a lightning address, LNURL, or a custom value that another plugin supports</span>
|
<span class="text-danger w-100">Invalid</span>
|
||||||
</div>
|
}
|
||||||
<div class="form-group">
|
<span class="form-text">Can be a lightning address, LNURL, or a custom value that another plugin supports</span>
|
||||||
<label class="form-label">Sat Threshold</label>
|
</div>
|
||||||
<input type="number" @bind="WorkingCopy.SatThreshold" min="1" class="form-control"/>
|
<div class="form-group">
|
||||||
<span class="form-text">How many sats do you want to accumulate before sending? Leave blank to use default setting.</span>
|
<label class="form-label">Sat Threshold</label>
|
||||||
</div>
|
<input type="number" @bind="WorkingCopy.SatThreshold" min="1" class="form-control"/>
|
||||||
<div class="form-group">
|
<span class="form-text">How many sats do you want to accumulate before sending? Leave blank to use default setting.</span>
|
||||||
<label class="form-label">Reserve fee</label>
|
</div>
|
||||||
<input type="number" @bind="WorkingCopy.Reserve" min="0" max="100" class="form-control"/>
|
<div class="form-group">
|
||||||
<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>
|
<label class="form-label">Reserve fee</label>
|
||||||
</div>
|
<input type="number" @bind="WorkingCopy.Reserve" min="0" max="100" class="form-control"/>
|
||||||
<div>
|
<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>
|
||||||
<button type="button" class="btn btn-primary" @onclick="Update">@(string.IsNullOrEmpty(OriginalWorkingId)? "Create": "Update")</button>
|
</div>
|
||||||
<button type="button" class="btn btn-secondary" @onclick="Cancel">Cancel</button>
|
<div>
|
||||||
@if (!string.IsNullOrEmpty(OriginalWorkingId))
|
<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>
|
||||||
<button type="button" class="btn btn-outline-danger" @onclick="() => SettingsChanged.InvokeAsync(null)">Remove</button>
|
@if (!string.IsNullOrEmpty(OriginalWorkingId))
|
||||||
}
|
{
|
||||||
</div>
|
<button type="button" class="btn btn-outline-danger" @onclick="() => OnUpdate.InvokeAsync((OriginalWorkingId, null))">Remove</button>
|
||||||
</div>
|
}
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</div >
|
||||||
|
|
||||||
@code {
|
@code {
|
||||||
|
|
||||||
@@ -45,9 +48,10 @@
|
|||||||
private PrismDestination WorkingCopy { get; set; }
|
private PrismDestination WorkingCopy { get; set; }
|
||||||
private string WorkingId { get; set; }
|
private string WorkingId { get; set; }
|
||||||
private string OriginalWorkingId { get; set; }
|
private string OriginalWorkingId { get; set; }
|
||||||
|
|
||||||
[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; }
|
||||||
|
|
||||||
@@ -71,9 +75,8 @@ public EventCallback OnCancel { get; set; }
|
|||||||
get => WorkingId;
|
get => WorkingId;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (OriginalWorkingId != value )
|
if (OriginalWorkingId != value)
|
||||||
{
|
{
|
||||||
|
|
||||||
WorkingId = value;
|
WorkingId = value;
|
||||||
OriginalWorkingId = value;
|
OriginalWorkingId = value;
|
||||||
InvalidId = false;
|
InvalidId = false;
|
||||||
@@ -88,23 +91,21 @@ public EventCallback OnCancel { get; set; }
|
|||||||
Invalid = !ValidateDestination.Invoke(WorkingCopy.Destination);
|
Invalid = !ValidateDestination.Invoke(WorkingCopy.Destination);
|
||||||
|
|
||||||
InvalidId = !ValidateId.Invoke(WorkingId);
|
InvalidId = !ValidateId.Invoke(WorkingId);
|
||||||
|
|
||||||
if(Invalid || InvalidId)
|
if (Invalid || InvalidId)
|
||||||
{
|
{
|
||||||
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()
|
||||||
{
|
{
|
||||||
return OnCancel.InvokeAsync(null);
|
return OnCancel.InvokeAsync(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user